13 #include <zypp-core/zyppng/base/EventDispatcher> 14 #include <zypp-core/zyppng/base/private/linuxhelpers_p.h> 15 #include <zypp-core/zyppng/core/String> 17 #include <zypp-curl/CurlConfig> 18 #include <zypp-curl/auth/CurlAuthData> 19 #include <zypp-media/MediaConfig> 20 #include <zypp-core/base/String.h> 21 #include <zypp-core/base/StringV.h> 22 #include <zypp-core/Pathname.h> 23 #include <curl/curl.h> 30 #include <boost/variant.hpp> 31 #include <boost/variant/polymorphic_get.hpp> 37 static size_t nwr_headerCallback (
char *ptr,
size_t size,
size_t nmemb,
void *userdata ) {
41 NetworkRequestPrivate *that =
reinterpret_cast<NetworkRequestPrivate *
>( userdata );
42 return that->headerCallback( ptr, size, nmemb );
44 static size_t nwr_writeCallback (
char *ptr,
size_t size,
size_t nmemb,
void *userdata ) {
48 NetworkRequestPrivate *that =
reinterpret_cast<NetworkRequestPrivate *
>( userdata );
49 return that->writeCallback( ptr, size, nmemb );
53 template<
class T>
struct always_false : std::false_type {};
56 std::vector<char>
peek_data_fd( FILE *fd, off_t offset,
size_t count )
63 std::vector<char> data( count + 1 ,
'\0' );
66 while ((l = pread( fileno( fd ), data.data(), count, offset ) ) == -1 && errno == EINTR)
80 ._digest = std::move( digest ),
81 ._checksum = std::move( expectedChkSum ),
82 ._relevantDigestLen = std::move( digestCompareLen ),
83 ._chksumPad = std::move( dataBlockPadding ),
85 ._rangeState = State::Pending
90 : _outFile(
std::move(prevState._outFile) )
91 , _downloaded( prevState._downloaded )
92 , _rangeAttemptIdx( prevState._rangeAttemptIdx )
96 : _requireStatusPartial( prevState._requireStatusPartial )
100 : _outFile(
std::move(prevState._outFile) )
101 , _requireStatusPartial( true )
102 , _downloaded( prevState._downloaded )
103 , _rangeAttemptIdx( prevState._rangeAttemptIdx )
111 ,
_headers(
std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >(
nullptr, &curl_slist_free_all ) )
141 const std::string urlScheme =
_url.getScheme();
142 if ( urlScheme ==
"http" || urlScheme ==
"https" )
154 std::string urlBuffer(
_url.asString() );
181 std::visit( [&](
auto &arg ){
182 using T = std::decay_t<decltype(arg)>;
183 if constexpr ( std::is_same_v<T, pending_t> ) {
184 arg._requireStatusPartial =
false;
186 DBG <<
_easyHandle <<
" " <<
"NetworkRequestPrivate::setupHandle called in unexpected state" << std::endl;
201 const auto &cHeaders =
_dispatcher->hostSpecificHeaders();
202 if (
auto i = cHeaders.find(
_url.getHost()); i != cHeaders.end() ) {
203 for (
const auto &[key, value] : i->second ) {
205 "%s: %s", key.c_str(), value.c_str() )
216 case 4:
setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
break;
217 case 6:
setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6 );
break;
221 setCurlOption( CURLOPT_HEADERFUNCTION, &nwr_headerCallback );
236 if ( urlScheme ==
"https" )
238 #if CURLVERSION_AT_LEAST(7,19,4) 240 if (
_url.getHost() ==
"download.opensuse.org" )
241 setCurlOption( CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS );
261 #ifdef CURLSSLOPT_ALLOW_BEAST 263 setCurlOption( CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST );
290 if (use_auth.empty())
291 use_auth =
"digest,basic";
293 if( auth != CURLAUTH_NONE)
295 DBG <<
_easyHandle <<
" " <<
"Enabling HTTP authentication methods: " << use_auth
296 <<
" (CURLOPT_HTTPAUTH=" << auth <<
")" << std::endl;
305 setCurlOption(CURLOPT_PROXYAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST|CURLAUTH_NTLM );
316 if ( proxyuserpwd.empty() )
321 DBG <<
_easyHandle <<
" " <<
"Proxy: ~/.curlrc does not contain the proxy-user option" << std::endl;
325 DBG <<
_easyHandle <<
" " <<
"Proxy: using proxy-user from ~/.curlrc" << std::endl;
333 if ( ! proxyuserpwd.empty() )
338 #if CURLVERSION_AT_LEAST(7,19,4) 343 DBG <<
_easyHandle <<
" " <<
"Proxy: explicitly NOPROXY" << std::endl;
358 #if CURLVERSION_AT_LEAST(7,15,5) 369 #if CURLVERSION_AT_LEAST(7,18,0) 375 for (
const auto &header : locSet.
headers() ) {
376 if ( !z_func()->addRequestHeader( header.c_str() ) )
394 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
396 DBG <<
_easyHandle <<
"Can only create output file in running mode" << std::endl;
400 if ( !rmode->_outFile ) {
401 std::string openMode =
"w+b";
412 if ( !rmode->_outFile ) {
425 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
433 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
438 if ( rmode->_rangeAttemptIdx + 1 >=
sizeof(
_rangeAttempt ) ) {
439 errBuf =
"No more range batch sizes available";
442 rmode->_rangeAttemptIdx++;
458 errBuf =
"Request has no more work";
466 errBuf =
"Calling the prepareNextRangeBatch function without a range to download is not supported.";
470 std::string rangeDesc;
471 uint rangesAdded = 0;
473 errBuf =
"Using more than one range is not supported with protocols other than HTTP/HTTPS";
479 if ( !std::holds_alternative<pending_t>(
_runningMode ) ) {
485 std::get<pending_t>(
_runningMode )._requireStatusPartial =
false;
489 return ( elem1.start < elem2.start );
492 if ( std::holds_alternative<pending_t>(
_runningMode ) )
493 std::get<pending_t>(
_runningMode )._requireStatusPartial =
true;
496 if ( std::holds_alternative<prepareNextRangeBatch_t>(
_runningMode ) )
500 auto addRangeString = [ &rangeDesc, &rangesAdded ](
const std::pair<size_t, size_t> &range ) {
501 std::string rangeD =
zypp::str::form(
"%llu-", static_cast<unsigned long long>( range.first ) );
502 if( range.second > 0 )
503 rangeD.append(
zypp::str::form(
"%llu", static_cast<unsigned long long>( range.second ) ) );
505 if ( rangeDesc.size() )
506 rangeDesc.append(
",").append( rangeD );
508 rangeDesc = std::move( rangeD );
513 std::optional<std::pair<size_t, size_t>> currentZippedRange;
514 bool closedRange =
true;
521 range.bytesWritten = 0;
525 if ( !closedRange ) {
526 errBuf =
"It is not supported to request more ranges after a open range.";
530 const auto rangeEnd = range.len > 0 ? range.start + range.len - 1 : 0;
531 closedRange = (rangeEnd > 0);
535 range.bytesWritten = 0;
537 range._digest->reset();
541 if ( !currentZippedRange ) {
542 currentZippedRange = std::make_pair( range.start, rangeEnd );
545 if ( currentZippedRange->second + 1 == range.start ) {
546 currentZippedRange->second = rangeEnd;
549 addRangeString( *currentZippedRange );
550 currentZippedRange = std::make_pair( range.start, rangeEnd );
554 if ( rangesAdded >= maxRanges ) {
555 MIL <<
_easyHandle <<
" " <<
"Reached max nr of ranges (" << maxRanges <<
"), batching the request to not break the server" << std::endl;
561 if ( currentZippedRange )
562 addRangeString( *currentZippedRange );
564 MIL <<
_easyHandle <<
" " <<
"Requesting Ranges: " << rangeDesc << std::endl;
580 bool isRangeContinuation = std::holds_alternative<prepareNextRangeBatch_t>(
_runningMode );
581 if ( isRangeContinuation ) {
582 MIL <<
_easyHandle <<
" " <<
"Continuing a previously started range batch." << std::endl;
587 mode._currentRange = 0;
594 if ( m._activityTimer ) {
597 m._activityTimer->start( static_cast<uint64_t>(
_settings.
timeout() * 1000 ) );
600 if ( !isRangeContinuation )
606 if ( std::holds_alternative<running_t>(
_runningMode) ) {
609 if ( rmode._currentRange >= 0 ) {
611 rmode._currentRange = -1;
621 resState.
_result = std::move(err);
623 if ( std::holds_alternative<running_t>(
_runningMode) ) {
626 rmode._outFile.reset();
634 if ( r.len > 0 && r.bytesWritten != r.len )
667 MIL_MEDIA <<
_easyHandle <<
" Request timeout interval: " << t.interval()<<
" remaining: " << t.remaining() << std::endl;
668 std::map<std::string, boost::any> extraInfo;
669 extraInfo.insert( {
"requestUrl",
_url } );
677 auto bytesHashed = rng.
_digest->bytesHashed ();
681 rng.
_digest->update( padding.data(), padding.size() );
683 auto digVec = rng.
_digest->digestVector();
715 DBG <<
_easyHandle <<
" " <<
"Invalid Content-Range Header format: '" << std::string(line) << std::endl;
719 size_t s = zypp::str::strtonum<size_t>( what[1]);
720 size_t e = zypp::str::strtonum<size_t>( what[2]);
721 start = std::move(s);
732 if ( what.
size() >= 2 ) {
747 if ( std::holds_alternative<running_t>(
_runningMode ) ){
749 if ( rmode._activityTimer && rmode._activityTimer->isRunning() )
750 rmode._activityTimer->start();
760 if ( !std::holds_alternative<running_t>(that->
_runningMode) ){
761 DBG << that->
_easyHandle <<
" " <<
"Curl progress callback was called in invalid state "<< that->z_func()->state() << std::endl;
765 auto &rmode = std::get<running_t>( that->
_runningMode );
770 rmode._isInCallback =
true;
771 if ( rmode._lastProgressNow != dlnow ) {
772 rmode._lastProgressNow = dlnow;
773 that->
_sigProgress.emit( *that->z_func(), dltotal, dlnow, ultotal, ulnow );
775 rmode._isInCallback =
false;
777 return rmode._cachedResult ? CURLE_ABORTED_BY_CALLBACK : CURLE_OK;
783 if ( size * nmemb == 0)
790 std::string_view hdr( ptr, size*nmemb );
792 hdr.remove_prefix( std::min( hdr.find_first_not_of(
" \t\r\n"), hdr.size() ) );
793 const auto lastNonWhitespace = hdr.find_last_not_of(
" \t\r\n");
794 if ( lastNonWhitespace != hdr.npos )
795 hdr.remove_suffix( hdr.size() - (lastNonWhitespace + 1) );
797 hdr = std::string_view();
801 return ( size * nmemb );
806 (void)curl_easy_getinfo(
_easyHandle, CURLINFO_RESPONSE_CODE, &statuscode);
808 const auto &doRangeFail = [&](){
809 WAR <<
_easyHandle <<
" " <<
"Range FAIL, trying with a smaller batch" << std::endl;
824 if ( rmode._requireStatusPartial ) {
826 if ( ( statuscode >= 200 && statuscode <= 299 && statuscode != 206 )
827 || statuscode == 416 ) {
828 return doRangeFail();
839 rmode._gotMultiRangeHeader =
true;
840 rmode._seperatorString =
"--"+sep;
849 rmode._gotContentRangeHeader =
true;
850 rmode._currentSrvRange = r;
854 auto str = std::string ( lenStr.data(), lenStr.length() );
855 auto len = zypp::str::strtonum<typename zypp::ByteCount::SizeType>(
str.data() );
857 DBG <<
_easyHandle <<
" " <<
"Got Content-Length Header: " << len << std::endl;
863 return ( size * nmemb );
868 const auto max = ( size * nmemb );
878 return ( size * nmemb );
883 auto writeDataToFile = [
this, &rmode ]( off_t offset,
const char *data,
size_t len ) -> off_t {
885 if ( rmode._currentRange < 0 ) {
886 DBG <<
_easyHandle <<
" " <<
"Current range is zero in write request" << std::endl;
896 if ( fseek( rmode._outFile, offset, SEEK_SET ) != 0 ) {
898 "Unable to set output file pointer." );
904 const auto bytesToWrite = rng.len > 0 ? std::min( rng.len - rng.bytesWritten, len ) : len;
912 auto written = fwrite( data, 1, bytesToWrite, rmode._outFile );
916 if ( rng._digest && rng._checksum.size() ) {
917 if ( !rng._digest->update( data, written ) )
921 rng.bytesWritten += written;
922 if ( rmode._currentSrvRange ) rmode._currentSrvRange->bytesWritten += written;
924 if ( rng.len > 0 && rng.bytesWritten >= rng.len ) {
925 rmode._currentRange = -1;
929 if ( rmode._currentSrvRange && rmode._currentSrvRange->len > 0 && rmode._currentSrvRange->bytesWritten >= rmode._currentSrvRange->len ) {
930 rmode._currentSrvRange.reset();
933 rmode._currentRange = -1;
937 rmode._downloaded += written;
944 size_t bytesWrittenSoFar = 0;
946 while ( bytesWrittenSoFar != max ) {
951 if ( !rmode._allHeadersReceived ) {
952 rmode._allHeadersReceived =
true;
955 if ( !rmode._gotMultiRangeHeader && !rmode._gotContentRangeHeader ) {
957 if ( rmode._requireStatusPartial ) {
960 "Invalid data from server, range respone was announced but there was no range definiton." );
970 rmode._currentRange = 0;
975 if ( rmode._currentSrvRange && rmode._currentRange == -1 ) {
981 std::optional<uint> foundRange;
982 const size_t beginRange = rmode._currentSrvRange->start + rmode._currentSrvRange->bytesWritten;
983 const size_t endRange = beginRange + (rmode._currentSrvRange->len - rmode._currentSrvRange->bytesWritten);
984 auto currDist = ULONG_MAX;
993 if ( currR.len == currR.bytesWritten )
996 const auto currRBegin = currR.start + currR.bytesWritten;
997 if ( !( beginRange <= currRBegin && endRange >= currRBegin ) )
1001 const auto newDist = currRBegin - beginRange;
1003 if ( !foundRange ) {
1008 if ( newDist < currDist ) {
1014 if ( !foundRange ) {
1016 ,
"Unable to find a matching range for data returned by the server." );
1021 rmode._currentRange = *foundRange;
1027 const auto skipBytes = seekTo - beginRange;
1028 bytesWrittenSoFar += skipBytes;
1029 rmode._currentSrvRange->bytesWritten += skipBytes;
1032 if ( rmode._currentRange >= 0 ) {
1033 auto availableData = max - bytesWrittenSoFar;
1034 if ( rmode._currentSrvRange ) {
1035 availableData = std::min( availableData, rmode._currentSrvRange->len - rmode._currentSrvRange->bytesWritten );
1037 auto bw = writeDataToFile( seekTo, ptr + bytesWrittenSoFar, availableData );
1041 bytesWrittenSoFar += bw;
1044 if ( bytesWrittenSoFar == max )
1047 if ( rmode._currentRange == -1 ) {
1050 if ( rmode._currentSrvRange )
1053 std::string_view incoming( ptr + bytesWrittenSoFar, max - bytesWrittenSoFar );
1054 auto hdrEnd = incoming.find(
"\r\n\r\n");
1055 if ( hdrEnd == incoming.npos ) {
1057 rmode._rangePrefaceBuffer.insert( rmode._rangePrefaceBuffer.end(), incoming.begin(), incoming.end() );
1062 rmode._rangePrefaceBuffer.insert( rmode._rangePrefaceBuffer.end(), incoming.begin(), incoming.begin() + ( hdrEnd + 4 ) );
1063 bytesWrittenSoFar += ( hdrEnd + 4 );
1065 std::string_view data( rmode._rangePrefaceBuffer.data(), rmode._rangePrefaceBuffer.size() );
1066 auto sepStrIndex = data.find( rmode._seperatorString );
1067 if ( sepStrIndex == data.npos ) {
1069 "Invalid multirange header format, seperator string missing." );
1073 auto startOfHeader = sepStrIndex + rmode._seperatorString.length();
1074 std::vector<std::string_view> lines;
1076 for (
const auto &hdrLine : lines ) {
1084 rmode._currentSrvRange = r;
1089 rmode._rangePrefaceBuffer.clear();
1092 return bytesWrittenSoFar;
1106 if ( d->_dispatcher )
1107 d->_dispatcher->cancel( *
this,
"Request destroyed while still running" );
1112 d_func()->_expectedFileSize = std::move( expectedFileSize );
1118 d->_priority = prio;
1119 if (
state() ==
Pending && triggerReschedule && d->_dispatcher )
1120 d->_dispatcher->reschedule();
1125 return d_func()->_priority;
1130 d_func()->_options = opt;
1135 return d_func()->_options;
1144 d->_requestedRanges.push_back(
Range::make( start, len, std::move(digest), std::move( expectedChkSum ), std::move( userData ), digestCompareLen, chksumpad ) );
1153 d->_requestedRanges.push_back( range );
1154 auto &rng = d->_requestedRanges.back();
1156 rng.bytesWritten = 0;
1158 rng._digest->reset();
1166 d->_requestedRanges.clear();
1171 const auto mystate =
state();
1177 std::vector<Range> failed;
1178 for (
const auto &r : d->_requestedRanges ) {
1180 failed.push_back( r );
1187 return d_func()->_requestedRanges;
1192 return d_func()->_lastRedirect;
1197 return d_func()->_easyHandle;
1202 const auto myerr =
error();
1203 const auto mystate =
state();
1209 auto getMeasurement = [ this ](
const CURLINFO info, std::chrono::microseconds &target ){
1210 using FPSeconds = std::chrono::duration<double, std::chrono::seconds::period>;
1212 const auto res = curl_easy_getinfo( d_func()->_easyHandle, info, &val );
1213 if ( CURLE_OK == res ) {
1214 target = std::chrono::duration_cast<std::chrono::microseconds>( FPSeconds(val) );
1218 getMeasurement( CURLINFO_NAMELOOKUP_TIME, t.
namelookup );
1219 getMeasurement( CURLINFO_CONNECT_TIME, t.
connect);
1220 getMeasurement( CURLINFO_APPCONNECT_TIME, t.
appconnect);
1221 getMeasurement( CURLINFO_PRETRANSFER_TIME , t.
pretransfer);
1222 getMeasurement( CURLINFO_TOTAL_TIME, t.
total);
1223 getMeasurement( CURLINFO_REDIRECT_TIME, t.
redirect);
1232 if ( !std::holds_alternative<NetworkRequestPrivate::running_t>( d->_runningMode) )
1235 const auto &rmode = std::get<NetworkRequestPrivate::running_t>( d->_runningMode );
1241 return d_func()->_url;
1255 return d_func()->_targetFile;
1263 d->_targetFile = path;
1268 return d_func()->_fMode;
1276 d->_fMode = std::move( mode );
1282 if ( curl_easy_getinfo( d_func()->_easyHandle, CURLINFO_CONTENT_TYPE, &ptr ) == CURLE_OK && ptr )
1283 return std::string(ptr);
1284 return std::string();
1290 using T = std::decay_t<decltype(arg)>;
1291 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
1293 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
1294 || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
1295 return arg._contentLenght;
1297 static_assert(always_false<T>::value,
"Unhandled state type");
1298 }, d_func()->_runningMode);
1304 using T = std::decay_t<decltype(arg)>;
1305 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
1307 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
1308 || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t>
1309 || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
1310 return arg._downloaded;
1312 static_assert(always_false<T>::value,
"Unhandled state type");
1313 }, d_func()->_runningMode);
1318 return d_func()->_settings;
1323 return std::visit([
this](
auto& arg) {
1324 using T = std::decay_t<decltype(arg)>;
1325 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
1327 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
1329 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::finished_t>) {
1330 if ( std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode ).
_result.isError() )
1336 static_assert(always_false<T>::value,
"Unhandled state type");
1337 }, d_func()->_runningMode);
1342 const auto s =
state();
1345 return std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode).
_result;
1351 return std::string();
1365 curl_slist *res = curl_slist_append( d->_headers ? d->_headers.get() :
nullptr, header.c_str() );
1370 d->_headers = std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >( res, &curl_slist_free_all );
1377 return d_func()->_sigStarted;
1382 return d_func()->_sigBytesDownloaded;
1387 return d_func()->_sigProgress;
1392 return d_func()->_sigFinished;
Signal< void(NetworkRequest &req)> _sigStarted
std::string errorMessage() const
bool isError() const
isError Will return true if this is a actual error
void setCurlOption(CURLoption opt, T data)
std::optional< Timings > timings() const
After the request is finished query the timings that were collected during download.
void * nativeHandle() const
std::optional< size_t > _chksumPad
zypp::ByteCount reportedByteCount() const
Returns the number of bytes that are reported from the backend as the full download size...
const std::vector< Range > & requestedRanges() const
std::chrono::microseconds connect
std::array< char, CURL_ERROR_SIZE+1 > _errorBuf
void addRequestRange(size_t start, size_t len=0, DigestPtr digest=nullptr, CheckSumBytes expectedChkSum=CheckSumBytes(), std::any userData=std::any(), std::optional< size_t > digestCompareLen={}, std::optional< size_t > chksumpad={})
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
ZYPP_IMPL_PRIVATE(Provide)
std::optional< size_t > _relevantDigestLen
SignalProxy< void(NetworkRequest &req, zypp::ByteCount count)> sigBytesDownloaded()
Signals that new data has been downloaded, this is only the payload and does not include control data...
bool hasPrefixCI(const C_Str &str_r, const C_Str &prefix_r)
NetworkRequest::FileMode _fMode
bool checkIfRangeChkSumIsValid(const NetworkRequest::Range &rng)
Store and operate with byte count.
const std::string & lastRedirectInfo() const
const std::string _currentCookieFile
std::chrono::microseconds pretransfer
zypp::ByteCount downloadedByteCount() const
Returns the number of already downloaded bytes as reported by the backend.
NetworkRequest::Options _options
const char * c_str() const
String representation.
void resetActivityTimer()
String related utilities and Regular expression matching.
std::chrono::microseconds appconnect
bool prepareNextRangeBatch(std::string &errBuf)
constexpr bool always_false
running_t(pending_t &&prevState)
std::string nativeErrorString() const
Signal< void(NetworkRequest &req, zypp::ByteCount count)> _sigBytesDownloaded
void setOptions(Options opt)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
void resetRequestRanges()
TransferSettings & transferSettings()
enum zyppng::NetworkRequestPrivate::ProtocolMode _protocolMode
void setExpectedFileSize(zypp::ByteCount expectedFileSize)
void setFileOpenMode(FileMode mode)
Sets the file open mode to mode.
bool hasError() const
Checks if there was a error with the request.
void onActivityTimeout(Timer &)
static std::string digestVectorToString(const UByteArray &vec)
get hex string representation of the digest vector given as parameter
int ZYPP_MEDIA_CURL_IPRESOLVE()
4/6 to force IPv4/v6
zypp::Pathname _targetFile
virtual ~NetworkRequestPrivate()
bool empty() const
Test for an empty path.
void setUrl(const Url &url)
This will change the URL of the request.
std::chrono::microseconds namelookup
Do not differentiate case.
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, const Trim trim_r=NO_TRIM)
Split line_r into words.
size_t headerCallback(char *ptr, size_t size, size_t nmemb)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
bool addRequestHeader(const std::string &header)
std::string trim(const std::string &s, const Trim trim_r)
const std::string & asString() const
String representation.
Signal< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> _sigProgress
bool parseContentTypeMultiRangeHeader(const std::string_view &line, std::string &boundary)
std::string asString() const
Error message provided by dumpOn as string.
bool initialize(std::string &errBuf)
The NetworkRequestError class Represents a error that occured in.
std::vector< char > peekData(off_t offset, size_t count) const
NetworkRequestError error() const
Returns the last set Error.
zypp::ByteCount _expectedFileSize
static constexpr int _rangeAttempt[]
std::string extendedErrorString() const
In some cases, curl can provide extended error information collected at runtime.
Priority priority() const
bool setupHandle(std::string &errBuf)
const zypp::Pathname & targetFilePath() const
Returns the target filename path.
void validateRange(NetworkRequest::Range &rng)
std::unique_ptr< curl_slist, decltype(&curl_slist_free_all) > _headers
bool parseContentRangeHeader(const std::string_view &line, size_t &start, size_t &len)
std::vector< char > peek_data_fd(FILE *fd, off_t offset, size_t count)
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
void setTargetFilePath(const zypp::Pathname &path)
Changes the target file path of the download.
static int curlProgressCallback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
Regular expression match result.
std::string contentType() const
Returns the content type as reported from the server.
static const Unit B
1 Byte
Base class for Exception.
std::string _lastRedirect
to log/report redirections
std::chrono::microseconds total
bool any_of(const Container &c, Fnc &&cb)
CheckSumBytes _checksum
Enables automated checking of downloaded contents against a checksum.
std::string curlUnEscape(std::string text_r)
void setupZYPP_MEDIA_CURL_DEBUG(CURL *curl)
Setup CURLOPT_VERBOSE and CURLOPT_DEBUGFUNCTION according to env::ZYPP_MEDIA_CURL_DEBUG.
static Range make(size_t start, size_t len=0, DigestPtr &&digest=nullptr, CheckSumBytes &&expectedChkSum=CheckSumBytes(), std::any &&userData=std::any(), std::optional< size_t > digestCompareLen={}, std::optional< size_t > _dataBlockPadding={})
void setPriority(Priority prio, bool triggerReschedule=true)
State state() const
Returns the current state the HttpDownloadRequest is in.
TransferSettings _settings
NetworkRequestDispatcher * _dispatcher
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
virtual ~NetworkRequest()
std::vector< NetworkRequest::Range > _requestedRanges
the requested ranges that need to be downloaded
size_t writeCallback(char *ptr, size_t size, size_t nmemb)
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
std::chrono::microseconds redirect
std::shared_ptr< zypp::Digest > DigestPtr
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
Signal< void(NetworkRequest &req, const NetworkRequestError &err)> _sigFinished
Type type() const
type Returns the type of the error
These are enforced even if you don't pass them as flag argument.
SignalProxy< void(NetworkRequest &req)> sigStarted()
Signals that the dispatcher dequeued the request and actually starts downloading data.
zypp::ByteCount _contentLenght
#define EXPLICITLY_NO_PROXY
FileMode fileOpenMode() const
Returns the currently configured file open mode.
std::vector< Range > failedRanges() const
Easy-to use interface to the ZYPP dependency resolver.
NetworkRequestPrivate(Url &&url, zypp::Pathname &&targetFile, NetworkRequest::FileMode fMode, NetworkRequest &p)
void setResult(NetworkRequestError &&err)
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.
bool prepareToContinue(std::string &errBuf)
NetworkRequestError _result
ZYppCommitResult & _result
std::variant< pending_t, running_t, prepareNextRangeBatch_t, finished_t > _runningMode