ref: refs/heads/SuSE-SLE-10-SP3-Branch
commit d8e75ff1d46cec5472691a7febfb8344febfdce0
Author: Michael Andres
Date: Thu Oct 1 14:27:59 2009 +0200
Add ProxyInfo::useProxyFor(Url) to evaluate Url matching a no_proxy entry.
---
zypp/media/ProxyInfo.cc | 3 +++
zypp/media/ProxyInfo.h | 9 ++++++++-
zypp/media/proxyinfo/ProxyInfoImpl.h | 32 ++++++++++++++++++++++++++++++--
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/zypp/media/ProxyInfo.cc b/zypp/media/ProxyInfo.cc
index f17e039..0b496ec 100644
--- a/zypp/media/ProxyInfo.cc
+++ b/zypp/media/ProxyInfo.cc
@@ -47,5 +47,8 @@ namespace zypp {
ProxyInfo::NoProxyIterator ProxyInfo::noProxyEnd() const
{ return _pimpl->noProxyEnd(); }
+ bool ProxyInfo::useProxyFor( const Url & url_r ) const
+ { return _pimpl->useProxyFor( url_r ); }
+
} // namespace media
} // namespace zypp
diff --git a/zypp/media/ProxyInfo.h b/zypp/media/ProxyInfo.h
index d704f23..2c7bed8 100644
--- a/zypp/media/ProxyInfo.h
+++ b/zypp/media/ProxyInfo.h
@@ -18,6 +18,9 @@
#include "zypp/base/PtrTypes.h"
namespace zypp {
+
+ class Url;
+
namespace media {
///////////////////////////////////////////////////////////////////
@@ -30,7 +33,7 @@ namespace zypp {
typedef intrusive_ptr<ProxyInfo> constPtr;
typedef std::liststd::string NoProxyList;
typedef std::liststd::string::const_iterator NoProxyIterator;
-
+
/** Implementation */
struct Impl;
typedef shared_ptr<Impl> ImplPtr;
@@ -43,6 +46,10 @@ namespace zypp {
NoProxyList noProxy() const;
NoProxyIterator noProxyBegin() const;
NoProxyIterator noProxyEnd() const;
+
+ /** Return \c true if \ref enabled and \a url_r does not match \ref noProxy. */
+ bool useProxyFor( const Url & url_r ) const;
+
private:
/** Pointer to implementation */
RW_pointer<Impl> _pimpl;
diff --git a/zypp/media/proxyinfo/ProxyInfoImpl.h b/zypp/media/proxyinfo/ProxyInfoImpl.h
index 9a07c67..9996b3a 100644
--- a/zypp/media/proxyinfo/ProxyInfoImpl.h
+++ b/zypp/media/proxyinfo/ProxyInfoImpl.h
@@ -15,6 +15,8 @@
#include <string>
#include <list>
+#include "zypp/Url.h"
+#include "zypp/base/String.h"
#include "zypp/media/ProxyInfo.h"
namespace zypp {
@@ -29,7 +31,7 @@ namespace zypp {
/** Dtor */
virtual ~Impl()
{}
-
+
public:
/** */
virtual bool enabled() const = 0;
@@ -41,7 +43,33 @@ namespace zypp {
virtual ProxyInfo::NoProxyIterator noProxyBegin() const = 0;
/** */
virtual ProxyInfo::NoProxyIterator noProxyEnd() const = 0;
-
+
+ /** Return \c true if \ref enabled and \a url_r does not match \ref noProxy. */
+ bool useProxyFor( const Url & url_r ) const
+ {
+ if ( ! enabled() )
+ return false;
+
+ ProxyInfo::NoProxyList noproxy( noProxy() );
+ if ( noproxy.size() == 1 && noproxy.front() == "*" )
+ return false; // just an asterisk disables all.
+
+ // No proxy: Either an exact match, or the previous character
+ // is a '.', so host is within the same domain.
+ // A leading '.' in the pattern is ignored. Some implementations
+ // need '.foo.ba' to prevent 'foo.ba' from matching 'xfoo.ba'.
+ std::string host( str::toLower( url_r.getHost() ) );
+ for_( it, noproxy.begin(), noproxy.end() )
+ {
+ std::string pattern( str::toLower( (*it)[0] == '.' ? it->c_str() + 1 : it->c_str() ) );
+ if ( str::hasSuffix( host, pattern )
+ && ( host.size() == pattern.size()
+ || host[host.size()-pattern.size()-1] == '.' ) )
+ return false;
+ }
+ return true;
+ }
+
public:
/** Default Impl: empty sets. */
static shared_ptr<Impl> _nullimpl;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org