libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H 00013 #define ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H 00014 00015 #include <string> 00016 #include <list> 00017 00018 #include "zypp/Url.h" 00019 #include "zypp/base/String.h" 00020 #include "zypp/media/ProxyInfo.h" 00021 00022 namespace zypp { 00023 namespace media { 00024 00025 struct ProxyInfo::Impl 00026 { 00028 Impl() 00029 {} 00030 00032 virtual ~Impl() 00033 {} 00034 00035 public: 00037 virtual bool enabled() const = 0; 00039 virtual std::string proxy(const Url & url_r) const = 0; 00041 virtual ProxyInfo::NoProxyList noProxy() const = 0; 00043 virtual ProxyInfo::NoProxyIterator noProxyBegin() const = 0; 00045 virtual ProxyInfo::NoProxyIterator noProxyEnd() const = 0; 00046 00048 bool useProxyFor( const Url & url_r ) const 00049 { 00050 if ( ! enabled() || proxy( url_r ).empty() ) 00051 return false; 00052 00053 ProxyInfo::NoProxyList noproxy( noProxy() ); 00054 if ( noproxy.size() == 1 && noproxy.front() == "*" ) 00055 return false; // just an asterisk disables all. 00056 00057 // No proxy: Either an exact match, or the previous character 00058 // is a '.', so host is within the same domain. 00059 // A leading '.' in the pattern is ignored. Some implementations 00060 // need '.foo.ba' to prevent 'foo.ba' from matching 'xfoo.ba'. 00061 std::string host( str::toLower( url_r.getHost() ) ); 00062 for_( it, noproxy.begin(), noproxy.end() ) 00063 { 00064 std::string pattern( str::toLower( (*it)[0] == '.' ? it->c_str() + 1 : it->c_str() ) ); 00065 if ( str::hasSuffix( host, pattern ) 00066 && ( host.size() == pattern.size() 00067 || host[host.size()-pattern.size()-1] == '.' ) ) 00068 return false; 00069 } 00070 return true; 00071 } 00072 00073 public: 00075 static shared_ptr<Impl> _nullimpl; 00076 }; 00077 00078 00080 00081 } // namespace media 00082 } // namespace zypp 00083 00084 #endif // ZYPP_MEDIA_PROXYINFO_PROXYINFOIMPL_H