1#ifndef ZYPPNG_CURLMULTIPARTHANDLER_H
2#define ZYPPNG_CURLMULTIPARTHANDLER_H
4#include <zypp-core/zyppng/base/Base>
5#include <zypp-core/zyppng/core/ByteArray>
7#include <zypp-core/zyppng/pipelines/Expected>
8#include <zypp-curl/ng/network/NetworkRequestError>
33 virtual size_t writefunction (
char *ptr, std::optional<off_t> offset,
size_t bytes ) = 0;
42 virtual bool beginRange ( off_t range, std::string &cancelReason ) {
return true; };
54 virtual bool finishedRange ( off_t range,
bool validated, std::string &cancelReason ) {
return true; };
123 static Range make (
size_t start,
size_t len = 0, std::optional<zypp::Digest> &&digest = {},
CheckSumBytes &&expectedChkSum =
CheckSumBytes(), std::any &&
userData = std::any(), std::optional<size_t> digestCompareLen = {}, std::optional<size_t> _dataBlockPadding = {} );
151 void setCode (
Code c, std::string msg,
bool force =
false );
153 static size_t curl_hdrcallback (
char *ptr,
size_t size,
size_t nmemb,
void *userdata );
154 static size_t curl_wrtcallback (
char *ptr,
size_t size,
size_t nmemb,
void *userdata );
156 size_t hdrcallback (
char *ptr,
size_t size,
size_t nmemb );
157 size_t wrtcallback (
char *ptr,
size_t size,
size_t nmemb );
virtual size_t headerfunction(char *ptr, size_t bytes)=0
virtual void notifyErrorCodeChanged()
virtual ~CurlMultiPartDataReceiver()=default
virtual size_t writefunction(char *ptr, std::optional< off_t > offset, size_t bytes)=0
virtual bool finishedRange(off_t range, bool validated, std::string &cancelReason)
virtual bool beginRange(off_t range, std::string &cancelReason)
size_t wrtcallback(char *ptr, size_t size, size_t nmemb)
unsigned _rangeAttemptIdx
static constexpr unsigned _rangeAttemptSize
ProtocolMode _protocolMode
CurlMultiPartHandler(ProtocolMode mode, void *easyHandle, std::vector< Range > &ranges, CurlMultiPartDataReceiver &receiver)
std::optional< Range > _currentSrvRange
std::string _seperatorString
The seperator string for multipart responses as defined in RFC 7233 Section 4.1.
NetworkRequestError::Type Code
std::string _lastErrorMsg
bool _gotContentRangeInfo
static size_t curl_wrtcallback(char *ptr, size_t size, size_t nmemb, void *userdata)
static size_t curl_hdrcallback(char *ptr, size_t size, size_t nmemb, void *userdata)
~CurlMultiPartHandler() override
const std::string & lastErrorMessage() const
static constexpr unsigned _rangeAttempt[]
bool parseContentRangeHeader(const std::string_view &line, size_t &start, size_t &len, size_t &fileLen)
void setCode(Code c, std::string msg, bool force=false)
std::vector< char > _rangePrefaceBuffer
Here we buffer.
std::optional< off_t > currentRange() const
std::optional< size_t > _reportedFileSize
Filesize as reported by the content range or byte range headers.
size_t hdrcallback(char *ptr, size_t size, size_t nmemb)
bool validateRange(Range &rng)
CurlMultiPartDataReceiver & _receiver
void setRangeState(Range &rng, State state)
std::optional< size_t > reportedFileSize() const
bool parseContentTypeMultiRangeHeader(const std::string_view &line, std::string &boundary)
void * easyHandle() const
bool checkIfRangeChkSumIsValid(Range &rng)
std::vector< Range > & _requestedRanges
the requested ranges that need to be downloaded
std::optional< off_t > _currentRange
std::optional< zypp::Digest > _digest
Enables automated checking of downloaded contents against a checksum.
static Range make(size_t start, size_t len=0, std::optional< zypp::Digest > &&digest={}, CheckSumBytes &&expectedChkSum=CheckSumBytes(), std::any &&userData=std::any(), std::optional< size_t > digestCompareLen={}, std::optional< size_t > _dataBlockPadding={})