libzypp 17.37.6
MediaCurl.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
13#include <iostream>
14#include <chrono>
15#include <list>
16
17#include <zypp/base/Logger.h>
19#include <zypp/base/String.h>
20#include <zypp/base/Gettext.h>
21#include <utility>
22#include <zypp-core/parser/Sysconfig>
23#include <zypp/base/Gettext.h>
24
28#include <zypp-curl/ProxyInfo>
29#include <zypp-curl/auth/CurlAuthData>
30#include <zypp-media/auth/CredentialManager>
31#include <zypp-curl/CurlConfig>
32#include <zypp/Target.h>
33#include <zypp/ZYppFactory.h>
34#include <zypp/ZConfig.h>
35#include <zypp/zypp_detail/ZYppImpl.h> // for zypp_poll
36
37#include <cstdlib>
38#include <sys/types.h>
39#include <sys/stat.h>
40#include <sys/mount.h>
41#include <dirent.h>
42#include <unistd.h>
43#include <glib.h>
44
46
47using std::endl;
48
49namespace internal {
50 using namespace zypp;
52 {
53 ProgressData( CURL *curl, time_t timeout = 0, zypp::Url url = zypp::Url(),
54 zypp::ByteCount expectedFileSize_r = 0,
56
57 void updateStats( curl_off_t dltotal = 0.0, curl_off_t dlnow = 0.0 );
58
59 int reportProgress() const;
60
61 CURL * curl()
62 { return _curl; }
63
64 bool timeoutReached() const
65 { return _timeoutReached; }
66
67 bool fileSizeExceeded() const
68 { return _fileSizeExceeded; }
69
72
73 void expectedFileSize( ByteCount newval_r )
74 { _expectedFileSize = newval_r; }
75
76 private:
77 CURL * _curl;
79 time_t _timeout;
84
85 time_t _timeStart = 0;
86 time_t _timeLast = 0;
87 time_t _timeRcv = 0;
88 time_t _timeNow = 0;
89
90 curl_off_t _dnlTotal = 0.0;
91 curl_off_t _dnlLast = 0.0;
92 curl_off_t _dnlNow = 0.0;
93
94 int _dnlPercent= 0;
95
96 double _drateTotal= 0.0;
97 double _drateLast = 0.0;
98 };
99
100
101
103 : _curl( curl )
104 , _url(std::move( url ))
105 , _timeout( timeout )
106 , _timeoutReached( false )
107 , _fileSizeExceeded ( false )
108 , _expectedFileSize( expectedFileSize_r )
109 , report( _report )
110 {}
111
112 void ProgressData::updateStats( curl_off_t dltotal, curl_off_t dlnow )
113 {
114 time_t now = _timeNow = time(0);
115
116 // If called without args (0.0), recompute based on the last values seen
117 if ( dltotal && dltotal != _dnlTotal )
118 _dnlTotal = dltotal;
119
120 if ( dlnow && dlnow != _dnlNow )
121 {
122 _timeRcv = now;
123 _dnlNow = dlnow;
124 }
125
126 // init or reset if time jumps back
127 if ( !_timeStart || _timeStart > now )
128 _timeStart = _timeLast = _timeRcv = now;
129
130 // timeout condition
131 if ( _timeout )
132 _timeoutReached = ( (now - _timeRcv) > _timeout );
133
134 // check if the downloaded data is already bigger than what we expected
136
137 // percentage:
138 if ( _dnlTotal )
139 _dnlPercent = int( _dnlNow * 100 / _dnlTotal );
140
141 // download rates:
142 _drateTotal = double(_dnlNow) / std::max( int(now - _timeStart), 1 );
143
144 if ( _timeLast < now )
145 {
146 _drateLast = double(_dnlNow - _dnlLast) / int(now - _timeLast);
147 // start new period
148 _timeLast = now;
150 }
151 else if ( _timeStart == _timeLast )
153 }
154
156 {
157 if ( _fileSizeExceeded )
158 return 1;
159 if ( _timeoutReached )
160 return 1; // no-data timeout
161 if ( report && !(*report)->progress( _dnlPercent, _url, _drateTotal, _drateLast ) )
162 return 1; // user requested abort
163 return 0;
164 }
165
170 {
171 public:
173 const std::string & err_r,
174 const std::string & msg_r )
175 : media::MediaCurlException( url_r, err_r, msg_r )
176 {}
177 //~MediaCurlExceptionMayRetryInternaly() noexcept {}
178 };
179
180}
181
182
183using namespace internal;
184using namespace zypp::base;
185
186namespace zypp {
187
188 namespace media {
189
190Pathname MediaCurl::_cookieFile = "/var/lib/YaST2/cookies";
191
192// we use this define to unbloat code as this C setting option
193// and catching exception is done frequently.
195#define SET_OPTION(opt,val) do { \
196 ret = curl_easy_setopt ( curl, opt, val ); \
197 if ( ret != 0) { \
198 ZYPP_THROW(MediaCurlSetOptException(_origin.at(rData.mirror).url(), _curlError)); \
199 } \
200 } while ( false )
201
202#define SET_OPTION_OFFT(opt,val) SET_OPTION(opt,(curl_off_t)val)
203#define SET_OPTION_LONG(opt,val) SET_OPTION(opt,(long)val)
204#define SET_OPTION_VOID(opt,val) SET_OPTION(opt,(void*)val)
205
207 const Pathname & attach_point_hint_r )
208 : MediaNetworkCommonHandler( origin_r, attach_point_hint_r,
209 "/", // urlpath at attachpoint
210 true ), // does_download
212{
213 _multi = curl_multi_init();
214
215 _curlError[0] = '\0';
216
217 MIL << "MediaCurl::MediaCurl(" << origin_r.authority().url() << ", " << attach_point_hint_r << ")" << endl;
218
220
221 if( !attachPoint().empty())
222 {
223 PathInfo ainfo(attachPoint());
224 Pathname apath(attachPoint() + "XXXXXX");
225 char *atemp = ::strdup( apath.asString().c_str());
226 char *atest = NULL;
227 if( !ainfo.isDir() || !ainfo.userMayRWX() ||
228 atemp == NULL || (atest=::mkdtemp(atemp)) == NULL)
229 {
230 WAR << "attach point " << ainfo.path()
231 << " is not useable for " << origin_r.authority().url().getScheme() << endl;
232 setAttachPoint("", true);
233 }
234 else if( atest != NULL)
235 ::rmdir(atest);
236
237 if( atemp != NULL)
238 ::free(atemp);
239 }
240}
241
243{
244 try { release(); } catch(...) {}
245 if (_multi)
246 curl_multi_cleanup(_multi);
247}
248
249void MediaCurl::setCookieFile( const Pathname &fileName )
250{
251 _cookieFile = fileName;
252}
253
254void MediaCurl::setCurlError(const char* error)
255{
256 // FIXME(dmllr): Use strlcpy if available for better performance
257 strncpy(_curlError, error, sizeof(_curlError)-1);
258 _curlError[sizeof(_curlError)-1] = '\0';
259}
260
262
264{
265 curl_version_info_data *curl_info = NULL;
266 curl_info = curl_version_info(CURLVERSION_NOW);
267 // curl_info does not need any free (is static)
268 if (curl_info->protocols)
269 {
270 const char * const *proto = nullptr;
271 std::string scheme( url.getScheme());
272 bool found = false;
273 for(proto=curl_info->protocols; !found && *proto; ++proto)
274 {
275 if( scheme == std::string((const char *)*proto))
276 found = true;
277 }
278 if( !found)
279 {
280 std::string msg("Unsupported protocol '");
281 msg += scheme;
282 msg += "'";
284 }
285 }
286}
287
289{
290 CURL *curl = rData.curl;
291
292 // kill old settings
293 curl_easy_reset ( curl );
294
296 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, log_redirects_curl);
297 curl_easy_setopt(curl, CURLOPT_HEADERDATA, &_lastRedirect);
298 CURLcode ret = curl_easy_setopt( curl, CURLOPT_ERRORBUFFER, _curlError );
299 if ( ret != 0 ) {
300 ZYPP_THROW(MediaCurlSetOptException( _origin.at(rData.mirror).url(), "Error setting error buffer"));
301 }
302
303 SET_OPTION(CURLOPT_FAILONERROR, 1L);
304 SET_OPTION(CURLOPT_NOSIGNAL, 1L);
305
308 {
309 case 4: SET_OPTION(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); break;
310 case 6: SET_OPTION(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6); break;
311 }
312
316 SET_OPTION(CURLOPT_CONNECTTIMEOUT, settings.connectTimeout());
317 // If a transfer timeout is set, also set CURLOPT_TIMEOUT to an upper limit
318 // just in case curl does not trigger its progress callback frequently
319 // enough.
320 if ( settings.timeout() )
321 {
322 SET_OPTION(CURLOPT_TIMEOUT, 3600L);
323 }
324
325 // follow any Location: header that the server sends as part of
326 // an HTTP header (#113275)
327 SET_OPTION(CURLOPT_FOLLOWLOCATION, 1L);
328 // 3 redirects seem to be too few in some cases (bnc #465532)
329 SET_OPTION(CURLOPT_MAXREDIRS, 6L);
330
331 if ( _origin.at(rData.mirror).url().getScheme() == "https" )
332 {
333 if ( :: internal::setCurlRedirProtocols ( curl ) != CURLE_OK ) {
335 }
336
337 if( settings.verifyPeerEnabled() ||
338 settings.verifyHostEnabled() )
339 {
340 SET_OPTION(CURLOPT_CAPATH, settings.certificateAuthoritiesPath().c_str());
341 }
342
343 if( ! settings.clientCertificatePath().empty() )
344 {
345 SET_OPTION(CURLOPT_SSLCERT, settings.clientCertificatePath().c_str());
346 }
347 if( ! settings.clientKeyPath().empty() )
348 {
349 SET_OPTION(CURLOPT_SSLKEY, settings.clientKeyPath().c_str());
350 }
351
352#ifdef CURLSSLOPT_ALLOW_BEAST
353 // see bnc#779177
354 ret = curl_easy_setopt( curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST );
355 if ( ret != 0 ) {
358 }
359#endif
360 SET_OPTION(CURLOPT_SSL_VERIFYPEER, settings.verifyPeerEnabled() ? 1L : 0L);
361 SET_OPTION(CURLOPT_SSL_VERIFYHOST, settings.verifyHostEnabled() ? 2L : 0L);
362 // bnc#903405 - POODLE: libzypp should only talk TLS
363 SET_OPTION(CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
364 }
365
366 SET_OPTION(CURLOPT_USERAGENT, settings.userAgentString().c_str() );
367
368 /* Fixes bsc#1174011 "auth=basic ignored in some cases"
369 * We should proactively add the password to the request if basic auth is configured
370 * and a password is available in the credentials but not in the URL.
371 *
372 * We will be a bit paranoid here and require that the URL has a user embedded, otherwise we go the default route
373 * and ask the server first about the auth method
374 */
375 if ( settings.authType() == "basic"
376 && settings.username().size()
377 && !settings.password().size() ) {
378
380 const auto cred = cm.getCred( _origin.at(rData.mirror).url() );
381 if ( cred && cred->valid() ) {
382 if ( !settings.username().size() )
383 settings.setUsername(cred->username());
384 settings.setPassword(cred->password());
385 }
386 }
387
388 /*---------------------------------------------------------------*
389 CURLOPT_USERPWD: [user name]:[password]
390
391 Url::username/password -> CURLOPT_USERPWD
392 If not provided, anonymous FTP identification
393 *---------------------------------------------------------------*/
394
395 if ( settings.userPassword().size() )
396 {
397 SET_OPTION(CURLOPT_USERPWD, settings.userPassword().c_str());
398 std::string use_auth = settings.authType();
399 if (use_auth.empty())
400 use_auth = "digest,basic"; // our default
401 long auth = CurlAuthData::auth_type_str2long(use_auth);
402 if( auth != CURLAUTH_NONE)
403 {
404 DBG << "Enabling HTTP authentication methods: " << use_auth
405 << " (CURLOPT_HTTPAUTH=" << auth << ")" << std::endl;
406 SET_OPTION(CURLOPT_HTTPAUTH, auth);
407 }
408 }
409
410 if ( settings.proxyEnabled() && ! settings.proxy().empty() )
411 {
412 DBG << "Proxy: '" << settings.proxy() << "'" << endl;
413 SET_OPTION(CURLOPT_PROXY, settings.proxy().c_str());
414 SET_OPTION(CURLOPT_PROXYAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST|CURLAUTH_NTLM );
415 /*---------------------------------------------------------------*
416 * CURLOPT_PROXYUSERPWD: [user name]:[password]
417 *
418 * Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
419 * If not provided, $HOME/.curlrc is evaluated
420 *---------------------------------------------------------------*/
421
422 std::string proxyuserpwd = settings.proxyUserPassword();
423
424 if ( proxyuserpwd.empty() )
425 {
426 CurlConfig curlconf;
427 CurlConfig::parseConfig(curlconf); // parse ~/.curlrc
428 if ( curlconf.proxyuserpwd.empty() )
429 DBG << "Proxy: ~/.curlrc does not contain the proxy-user option" << endl;
430 else
431 {
432 proxyuserpwd = curlconf.proxyuserpwd;
433 DBG << "Proxy: using proxy-user from ~/.curlrc" << endl;
434 }
435 }
436 else
437 {
438 DBG << "Proxy: using provided proxy-user '" << settings.proxyUsername() << "'" << endl;
439 }
440
441 if ( ! proxyuserpwd.empty() )
442 {
443 SET_OPTION(CURLOPT_PROXYUSERPWD, curlUnEscape( proxyuserpwd ).c_str());
444 }
445 }
446#if CURLVERSION_AT_LEAST(7,19,4)
447 else if ( settings.proxy() == EXPLICITLY_NO_PROXY )
448 {
449 // Explicitly disabled in URL (see fillSettingsFromUrl()).
450 // This should also prevent libcurl from looking into the environment.
451 DBG << "Proxy: explicitly NOPROXY" << endl;
452 SET_OPTION(CURLOPT_NOPROXY, "*");
453 }
454#endif
455 else
456 {
457 DBG << "Proxy: not explicitly set" << endl;
458 DBG << "Proxy: libcurl may look into the environment" << endl;
459 }
460
462 if ( settings.minDownloadSpeed() != 0 )
463 {
464 SET_OPTION(CURLOPT_LOW_SPEED_LIMIT, settings.minDownloadSpeed());
465 // default to 10 seconds at low speed
466 SET_OPTION(CURLOPT_LOW_SPEED_TIME, 60L);
467 }
468
469#if CURLVERSION_AT_LEAST(7,15,5)
470 if ( settings.maxDownloadSpeed() != 0 )
471 SET_OPTION_OFFT(CURLOPT_MAX_RECV_SPEED_LARGE, settings.maxDownloadSpeed());
472#endif
473
474 /*---------------------------------------------------------------*
475 *---------------------------------------------------------------*/
476
477 _currentCookieFile = _cookieFile.asString();
478 if ( ::geteuid() == 0 || PathInfo(_currentCookieFile).owner() == ::geteuid() )
480
481 const auto &cookieFileParam = _origin.at(rData.mirror).url().getQueryParam( "cookies" );
482 if ( !cookieFileParam.empty() && str::strToBool( cookieFileParam, true ) )
483 SET_OPTION(CURLOPT_COOKIEFILE, _currentCookieFile.c_str() );
484 else
485 MIL << "No cookies requested" << endl;
486 SET_OPTION(CURLOPT_COOKIEJAR, _currentCookieFile.c_str() );
487 SET_OPTION(CURLOPT_XFERINFOFUNCTION, &progressCallback );
488 SET_OPTION(CURLOPT_NOPROGRESS, 0L);
489
490#if CURLVERSION_AT_LEAST(7,18,0)
491 // bnc #306272
492 SET_OPTION(CURLOPT_PROXY_TRANSFER_MODE, 1L );
493#endif
494 // Append settings custom headers to curl.
495 // TransferSettings assert strings are trimmed (HTTP/2 RFC 9113)
496 if ( _customHeaders ) {
497 curl_slist_free_all(_customHeaders);
498 _customHeaders = 0L;
499 }
500 for ( const auto &header : settings.headers() ) {
501 _customHeaders = curl_slist_append(_customHeaders, header.c_str());
502 if ( !_customHeaders )
504 }
505 SET_OPTION(CURLOPT_HTTPHEADER, _customHeaders);
506}
507
509
511{
512 if ( _customHeaders ) {
513 curl_slist_free_all(_customHeaders);
514 _customHeaders = 0L;
515 }
516
517 // clear effective settings
519}
520
522
523void MediaCurl::releaseFrom( const std::string & ejectDev )
524{
525 disconnect();
526}
527
529
530void MediaCurl::getFileCopy( const OnMediaLocation & srcFile , const Pathname & target ) const
531{
532 // we need a non const pointer to work around the current API
533 auto that = const_cast<MediaCurl *>(this);
534 std::exception_ptr lastErr;
535 const auto &mirrOrder = mirrorOrder (srcFile);
536 for ( unsigned mirr : mirrOrder ) {
537 try {
538 return that->getFileCopyFromMirror ( mirr, srcFile, target );
539
540 } catch (MediaException & excpt_r) {
541 if ( !canTryNextMirror ( excpt_r ) )
542 ZYPP_RETHROW(excpt_r);
543 lastErr = ZYPP_FWD_CURRENT_EXCPT();
544 }
545 }
546 if ( lastErr ) {
547 ZYPP_RETHROW( lastErr );
548 }
549
550 // should not happen
551 ZYPP_THROW( MediaException("No usable mirror available.") );
552
553}
554
555void MediaCurl::getFileCopyFromMirror(const int mirror, const OnMediaLocation &srcFile, const Pathname &target)
556{
557 const auto &filename = srcFile.filename();
558
559 // Optional files will send no report until data are actually received (we know it exists).
560 OptionalDownloadProgressReport reportfilter( srcFile.optional() );
562
563 auto &myUrl = _origin[mirror];
564 auto &settings = myUrl.getConfig<TransferSettings>(MIRR_SETTINGS_KEY.data());
565
566 AutoDispose<CURL*> curl( curl_easy_init(), []( CURL *hdl ) { if ( hdl ) { curl_easy_cleanup(hdl); } } );
567
568 RequestData rData;
569 rData.mirror = mirror;
570 rData.curl = curl.value ();
571
572 if( !myUrl.url().isValid() )
573 ZYPP_THROW(MediaBadUrlException(myUrl.url()));
574
575 if( myUrl.url().getHost().empty() )
577
578 Url fileurl( getFileUrl(mirror, filename) );
579
580 bool firstAuth = true; // bsc#1210870: authenticate must not return stored credentials more than once.
581 unsigned internalTry = 0;
582 static constexpr unsigned maxInternalTry = 3;
583
584 do
585 {
586 try
587 {
588 Pathname dest = target.absolutename();
589 if( assert_dir( dest.dirname() ) )
590 {
591 DBG << "assert_dir " << dest.dirname() << " failed" << endl;
592 ZYPP_THROW( MediaSystemException(fileurl, "System error on " + dest.dirname().asString()) );
593 }
594
595 ManagedFile destNew { target.extend( ".new.zypp.XXXXXX" ) };
596 AutoFILE file;
597 {
598 AutoFREE<char> buf { ::strdup( (*destNew).c_str() ) };
599 if( ! buf )
600 {
601 ERR << "out of memory for temp file name" << endl;
602 ZYPP_THROW(MediaSystemException(fileurl, "out of memory for temp file name"));
603 }
604
605 AutoFD tmp_fd { ::mkostemp( buf, O_CLOEXEC ) };
606 if( tmp_fd == -1 )
607 {
608 ERR << "mkstemp failed for file '" << destNew << "'" << endl;
610 }
611 destNew = ManagedFile( (*buf), filesystem::unlink );
612
613 file = ::fdopen( tmp_fd, "we" );
614 if ( ! file )
615 {
616 ERR << "fopen failed for file '" << destNew << "'" << endl;
618 }
619 tmp_fd.resetDispose(); // don't close it here! ::fdopen moved ownership to file
620 }
621
622 DBG << "dest: " << dest << endl;
623 DBG << "temp: " << destNew << endl;
624
625 setupEasy( rData, settings );
626
627 // set IFMODSINCE time condition (no download if not modified)
628 if( PathInfo(target).isExist() )
629 {
630 curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
631 curl_easy_setopt(curl, CURLOPT_TIMEVALUE, (long)PathInfo(target).mtime());
632 }
633 else
634 {
635 curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
636 curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 0L);
637 }
638
640 curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
641 curl_easy_setopt(curl, CURLOPT_TIMEVALUE, 0L);
642 };
643
644 DBG << srcFile.filename().asString() << endl;
645
646 DBG << "URL: " << fileurl.asString() << endl;
647 // Use URL without options and without username and passwd
648 // (some proxies dislike them in the URL).
649 // Curl seems to need the just scheme, hostname and a path;
650 // the rest was already passed as curl options (in attachTo).
651 Url curlUrl( clearQueryString(fileurl) );
652
653 //
654 // See also Bug #154197 and ftp url definition in RFC 1738:
655 // The url "ftp://user@host/foo/bar/file" contains a path,
656 // that is relative to the user's home.
657 // The url "ftp://user@host//foo/bar/file" (or also with
658 // encoded slash as %2f) "ftp://user@host/%2ffoo/bar/file"
659 // contains an absolute path.
660 //
661 _lastRedirect.clear();
662 std::string urlBuffer( curlUrl.asString());
663 CURLcode ret = curl_easy_setopt( curl, CURLOPT_URL,
664 urlBuffer.c_str() );
665 if ( ret != 0 ) {
667 }
668
669 ret = curl_easy_setopt( curl, CURLOPT_WRITEDATA, file.value() );
670 if ( ret != 0 ) {
672 }
673
674 // Set callback and perform.
675 internal::ProgressData progressData( curl, settings.timeout(), fileurl, srcFile.downloadSize(), &report );
676 report->start(fileurl, dest);
677
678 if ( curl_easy_setopt( curl, CURLOPT_PROGRESSDATA, &progressData ) != 0 ) {
679 WAR << "Can't set CURLOPT_PROGRESSDATA: " << _curlError << endl;;
680 }
681
682 ret = executeCurl( rData );
683 #if CURLVERSION_AT_LEAST(7,19,4)
684 // bnc#692260: If the client sends a request with an If-Modified-Since header
685 // with a future date for the server, the server may respond 200 sending a
686 // zero size file.
687 // curl-7.19.4 introduces CURLINFO_CONDITION_UNMET to check this condition.
688 if ( ftell(file) == 0 && ret == 0 )
689 {
690 long httpReturnCode = 33;
691 if ( curl_easy_getinfo( curl, CURLINFO_RESPONSE_CODE, &httpReturnCode ) == CURLE_OK && httpReturnCode == 200 )
692 {
693 long conditionUnmet = 33;
694 if ( curl_easy_getinfo( curl, CURLINFO_CONDITION_UNMET, &conditionUnmet ) == CURLE_OK && conditionUnmet )
695 {
696 WAR << "TIMECONDITION unmet - retry without." << endl;
697 curl_easy_setopt( curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
698 curl_easy_setopt( curl, CURLOPT_TIMEVALUE, 0L);
699 ret = executeCurl( rData );
700 }
701 }
702 }
703 #endif
704
705 if ( curl_easy_setopt( curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) {
706 WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;;
707 }
708
709 if ( ret != 0 ) {
710 ERR << "curl error: " << ret << ": " << _curlError
711 << ", temp file size " << ftell(file)
712 << " bytes." << endl;
713
714 // the timeout is determined by the progress data object
715 // which holds whether the timeout was reached or not,
716 // otherwise it would be a user cancel
717
718 if ( progressData.fileSizeExceeded() )
720
721 evaluateCurlCode( rData, srcFile.filename(), ret, progressData.timeoutReached() );
722 }
723
724 long httpReturnCode = 0;
725 CURLcode infoRet = curl_easy_getinfo(curl,
726 CURLINFO_RESPONSE_CODE,
727 &httpReturnCode);
728 bool modified = true;
729 if (infoRet == CURLE_OK)
730 {
731 DBG << "HTTP response: " + str::numstring(httpReturnCode);
732 if ( httpReturnCode == 304
733 || ( httpReturnCode == 213 && (myUrl.url().getScheme() == "ftp" || myUrl.url().getScheme() == "tftp") ) ) // not modified
734 {
735 DBG << " Not modified.";
736 modified = false;
737 }
738 DBG << endl;
739 }
740 else
741 {
742 WAR << "Could not get the response code." << endl;
743 }
744
745 if (modified || infoRet != CURLE_OK)
746 {
747 // apply umask
748 if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
749 {
750 ERR << "Failed to chmod file " << destNew << endl;
751 }
752
753 file.resetDispose(); // we're going to close it manually here
754 if ( ::fclose( file ) )
755 {
756 ERR << "Fclose failed for file '" << destNew << "'" << endl;
758 }
759
760 // move the temp file into dest
761 if ( rename( destNew, dest ) != 0 ) {
762 ERR << "Rename failed" << endl;
764 }
765 destNew.resetDispose(); // no more need to unlink it
766 }
767
768 DBG << "done: " << PathInfo(dest) << endl;
769 break; // success!
770 }
771 // retry with proper authentication data
772 catch (MediaUnauthorizedException & ex_r)
773 {
774 if ( authenticate( myUrl.url(), settings, ex_r.hint(), firstAuth) ) {
775 firstAuth = false; // must not return stored credentials again
776 continue; // retry
777 }
778
780 ZYPP_RETHROW(ex_r);
781 }
782 // unexpected exception
783 catch (MediaException & excpt_r)
784 {
785 if ( typeid(excpt_r) == typeid( MediaCurlExceptionMayRetryInternaly ) ) {
786 ++internalTry;
787 if ( internalTry < maxInternalTry ) {
788 // just report (NO_ERROR); no interactive request to the user
789 report->problem(fileurl, media::DownloadProgressReport::NO_ERROR, excpt_r.asUserHistory()+_("Will try again..."));
790 continue; // retry
791 }
792 excpt_r.addHistory( str::Format(_("Giving up after %1% attempts.")) % maxInternalTry );
793 }
794
796 if( typeid(excpt_r) == typeid( media::MediaFileNotFoundException ) ||
797 typeid(excpt_r) == typeid( media::MediaNotAFileException ) )
798 {
800 }
801 report->finish(fileurl, reason, excpt_r.asUserHistory());
802 ZYPP_RETHROW(excpt_r);
803 }
804 } while ( true );
805
806 report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
807}
808
810
811bool MediaCurl::getDoesFileExist( const Pathname & filename ) const
812{
813 // we need a non const pointer to work around the current API
814 auto that = const_cast<MediaCurl *>(this);
815
816 std::exception_ptr lastErr;
817 for ( int i : mirrorOrder( OnMediaLocation(filename).setMirrorsAllowed(false) )) {
818 try {
819 return that->doGetDoesFileExist( i, filename );
820
821 } catch (MediaException & excpt_r) {
822 if ( !canTryNextMirror ( excpt_r ) )
823 ZYPP_RETHROW(excpt_r);
824 lastErr = ZYPP_FWD_CURRENT_EXCPT();
825 }
826 }
827 if ( lastErr ) {
828 try {
829 ZYPP_RETHROW( lastErr );
830 } catch ( const MediaFileNotFoundException &e ) {
831 // on file not found we return false
832 ZYPP_CAUGHT(e);
833 return false;
834 }
835 }
836 return false;
837}
838
840
842 const Pathname &filename,
843 CURLcode code,
844 bool timeout_reached) const
845{
846 if ( code != 0 )
847 {
848 const auto &baseMirr = _origin[rData.mirror];
849 Url url;
850 if (filename.empty())
851 url = baseMirr.url();
852 else
853 url = getFileUrl(rData.mirror, filename);
854
855 std::string err;
856 {
857 switch ( code )
858 {
859 case CURLE_UNSUPPORTED_PROTOCOL:
860 err = " Unsupported protocol";
861 if ( !_lastRedirect.empty() )
862 {
863 err += " or redirect (";
864 err += _lastRedirect;
865 err += ")";
866 }
867 break;
868 case CURLE_URL_MALFORMAT:
869 case CURLE_URL_MALFORMAT_USER:
870 err = " Bad URL";
871 break;
872 case CURLE_LOGIN_DENIED:
874 MediaUnauthorizedException(url, "Login failed.", _curlError, ""));
875 break;
876 case CURLE_HTTP_RETURNED_ERROR:
877 {
878 long httpReturnCode = 0;
879 CURLcode infoRet = curl_easy_getinfo( rData.curl,
880 CURLINFO_RESPONSE_CODE,
881 &httpReturnCode );
882 if ( infoRet == CURLE_OK )
883 {
884 std::string msg = "HTTP response: " + str::numstring( httpReturnCode );
885 switch ( httpReturnCode )
886 {
887 case 401:
888 {
889 std::string auth_hint = getAuthHint( rData.curl );
890
891 DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl;
892 DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl;
893
895 url, "Login failed.", _curlError, auth_hint
896 ));
897 }
898
899 case 502: // bad gateway (bnc #1070851)
900 case 503: // service temporarily unavailable (bnc #462545)
902 case 504: // gateway timeout
904 case 403:
905 {
906 std::string msg403;
907 if ( url.getHost().find(".suse.com") != std::string::npos )
908 msg403 = _("Visit the SUSE Customer Center to check whether your registration is valid and has not expired.");
909 else if (url.asString().find("novell.com") != std::string::npos)
910 msg403 = _("Visit the Novell Customer Center to check whether your registration is valid and has not expired.");
912 }
913 case 404:
914 case 410:
915 ZYPP_THROW(MediaFileNotFoundException(baseMirr.url(), filename));
916 }
917
918 DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
920 }
921 else
922 {
923 std::string msg = "Unable to retrieve HTTP response:";
924 DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
926 }
927 }
928 break;
929 case CURLE_FTP_COULDNT_RETR_FILE:
930#if CURLVERSION_AT_LEAST(7,16,0)
931 case CURLE_REMOTE_FILE_NOT_FOUND:
932#endif
933 case CURLE_FTP_ACCESS_DENIED:
934 case CURLE_TFTP_NOTFOUND:
935 err = "File not found";
936 ZYPP_THROW(MediaFileNotFoundException(baseMirr.url(), filename));
937 break;
938 case CURLE_BAD_PASSWORD_ENTERED:
939 case CURLE_FTP_USER_PASSWORD_INCORRECT:
940 err = "Login failed";
941 break;
942 case CURLE_COULDNT_RESOLVE_PROXY:
943 case CURLE_COULDNT_RESOLVE_HOST:
944 case CURLE_COULDNT_CONNECT:
945 case CURLE_FTP_CANT_GET_HOST:
946 err = "Connection failed";
947 break;
948 case CURLE_WRITE_ERROR:
949 err = "Write error";
950 break;
951 case CURLE_PARTIAL_FILE:
952 case CURLE_OPERATION_TIMEDOUT:
953 timeout_reached = true; // fall though to TimeoutException
954 // fall though...
955 case CURLE_ABORTED_BY_CALLBACK:
956 if( timeout_reached )
957 {
958 err = "Timeout reached";
960 }
961 else
962 {
963 err = "User abort";
964 }
965 break;
966
967 default:
968 err = "Curl error " + str::numstring( code );
969 break;
970 }
971
972 // uhm, no 0 code but unknown curl exception
974 }
975 }
976 else
977 {
978 // actually the code is 0, nothing happened
979 }
980}
981
983
984bool MediaCurl::doGetDoesFileExist( const int mirror, const Pathname & filename )
985{
986 DBG << filename.asString() << endl;
987
988 AutoDispose<CURL*> curl( curl_easy_init(), []( CURL *hdl ) { if ( hdl ) { curl_easy_cleanup(hdl); } } );
989 RequestData rData;
990 rData.mirror = mirror;
991 rData.curl = curl.value ();
992
993 auto &myUrl = _origin[mirror];
994
995 if( !myUrl.url().isValid() )
996 ZYPP_THROW(MediaBadUrlException(myUrl.url()));
997
998 if( myUrl.url().getHost().empty() )
1000
1001 Url url(getFileUrl(mirror, filename));
1002
1003 DBG << "URL: " << url.asString() << endl;
1004 // Use URL without options and without username and passwd
1005 // (some proxies dislike them in the URL).
1006 // Curl seems to need the just scheme, hostname and a path;
1007 // the rest was already passed as curl options (in attachTo).
1008 Url curlUrl( clearQueryString(url) );
1009
1010 // See also Bug #154197 and ftp url definition in RFC 1738:
1011 // The url "ftp://user@host/foo/bar/file" contains a path,
1012 // that is relative to the user's home.
1013 // The url "ftp://user@host//foo/bar/file" (or also with
1014 // encoded slash as %2f) "ftp://user@host/%2ffoo/bar/file"
1015 // contains an absolute path.
1016 //
1017 _lastRedirect.clear();
1018 std::string urlBuffer( curlUrl.asString());
1019
1020 CURLcode ok;
1021 bool canRetry = true;
1022 bool firstAuth = true;
1023 auto &settings = myUrl.getConfig<TransferSettings>( MIRR_SETTINGS_KEY.data() );
1024
1025 while ( canRetry ) {
1026 canRetry = false;
1027 setupEasy( rData, settings );
1028
1029 CURLcode ret = curl_easy_setopt( curl, CURLOPT_URL,
1030 urlBuffer.c_str() );
1031 if ( ret != 0 ) {
1033 }
1034
1035 AutoFILE file { ::fopen( "/dev/null", "w" ) };
1036 if ( !file ) {
1037 ERR << "fopen failed for /dev/null" << endl;
1038 ZYPP_THROW(MediaWriteException("/dev/null"));
1039 }
1040
1041 ret = curl_easy_setopt( curl, CURLOPT_WRITEDATA, (*file) );
1042 if ( ret != 0 ) {
1044 }
1045
1046 // If no head requests allowed (?head_requests=no):
1047 // Instead of returning no data with NOBODY, we return
1048 // little data, that works with broken servers, and
1049 // works for ftp as well, because retrieving only headers
1050 // ftp will return always OK code ?
1051 // See http://curl.haxx.se/docs/knownbugs.html #58
1052 const bool doHeadRequest = (myUrl.url().getScheme() == "http" || myUrl.url().getScheme() == "https") && settings.headRequestsAllowed();
1053 if ( doHeadRequest ) {
1054 curl_easy_setopt( curl, CURLOPT_NOBODY, 1L );
1055 } else {
1056 curl_easy_setopt( curl, CURLOPT_RANGE, "0-1" );
1057 }
1058
1059 try {
1060 ok = const_cast<MediaCurl *>(this)->executeCurl( rData );
1061 MIL << "perform code: " << ok << " [ " << curl_easy_strerror(ok) << " ]" << endl;
1062
1063 // as we are not having user interaction, the user can't cancel
1064 // the file existence checking, a callback or timeout return code
1065 // will be always a timeout.
1066 evaluateCurlCode( rData, filename, ok, true /* timeout */);
1067 }
1068 catch ( const MediaFileNotFoundException &e ) {
1069 // if the file did not exist then we can return false
1070 return false;
1071 }
1072 catch ( const MediaUnauthorizedException &e ) {
1073 if ( authenticate( myUrl.url(), settings, e.hint(), firstAuth ) ) {
1074 firstAuth = false;
1075 canRetry = true;
1076 continue;
1077 }
1078 }
1079
1080 // exists
1081 return ( ok == CURLE_OK );
1082 }
1083
1084 return false;
1085}
1086
1088//
1089int MediaCurl::aliveCallback( void *clientp, curl_off_t /*dltotal*/, curl_off_t dlnow, curl_off_t /*ultotal*/, curl_off_t /*ulnow*/ )
1090{
1091 internal::ProgressData *pdata = reinterpret_cast<internal::ProgressData *>( clientp );
1092 if( pdata )
1093 {
1094 // Do not propagate dltotal in alive callbacks. MultiCurl uses this to
1095 // prevent a percentage raise while downloading a metalink file. Download
1096 // activity however is indicated by propagating the download rate (via dlnow).
1097 pdata->updateStats( 0.0, dlnow );
1098 return pdata->reportProgress();
1099 }
1100 return 0;
1101}
1102
1103int MediaCurl::progressCallback( void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow )
1104{
1105 internal::ProgressData *pdata = reinterpret_cast<internal::ProgressData *>( clientp );
1106 if( pdata )
1107 {
1108 // work around curl bug that gives us old data
1109 long httpReturnCode = 0;
1110 if ( curl_easy_getinfo( pdata->curl(), CURLINFO_RESPONSE_CODE, &httpReturnCode ) != CURLE_OK || httpReturnCode == 0 )
1111 return aliveCallback( clientp, dltotal, dlnow, ultotal, ulnow );
1112
1113 pdata->updateStats( dltotal, dlnow );
1114 return pdata->reportProgress();
1115 }
1116 return 0;
1117}
1118
1120{
1121 internal::ProgressData *pdata = reinterpret_cast<internal::ProgressData *>(clientp);
1122 return pdata ? pdata->curl() : 0;
1123}
1124
1126
1127std::string MediaCurl::getAuthHint( CURL *curl ) const
1128{
1129 long auth_info = CURLAUTH_NONE;
1130
1131 CURLcode infoRet =
1132 curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_AVAIL, &auth_info);
1133
1134 if(infoRet == CURLE_OK)
1135 {
1136 return CurlAuthData::auth_type_long2str(auth_info);
1137 }
1138
1139 return "";
1140}
1141
1146void MediaCurl::resetExpectedFileSize(void *clientp, const ByteCount &expectedFileSize)
1147{
1148 internal::ProgressData *data = reinterpret_cast<internal::ProgressData *>(clientp);
1149 if ( data ) {
1150 data->expectedFileSize( expectedFileSize );
1151 }
1152}
1153
1160{
1161 CURL *curl = rData.curl;
1162 const auto &baseUrl = _origin.at(rData.mirror);
1163
1164 if (!_multi)
1165 ZYPP_THROW(MediaCurlInitException(baseUrl.url()));
1166
1167 internal::CurlPollHelper _curlHelper(*this);
1168
1169 // add the easy handle to the multi instance
1170 if ( curl_multi_add_handle( _multi, curl ) != CURLM_OK )
1171 ZYPP_THROW(MediaCurlException( baseUrl.url(), "curl_multi_add_handle", "unknown error"));
1172
1173 // make sure the handle is cleanly removed from the multi handle
1174 OnScopeExit autoRemove([&](){ curl_multi_remove_handle( _multi, curl ); });
1175
1176 // kickstart curl, this will cause libcurl to go over the added handles and register sockets and timeouts
1177 CURLMcode mcode = _curlHelper.handleTimout();
1178 if (mcode != CURLM_OK)
1179 ZYPP_THROW(MediaCurlException( baseUrl.url(), "curl_multi_socket_action", "unknown error"));
1180
1181 bool canContinue = true;
1182 while ( canContinue ) {
1183
1184 CURLMsg *msg = nullptr;
1185 int nqueue = 0;
1186 while ((msg = curl_multi_info_read( _multi, &nqueue)) != 0) {
1187 if ( msg->msg != CURLMSG_DONE ) continue;
1188 if ( msg->easy_handle != curl ) continue;
1189
1190 return msg->data.result;
1191 }
1192
1193 // copy watched sockets in case curl changes the vector as we go over the events later
1194 std::vector<GPollFD> requestedFds = _curlHelper.socks;
1195
1196 int r = zypp_detail::zypp_poll( requestedFds, _curlHelper.timeout_ms.value_or( -1 ) );
1197 if ( r == -1 )
1198 ZYPP_THROW( MediaCurlException(baseUrl.url(), "zypp_poll() failed", "unknown error") );
1199
1200 // run curl
1201 if ( r == 0 ) {
1202 CURLMcode mcode = _curlHelper.handleTimout();
1203 if (mcode != CURLM_OK)
1204 ZYPP_THROW(MediaCurlException(baseUrl.url(), "curl_multi_socket_action", "unknown error"));
1205 } else {
1206 CURLMcode mcode = _curlHelper.handleSocketActions( requestedFds );
1207 if (mcode != CURLM_OK)
1208 ZYPP_THROW(MediaCurlException(baseUrl.url(), "curl_multi_socket_action", "unknown error"));
1209 }
1210 }
1211 return CURLE_OK;
1212}
1213
1214
1215 } // namespace media
1216} // namespace zypp
1217//
#define SET_OPTION_OFFT(opt, val)
Definition MediaCurl.cc:202
#define SET_OPTION(opt, val)
Definition MediaCurl.cc:195
Attempt to work around certain issues by autoretry in MediaCurl::getFileCopy E.g.
Definition MediaCurl.cc:170
MediaCurlExceptionMayRetryInternaly(const Url &url_r, const std::string &err_r, const std::string &msg_r)
Definition MediaCurl.cc:172
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
reference value() const
Reference to the Tp object.
void resetDispose()
Set no dispose function.
Store and operate with byte count.
Definition ByteCount.h:32
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition Exception.cc:140
void addHistory(const std::string &msg_r)
Add some message text to the history.
Definition Exception.cc:189
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
const OriginEndpoint & authority() const
Describes a resource file located on a medium.
bool optional() const
Whether this is an optional resource.
const ByteCount & downloadSize() const
The size of the resource on the server.
const Pathname & filename() const
The path to the resource on the medium.
const zypp::Url & url() const
ProgressData()
Ctor no range [0,0](0).
Url manipulation class.
Definition Url.h:93
std::string getScheme() const
Returns the scheme name of the URL.
Definition Url.cc:551
std::string asString() const
Returns a default string representation of the Url object.
Definition Url.cc:515
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:940
Wrapper class for stat/lstat.
Definition PathInfo.h:226
const Pathname & path() const
Return current Pathname.
Definition PathInfo.h:251
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:126
const char * c_str() const
String representation.
Definition Pathname.h:112
const std::string & asString() const
String representation.
Definition Pathname.h:93
bool empty() const
Test for an empty path.
Definition Pathname.h:116
AuthData_Ptr getCred(const Url &url)
Get credentials for the specified url.
static std::string auth_type_long2str(long auth_type)
Converts a long of ORed CURLAUTH_* identifiers into a string of comma separated list of authenticatio...
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_* ...
MediaCurlException(const Url &url_r, std::string err_r, std::string msg_r)
bool doGetDoesFileExist(const int mirror, const Pathname &filename)
Definition MediaCurl.cc:984
void checkProtocol(const Url &url) const override
check the url is supported by the curl library
Definition MediaCurl.cc:263
static void setCookieFile(const Pathname &)
Definition MediaCurl.cc:249
bool getDoesFileExist(const Pathname &filename) const override
Repeatedly calls doGetDoesFileExist() until it successfully returns, fails unexpectedly,...
Definition MediaCurl.cc:811
static void resetExpectedFileSize(void *clientp, const ByteCount &expectedFileSize)
MediaMultiCurl needs to reset the expected filesize in case a metalink file is downloaded otherwise t...
std::string _currentCookieFile
Definition MediaCurl.h:125
static Pathname _cookieFile
Definition MediaCurl.h:126
std::string getAuthHint(CURL *curl) const
Return a comma separated list of available authentication methods supported by server.
void getFileCopyFromMirror(const int mirror, const OnMediaLocation &srcFile, const Pathname &target)
Definition MediaCurl.cc:555
static int progressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Callback reporting download progress.
std::string _lastRedirect
to log/report redirections
Definition MediaCurl.h:129
char _curlError[CURL_ERROR_SIZE]
Definition MediaCurl.h:127
void evaluateCurlCode(RequestData &rData, const zypp::Pathname &fileName, CURLcode code, bool timeout) const
Evaluates a curl return code and throws the right MediaException filename Filename being downloaded c...
Definition MediaCurl.cc:841
CURLcode executeCurl(RequestData &rData)
MediaCurl(const MirroredOrigin &origin_r, const Pathname &attach_point_hint_r)
Definition MediaCurl.cc:206
void setCurlError(const char *error)
Definition MediaCurl.cc:254
static CURL * progressCallback_getcurl(void *clientp)
void releaseFrom(const std::string &ejectDev) override
Call concrete handler to release the media.
Definition MediaCurl.cc:523
static int aliveCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Callback sending just an alive trigger to the UI, without stats (e.g.
void disconnectFrom() override
Definition MediaCurl.cc:510
void setupEasy(RequestData &rData, TransferSettings &settings)
initializes the curl easy handle with the data from the url
Definition MediaCurl.cc:288
curl_slist * _customHeaders
Definition MediaCurl.h:130
void getFileCopy(const OnMediaLocation &srcFile, const Pathname &target) const override
Definition MediaCurl.cc:530
Just inherits Exception to separate media exceptions.
MirroredOrigin _origin
Contains the authority URL and mirrors.
Url url() const
Primary Url used.
void disconnect()
Use concrete handler to isconnect media.
void release(const std::string &ejectDev="")
Use concrete handler to release the media.
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Pathname attachPoint() const
Return the currently used attach point.
bool authenticate(const Url &url, TransferSettings &settings, const std::string &availAuthTypes, bool firstTry)
static bool canTryNextMirror(const Excpt &excpt_r)
std::vector< unsigned > mirrorOrder(const OnMediaLocation &loc) const
Url getFileUrl(int mirrorIdx, const Pathname &filename) const
concatenate the attach url and the filename to a complete download url
MediaNetworkCommonHandler(const MirroredOrigin &origin_r, const Pathname &attach_point_r, const Pathname &urlpath_below_attachpoint_r, const bool does_download_r)
static constexpr std::string_view MIRR_SETTINGS_KEY
const std::string & hint() const
comma separated list of available authentication types
Holds transfer setting.
const std::string & password() const
auth password
long maxDownloadSpeed() const
Maximum download speed (bytes per second)
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
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.
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.
std::string proxyUserPassword() const
returns the proxy user and password as a user:pass string
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 proxyEnabled() const
proxy is enabled
const std::string & username() const
auth username
const std::string & proxyUsername() const
proxy auth username
const Pathname & certificateAuthoritiesPath() const
SSL certificate authorities path ( default: /etc/ssl/certs )
bool verifyPeerEnabled() const
Whether to verify peer for ssl.
#define EXPLICITLY_NO_PROXY
size_t log_redirects_curl(char *ptr, size_t size, size_t nmemb, void *userdata)
void globalInitCurlOnce()
Definition curlhelper.cc:64
std::string curlUnEscape(const std::string &text_r)
void setupZYPP_MEDIA_CURL_DEBUG(CURL *curl)
Setup CURLOPT_VERBOSE and CURLOPT_DEBUGFUNCTION according to env::ZYPP_MEDIA_CURL_DEBUG.
CURLcode setCurlRedirProtocols(CURL *curl)
Definition Arch.h:364
int ZYPP_MEDIA_CURL_IPRESOLVE()
4/6 to force IPv4/v6
Definition curlhelper.cc:45
mode_t applyUmaskTo(mode_t mode_r)
Modify mode_r according to the current umask ( mode_r & ~getUmask() ).
Definition PathInfo.h:805
int assert_file_mode(const Pathname &path, unsigned mode)
Like assert_file but enforce mode even if the file already exists.
Definition PathInfo.cc:1210
int unlink(const Pathname &path)
Like 'unlink'.
Definition PathInfo.cc:705
std::string numstring(char n, int w=0)
Definition String.h:290
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition String.h:500
Url details namespace.
Definition UrlBase.cc:58
int zypp_poll(std::vector< GPollFD > &fds, int timeout)
Small wrapper around g_poll that additionally listens to the shutdown FD returned by ZYpp::shutdownSi...
Definition ZYppImpl.cc:313
Easy-to use interface to the ZYPP dependency resolver.
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
AutoDispose< void > OnScopeExit
CURLMcode handleSocketActions(const std::vector< GPollFD > &actionsFds, int first=0)
std::vector< GPollFD > socks
std::optional< long > timeout_ms
Bottleneck filtering all DownloadProgressReport issued from Media[Muli]Curl.
ByteCount _expectedFileSize
Definition MediaCurl.cc:82
curl_off_t _dnlNow
Bytes downloaded now.
Definition MediaCurl.cc:92
int _dnlPercent
Percent completed or 0 if _dnlTotal is unknown.
Definition MediaCurl.cc:94
time_t _timeRcv
Start of no-data timeout.
Definition MediaCurl.cc:87
ByteCount expectedFileSize() const
Definition MediaCurl.cc:70
time_t _timeLast
Start last period(~1sec)
Definition MediaCurl.cc:86
int reportProgress() const
Definition MediaCurl.cc:155
double _drateLast
Download rate in last period.
Definition MediaCurl.cc:97
bool timeoutReached() const
Definition MediaCurl.cc:64
void expectedFileSize(ByteCount newval_r)
Definition MediaCurl.cc:73
curl_off_t _dnlLast
Bytes downloaded at period start.
Definition MediaCurl.cc:91
bool fileSizeExceeded() const
Definition MediaCurl.cc:67
void updateStats(curl_off_t dltotal=0.0, curl_off_t dlnow=0.0)
Definition MediaCurl.cc:112
double _drateTotal
Download rate so far.
Definition MediaCurl.cc:96
zypp::callback::SendReport< zypp::media::DownloadProgressReport > * report
Definition MediaCurl.cc:83
curl_off_t _dnlTotal
Bytes to download or 0 if unknown.
Definition MediaCurl.cc:90
time_t _timeStart
Start total stats.
Definition MediaCurl.cc:85
ProgressData(CURL *curl, time_t timeout=0, zypp::Url url=zypp::Url(), zypp::ByteCount expectedFileSize_r=0, zypp::callback::SendReport< zypp::media::DownloadProgressReport > *_report=nullptr)
Definition MediaCurl.cc:102
AutoDispose<int> calling close
AutoDispose<FILE*> calling fclose
Structure holding values of curlrc options.
Definition curlconfig.h:27
std::string proxyuserpwd
Definition curlconfig.h:49
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
Convenient building of std::string with boost::format.
Definition String.h:254
#define zypp_defer
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition Exception.h:479
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:471
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
#define _(MSG)
Definition Gettext.h:39
#define DBG
Definition Logger.h:99
#define MIL
Definition Logger.h:100
#define ERR
Definition Logger.h:102
#define WAR
Definition Logger.h:101
Interface to gettext.