20#include <zypp-core/fs/WatchFile> 
   23#include <zypp-curl/proxyinfo/ProxyInfoLibproxy> 
   35      static const bool _inYAST { ::getenv(
"YAST_IS_RUNNING") };
 
 
   51        CreateFactoryCb createProxyFactory = 
nullptr;
 
   52        DelFactoryCb    deleteProxyFactory = 
nullptr;
 
   53        GetProxiesCb    getProxies         = 
nullptr;
 
   61        static void fallbackFreeProxies( 
char **proxies ) {
 
   62          g_clear_pointer (&proxies, g_strfreev);
 
   65        static std::unique_ptr<LibProxyAPI> create() {
 
   66          MIL << 
"Detecting libproxy availability" << std::endl;
 
   67          zypp::AutoDispose<void *> handle( dlopen(
"libproxy.so.1", RTLD_LAZY ), []( 
void *ptr ){ 
if ( ptr ) ::dlclose(ptr); });
 
   69            MIL << 
"No libproxy support detected (could not load library): " << dlerror() << std::endl;
 
   73          std::unique_ptr<LibProxyAPI> apiInstance = std::make_unique<LibProxyAPI>();
 
   74          apiInstance->libProxyLibHandle = std::move(handle);
 
   75          apiInstance->createProxyFactory = (CreateFactoryCb)::dlsym ( apiInstance->libProxyLibHandle, 
"px_proxy_factory_new" );
 
   76          if ( !apiInstance->createProxyFactory ){
 
   77            ERR << 
"Incompatible libproxy detected (could not resolve px_proxy_factory_new): " << dlerror() << std::endl;
 
   80          apiInstance->deleteProxyFactory = (DelFactoryCb)::dlsym ( apiInstance->libProxyLibHandle, 
"px_proxy_factory_free" );
 
   81          if ( !apiInstance->deleteProxyFactory ){
 
   82            ERR << 
"Incompatible libproxy detected (could not resolve px_proxy_factory_free): " << dlerror() << std::endl;
 
   85          apiInstance->getProxies = (GetProxiesCb)::dlsym ( apiInstance->libProxyLibHandle, 
"px_proxy_factory_get_proxies" );
 
   86          if ( !apiInstance->getProxies ){
 
   87            ERR << 
"Incompatible libproxy detected (could not resolve px_proxy_factory_get_proxies): " << dlerror() << std::endl;
 
   90          apiInstance->freeProxies = (
FreeProxiesCb)::dlsym ( apiInstance->libProxyLibHandle, 
"px_proxy_factory_free_proxies" );
 
   91          if ( !apiInstance->freeProxies ){
 
   92            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;
 
   93            apiInstance->freeProxies = &fallbackFreeProxies;
 
   96          MIL << 
"Libproxy is available" << std::endl;
 
  101      LibProxyAPI *proxyApi() {
 
  102        static std::unique_ptr<LibProxyAPI> api = LibProxyAPI::create();
 
  106      LibProxyAPI &assertProxyApi() {
 
  107        auto api = proxyApi();
 
  109          ZYPP_THROW( zypp::Exception(
"LibProxyAPI is not available.") );
 
  117        const char * val = getenv( 
_var.c_str() );
 
  122          ::unsetenv( 
_var.c_str() );
 
 
  135          setenv( 
_var.c_str(), 
_val.c_str(), 1 );
 
 
 
  153        MIL << 
"Build Libproxy Factory from /etc/sysconfig/proxy" << endl;
 
  155          assertProxyApi().deleteProxyFactory( proxyFactory );
 
  157        TmpUnsetEnv envguard[] __attribute__ ((__unused__)) = { 
"KDE_FULL_SESSION", 
"GNOME_DESKTOP_SESSION_ID", 
"DESKTOP_SESSION" };
 
  158        proxyFactory = assertProxyApi().createProxyFactory();
 
  160      else if ( ! proxyFactory )
 
  162        MIL << 
"Build Libproxy Factory" << endl;
 
  163        proxyFactory = assertProxyApi().createProxyFactory();
 
 
  181      return ( proxyApi () != 
nullptr );
 
 
  190              url::ViewOption::WITH_SCHEME
 
  191              + url::ViewOption::WITH_HOST
 
  192              + url::ViewOption::WITH_PORT
 
  193              + url::ViewOption::WITH_PATH_NAME;
 
  195      auto &api = assertProxyApi ();
 
  201      if ( !proxies.
value() )
 
  209      const std::string myschema { url_r.
getScheme()+
":" };
 
  210      std::optional<std::string> result;
 
  211      for ( 
int i = 0; proxies[i]; ++i ) {
 
  219      return result.value_or( 
"" );
 
 
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
reference value() const
Reference to the Tp object.
std::string getScheme() const
Returns the scheme name of the URL.
std::string asString() const
Returns a default string representation of the Url object.
Remember a files attributes to detect content changes.
Namespace intended to collect all environment variables we use.
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Easy-to use interface to the ZYPP dependency resolver.
struct _pxProxyFactory pxProxyFactoryType
Url::asString() view options.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.