4 #include "zypp/base/String.h"
5 #include "zypp/base/Logger.h"
6 #include "zypp/base/WatchFile.h"
7 #include "zypp/base/ReferenceCounted.h"
8 #include "zypp/base/NonCopyable.h"
9 #include "zypp/ExternalProgram.h"
10 #include "zypp/media/TransferSettings.h"
11 #include "zypp/ZConfig.h"
15 #define CURL_BINARY "/usr/bin/curl"
22 class TransferSettings::Impl
29 , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
30 , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
31 , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
32 , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
35 , _ca_path("/etc/ssl/certs")
36 , _head_requests_allowed(true)
42 /** Offer default Impl. */
43 static shared_ptr<Impl> nullimpl()
45 static shared_ptr<Impl> _nullimpl( new Impl );
50 friend Impl * rwcowClone<Impl>( const Impl * rhs );
51 /** clone for RWCOW_pointer */
53 { return new Impl( *this ); }
56 vector<string> _headers;
62 string _proxy_username;
63 string _proxy_password;
66 long _connect_timeout;
70 long _maxConcurrentConnections;
71 long _minDownloadSpeed;
72 long _maxDownloadSpeed;
78 Pathname _client_cert_path;
81 bool _head_requests_allowed;
84 TransferSettings::TransferSettings()
85 : _impl(new TransferSettings::Impl())
90 void TransferSettings::reset()
92 _impl.reset(new TransferSettings::Impl());
95 void TransferSettings::addHeader( const std::string &header )
97 _impl->_headers.push_back(header);
100 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
102 return _impl->_headers.begin();
105 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
107 return _impl->_headers.end();
110 void TransferSettings::setUserAgentString( const std::string &agent )
112 _impl->_useragent = agent;
115 std::string TransferSettings::userAgentString() const
117 return _impl->_useragent;
120 void TransferSettings::setUsername( const std::string &username )
122 _impl->_username = username;
125 std::string TransferSettings::username() const
127 return _impl->_username;
130 void TransferSettings::setPassword( const std::string &password )
132 _impl->_password = password;
135 void TransferSettings::setAnonymousAuth()
137 setUsername("anonymous");
139 setPassword(id + VERSION);
142 std::string TransferSettings::password() const
144 return _impl->_password;
147 std::string TransferSettings::userPassword() const
149 string userpwd = username();
150 if ( password().size() ) {
151 userpwd += ":" + password();
156 void TransferSettings::setProxyEnabled( bool enabled )
158 _impl->_useproxy = enabled;
161 bool TransferSettings::proxyEnabled() const
163 return _impl->_useproxy;
166 void TransferSettings::setProxy( const std::string &proxy )
168 _impl->_proxy = proxy;
171 std::string TransferSettings::proxy() const
173 return _impl->_proxy;
176 void TransferSettings::setProxyUsername( const std::string &proxyuser )
178 _impl->_proxy_username = proxyuser;
181 std::string TransferSettings::proxyUsername() const
183 return _impl->_proxy_username;
186 void TransferSettings::setProxyPassword( const std::string &proxypass )
188 _impl->_proxy_password = proxypass;
191 std::string TransferSettings::proxyPassword() const
193 return _impl->_proxy_password;
196 std::string TransferSettings::proxyUserPassword() const
198 string userpwd = proxyUsername();
199 if ( proxyPassword().size() ) {
200 userpwd += ":" + proxyPassword();
205 void TransferSettings::setTimeout( long t )
210 long TransferSettings::timeout() const
212 return _impl->_timeout;
215 void TransferSettings::setConnectTimeout( long t )
217 _impl->_connect_timeout = t;
220 long TransferSettings::connectTimeout() const
222 return _impl->_connect_timeout;
225 long TransferSettings::maxConcurrentConnections() const
227 return _impl->_maxConcurrentConnections;
230 void TransferSettings::setMaxConcurrentConnections(long v)
232 _impl->_maxConcurrentConnections = v;
235 long TransferSettings::minDownloadSpeed() const
237 return _impl->_minDownloadSpeed;
240 void TransferSettings::setMinDownloadSpeed(long v)
242 _impl->_minDownloadSpeed = v;
245 long TransferSettings::maxDownloadSpeed() const
247 return _impl->_maxDownloadSpeed;
250 void TransferSettings::setMaxDownloadSpeed(long v)
252 _impl->_maxDownloadSpeed = v;
255 long TransferSettings::maxSilentTries() const
257 return _impl->_maxSilentTries;
260 void TransferSettings::setMaxSilentTries(long v)
262 _impl->_maxSilentTries = v;
265 bool TransferSettings::verifyHostEnabled() const
267 return _impl->_verify_host;
270 void TransferSettings::setVerifyHostEnabled( bool enabled )
272 _impl->_verify_host = enabled;
275 bool TransferSettings::verifyPeerEnabled() const
277 return _impl->_verify_peer;
280 Pathname TransferSettings::clientCertificatePath() const
282 return _impl->_client_cert_path;
285 void TransferSettings::setClientCertificatePath( const zypp::Pathname &path )
287 _impl->_client_cert_path = path;
291 void TransferSettings::setVerifyPeerEnabled( bool enabled )
293 _impl->_verify_peer = enabled;
296 Pathname TransferSettings::certificateAuthoritiesPath() const
298 return _impl->_ca_path;
301 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
303 _impl->_ca_path = path;
306 void TransferSettings::setAuthType( const std::string &authtype)
308 _impl->_authtype = authtype;
311 std::string TransferSettings::authType() const
313 return _impl->_authtype;
316 void TransferSettings::setHeadRequestsAllowed(bool allowed)
318 _impl->_head_requests_allowed = allowed;
321 bool TransferSettings::headRequestsAllowed() const
323 return _impl->_head_requests_allowed;