libzypp  11.13.5
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 ARIA2C_BINARY "/usr/bin/aria2c"
16 #define CURL_BINARY "/usr/bin/curl"
17 
18 namespace zypp
19 {
20 namespace media
21 {
22 
24 {
25 public:
26  Impl()
27  : _useproxy(false)
28  , _timeout(0)
29  , _connect_timeout(0)
30  , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
31  , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
32  , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
33  , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
34  , _verify_host(false)
35  , _verify_peer(false)
36  , _ca_path("/etc/ssl/certs")
37  , _head_requests_allowed(true)
38  {}
39 
40  virtual ~Impl()
41  {}
42 
44  static shared_ptr<Impl> nullimpl()
45  {
46  static shared_ptr<Impl> _nullimpl( new Impl );
47  return _nullimpl;
48  }
49 
50 private:
51  friend Impl * rwcowClone<Impl>( const Impl * rhs );
53  Impl * clone() const
54  { return new Impl( *this ); }
55 
56 public:
57  vector<string> _headers;
58  string _useragent;
59  string _username;
60  string _password;
61  bool _useproxy;
62  string _proxy;
65  string _authtype;
66  long _timeout;
69  Pathname _targetdir;
70 
75 
78  Pathname _ca_path;
79 
80  // workarounds
82 };
83 
84 TransferSettings::TransferSettings()
85  : _impl(new TransferSettings::Impl())
86 {
87 
88 }
89 
91 {
93 }
94 
95 void TransferSettings::addHeader( const std::string &header )
96 {
97  _impl->_headers.push_back(header);
98 }
99 
100 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
101 {
102  return _impl->_headers.begin();
103 }
104 
105 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
106 {
107  return _impl->_headers.end();
108 }
109 
110 void TransferSettings::setUserAgentString( const std::string &agent )
111 {
112  _impl->_useragent = agent;
113 }
114 
116 {
117  return _impl->_useragent;
118 }
119 
120 void TransferSettings::setUsername( const std::string &username )
121 {
123 }
124 
125 std::string TransferSettings::username() const
126 {
127  return _impl->_username;
128 }
129 
130 void TransferSettings::setPassword( const std::string &password )
131 {
133 }
134 
136 {
137  setUsername("anonymous");
138  string id = "yast@";
139  setPassword(id + VERSION);
140 }
141 
142 std::string TransferSettings::password() const
143 {
144  return _impl->_password;
145 }
146 
148 {
149  string userpwd = username();
150  if ( password().size() ) {
151  userpwd += ":" + password();
152  }
153  return userpwd;
154 }
155 
157 {
158  _impl->_useproxy = enabled;
159 }
160 
162 {
163  return _impl->_useproxy;
164 }
165 
166 void TransferSettings::setProxy( const std::string &proxy )
167 {
168  _impl->_proxy = proxy;
169 }
170 
171 std::string TransferSettings::proxy() const
172 {
173  return _impl->_proxy;
174 }
175 
176 void TransferSettings::setProxyUsername( const std::string &proxyuser )
177 {
178  _impl->_proxy_username = proxyuser;
179 }
180 
182 {
183  return _impl->_proxy_username;
184 }
185 
186 void TransferSettings::setProxyPassword( const std::string &proxypass )
187 {
188  _impl->_proxy_password = proxypass;
189 }
190 
192 {
193  return _impl->_proxy_password;
194 }
195 
197 {
198  string userpwd = proxyUsername();
199  if ( proxyPassword().size() ) {
200  userpwd += ":" + proxyPassword();
201  }
202  return userpwd;
203 }
204 
206 {
207  _impl->_timeout = t;
208 }
209 
211 {
212  return _impl->_timeout;
213 }
214 
216 {
217  _impl->_connect_timeout = t;
218 }
219 
221 {
222  return _impl->_connect_timeout;
223 }
224 
226 {
228 }
229 
231 {
233 }
234 
236 {
237  return _impl->_minDownloadSpeed;
238 }
239 
241 {
243 }
244 
246 {
247  return _impl->_maxDownloadSpeed;
248 }
249 
251 {
253 }
254 
256 {
257  return _impl->_maxSilentTries;
258 }
259 
261 {
262  _impl->_maxSilentTries = v;
263 }
264 
266 {
267  return _impl->_verify_host;
268 }
269 
271 {
272  _impl->_verify_host = enabled;
273 }
274 
276 {
277  return _impl->_verify_peer;
278 }
279 
280 
282 {
283  _impl->_verify_peer = enabled;
284 }
285 
287 {
288  return _impl->_ca_path;
289 }
290 
291 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
292 {
293  _impl->_ca_path = path;
294 }
295 
296 void TransferSettings::setAuthType( const std::string &authtype)
297 {
298  _impl->_authtype = authtype;
299 }
300 
301 std::string TransferSettings::authType() const
302 {
303  return _impl->_authtype;
304 }
305 
307 {
308  _impl->_head_requests_allowed = allowed;
309 }
310 
312 {
313  return _impl->_head_requests_allowed;
314 }
315 
316 } // ns media
317 } // ns zypp
318