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 {} 00038 00039 virtual ~Impl() 00040 {} 00041 00043 static shared_ptr<Impl> nullimpl() 00044 { 00045 static shared_ptr<Impl> _nullimpl( new Impl ); 00046 return _nullimpl; 00047 } 00048 00049 private: 00050 friend Impl * rwcowClone<Impl>( const Impl * rhs ); 00052 Impl * clone() const 00053 { return new Impl( *this ); } 00054 00055 public: 00056 vector<string> _headers; 00057 string _useragent; 00058 string _username; 00059 string _password; 00060 bool _useproxy; 00061 string _proxy; 00062 string _proxy_username; 00063 string _proxy_password; 00064 long _timeout; 00065 long _connect_timeout; 00066 Url _url; 00067 Pathname _targetdir; 00068 00069 long _maxConcurrentConnections; 00070 long _minDownloadSpeed; 00071 long _maxDownloadSpeed; 00072 long _maxSilentTries; 00073 00074 bool _verify_host; 00075 bool _verify_peer; 00076 Pathname _ca_path; 00077 }; 00078 00079 TransferSettings::TransferSettings() 00080 : _impl(new TransferSettings::Impl()) 00081 { 00082 00083 } 00084 00085 void TransferSettings::reset() 00086 { 00087 _impl.reset(new TransferSettings::Impl()); 00088 } 00089 00090 void TransferSettings::addHeader( const std::string &header ) 00091 { 00092 _impl->_headers.push_back(header); 00093 } 00094 00095 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const 00096 { 00097 return _impl->_headers.begin(); 00098 } 00099 00100 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const 00101 { 00102 return _impl->_headers.end(); 00103 } 00104 00105 void TransferSettings::setUserAgentString( const std::string &agent ) 00106 { 00107 _impl->_useragent = agent; 00108 } 00109 00110 std::string TransferSettings::userAgentString() const 00111 { 00112 return _impl->_useragent; 00113 } 00114 00115 void TransferSettings::setUsername( const std::string &username ) 00116 { 00117 _impl->_username = username; 00118 } 00119 00120 std::string TransferSettings::username() const 00121 { 00122 return _impl->_username; 00123 } 00124 00125 void TransferSettings::setPassword( const std::string &password ) 00126 { 00127 _impl->_password = password; 00128 } 00129 00130 void TransferSettings::setAnonymousAuth() 00131 { 00132 setUsername("anonymous"); 00133 string id = "yast@"; 00134 setPassword(id + VERSION); 00135 } 00136 00137 std::string TransferSettings::password() const 00138 { 00139 return _impl->_password; 00140 } 00141 00142 std::string TransferSettings::userPassword() const 00143 { 00144 string userpwd = username(); 00145 if ( password().size() ) { 00146 userpwd += ":" + password(); 00147 } 00148 return userpwd; 00149 } 00150 00151 void TransferSettings::setProxyEnabled( bool enabled ) 00152 { 00153 _impl->_useproxy = enabled; 00154 } 00155 00156 bool TransferSettings::proxyEnabled() const 00157 { 00158 return _impl->_useproxy; 00159 } 00160 00161 void TransferSettings::setProxy( const std::string &proxy ) 00162 { 00163 _impl->_proxy = proxy; 00164 } 00165 00166 std::string TransferSettings::proxy() const 00167 { 00168 return _impl->_proxy; 00169 } 00170 00171 void TransferSettings::setProxyUsername( const std::string &proxyuser ) 00172 { 00173 _impl->_proxy_username = proxyuser; 00174 } 00175 00176 std::string TransferSettings::proxyUsername() const 00177 { 00178 return _impl->_proxy_username; 00179 } 00180 00181 void TransferSettings::setProxyPassword( const std::string &proxypass ) 00182 { 00183 _impl->_proxy_password = proxypass; 00184 } 00185 00186 std::string TransferSettings::proxyPassword() const 00187 { 00188 return _impl->_proxy_password; 00189 } 00190 00191 std::string TransferSettings::proxyUserPassword() const 00192 { 00193 string userpwd = proxyUsername(); 00194 if ( proxyPassword().size() ) { 00195 userpwd += ":" + proxyPassword(); 00196 } 00197 return userpwd; 00198 } 00199 00200 void TransferSettings::setTimeout( long t ) 00201 { 00202 _impl->_timeout = t; 00203 } 00204 00205 long TransferSettings::timeout() const 00206 { 00207 return _impl->_timeout; 00208 } 00209 00210 void TransferSettings::setConnectTimeout( long t ) 00211 { 00212 _impl->_connect_timeout = t; 00213 } 00214 00215 long TransferSettings::connectTimeout() const 00216 { 00217 return _impl->_connect_timeout; 00218 } 00219 00220 long TransferSettings::maxConcurrentConnections() const 00221 { 00222 return _impl->_maxConcurrentConnections; 00223 } 00224 00225 void TransferSettings::setMaxConcurrentConnections(long v) 00226 { 00227 _impl->_maxConcurrentConnections = v; 00228 } 00229 00230 long TransferSettings::minDownloadSpeed() const 00231 { 00232 return _impl->_minDownloadSpeed; 00233 } 00234 00235 void TransferSettings::setMinDownloadSpeed(long v) 00236 { 00237 _impl->_minDownloadSpeed = v; 00238 } 00239 00240 long TransferSettings::maxDownloadSpeed() const 00241 { 00242 return _impl->_maxDownloadSpeed; 00243 } 00244 00245 void TransferSettings::setMaxDownloadSpeed(long v) 00246 { 00247 _impl->_maxDownloadSpeed = v; 00248 } 00249 00250 long TransferSettings::maxSilentTries() const 00251 { 00252 return _impl->_maxSilentTries; 00253 } 00254 00255 void TransferSettings::setMaxSilentTries(long v) 00256 { 00257 _impl->_maxSilentTries = v; 00258 } 00259 00260 bool TransferSettings::verifyHostEnabled() const 00261 { 00262 return _impl->_verify_host; 00263 } 00264 00265 void TransferSettings::setVerifyHostEnabled( bool enabled ) 00266 { 00267 _impl->_verify_host = enabled; 00268 } 00269 00270 bool TransferSettings::verifyPeerEnabled() const 00271 { 00272 return _impl->_verify_peer; 00273 } 00274 00275 00276 void TransferSettings::setVerifyPeerEnabled( bool enabled ) 00277 { 00278 _impl->_verify_peer = enabled; 00279 } 00280 00281 Pathname TransferSettings::certificateAuthoritiesPath() const 00282 { 00283 return _impl->_ca_path; 00284 } 00285 00286 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path ) 00287 { 00288 _impl->_ca_path = path; 00289 } 00290 00291 00292 } // ns media 00293 } // ns zypp 00294