libzypp 17.32.5
proxyinfolibproxy.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
13#include <iostream>
14#include <fstream>
15
18#include <zypp-core/fs/WatchFile>
19#include <zypp-core/Pathname.h>
20
21#include <zypp-curl/proxyinfo/ProxyInfoLibproxy>
22
23using std::endl;
24using namespace zypp::base;
25
26namespace zypp {
27 namespace media {
28
30 {
31 TmpUnsetEnv(const char *var_r) : _set(false), _var(var_r) {
32 const char * val = getenv( _var.c_str() );
33 if ( val )
34 {
35 _set = true;
36 _val = val;
37 ::unsetenv( _var.c_str() );
38 }
39 }
40
41 TmpUnsetEnv(const TmpUnsetEnv &) = delete;
43 TmpUnsetEnv &operator=(const TmpUnsetEnv &) = delete;
45
47 {
48 if ( _set )
49 {
50 setenv( _var.c_str(), _val.c_str(), 1 );
51 }
52 }
53
54 bool _set;
55 std::string _var;
56 std::string _val;
57 };
58
60 {
61 static pxProxyFactory * proxyFactory = 0;
62
63 // Force libproxy into using "/etc/sysconfig/proxy"
64 // if it exists.
65 static WatchFile sysconfigProxy( "/etc/sysconfig/proxy", WatchFile::NO_INIT );
66 if ( sysconfigProxy.hasChanged() )
67 {
68 MIL << "Build Libproxy Factory from /etc/sysconfig/proxy" << endl;
69 if ( proxyFactory )
70 ::px_proxy_factory_free( proxyFactory );
71
72 TmpUnsetEnv envguard[] __attribute__ ((__unused__)) = { "KDE_FULL_SESSION", "GNOME_DESKTOP_SESSION_ID", "DESKTOP_SESSION" };
73 proxyFactory = ::px_proxy_factory_new();
74 }
75 else if ( ! proxyFactory )
76 {
77 MIL << "Build Libproxy Factory" << endl;
78 proxyFactory = ::px_proxy_factory_new();
79 }
80
81 return proxyFactory;
82 }
83
90
93
94 std::string ProxyInfoLibproxy::proxy(const Url & url_r) const
95 {
96 if (!_enabled)
97 return "";
98
99 const url::ViewOption vopt =
104
106 (char *)url_r.asString(vopt).c_str());
107 if (!proxies)
108 return "";
109
110 /* cURL can only handle HTTP proxies, not SOCKS. And can only handle
111 one. So look through the list and find an appropriate one. */
112 char *result = NULL;
113
114 for (int i = 0; proxies[i]; i++) {
115 if (!result &&
116 !strncmp(proxies[i], "http://", 7))
117 result = proxies[i];
118 else
119 free(proxies[i]);
120 }
121 free(proxies);
122
123 if (!result)
124 return "";
125
126 std::string sresult = result;
127 free(result);
128 return sresult;
129 }
130
133
136
137 } // namespace media
138} // namespace zypp
RepoManager implementation.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Url manipulation class.
Definition Url.h:92
Remember a files attributes to detect content changes.
Definition watchfile.h:50
DefaultIntegral< bool, false > _enabled
ProxyInfo::NoProxyIterator noProxyBegin() const override
std::string proxy(const Url &url_r) const override
ProxyInfo::NoProxyIterator noProxyEnd() const override
ProxyInfo::NoProxyList _no_proxy
std::list< std::string >::const_iterator NoProxyIterator
Definition proxyinfo.h:35
static pxProxyFactory * getProxyFactory()
Easy-to use interface to the ZYPP dependency resolver.
TmpUnsetEnv(TmpUnsetEnv &&)=delete
TmpUnsetEnv(const char *var_r)
TmpUnsetEnv & operator=(const TmpUnsetEnv &)=delete
TmpUnsetEnv & operator=(TmpUnsetEnv &&)=delete
TmpUnsetEnv(const TmpUnsetEnv &)=delete
Url::asString() view options.
Definition UrlBase.h:40
static const ViewOption WITH_SCHEME
Option to include scheme name in the URL string.
Definition UrlBase.h:51
static const ViewOption WITH_PORT
Option to include port number in the URL string.
Definition UrlBase.h:81
static const ViewOption WITH_PATH_NAME
Option to include path name in the URL string.
Definition UrlBase.h:87
static const ViewOption WITH_HOST
Option to include hostname in the URL string.
Definition UrlBase.h:74
#define MIL
Definition Logger.h:96