separated implementation classes
authorJiri Srain <jsrain@suse.cz>
Thu, 15 Dec 2005 08:49:45 +0000 (08:49 +0000)
committerJiri Srain <jsrain@suse.cz>
Thu, 15 Dec 2005 08:49:45 +0000 (08:49 +0000)
zypp/media/proxyinfo/Makefile.am [new file with mode: 0644]
zypp/media/proxyinfo/ProxyInfoImpl.h [new file with mode: 0644]
zypp/media/proxyinfo/ProxyInfoSysconfig.cc [new file with mode: 0644]
zypp/media/proxyinfo/ProxyInfoSysconfig.h [new file with mode: 0644]

diff --git a/zypp/media/proxyinfo/Makefile.am b/zypp/media/proxyinfo/Makefile.am
new file mode 100644 (file)
index 0000000..4d6304c
--- /dev/null
@@ -0,0 +1,25 @@
+## Process this file with automake to produce Makefile.in
+## ##################################################
+
+SUBDIRS =
+
+INCLUDES = -I$(oldincludedir)/libxml2
+
+## ##################################################
+
+include_HEADERS =              \
+       ProxyInfoImpl.h         \
+       ProxyInfoSysconfig.h
+
+
+noinst_LTLIBRARIES =   lib@PACKAGE@_media.la
+
+## ##################################################
+
+lib@PACKAGE@_media_la_SOURCES = \
+       ProxyInfoSysconfig.cc
+
+
+lib@PACKAGE@_media_la_LIBADD = -lcurl
+
+## ##################################################
diff --git a/zypp/media/proxyinfo/ProxyInfoImpl.h b/zypp/media/proxyinfo/ProxyInfoImpl.h
new file mode 100644 (file)
index 0000000..9355c51
--- /dev/null
@@ -0,0 +1,52 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/proxyinfoProxyInfoImpl.h
+ *
+*/
+#ifndef ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H
+#define ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H
+
+#include <string>
+#include <list>
+
+#include "zypp/media/ProxyInfo.h"
+
+namespace zypp {
+  namespace media {
+
+    struct ProxyInfo::Impl
+    {
+      /** Ctor */
+      Impl()
+      {}
+
+      /** Dtor */
+      virtual ~Impl()
+      {}
+  
+    public:
+      /**  */
+      virtual bool enabled() const = 0;
+      /**  */
+      virtual std::string proxy(const std::string & prorocol_r) const = 0;
+      /**  */
+      virtual std::list<std::string> noProxy() const = 0;
+  
+    public:
+      /** Default Impl: empty sets. */
+      static shared_ptr<Impl> _nullimpl;
+    };
+
+
+///////////////////////////////////////////////////////////////////
+
+  } // namespace media
+} // namespace zypp
+
+#endif // ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H
diff --git a/zypp/media/proxyinfo/ProxyInfoSysconfig.cc b/zypp/media/proxyinfo/ProxyInfoSysconfig.cc
new file mode 100644 (file)
index 0000000..e4e2640
--- /dev/null
@@ -0,0 +1,94 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/proxyinfo/ProxyInfoSysconfig.cc
+ *
+*/
+
+#include <iostream>
+#include <fstream>
+
+#include "zypp/base/Logger.h"
+#include "zypp/base/String.h"
+#include "zypp/Pathname.h"
+
+#include "zypp/media/proxyinfo/ProxyInfoSysconfig.h"
+
+using namespace std;
+using namespace zypp::base;
+
+namespace zypp {
+  namespace media {
+
+
+    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
+    }
+
+    std::string ProxyInfo_sysconfig::proxy(const std::string & protocol_r) const
+    { return ""; }
+
+
+  } // namespace media
+} // namespace zypp
diff --git a/zypp/media/proxyinfo/ProxyInfoSysconfig.h b/zypp/media/proxyinfo/ProxyInfoSysconfig.h
new file mode 100644 (file)
index 0000000..f9145a8
--- /dev/null
@@ -0,0 +1,51 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/proxyinfo/ProxyInfoSysconfig.h
+ *
+*/
+#ifndef ZYPP_MEDIA_PROXYINFO_PROXYINFOSYSCONFIG_H
+#define ZYPP_MEDIA_PROXYINFO_PROXYINFOSYSCONFIG_H
+
+#include <string>
+#include <list>
+
+#include "zypp/media/ProxyInfo.h"
+#include "zypp/media/proxyinfo/ProxyInfoImpl.h"
+
+namespace zypp {
+  namespace media {
+
+
+    class ProxyInfo_sysconfig : public ProxyInfo::Impl
+    {
+    public:
+      ProxyInfo_sysconfig(const Pathname & path);
+      /**  */
+      bool enabled() const
+      { return _enabled; }
+      /**  */
+      std::string proxy(const std::string & protocol_r) const;
+      /**  */
+      std::list<std::string> noProxy() const
+      { return _no_proxy; }
+    private:
+      bool _enabled;
+      std::list<std::string> _no_proxy;
+    };
+
+    namespace proxyinfo {
+      std::map<std::string,std::string> sysconfigRead(const Pathname & _path);
+    } // namespace proxyinfo
+
+///////////////////////////////////////////////////////////////////
+
+  } // namespace media
+} // namespace zypp
+
+#endif // ZYPP_MEDIA_PROXYINFO_PROXYINFOSYSCONFIG_H