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) 376 for (
const auto &header : locSet.
headers() ) {
377 if ( !z_func()->addRequestHeader( header.c_str() ) )
395 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
397 DBG <<
_easyHandle <<
"Can only create output file in running mode" << std::endl;
401 if ( !rmode->_outFile ) {
402 std::string openMode =
"w+b";
413 if ( !rmode->_outFile ) {
426 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
434 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
439 if ( rmode->_rangeAttemptIdx + 1 >=
sizeof(
_rangeAttempt ) ) {
440 errBuf =
"No more range batch sizes available";
443 rmode->_rangeAttemptIdx++;
459 errBuf =
"Request has no more work";
467 errBuf =
"Calling the prepareNextRangeBatch function without a range to download is not supported.";
471 std::string rangeDesc;
472 uint rangesAdded = 0;
474 errBuf =
"Using more than one range is not supported with protocols other than HTTP/HTTPS";
480 if ( !std::holds_alternative<pending_t>(
_runningMode ) ) {
486 std::get<pending_t>(
_runningMode )._requireStatusPartial =
false;
490 return ( elem1.start < elem2.start );
493 if ( std::holds_alternative<pending_t>(
_runningMode ) )
494 std::get<pending_t>(
_runningMode )._requireStatusPartial =
true;
497 if ( std::holds_alternative<prepareNextRangeBatch_t>(
_runningMode ) )
501 auto addRangeString = [ &rangeDesc, &rangesAdded ](
const std::pair<size_t, size_t> &range ) {
502 std::string rangeD =
zypp::str::form(
"%llu-", static_cast<unsigned long long>( range.first ) );
503 if( range.second > 0 )
504 rangeD.append(
zypp::str::form(
"%llu", static_cast<unsigned long long>( range.second ) ) );
506 if ( rangeDesc.size() )
507 rangeDesc.append(
",").append( rangeD );
509 rangeDesc = std::move( rangeD );
514 std::optional<std::pair<size_t, size_t>> currentZippedRange;
515 bool closedRange =
true;
522 range.bytesWritten = 0;
526 if ( !closedRange ) {
527 errBuf =
"It is not supported to request more ranges after a open range.";
531 const auto rangeEnd = range.len > 0 ? range.start + range.len - 1 : 0;
532 closedRange = (rangeEnd > 0);
536 range.bytesWritten = 0;
538 range._digest->reset();
542 if ( !currentZippedRange ) {
543 currentZippedRange = std::make_pair( range.start, rangeEnd );
546 if ( currentZippedRange->second + 1 == range.start ) {
547 currentZippedRange->second = rangeEnd;
550 addRangeString( *currentZippedRange );
551 currentZippedRange = std::make_pair( range.start, rangeEnd );
555 if ( rangesAdded >= maxRanges ) {
556 MIL <<
_easyHandle <<
" " <<
"Reached max nr of ranges (" << maxRanges <<
"), batching the request to not break the server" << std::endl;
562 if ( currentZippedRange )
563 addRangeString( *currentZippedRange );
565 MIL <<
_easyHandle <<
" " <<
"Requesting Ranges: " << rangeDesc << std::endl;
581 bool isRangeContinuation = std::holds_alternative<prepareNextRangeBatch_t>(
_runningMode );
582 if ( isRangeContinuation ) {
583 MIL <<
_easyHandle <<
" " <<
"Continuing a previously started range batch." << std::endl;
588 mode._currentRange = 0;
595 if ( m._activityTimer ) {
598 m._activityTimer->start( static_cast<uint64_t>(
_settings.
timeout() * 1000 ) );
601 if ( !isRangeContinuation )
607 if ( std::holds_alternative<running_t>(
_runningMode) ) {
610 if ( rmode._currentRange >= 0 ) {
612 rmode._currentRange = -1;
622 resState.
_result = std::move(err);
624 if ( std::holds_alternative<running_t>(
_runningMode) ) {
627 rmode._outFile.reset();
635 if ( r.len > 0 && r.bytesWritten != r.len )
668 MIL_MEDIA <<
_easyHandle <<
" Request timeout interval: " << t.interval()<<
" remaining: " << t.remaining() << std::endl;
669 std::map<std::string, boost::any> extraInfo;
670 extraInfo.insert( {
"requestUrl",
_url } );
678 auto bytesHashed = rng.
_digest->bytesHashed ();
682 rng.
_digest->update( padding.data(), padding.size() );
684 auto digVec = rng.
_digest->digestVector();
716 DBG <<
_easyHandle <<
" " <<
"Invalid Content-Range Header format: '" << std::string(line) << std::endl;
720 size_t s = zypp::str::strtonum<size_t>( what[1]);
721 size_t e = zypp::str::strtonum<size_t>( what[2]);
722 start = std::move(s);
733 if ( what.
size() >= 2 ) {
748 if ( std::holds_alternative<running_t>(
_runningMode ) ){
750 if ( rmode._activityTimer && rmode._activityTimer->isRunning() )
751 rmode._activityTimer->start();
761 if ( !std::holds_alternative<running_t>(that->
_runningMode) ){
762 DBG << that->
_easyHandle <<
" " <<
"Curl progress callback was called in invalid state "<< that->z_func()->state() << std::endl;
766 auto &rmode = std::get<running_t>( that->
_runningMode );
771 rmode._isInCallback =
true;
772 if ( rmode._lastProgressNow != dlnow ) {
773 rmode._lastProgressNow = dlnow;
774 that->
_sigProgress.emit( *that->z_func(), dltotal, dlnow, ultotal, ulnow );
776 rmode._isInCallback =
false;
778 return rmode._cachedResult ? CURLE_ABORTED_BY_CALLBACK : CURLE_OK;
784 if ( size * nmemb == 0)
791 std::string_view hdr( ptr, size*nmemb );
793 hdr.remove_prefix( std::min( hdr.find_first_not_of(
" \t\r\n"), hdr.size() ) );
794 const auto lastNonWhitespace = hdr.find_last_not_of(
" \t\r\n");
795 if ( lastNonWhitespace != hdr.npos )
796 hdr.remove_suffix( hdr.size() - (lastNonWhitespace + 1) );
798 hdr = std::string_view();
802 return ( size * nmemb );
807 (void)curl_easy_getinfo(
_easyHandle, CURLINFO_RESPONSE_CODE, &statuscode);
809 const auto &doRangeFail = [&](){
810 WAR <<
_easyHandle <<
" " <<
"Range FAIL, trying with a smaller batch" << std::endl;
825 if ( rmode._requireStatusPartial ) {
827 if ( ( statuscode >= 200 && statuscode <= 299 && statuscode != 206 )
828 || statuscode == 416 ) {
829 return doRangeFail();
840 rmode._gotMultiRangeHeader =
true;
841 rmode._seperatorString =
"--"+sep;
850 rmode._gotContentRangeHeader =
true;
851 rmode._currentSrvRange = r;
855 auto str = std::string ( lenStr.data(), lenStr.length() );
856 auto len = zypp::str::strtonum<typename zypp::ByteCount::SizeType>(
str.data() );
858 DBG <<
_easyHandle <<
" " <<
"Got Content-Length Header: " << len << std::endl;
864 return ( size * nmemb );
869 const auto max = ( size * nmemb );
879 return ( size * nmemb );
884 auto writeDataToFile = [
this, &rmode ]( off_t offset,
const char *data,
size_t len ) -> off_t {
886 if ( rmode._currentRange < 0 ) {
887 DBG <<
_easyHandle <<
" " <<
"Current range is zero in write request" << std::endl;
897 if ( fseek( rmode._outFile, offset, SEEK_SET ) != 0 ) {
899 "Unable to set output file pointer." );
905 const auto bytesToWrite = rng.len > 0 ? std::min( rng.len - rng.bytesWritten, len ) : len;
913 auto written = fwrite( data, 1, bytesToWrite, rmode._outFile );
917 if ( rng._digest && rng._checksum.size() ) {
918 if ( !rng._digest->update( data, written ) )
922 rng.bytesWritten += written;
923 if ( rmode._currentSrvRange ) rmode._currentSrvRange->bytesWritten += written;
925 if ( rng.len > 0 && rng.bytesWritten >= rng.len ) {
926 rmode._currentRange = -1;
930 if ( rmode._currentSrvRange && rmode._currentSrvRange->len > 0 && rmode._currentSrvRange->bytesWritten >= rmode._currentSrvRange->len ) {
931 rmode._currentSrvRange.reset();
934 rmode._currentRange = -1;
938 rmode._downloaded += written;
945 size_t bytesWrittenSoFar = 0;
947 while ( bytesWrittenSoFar != max ) {
952 if ( !rmode._allHeadersReceived ) {
953 rmode._allHeadersReceived =
true;
956 if ( !rmode._gotMultiRangeHeader && !rmode._gotContentRangeHeader ) {
958 if ( rmode._requireStatusPartial ) {
961 "Invalid data from server, range respone was announced but there was no range definiton." );
971 rmode._currentRange = 0;
976 if ( rmode._currentSrvRange && rmode._currentRange == -1 ) {
982 std::optional<uint> foundRange;
983 const size_t beginRange = rmode._currentSrvRange->start + rmode._currentSrvRange->bytesWritten;
984 const size_t endRange = beginRange + (rmode._currentSrvRange->len - rmode._currentSrvRange->bytesWritten);
985 auto currDist = ULONG_MAX;
994 if ( currR.len == currR.bytesWritten )
997 const auto currRBegin = currR.start + currR.bytesWritten;
998 if ( !( beginRange <= currRBegin && endRange >= currRBegin ) )
1002 const auto newDist = currRBegin - beginRange;
1004 if ( !foundRange ) {
1009 if ( newDist < currDist ) {
1015 if ( !foundRange ) {
1017 ,
"Unable to find a matching range for data returned by the server." );
1022 rmode._currentRange = *foundRange;
1028 const auto skipBytes = seekTo - beginRange;
1029 bytesWrittenSoFar += skipBytes;
1030 rmode._currentSrvRange->bytesWritten += skipBytes;
1033 if ( rmode._currentRange >= 0 ) {
1034 auto availableData = max - bytesWrittenSoFar;
1035 if ( rmode._currentSrvRange ) {
1036 availableData = std::min( availableData, rmode._currentSrvRange->len - rmode._currentSrvRange->bytesWritten );
1038 auto bw = writeDataToFile( seekTo, ptr + bytesWrittenSoFar, availableData );
1042 bytesWrittenSoFar += bw;
1045 if ( bytesWrittenSoFar == max )
1048 if ( rmode._currentRange == -1 ) {
1051 if ( rmode._currentSrvRange )
1054 std::string_view incoming( ptr + bytesWrittenSoFar, max - bytesWrittenSoFar );
1055 auto hdrEnd = incoming.find(
"\r\n\r\n");
1056 if ( hdrEnd == incoming.npos ) {
1058 rmode._rangePrefaceBuffer.insert( rmode._rangePrefaceBuffer.end(), incoming.begin(), incoming.end() );
1063 rmode._rangePrefaceBuffer.insert( rmode._rangePrefaceBuffer.end(), incoming.begin(), incoming.begin() + ( hdrEnd + 4 ) );
1064 bytesWrittenSoFar += ( hdrEnd + 4 );
1066 std::string_view data( rmode._rangePrefaceBuffer.data(), rmode._rangePrefaceBuffer.size() );
1067 auto sepStrIndex = data.find( rmode._seperatorString );
1068 if ( sepStrIndex == data.npos ) {
1070 "Invalid multirange header format, seperator string missing." );
1074 auto startOfHeader = sepStrIndex + rmode._seperatorString.length();
1075 std::vector<std::string_view> lines;
1077 for (
const auto &hdrLine : lines ) {
1085 rmode._currentSrvRange = r;
1090 rmode._rangePrefaceBuffer.clear();
1093 return bytesWrittenSoFar;
1107 if ( d->_dispatcher )
1108 d->_dispatcher->cancel( *
this,
"Request destroyed while still running" );
1113 d_func()->_expectedFileSize = std::move( expectedFileSize );
1119 d->_priority = prio;
1120 if (
state() ==
Pending && triggerReschedule && d->_dispatcher )
1121 d->_dispatcher->reschedule();
1126 return d_func()->_priority;
1131 d_func()->_options = opt;
1136 return d_func()->_options;
1145 d->_requestedRanges.push_back(
Range::make( start, len, std::move(digest), std::move( expectedChkSum ), std::move( userData ), digestCompareLen, chksumpad ) );
1154 d->_requestedRanges.push_back( range );
1155 auto &rng = d->_requestedRanges.back();
1157 rng.bytesWritten = 0;
1159 rng._digest->reset();
1167 d->_requestedRanges.clear();
1172 const auto mystate =
state();
1178 std::vector<Range> failed;
1179 for (
const auto &r : d->_requestedRanges ) {
1181 failed.push_back( r );
1188 return d_func()->_requestedRanges;
1193 return d_func()->_lastRedirect;
1198 return d_func()->_easyHandle;
1203 const auto myerr =
error();
1204 const auto mystate =
state();
1210 auto getMeasurement = [ this ](
const CURLINFO info, std::chrono::microseconds &target ){
1211 using FPSeconds = std::chrono::duration<double, std::chrono::seconds::period>;
1213 const auto res = curl_easy_getinfo( d_func()->_easyHandle, info, &val );
1214 if ( CURLE_OK == res ) {
1215 target = std::chrono::duration_cast<std::chrono::microseconds>( FPSeconds(val) );
1219 getMeasurement( CURLINFO_NAMELOOKUP_TIME, t.
namelookup );
1220 getMeasurement( CURLINFO_CONNECT_TIME, t.
connect);
1221 getMeasurement( CURLINFO_APPCONNECT_TIME, t.
appconnect);
1222 getMeasurement( CURLINFO_PRETRANSFER_TIME , t.
pretransfer);
1223 getMeasurement( CURLINFO_TOTAL_TIME, t.
total);
1224 getMeasurement( CURLINFO_REDIRECT_TIME, t.
redirect);
1233 if ( !std::holds_alternative<NetworkRequestPrivate::running_t>( d->_runningMode) )
1236 const auto &rmode = std::get<NetworkRequestPrivate::running_t>( d->_runningMode );
1242 return d_func()->_url;
1256 return d_func()->_targetFile;
1264 d->_targetFile = path;
1269 return d_func()->_fMode;
1277 d->_fMode = std::move( mode );
1283 if ( curl_easy_getinfo( d_func()->_easyHandle, CURLINFO_CONTENT_TYPE, &ptr ) == CURLE_OK && ptr )
1284 return std::string(ptr);
1285 return std::string();
1291 using T = std::decay_t<decltype(arg)>;
1292 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
1294 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
1295 || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
1296 return arg._contentLenght;
1298 static_assert(always_false<T>::value,
"Unhandled state type");
1299 }, d_func()->_runningMode);
1305 using T = std::decay_t<decltype(arg)>;
1306 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
1308 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
1309 || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t>
1310 || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
1311 return arg._downloaded;
1313 static_assert(always_false<T>::value,
"Unhandled state type");
1314 }, d_func()->_runningMode);
1319 return d_func()->_settings;
1324 return std::visit([
this](
auto& arg) {
1325 using T = std::decay_t<decltype(arg)>;
1326 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
1328 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
1330 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::finished_t>) {
1331 if ( std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode ).
_result.isError() )
1337 static_assert(always_false<T>::value,
"Unhandled state type");
1338 }, d_func()->_runningMode);
1343 const auto s =
state();
1346 return std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode).
_result;
1352 return std::string();
1366 curl_slist *res = curl_slist_append( d->_headers ? d->_headers.get() :
nullptr, header.c_str() );
1371 d->_headers = std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >( res, &curl_slist_free_all );
1378 return d_func()->_sigStarted;
1383 return d_func()->_sigBytesDownloaded;
1388 return d_func()->_sigProgress;
1393 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