14#include <zypp-core/base/Logger.h>
15#include <zypp-core/ByteArray.h>
16#include <zypp-core/AutoDispose.h>
22#include <libxml2/libxml/SAX2.h>
31 static bool val = [](){
32 const char * env =
getenv(
"ZYPP_METALINK_DEBUG");
72 const std::unordered_map<ParserState, std::vector<transition> > &
transitions () {
73 static std::unordered_map<ParserState, std::vector<transition> > map {
185 std::vector<MetalinkMirror>
urls;
212 return reinterpret_cast<const char*
>(
atts[1]);
237 return tr.elementName == reinterpret_cast<const char *>(name);
260 auto &
mirr = pd->
urls.emplace_back();
262 prio = str::strtonum<int>(priority);
286 blksize = str::strtonum<unsigned long>(
length);
296 else if (!
strcmp(type,
"zsync"))
313 else if (!
strcmp(type,
"sha256") || !
strcmp(type,
"sha-256"))
339 return Digest::hexStringToUByteArray(
str );
356 pd->
size = (off_t)str::strtonum<off_t>(pd->
content);
439 while (
is.stream().good())
445 MIL <<
"Parsed " <<
pd->urls.size() <<
" mirrors from " <<
is.path() << std::endl;
447 for (
const auto &
mirr :
pd->urls )
448 DBG <<
"- " <<
mirr.priority <<
" " <<
mirr.url << std::endl;
469 if (
pd->urls.size() ) {
470 stable_sort(
pd->urls.begin(),
pd->urls.end(), [](
const auto &
a,
const auto &
b ){
471 return a.priority < b.priority;
479 std::vector<Url> urls;
480 urls.reserve(
pd->urls.size());
481 for (
const auto &
mirr :
pd->urls )
482 urls.push_back(
mirr.url );
494 if (
pd->chksuml == 20)
496 else if (
pd->chksuml == 32)
498 if (
pd->size != off_t(-1) &&
pd->blksize)
500 size_t nb = (
pd->size +
pd->blksize - 1) /
pd->blksize;
502 size_t size =
pd->blksize;
503 for (
size_t i = 0;
i <
nb;
i++ )
507 size =
pd->size %
pd->blksize;
517 unsigned char *
p =
pd->zsync[
i].data();
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Base class for Exception.
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
bool ZYPP_METALINK_DEBUG()
Hack to circumvent the currently poor –root support.
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.