21 constexpr auto minMetalinkProbeSize = 256;
23 MetaDataType looks_like_meta_data(
const std::vector<char> &data )
28 const char *p = data.data();
29 while (*p ==
' ' || *p ==
'\t' || *p ==
'\r' || *p ==
'\n')
33 if ( !strncasecmp( p,
"zsync:", 6 ) ) {
37 if (!strncasecmp(p,
"<?xml", 5))
39 while (*p && *p !=
'>')
43 while (*p ==
' ' || *p ==
'\t' || *p ==
'\r' || *p ==
'\n')
46 bool ret = !strncasecmp( p,
"<metalink", 9 ) ? true :
false;
55 std::unique_ptr<FILE,
decltype(&fclose)> fd( fopen( file.
c_str(),
"r" ), &fclose );
65 MIL <<
"Downloading metalink/zsync on " << parent.
_spec.
url() << std::endl;
71 MIL <<
"Downloading metalink/zsync on " << parent.
_spec.
url() << std::endl;
76 MIL <<
"Downloading on " << stateMachine()._spec.url() <<
" transition to final state. " << std::endl;
77 return std::make_shared<FinishedState>( std::move(
_error), stateMachine() );
84 auto nState = std::make_shared<PrepareMultiState>( std::move(
_request ), prepareMode, stateMachine() );
91 MIL <<
"Requesting Metadata info from server!" << std::endl;
92 r->transferSettings().addHeader(
"Accept: */*, application/x-zsync, application/metalink+xml, application/metalink4+xml");
104 MIL <<
"Downloading on " << stateMachine()._spec.url() <<
" was successful, no metalink/zsync data. " << std::endl;
108 auto &sm = stateMachine();
109 if ( sm._stopOnMetalink ) {
110 MIL <<
"Stopping after receiving MetaData as requested" << std::endl;
111 sm._stoppedOnMetalink =
true;
117 MIL <<
"Downloading on " << sm._spec.url() <<
" returned a Zsync file " << std::endl;
119 MIL <<
"Downloading on " << sm._spec.url() <<
" returned a Metalink file" << std::endl;
125 auto &sm = stateMachine();
129 return sm._sigAlive.emit( *sm.z_func(), dlnow );
134 if ( cType.find(
"application/x-zsync") == 0 )
136 else if ( cType.find(
"application/metalink+xml") == 0 || cType.find(
"application/metalink4+xml") == 0 )
147 WAR <<
"Metadata file exceeds 2MB in filesize, aborting."<<std::endl;
152 return sm._sigAlive.emit( *sm.z_func(), dlnow );
158 MIL <<
"No Metalink file detected after " << minMetalinkProbeSize <<
", falling back to normal progress updates" << std::endl;
Store and operate with byte count.
static const Unit MB
1000^2 Byte
const char * c_str() const
String representation.
static zyppng::NetworkRequestError customError(NetworkRequestError::Type t, std::string &&errorMsg="", std::map< std::string, boost::any > &&extraInfo={})
zypp::ByteCount downloadedByteCount() const
Returns the number of already downloaded bytes as reported by the backend.
std::vector< char > peekData(off_t offset, size_t count) const
std::string contentType() const
Returns the content type as reported from the server.
std::vector< char > peek_data_fd(FILE *fd, off_t offset, size_t count)
virtual void handleRequestProgress(NetworkRequest &req, off_t dltotal, off_t dlnow)
virtual void gotFinished()
NetworkRequestError _error
std::shared_ptr< Request > _request
virtual bool initializeRequest(std::shared_ptr< Request > &r)