libzypp  17.22.0
request.cc
Go to the documentation of this file.
7 #include <zypp/ZConfig.h>
8 #include <zypp/base/Logger.h>
9 #include <zypp/base/String.h>
10 #include <zypp/Pathname.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <strstream>
14 
15 
16 namespace zyppng {
17 
18  std::vector<char> peek_data_fd( FILE *fd, off_t offset, size_t count )
19  {
20  if ( !fd )
21  return {};
22 
23  fflush( fd );
24 
25  std::vector<char> data( count + 1 , '\0' );
26 
27  ssize_t l = -1;
28  while ((l = pread( fileno( fd ), data.data(), count, offset ) ) == -1 && errno == EINTR)
29  ;
30  if (l == -1)
31  return {};
32 
33  return data;
34  }
35 
37  : _url ( std::move(url) )
38  , _targetFile ( std::move( targetFile) )
39  , _start ( std::move(start) )
40  , _len ( std::move(len) )
41  , _fMode ( std::move(fMode) )
42  , _activityTimer ( Timer::create() )
43  , _headers( std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >( nullptr, &curl_slist_free_all ) )
44  {
45  _activityTimer->sigExpired().connect( sigc::mem_fun( this, &NetworkRequestPrivate::onActivityTimeout ));
46  }
47 
49  {
50  if ( _easyHandle ) {
51  //clean up for now, later we might reuse handles
52  curl_easy_cleanup( _easyHandle );
53  //reset in request but make sure the request was not enqueued again and got a new handle
54  _easyHandle = nullptr;
55  }
56  }
57 
58  bool NetworkRequestPrivate::initialize( std::string &errBuf )
59  {
60  reset();
61 
62  if ( _easyHandle )
63  //will reset to defaults but keep live connections, session ID and DNS caches
64  curl_easy_reset( _easyHandle );
65  else
66  _easyHandle = curl_easy_init();
67 
68  _errorBuf.fill( '\0' );
69  curl_easy_setopt( _easyHandle, CURLOPT_ERRORBUFFER, this->_errorBuf.data() );
70 
71  try {
72 
73  setCurlOption( CURLOPT_PRIVATE, this );
75  setCurlOption( CURLOPT_XFERINFODATA, this );
76  setCurlOption( CURLOPT_NOPROGRESS, 0L);
77  setCurlOption( CURLOPT_FAILONERROR, 1L);
78  setCurlOption( CURLOPT_NOSIGNAL, 1L);
79 
80  std::string urlBuffer( _url.asString() );
81  setCurlOption( CURLOPT_URL, urlBuffer.c_str() );
82 
83  setCurlOption( CURLOPT_WRITEFUNCTION, NetworkRequestPrivate::writeCallback );
84  setCurlOption( CURLOPT_WRITEDATA, this );
85 
87  // instead of returning no data with NOBODY, we return
88  // little data, that works with broken servers, and
89  // works for ftp as well, because retrieving only headers
90  // ftp will return always OK code ?
91  // See http://curl.haxx.se/docs/knownbugs.html #58
92  if ( (_url.getScheme() == "http" || _url.getScheme() == "https") && _settings.headRequestsAllowed() )
93  setCurlOption( CURLOPT_NOBODY, 1L );
94  else
95  setCurlOption( CURLOPT_RANGE, "0-1" );
96  } else {
97  std::string rangeDesc;
98  if ( _start >= 0) {
99  _expectRangeStatus = true;
100  rangeDesc = zypp::str::form("%llu-", static_cast<unsigned long long>( _start ));
101  if( _len > 0 ) {
102  rangeDesc.append( zypp::str::form( "%llu", static_cast<unsigned long long>(_start + _len - 1) ) );
103  }
104  if ( setCurlOption( CURLOPT_RANGE, rangeDesc.c_str() ), CURLE_OK ) {
105  strncpy( _errorBuf.data(), "curl_easy_setopt range failed", CURL_ERROR_SIZE);
106  return false;
107  }
108  } else {
109  _expectRangeStatus = false;
110  }
111 
112  }
113 
114  //make a local copy of the settings, so headers are not added multiple times
115  TransferSettings locSet = _settings;
116 
117  // add custom headers for download.opensuse.org (bsc#955801)
118  if ( _url.getHost() == "download.opensuse.org" )
119  {
122  }
123 
124  locSet.addHeader("Pragma:");
125 
126  locSet.setTimeout( zypp::ZConfig::instance().download_transfer_timeout() );
128 
130 
131  {
132  char *ptr = getenv("ZYPP_MEDIA_CURL_DEBUG");
133  _curlDebug = (ptr && *ptr) ? zypp::str::strtonum<long>( ptr) : 0L;
134  if( _curlDebug > 0)
135  {
136  setCurlOption( CURLOPT_VERBOSE, 1L);
137  setCurlOption( CURLOPT_DEBUGFUNCTION, internal::log_curl);
138  setCurlOption( CURLOPT_DEBUGDATA, &_curlDebug);
139  }
140  }
141 
144  {
145  case 4: setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); break;
146  case 6: setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6 ); break;
147  default: break;
148  }
149 
150  setCurlOption( CURLOPT_HEADERFUNCTION, internal::log_redirects_curl );
151  setCurlOption( CURLOPT_HEADERDATA, &_lastRedirect );
152 
156  setCurlOption( CURLOPT_CONNECTTIMEOUT, locSet.connectTimeout() );
157  // If a transfer timeout is set, also set CURLOPT_TIMEOUT to an upper limit
158  // just in case curl does not trigger its progress callback frequently
159  // enough.
160  if ( locSet.timeout() )
161  {
162  setCurlOption( CURLOPT_TIMEOUT, 3600L );
163  }
164 
165  if ( _url.getScheme() == "https" )
166  {
167 #if CURLVERSION_AT_LEAST(7,19,4)
168  // restrict following of redirections from https to https only
169  setCurlOption( CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS );
170 #endif
171 
172 #if CURLVERSION_AT_LEAST(7,60,0) // SLE15+
173  setCurlOption( CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS );
174 #endif
175 
176  if( locSet.verifyPeerEnabled() ||
177  locSet.verifyHostEnabled() )
178  {
179  setCurlOption(CURLOPT_CAPATH, locSet.certificateAuthoritiesPath().c_str());
180  }
181 
182  if( ! locSet.clientCertificatePath().empty() )
183  {
184  setCurlOption(CURLOPT_SSLCERT, locSet.clientCertificatePath().c_str());
185  }
186  if( ! locSet.clientKeyPath().empty() )
187  {
188  setCurlOption(CURLOPT_SSLKEY, locSet.clientKeyPath().c_str());
189  }
190 
191 #ifdef CURLSSLOPT_ALLOW_BEAST
192  // see bnc#779177
193  setCurlOption( CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST );
194 #endif
195  setCurlOption(CURLOPT_SSL_VERIFYPEER, locSet.verifyPeerEnabled() ? 1L : 0L);
196  setCurlOption(CURLOPT_SSL_VERIFYHOST, locSet.verifyHostEnabled() ? 2L : 0L);
197  // bnc#903405 - POODLE: libzypp should only talk TLS
198  setCurlOption(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
199  }
200 
201  // follow any Location: header that the server sends as part of
202  // an HTTP header (#113275)
203  setCurlOption( CURLOPT_FOLLOWLOCATION, 1L);
204  // 3 redirects seem to be too few in some cases (bnc #465532)
205  setCurlOption( CURLOPT_MAXREDIRS, 6L );
206 
207  //set the user agent
208  setCurlOption(CURLOPT_USERAGENT, locSet.userAgentString().c_str() );
209 
210 
211  /*---------------------------------------------------------------*
212  CURLOPT_USERPWD: [user name]:[password]
213  Url::username/password -> CURLOPT_USERPWD
214  If not provided, anonymous FTP identification
215  *---------------------------------------------------------------*/
216  if ( locSet.userPassword().size() )
217  {
218  setCurlOption(CURLOPT_USERPWD, locSet.userPassword().c_str());
219  std::string use_auth = _settings.authType();
220  if (use_auth.empty())
221  use_auth = "digest,basic"; // our default
222  long auth = zypp::media::CurlAuthData::auth_type_str2long(use_auth);
223  if( auth != CURLAUTH_NONE)
224  {
225  DBG << "Enabling HTTP authentication methods: " << use_auth
226  << " (CURLOPT_HTTPAUTH=" << auth << ")" << std::endl;
227  setCurlOption(CURLOPT_HTTPAUTH, auth);
228  }
229  }
230 
231  if ( locSet.proxyEnabled() && ! locSet.proxy().empty() )
232  {
233  DBG << "Proxy: '" << locSet.proxy() << "'" << std::endl;
234  setCurlOption(CURLOPT_PROXY, locSet.proxy().c_str());
235  setCurlOption(CURLOPT_PROXYAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST|CURLAUTH_NTLM );
236 
237  /*---------------------------------------------------------------*
238  * CURLOPT_PROXYUSERPWD: [user name]:[password]
239  *
240  * Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
241  * If not provided, $HOME/.curlrc is evaluated
242  *---------------------------------------------------------------*/
243 
244  std::string proxyuserpwd = locSet.proxyUserPassword();
245 
246  if ( proxyuserpwd.empty() )
247  {
248  zypp::media::CurlConfig curlconf;
249  zypp::media::CurlConfig::parseConfig(curlconf); // parse ~/.curlrc
250  if ( curlconf.proxyuserpwd.empty() )
251  DBG << "Proxy: ~/.curlrc does not contain the proxy-user option" << std::endl;
252  else
253  {
254  proxyuserpwd = curlconf.proxyuserpwd;
255  DBG << "Proxy: using proxy-user from ~/.curlrc" << std::endl;
256  }
257  }
258  else
259  {
260  DBG << "Proxy: using provided proxy-user '" << _settings.proxyUsername() << "'" << std::endl;
261  }
262 
263  if ( ! proxyuserpwd.empty() )
264  {
265  setCurlOption(CURLOPT_PROXYUSERPWD, internal::curlUnEscape( proxyuserpwd ).c_str());
266  }
267  }
268 #if CURLVERSION_AT_LEAST(7,19,4)
269  else if ( locSet.proxy() == EXPLICITLY_NO_PROXY )
270  {
271  // Explicitly disabled in URL (see fillSettingsFromUrl()).
272  // This should also prevent libcurl from looking into the environment.
273  DBG << "Proxy: explicitly NOPROXY" << std::endl;
274  setCurlOption(CURLOPT_NOPROXY, "*");
275  }
276 
277 #endif
278  else
279  {
280  DBG << "Proxy: not explicitly set" << std::endl;
281  DBG << "Proxy: libcurl may look into the environment" << std::endl;
282  }
283 
285  if ( locSet.minDownloadSpeed() != 0 )
286  {
287  setCurlOption(CURLOPT_LOW_SPEED_LIMIT, locSet.minDownloadSpeed());
288  // default to 10 seconds at low speed
289  setCurlOption(CURLOPT_LOW_SPEED_TIME, 60L);
290  }
291 
292 #if CURLVERSION_AT_LEAST(7,15,5)
293  if ( locSet.maxDownloadSpeed() != 0 )
294  setCurlOption(CURLOPT_MAX_RECV_SPEED_LARGE, locSet.maxDownloadSpeed());
295 #endif
296 
297  if ( zypp::str::strToBool( _url.getQueryParam( "cookies" ), true ) )
298  setCurlOption( CURLOPT_COOKIEFILE, _currentCookieFile.c_str() );
299  else
300  MIL << "No cookies requested" << std::endl;
301  setCurlOption(CURLOPT_COOKIEJAR, _currentCookieFile.c_str() );
302 
303 #if CURLVERSION_AT_LEAST(7,18,0)
304  // bnc #306272
305  setCurlOption(CURLOPT_PROXY_TRANSFER_MODE, 1L );
306 #endif
307 
308  // append settings custom headers to curl
309  for ( TransferSettings::Headers::const_iterator it = locSet.headersBegin();
310  it != locSet.headersEnd();
311  ++it ) {
312  if ( !z_func()->addRequestHeader( it->c_str() ) )
314  }
315 
316  if ( _headers )
317  setCurlOption( CURLOPT_HTTPHEADER, _headers.get() );
318 
319  return true;
320 
321  } catch ( const zypp::Exception &excp ) {
322  ZYPP_CAUGHT(excp);
323  errBuf = excp.asString();
324  }
325  return false;
326  }
327 
329  {
330  if ( _activityTimer )
331  _activityTimer->start( static_cast<uint64_t>( _settings.timeout() ) * 1000 );
332 
334  _sigStarted.emit( *z_func() );
335  }
336 
338  {
339  if ( _outFile )
340  fclose( _outFile );
341  _outFile = nullptr;
342 
343  _result = std::move(err);
344 
345  if ( _activityTimer )
346  _activityTimer->stop();
347 
349  //we have a successful download, lets see if the checksum is fine IF we have one
351  if ( _expectedChecksum.size() && _digest ) {
352  if ( _digest->digestVector() != _expectedChecksum ) {
354 
355  auto hexToStr = []( const std::vector<u_char> &hex ) {
356  std::string res;
357  for (std::vector<u_char>::size_type j = 0; j < hex.size(); j++)
358  res += zypp::str::form("%02hhx", hex[j]);
359  return res;
360  };
361 
362  _result = NetworkRequestErrorPrivate::customError( NetworkRequestError::InvalidChecksum, (zypp::str::Format("Invalid checksum %1%, expected checksum %2%") % _digest->digest() % hexToStr( _expectedChecksum ) ) );
363  }
364  }
365  } else
367 
368  _sigFinished.emit( *z_func(), _result );
369  }
370 
372  {
373  if ( _outFile )
374  fclose( _outFile );
375 
376  if ( _digest )
377  _digest->reset();
378 
379  _outFile = nullptr;
380  _easyHandle = nullptr;
383  _downloaded = -1;
384  _reportedSize = 0;
385  _errorBuf.fill( 0 );
386  _headers.reset( nullptr );
387  }
388 
390  {
391  std::map<std::string, boost::any> extraInfo;
392  extraInfo.insert( {"requestUrl", _url } );
393  extraInfo.insert( {"filepath", _targetFile } );
394  _dispatcher->cancel( *z_func(), NetworkRequestErrorPrivate::customError( NetworkRequestError::Timeout, "Download timed out", std::move(extraInfo) ) );
395  }
396 
397  int NetworkRequestPrivate::curlProgressCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow )
398  {
399  if ( !clientp )
400  return 0;
401  NetworkRequestPrivate *that = reinterpret_cast<NetworkRequestPrivate *>( clientp );
402 
403  //reset the timer
404  if ( that->_activityTimer && that->_activityTimer->isRunning() )
405  that->_activityTimer->start();
406 
407  //keep signals to a minimum
408  if ( that->_downloaded == dlnow )
409  return 0;
410 
411  that->_downloaded = dlnow;
412  that->_reportedSize = dltotal;
413 
414  if ( that->_len > 0 && that->_len < dlnow ) {
416  return 0;
417  }
418 
419  that->_sigProgress.emit( *that->z_func(), dltotal, dlnow, ultotal, ulnow );
420  return 0;
421  }
422 
423  size_t NetworkRequestPrivate::writeCallback( char *ptr, size_t size, size_t nmemb, void *userdata )
424  {
425  if ( !userdata )
426  return 0;
427 
428  //it is valid to call this function with no data to write, just return OK
429  if ( size * nmemb == 0)
430  return 0;
431 
432  NetworkRequestPrivate *that = reinterpret_cast<NetworkRequestPrivate *>( userdata );
433 
434  //in case of a HEAD request, we do not write anything
435  if ( that->_options & NetworkRequest::HeadRequest ) {
436  return ( size * nmemb );
437  }
438 
439  //If we expect a file range we better double check that we got the status code for it
440  if ( that->_expectRangeStatus ) {
441  char *effurl;
442  (void)curl_easy_getinfo( that->_easyHandle, CURLINFO_EFFECTIVE_URL, &effurl);
443  if (effurl && !strncasecmp(effurl, "http", 4))
444  {
445  long statuscode = 0;
446  (void)curl_easy_getinfo( that->_easyHandle, CURLINFO_RESPONSE_CODE, &statuscode);
447  if (statuscode != 206) {
448  strncpy( that->_errorBuf.data(), "Expected range status code 206, but got none.", CURL_ERROR_SIZE);
449  return 0;
450  }
451  }
452  }
453 
454  if ( !that->_outFile ) {
455  std::string openMode = "w+b";
456  if ( that->_fMode == NetworkRequest::WriteShared )
457  openMode = "r+b";
458 
459  that->_outFile = fopen( that->_targetFile.asString().c_str() , openMode.c_str() );
460 
461  //if the file does not exist create a new one
462  if ( !that->_outFile && that->_fMode == NetworkRequest::WriteShared ) {
463  that->_outFile = fopen( that->_targetFile.asString().c_str() , "w+b" );
464  }
465 
466  if ( !that->_outFile ) {
467  strncpy( that->_errorBuf.data(), "Unable to open target file.", CURL_ERROR_SIZE);
468  return 0;
469  }
470 
471  if ( that->_start > 0 )
472  if ( fseek( that->_outFile, that->_start, SEEK_SET ) != 0 ) {
473  strncpy( that->_errorBuf.data(), "Unable to set output file pointer.", CURL_ERROR_SIZE);
474  return 0;
475  }
476  }
477 
478  size_t written = fwrite( ptr, size, nmemb, that->_outFile );
479  if ( that->_digest ) {
480  that->_digest->update( ptr, written );
481  }
482 
483  return written;
484  }
485 
487  : Base ( *new NetworkRequestPrivate( std::move(url), std::move(targetFile), std::move(start), std::move(len), std::move(fMode) ) )
488  {
489  }
490 
492  {
493  Z_D();
494 
495  if ( d->_dispatcher )
496  d->_dispatcher->cancel( *this, "Request destroyed while still running" );
497 
498  if ( d->_outFile )
499  fclose( d->_outFile );
500  }
501 
503  {
504  d_func()->_priority = prio;
505  }
506 
508  {
509  return d_func()->_priority;
510  }
511 
512  void NetworkRequest::setOptions( Options opt )
513  {
514  d_func()->_options = opt;
515  }
516 
517  NetworkRequest::Options NetworkRequest::options() const
518  {
519  return d_func()->_options;
520  }
521 
522  void NetworkRequest::setRequestRange(off_t start, off_t len)
523  {
524  Z_D();
525  if ( d->_state == Running )
526  return;
527  d->_start = start;
528  d->_len = len;
529  }
530 
531  const std::string &NetworkRequest::lastRedirectInfo() const
532  {
533  return d_func()->_lastRedirect;
534  }
535 
537  {
538  return d_func()->_easyHandle;
539  }
540 
541  std::vector<char> NetworkRequest::peekData( off_t offset, size_t count ) const
542  {
543  Z_D();
544  return peek_data_fd( d->_outFile, offset, count );
545  }
546 
548  {
549  return d_func()->_url;
550  }
551 
553  {
554  Z_D();
555  if ( d->_state == NetworkRequest::Running )
556  return;
557 
558  d->_url = url;
559  }
560 
562  {
563  return d_func()->_targetFile;
564  }
565 
566  std::string NetworkRequest::contentType() const
567  {
568  char *ptr = NULL;
569  if ( curl_easy_getinfo( d_func()->_easyHandle, CURLINFO_CONTENT_TYPE, &ptr ) == CURLE_OK && ptr )
570  return std::string(ptr);
571  return std::string();
572  }
573 
575  {
576  return d_func()->_start;
577  }
578 
580  {
581  return d_func()->_reportedSize;
582  }
583 
585  {
586  return d_func()->_len;
587  }
588 
590  {
591  Z_D();
592  if ( d->_downloaded == -1 )
593  return 0;
594  return d->_downloaded;
595  }
596 
597  void NetworkRequest::setDigest( std::shared_ptr<zypp::Digest> dig )
598  {
599  d_func()->_digest = dig;
600  }
601 
602  void NetworkRequest::setExpectedChecksum(std::vector<unsigned char> checksum )
603  {
604  d_func()->_expectedChecksum = std::move(checksum);
605  }
606 
608  {
609  return d_func()->_settings;
610  }
611 
612  std::shared_ptr<zypp::Digest> NetworkRequest::digest( ) const
613  {
614  return d_func()->_digest;
615  }
616 
618  {
619  return d_func()->_state;
620  }
621 
623  {
624  return d_func()->_result;
625  }
626 
628  {
629  Z_D();
630  if ( !hasError() )
631  return std::string();
632 
633  return d->_result.nativeErrorString();
634  }
635 
637  {
638  return error().isError();
639  }
640 
641  bool NetworkRequest::addRequestHeader( const std::string &header )
642  {
643  Z_D();
644 
645  curl_slist *res = curl_slist_append( d->_headers ? d->_headers.get() : nullptr, header.c_str() );
646  if ( !res )
647  return false;
648 
649  if ( !d->_headers )
650  d->_headers = std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >( res, &curl_slist_free_all );
651 
652  return true;
653  }
654 
656  {
657  return d_func()->_sigStarted;
658  }
659 
661  {
662  return d_func()->_sigProgress;
663  }
664 
666  {
667  return d_func()->_sigFinished;
668  }
669 
670 
671 }
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
long timeout() const
transfer timeout
std::string authType() const
get the allowed authentication types
bool isError() const
isError Will return true if this is a actual error
#define MIL
Definition: Logger.h:79
void setCurlOption(CURLoption opt, T data)
Definition: request_p.h:30
void * nativeHandle() const
Definition: request.cc:536
const NetworkRequestError & error() const
Returns the last set Error.
Definition: request.cc:622
std::array< char, CURL_ERROR_SIZE+1 > _errorBuf
Definition: request_p.h:60
void addHeader(std::string &&val_r)
add a header, on the form "Foo: Bar"
size_t log_redirects_curl(char *ptr, size_t size, size_t nmemb, void *userdata)
Definition: CurlHelper.cc:53
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:124
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
const char * anonymousIdHeader()
initialized only once, this gets the anonymous id from the target, which we pass in the http header ...
Definition: CurlHelper.cc:285
Pathname clientCertificatePath() const
SSL client certificate file.
NetworkRequest::FileMode _fMode
Definition: request_p.h:52
const std::string & lastRedirectInfo() const
Definition: request.cc:531
signal< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> _sigProgress
Definition: request_p.h:70
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
std::string proxy() const
proxy host
Holds transfer setting.
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata)
Definition: request.cc:423
NetworkRequest::Options _options
Definition: request_p.h:41
bool verifyHostEnabled() const
Whether to verify host for ssl.
std::shared_ptr< zypp::Digest > digest() const
Returns the currently used.
Definition: request.cc:612
const char * c_str() const
String representation.
Definition: Pathname.h:110
NetworkRequest::State _state
Definition: request_p.h:58
NetworkRequestPrivate(Url &&url, zypp::Pathname &&targetFile, off_t &&start, off_t &&len, NetworkRequest::FileMode fMode)
Definition: request.cc:36
Pathname certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
Definition: Arch.h:347
Url url
Definition: MediaCurl.cc:65
void setConnectTimeout(long t)
set the connect timeout
signal< void(NetworkRequest &req)> _sigStarted
Definition: request_p.h:69
off_t expectedByteCount() const
Returns the expected byte count that was passed to the constructor, zero if none was given...
Definition: request.cc:584
Convenient building of std::string with boost::format.
Definition: String.h:249
Structure holding values of curlrc options.
Definition: CurlConfig.h:16
void setOptions(Options opt)
Definition: request.cc:512
Headers::const_iterator headersEnd() const
end iterators to additional headers
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
std::string userAgentString() const
user agent string
TransferSettings & transferSettings()
Definition: request.cc:607
const char * distributionFlavorHeader()
initialized only once, this gets the distribution flavor from the target, which we pass in the http h...
Definition: CurlHelper.cc:299
bool hasError() const
Checks if there was a error with the request.
Definition: request.cc:636
void onActivityTimeout(Timer &)
Definition: request.cc:389
#define Z_D()
Definition: zyppglobal.h:44
zypp::Pathname _targetFile
Definition: request_p.h:39
virtual ~NetworkRequestPrivate()
Definition: request.cc:48
std::vector< unsigned char > _expectedChecksum
Definition: request_p.h:56
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
void setUrl(const Url &url)
This will change the URL of the request.
Definition: request.cc:552
static int parseConfig(CurlConfig &config, const std::string &filename="")
Parse a curlrc file and store the result in the config structure.
Definition: CurlConfig.cc:24
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:492
void setDigest(std::shared_ptr< zypp::Digest > dig)
Set a.
Definition: request.cc:597
std::string getQueryParam(const std::string &param, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
Definition: Url.cc:655
bool addRequestHeader(const std::string &header)
Definition: request.cc:641
const std::string & asString() const
String representation.
Definition: Pathname.h:91
std::string asString() const
Error message provided by dumpOn as string.
Definition: Exception.cc:75
long connectTimeout() const
connection timeout
bool initialize(std::string &errBuf)
Definition: request.cc:58
The NetworkRequestError class Represents a error that occured in.
The Timer class provides repetitive and single-shot timers.
Definition: timer.h:42
std::vector< char > peekData(off_t offset, size_t count) const
Definition: request.cc:541
std::string extendedErrorString() const
In some cases curl can provide extended error informations collected at runtime.
Definition: request.cc:627
void setTimeout(long t)
set the transfer timeout
Priority priority() const
Definition: request.cc:507
#define nullptr
Definition: Easy.h:55
Headers::const_iterator headersBegin() const
begin iterators to additional headers
std::string proxyuserpwd
Definition: CurlConfig.h:39
Pathname clientKeyPath() const
SSL client key file.
std::shared_ptr< zypp::Digest > _digest
Definition: request_p.h:55
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
Definition: request.cc:561
SolvableIdType size_type
Definition: PoolMember.h:126
std::unique_ptr< curl_slist, decltype(&curl_slist_free_all) > _headers
Definition: request_p.h:76
long minDownloadSpeed() const
Minimum download speed (bytes per second) until the connection is dropped.
std::vector< char > peek_data_fd(FILE *fd, off_t offset, size_t count)
Definition: request.cc:18
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
bool proxyEnabled() const
proxy is enabled
static int curlProgressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Definition: request.cc:397
std::string contentType() const
Returns the content type as reported from the server.
Definition: request.cc:566
NetworkRequestError _result
Definition: request_p.h:59
Base class for Exception.
Definition: Exception.h:145
std::string _lastRedirect
to log/report redirections
Definition: request_p.h:44
#define CONNECT_TIMEOUT
Definition: CurlHelper.h:21
std::string checksum(const Pathname &file, const std::string &algorithm)
Compute a files checksum.
Definition: PathInfo.cc:1004
std::string curlUnEscape(std::string text_r)
Definition: CurlHelper.cc:342
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:583
signal< void(NetworkRequest &req, const NetworkRequestError &err)> _sigFinished
Definition: request_p.h:71
State state() const
Returns the current state the HttpDownloadRequest is in.
Definition: request.cc:617
TransferSettings _settings
Definition: request_p.h:40
NetworkRequestDispatcher * _dispatcher
Definition: request_p.h:64
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition: String.h:426
static long auth_type_str2long(std::string &auth_type_str)
Converts a string of comma separated list of authetication type names into a long of ORed CURLAUTH_* ...
virtual ~NetworkRequest()
Definition: request.cc:491
void setUserAgentString(std::string &&val_r)
sets the user agent ie: "Mozilla v3"
Options options() const
Definition: request.cc:517
off_t downloadOffset() const
Returns the requested start offset.
Definition: request.cc:574
const char * agentString()
initialized only once, this gets the agent string which also includes the curl version ...
Definition: CurlHelper.cc:313
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
Definition: request.cc:665
std::string _currentCookieFile
Definition: request_p.h:45
void setPriority(Priority prio)
Definition: request.cc:502
Type type() const
type Returns the type of the error
SignalProxy< void(NetworkRequest &req)> sigStarted()
Signals that the dispatcher dequeued the request and actually starts downloading data.
Definition: request.cc:655
void setExpectedChecksum(std::vector< unsigned char > checksum)
Enables automated checking of downloaded contents against a checksum.
Definition: request.cc:602
std::string userPassword() const
returns the user and password as a user:pass string
std::string proxyUsername() const
proxy auth username
off_t downloadedByteCount() const
Returns the number of already downloaded bytes as reported by the backend.
Definition: request.cc:589
int log_curl(CURL *curl, curl_infotype info, char *ptr, size_t len, void *max_lvl)
Definition: CurlHelper.cc:27
void setResult(NetworkRequestError &&err)
Definition: request.cc:337
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
SignalProxy< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> sigProgress()
Signals if there was data read from the download.
Definition: request.cc:660
off_t reportedByteCount() const
Returns the number of bytes that are reported from the backend as the full download size...
Definition: request.cc:579
Convenience interface for handling authentication data of media user.
#define EXPLICITLY_NO_PROXY
Definition: CurlHelper.h:25
Url manipulation class.
Definition: Url.h:87
bool headRequestsAllowed() const
whether HEAD requests are allowed
int ZYPP_MEDIA_CURL_IPRESOLVE()
Definition: CurlHelper.h:36
#define DBG
Definition: Logger.h:78
void setRequestRange(off_t start=-1, off_t len=0)
Definition: request.cc:522
NetworkRequest(Url url, zypp::Pathname targetFile, off_t start=-1, off_t len=0, FileMode fMode=WriteExclusive)
Definition: request.cc:486