libzypp  15.28.6
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 std;
23 using namespace zypp::base;
24 
25 namespace zypp {
26  namespace media {
27 
28  ProxyInfoSysconfig::ProxyInfoSysconfig(const Pathname & path)
29  : ProxyInfo::Impl()
30  {
31  map<string,string> data = sysconfig::read(
32  path.relative()
33  ? "/etc/sysconfig" + path
34  : path);
35  map<string,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  map<string,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
Helper filtering the files offered by a RepomdFileReader.
virtual ProxyInfo::NoProxyIterator noProxyEnd() const
ProxyInfo::NoProxyList _no_proxy
map< string, 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=" \t")
Split line_r into words.
Definition: String.h:518
std::string proxy(const Url &url_r) const
std::list< std::string >::const_iterator NoProxyIterator
Definition: ProxyInfo.h:35
virtual ProxyInfo::NoProxyIterator noProxyBegin() const
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:527
DefaultIntegral< bool, false > _enabled
std::map< std::string, std::string > _proxies
Url manipulation class.
Definition: Url.h:87