libzypp 17.28.8
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>
7#include <zypp/base/ReferenceCounted.h>
8#include <zypp/base/NonCopyable.h>
9#include <zypp/ExternalProgram.h>
11#include <zypp/ZConfig.h>
12
13#include <zypp-proto/transfersettings.pb.h>
14
15using std::endl;
16
17#define CURL_BINARY "/usr/bin/curl"
18
19namespace zypp
20{
21 namespace media
22 {
24 {
25 public:
26 Impl() {
27 _settingsObj.set_useproxy( false );
28 _settingsObj.set_timeout( ZConfig::instance().download_transfer_timeout() );
29 _settingsObj.set_connect_timeout( 60 );
30 _settingsObj.set_maxconcurrentconnections( ZConfig::instance().download_max_concurrent_connections() );
31 _settingsObj.set_mindownloadspeed(ZConfig::instance().download_min_download_speed());
32 _settingsObj.set_maxdownloadspeed(ZConfig::instance().download_max_download_speed());
33 _settingsObj.set_maxsilenttries(ZConfig::instance().download_max_silent_tries() );
34 _settingsObj.set_verify_host(false);
35 _settingsObj.set_verify_peer(false);
36 _settingsObj.set_ca_path("/etc/ssl/certs");
37 _settingsObj.set_head_requests_allowed(true);
38 }
39
40 virtual ~Impl()
41 {}
42
44 static shared_ptr<Impl> nullimpl()
45 {
46 static shared_ptr<Impl> _nullimpl( new Impl );
47 return _nullimpl;
48 }
49
50 private:
51 friend Impl * rwcowClone<Impl>( const Impl * rhs );
53 Impl * clone() const
54 { return new Impl( *this ); }
55
56 public:
57 std::vector<std::string> _headers;
58 zypp::proto::TransferSettings _settingsObj;
59 };
60
62 : _impl(new TransferSettings::Impl())
63 {}
64
65 TransferSettings::TransferSettings( const proto::TransferSettings &settings )
66 : _impl(new TransferSettings::Impl())
67 {
68 _impl->_settingsObj = settings;
69 }
70
72 { _impl.reset(new TransferSettings::Impl()); }
73
74
75 void TransferSettings::addHeader( std::string && val_r )
76 { if ( ! val_r.empty() ) *_impl->_settingsObj.add_header() = std::move(val_r); }
77
79 {
80 //@TODO check if we could use a vector of std::string_view here
81 auto vec = Headers();
82 for ( const auto &head : _impl->_settingsObj.header() ) {
83 vec.push_back( head );
84 }
85 return vec;
86 }
87
88 void TransferSettings::setUserAgentString( std::string && val_r )
89 { _impl->_settingsObj.set_useragent( std::move(val_r) ); }
90
92 { return _impl->_settingsObj.useragent(); }
93
94
95 void TransferSettings::setUsername( std::string && val_r )
96 { _impl->_settingsObj.set_username( std::move(val_r) ); }
97
98 std::string TransferSettings::username() const
99 { return _impl->_settingsObj.username(); }
100
101 void TransferSettings::setPassword( std::string && val_r )
102 { _impl->_settingsObj.set_password( std::move(val_r) ); }
103
104 std::string TransferSettings::password() const
105 { return _impl->_settingsObj.password(); }
106
108 {
109 std::string userpwd = username();
110 if ( password().size() ) {
111 userpwd += ":" + password();
112 }
113 return userpwd;
114 }
115
117 {
118 setUsername("anonymous");
119 setPassword("yast@" LIBZYPP_VERSION_STRING);
120 }
121
122
124 { _impl->_settingsObj.set_useproxy( enabled ); }
125
127 { return _impl->_settingsObj.useproxy(); }
128
129
130 void TransferSettings::setProxy( std::string && val_r )
131 { _impl->_settingsObj.set_proxy( std::move(val_r) ); }
132
133 std::string TransferSettings::proxy() const
134 { return _impl->_settingsObj.proxy(); }
135
136
137 void TransferSettings::setProxyUsername( std::string && val_r )
138 { _impl->_settingsObj.set_proxy_username( std::move(val_r) ); }
139
141 { return _impl->_settingsObj.proxy_username(); }
142
143 void TransferSettings::setProxyPassword( std::string && val_r )
144 { _impl->_settingsObj.set_proxy_password( std::move(val_r) ); }
145
147 { return _impl->_settingsObj.proxy_password(); }
148
150 {
151 std::string userpwd = proxyUsername();
152 if ( proxyPassword().size() ) {
153 userpwd += ":" + proxyPassword();
154 }
155 return userpwd;
156 }
157
158
160 { _impl->_settingsObj.set_timeout(t); }
161
163 { return _impl->_settingsObj.timeout(); }
164
165
167 { _impl->_settingsObj.set_connect_timeout(t); }
168
170 { return _impl->_settingsObj.connect_timeout(); }
171
172
174 { _impl->_settingsObj.set_maxconcurrentconnections(v); }
175
177 { return _impl->_settingsObj.maxconcurrentconnections(); }
178
179
181 { _impl->_settingsObj.set_mindownloadspeed(v); }
182
184 { return _impl->_settingsObj.mindownloadspeed(); }
185
186
188 { _impl->_settingsObj.set_maxdownloadspeed(v); }
189
191 { return _impl->_settingsObj.maxdownloadspeed(); }
192
193
195 { _impl->_settingsObj.set_maxsilenttries(v); }
196
198 { return _impl->_settingsObj.maxsilenttries(); }
199
200
202 { _impl->_settingsObj.set_verify_host(enabled); }
203
205 { return _impl->_settingsObj.verify_host(); }
206
207
209 { _impl->_settingsObj.set_verify_peer(enabled); }
210
212 { return _impl->_settingsObj.verify_peer(); }
213
214
216 { _impl->_settingsObj.set_client_cert_path( val_r.asString() ); }
217
219 { return _impl->_settingsObj.client_cert_path(); }
220
221
223 { _impl->_settingsObj.set_client_key_path( val_r.asString() ); }
224
226 { return _impl->_settingsObj.client_key_path(); }
227
228 proto::TransferSettings &TransferSettings::protoData()
229 {
230 return _impl->_settingsObj;
231 }
232
233 const proto::TransferSettings &TransferSettings::protoData() const
234 {
235 return _impl->_settingsObj;
236 }
237
239 { _impl->_settingsObj.set_ca_path(val_r.asString()); }
240
242 { return _impl->_settingsObj.ca_path(); }
243
244
245 void TransferSettings::setAuthType( std::string && val_r )
246 { _impl->_settingsObj.set_authtype( std::move(val_r) ); }
247
248 std::string TransferSettings::authType() const
249 { return _impl->_settingsObj.authtype(); }
250
251
253 { _impl->_settingsObj.set_head_requests_allowed(allowed); }
254
256 { return _impl->_settingsObj.head_requests_allowed(); }
257
258 } // namespace media
259} // namespace zypp
260
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:126
zypp::proto::TransferSettings _settingsObj
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
std::string proxyPassword() const
proxy auth password
void setClientCertificatePath(Pathname &&val_r)
Sets the SSL client certificate file.
const zypp::proto::TransferSettings & protoData() const
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)
std::vector< std::string > Headers
RWCOW_pointer< Impl > _impl
Headers headers() const
returns a list of all added headers
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.
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2