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 #include <transfersettings.pb.h>
14 
15 using std::endl;
16 
17 #define CURL_BINARY "/usr/bin/curl"
18 
19 namespace 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 
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 
107  std::string TransferSettings::userPassword() const
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 
zypp::media::TransferSettings::verifyHostEnabled
bool verifyHostEnabled() const
Whether to verify host for ssl.
Definition: TransferSettings.cc:204
zypp::media::TransferSettings::Impl::_settingsObj
zypp::proto::TransferSettings _settingsObj
Definition: TransferSettings.cc:58
ExternalProgram.h
zypp::media::TransferSettings::verifyPeerEnabled
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
Definition: TransferSettings.cc:211
zypp::media::TransferSettings::setConnectTimeout
void setConnectTimeout(long t)
set the connect timeout
Definition: TransferSettings.cc:166
zypp::media::TransferSettings::userPassword
std::string userPassword() const
returns the user and password as a user:pass string
Definition: TransferSettings.cc:107
zypp::media::TransferSettings::reset
void reset()
reset the settings to the defaults
Definition: TransferSettings.cc:71
WatchFile.h
zypp::media::TransferSettings::proxyPassword
std::string proxyPassword() const
proxy auth password
Definition: TransferSettings.cc:146
zypp::media::TransferSettings::setTimeout
void setTimeout(long t)
set the transfer timeout
Definition: TransferSettings.cc:159
zypp::media::TransferSettings::setMaxSilentTries
void setMaxSilentTries(long v)
Set maximum silent retries.
Definition: TransferSettings.cc:194
zypp::media::TransferSettings::username
std::string username() const
auth username
Definition: TransferSettings.cc:98
zypp::media::TransferSettings::minDownloadSpeed
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
Definition: TransferSettings.cc:183
ZConfig.h
zypp::media::TransferSettings::certificateAuthoritiesPath
Pathname certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
Definition: TransferSettings.cc:241
zypp::media::TransferSettings::timeout
long timeout() const
transfer timeout
Definition: TransferSettings.cc:162
zypp::media::TransferSettings::authType
std::string authType() const
get the allowed authentication types
Definition: TransferSettings.cc:248
zypp::media::TransferSettings::setMaxConcurrentConnections
void setMaxConcurrentConnections(long v)
Set maximum number of concurrent connections for a single transfer.
Definition: TransferSettings.cc:173
zypp::media::TransferSettings::maxConcurrentConnections
long maxConcurrentConnections() const
Maximum number of concurrent connections for a single transfer.
Definition: TransferSettings.cc:176
zypp::media::TransferSettings::proxyUserPassword
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
Definition: TransferSettings.cc:149
zypp::media::TransferSettings::headRequestsAllowed
bool headRequestsAllowed() const
whether HEAD requests are allowed
Definition: TransferSettings.cc:255
zypp::media::TransferSettings::Impl::~Impl
virtual ~Impl()
Definition: TransferSettings.cc:40
zypp::media::TransferSettings::setVerifyHostEnabled
void setVerifyHostEnabled(bool enabled)
Sets whether to verify host for ssl.
Definition: TransferSettings.cc:201
zypp::media::TransferSettings::proxyEnabled
bool proxyEnabled() const
proxy is enabled
Definition: TransferSettings.cc:126
zypp::media::TransferSettings
Holds transfer setting.
Definition: TransferSettings.h:25
zypp::media::TransferSettings::setProxyEnabled
void setProxyEnabled(bool enabled)
whether the proxy is used or not
Definition: TransferSettings.cc:123
zypp::media::TransferSettings::setUsername
void setUsername(std::string &&val_r)
sets the auth username
Definition: TransferSettings.cc:95
zypp::media::TransferSettings::setClientCertificatePath
void setClientCertificatePath(Pathname &&val_r)
Sets the SSL client certificate file.
Definition: TransferSettings.cc:215
zypp::media::TransferSettings::setHeadRequestsAllowed
void setHeadRequestsAllowed(bool allowed)
set whether HEAD requests are allowed
Definition: TransferSettings.cc:252
zypp::media::TransferSettings::headers
Headers headers() const
returns a list of all added headers
Definition: TransferSettings.cc:78
zypp::media::TransferSettings::maxSilentTries
long maxSilentTries() const
Maximum silent retries.
Definition: TransferSettings.cc:197
zypp::media::TransferSettings::proxyUsername
std::string proxyUsername() const
proxy auth username
Definition: TransferSettings.cc:140
zypp::media::TransferSettings::Impl::_headers
std::vector< std::string > _headers
Definition: TransferSettings.cc:57
Logger.h
zypp::media::TransferSettings::setProxy
void setProxy(std::string &&val_r)
proxy to use if it is enabled
Definition: TransferSettings.cc:130
zypp::media::TransferSettings::Impl::nullimpl
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: TransferSettings.cc:44
TransferSettings.h
zypp::media::TransferSettings::Impl
Definition: TransferSettings.cc:24
zypp::media::TransferSettings::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition: TransferSettings.cc:53
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:126
zypp::media::TransferSettings::protoData
const zypp::proto::TransferSettings & protoData() const
Definition: TransferSettings.cc:233
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::media::TransferSettings::userAgentString
std::string userAgentString() const
user agent string
Definition: TransferSettings.cc:91
zypp::media::TransferSettings::clientKeyPath
Pathname clientKeyPath() const
SSL client key file.
Definition: TransferSettings.cc:225
zypp::media::TransferSettings::clientCertificatePath
Pathname clientCertificatePath() const
SSL client certificate file.
Definition: TransferSettings.cc:218
zypp::media::TransferSettings::setVerifyPeerEnabled
void setVerifyPeerEnabled(bool enabled)
Sets whether to verify host for ssl.
Definition: TransferSettings.cc:208
zypp::media::TransferSettings::setMaxDownloadSpeed
void setMaxDownloadSpeed(long v)
Set max download speed (bytes per second)
Definition: TransferSettings.cc:187
Impl
zypp::media::TransferSettings::setProxyPassword
void setProxyPassword(std::string &&val_r)
sets the proxy password
Definition: TransferSettings.cc:143
zypp::media::TransferSettings::TransferSettings
TransferSettings()
Constructs a transfer program cmd line access.
Definition: TransferSettings.cc:61
zypp::media::TransferSettings::addHeader
void addHeader(std::string &&val_r)
add a header, on the form "Foo: Bar"
Definition: TransferSettings.cc:75
ReferenceCounted.h
zypp::media::TransferSettings::Headers
std::vector< std::string > Headers
Definition: TransferSettings.h:32
String.h
zypp::media::TransferSettings::setAuthType
void setAuthType(std::string &&val_r)
set the allowed authentication types
Definition: TransferSettings.cc:245
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:222
zypp::media::TransferSettings::setPassword
void setPassword(std::string &&val_r)
sets the auth password
Definition: TransferSettings.cc:101
zypp::media::TransferSettings::setMinDownloadSpeed
void setMinDownloadSpeed(long v)
Set minimum download speed (bytes per second) until the connection is dropped.
Definition: TransferSettings.cc:180
zypp::media::TransferSettings::setProxyUsername
void setProxyUsername(std::string &&val_r)
sets the proxy user
Definition: TransferSettings.cc:137
zypp::media::TransferSettings::setCertificateAuthoritiesPath
void setCertificateAuthoritiesPath(Pathname &&val_r)
Sets the SSL certificate authorities path.
Definition: TransferSettings.cc:238
zypp::media::TransferSettings::connectTimeout
long connectTimeout() const
connection timeout
Definition: TransferSettings.cc:169
zypp::media::TransferSettings::Impl::Impl
Impl()
Definition: TransferSettings.cc:26
zypp::media::TransferSettings::setUserAgentString
void setUserAgentString(std::string &&val_r)
sets the user agent ie: "Mozilla v3"
Definition: TransferSettings.cc:88
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:116
zypp::media::TransferSettings::proxy
std::string proxy() const
proxy host
Definition: TransferSettings.cc:133
zypp::media::TransferSettings::password
std::string password() const
auth password
Definition: TransferSettings.cc:104
zypp::media::TransferSettings::_impl
RWCOW_pointer< Impl > _impl
Definition: TransferSettings.h:194
NonCopyable.h
zypp::media::TransferSettings::maxDownloadSpeed
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
Definition: TransferSettings.cc:190