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 ARIA2C_BINARY "/usr/bin/aria2c"
16 #define CURL_BINARY "/usr/bin/curl"
23 class TransferSettings::Impl
30 , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
31 , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
32 , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
33 , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
36 , _ca_path("/etc/ssl/certs")
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;
80 TransferSettings::TransferSettings()
81 : _impl(new TransferSettings::Impl())
86 void TransferSettings::reset()
88 _impl.reset(new TransferSettings::Impl());
91 void TransferSettings::addHeader( const std::string &header )
93 _impl->_headers.push_back(header);
96 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
98 return _impl->_headers.begin();
101 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
103 return _impl->_headers.end();
106 void TransferSettings::setUserAgentString( const std::string &agent )
108 _impl->_useragent = agent;
111 std::string TransferSettings::userAgentString() const
113 return _impl->_useragent;
116 void TransferSettings::setUsername( const std::string &username )
118 _impl->_username = username;
121 std::string TransferSettings::username() const
123 return _impl->_username;
126 void TransferSettings::setPassword( const std::string &password )
128 _impl->_password = password;
131 void TransferSettings::setAnonymousAuth()
133 setUsername("anonymous");
135 setPassword(id + VERSION);
138 std::string TransferSettings::password() const
140 return _impl->_password;
143 std::string TransferSettings::userPassword() const
145 string userpwd = username();
146 if ( password().size() ) {
147 userpwd += ":" + password();
152 void TransferSettings::setProxyEnabled( bool enabled )
154 _impl->_useproxy = enabled;
157 bool TransferSettings::proxyEnabled() const
159 return _impl->_useproxy;
162 void TransferSettings::setProxy( const std::string &proxy )
164 _impl->_proxy = proxy;
167 std::string TransferSettings::proxy() const
169 return _impl->_proxy;
172 void TransferSettings::setProxyUsername( const std::string &proxyuser )
174 _impl->_proxy_username = proxyuser;
177 std::string TransferSettings::proxyUsername() const
179 return _impl->_proxy_username;
182 void TransferSettings::setProxyPassword( const std::string &proxypass )
184 _impl->_proxy_password = proxypass;
187 std::string TransferSettings::proxyPassword() const
189 return _impl->_proxy_password;
192 std::string TransferSettings::proxyUserPassword() const
194 string userpwd = proxyUsername();
195 if ( proxyPassword().size() ) {
196 userpwd += ":" + proxyPassword();
201 void TransferSettings::setTimeout( long t )
206 long TransferSettings::timeout() const
208 return _impl->_timeout;
211 void TransferSettings::setConnectTimeout( long t )
213 _impl->_connect_timeout = t;
216 long TransferSettings::connectTimeout() const
218 return _impl->_connect_timeout;
221 long TransferSettings::maxConcurrentConnections() const
223 return _impl->_maxConcurrentConnections;
226 void TransferSettings::setMaxConcurrentConnections(long v)
228 _impl->_maxConcurrentConnections = v;
231 long TransferSettings::minDownloadSpeed() const
233 return _impl->_minDownloadSpeed;
236 void TransferSettings::setMinDownloadSpeed(long v)
238 _impl->_minDownloadSpeed = v;
241 long TransferSettings::maxDownloadSpeed() const
243 return _impl->_maxDownloadSpeed;
246 void TransferSettings::setMaxDownloadSpeed(long v)
248 _impl->_maxDownloadSpeed = v;
251 long TransferSettings::maxSilentTries() const
253 return _impl->_maxSilentTries;
256 void TransferSettings::setMaxSilentTries(long v)
258 _impl->_maxSilentTries = v;
261 bool TransferSettings::verifyHostEnabled() const
263 return _impl->_verify_host;
266 void TransferSettings::setVerifyHostEnabled( bool enabled )
268 _impl->_verify_host = enabled;
271 bool TransferSettings::verifyPeerEnabled() const
273 return _impl->_verify_peer;
277 void TransferSettings::setVerifyPeerEnabled( bool enabled )
279 _impl->_verify_peer = enabled;
282 Pathname TransferSettings::certificateAuthoritiesPath() const
284 return _impl->_ca_path;
287 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
289 _impl->_ca_path = path;
292 void TransferSettings::setAuthType( const std::string &authtype)
294 _impl->_authtype = authtype;
297 std::string TransferSettings::authType() const
299 return _impl->_authtype;