libzypp 17.35.12
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
19#include <zypp-core/fs/WatchFile>
23#include <zypp-media/MediaConfig>
24
25#include <zypp-core/Globals.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( MediaConfig::instance().download_connect_timeout() ),
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 Impl(const Impl &) = default;
52 Impl(Impl &&) = default;
53 Impl &operator=(const Impl &) = delete;
54 Impl &operator=(Impl &&) = delete;
55 virtual ~Impl() {}
56
58 static shared_ptr<Impl> nullimpl()
59 {
60 static shared_ptr<Impl> _nullimpl( new Impl );
61 return _nullimpl;
62 }
63
64 private:
65 friend Impl * rwcowClone<Impl>( const Impl * rhs );
67 Impl * clone() const
68 { return new Impl( *this ); }
69
70 public:
71 void safeAddHeader( std::string val_r ) {
72 // bsc#1212187: HTTP/2 RFC 9113 forbids fields ending with a space.
73 // Trim and discard empty header.
74 val_r = str::trim( std::move(val_r) );
75 if ( not val_r.empty() )
76 _headers.push_back( std::move(val_r) );
77 else
78 WAR << "Discard empty header" << endl;
79 }
80
81 public:
82 std::vector<std::string> _headers;
83 std::string _useragent;
84 std::string _username;
85 std::string _password;
87 std::string _proxy;
88 std::string _proxy_username;
89 std::string _proxy_password;
90 std::string _authtype;
95
100
106
107 // workarounds
109 };
110
114
117
118
119 void TransferSettings::addHeader( const std::string & val_r )
120 { _impl->safeAddHeader( val_r ); }
121 void TransferSettings::addHeader( std::string && val_r )
122 { _impl->safeAddHeader( std::move(val_r) ); }
123
125 {
126 //@TODO check if we could use a vector of std::string_view here
127 return _impl->_headers;
128 }
129
130 void TransferSettings::setUserAgentString( const std::string &val_r )
131 { _impl->_useragent = str::trim( val_r ); } // bsc#1212187: HTTP/2 RFC 9113 forbids fields ending with a space
132
133 void TransferSettings::setUserAgentString( std::string && val_r )
134 { _impl->_useragent = str::trim( std::move(val_r) ); } // bsc#1212187: HTTP/2 RFC 9113 forbids fields ending with a space
135
136 const std::string &TransferSettings::userAgentString() const
137 { return _impl->_useragent; }
138
139
140 void TransferSettings::setUsername( const std::string &val_r )
141 { _impl->_username = val_r; }
142
143 void TransferSettings::setUsername( std::string && val_r )
144 { _impl->_username = std::move(val_r); }
145
146 const std::string &TransferSettings::username() const
147 { return _impl->_username; }
148
149 void TransferSettings::setPassword( const std::string & val_r )
150 { _impl->_password = val_r; }
151
152 void TransferSettings::setPassword( std::string && val_r )
153 { _impl->_password = std::move(val_r); }
154
155 const std::string &TransferSettings::password() const
156 { return _impl->_password; }
157
159 {
160 std::string userpwd = username();
161 if ( password().size() ) {
162 userpwd += ":" + password();
163 }
164 return userpwd;
165 }
166
168 {
169 setUsername("anonymous");
170 setPassword("yast@" LIBZYPP_VERSION_STRING);
171 }
172
173
175 { _impl->_useproxy = enabled; }
176
178 { return _impl->_useproxy; }
179
180
181 void TransferSettings::setProxy( const std::string &val_r )
182 { _impl->_proxy = val_r; }
183
184 void TransferSettings::setProxy( std::string && val_r )
185 { _impl->_proxy = std::move(val_r); }
186
187 const std::string &TransferSettings::proxy() const
188 { return _impl->_proxy; }
189
190
191 void TransferSettings::setProxyUsername( const std::string &val_r )
192 { _impl->_proxy_username = val_r; }
193
194 void TransferSettings::setProxyUsername( std::string && val_r )
195 { _impl->_proxy_username = std::move(val_r); }
196
197 const std::string &TransferSettings::proxyUsername() const
198 { return _impl->_proxy_username; }
199
200 void TransferSettings::setProxyPassword( const std::string &val_r )
201 { _impl->_proxy_password = val_r; }
202
203 void TransferSettings::setProxyPassword( std::string && val_r )
204 { _impl->_proxy_password = std::move(val_r); }
205
206 const std::string &TransferSettings::proxyPassword() const
207 { return _impl->_proxy_password; }
208
210 {
211 std::string userpwd = proxyUsername();
212 if ( proxyPassword().size() ) {
213 userpwd += ":" + proxyPassword();
214 }
215 return userpwd;
216 }
217
218
220 { _impl->_timeout = (t); }
221
223 { return _impl->_timeout; }
224
225
228
231
232
235
238
239
242
245
246
249
252
253
256
259
260
262 { _impl->_verify_host = (enabled); }
263
266
267
269 { _impl->_verify_peer = enabled; }
270
273
276
278 { _impl->_client_cert_path = std::move( val_r ); }
279
282
283
286
288 { _impl->_client_key_path = std::move( val_r ); }
289
292
293
296
298 { _impl->_ca_path = std::move(val_r); }
299
302
303
304 void TransferSettings::setAuthType( const std::string &val_r )
305 { _impl->_authtype = val_r; }
306
307 void TransferSettings::setAuthType( std::string && val_r )
308 { _impl->_authtype = std::move(val_r); }
309
310 const std::string &TransferSettings::authType() const
311 { return _impl->_authtype; }
312
313
316
319
320 } // namespace media
321} // namespace zypp
Url manipulation class.
Definition Url.h:92
friend Impl * rwcowClone(const Impl *rhs)
std::vector< std::string > _headers
void safeAddHeader(std::string val_r)
Impl * clone() const
clone for RWCOW_pointer
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Impl & operator=(const Impl &)=delete
Impl & operator=(Impl &&)=delete
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 (trimmed)
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" (trims)
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" (trims)
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 (trimmed)
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
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.
std::string trim(const std::string &s, const Trim trim_r)
Definition String.cc:224
Easy-to use interface to the ZYPP dependency resolver.
Provides API related macros.
#define WAR
Definition Logger.h:99