20 #include <zypp-core/fs/WatchFile> 24 #include <zypp-curl/proxyinfo/ProxyInfoLibproxy> 36 static const bool _inYAST {
static_cast<bool>(::getenv(
"YAST_IS_RUNNING")) };
51 using CreateFactoryCb = CreateFactorySig<pxProxyFactoryType>;
52 using DelFactoryCb = DelFactorySig<pxProxyFactoryType>;
53 using GetProxiesCb = GetProxiesSig<pxProxyFactoryType>;
68 static void fallbackFreeProxies(
char **proxies ) {
69 g_clear_pointer (&proxies, g_strfreev);
72 static std::unique_ptr<LibProxyAPI> create() {
73 MIL <<
"Detecting libproxy availability" << std::endl;
76 MIL <<
"No libproxy support detected (could not load library): " << dlerror() << std::endl;
80 std::unique_ptr<LibProxyAPI> apiInstance = std::make_unique<LibProxyAPI>();
81 apiInstance->libProxyLibHandle = std::move(handle);
82 apiInstance->createProxyFactory = (CreateFactoryCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_new" );
83 if ( !apiInstance->createProxyFactory ){
84 ERR <<
"Incompatible libproxy detected (could not resolve px_proxy_factory_new): " << dlerror() << std::endl;
87 apiInstance->deleteProxyFactory = (DelFactoryCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_free" );
88 if ( !apiInstance->deleteProxyFactory ){
89 ERR <<
"Incompatible libproxy detected (could not resolve px_proxy_factory_free): " << dlerror() << std::endl;
92 apiInstance->getProxies = (GetProxiesCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_get_proxies" );
93 if ( !apiInstance->getProxies ){
94 ERR <<
"Incompatible libproxy detected (could not resolve px_proxy_factory_get_proxies): " << dlerror() << std::endl;
97 apiInstance->freeProxies = (
FreeProxiesCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_free_proxies" );
98 if ( !apiInstance->freeProxies ){
99 MIL <<
"Older version of libproxy detected, using fallback function to free the proxy list (could not resolve px_proxy_factory_free_proxies): " << dlerror() << std::endl;
100 apiInstance->freeProxies = &fallbackFreeProxies;
103 MIL <<
"Libproxy is available" << std::endl;
108 LibProxyAPI *proxyApi() {
109 static std::unique_ptr<LibProxyAPI> api = LibProxyAPI::create();
113 LibProxyAPI &assertProxyApi() {
114 auto api = proxyApi();
124 :
env::ScopedSet( var_r, nullptr )
137 MIL <<
"Build Libproxy Factory from /etc/sysconfig/proxy" << endl;
139 assertProxyApi().deleteProxyFactory( proxyFactory );
141 TmpUnsetEnv envguard[]
__attribute__ ((__unused__)) = {
"KDE_FULL_SESSION",
"GNOME_DESKTOP_SESSION_ID",
"DESKTOP_SESSION" };
142 proxyFactory = assertProxyApi().createProxyFactory();
144 else if ( ! proxyFactory )
146 MIL <<
"Build Libproxy Factory" << endl;
147 proxyFactory = assertProxyApi().createProxyFactory();
153 ProxyInfoLibproxy::ProxyInfoLibproxy()
165 return ( proxyApi () !=
nullptr );
174 url::ViewOption::WITH_SCHEME
175 + url::ViewOption::WITH_HOST
176 + url::ViewOption::WITH_PORT
177 + url::ViewOption::WITH_PATH_NAME;
179 auto &api = assertProxyApi ();
185 if ( !proxies.
value() )
194 std::optional<std::string> result;
195 for (
int i = 0; proxies[i]; ++i ) {
204 L_DBG(
"PX_DEBUG") <<
"Url " << url_r << endl;
205 for (
int i = 0; proxies[i]; ++i ) {
206 L_DBG(
"PX_DEBUG") <<
"got " << proxies[i] << endl;
208 L_DBG(
"PX_DEBUG") <<
"--> " << result.value_or(
"" ) << endl;
211 return result.value_or(
"" );
Namespace intended to collect all environment variables we use.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
FreeProxiesCb freeProxies
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Url::asString() view options.
Remember a files attributes to detect content changes.
Temporarily set/unset an environment variable.
std::string asString() const
Returns a default string representation of the Url object.
zypp::AutoDispose< void * > libProxyLibHandle
TriBool getenvBool(const C_Str &var_r)
If the environment variable var_r is set to a legal true or false string return bool, else indeterminate.
DelFactoryCb deleteProxyFactory
struct _pxProxyFactory pxProxyFactoryType
Base class for Exception.
reference value() const
Reference to the Tp object.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
CreateFactoryCb createProxyFactory
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.