TransferSettings.cc
Go to the documentation of this file.00001 #include <iostream>
00002 #include <sstream>
00003
00004 #include "zypp/base/String.h"
00005 #include "zypp/base/Logger.h"
00006 #include "zypp/base/WatchFile.h"
00007 #include "zypp/base/ReferenceCounted.h"
00008 #include "zypp/base/NonCopyable.h"
00009 #include "zypp/ExternalProgram.h"
00010 #include "zypp/media/TransferSettings.h"
00011 #include "zypp/ZConfig.h"
00012
00013 using namespace std;
00014
00015 #define ARIA2C_BINARY "/usr/bin/aria2c"
00016 #define CURL_BINARY "/usr/bin/curl"
00017
00018 namespace zypp
00019 {
00020 namespace media
00021 {
00022
00023 class TransferSettings::Impl
00024 {
00025 public:
00026 Impl()
00027 : _useproxy(false)
00028 , _timeout(0)
00029 , _connect_timeout(0)
00030 , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
00031 , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
00032 , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
00033 , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
00034 , _verify_host(false)
00035 , _verify_peer(false)
00036 , _ca_path("/etc/ssl/certs")
00037 , _head_requests_allowed(true)
00038 {}
00039
00040 virtual ~Impl()
00041 {}
00042
00044 static shared_ptr<Impl> nullimpl()
00045 {
00046 static shared_ptr<Impl> _nullimpl( new Impl );
00047 return _nullimpl;
00048 }
00049
00050 private:
00051 friend Impl * rwcowClone<Impl>( const Impl * rhs );
00053 Impl * clone() const
00054 { return new Impl( *this ); }
00055
00056 public:
00057 vector<string> _headers;
00058 string _useragent;
00059 string _username;
00060 string _password;
00061 bool _useproxy;
00062 string _proxy;
00063 string _proxy_username;
00064 string _proxy_password;
00065 string _authtype;
00066 long _timeout;
00067 long _connect_timeout;
00068 Url _url;
00069 Pathname _targetdir;
00070
00071 long _maxConcurrentConnections;
00072 long _minDownloadSpeed;
00073 long _maxDownloadSpeed;
00074 long _maxSilentTries;
00075
00076 bool _verify_host;
00077 bool _verify_peer;
00078 Pathname _ca_path;
00079
00080
00081 bool _head_requests_allowed;
00082 };
00083
00084 TransferSettings::TransferSettings()
00085 : _impl(new TransferSettings::Impl())
00086 {
00087
00088 }
00089
00090 void TransferSettings::reset()
00091 {
00092 _impl.reset(new TransferSettings::Impl());
00093 }
00094
00095 void TransferSettings::addHeader( const std::string &header )
00096 {
00097 _impl->_headers.push_back(header);
00098 }
00099
00100 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
00101 {
00102 return _impl->_headers.begin();
00103 }
00104
00105 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
00106 {
00107 return _impl->_headers.end();
00108 }
00109
00110 void TransferSettings::setUserAgentString( const std::string &agent )
00111 {
00112 _impl->_useragent = agent;
00113 }
00114
00115 std::string TransferSettings::userAgentString() const
00116 {
00117 return _impl->_useragent;
00118 }
00119
00120 void TransferSettings::setUsername( const std::string &username )
00121 {
00122 _impl->_username = username;
00123 }
00124
00125 std::string TransferSettings::username() const
00126 {
00127 return _impl->_username;
00128 }
00129
00130 void TransferSettings::setPassword( const std::string &password )
00131 {
00132 _impl->_password = password;
00133 }
00134
00135 void TransferSettings::setAnonymousAuth()
00136 {
00137 setUsername("anonymous");
00138 string id = "yast@";
00139 setPassword(id + VERSION);
00140 }
00141
00142 std::string TransferSettings::password() const
00143 {
00144 return _impl->_password;
00145 }
00146
00147 std::string TransferSettings::userPassword() const
00148 {
00149 string userpwd = username();
00150 if ( password().size() ) {
00151 userpwd += ":" + password();
00152 }
00153 return userpwd;
00154 }
00155
00156 void TransferSettings::setProxyEnabled( bool enabled )
00157 {
00158 _impl->_useproxy = enabled;
00159 }
00160
00161 bool TransferSettings::proxyEnabled() const
00162 {
00163 return _impl->_useproxy;
00164 }
00165
00166 void TransferSettings::setProxy( const std::string &proxy )
00167 {
00168 _impl->_proxy = proxy;
00169 }
00170
00171 std::string TransferSettings::proxy() const
00172 {
00173 return _impl->_proxy;
00174 }
00175
00176 void TransferSettings::setProxyUsername( const std::string &proxyuser )
00177 {
00178 _impl->_proxy_username = proxyuser;
00179 }
00180
00181 std::string TransferSettings::proxyUsername() const
00182 {
00183 return _impl->_proxy_username;
00184 }
00185
00186 void TransferSettings::setProxyPassword( const std::string &proxypass )
00187 {
00188 _impl->_proxy_password = proxypass;
00189 }
00190
00191 std::string TransferSettings::proxyPassword() const
00192 {
00193 return _impl->_proxy_password;
00194 }
00195
00196 std::string TransferSettings::proxyUserPassword() const
00197 {
00198 string userpwd = proxyUsername();
00199 if ( proxyPassword().size() ) {
00200 userpwd += ":" + proxyPassword();
00201 }
00202 return userpwd;
00203 }
00204
00205 void TransferSettings::setTimeout( long t )
00206 {
00207 _impl->_timeout = t;
00208 }
00209
00210 long TransferSettings::timeout() const
00211 {
00212 return _impl->_timeout;
00213 }
00214
00215 void TransferSettings::setConnectTimeout( long t )
00216 {
00217 _impl->_connect_timeout = t;
00218 }
00219
00220 long TransferSettings::connectTimeout() const
00221 {
00222 return _impl->_connect_timeout;
00223 }
00224
00225 long TransferSettings::maxConcurrentConnections() const
00226 {
00227 return _impl->_maxConcurrentConnections;
00228 }
00229
00230 void TransferSettings::setMaxConcurrentConnections(long v)
00231 {
00232 _impl->_maxConcurrentConnections = v;
00233 }
00234
00235 long TransferSettings::minDownloadSpeed() const
00236 {
00237 return _impl->_minDownloadSpeed;
00238 }
00239
00240 void TransferSettings::setMinDownloadSpeed(long v)
00241 {
00242 _impl->_minDownloadSpeed = v;
00243 }
00244
00245 long TransferSettings::maxDownloadSpeed() const
00246 {
00247 return _impl->_maxDownloadSpeed;
00248 }
00249
00250 void TransferSettings::setMaxDownloadSpeed(long v)
00251 {
00252 _impl->_maxDownloadSpeed = v;
00253 }
00254
00255 long TransferSettings::maxSilentTries() const
00256 {
00257 return _impl->_maxSilentTries;
00258 }
00259
00260 void TransferSettings::setMaxSilentTries(long v)
00261 {
00262 _impl->_maxSilentTries = v;
00263 }
00264
00265 bool TransferSettings::verifyHostEnabled() const
00266 {
00267 return _impl->_verify_host;
00268 }
00269
00270 void TransferSettings::setVerifyHostEnabled( bool enabled )
00271 {
00272 _impl->_verify_host = enabled;
00273 }
00274
00275 bool TransferSettings::verifyPeerEnabled() const
00276 {
00277 return _impl->_verify_peer;
00278 }
00279
00280
00281 void TransferSettings::setVerifyPeerEnabled( bool enabled )
00282 {
00283 _impl->_verify_peer = enabled;
00284 }
00285
00286 Pathname TransferSettings::certificateAuthoritiesPath() const
00287 {
00288 return _impl->_ca_path;
00289 }
00290
00291 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
00292 {
00293 _impl->_ca_path = path;
00294 }
00295
00296 void TransferSettings::setAuthType( const std::string &authtype)
00297 {
00298 _impl->_authtype = authtype;
00299 }
00300
00301 std::string TransferSettings::authType() const
00302 {
00303 return _impl->_authtype;
00304 }
00305
00306 void TransferSettings::setHeadRequestsAllowed(bool allowed)
00307 {
00308 _impl->_head_requests_allowed = allowed;
00309 }
00310
00311 bool TransferSettings::headRequestsAllowed() const
00312 {
00313 return _impl->_head_requests_allowed;
00314 }
00315
00316 }
00317 }
00318