libzypp 17.25.10
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 std::endl;
14 
15 #define CURL_BINARY "/usr/bin/curl"
16 
17 namespace zypp
18 {
19  namespace media
20  {
22  {
23  public:
24  Impl()
25  : _useproxy(false)
26  , _timeout( ZConfig::instance().download_transfer_timeout() )
27  , _connect_timeout( 60 )
28  , _maxConcurrentConnections(ZConfig::instance().download_max_concurrent_connections())
29  , _minDownloadSpeed(ZConfig::instance().download_min_download_speed())
30  , _maxDownloadSpeed(ZConfig::instance().download_max_download_speed())
31  , _maxSilentTries(ZConfig::instance().download_max_silent_tries())
32  , _verify_host(false)
33  , _verify_peer(false)
34  , _ca_path("/etc/ssl/certs")
36  {}
37 
38  virtual ~Impl()
39  {}
40 
42  static shared_ptr<Impl> nullimpl()
43  {
44  static shared_ptr<Impl> _nullimpl( new Impl );
45  return _nullimpl;
46  }
47 
48  private:
49  friend Impl * rwcowClone<Impl>( const Impl * rhs );
51  Impl * clone() const
52  { return new Impl( *this ); }
53 
54  public:
55  std::vector<std::string> _headers;
56  std::string _useragent;
57  std::string _username;
58  std::string _password;
59  bool _useproxy;
60  std::string _proxy;
61  std::string _proxy_username;
62  std::string _proxy_password;
63  std::string _authtype;
64  long _timeout;
68 
73 
79 
80  // workarounds
82  };
83 
85  : _impl(new TransferSettings::Impl())
86  {}
87 
89  { _impl.reset(new TransferSettings::Impl()); }
90 
91 
92  void TransferSettings::addHeader( std::string && val_r )
93  { if ( ! val_r.empty() ) _impl->_headers.push_back( std::move(val_r) ); }
94 
95  TransferSettings::Headers::const_iterator TransferSettings::headersBegin() const
96  { return _impl->_headers.begin(); }
97 
98  TransferSettings::Headers::const_iterator TransferSettings::headersEnd() const
99  { return _impl->_headers.end(); }
100 
101 
102  void TransferSettings::setUserAgentString( std::string && val_r )
103  { _impl->_useragent = std::move(val_r); }
104 
106  { return _impl->_useragent; }
107 
108 
109  void TransferSettings::setUsername( std::string && val_r )
110  { _impl->_username = std::move(val_r); }
111 
112  std::string TransferSettings::username() const
113  { return _impl->_username; }
114 
115  void TransferSettings::setPassword( std::string && val_r )
116  { _impl->_password = std::move(val_r); }
117 
118  std::string TransferSettings::password() const
119  { return _impl->_password; }
120 
121  std::string TransferSettings::userPassword() const
122  {
123  std::string userpwd = username();
124  if ( password().size() ) {
125  userpwd += ":" + password();
126  }
127  return userpwd;
128  }
129 
131  {
132  setUsername("anonymous");
133  setPassword("yast@" LIBZYPP_VERSION_STRING);
134  }
135 
136 
138  { _impl->_useproxy = enabled; }
139 
141  { return _impl->_useproxy; }
142 
143 
144  void TransferSettings::setProxy( std::string && val_r )
145  { _impl->_proxy = std::move(val_r); }
146 
147  std::string TransferSettings::proxy() const
148  { return _impl->_proxy; }
149 
150 
151  void TransferSettings::setProxyUsername( std::string && val_r )
152  { _impl->_proxy_username = std::move(val_r); }
153 
155  { return _impl->_proxy_username; }
156 
157  void TransferSettings::setProxyPassword( std::string && val_r )
158  { _impl->_proxy_password = std::move(val_r); }
159 
161  { return _impl->_proxy_password; }
162 
164  {
165  std::string userpwd = proxyUsername();
166  if ( proxyPassword().size() ) {
167  userpwd += ":" + proxyPassword();
168  }
169  return userpwd;
170  }
171 
172 
174  { _impl->_timeout = t; }
175 
177  { return _impl->_timeout; }
178 
179 
181  { _impl->_connect_timeout = t; }
182 
184  { return _impl->_connect_timeout; }
185 
186 
188  { _impl->_maxConcurrentConnections = v; }
189 
191  { return _impl->_maxConcurrentConnections; }
192 
193 
195  { _impl->_minDownloadSpeed = v; }
196 
198  { return _impl->_minDownloadSpeed; }
199 
200 
202  { _impl->_maxDownloadSpeed = v; }
203 
205  { return _impl->_maxDownloadSpeed; }
206 
207 
209  { _impl->_maxSilentTries = v; }
210 
212  { return _impl->_maxSilentTries; }
213 
214 
216  { _impl->_verify_host = enabled; }
217 
219  { return _impl->_verify_host; }
220 
221 
223  { _impl->_verify_peer = enabled; }
224 
226  { return _impl->_verify_peer; }
227 
228 
230  { _impl->_client_cert_path = std::move(val_r); }
231 
233  { return _impl->_client_cert_path; }
234 
235 
237  { _impl->_client_key_path = std::move(val_r); }
238 
240  { return _impl->_client_key_path; }
241 
242 
244  { _impl->_ca_path = std::move(val_r); }
245 
247  { return _impl->_ca_path; }
248 
249 
250  void TransferSettings::setAuthType( std::string && val_r )
251  { _impl->_authtype = std::move(val_r); }
252 
253  std::string TransferSettings::authType() const
254  { return _impl->_authtype; }
255 
256 
258  { _impl->_head_requests_allowed = allowed; }
259 
261  { return _impl->_head_requests_allowed; }
262 
263  } // namespace media
264 } // namespace zypp
265 
Url manipulation class.
Definition: Url.h:92
Interim helper class to collect global options and settings.
Definition: ZConfig.h:62
std::vector< std::string > _headers
Impl * clone() const
clone for RWCOW_pointer
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Holds transfer setting.
std::string proxy() const
proxy host
void setProxyEnabled(bool enabled)
whether the proxy is used or not
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
TransferSettings()
Constructs a transfer program cmd line access.
void setProxyUsername(std::string &&val_r)
sets the proxy user
long connectTimeout() const
connection timeout
std::string password() const
auth password
long timeout() const
transfer timeout
Headers::const_iterator headersEnd() const
end iterators to additional headers
std::string proxyPassword() const
proxy auth password
void setClientCertificatePath(Pathname &&val_r)
Sets the SSL client certificate file.
void setProxy(std::string &&val_r)
proxy to use if it is enabled
void reset()
reset the settings to the defaults
long maxSilentTries() const
Maximum silent retries.
std::string userPassword() const
returns the user and password as a user:pass string
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
void setHeadRequestsAllowed(bool allowed)
set whether HEAD requests are allowed
void setAuthType(std::string &&val_r)
set the allowed authentication types
void setUsername(std::string &&val_r)
sets the auth username
void setVerifyHostEnabled(bool enabled)
Sets whether to verify host for ssl.
void setUserAgentString(std::string &&val_r)
sets the user agent ie: "Mozilla v3"
void setConnectTimeout(long t)
set the connect timeout
std::string userAgentString() const
user agent string
void setPassword(std::string &&val_r)
sets the auth password
void setCertificateAuthoritiesPath(Pathname &&val_r)
Sets the SSL certificate authorities path.
void addHeader(std::string &&val_r)
add a header, on the form "Foo: Bar"
void setMinDownloadSpeed(long v)
Set minimum download speed (bytes per second) until the connection is dropped.
long maxConcurrentConnections() const
Maximum number of concurrent connections for a single transfer.
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
bool verifyHostEnabled() const
Whether to verify host for ssl.
void setClientKeyPath(Pathname &&val_r)
Sets the SSL client key file.
Pathname clientCertificatePath() const
SSL client certificate file.
void setProxyPassword(std::string &&val_r)
sets the proxy password
Pathname certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
bool headRequestsAllowed() const
whether HEAD requests are allowed
std::string proxyUsername() const
proxy auth username
std::string authType() const
get the allowed authentication types
void setVerifyPeerEnabled(bool enabled)
Sets whether to verify host for ssl.
bool proxyEnabled() const
proxy is enabled
void setMaxDownloadSpeed(long v)
Set max download speed (bytes per second)
std::string username() const
auth username
void setAnonymousAuth()
sets anonymous authentication (ie: for ftp)
RWCOW_pointer< Impl > _impl
void setMaxConcurrentConnections(long v)
Set maximum number of concurrent connections for a single transfer.
Pathname clientKeyPath() const
SSL client key file.
void setTimeout(long t)
set the transfer timeout
void setMaxSilentTries(long v)
Set maximum silent retries.
Headers::const_iterator headersBegin() const
begin iterators to additional headers
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2