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;
79 Pathname _client_key_path;
82 bool _head_requests_allowed;
85 TransferSettings::TransferSettings()
86 : _impl(new TransferSettings::Impl())
91 void TransferSettings::reset()
93 _impl.reset(new TransferSettings::Impl());
96 void TransferSettings::addHeader( const std::string &header )
98 if ( ! header.empty() )
99 _impl->_headers.push_back(header);
102 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
104 return _impl->_headers.begin();
107 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
109 return _impl->_headers.end();
112 void TransferSettings::setUserAgentString( const std::string &agent )
114 _impl->_useragent = agent;
117 std::string TransferSettings::userAgentString() const
119 return _impl->_useragent;
122 void TransferSettings::setUsername( const std::string &username )
124 _impl->_username = username;
127 std::string TransferSettings::username() const
129 return _impl->_username;
132 void TransferSettings::setPassword( const std::string &password )
134 _impl->_password = password;
137 void TransferSettings::setAnonymousAuth()
139 setUsername("anonymous");
141 setPassword(id + VERSION);
144 std::string TransferSettings::password() const
146 return _impl->_password;
149 std::string TransferSettings::userPassword() const
151 string userpwd = username();
152 if ( password().size() ) {
153 userpwd += ":" + password();
158 void TransferSettings::setProxyEnabled( bool enabled )
160 _impl->_useproxy = enabled;
163 bool TransferSettings::proxyEnabled() const
165 return _impl->_useproxy;
168 void TransferSettings::setProxy( const std::string &proxy )
170 _impl->_proxy = proxy;
173 std::string TransferSettings::proxy() const
175 return _impl->_proxy;
178 void TransferSettings::setProxyUsername( const std::string &proxyuser )
180 _impl->_proxy_username = proxyuser;
183 std::string TransferSettings::proxyUsername() const
185 return _impl->_proxy_username;
188 void TransferSettings::setProxyPassword( const std::string &proxypass )
190 _impl->_proxy_password = proxypass;
193 std::string TransferSettings::proxyPassword() const
195 return _impl->_proxy_password;
198 std::string TransferSettings::proxyUserPassword() const
200 string userpwd = proxyUsername();
201 if ( proxyPassword().size() ) {
202 userpwd += ":" + proxyPassword();
207 void TransferSettings::setTimeout( long t )
212 long TransferSettings::timeout() const
214 return _impl->_timeout;
217 void TransferSettings::setConnectTimeout( long t )
219 _impl->_connect_timeout = t;
222 long TransferSettings::connectTimeout() const
224 return _impl->_connect_timeout;
227 long TransferSettings::maxConcurrentConnections() const
229 return _impl->_maxConcurrentConnections;
232 void TransferSettings::setMaxConcurrentConnections(long v)
234 _impl->_maxConcurrentConnections = v;
237 long TransferSettings::minDownloadSpeed() const
239 return _impl->_minDownloadSpeed;
242 void TransferSettings::setMinDownloadSpeed(long v)
244 _impl->_minDownloadSpeed = v;
247 long TransferSettings::maxDownloadSpeed() const
249 return _impl->_maxDownloadSpeed;
252 void TransferSettings::setMaxDownloadSpeed(long v)
254 _impl->_maxDownloadSpeed = v;
257 long TransferSettings::maxSilentTries() const
259 return _impl->_maxSilentTries;
262 void TransferSettings::setMaxSilentTries(long v)
264 _impl->_maxSilentTries = v;
267 bool TransferSettings::verifyHostEnabled() const
269 return _impl->_verify_host;
272 void TransferSettings::setVerifyHostEnabled( bool enabled )
274 _impl->_verify_host = enabled;
277 bool TransferSettings::verifyPeerEnabled() const
279 return _impl->_verify_peer;
282 Pathname TransferSettings::clientCertificatePath() const
284 return _impl->_client_cert_path;
287 void TransferSettings::setClientCertificatePath( const zypp::Pathname &path )
289 _impl->_client_cert_path = path;
292 Pathname TransferSettings::clientKeyPath() const
294 return _impl->_client_key_path;
297 void TransferSettings::setClientKeyPath( const zypp::Pathname &path )
299 _impl->_client_key_path = path;
303 void TransferSettings::setVerifyPeerEnabled( bool enabled )
305 _impl->_verify_peer = enabled;
308 Pathname TransferSettings::certificateAuthoritiesPath() const
310 return _impl->_ca_path;
313 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
315 _impl->_ca_path = path;
318 void TransferSettings::setAuthType( const std::string &authtype)
320 _impl->_authtype = authtype;
323 std::string TransferSettings::authType() const
325 return _impl->_authtype;
328 void TransferSettings::setHeadRequestsAllowed(bool allowed)
330 _impl->_head_requests_allowed = allowed;
333 bool TransferSettings::headRequestsAllowed() const
335 return _impl->_head_requests_allowed;