libzypp  16.22.9
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;
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  std::string val { str::trim( header ) };
99  if ( not val.empty() )
100  _impl->_headers.push_back( std::move(val) );
101  else
102  WAR << "Discard empty header" << endl;
103 }
104 
105 TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
106 {
107  return _impl->_headers.begin();
108 }
109 
110 TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
111 {
112  return _impl->_headers.end();
113 }
114 
115 void TransferSettings::setUserAgentString( const std::string &agent )
116 {
117  _impl->_useragent = agent;
118 }
119 
121 {
122  return _impl->_useragent;
123 }
124 
125 void TransferSettings::setUsername( const std::string &username )
126 {
128 }
129 
130 std::string TransferSettings::username() const
131 {
132  return _impl->_username;
133 }
134 
135 void TransferSettings::setPassword( const std::string &password )
136 {
138 }
139 
141 {
142  setUsername("anonymous");
143  string id = "yast@";
144  setPassword(id + VERSION);
145 }
146 
147 std::string TransferSettings::password() const
148 {
149  return _impl->_password;
150 }
151 
153 {
154  string userpwd = username();
155  if ( password().size() ) {
156  userpwd += ":" + password();
157  }
158  return userpwd;
159 }
160 
162 {
163  _impl->_useproxy = enabled;
164 }
165 
167 {
168  return _impl->_useproxy;
169 }
170 
171 void TransferSettings::setProxy( const std::string &proxy )
172 {
173  _impl->_proxy = proxy;
174 }
175 
176 std::string TransferSettings::proxy() const
177 {
178  return _impl->_proxy;
179 }
180 
181 void TransferSettings::setProxyUsername( const std::string &proxyuser )
182 {
183  _impl->_proxy_username = proxyuser;
184 }
185 
187 {
188  return _impl->_proxy_username;
189 }
190 
191 void TransferSettings::setProxyPassword( const std::string &proxypass )
192 {
193  _impl->_proxy_password = proxypass;
194 }
195 
197 {
198  return _impl->_proxy_password;
199 }
200 
202 {
203  string userpwd = proxyUsername();
204  if ( proxyPassword().size() ) {
205  userpwd += ":" + proxyPassword();
206  }
207  return userpwd;
208 }
209 
211 {
212  _impl->_timeout = t;
213 }
214 
216 {
217  return _impl->_timeout;
218 }
219 
221 {
222  _impl->_connect_timeout = t;
223 }
224 
226 {
227  return _impl->_connect_timeout;
228 }
229 
231 {
233 }
234 
236 {
238 }
239 
241 {
242  return _impl->_minDownloadSpeed;
243 }
244 
246 {
248 }
249 
251 {
252  return _impl->_maxDownloadSpeed;
253 }
254 
256 {
258 }
259 
261 {
262  return _impl->_maxSilentTries;
263 }
264 
266 {
267  _impl->_maxSilentTries = v;
268 }
269 
271 {
272  return _impl->_verify_host;
273 }
274 
276 {
277  _impl->_verify_host = enabled;
278 }
279 
281 {
282  return _impl->_verify_peer;
283 }
284 
286 {
287  return _impl->_client_cert_path;
288 }
289 
290 void TransferSettings::setClientCertificatePath( const zypp::Pathname &path )
291 {
292  _impl->_client_cert_path = path;
293 }
294 
296 {
297  return _impl->_client_key_path;
298 }
299 
300 void TransferSettings::setClientKeyPath( const zypp::Pathname &path )
301 {
302  _impl->_client_key_path = path;
303 }
304 
305 
307 {
308  _impl->_verify_peer = enabled;
309 }
310 
312 {
313  return _impl->_ca_path;
314 }
315 
316 void TransferSettings::setCertificateAuthoritiesPath( const zypp::Pathname &path )
317 {
318  _impl->_ca_path = path;
319 }
320 
321 void TransferSettings::setAuthType( const std::string &authtype)
322 {
323  _impl->_authtype = authtype;
324 }
325 
326 std::string TransferSettings::authType() const
327 {
328  return _impl->_authtype;
329 }
330 
332 {
333  _impl->_head_requests_allowed = allowed;
334 }
335 
337 {
339 }
340 
341 } // ns media
342 } // ns zypp
343 
std::string userPassword() const
returns the user and password as a user:pass string
bool verifyHostEnabled() const
Whether to verify host for ssl.
Pathname clientKeyPath() const
SSL client key file.
Impl * clone() const
clone for RWCOW_pointer
long connectTimeout() const
connection timeout
Headers::const_iterator headersEnd() const
end iterators to additional headers
void setClientKeyPath(const zypp::Pathname &path)
Sets the SSL client key file.
Holds transfer setting.
void setProxyUsername(const std::string &proxyuser)
sets the proxy user
Pathname certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
std::string password() const
auth password
void setHeadRequestsAllowed(bool allowed)
set whether HEAD requests are allowed
Definition: Arch.h:344
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
void setConnectTimeout(long t)
set the connect timeout
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
bool headRequestsAllowed() const
whether HEAD requests are allowed
void setAnonymousAuth()
sets anonymous authentication (ie: for ftp)
std::string userAgentString() const
user agent string
void setProxyPassword(const std::string &proxypass)
sets the proxy password
void setAuthType(const std::string &authtype)
set the allowed authentication types
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:221
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Interim helper class to collect global options and settings.
Definition: ZConfig.h:59
#define WAR
Definition: Logger.h:65
void setMaxSilentTries(long v)
Set maximum silent retries.
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
void setTimeout(long t)
set the transfer timeout
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
RWCOW_pointer< Impl > _impl
void setMaxDownloadSpeed(long v)
Set max download speed (bytes per second)
Headers::const_iterator headersBegin() const
begin iterators to additional headers
void setClientCertificatePath(const zypp::Pathname &path)
Sets the SSL client certificate file.
void reset()
reset the settings to the defaults
void setMaxConcurrentConnections(long v)
Set 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 proxyPassword() const
proxy auth password
long maxConcurrentConnections() const
Maximum number of concurrent connections for a single transfer.
long maxSilentTries() const
Maximum silent retries.
std::string authType() const
get the allowed authentication types
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.
Pathname clientCertificatePath() const
SSL client certificate file.
std::string proxy() const
proxy host
bool proxyEnabled() const
proxy is enabled
void setVerifyHostEnabled(bool enabled)
Sets whether to verify host for ssl.
Url manipulation class.
Definition: Url.h:87
void setUserAgentString(const std::string &agent)
sets the user agent ie: "Mozilla v3"
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
void setProxyEnabled(bool enabled)
whether the proxy is used or not
std::string username() const
auth username
std::string proxyUsername() const
proxy auth username
long timeout() const
transfer timeout