20#include <zypp-core/fs/WatchFile> 
   24#include <zypp-curl/proxyinfo/ProxyInfoLibproxy> 
   36      static const bool _inYAST { ::getenv(
"YAST_IS_RUNNING") };
 
 
   58        CreateFactoryCb createProxyFactory = 
nullptr;
 
   59        DelFactoryCb    deleteProxyFactory = 
nullptr;
 
   60        GetProxiesCb    getProxies         = 
nullptr;
 
   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;
 
   74          zypp::AutoDispose<void *> handle( dlopen(
"libproxy.so.1", RTLD_LAZY ), []( 
void *ptr ){ 
if ( ptr ) ::dlclose(ptr); });
 
   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();
 
  116          ZYPP_THROW( zypp::Exception(
"LibProxyAPI is not available.") );
 
  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();
 
 
  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() )
 
  193      const std::string myschema { url_r.
getScheme()+
":" };
 
  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( 
"" );
 
 
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.
TriBool getenvBool(const C_Str &var_r)
If the environment variable var_r is set to a legal true or false string return bool,...
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
Temporarily set/unset an environment variable.
ScopedSet(const ScopedSet &)=delete
Url::asString() view options.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.