libzypp 17.31.7
transfersettings.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
13#include "transfersettings.h"
14#include <iostream>
15#include <sstream>
16
17#include <zypp-core/base/String.h>
18#include <zypp-core/base/Logger.h>
19#include <zypp-core/fs/WatchFile>
20#include <zypp-core/base/ReferenceCounted.h>
21#include <zypp-core/base/NonCopyable.h>
22#include <zypp-core/ExternalProgram.h>
23#include <zypp-media/MediaConfig>
24
25#include <zypp/APIConfig.h>
26
27using std::endl;
28
29#define CURL_BINARY "/usr/bin/curl"
30
31namespace zypp
32{
33 namespace media
34 {
36 {
37 public:
38 Impl() : _useproxy( false ),
39 _timeout( MediaConfig::instance().download_transfer_timeout() ),
40 _connect_timeout( 60 ),
41 _maxConcurrentConnections( MediaConfig::instance().download_max_concurrent_connections() ),
42 _minDownloadSpeed(MediaConfig::instance().download_min_download_speed()),
43 _maxDownloadSpeed(MediaConfig::instance().download_max_download_speed()),
44 _maxSilentTries(MediaConfig::instance().download_max_silent_tries() ),
45 _verify_host(false),
46 _verify_peer(false),
47 _ca_path("/etc/ssl/certs"),
49 {}
50
51 virtual ~Impl()
52 {}
53
55 static shared_ptr<Impl> nullimpl()
56 {
57 static shared_ptr<Impl> _nullimpl( new Impl );
58 return _nullimpl;
59 }
60
61 private:
62 friend Impl * rwcowClone<Impl>( const Impl * rhs );
64 Impl * clone() const
65 { return new Impl( *this ); }
66
67 public:
68 std::vector<std::string> _headers;
69 std::string _useragent;
70 std::string _username;
71 std::string _password;
73 std::string _proxy;
74 std::string _proxy_username;
75 std::string _proxy_password;
76 std::string _authtype;
81
86
92
93 // workarounds
95 };
96
98 : _impl(new TransferSettings::Impl())
99 {}
100
102 { _impl.reset(new TransferSettings::Impl()); }
103
104
105 void TransferSettings::addHeader( const std::string & val_r )
106 { if ( ! val_r.empty() ) _impl->_headers.push_back(val_r); }
107
108 void TransferSettings::addHeader( std::string && val_r )
109 { if ( ! val_r.empty() ) _impl->_headers.push_back(std::move(val_r)); }
110
112 {
113 //@TODO check if we could use a vector of std::string_view here
114 return _impl->_headers;
115 }
116
117 void TransferSettings::setUserAgentString( const std::string && val_r )
118 { _impl->_useragent = val_r; }
119
120 void TransferSettings::setUserAgentString( std::string && val_r )
121 { _impl->_useragent = std::move(val_r); }
122
123 const std::string &TransferSettings::userAgentString() const
124 { return _impl->_useragent; }
125
126
127 void TransferSettings::setUsername( const std::string &val_r )
128 { _impl->_username = val_r; }
129
130 void TransferSettings::setUsername( std::string && val_r )
131 { _impl->_username = std::move(val_r); }
132
133 const std::string &TransferSettings::username() const
134 { return _impl->_username; }
135
136 void TransferSettings::setPassword( const std::string & val_r )
137 { _impl->_password = val_r; }
138
139 void TransferSettings::setPassword( std::string && val_r )
140 { _impl->_password = std::move(val_r); }
141
142 const std::string &TransferSettings::password() const
143 { return _impl->_password; }
144
146 {
147 std::string userpwd = username();
148 if ( password().size() ) {
149 userpwd += ":" + password();
150 }
151 return userpwd;
152 }
153
155 {
156 setUsername("anonymous");
157 setPassword("yast@" LIBZYPP_VERSION_STRING);
158 }
159
160
162 { _impl->_useproxy = enabled; }
163
165 { return _impl->_useproxy; }
166
167
168 void TransferSettings::setProxy( const std::string &val_r )
169 { _impl->_proxy = val_r; }
170
171 void TransferSettings::setProxy( std::string && val_r )
172 { _impl->_proxy = std::move(val_r); }
173
174 const std::string &TransferSettings::proxy() const
175 { return _impl->_proxy; }
176
177
178 void TransferSettings::setProxyUsername( const std::string &val_r )
179 { _impl->_proxy_username = val_r; }
180
181 void TransferSettings::setProxyUsername( std::string && val_r )
182 { _impl->_proxy_username = std::move(val_r); }
183
184 const std::string &TransferSettings::proxyUsername() const
185 { return _impl->_proxy_username; }
186
187 void TransferSettings::setProxyPassword( const std::string &val_r )
188 { _impl->_proxy_password = val_r; }
189
190 void TransferSettings::setProxyPassword( std::string && val_r )
191 { _impl->_proxy_password = std::move(val_r); }
192
193 const std::string &TransferSettings::proxyPassword() const
194 { return _impl->_proxy_password; }
195
197 {
198 std::string userpwd = proxyUsername();
199 if ( proxyPassword().size() ) {
200 userpwd += ":" + proxyPassword();
201 }
202 return userpwd;
203 }
204
205
207 { _impl->_timeout = (t); }
208
210 { return _impl->_timeout; }
211
212
214 { _impl->_connect_timeout = (t); }
215
217 { return _impl->_connect_timeout; }
218
219
221 { _impl->_maxConcurrentConnections = (v); }
222
224 { return _impl->_maxConcurrentConnections; }
225
226
228 { _impl->_minDownloadSpeed = (v); }
229
231 { return _impl->_minDownloadSpeed; }
232
233
235 { _impl->_maxDownloadSpeed = (v); }
236
238 { return _impl->_maxDownloadSpeed; }
239
240
242 { _impl->_maxSilentTries = (v); }
243
245 { return _impl->_maxSilentTries; }
246
247
249 { _impl->_verify_host = (enabled); }
250
252 { return _impl->_verify_host; }
253
254
256 { _impl->_verify_peer = enabled; }
257
259 { return _impl->_verify_peer; }
260
262 { _impl->_client_cert_path = val_r; }
263
265 { _impl->_client_cert_path = std::move( val_r ); }
266
268 { return _impl->_client_cert_path; }
269
270
272 { _impl->_client_key_path = val_r; }
273
275 { _impl->_client_key_path = std::move( val_r ); }
276
278 { return _impl->_client_key_path; }
279
280
282 { _impl->_ca_path = val_r; }
283
285 { _impl->_ca_path = std::move(val_r.asString()); }
286
288 { return _impl->_ca_path; }
289
290
291 void TransferSettings::setAuthType( const std::string &val_r )
292 { _impl->_authtype = val_r; }
293
294 void TransferSettings::setAuthType( std::string && val_r )
295 { _impl->_authtype = std::move(val_r); }
296
297 const std::string &TransferSettings::authType() const
298 { return _impl->_authtype; }
299
300
302 { _impl->_head_requests_allowed = allowed; }
303
305 { return _impl->_head_requests_allowed; }
306
307 } // namespace media
308} // namespace zypp
Url manipulation class.
Definition: Url.h:92
std::vector< std::string > _headers
Impl * clone() const
clone for RWCOW_pointer
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Holds transfer setting.
const std::string & password() const
auth password
void setProxy(const std::string &val_r)
proxy to use if it is enabled
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.
long connectTimeout() const
connection timeout
const std::string & authType() const
get the allowed authentication types
long timeout() const
transfer timeout
void setUsername(const std::string &val_r)
sets the auth username
void reset()
reset the settings to the defaults
long maxSilentTries() const
Maximum silent retries.
const Pathname & clientCertificatePath() const
SSL client certificate file.
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 setProxyUsername(const std::string &val_r)
sets the proxy user
void setHeadRequestsAllowed(bool allowed)
set whether HEAD requests are allowed
const Headers & headers() const
returns a list of all added headers
const std::string & proxy() const
proxy host
const Pathname & clientKeyPath() const
SSL client key file.
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
void setClientKeyPath(const Pathname &val_r)
Sets the SSL client key file.
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
void setClientCertificatePath(const Pathname &val_r)
Sets the SSL client certificate file.
bool verifyHostEnabled() const
Whether to verify host for ssl.
const std::string & userAgentString() const
user agent string
void setPassword(const std::string &val_r)
sets the auth password
bool headRequestsAllowed() const
whether HEAD requests are allowed
const std::string & proxyPassword() const
proxy auth password
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)
void setAnonymousAuth()
sets anonymous authentication (ie: for ftp)
std::vector< std::string > Headers
const std::string & username() const
auth username
RWCOW_pointer< Impl > _impl
const std::string & proxyUsername() const
proxy auth username
void setAuthType(const std::string &val_r)
set the allowed authentication types
void setCertificateAuthoritiesPath(const Pathname &val_r)
Sets the SSL certificate authorities path.
void setProxyPassword(const std::string &val_r)
sets the proxy password
void setMaxConcurrentConnections(long v)
Set maximum number of concurrent connections for a single transfer.
const Pathname & certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
void setTimeout(long t)
set the transfer timeout
void setMaxSilentTries(long v)
Set maximum silent retries.
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2