5 #include "zypp/base/String.h"
6 #include "zypp/base/Logger.h"
7 #include "zypp/base/WatchFile.h"
8 #include "zypp/base/ReferenceCounted.h"
9 #include "zypp/base/NonCopyable.h"
10 #include "zypp/ExternalProgram.h"
11 #include "zypp/media/TransferSettings.h"
12 #include "zypp/ZConfig.h"
16 #define ARIA2C_BINARY "/usr/bin/aria2c"
17 #define CURL_BINARY "/usr/bin/curl"
24 class TransferSettings::Impl
31 , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
32 , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
33 , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
34 , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
37 , _ca_path("/etc/ssl/certs")
43 /** Offer default Impl. */
44 static shared_ptr<Impl> nullimpl()
46 static shared_ptr<Impl> _nullimpl( new Impl );
51 friend Impl * rwcowClone<Impl>( const Impl * rhs );
52 /** clone for RWCOW_pointer */
54 { return new Impl( *this ); }
57 vector<string> _headers;
63 string _proxy_username;
64 string _proxy_password;
66 long _connect_timeout;
70 long _maxConcurrentConnections;
71 long _minDownloadSpeed;
72 long _maxDownloadSpeed;
80 TransferSettings::TransferSettings()
81 : _impl(new TransferSettings::Impl())
86 void TransferSettings::addHeader( const std::string &header )
88 _impl->_headers.push_back(header);
91 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
93 return _impl->_headers.begin();
96 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
98 return _impl->_headers.end();
101 void TransferSettings::setUserAgentString( const std::string &agent )
103 _impl->_useragent = agent;
106 std::string TransferSettings::userAgentString() const
108 return _impl->_useragent;
111 void TransferSettings::setUsername( const std::string &username )
113 _impl->_username = username;
116 std::string TransferSettings::username() const
118 return _impl->_username;
121 void TransferSettings::setPassword( const std::string &password )
123 _impl->_password = password;
126 void TransferSettings::setAnonymousAuth()
128 setUsername("anonymous");
130 setPassword(id + VERSION);
133 std::string TransferSettings::password() const
135 return _impl->_password;
138 std::string TransferSettings::userPassword() const
140 string userpwd = username();
141 if ( password().size() ) {
142 userpwd += ":" + password();
147 void TransferSettings::setProxyEnabled( bool enabled )
149 _impl->_useproxy = enabled;
152 bool TransferSettings::proxyEnabled() const
154 return _impl->_useproxy;
157 void TransferSettings::setProxy( const std::string &proxy )
159 _impl->_proxy = proxy;
162 std::string TransferSettings::proxy() const
164 return _impl->_proxy;
167 void TransferSettings::setProxyUsername( const std::string &proxyuser )
169 _impl->_proxy_username = proxyuser;
172 std::string TransferSettings::proxyUsername() const
174 return _impl->_proxy_username;
177 void TransferSettings::setProxyPassword( const std::string &proxypass )
179 _impl->_proxy_password = proxypass;
182 std::string TransferSettings::proxyPassword() const
184 return _impl->_proxy_password;
187 std::string TransferSettings::proxyUserPassword() const
189 string userpwd = proxyUsername();
190 if ( proxyPassword().size() ) {
191 userpwd += ":" + proxyPassword();
196 void TransferSettings::setTimeout( long t )
201 long TransferSettings::timeout() const
203 return _impl->_timeout;
206 void TransferSettings::setConnectTimeout( long t )
208 _impl->_connect_timeout = t;
211 long TransferSettings::connectTimeout() const
213 return _impl->_connect_timeout;
216 long TransferSettings::maxConcurrentConnections() const
218 return _impl->_maxConcurrentConnections;
221 void TransferSettings::setMaxConcurrentConnections(long v)
223 _impl->_maxConcurrentConnections = v;
226 long TransferSettings::minDownloadSpeed() const
228 return _impl->_minDownloadSpeed;
231 void TransferSettings::setMinDownloadSpeed(long v)
233 _impl->_minDownloadSpeed = v;
236 long TransferSettings::maxDownloadSpeed() const
238 return _impl->_maxDownloadSpeed;
241 void TransferSettings::setMaxDownloadSpeed(long v)
243 _impl->_maxDownloadSpeed = v;
246 long TransferSettings::maxSilentTries() const
248 return _impl->_maxSilentTries;
251 void TransferSettings::setMaxSilentTries(long v)
253 _impl->_maxSilentTries = v;
256 bool TransferSettings::verifyHostEnabled() const
258 return _impl->_verify_host;
261 void TransferSettings::setVerifyHostEnabled( bool enabled )
263 _impl->_verify_host = enabled;
266 bool TransferSettings::verifyPeerEnabled() const
268 return _impl->_verify_peer;
272 void TransferSettings::setVerifyPeerEnabled( bool enabled )
274 _impl->_verify_peer = enabled;
277 Pathname TransferSettings::certificateAuthoritiesPath() const
279 return _impl->_ca_path;
282 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
284 _impl->_ca_path = path;