Mailinglist Archive: zypp-devel (26 mails)
| < Previous | Next > |
Re: [zypp-devel] [PATCH] Disable proxy for special repository
- From: "Duncan Mac-Vicar P." <dmacvicar@xxxxxxx>
- Date: Mon, 20 Sep 2010 15:11:19 +0200
- Message-id: <4C975D77.4020101@xxxxxxx>
On 09/20/2010 01:19 PM, Zhang, Qiang Z wrote:
I think the right implementation would look like this, as there is no need to set the values in each protocol, there is a TransferSettings class for that,
Others, feedback?
Duncan
diff --git a/zypp/Url.cc b/zypp/Url.cc
index 7ca3c61..81e8230 100644
--- a/zypp/Url.cc
+++ b/zypp/Url.cc
@@ -814,6 +814,13 @@ namespace zypp
}
// -----------------------------------------------------------------
+ void
+ Url::removeQueryParam(const std::string ¶m)
+ {
+ m_impl->removeQueryParam(param);
+ }
+
+ // -----------------------------------------------------------------
ViewOptions
Url::getViewOptions() const
{
diff --git a/zypp/Url.h b/zypp/Url.h
index e56bb17..a276e40 100644
--- a/zypp/Url.h
+++ b/zypp/Url.h
@@ -755,6 +755,16 @@ namespace zypp
void
setQueryParam(const std::string ¶m, const std::string &value);
+ /**
+ * \brief Delete the specified query parameter.
+ * \param param The decoded query parameter name.
+ * \throws url::UrlNotSupportedException if parameter parsing
+ * is not supported for a URL (scheme).
+ * \throws url::UrlDecodingException if the decoded result string
+ * would contain a '\\0' character.
+ */
+ void
+ removeQueryParam(const std::string ¶m);
// -----------------
/**
diff --git a/zypp/media/MediaCurl.cc b/zypp/media/MediaCurl.cc
index 086bdf1..f7cce4e 100644
--- a/zypp/media/MediaCurl.cc
+++ b/zypp/media/MediaCurl.cc
@@ -285,12 +285,17 @@ void fillSettingsFromUrl( const Url &url,
TransferSettings &s )
string proxy = url.getQueryParam( "proxy" );
if ( ! proxy.empty() )
{
- string proxyport( url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- proxy += ":" + proxyport;
+ if ( proxy == "_none_" ) {
+ s.setProxyEnabled(false);
}
- s.setProxy(proxy);
- s.setProxyEnabled(true);
+ else {
+ string proxyport( url.getQueryParam( "proxyport" ) );
+ if ( ! proxyport.empty() ) {
+ proxy += ":" + proxyport;
+ }
+ s.setProxy(proxy);
+ s.setProxyEnabled(true);
+ }
}
// HTTP authentication type
@@ -600,7 +605,11 @@ void MediaCurl::setupEasy()
SET_OPTION(CURLOPT_PROXYUSERPWD, proxyuserpwd.c_str());
}
}
-
+ else
+ {
+ SET_OPTION(CURLOPT_NOPROXY, "*");
+ }
+
/** Speed limits */
if ( _settings.minDownloadSpeed() != 0 )
{
diff --git a/zypp/parser/RepoFileReader.cc b/zypp/parser/RepoFileReader.cc
index 9196baf..11bcf89 100644
--- a/zypp/parser/RepoFileReader.cc
+++ b/zypp/parser/RepoFileReader.cc
@@ -43,6 +43,7 @@ namespace zypp
{
RepoInfo info;
info.setAlias(*its);
+ Url url;
for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
it != dict.entriesEnd(*its);
@@ -56,7 +57,7 @@ namespace zypp
else if ( it->first == "priority" )
info.setPriority( str::strtonum<unsigned>( it->second ) );
else if ( it->first == "baseurl" && !it->second.empty())
- info.addBaseUrl( Url(it->second) );
+ url = it->second;
else if ( it->first == "path" )
info.setPath( Pathname(it->second) );
else if ( it->first == "type" )
@@ -73,7 +74,16 @@ namespace zypp
info.setKeepPackages( str::strToTrue( it->second ) );
else if ( it->first == "service" )
info.setService( it->second );
- else
+ else if ( it->first == "proxy" )
+ {
+ if (it->second != "_none_" )
+ {
+ int pos = it->second.find(":", 0);
+ url.setQueryParam("proxy", it->second.substr(0, pos));
+ url.setQueryParam("proxyport", it->second.substr(pos + 1));
+ } else
+ url.setQueryParam("noproxy", "yes");
+ } else
ERR << "Unknown attribute in [" << *its << "]: " << it->second <<
" ignored" << endl;
}
info.setFilepath(is.path());
diff --git a/zypp/url/UrlBase.cc b/zypp/url/UrlBase.cc
index d42a032..c8578c1 100644
--- a/zypp/url/UrlBase.cc
+++ b/zypp/url/UrlBase.cc
@@ -1246,6 +1246,14 @@ namespace zypp
setQueryStringMap(pmap);
}
+ // ---------------------------------------------------------------
+ void
+ UrlBase::removeQueryParam(const std::string ¶m)
+ {
+ zypp::url::ParamMap pmap( getQueryStringMap(zypp::url::E_DECODED));
+ pmap.erase(param);
+ setQueryStringMap(pmap);
+ }
// ---------------------------------------------------------------
std::string
diff --git a/zypp/url/UrlBase.h b/zypp/url/UrlBase.h
index 09be00b..d106024 100644
--- a/zypp/url/UrlBase.h
+++ b/zypp/url/UrlBase.h
@@ -862,6 +862,16 @@ namespace zypp
virtual void
setQueryParam(const std::string ¶m, const std::string &value);
+ /**
+ * \brief Delete the specified query parameter.
+ * \param param The decoded query parameter name.
+ * \throws url::UrlNotSupportedException if parameter parsing
+ * is not supported for a URL (scheme).
+ * \throws url::UrlDecodingException if the decoded result string
+ * would contain a '\\0' character.
+ */
+ virtual void
+ removeQueryParam(const std::string ¶m);
// -----------------
/**
curl_easy_setopt(_curl, CURLOPT_NOPROXY, "*");Thanks Zhang for the patch.
I think the right implementation would look like this, as there is no need to set the values in each protocol, there is a TransferSettings class for that,
Others, feedback?
Duncan
diff --git a/zypp/Url.cc b/zypp/Url.cc
index 7ca3c61..81e8230 100644
--- a/zypp/Url.cc
+++ b/zypp/Url.cc
@@ -814,6 +814,13 @@ namespace zypp
}
// -----------------------------------------------------------------
+ void
+ Url::removeQueryParam(const std::string ¶m)
+ {
+ m_impl->removeQueryParam(param);
+ }
+
+ // -----------------------------------------------------------------
ViewOptions
Url::getViewOptions() const
{
diff --git a/zypp/Url.h b/zypp/Url.h
index e56bb17..a276e40 100644
--- a/zypp/Url.h
+++ b/zypp/Url.h
@@ -755,6 +755,16 @@ namespace zypp
void
setQueryParam(const std::string ¶m, const std::string &value);
+ /**
+ * \brief Delete the specified query parameter.
+ * \param param The decoded query parameter name.
+ * \throws url::UrlNotSupportedException if parameter parsing
+ * is not supported for a URL (scheme).
+ * \throws url::UrlDecodingException if the decoded result string
+ * would contain a '\\0' character.
+ */
+ void
+ removeQueryParam(const std::string ¶m);
// -----------------
/**
diff --git a/zypp/media/MediaCurl.cc b/zypp/media/MediaCurl.cc
index 086bdf1..f7cce4e 100644
--- a/zypp/media/MediaCurl.cc
+++ b/zypp/media/MediaCurl.cc
@@ -285,12 +285,17 @@ void fillSettingsFromUrl( const Url &url,
TransferSettings &s )
string proxy = url.getQueryParam( "proxy" );
if ( ! proxy.empty() )
{
- string proxyport( url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- proxy += ":" + proxyport;
+ if ( proxy == "_none_" ) {
+ s.setProxyEnabled(false);
}
- s.setProxy(proxy);
- s.setProxyEnabled(true);
+ else {
+ string proxyport( url.getQueryParam( "proxyport" ) );
+ if ( ! proxyport.empty() ) {
+ proxy += ":" + proxyport;
+ }
+ s.setProxy(proxy);
+ s.setProxyEnabled(true);
+ }
}
// HTTP authentication type
@@ -600,7 +605,11 @@ void MediaCurl::setupEasy()
SET_OPTION(CURLOPT_PROXYUSERPWD, proxyuserpwd.c_str());
}
}
-
+ else
+ {
+ SET_OPTION(CURLOPT_NOPROXY, "*");
+ }
+
/** Speed limits */
if ( _settings.minDownloadSpeed() != 0 )
{
diff --git a/zypp/parser/RepoFileReader.cc b/zypp/parser/RepoFileReader.cc
index 9196baf..11bcf89 100644
--- a/zypp/parser/RepoFileReader.cc
+++ b/zypp/parser/RepoFileReader.cc
@@ -43,6 +43,7 @@ namespace zypp
{
RepoInfo info;
info.setAlias(*its);
+ Url url;
for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
it != dict.entriesEnd(*its);
@@ -56,7 +57,7 @@ namespace zypp
else if ( it->first == "priority" )
info.setPriority( str::strtonum<unsigned>( it->second ) );
else if ( it->first == "baseurl" && !it->second.empty())
- info.addBaseUrl( Url(it->second) );
+ url = it->second;
else if ( it->first == "path" )
info.setPath( Pathname(it->second) );
else if ( it->first == "type" )
@@ -73,7 +74,16 @@ namespace zypp
info.setKeepPackages( str::strToTrue( it->second ) );
else if ( it->first == "service" )
info.setService( it->second );
- else
+ else if ( it->first == "proxy" )
+ {
+ if (it->second != "_none_" )
+ {
+ int pos = it->second.find(":", 0);
+ url.setQueryParam("proxy", it->second.substr(0, pos));
+ url.setQueryParam("proxyport", it->second.substr(pos + 1));
+ } else
+ url.setQueryParam("noproxy", "yes");
+ } else
ERR << "Unknown attribute in [" << *its << "]: " << it->second <<
" ignored" << endl;
}
info.setFilepath(is.path());
diff --git a/zypp/url/UrlBase.cc b/zypp/url/UrlBase.cc
index d42a032..c8578c1 100644
--- a/zypp/url/UrlBase.cc
+++ b/zypp/url/UrlBase.cc
@@ -1246,6 +1246,14 @@ namespace zypp
setQueryStringMap(pmap);
}
+ // ---------------------------------------------------------------
+ void
+ UrlBase::removeQueryParam(const std::string ¶m)
+ {
+ zypp::url::ParamMap pmap( getQueryStringMap(zypp::url::E_DECODED));
+ pmap.erase(param);
+ setQueryStringMap(pmap);
+ }
// ---------------------------------------------------------------
std::string
diff --git a/zypp/url/UrlBase.h b/zypp/url/UrlBase.h
index 09be00b..d106024 100644
--- a/zypp/url/UrlBase.h
+++ b/zypp/url/UrlBase.h
@@ -862,6 +862,16 @@ namespace zypp
virtual void
setQueryParam(const std::string ¶m, const std::string &value);
+ /**
+ * \brief Delete the specified query parameter.
+ * \param param The decoded query parameter name.
+ * \throws url::UrlNotSupportedException if parameter parsing
+ * is not supported for a URL (scheme).
+ * \throws url::UrlDecodingException if the decoded result string
+ * would contain a '\\0' character.
+ */
+ virtual void
+ removeQueryParam(const std::string ¶m);
// -----------------
/**
| < Previous | Next > |