more updates of proxy handling
authorJiri Srain <jsrain@suse.cz>
Thu, 15 Dec 2005 09:37:57 +0000 (09:37 +0000)
committerJiri Srain <jsrain@suse.cz>
Thu, 15 Dec 2005 09:37:57 +0000 (09:37 +0000)
zypp/media/Makefile.am
zypp/media/MediaCurl.cc
zypp/media/ProxyInfo.cc
zypp/media/ProxyInfo.h
zypp/media/proxyinfo/Makefile.am
zypp/media/proxyinfo/ProxyInfoImpl.h
zypp/media/proxyinfo/ProxyInfoSysconfig.cc
zypp/media/proxyinfo/ProxyInfoSysconfig.h
zypp/media/proxyinfo/ProxyInfos.h [new file with mode: 0644]

index 138d555..e5e145a 100644 (file)
@@ -1,7 +1,7 @@
 ## Process this file with automake to produce Makefile.in
 ## ##################################################
 
-SUBDIRS =
+SUBDIRS = proxyinfo
 
 INCLUDES = -I$(oldincludedir)/libxml2
 
@@ -41,6 +41,7 @@ lib@PACKAGE@_media_la_SOURCES = \
        MediaCurl.cc
 
 
-lib@PACKAGE@_media_la_LIBADD = -lcurl
+lib@PACKAGE@_media_la_LIBADD = proxyinfo/lib@PACKAGE@_media_proxyinfo.la \
+                               -lcurl
 
 ## ##################################################
index cca16a1..0b718c6 100644 (file)
@@ -18,6 +18,7 @@
 
 #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>
@@ -195,15 +196,15 @@ void MediaCurl::attachTo (bool next)
     }
   } 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,
@@ -219,13 +220,7 @@ void MediaCurl::attachTo (bool next)
       }
 
       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());
       }
     }
   }
index 05522f3..6f940f3 100644 (file)
 */
 
 #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;
@@ -34,81 +32,20 @@ namespace zypp {
     : _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
index 9b9bd4e..d2e65ee 100644 (file)
 #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 {
@@ -26,86 +23,30 @@ 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
 
 ///////////////////////////////////////////////////////////////////
 
index 4d6304c..f692c6b 100644 (file)
@@ -9,17 +9,17 @@ INCLUDES = -I$(oldincludedir)/libxml2
 
 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 =
 
 ## ##################################################
index 9355c51..c7f813a 100644 (file)
@@ -36,7 +36,11 @@ namespace zypp {
       /**  */
       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. */
index e4e2640..65ae18c 100644 (file)
@@ -61,7 +61,7 @@ namespace zypp {
       }
     } // namespace proxyinfo
 
-    ProxyInfo_sysconfig::ProxyInfo_sysconfig(const Pathname & path)
+    ProxyInfoSysconfig::ProxyInfoSysconfig(const Pathname & path)
     : ProxyInfo::Impl()
     {
       map<string,string> data = proxyinfo::sysconfigRead(
@@ -71,24 +71,34 @@ namespace zypp {
       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
index f9145a8..93030d2 100644 (file)
@@ -13,7 +13,7 @@
 #define ZYPP_MEDIA_PROXYINFO_PROXYINFOSYSCONFIG_H
 
 #include <string>
-#include <list>
+#include <map>
 
 #include "zypp/media/ProxyInfo.h"
 #include "zypp/media/proxyinfo/ProxyInfoImpl.h"
@@ -22,21 +22,26 @@ namespace zypp {
   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 {
diff --git a/zypp/media/proxyinfo/ProxyInfos.h b/zypp/media/proxyinfo/ProxyInfos.h
new file mode 100644 (file)
index 0000000..b827aeb
--- /dev/null
@@ -0,0 +1,20 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ 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