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 _impl->_headers.push_back(header);
101 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
103 return _impl->_headers.begin();
106 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
108 return _impl->_headers.end();
111 void TransferSettings::setUserAgentString( const std::string &agent )
113 _impl->_useragent = agent;
116 std::string TransferSettings::userAgentString() const
118 return _impl->_useragent;
121 void TransferSettings::setUsername( const std::string &username )
123 _impl->_username = username;
126 std::string TransferSettings::username() const
128 return _impl->_username;
131 void TransferSettings::setPassword( const std::string &password )
133 _impl->_password = password;
136 void TransferSettings::setAnonymousAuth()
138 setUsername("anonymous");
140 setPassword(id + VERSION);
143 std::string TransferSettings::password() const
145 return _impl->_password;
148 std::string TransferSettings::userPassword() const
150 string userpwd = username();
151 if ( password().size() ) {
152 userpwd += ":" + password();
157 void TransferSettings::setProxyEnabled( bool enabled )
159 _impl->_useproxy = enabled;
162 bool TransferSettings::proxyEnabled() const
164 return _impl->_useproxy;
167 void TransferSettings::setProxy( const std::string &proxy )
169 _impl->_proxy = proxy;
172 std::string TransferSettings::proxy() const
174 return _impl->_proxy;
177 void TransferSettings::setProxyUsername( const std::string &proxyuser )
179 _impl->_proxy_username = proxyuser;
182 std::string TransferSettings::proxyUsername() const
184 return _impl->_proxy_username;
187 void TransferSettings::setProxyPassword( const std::string &proxypass )
189 _impl->_proxy_password = proxypass;
192 std::string TransferSettings::proxyPassword() const
194 return _impl->_proxy_password;
197 std::string TransferSettings::proxyUserPassword() const
199 string userpwd = proxyUsername();
200 if ( proxyPassword().size() ) {
201 userpwd += ":" + proxyPassword();
206 void TransferSettings::setTimeout( long t )
211 long TransferSettings::timeout() const
213 return _impl->_timeout;
216 void TransferSettings::setConnectTimeout( long t )
218 _impl->_connect_timeout = t;
221 long TransferSettings::connectTimeout() const
223 return _impl->_connect_timeout;
226 long TransferSettings::maxConcurrentConnections() const
228 return _impl->_maxConcurrentConnections;
231 void TransferSettings::setMaxConcurrentConnections(long v)
233 _impl->_maxConcurrentConnections = v;
236 long TransferSettings::minDownloadSpeed() const
238 return _impl->_minDownloadSpeed;
241 void TransferSettings::setMinDownloadSpeed(long v)
243 _impl->_minDownloadSpeed = v;
246 long TransferSettings::maxDownloadSpeed() const
248 return _impl->_maxDownloadSpeed;
251 void TransferSettings::setMaxDownloadSpeed(long v)
253 _impl->_maxDownloadSpeed = v;
256 long TransferSettings::maxSilentTries() const
258 return _impl->_maxSilentTries;
261 void TransferSettings::setMaxSilentTries(long v)
263 _impl->_maxSilentTries = v;
266 bool TransferSettings::verifyHostEnabled() const
268 return _impl->_verify_host;
271 void TransferSettings::setVerifyHostEnabled( bool enabled )
273 _impl->_verify_host = enabled;
276 bool TransferSettings::verifyPeerEnabled() const
278 return _impl->_verify_peer;
281 Pathname TransferSettings::clientCertificatePath() const
283 return _impl->_client_cert_path;
286 void TransferSettings::setClientCertificatePath( const zypp::Pathname &path )
288 _impl->_client_cert_path = path;
291 Pathname TransferSettings::clientKeyPath() const
293 return _impl->_client_key_path;
296 void TransferSettings::setClientKeyPath( const zypp::Pathname &path )
298 _impl->_client_key_path = path;
302 void TransferSettings::setVerifyPeerEnabled( bool enabled )
304 _impl->_verify_peer = enabled;
307 Pathname TransferSettings::certificateAuthoritiesPath() const
309 return _impl->_ca_path;
312 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
314 _impl->_ca_path = path;
317 void TransferSettings::setAuthType( const std::string &authtype)
319 _impl->_authtype = authtype;
322 std::string TransferSettings::authType() const
324 return _impl->_authtype;
327 void TransferSettings::setHeadRequestsAllowed(bool allowed)
329 _impl->_head_requests_allowed = allowed;
332 bool TransferSettings::headRequestsAllowed() const
334 return _impl->_head_requests_allowed;