libzypp  17.14.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:
57  string _useragent;
58  string _username;
59  string _password;
60  bool _useproxy;
61  string _proxy;
64  string _authtype;
65  long _timeout;
68  Pathname _targetdir;
69 
74 
77  Pathname _ca_path;
79  Pathname _client_key_path;
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 
287 void TransferSettings::setClientCertificatePath( const zypp::Pathname &path )
288 {
289  _impl->_client_cert_path = path;
290 }
291 
293 {
294  return _impl->_client_key_path;
295 }
296 
297 void TransferSettings::setClientKeyPath( const zypp::Pathname &path )
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 
313 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
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