libzypp  17.25.2
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 
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 
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 
zypp::media::TransferSettings::verifyHostEnabled
bool verifyHostEnabled() const
Whether to verify host for ssl.
Definition: TransferSettings.cc:218
zypp::media::TransferSettings::Impl::_targetdir
Pathname _targetdir
Definition: TransferSettings.cc:67
ExternalProgram.h
zypp::media::TransferSettings::verifyPeerEnabled
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
Definition: TransferSettings.cc:225
zypp::media::TransferSettings::Impl::_timeout
long _timeout
Definition: TransferSettings.cc:64
zypp::media::TransferSettings::setConnectTimeout
void setConnectTimeout(long t)
set the connect timeout
Definition: TransferSettings.cc:180
zypp::media::TransferSettings::userPassword
std::string userPassword() const
returns the user and password as a user:pass string
Definition: TransferSettings.cc:121
zypp::media::TransferSettings::reset
void reset()
reset the settings to the defaults
Definition: TransferSettings.cc:88
WatchFile.h
zypp::media::TransferSettings::proxyPassword
std::string proxyPassword() const
proxy auth password
Definition: TransferSettings.cc:160
zypp::media::TransferSettings::Impl::_verify_peer
bool _verify_peer
Definition: TransferSettings.cc:75
zypp::media::TransferSettings::setTimeout
void setTimeout(long t)
set the transfer timeout
Definition: TransferSettings.cc:173
zypp::media::TransferSettings::setMaxSilentTries
void setMaxSilentTries(long v)
Set maximum silent retries.
Definition: TransferSettings.cc:208
zypp::media::TransferSettings::username
std::string username() const
auth username
Definition: TransferSettings.cc:112
zypp::media::TransferSettings::headersBegin
Headers::const_iterator headersBegin() const
begin iterators to additional headers
Definition: TransferSettings.cc:95
zypp::media::TransferSettings::minDownloadSpeed
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
Definition: TransferSettings.cc:197
zypp::media::TransferSettings::Impl::_useproxy
bool _useproxy
Definition: TransferSettings.cc:59
ZConfig.h
zypp::media::TransferSettings::certificateAuthoritiesPath
Pathname certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
Definition: TransferSettings.cc:246
zypp::media::TransferSettings::timeout
long timeout() const
transfer timeout
Definition: TransferSettings.cc:176
zypp::media::TransferSettings::Impl::_proxy_username
std::string _proxy_username
Definition: TransferSettings.cc:61
zypp::media::TransferSettings::Impl::_ca_path
Pathname _ca_path
Definition: TransferSettings.cc:76
zypp::media::TransferSettings::authType
std::string authType() const
get the allowed authentication types
Definition: TransferSettings.cc:253
zypp::media::TransferSettings::setMaxConcurrentConnections
void setMaxConcurrentConnections(long v)
Set maximum number of concurrent connections for a single transfer.
Definition: TransferSettings.cc:187
zypp::media::TransferSettings::maxConcurrentConnections
long maxConcurrentConnections() const
Maximum number of concurrent connections for a single transfer.
Definition: TransferSettings.cc:190
zypp::media::TransferSettings::proxyUserPassword
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
Definition: TransferSettings.cc:163
zypp::media::TransferSettings::headRequestsAllowed
bool headRequestsAllowed() const
whether HEAD requests are allowed
Definition: TransferSettings.cc:260
zypp::media::TransferSettings::Impl::~Impl
virtual ~Impl()
Definition: TransferSettings.cc:38
zypp::media::TransferSettings::setVerifyHostEnabled
void setVerifyHostEnabled(bool enabled)
Sets whether to verify host for ssl.
Definition: TransferSettings.cc:215
zypp::media::TransferSettings::proxyEnabled
bool proxyEnabled() const
proxy is enabled
Definition: TransferSettings.cc:140
zypp::media::TransferSettings
Holds transfer setting.
Definition: TransferSettings.h:21
zypp::media::TransferSettings::setProxyEnabled
void setProxyEnabled(bool enabled)
whether the proxy is used or not
Definition: TransferSettings.cc:137
zypp::media::TransferSettings::setUsername
void setUsername(std::string &&val_r)
sets the auth username
Definition: TransferSettings.cc:109
zypp::media::TransferSettings::setClientCertificatePath
void setClientCertificatePath(Pathname &&val_r)
Sets the SSL client certificate file.
Definition: TransferSettings.cc:229
zypp::media::TransferSettings::setHeadRequestsAllowed
void setHeadRequestsAllowed(bool allowed)
set whether HEAD requests are allowed
Definition: TransferSettings.cc:257
zypp::media::TransferSettings::Impl::_proxy_password
std::string _proxy_password
Definition: TransferSettings.cc:62
zypp::media::TransferSettings::Impl::_proxy
std::string _proxy
Definition: TransferSettings.cc:60
zypp::media::TransferSettings::maxSilentTries
long maxSilentTries() const
Maximum silent retries.
Definition: TransferSettings.cc:211
zypp::media::TransferSettings::proxyUsername
std::string proxyUsername() const
proxy auth username
Definition: TransferSettings.cc:154
zypp::media::TransferSettings::Impl::_url
Url _url
Definition: TransferSettings.cc:66
zypp::media::TransferSettings::Impl::_headers
std::vector< std::string > _headers
Definition: TransferSettings.cc:55
Logger.h
zypp::media::TransferSettings::setProxy
void setProxy(std::string &&val_r)
proxy to use if it is enabled
Definition: TransferSettings.cc:144
zypp::media::TransferSettings::Impl::_minDownloadSpeed
long _minDownloadSpeed
Definition: TransferSettings.cc:70
zypp::media::TransferSettings::Impl::nullimpl
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: TransferSettings.cc:42
TransferSettings.h
zypp::media::TransferSettings::Impl
Definition: TransferSettings.cc:22
zypp::media::TransferSettings::Impl::_maxSilentTries
long _maxSilentTries
Definition: TransferSettings.cc:72
zypp::media::TransferSettings::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition: TransferSettings.cc:51
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::ZConfig
Interim helper class to collect global options and settings.
Definition: ZConfig.h:60
zypp::media::TransferSettings::userAgentString
std::string userAgentString() const
user agent string
Definition: TransferSettings.cc:105
zypp::media::TransferSettings::Impl::_useragent
std::string _useragent
Definition: TransferSettings.cc:56
zypp::media::TransferSettings::clientKeyPath
Pathname clientKeyPath() const
SSL client key file.
Definition: TransferSettings.cc:239
zypp::media::TransferSettings::clientCertificatePath
Pathname clientCertificatePath() const
SSL client certificate file.
Definition: TransferSettings.cc:232
zypp::media::TransferSettings::setVerifyPeerEnabled
void setVerifyPeerEnabled(bool enabled)
Sets whether to verify host for ssl.
Definition: TransferSettings.cc:222
zypp::media::TransferSettings::Impl::_password
std::string _password
Definition: TransferSettings.cc:58
zypp::media::TransferSettings::Impl::_connect_timeout
long _connect_timeout
Definition: TransferSettings.cc:65
zypp::media::TransferSettings::setMaxDownloadSpeed
void setMaxDownloadSpeed(long v)
Set max download speed (bytes per second)
Definition: TransferSettings.cc:201
zypp::media::TransferSettings::Impl::_verify_host
bool _verify_host
Definition: TransferSettings.cc:74
zypp::media::TransferSettings::Impl::_maxConcurrentConnections
long _maxConcurrentConnections
Definition: TransferSettings.cc:69
zypp::media::TransferSettings::setProxyPassword
void setProxyPassword(std::string &&val_r)
sets the proxy password
Definition: TransferSettings.cc:157
zypp::media::TransferSettings::TransferSettings
TransferSettings()
Constructs a transfer program cmd line access.
Definition: TransferSettings.cc:84
zypp::media::TransferSettings::addHeader
void addHeader(std::string &&val_r)
add a header, on the form "Foo: Bar"
Definition: TransferSettings.cc:92
ReferenceCounted.h
zypp::media::TransferSettings::Impl::_authtype
std::string _authtype
Definition: TransferSettings.cc:63
zypp::media::TransferSettings::Impl::_maxDownloadSpeed
long _maxDownloadSpeed
Definition: TransferSettings.cc:71
zypp::media::TransferSettings::Impl::_head_requests_allowed
bool _head_requests_allowed
Definition: TransferSettings.cc:81
String.h
zypp::media::TransferSettings::setAuthType
void setAuthType(std::string &&val_r)
set the allowed authentication types
Definition: TransferSettings.cc:250
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::media::TransferSettings::setClientKeyPath
void setClientKeyPath(Pathname &&val_r)
Sets the SSL client key file.
Definition: TransferSettings.cc:236
zypp::media::TransferSettings::setPassword
void setPassword(std::string &&val_r)
sets the auth password
Definition: TransferSettings.cc:115
zypp::media::TransferSettings::setMinDownloadSpeed
void setMinDownloadSpeed(long v)
Set minimum download speed (bytes per second) until the connection is dropped.
Definition: TransferSettings.cc:194
zypp::media::TransferSettings::setProxyUsername
void setProxyUsername(std::string &&val_r)
sets the proxy user
Definition: TransferSettings.cc:151
zypp::media::TransferSettings::setCertificateAuthoritiesPath
void setCertificateAuthoritiesPath(Pathname &&val_r)
Sets the SSL certificate authorities path.
Definition: TransferSettings.cc:243
zypp::media::TransferSettings::connectTimeout
long connectTimeout() const
connection timeout
Definition: TransferSettings.cc:183
zypp::media::TransferSettings::Impl::Impl
Impl()
Definition: TransferSettings.cc:24
zypp::media::TransferSettings::setUserAgentString
void setUserAgentString(std::string &&val_r)
sets the user agent ie: "Mozilla v3"
Definition: TransferSettings.cc:102
zypp::media::TransferSettings::headersEnd
Headers::const_iterator headersEnd() const
end iterators to additional headers
Definition: TransferSettings.cc:98
zypp::RWCOW_pointer::reset
void reset()
Definition: PtrTypes.h:482
zypp::media::TransferSettings::setAnonymousAuth
void setAnonymousAuth()
sets anonymous authentication (ie: for ftp)
Definition: TransferSettings.cc:130
zypp::Url
Url manipulation class.
Definition: Url.h:88
zypp::media::TransferSettings::proxy
std::string proxy() const
proxy host
Definition: TransferSettings.cc:147
zypp::media::TransferSettings::password
std::string password() const
auth password
Definition: TransferSettings.cc:118
zypp::media::TransferSettings::Impl::_username
std::string _username
Definition: TransferSettings.cc:57
zypp::media::TransferSettings::_impl
RWCOW_pointer< Impl > _impl
Definition: TransferSettings.h:189
zypp::media::TransferSettings::Impl::_client_key_path
Pathname _client_key_path
Definition: TransferSettings.cc:78
zypp::media::TransferSettings::Impl::_client_cert_path
Pathname _client_cert_path
Definition: TransferSettings.cc:77
NonCopyable.h
zypp::media::TransferSettings::maxDownloadSpeed
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
Definition: TransferSettings.cc:204