libzypp  17.28.5
ProxyInfoSysconfig.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <iostream>
14 #include <fstream>
15 
16 #include <zypp/base/Logger.h>
17 #include <zypp/base/String.h>
18 #include <zypp/Pathname.h>
19 
21 
22 using namespace zypp::base;
23 
24 namespace zypp {
25  namespace media {
26 
27  ProxyInfoSysconfig::ProxyInfoSysconfig(const Pathname & path)
28  : ProxyInfo::Impl()
29  {
30  std::map<std::string,std::string> data = sysconfig::read(
31  path.relative()
32  ? "/etc/sysconfig" + path
33  : path);
34  std::map<std::string,std::string>::const_iterator it = data.find("PROXY_ENABLED");
35  if (it != data.end())
36  _enabled = it->second != "no";
37  it = data.find("HTTP_PROXY");
38  if (it != data.end())
39  _proxies["http"] = it->second;
40  it = data.find("HTTPS_PROXY");
41  if (it != data.end())
42  _proxies["https"] = it->second;
43  it = data.find("FTP_PROXY");
44  if (it != data.end())
45  _proxies["ftp"] = it->second;
46  it = data.find("NO_PROXY");
47  if (it != data.end())
48  str::split(it->second, std::back_inserter(_no_proxy), ", \t");
49  }
50 
51  std::string ProxyInfoSysconfig::proxy(const Url & url_r) const
52  {
53  std::map<std::string,std::string>::const_iterator it = _proxies.find(url_r.getScheme());
54  if (it != _proxies.end())
55  return it->second;
56  return "";
57  }
58 
60  { return _no_proxy.begin(); }
61 
63  { return _no_proxy.end(); }
64 
65  } // namespace media
66 } // namespace zypp
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
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