libzypp  17.28.5
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>
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 
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 
long timeout() const
transfer timeout
std::string authType() const
get the allowed authentication types
std::string password() const
auth password
zypp::proto::TransferSettings _settingsObj
void addHeader(std::string &&val_r)
add a header, on the form "Foo: Bar"
void setAuthType(std::string &&val_r)
set the allowed authentication types
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:126
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
Pathname clientCertificatePath() const
SSL client certificate file.
void setUsername(std::string &&val_r)
sets the auth username
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
std::string proxy() const
proxy host
Holds transfer setting.
bool verifyHostEnabled() const
Whether to verify host for ssl.
void setHeadRequestsAllowed(bool allowed)
set whether HEAD requests are allowed
Pathname certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
std::string username() const
auth username
Headers headers() const
returns a list of all added headers
void setConnectTimeout(long t)
set the connect timeout
std::string userAgentString() const
user agent string
void setClientCertificatePath(Pathname &&val_r)
Sets the SSL client certificate file.
void setAnonymousAuth()
sets anonymous authentication (ie: for ftp)
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
long maxSilentTries() const
Maximum silent retries.
void setProxyPassword(std::string &&val_r)
sets the proxy password
static shared_ptr< Impl > nullimpl()
Offer default Impl.
long connectTimeout() const
connection timeout
void setClientKeyPath(Pathname &&val_r)
Sets the SSL client key file.
std::vector< std::string > _headers
std::vector< std::string > Headers
TransferSettings()
Constructs a transfer program cmd line access.
void setMaxSilentTries(long v)
Set maximum silent retries.
std::string proxyPassword() const
proxy auth password
void setTimeout(long t)
set the transfer timeout
void setProxyUsername(std::string &&val_r)
sets the proxy user
Pathname clientKeyPath() const
SSL client key file.
const zypp::proto::TransferSettings & protoData() const
RWCOW_pointer< Impl > _impl
void setMaxDownloadSpeed(long v)
Set max download speed (bytes per second)
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
Impl * clone() const
clone for RWCOW_pointer
bool proxyEnabled() const
proxy is enabled
void setProxy(std::string &&val_r)
proxy to use if it is enabled
void reset()
reset the settings to the defaults
void setMaxConcurrentConnections(long v)
Set maximum number of concurrent connections for a single transfer.
long maxConcurrentConnections() const
Maximum number of concurrent connections for a single transfer.
void setUserAgentString(std::string &&val_r)
sets the user agent ie: "Mozilla v3"
std::string userPassword() const
returns the user and password as a user:pass string
void setPassword(std::string &&val_r)
sets the auth password
std::string proxyUsername() const
proxy auth username
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
void setMinDownloadSpeed(long v)
Set minimum download speed (bytes per second) until the connection is dropped.
void setCertificateAuthoritiesPath(Pathname &&val_r)
Sets the SSL certificate authorities path.
void setVerifyPeerEnabled(bool enabled)
Sets whether to verify host for ssl.
void setVerifyHostEnabled(bool enabled)
Sets whether to verify host for ssl.
bool headRequestsAllowed() const
whether HEAD requests are allowed
void setProxyEnabled(bool enabled)
whether the proxy is used or not