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 CURL_BINARY "/usr/bin/curl"
22 class TransferSettings::Impl
29 , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
30 , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
31 , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
32 , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
35 , _ca_path("/etc/ssl/certs")
36 , _head_requests_allowed(true)
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;
78 Pathname _client_cert_path;
79 Pathname _client_key_path;
82 bool _head_requests_allowed;
85 TransferSettings::TransferSettings()
86 : _impl(new TransferSettings::Impl())
89 void TransferSettings::reset()
90 { _impl.reset(new TransferSettings::Impl()); }
93 void TransferSettings::addHeader( std::string && val_r )
94 { if ( ! val_r.empty() ) _impl->_headers.push_back( std::move(val_r) ); }
96 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
97 { return _impl->_headers.begin(); }
99 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
100 { return _impl->_headers.end(); }
103 void TransferSettings::setUserAgentString( std::string && val_r )
104 { _impl->_useragent = std::move(val_r); }
106 std::string TransferSettings::userAgentString() const
107 { return _impl->_useragent; }
110 void TransferSettings::setUsername( std::string && val_r )
111 { _impl->_username = std::move(val_r); }
113 std::string TransferSettings::username() const
114 { return _impl->_username; }
116 void TransferSettings::setPassword( std::string && val_r )
117 { _impl->_password = std::move(val_r); }
119 std::string TransferSettings::password() const
120 { return _impl->_password; }
122 std::string TransferSettings::userPassword() const
124 string userpwd = username();
125 if ( password().size() ) {
126 userpwd += ":" + password();
131 void TransferSettings::setAnonymousAuth()
133 setUsername("anonymous");
134 setPassword("yast@" LIBZYPP_VERSION_STRING);
138 void TransferSettings::setProxyEnabled( bool enabled )
139 { _impl->_useproxy = enabled; }
141 bool TransferSettings::proxyEnabled() const
142 { return _impl->_useproxy; }
145 void TransferSettings::setProxy( std::string && val_r )
146 { _impl->_proxy = std::move(val_r); }
148 std::string TransferSettings::proxy() const
149 { return _impl->_proxy; }
152 void TransferSettings::setProxyUsername( std::string && val_r )
153 { _impl->_proxy_username = std::move(val_r); }
155 std::string TransferSettings::proxyUsername() const
156 { return _impl->_proxy_username; }
158 void TransferSettings::setProxyPassword( std::string && val_r )
159 { _impl->_proxy_password = std::move(val_r); }
161 std::string TransferSettings::proxyPassword() const
162 { return _impl->_proxy_password; }
164 std::string TransferSettings::proxyUserPassword() const
166 string userpwd = proxyUsername();
167 if ( proxyPassword().size() ) {
168 userpwd += ":" + proxyPassword();
174 void TransferSettings::setTimeout( long t )
175 { _impl->_timeout = t; }
177 long TransferSettings::timeout() const
178 { return _impl->_timeout; }
181 void TransferSettings::setConnectTimeout( long t )
182 { _impl->_connect_timeout = t; }
184 long TransferSettings::connectTimeout() const
185 { return _impl->_connect_timeout; }
188 void TransferSettings::setMaxConcurrentConnections( long v )
189 { _impl->_maxConcurrentConnections = v; }
191 long TransferSettings::maxConcurrentConnections() const
192 { return _impl->_maxConcurrentConnections; }
195 void TransferSettings::setMinDownloadSpeed( long v )
196 { _impl->_minDownloadSpeed = v; }
198 long TransferSettings::minDownloadSpeed() const
199 { return _impl->_minDownloadSpeed; }
202 void TransferSettings::setMaxDownloadSpeed( long v )
203 { _impl->_maxDownloadSpeed = v; }
205 long TransferSettings::maxDownloadSpeed() const
206 { return _impl->_maxDownloadSpeed; }
209 void TransferSettings::setMaxSilentTries( long v )
210 { _impl->_maxSilentTries = v; }
212 long TransferSettings::maxSilentTries() const
213 { return _impl->_maxSilentTries; }
216 void TransferSettings::setVerifyHostEnabled( bool enabled )
217 { _impl->_verify_host = enabled; }
219 bool TransferSettings::verifyHostEnabled() const
220 { return _impl->_verify_host; }
223 void TransferSettings::setVerifyPeerEnabled( bool enabled )
224 { _impl->_verify_peer = enabled; }
226 bool TransferSettings::verifyPeerEnabled() const
227 { return _impl->_verify_peer; }
230 void TransferSettings::setClientCertificatePath( Pathname && val_r )
231 { _impl->_client_cert_path = std::move(val_r); }
233 Pathname TransferSettings::clientCertificatePath() const
234 { return _impl->_client_cert_path; }
237 void TransferSettings::setClientKeyPath( Pathname && val_r )
238 { _impl->_client_key_path = std::move(val_r); }
240 Pathname TransferSettings::clientKeyPath() const
241 { return _impl->_client_key_path; }
244 void TransferSettings::setCertificateAuthoritiesPath( Pathname && val_r )
245 { _impl->_ca_path = std::move(val_r); }
247 Pathname TransferSettings::certificateAuthoritiesPath() const
248 { return _impl->_ca_path; }
251 void TransferSettings::setAuthType( std::string && val_r )
252 { _impl->_authtype = std::move(val_r); }
254 std::string TransferSettings::authType() const
255 { return _impl->_authtype; }
258 void TransferSettings::setHeadRequestsAllowed( bool allowed )
259 { _impl->_head_requests_allowed = allowed; }
261 bool TransferSettings::headRequestsAllowed() const
262 { return _impl->_head_requests_allowed; }