libzypp  17.7.0
TransferSettings.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 
4 #include "zypp/base/String.h"
5 #include "zypp/base/Logger.h"
6 #include "zypp/base/WatchFile.h"
9 #include "zypp/ExternalProgram.h"
11 #include "zypp/ZConfig.h"
12 
13 using namespace std;
14 
15 #define CURL_BINARY "/usr/bin/curl"
16 
17 namespace zypp
18 {
19 namespace media
20 {
21 
23 {
24 public:
25  Impl()
26  : _useproxy(false)
27  , _timeout(0)
28  , _connect_timeout(0)
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())
33  , _verify_host(false)
34  , _verify_peer(false)
35  , _ca_path("/etc/ssl/certs")
36  , _head_requests_allowed(true)
37  {}
38 
39  virtual ~Impl()
40  {}
41 
43  static shared_ptr<Impl> nullimpl()
44  {
45  static shared_ptr<Impl> _nullimpl( new Impl );
46  return _nullimpl;
47  }
48 
49 private:
50  friend Impl * rwcowClone<Impl>( const Impl * rhs );
52  Impl * clone() const
53  { return new Impl( *this ); }
54 
55 public:
56  vector<string> _headers;
57  string _useragent;
58  string _username;
59  string _password;
60  bool _useproxy;
61  string _proxy;
64  string _authtype;
65  long _timeout;
69 
74 
80 
81  // workarounds
83 };
84 
85 TransferSettings::TransferSettings()
86  : _impl(new TransferSettings::Impl())
87 {
88 
89 }
90 
92 {
94 }
95 
96 void TransferSettings::addHeader( const std::string &header )
97 {
98  if ( ! header.empty() )
99  _impl->_headers.push_back(header);
100 }
101 
102 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
103 {
104  return _impl->_headers.begin();
105 }
106 
107 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
108 {
109  return _impl->_headers.end();
110 }
111 
112 void TransferSettings::setUserAgentString( const std::string &agent )
113 {
114  _impl->_useragent = agent;
115 }
116 
118 {
119  return _impl->_useragent;
120 }
121 
122 void TransferSettings::setUsername( const std::string &username )
123 {
125 }
126 
127 std::string TransferSettings::username() const
128 {
129  return _impl->_username;
130 }
131 
132 void TransferSettings::setPassword( const std::string &password )
133 {
135 }
136 
138 {
139  setUsername("anonymous");
140  string id = "yast@";
141  setPassword(id + VERSION);
142 }
143 
144 std::string TransferSettings::password() const
145 {
146  return _impl->_password;
147 }
148 
150 {
151  string userpwd = username();
152  if ( password().size() ) {
153  userpwd += ":" + password();
154  }
155  return userpwd;
156 }
157 
159 {
160  _impl->_useproxy = enabled;
161 }
162 
164 {
165  return _impl->_useproxy;
166 }
167 
168 void TransferSettings::setProxy( const std::string &proxy )
169 {
170  _impl->_proxy = proxy;
171 }
172 
173 std::string TransferSettings::proxy() const
174 {
175  return _impl->_proxy;
176 }
177 
178 void TransferSettings::setProxyUsername( const std::string &proxyuser )
179 {
180  _impl->_proxy_username = proxyuser;
181 }
182 
184 {
185  return _impl->_proxy_username;
186 }
187 
188 void TransferSettings::setProxyPassword( const std::string &proxypass )
189 {
190  _impl->_proxy_password = proxypass;
191 }
192 
194 {
195  return _impl->_proxy_password;
196 }
197 
199 {
200  string userpwd = proxyUsername();
201  if ( proxyPassword().size() ) {
202  userpwd += ":" + proxyPassword();
203  }
204  return userpwd;
205 }
206 
208 {
209  _impl->_timeout = t;
210 }
211 
213 {
214  return _impl->_timeout;
215 }
216 
218 {
219  _impl->_connect_timeout = t;
220 }
221 
223 {
224  return _impl->_connect_timeout;
225 }
226 
228 {
230 }
231 
233 {
235 }
236 
238 {
239  return _impl->_minDownloadSpeed;
240 }
241 
243 {
245 }
246 
248 {
249  return _impl->_maxDownloadSpeed;
250 }
251 
253 {
255 }
256 
258 {
259  return _impl->_maxSilentTries;
260 }
261 
263 {
264  _impl->_maxSilentTries = v;
265 }
266 
268 {
269  return _impl->_verify_host;
270 }
271 
273 {
274  _impl->_verify_host = enabled;
275 }
276 
278 {
279  return _impl->_verify_peer;
280 }
281 
283 {
284  return _impl->_client_cert_path;
285 }
286 
288 {
289  _impl->_client_cert_path = path;
290 }
291 
293 {
294  return _impl->_client_key_path;
295 }
296 
298 {
299  _impl->_client_key_path = path;
300 }
301 
302 
304 {
305  _impl->_verify_peer = enabled;
306 }
307 
309 {
310  return _impl->_ca_path;
311 }
312 
314 {
315  _impl->_ca_path = path;
316 }
317 
318 void TransferSettings::setAuthType( const std::string &authtype)
319 {
320  _impl->_authtype = authtype;
321 }
322 
323 std::string TransferSettings::authType() const
324 {
325  return _impl->_authtype;
326 }
327 
329 {
330  _impl->_head_requests_allowed = allowed;
331 }
332 
334 {
336 }
337 
338 } // ns media
339 } // ns zypp
340 
long timeout() const
transfer timeout
std::string authType() const
get the allowed authentication types
std::string password() const
auth password
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
Pathname clientCertificatePath() const
SSL client certificate file.
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
std::string proxy() const
proxy host
void setClientKeyPath(const zypp::Pathname &path)
Sets the SSL client key file.
Holds transfer setting.
bool verifyHostEnabled() const
Whether to verify host for ssl.
void setProxyUsername(const std::string &proxyuser)
sets the proxy user
void setHeadRequestsAllowed(bool allowed)
set whether HEAD requests are allowed
Pathname certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
Definition: Arch.h:344
std::string username() const
auth username
void setConnectTimeout(long t)
set the connect timeout
Headers::const_iterator headersEnd() const
end iterators to additional headers
std::string userAgentString() const
user agent string
void setProxy(const std::string &proxyhost)
proxy to use if it is enabled
void setPassword(const std::string &password)
sets the auth password
void setUsername(const std::string &username)
sets the auth username
void setAnonymousAuth()
sets anonymous authentication (ie: for ftp)
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
long maxSilentTries() const
Maximum silent retries.
void setProxyPassword(const std::string &proxypass)
sets the proxy password
void setAuthType(const std::string &authtype)
set the allowed authentication types
static shared_ptr< Impl > nullimpl()
Offer default Impl.
long connectTimeout() const
connection timeout
Interim helper class to collect global options and settings.
Definition: ZConfig.h:59
void setMaxSilentTries(long v)
Set maximum silent retries.
std::string proxyPassword() const
proxy auth password
void setTimeout(long t)
set the transfer timeout
Headers::const_iterator headersBegin() const
begin iterators to additional headers
Pathname clientKeyPath() const
SSL client key file.
RWCOW_pointer< Impl > _impl
void setMaxDownloadSpeed(long v)
Set max download speed (bytes per second)
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
void setClientCertificatePath(const zypp::Pathname &path)
Sets the SSL client certificate file.
Impl * clone() const
clone for RWCOW_pointer
bool proxyEnabled() const
proxy is enabled
void reset()
reset the settings to the defaults
void setMaxConcurrentConnections(long v)
Set maximum number of concurrent connections for a single transfer.
long maxConcurrentConnections() const
Maximum number of concurrent connections for a single transfer.
void addHeader(const std::string &header)
add a header, on the form "Foo: Bar"
void setCertificateAuthoritiesPath(const zypp::Pathname &path)
Sets the SSL certificate authorities path.
std::string userPassword() const
returns the user and password as a user:pass string
std::string proxyUsername() const
proxy auth username
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void setMinDownloadSpeed(long v)
Set minimum download speed (bytes per second) until the connection is dropped.
void setVerifyPeerEnabled(bool enabled)
Sets whether to verify host for ssl.
void setVerifyHostEnabled(bool enabled)
Sets whether to verify host for ssl.
Url manipulation class.
Definition: Url.h:87
bool headRequestsAllowed() const
whether HEAD requests are allowed
void setUserAgentString(const std::string &agent)
sets the user agent ie: "Mozilla v3"
void setProxyEnabled(bool enabled)
whether the proxy is used or not