libzypp 17.37.10

proxyinfosysconfig.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
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
60 ProxyInfo::NoProxyIterator ProxyInfoSysconfig::noProxyBegin() const
61 { return _no_proxy.begin(); }
62
63 ProxyInfo::NoProxyIterator ProxyInfoSysconfig::noProxyEnd() const
64 { return _no_proxy.end(); }
65
66 } // namespace media
67} // namespace zypp
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::Url::getScheme
std::string getScheme() const
Returns the scheme name of the URL.
Definition Url.cc:551
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::filesystem::Pathname::relative
bool relative() const
Test for a relative path.
Definition Pathname.h:120
zypp::media::ProxyInfoSysconfig::_proxies
std::map< std::string, std::string > _proxies
Definition proxyinfosysconfig.h:46
zypp::media::ProxyInfoSysconfig::noProxyEnd
ProxyInfo::NoProxyIterator noProxyEnd() const override
Definition proxyinfosysconfig.cc:63
zypp::media::ProxyInfoSysconfig::noProxyBegin
ProxyInfo::NoProxyIterator noProxyBegin() const override
Definition proxyinfosysconfig.cc:60
zypp::media::ProxyInfoSysconfig::ProxyInfoSysconfig
ProxyInfoSysconfig(const Pathname &path)
Definition proxyinfosysconfig.cc:28
zypp::media::ProxyInfoSysconfig::_enabled
DefaultIntegral< bool, false > _enabled
Definition proxyinfosysconfig.h:44
zypp::media::ProxyInfoSysconfig::proxy
std::string proxy(const Url &url_r) const override
Definition proxyinfosysconfig.cc:52
zypp::media::ProxyInfoSysconfig::_no_proxy
ProxyInfo::NoProxyList _no_proxy
Definition proxyinfosysconfig.h:45
zypp::media::ProxyInfo
Definition proxyinfo.h:30
zypp::media::ProxyInfo::NoProxyIterator
std::list< std::string >::const_iterator NoProxyIterator
Definition proxyinfo.h:35
zypp::base::sysconfig::read
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
Definition sysconfig.cc:34
zypp::base
Definition Random.cc:7
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::str::split
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
Definition String.h:602
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
proxyinfosysconfig.h
zypp::media::ProxyInfo::Impl::Impl
Impl()
Ctor.
Definition proxyinfoimpl.h:28
Pathname.h
Logger.h
String.h