## Process this file with automake to produce Makefile.in
## ##################################################
-SUBDIRS =
+SUBDIRS = proxyinfo
INCLUDES = -I$(oldincludedir)/libxml2
MediaCurl.cc
-lib@PACKAGE@_media_la_LIBADD = -lcurl
+lib@PACKAGE@_media_la_LIBADD = proxyinfo/lib@PACKAGE@_media_proxyinfo.la \
+ -lcurl
## ##################################################
#include "zypp/media/MediaCurl.h"
#include "zypp/media/MediaCallbacks.h"
+#include "zypp/media/proxyinfo/ProxyInfos.h"
#include "zypp/media/ProxyInfo.h"
#include <sys/types.h>
}
} else {
- ProxyInfo proxy_info (RW_pointer<ProxyInfo::Impl>(new ProxyInfo_sysconfig("proxy")));
+ ProxyInfo proxy_info (RW_pointer<ProxyInfo::Impl>(new ProxyInfoSysconfig("proxy")));
if ( proxy_info.enabled())
{
bool useproxy = true;
std::list<std::string> nope = proxy_info.noProxy();
- for (std::list<std::string>::const_iterator it = nope.begin();
- it != nope.end();
+ for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
+ it != proxy_info.noProxyEnd();
it++)
{
// no proxy: if nope equals host,
}
if ( useproxy ) {
- if ( _url.getScheme() == "ftp" ) {
- _proxy = proxy_info.ftp();
- } else if ( _url.getScheme() == "http" ) {
- _proxy = proxy_info.http();
- } else if ( _url.getScheme() == "https" ) {
- _proxy = proxy_info.https();
- }
+ _proxy = proxy_info.proxy(_url.getScheme());
}
}
}
*/
#include <iostream>
-#include <fstream>
#include "zypp/base/Logger.h"
-#include "zypp/base/String.h"
-#include "zypp/Pathname.h"
#include "zypp/media/ProxyInfo.h"
+#include "zypp/media/proxyinfo/ProxyInfoImpl.h"
using namespace std;
using namespace zypp::base;
: _pimpl(impl)
{}
- bool ProxyInfo::enabled()
+ bool ProxyInfo::enabled() const
{ return _pimpl->enabled(); }
- std::string ProxyInfo::http()
- { return _pimpl->http(); }
+ std::string ProxyInfo::proxy(const std::string & protocol_r) const
+ { return _pimpl->proxy(protocol_r); }
- std::string ProxyInfo::ftp()
- { return _pimpl->ftp(); }
-
- std::string ProxyInfo::https()
- { return _pimpl->https(); }
-
- std::list<std::string> ProxyInfo::noProxy()
+ ProxyInfo::NoProxyList ProxyInfo::noProxy() const
{ return _pimpl->noProxy(); }
- namespace proxyinfo {
- map<string,string> sysconfigRead(const Pathname & _path)
- {
- DBG << "Load '" << _path << "'" << endl;
- map<string,string> ret;
-
- string line;
- ifstream in( _path.asString().c_str() );
- if ( in.fail() ) {
- WAR << "Unable to load '" << _path << "'" << endl;
- return ret;
- }
- while( getline( in, line ) ) {
- if ( *line.begin() != '#' ) {
- string::size_type pos = line.find( '=', 0 );
- if ( pos != string::npos ) {
- string key = str::trim( line.substr( 0, pos ) );
- string value = str::trim( line.substr( pos + 1, line.length() - pos - 1 ) );
- if ( value.length() >= 2 && *(value.begin()) == '"' &&
- *(value.rbegin()) == '"' ) {
- value = value.substr( 1, value.length() - 2 );
- }
- if ( value.length() >= 2 && *(value.begin()) == '\'' &&
- *(value.rbegin()) == '\'' ) {
- value = value.substr( 1, value.length() - 2 );
- }
- DBG << "KEY: '" << key << "' VALUE: '" << value << "'" << endl;
- ret[key] = value;
- }
- }
- }
- return ret;
- }
- } // namespace proxyinfo
-
- ProxyInfo_sysconfig::ProxyInfo_sysconfig(const Pathname & path)
- : ProxyInfo::Impl()
- {
- map<string,string> data = proxyinfo::sysconfigRead(
- path.relative()
- ? "/etc/sysconfig" + path
- : path);
- map<string,string>::const_iterator it = data.find("PROXY_ENABLED");
- if (it != data.end())
- _enabled = it->second != "no";
- it = data.find("HTTP_PROXY");
- if (it != data.end())
- _http = it->second;
- it = data.find("HTTPS_PROXY");
- if (it != data.end())
- _https = it->second;
- it = data.find("FTP_PROXY");
- if (it != data.end())
- _ftp = it->second;
- it = data.find("NO_PROXY");
- if (it != data.end())
- _no_proxy.push_back(it->second);
-#warning FIXME once splitting a string is in str:: namespace
- }
+ ProxyInfo::NoProxyIterator ProxyInfo::noProxyBegin() const
+ { return _pimpl->noProxyBegin(); }
+ ProxyInfo::NoProxyIterator ProxyInfo::noProxyEnd() const
+ { return _pimpl->noProxyEnd(); }
} // namespace media
} // namespace zypp
#define ZYPP_MEDIA_PROXYINFO_H
#include <string>
-#include <map>
#include <list>
-#include "zypp/base/ReferenceCounted.h"
-#include "zypp/base/NonCopyable.h"
#include "zypp/base/PtrTypes.h"
namespace zypp {
///////////////////////////////////////////////////////////////////
//
// CLASS NAME : ProxyInfo
- class ProxyInfo : public base::ReferenceCounted, private base::NonCopyable
+ class ProxyInfo
{
public:
typedef intrusive_ptr<ProxyInfo> Ptr;
typedef intrusive_ptr<ProxyInfo> constPtr;
+ typedef std::list<std::string> NoProxyList;
+ typedef std::list<std::string>::const_iterator NoProxyIterator;
+
/** Implementation */
struct Impl;
+ /** Ctor */
ProxyInfo();
+ /** Ctor */
ProxyInfo(RW_pointer<Impl> impl);
- bool enabled();
- std::string http();
- std::string ftp();
- std::string https();
- std::list<std::string> noProxy();
-
+ bool enabled() const;
+ std::string proxy(const std::string & protocol_r) const;
+ NoProxyList noProxy() const;
+ NoProxyIterator noProxyBegin() const;
+ NoProxyIterator noProxyEnd() const;
private:
/** Pointer to implementation */
RW_pointer<Impl> _pimpl;
};
- struct ProxyInfo::Impl
- {
- /** Ctor */
- Impl()
- : _enabled( false )
- , _http( "" )
- , _ftp( "" )
- , _https( "" )
- , _no_proxy()
- {}
- /** Ctor */
- Impl( const bool enabled,
- const std::string & http_r,
- const std::string & ftp_r,
- const std::string & https_r,
- const std::list<std::string> & no_proxy_r )
- : _enabled( enabled )
- , _http( http_r )
- , _ftp( ftp_r )
- , _https( https_r )
- , _no_proxy( no_proxy_r )
- {}
-
- public:
- /** */
- const bool & enabled() const
- { return _enabled; }
- /** */
- const std::string & http() const
- { return _http; }
- /** */
- const std::string & ftp() const
- { return _ftp; }
- /** */
- const std::string & https() const
- { return _https; }
- /** */
- const std::list<std::string> & noProxy() const
- { return _no_proxy; }
-
- protected:
- bool _enabled;
- std::string _http;
- std::string _ftp;
- std::string _https;
- std::list<std::string> _no_proxy;
- public:
- /** Default Impl: empty sets. */
- static shared_ptr<Impl> _nullimpl;
- };
-
- class ProxyInfo_sysconfig : public ProxyInfo::Impl
- {
- public:
- ProxyInfo_sysconfig(const Pathname & path);
- };
-
- namespace proxyinfo {
- std::map<std::string,std::string> sysconfigRead(const Pathname & _path);
- } // namespace proxyinfo
///////////////////////////////////////////////////////////////////
include_HEADERS = \
ProxyInfoImpl.h \
+ ProxyInfos.h \
ProxyInfoSysconfig.h
-noinst_LTLIBRARIES = lib@PACKAGE@_media.la
+noinst_LTLIBRARIES = lib@PACKAGE@_media_proxyinfo.la
## ##################################################
-lib@PACKAGE@_media_la_SOURCES = \
+lib@PACKAGE@_media_proxyinfo_la_SOURCES = \
ProxyInfoSysconfig.cc
-
-lib@PACKAGE@_media_la_LIBADD = -lcurl
+lib@PACKAGE@_media_proxyinfo_la_LIBADD =
## ##################################################
/** */
virtual std::string proxy(const std::string & prorocol_r) const = 0;
/** */
- virtual std::list<std::string> noProxy() const = 0;
+ virtual ProxyInfo::NoProxyList noProxy() const = 0;
+ /** */
+ virtual ProxyInfo::NoProxyIterator noProxyBegin() const = 0;
+ /** */
+ virtual ProxyInfo::NoProxyIterator noProxyEnd() const = 0;
public:
/** Default Impl: empty sets. */
}
} // namespace proxyinfo
- ProxyInfo_sysconfig::ProxyInfo_sysconfig(const Pathname & path)
+ ProxyInfoSysconfig::ProxyInfoSysconfig(const Pathname & path)
: ProxyInfo::Impl()
{
map<string,string> data = proxyinfo::sysconfigRead(
map<string,string>::const_iterator it = data.find("PROXY_ENABLED");
if (it != data.end())
_enabled = it->second != "no";
-/* it = data.find("HTTP_PROXY");
+ it = data.find("HTTP_PROXY");
if (it != data.end())
- _http = it->second;
+ _proxies["http"] = it->second;
it = data.find("HTTPS_PROXY");
if (it != data.end())
- _https = it->second;
+ _proxies["https"] = it->second;
it = data.find("FTP_PROXY");
if (it != data.end())
- _ftp = it->second;*/
+ _proxies["ftp"] = it->second;
it = data.find("NO_PROXY");
if (it != data.end())
_no_proxy.push_back(it->second);
#warning FIXME once splitting a string is in str:: namespace
}
- std::string ProxyInfo_sysconfig::proxy(const std::string & protocol_r) const
- { return ""; }
+ std::string ProxyInfoSysconfig::proxy(const std::string & protocol_r) const
+ {
+ map<string,string>::const_iterator it = _proxies.find(protocol_r);
+ if (it != _proxies.end())
+ return it->second;
+ return "";
+ }
+
+ ProxyInfo::NoProxyIterator ProxyInfoSysconfig::noProxyBegin() const
+ { return _no_proxy.begin(); }
+ ProxyInfo::NoProxyIterator ProxyInfoSysconfig::noProxyEnd() const
+ { return _no_proxy.end(); }
} // namespace media
} // namespace zypp
#define ZYPP_MEDIA_PROXYINFO_PROXYINFOSYSCONFIG_H
#include <string>
-#include <list>
+#include <map>
#include "zypp/media/ProxyInfo.h"
#include "zypp/media/proxyinfo/ProxyInfoImpl.h"
namespace media {
- class ProxyInfo_sysconfig : public ProxyInfo::Impl
+ class ProxyInfoSysconfig : public ProxyInfo::Impl
{
public:
- ProxyInfo_sysconfig(const Pathname & path);
+ ProxyInfoSysconfig(const Pathname & path);
/** */
bool enabled() const
{ return _enabled; }
/** */
std::string proxy(const std::string & protocol_r) const;
/** */
- std::list<std::string> noProxy() const
+ ProxyInfo::NoProxyList noProxy() const
{ return _no_proxy; }
+ /** */
+ virtual ProxyInfo::NoProxyIterator noProxyBegin() const;
+ /** */
+ virtual ProxyInfo::NoProxyIterator noProxyEnd() const;
private:
bool _enabled;
- std::list<std::string> _no_proxy;
+ ProxyInfo::NoProxyList _no_proxy;
+ std::map<std::string,std::string> _proxies;
};
namespace proxyinfo {
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/proxyinfoProxyInfos.h
+ *
+*/
+#ifndef ZYPP_MEDIA_PROXYINFO_PROXYINFOS_H
+#define ZYPP_MEDIA_PROXYINFO_PROXYINFOS_H
+
+#include <string>
+#include <list>
+
+#include "zypp/media/proxyinfo/ProxyInfoSysconfig.h"
+
+#endif // ZYPP_MEDIA_PROXYINFO_PROXYINFOS_H