libzypp  17.31.31
proxyinfosysconfig.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include "proxyinfosysconfig.h"
14 
15 #include <iostream>
16 #include <fstream>
17 
18 #include <zypp-core/base/Logger.h>
19 #include <zypp-core/base/String.h>
20 #include <zypp-core/Pathname.h>
21 
22 
23 using namespace zypp::base;
24 
25 namespace zypp {
26  namespace media {
27 
28  ProxyInfoSysconfig::ProxyInfoSysconfig(const Pathname & path)
29  : ProxyInfo::Impl()
30  {
31  std::map<std::string,std::string> data = sysconfig::read(
32  path.relative()
33  ? "/etc/sysconfig" + path
34  : path);
35  std::map<std::string,std::string>::const_iterator it = data.find("PROXY_ENABLED");
36  if (it != data.end())
37  _enabled = it->second != "no";
38  it = data.find("HTTP_PROXY");
39  if (it != data.end())
40  _proxies["http"] = it->second;
41  it = data.find("HTTPS_PROXY");
42  if (it != data.end())
43  _proxies["https"] = it->second;
44  it = data.find("FTP_PROXY");
45  if (it != data.end())
46  _proxies["ftp"] = it->second;
47  it = data.find("NO_PROXY");
48  if (it != data.end())
49  str::split(it->second, std::back_inserter(_no_proxy), ", \t");
50  }
51 
52  std::string ProxyInfoSysconfig::proxy(const Url & url_r) const
53  {
54  std::map<std::string,std::string>::const_iterator it = _proxies.find(url_r.getScheme());
55  if (it != _proxies.end())
56  return it->second;
57  return "";
58  }
59 
61  { return _no_proxy.begin(); }
62 
64  { return _no_proxy.end(); }
65 
66  } // namespace media
67 } // namespace zypp
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:533
ProxyInfo::NoProxyList _no_proxy
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
Definition: sysconfig.cc:34
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, const Trim trim_r=NO_TRIM)
Split line_r into words.
Definition: String.h:531
std::list< std::string >::const_iterator NoProxyIterator
Definition: proxyinfo.h:35
virtual ProxyInfo::NoProxyIterator noProxyEnd() const
bool relative() const
Test for a relative path.
Definition: Pathname.h:118
DefaultIntegral< bool, false > _enabled
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::map< std::string, std::string > _proxies
Url manipulation class.
Definition: Url.h:91
std::string proxy(const Url &url_r) const
virtual ProxyInfo::NoProxyIterator noProxyBegin() const