#include "zypp/base/Gettext.h"
#include "zypp/media/MediaCurl.h"
-#include "zypp/media/proxyinfo/ProxyInfos.h"
#include "zypp/media/ProxyInfo.h"
#include "zypp/media/MediaUserAuth.h"
#include "zypp/media/CredentialManager.h"
*/
void fillSettingsSystemProxy( const Url&url, TransferSettings &s )
{
-#ifdef _WITH_LIBPROXY_SUPPORT_
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoLibproxy()));
-#else
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
-#endif
+ ProxyInfo proxy_info;
if ( proxy_info.useProxyFor( url ) )
{
// We must extract any 'user:pass' from the proxy url
#include "zypp/media/ProxyInfo.h"
#include "zypp/media/proxyinfo/ProxyInfoImpl.h"
+#include "zypp/media/proxyinfo/ProxyInfos.h"
using namespace std;
using namespace zypp::base;
shared_ptr<ProxyInfo::Impl> ProxyInfo::Impl::_nullimpl;
ProxyInfo::ProxyInfo()
- : _pimpl( Impl::_nullimpl )
+#ifdef _WITH_LIBPROXY_SUPPORT_
+ : _pimpl( new ProxyInfoLibproxy() )
+#else
+ : _pimpl( new ProxyInfoSysconfig("proxy") )
+#endif
{}
+
ProxyInfo::ProxyInfo(ProxyInfo::ImplPtr pimpl_r)
: _pimpl(pimpl_r)
{}
/** Implementation */
struct Impl;
typedef shared_ptr<Impl> ImplPtr;
- /** Ctor */
+
+ /** Default Ctor: guess the best available implementation. */
ProxyInfo();
- /** Ctor */
- ProxyInfo(ProxyInfo::ImplPtr pimpl_r);
+ /** Ctor taking a specific implementation. */
+ ProxyInfo( ProxyInfo::ImplPtr pimpl_r );
+
bool enabled() const;
std::string proxy(const Url & url) const;
NoProxyList noProxy() const;
#include "zypp/base/Logger.h"
#include "zypp/base/String.h"
+#include "zypp/base/WatchFile.h"
#include "zypp/Pathname.h"
#include "zypp/media/proxyinfo/ProxyInfoLibproxy.h"
namespace zypp {
namespace media {
+ struct TmpUnsetEnv
+ {
+ TmpUnsetEnv( const char * var_r )
+ : _set( false )
+ , _var( var_r )
+ {
+ const char * val = getenv( _var.c_str() );
+ if ( val )
+ {
+ _set = true;
+ _val = val;
+ ::unsetenv( _var.c_str() );
+ }
+ }
+
+ ~TmpUnsetEnv()
+ {
+ if ( _set )
+ {
+ setenv( _var.c_str(), _val.c_str(), 1 );
+ }
+ }
+
+ bool _set;
+ std::string _var;
+ std::string _val;
+ };
+
+ static pxProxyFactory * getProxyFactory()
+ {
+ static pxProxyFactory * proxyFactory = 0;
+
+ // Force libproxy into using "/etc/sysconfig/proxy"
+ // if it exists.
+ static WatchFile sysconfigProxy( "/etc/sysconfig/proxy", WatchFile::NO_INIT );
+ if ( sysconfigProxy.hasChanged() )
+ {
+ MIL << "Build Libproxy Factory from /etc/sysconfig/proxy" << endl;
+ if ( proxyFactory )
+ ::px_proxy_factory_free( proxyFactory );
+
+ TmpUnsetEnv env[] = { "KDE_FULL_SESSION", "GNOME_DESKTOP_SESSION_ID", "DESKTOP_SESSION" };
+ proxyFactory = ::px_proxy_factory_new();
+ }
+ else if ( ! proxyFactory )
+ {
+ MIL << "Build Libproxy Factory" << endl;
+ proxyFactory = ::px_proxy_factory_new();
+ }
+
+ return proxyFactory;
+ }
+
ProxyInfoLibproxy::ProxyInfoLibproxy()
: ProxyInfo::Impl()
{
- _factory = px_proxy_factory_new();
+ _factory = getProxyFactory();
_enabled = !(_factory == NULL);
}
ProxyInfoLibproxy::~ProxyInfoLibproxy()
- {
- if (_enabled) {
- px_proxy_factory_free(_factory);
- _factory = NULL;
- _enabled = false;
- }
- }
+ {}
std::string ProxyInfoLibproxy::proxy(const Url & url_r) const
{
}
std::string ProxyInfoSysconfig::proxy(const Url & url_r) const
- {
+ {
map<string,string>::const_iterator it = _proxies.find(url_r.getScheme());
if (it != _proxies.end())
return it->second;