|
libzypp
9.1.2
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00013 #include <iostream> 00014 #include <fstream> 00015 00016 #include "zypp/base/Logger.h" 00017 #include "zypp/base/String.h" 00018 #include "zypp/Pathname.h" 00019 00020 #include "zypp/media/proxyinfo/ProxyInfoLibproxy.h" 00021 00022 using namespace std; 00023 using namespace zypp::base; 00024 00025 namespace zypp { 00026 namespace media { 00027 00028 ProxyInfoLibproxy::ProxyInfoLibproxy() 00029 : ProxyInfo::Impl() 00030 { 00031 _factory = px_proxy_factory_new(); 00032 _enabled = !(_factory == NULL); 00033 } 00034 00035 ProxyInfoLibproxy::~ProxyInfoLibproxy() 00036 { 00037 if (_enabled) { 00038 px_proxy_factory_free(_factory); 00039 _factory = NULL; 00040 _enabled = false; 00041 } 00042 } 00043 00044 std::string ProxyInfoLibproxy::proxy(const Url & url_r) const 00045 { 00046 if (!_enabled) 00047 return ""; 00048 00049 const url::ViewOption vopt = 00050 url::ViewOption::WITH_SCHEME 00051 + url::ViewOption::WITH_HOST 00052 + url::ViewOption::WITH_PORT 00053 + url::ViewOption::WITH_PATH_NAME; 00054 00055 char **proxies = px_proxy_factory_get_proxies(_factory, 00056 (char *)url_r.asString(vopt).c_str()); 00057 if (!proxies) 00058 return ""; 00059 00060 /* cURL can only handle HTTP proxies, not SOCKS. And can only handle 00061 one. So look through the list and find an appropriate one. */ 00062 char *result = NULL; 00063 00064 for (int i = 0; proxies[i]; i++) { 00065 if (!result && 00066 !strncmp(proxies[i], "http://", 7)) 00067 result = proxies[i]; 00068 else 00069 free(proxies[i]); 00070 } 00071 free(proxies); 00072 00073 if (!result) 00074 return ""; 00075 00076 std::string sresult = result; 00077 free(result); 00078 return sresult; 00079 } 00080 00081 ProxyInfo::NoProxyIterator ProxyInfoLibproxy::noProxyBegin() const 00082 { return _no_proxy.begin(); } 00083 00084 ProxyInfo::NoProxyIterator ProxyInfoLibproxy::noProxyEnd() const 00085 { return _no_proxy.end(); } 00086 00087 } // namespace media 00088 } // namespace zypp
1.7.6.1