libzypp 9.41.1

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     Pathname _client_cert_path;
00080     Pathname _client_key_path;
00081 
00082     // workarounds
00083     bool _head_requests_allowed;
00084 };
00085     
00086 TransferSettings::TransferSettings()
00087     : _impl(new TransferSettings::Impl())
00088 {
00089 
00090 }
00091 
00092 void TransferSettings::reset()
00093 {
00094     _impl.reset(new TransferSettings::Impl());
00095 }
00096 
00097 void TransferSettings::addHeader( const std::string &header )
00098 {
00099     _impl->_headers.push_back(header);
00100 }
00101 
00102 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
00103 {
00104     return _impl->_headers.begin();
00105 }
00106 
00107 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
00108 {
00109     return _impl->_headers.end();
00110 }
00111 
00112 void TransferSettings::setUserAgentString( const std::string &agent )
00113 {
00114     _impl->_useragent = agent;
00115 }
00116 
00117 std::string TransferSettings::userAgentString() const
00118 {
00119     return _impl->_useragent;
00120 }
00121 
00122 void TransferSettings::setUsername( const std::string &username )
00123 {
00124     _impl->_username = username;
00125 }
00126 
00127 std::string TransferSettings::username() const
00128 {
00129     return _impl->_username;
00130 }
00131 
00132 void TransferSettings::setPassword( const std::string &password )
00133 {
00134     _impl->_password = password;
00135 }
00136 
00137 void TransferSettings::setAnonymousAuth()
00138 {
00139     setUsername("anonymous");
00140     string id = "yast@";
00141     setPassword(id + VERSION);
00142 }
00143 
00144 std::string TransferSettings::password() const
00145 {
00146     return _impl->_password;
00147 }
00148 
00149 std::string TransferSettings::userPassword() const
00150 {
00151     string userpwd = username();
00152     if ( password().size() ) {
00153         userpwd += ":" + password();
00154     }
00155     return userpwd;
00156 }
00157 
00158 void TransferSettings::setProxyEnabled( bool enabled )
00159 {
00160     _impl->_useproxy = enabled;
00161 }
00162 
00163 bool TransferSettings::proxyEnabled() const
00164 {
00165     return _impl->_useproxy;
00166 }
00167 
00168 void TransferSettings::setProxy( const std::string &proxy )
00169 {
00170     _impl->_proxy = proxy;
00171 }
00172 
00173 std::string TransferSettings::proxy() const
00174 {
00175     return _impl->_proxy;
00176 }
00177 
00178 void TransferSettings::setProxyUsername( const std::string &proxyuser )
00179 {
00180     _impl->_proxy_username = proxyuser;
00181 }
00182 
00183 std::string TransferSettings::proxyUsername() const
00184 {
00185     return _impl->_proxy_username;
00186 }
00187 
00188 void TransferSettings::setProxyPassword( const std::string &proxypass )
00189 {
00190     _impl->_proxy_password = proxypass;
00191 }
00192 
00193 std::string TransferSettings::proxyPassword() const
00194 {
00195     return _impl->_proxy_password;
00196 }
00197 
00198 std::string TransferSettings::proxyUserPassword() const
00199 {
00200     string userpwd = proxyUsername();
00201     if ( proxyPassword().size() ) {
00202         userpwd += ":" + proxyPassword();
00203     }
00204     return userpwd;
00205 }
00206 
00207 void TransferSettings::setTimeout( long t )
00208 {
00209     _impl->_timeout = t;
00210 }
00211 
00212 long TransferSettings::timeout() const
00213 {
00214     return _impl->_timeout;
00215 }
00216 
00217 void TransferSettings::setConnectTimeout( long t )
00218 {
00219     _impl->_connect_timeout = t;
00220 }
00221 
00222 long TransferSettings::connectTimeout() const
00223 {
00224     return _impl->_connect_timeout;
00225 }
00226 
00227 long TransferSettings::maxConcurrentConnections() const
00228 {
00229     return _impl->_maxConcurrentConnections;
00230 }
00231 
00232 void TransferSettings::setMaxConcurrentConnections(long v)
00233 {
00234     _impl->_maxConcurrentConnections = v;
00235 }
00236 
00237 long TransferSettings::minDownloadSpeed() const
00238 {
00239     return _impl->_minDownloadSpeed;
00240 }
00241 
00242 void TransferSettings::setMinDownloadSpeed(long v)
00243 {
00244     _impl->_minDownloadSpeed = v;
00245 }
00246 
00247 long TransferSettings::maxDownloadSpeed() const
00248 {
00249     return _impl->_maxDownloadSpeed;
00250 }
00251 
00252 void TransferSettings::setMaxDownloadSpeed(long v)
00253 {
00254     _impl->_maxDownloadSpeed = v;
00255 }
00256 
00257 long TransferSettings::maxSilentTries() const
00258 {
00259     return _impl->_maxSilentTries;
00260 }
00261 
00262 void TransferSettings::setMaxSilentTries(long v)
00263 {
00264     _impl->_maxSilentTries = v;
00265 }
00266 
00267 bool TransferSettings::verifyHostEnabled() const
00268 {
00269     return _impl->_verify_host;
00270 }
00271 
00272 void TransferSettings::setVerifyHostEnabled( bool enabled )
00273 {
00274     _impl->_verify_host = enabled;
00275 }
00276 
00277 bool TransferSettings::verifyPeerEnabled() const
00278 {
00279     return _impl->_verify_peer;
00280 }
00281 
00282 Pathname TransferSettings::clientCertificatePath() const
00283 {
00284     return _impl->_client_cert_path;
00285 }
00286 
00287 void TransferSettings::setClientCertificatePath( const zypp::Pathname &path )
00288 {
00289     _impl->_client_cert_path = path;
00290 }
00291 
00292 Pathname TransferSettings::clientKeyPath() const
00293 {
00294     return _impl->_client_key_path;
00295 }
00296 
00297 void TransferSettings::setClientKeyPath( const zypp::Pathname &path )
00298 {
00299     _impl->_client_key_path = path;
00300 }
00301 
00302 
00303 void TransferSettings::setVerifyPeerEnabled( bool enabled )
00304 {
00305     _impl->_verify_peer = enabled;
00306 }
00307 
00308 Pathname TransferSettings::certificateAuthoritiesPath() const
00309 {
00310     return _impl->_ca_path;
00311 }
00312 
00313 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
00314 {
00315     _impl->_ca_path = path;
00316 }
00317 
00318 void TransferSettings::setAuthType( const std::string &authtype)
00319 {
00320     _impl->_authtype = authtype;
00321 }
00322 
00323 std::string TransferSettings::authType() const
00324 {
00325     return _impl->_authtype;
00326 }
00327 
00328 void TransferSettings::setHeadRequestsAllowed(bool allowed)
00329 {
00330     _impl->_head_requests_allowed = allowed;    
00331 }    
00332 
00333 bool TransferSettings::headRequestsAllowed() const
00334 {
00335     return _impl->_head_requests_allowed;    
00336 } 
00337 
00338 } // ns media
00339 } // ns zypp
00340