libzypp  17.23.8
ProxyInfoImpl.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H
13 #define ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H
14 
15 #include <string>
16 #include <list>
17 
18 #include <zypp/Url.h>
19 #include <zypp/base/String.h>
20 #include <zypp/media/ProxyInfo.h>
21 
22 namespace zypp {
23  namespace media {
24 
26  {
28  Impl()
29  {}
30 
32  virtual ~Impl()
33  {}
34 
35  public:
37  virtual bool enabled() const = 0;
39  virtual std::string proxy(const Url & url_r) const = 0;
41  virtual ProxyInfo::NoProxyList noProxy() const = 0;
43  virtual ProxyInfo::NoProxyIterator noProxyBegin() const = 0;
45  virtual ProxyInfo::NoProxyIterator noProxyEnd() const = 0;
46 
48  bool useProxyFor( const Url & url_r ) const
49  {
50  if ( ! enabled() || proxy( url_r ).empty() )
51  return false;
52 
53  ProxyInfo::NoProxyList noproxy( noProxy() );
54  if ( noproxy.size() == 1 && noproxy.front() == "*" )
55  return false; // just an asterisk disables all.
56 
57  // No proxy: Either an exact match, or the previous character
58  // is a '.', so host is within the same domain.
59  // A leading '.' in the pattern is ignored. Some implementations
60  // need '.foo.ba' to prevent 'foo.ba' from matching 'xfoo.ba'.
61  std::string host( str::toLower( url_r.getHost() ) );
62  for_( it, noproxy.begin(), noproxy.end() )
63  {
64  std::string pattern( str::toLower( (*it)[0] == '.' ? it->c_str() + 1 : it->c_str() ) );
65  if ( str::hasSuffix( host, pattern )
66  && ( host.size() == pattern.size()
67  || host[host.size()-pattern.size()-1] == '.' ) )
68  return false;
69  }
70  return true;
71  }
72 
73  public:
75  static shared_ptr<Impl> _nullimpl;
76  };
77 
78 
80 
81  } // namespace media
82 } // namespace zypp
83 
84 #endif // ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H
zypp::media::ProxyInfo::Impl::noProxyBegin
virtual ProxyInfo::NoProxyIterator noProxyBegin() const =0
zypp::media::ProxyInfo::NoProxyList
std::list< std::string > NoProxyList
Definition: ProxyInfo.h:34
zypp::media::ProxyInfo::Impl::useProxyFor
bool useProxyFor(const Url &url_r) const
Return true if enabled and url_r does not match noProxy.
Definition: ProxyInfoImpl.h:48
zypp::media::ProxyInfo::NoProxyIterator
std::list< std::string >::const_iterator NoProxyIterator
Definition: ProxyInfo.h:35
zypp::media::ProxyInfo::Impl
Definition: ProxyInfoImpl.h:25
ProxyInfo.h
zypp::media::ProxyInfo::Impl::noProxy
virtual ProxyInfo::NoProxyList noProxy() const =0
Url.h
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::str::toLower
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:172
zypp::str::hasSuffix
bool hasSuffix(const C_Str &str_r, const C_Str &suffix_r)
Return whether str_r has suffix suffix_r.
Definition: String.h:1037
zypp::media::ProxyInfo::Impl::enabled
virtual bool enabled() const =0
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
String.h
zypp::Url::getHost
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:583
zypp::media::ProxyInfo::Impl::proxy
virtual std::string proxy(const Url &url_r) const =0
zypp::media::ProxyInfo::Impl::noProxyEnd
virtual ProxyInfo::NoProxyIterator noProxyEnd() const =0
zypp::media::ProxyInfo::Impl::_nullimpl
static shared_ptr< Impl > _nullimpl
Default Impl: empty sets.
Definition: ProxyInfoImpl.h:75
zypp::Url
Url manipulation class.
Definition: Url.h:87
zypp::media::ProxyInfo::Impl::Impl
Impl()
Ctor.
Definition: ProxyInfoImpl.h:28
zypp::media::ProxyInfo::Impl::~Impl
virtual ~Impl()
Dtor.
Definition: ProxyInfoImpl.h:32