19 #include <zypp-core/fs/WatchFile> 22 #include <zypp-curl/proxyinfo/ProxyInfoLibproxy> 35 using CreateFactoryCb = CreateFactorySig<pxProxyFactoryType>;
36 using DelFactoryCb = DelFactorySig<pxProxyFactoryType>;
37 using GetProxiesCb = GetProxiesSig<pxProxyFactoryType>;
52 static void fallbackFreeProxies(
char **proxies ) {
53 g_clear_pointer (&proxies, g_strfreev);
56 static std::unique_ptr<LibProxyAPI> create() {
57 MIL <<
"Detecting libproxy availability" << std::endl;
60 MIL <<
"No libproxy support detected (could not load library): " << dlerror() << std::endl;
64 std::unique_ptr<LibProxyAPI> apiInstance = std::make_unique<LibProxyAPI>();
65 apiInstance->libProxyLibHandle = std::move(handle);
66 apiInstance->createProxyFactory = (CreateFactoryCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_new" );
67 if ( !apiInstance->createProxyFactory ){
68 ERR <<
"Incompatible libproxy detected (could not resolve px_proxy_factory_new): " << dlerror() << std::endl;
71 apiInstance->deleteProxyFactory = (DelFactoryCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_free" );
72 if ( !apiInstance->deleteProxyFactory ){
73 ERR <<
"Incompatible libproxy detected (could not resolve px_proxy_factory_free): " << dlerror() << std::endl;
76 apiInstance->getProxies = (GetProxiesCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_get_proxies" );
77 if ( !apiInstance->getProxies ){
78 ERR <<
"Incompatible libproxy detected (could not resolve px_proxy_factory_get_proxies): " << dlerror() << std::endl;
81 apiInstance->freeProxies = (
FreeProxiesCb)::dlsym ( apiInstance->libProxyLibHandle,
"px_proxy_factory_free_proxies" );
82 if ( !apiInstance->freeProxies ){
83 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;
84 apiInstance->freeProxies = &fallbackFreeProxies;
87 MIL <<
"Libproxy is available" << std::endl;
92 LibProxyAPI *proxyApi() {
93 static std::unique_ptr<LibProxyAPI> api = LibProxyAPI::create();
97 LibProxyAPI &assertProxyApi() {
98 auto api = proxyApi();
108 const char * val = getenv( _var.c_str() );
113 ::unsetenv( _var.c_str() );
126 setenv( _var.c_str(), _val.c_str(), 1 );
144 MIL <<
"Build Libproxy Factory from /etc/sysconfig/proxy" << endl;
146 assertProxyApi().deleteProxyFactory( proxyFactory );
148 TmpUnsetEnv envguard[]
__attribute__ ((__unused__)) = {
"KDE_FULL_SESSION",
"GNOME_DESKTOP_SESSION_ID",
"DESKTOP_SESSION" };
149 proxyFactory = assertProxyApi().createProxyFactory();
151 else if ( ! proxyFactory )
153 MIL <<
"Build Libproxy Factory" << endl;
154 proxyFactory = assertProxyApi().createProxyFactory();
160 ProxyInfoLibproxy::ProxyInfoLibproxy()
172 return ( proxyApi () !=
nullptr );
181 url::ViewOption::WITH_SCHEME
182 + url::ViewOption::WITH_HOST
183 + url::ViewOption::WITH_PORT
184 + url::ViewOption::WITH_PATH_NAME;
186 auto &api = assertProxyApi ();
192 if ( !proxies.
value() )
197 std::optional<std::string> result;
198 for (
int i = 0; proxies[i]; i++) {
199 if ( !result && !strncmp(proxies[i],
"http://", 7) ) {
204 return result.value_or(
"" );
#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.
std::string asString() const
Returns a default string representation of the Url object.
zypp::AutoDispose< void * > libProxyLibHandle
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
Easy-to use interface to the ZYPP dependency resolver.