13 #include <zypp-core/zyppng/base/EventDispatcher> 14 #include <zypp-core/zyppng/base/private/linuxhelpers_p.h> 15 #include <zypp-core/zyppng/core/String> 16 #include <zypp-core/fs/PathInfo.h> 18 #include <zypp-curl/CurlConfig> 19 #include <zypp-curl/auth/CurlAuthData> 20 #include <zypp-media/MediaConfig> 21 #include <zypp-core/base/String.h> 22 #include <zypp-core/base/StringV.h> 23 #include <zypp-core/Pathname.h> 24 #include <curl/curl.h> 31 #include <boost/variant.hpp> 32 #include <boost/variant/polymorphic_get.hpp> 38 static size_t nwr_headerCallback (
char *ptr,
size_t size,
size_t nmemb,
void *userdata ) {
42 NetworkRequestPrivate *that =
reinterpret_cast<NetworkRequestPrivate *
>( userdata );
43 return that->headerCallback( ptr, size, nmemb );
45 static size_t nwr_writeCallback (
char *ptr,
size_t size,
size_t nmemb,
void *userdata ) {
49 NetworkRequestPrivate *that =
reinterpret_cast<NetworkRequestPrivate *
>( userdata );
50 return that->writeCallback( ptr, size, nmemb );
54 template<
class T>
struct always_false : std::false_type {};
57 std::vector<char>
peek_data_fd( FILE *fd, off_t offset,
size_t count )
64 std::vector<char> data( count + 1 ,
'\0' );
67 while ((l = pread( fileno( fd ), data.data(), count, offset ) ) == -1 && errno == EINTR)
81 ._digest = std::move( digest ),
82 ._checksum = std::move( expectedChkSum ),
83 ._relevantDigestLen = std::move( digestCompareLen ),
84 ._chksumPad = std::move( dataBlockPadding ),
86 ._rangeState = State::Pending
91 : _outFile(
std::move(prevState._outFile) )
92 , _downloaded( prevState._downloaded )
93 , _rangeAttemptIdx( prevState._rangeAttemptIdx )
97 : _requireStatusPartial( prevState._requireStatusPartial )
101 : _outFile(
std::move(prevState._outFile) )
102 , _requireStatusPartial( true )
103 , _downloaded( prevState._downloaded )
104 , _rangeAttemptIdx( prevState._rangeAttemptIdx )
112 ,
_headers(
std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >(
nullptr, &curl_slist_free_all ) )
142 const std::string urlScheme =
_url.getScheme();
143 if ( urlScheme ==
"http" || urlScheme ==
"https" )
155 std::string urlBuffer(
_url.asString() );
182 std::visit( [&](
auto &arg ){
183 using T = std::decay_t<decltype(arg)>;
184 if constexpr ( std::is_same_v<T, pending_t> ) {
185 arg._requireStatusPartial =
false;
187 DBG <<
_easyHandle <<
" " <<
"NetworkRequestPrivate::setupHandle called in unexpected state" << std::endl;
202 const auto &cHeaders =
_dispatcher->hostSpecificHeaders();
203 if (
auto i = cHeaders.find(
_url.getHost()); i != cHeaders.end() ) {
204 for (
const auto &[key, value] : i->second ) {
206 "%s: %s", key.c_str(), value.c_str() )
217 case 4:
setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
break;
218 case 6:
setCurlOption( CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6 );
break;
222 setCurlOption( CURLOPT_HEADERFUNCTION, &nwr_headerCallback );
237 if ( urlScheme ==
"https" )
239 #if CURLVERSION_AT_LEAST(7,19,4) 241 if (
_url.getHost() ==
"download.opensuse.org" )
242 setCurlOption( CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS );
262 #ifdef CURLSSLOPT_ALLOW_BEAST 264 setCurlOption( CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST );
291 if (use_auth.empty())
292 use_auth =
"digest,basic";
294 if( auth != CURLAUTH_NONE)
296 DBG <<
_easyHandle <<
" " <<
"Enabling HTTP authentication methods: " << use_auth
297 <<
" (CURLOPT_HTTPAUTH=" << auth <<
")" << std::endl;
306 setCurlOption(CURLOPT_PROXYAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST|CURLAUTH_NTLM );
317 if ( proxyuserpwd.empty() )
322 DBG <<
_easyHandle <<
" " <<
"Proxy: ~/.curlrc does not contain the proxy-user option" << std::endl;
326 DBG <<
_easyHandle <<
" " <<
"Proxy: using proxy-user from ~/.curlrc" << std::endl;
334 if ( ! proxyuserpwd.empty() )
339 #if CURLVERSION_AT_LEAST(7,19,4) 344 DBG <<
_easyHandle <<
" " <<
"Proxy: explicitly NOPROXY" << std::endl;
359 #if CURLVERSION_AT_LEAST(7,15,5) 371 #if CURLVERSION_AT_LEAST(7,18,0) 378 for (
const auto &header : locSet.
headers() ) {
379 if ( !z_func()->addRequestHeader( header.c_str() ) )
397 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
399 DBG <<
_easyHandle <<
"Can only create output file in running mode" << std::endl;
403 if ( !rmode->_outFile ) {
404 std::string openMode =
"w+b";
415 if ( !rmode->_outFile ) {
428 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
436 auto rmode = std::get_if<NetworkRequestPrivate::running_t>( &
_runningMode );
441 if ( rmode->_rangeAttemptIdx + 1 >=
sizeof(
_rangeAttempt ) ) {
442 errBuf =
"No more range batch sizes available";
445 rmode->_rangeAttemptIdx++;
461 errBuf =
"Request has no more work";
469 errBuf =
"Calling the prepareNextRangeBatch function without a range to download is not supported.";
473 std::string rangeDesc;
474 uint rangesAdded = 0;
476 errBuf =
"Using more than one range is not supported with protocols other than HTTP/HTTPS";
482 if ( !std::holds_alternative<pending_t>(
_runningMode ) ) {
488 std::get<pending_t>(
_runningMode )._requireStatusPartial =
false;
492 return ( elem1.start < elem2.start );
495 if ( std::holds_alternative<pending_t>(
_runningMode ) )
496 std::get<pending_t>(
_runningMode )._requireStatusPartial =
true;
499 if ( std::holds_alternative<prepareNextRangeBatch_t>(
_runningMode ) )
503 auto addRangeString = [ &rangeDesc, &rangesAdded ](
const std::pair<size_t, size_t> &range ) {
504 std::string rangeD =
zypp::str::form(
"%llu-", static_cast<unsigned long long>( range.first ) );
505 if( range.second > 0 )
506 rangeD.append(
zypp::str::form(
"%llu", static_cast<unsigned long long>( range.second ) ) );
508 if ( rangeDesc.size() )
509 rangeDesc.append(
",").append( rangeD );
511 rangeDesc = std::move( rangeD );
516 std::optional<std::pair<size_t, size_t>> currentZippedRange;
517 bool closedRange =
true;
524 range.bytesWritten = 0;
528 if ( !closedRange ) {
529 errBuf =
"It is not supported to request more ranges after a open range.";
533 const auto rangeEnd = range.len > 0 ? range.start + range.len - 1 : 0;
534 closedRange = (rangeEnd > 0);
538 range.bytesWritten = 0;
540 range._digest->reset();
544 if ( !currentZippedRange ) {
545 currentZippedRange = std::make_pair( range.start, rangeEnd );
548 if ( currentZippedRange->second + 1 == range.start ) {
549 currentZippedRange->second = rangeEnd;
552 addRangeString( *currentZippedRange );
553 currentZippedRange = std::make_pair( range.start, rangeEnd );
557 if ( rangesAdded >= maxRanges ) {
558 MIL <<
_easyHandle <<
" " <<
"Reached max nr of ranges (" << maxRanges <<
"), batching the request to not break the server" << std::endl;
564 if ( currentZippedRange )
565 addRangeString( *currentZippedRange );
567 MIL <<
_easyHandle <<
" " <<
"Requesting Ranges: " << rangeDesc << std::endl;
583 bool isRangeContinuation = std::holds_alternative<prepareNextRangeBatch_t>(
_runningMode );
584 if ( isRangeContinuation ) {
585 MIL <<
_easyHandle <<
" " <<
"Continuing a previously started range batch." << std::endl;
590 mode._currentRange = 0;
597 if ( m._activityTimer ) {
600 m._activityTimer->start( static_cast<uint64_t>(
_settings.
timeout() * 1000 ) );
603 if ( !isRangeContinuation )
609 if ( std::holds_alternative<running_t>(
_runningMode) ) {
612 if ( rmode._currentRange >= 0 ) {
614 rmode._currentRange = -1;
624 resState.
_result = std::move(err);
626 if ( std::holds_alternative<running_t>(
_runningMode) ) {
629 rmode._outFile.reset();
637 if ( r.len > 0 && r.bytesWritten != r.len )
670 MIL_MEDIA <<
_easyHandle <<
" Request timeout interval: " << t.interval()<<
" remaining: " << t.remaining() << std::endl;
671 std::map<std::string, boost::any> extraInfo;
672 extraInfo.insert( {
"requestUrl",
_url } );
680 auto bytesHashed = rng.
_digest->bytesHashed ();
684 rng.
_digest->update( padding.data(), padding.size() );
686 auto digVec = rng.
_digest->digestVector();
718 DBG <<
_easyHandle <<
" " <<
"Invalid Content-Range Header format: '" << std::string(line) << std::endl;
722 size_t s = zypp::str::strtonum<size_t>( what[1]);
723 size_t e = zypp::str::strtonum<size_t>( what[2]);
724 start = std::move(s);
735 if ( what.
size() >= 2 ) {
750 if ( std::holds_alternative<running_t>(
_runningMode ) ){
752 if ( rmode._activityTimer && rmode._activityTimer->isRunning() )
753 rmode._activityTimer->start();
763 if ( !std::holds_alternative<running_t>(that->
_runningMode) ){
764 DBG << that->
_easyHandle <<
" " <<
"Curl progress callback was called in invalid state "<< that->z_func()->state() << std::endl;
768 auto &rmode = std::get<running_t>( that->
_runningMode );
773 rmode._isInCallback =
true;
774 if ( rmode._lastProgressNow != dlnow ) {
775 rmode._lastProgressNow = dlnow;
776 that->
_sigProgress.emit( *that->z_func(), dltotal, dlnow, ultotal, ulnow );
778 rmode._isInCallback =
false;
780 return rmode._cachedResult ? CURLE_ABORTED_BY_CALLBACK : CURLE_OK;
786 if ( size * nmemb == 0)
793 std::string_view hdr( ptr, size*nmemb );
795 hdr.remove_prefix( std::min( hdr.find_first_not_of(
" \t\r\n"), hdr.size() ) );
796 const auto lastNonWhitespace = hdr.find_last_not_of(
" \t\r\n");
797 if ( lastNonWhitespace != hdr.npos )
798 hdr.remove_suffix( hdr.size() - (lastNonWhitespace + 1) );
800 hdr = std::string_view();
804 return ( size * nmemb );
809 (void)curl_easy_getinfo(
_easyHandle, CURLINFO_RESPONSE_CODE, &statuscode);
811 const auto &doRangeFail = [&](){
812 WAR <<
_easyHandle <<
" " <<
"Range FAIL, trying with a smaller batch" << std::endl;
827 if ( rmode._requireStatusPartial ) {
829 if ( ( statuscode >= 200 && statuscode <= 299 && statuscode != 206 )
830 || statuscode == 416 ) {
831 return doRangeFail();
842 rmode._gotMultiRangeHeader =
true;
843 rmode._seperatorString =
"--"+sep;
852 rmode._gotContentRangeHeader =
true;
853 rmode._currentSrvRange = r;
857 auto str = std::string ( lenStr.data(), lenStr.length() );
858 auto len = zypp::str::strtonum<typename zypp::ByteCount::SizeType>(
str.data() );
860 DBG <<
_easyHandle <<
" " <<
"Got Content-Length Header: " << len << std::endl;
866 return ( size * nmemb );
871 const auto max = ( size * nmemb );
881 return ( size * nmemb );
886 auto writeDataToFile = [
this, &rmode ]( off_t offset,
const char *data,
size_t len ) -> off_t {
888 if ( rmode._currentRange < 0 ) {
889 DBG <<
_easyHandle <<
" " <<
"Current range is zero in write request" << std::endl;
899 if ( fseek( rmode._outFile, offset, SEEK_SET ) != 0 ) {
901 "Unable to set output file pointer." );
907 const auto bytesToWrite = rng.len > 0 ? std::min( rng.len - rng.bytesWritten, len ) : len;
915 auto written = fwrite( data, 1, bytesToWrite, rmode._outFile );
919 if ( rng._digest && rng._checksum.size() ) {
920 if ( !rng._digest->update( data, written ) )
924 rng.bytesWritten += written;
925 if ( rmode._currentSrvRange ) rmode._currentSrvRange->bytesWritten += written;
927 if ( rng.len > 0 && rng.bytesWritten >= rng.len ) {
928 rmode._currentRange = -1;
932 if ( rmode._currentSrvRange && rmode._currentSrvRange->len > 0 && rmode._currentSrvRange->bytesWritten >= rmode._currentSrvRange->len ) {
933 rmode._currentSrvRange.reset();
936 rmode._currentRange = -1;
940 rmode._downloaded += written;
947 size_t bytesWrittenSoFar = 0;
949 while ( bytesWrittenSoFar != max ) {
954 if ( !rmode._allHeadersReceived ) {
955 rmode._allHeadersReceived =
true;
958 if ( !rmode._gotMultiRangeHeader && !rmode._gotContentRangeHeader ) {
960 if ( rmode._requireStatusPartial ) {
963 "Invalid data from server, range respone was announced but there was no range definiton." );
973 rmode._currentRange = 0;
978 if ( rmode._currentSrvRange && rmode._currentRange == -1 ) {
984 std::optional<uint> foundRange;
985 const size_t beginRange = rmode._currentSrvRange->start + rmode._currentSrvRange->bytesWritten;
986 const size_t endRange = beginRange + (rmode._currentSrvRange->len - rmode._currentSrvRange->bytesWritten);
987 auto currDist = ULONG_MAX;
996 if ( currR.len == currR.bytesWritten )
999 const auto currRBegin = currR.start + currR.bytesWritten;
1000 if ( !( beginRange <= currRBegin && endRange >= currRBegin ) )
1004 const auto newDist = currRBegin - beginRange;
1006 if ( !foundRange ) {
1011 if ( newDist < currDist ) {
1017 if ( !foundRange ) {
1019 ,
"Unable to find a matching range for data returned by the server." );
1024 rmode._currentRange = *foundRange;
1030 const auto skipBytes = seekTo - beginRange;
1031 bytesWrittenSoFar += skipBytes;
1032 rmode._currentSrvRange->bytesWritten += skipBytes;
1035 if ( rmode._currentRange >= 0 ) {
1036 auto availableData = max - bytesWrittenSoFar;
1037 if ( rmode._currentSrvRange ) {
1038 availableData = std::min( availableData, rmode._currentSrvRange->len - rmode._currentSrvRange->bytesWritten );
1040 auto bw = writeDataToFile( seekTo, ptr + bytesWrittenSoFar, availableData );
1044 bytesWrittenSoFar += bw;
1047 if ( bytesWrittenSoFar == max )
1050 if ( rmode._currentRange == -1 ) {
1053 if ( rmode._currentSrvRange )
1056 std::string_view incoming( ptr + bytesWrittenSoFar, max - bytesWrittenSoFar );
1057 auto hdrEnd = incoming.find(
"\r\n\r\n");
1058 if ( hdrEnd == incoming.npos ) {
1060 rmode._rangePrefaceBuffer.insert( rmode._rangePrefaceBuffer.end(), incoming.begin(), incoming.end() );
1065 rmode._rangePrefaceBuffer.insert( rmode._rangePrefaceBuffer.end(), incoming.begin(), incoming.begin() + ( hdrEnd + 4 ) );
1066 bytesWrittenSoFar += ( hdrEnd + 4 );
1068 std::string_view data( rmode._rangePrefaceBuffer.data(), rmode._rangePrefaceBuffer.size() );
1069 auto sepStrIndex = data.find( rmode._seperatorString );
1070 if ( sepStrIndex == data.npos ) {
1072 "Invalid multirange header format, seperator string missing." );
1076 auto startOfHeader = sepStrIndex + rmode._seperatorString.length();
1077 std::vector<std::string_view> lines;
1079 for (
const auto &hdrLine : lines ) {
1087 rmode._currentSrvRange = r;
1092 rmode._rangePrefaceBuffer.clear();
1095 return bytesWrittenSoFar;
1109 if ( d->_dispatcher )
1110 d->_dispatcher->cancel( *
this,
"Request destroyed while still running" );
1115 d_func()->_expectedFileSize = std::move( expectedFileSize );
1121 d->_priority = prio;
1122 if (
state() ==
Pending && triggerReschedule && d->_dispatcher )
1123 d->_dispatcher->reschedule();
1128 return d_func()->_priority;
1133 d_func()->_options = opt;
1138 return d_func()->_options;
1147 d->_requestedRanges.push_back(
Range::make( start, len, std::move(digest), std::move( expectedChkSum ), std::move( userData ), digestCompareLen, chksumpad ) );
1156 d->_requestedRanges.push_back( range );
1157 auto &rng = d->_requestedRanges.back();
1159 rng.bytesWritten = 0;
1161 rng._digest->reset();
1169 d->_requestedRanges.clear();
1174 const auto mystate =
state();
1180 std::vector<Range> failed;
1181 for (
const auto &r : d->_requestedRanges ) {
1183 failed.push_back( r );
1190 return d_func()->_requestedRanges;
1195 return d_func()->_lastRedirect;
1200 return d_func()->_easyHandle;
1205 const auto myerr =
error();
1206 const auto mystate =
state();
1212 auto getMeasurement = [ this ](
const CURLINFO info, std::chrono::microseconds &target ){
1213 using FPSeconds = std::chrono::duration<double, std::chrono::seconds::period>;
1215 const auto res = curl_easy_getinfo( d_func()->_easyHandle, info, &val );
1216 if ( CURLE_OK == res ) {
1217 target = std::chrono::duration_cast<std::chrono::microseconds>( FPSeconds(val) );
1221 getMeasurement( CURLINFO_NAMELOOKUP_TIME, t.
namelookup );
1222 getMeasurement( CURLINFO_CONNECT_TIME, t.
connect);
1223 getMeasurement( CURLINFO_APPCONNECT_TIME, t.
appconnect);
1224 getMeasurement( CURLINFO_PRETRANSFER_TIME , t.
pretransfer);
1225 getMeasurement( CURLINFO_TOTAL_TIME, t.
total);
1226 getMeasurement( CURLINFO_REDIRECT_TIME, t.
redirect);
1235 if ( !std::holds_alternative<NetworkRequestPrivate::running_t>( d->_runningMode) )
1238 const auto &rmode = std::get<NetworkRequestPrivate::running_t>( d->_runningMode );
1244 return d_func()->_url;
1258 return d_func()->_targetFile;
1266 d->_targetFile = path;
1271 return d_func()->_fMode;
1279 d->_fMode = std::move( mode );
1285 if ( curl_easy_getinfo( d_func()->_easyHandle, CURLINFO_CONTENT_TYPE, &ptr ) == CURLE_OK && ptr )
1286 return std::string(ptr);
1287 return std::string();
1293 using T = std::decay_t<decltype(arg)>;
1294 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
1296 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
1297 || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
1298 return arg._contentLenght;
1300 static_assert(always_false<T>::value,
"Unhandled state type");
1301 }, d_func()->_runningMode);
1307 using T = std::decay_t<decltype(arg)>;
1308 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
1310 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t>
1311 || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t>
1312 || std::is_same_v<T, NetworkRequestPrivate::finished_t>)
1313 return arg._downloaded;
1315 static_assert(always_false<T>::value,
"Unhandled state type");
1316 }, d_func()->_runningMode);
1321 return d_func()->_settings;
1326 return std::visit([
this](
auto& arg) {
1327 using T = std::decay_t<decltype(arg)>;
1328 if constexpr (std::is_same_v<T, NetworkRequestPrivate::pending_t>)
1330 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::running_t> || std::is_same_v<T, NetworkRequestPrivate::prepareNextRangeBatch_t> )
1332 else if constexpr (std::is_same_v<T, NetworkRequestPrivate::finished_t>) {
1333 if ( std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode ).
_result.isError() )
1339 static_assert(always_false<T>::value,
"Unhandled state type");
1340 }, d_func()->_runningMode);
1345 const auto s =
state();
1348 return std::get<NetworkRequestPrivate::finished_t>( d_func()->_runningMode).
_result;
1354 return std::string();
1368 curl_slist *res = curl_slist_append( d->_headers ? d->_headers.get() :
nullptr, header.c_str() );
1373 d->_headers = std::unique_ptr< curl_slist, decltype (&curl_slist_free_all) >( res, &curl_slist_free_all );
1380 return d_func()->_sigStarted;
1385 return d_func()->_sigBytesDownloaded;
1390 return d_func()->_sigProgress;
1395 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
int assert_file_mode(const Pathname &path, unsigned mode)
Like assert_file but enforce mode even if the file already exists.
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