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 {
 
 
  122static void XMLCALL 
startElement(
void *userData, 
const xmlChar *name, 
const xmlChar **atts);
 
  123static void XMLCALL 
endElement(
void *userData, 
const xmlChar *name);
 
  124static void XMLCALL 
characterData(
void *userData, 
const xmlChar *s, 
int len);
 
  142    memset(&sax, 0, 
sizeof(sax));
 
 
  185  std::vector<MetalinkMirror> 
urls;
 
 
  209  for (; *atts; atts += 2)
 
  211      if (!strcmp(
reinterpret_cast<const char*
>(*atts), txt))
 
  212        return reinterpret_cast<const char*
>(atts[1]);
 
 
  231  const auto currStateTrs = trMap.find( pd->
state );
 
  232  if ( currStateTrs == trMap.end() )
 
  236  auto foundTr = std::find_if( currStateTrs->second.begin(), currStateTrs->second.end(), [name]( 
const auto &tr ){
 
  237    return tr.elementName == reinterpret_cast<const char *>(name);
 
  240  if ( foundTr == currStateTrs->second.end() ) {
 
  256        const char *priority       = 
find_attr(
"priority", atts);
 
  257        const char *preference     = 
find_attr(
"preference", atts);
 
  258        const char *maxconnections = 
find_attr(
"maxconnections", atts);
 
  260        auto &mirr = pd->
urls.emplace_back();
 
  267        mirr.priority = prio;
 
  269        if ( maxconnections )
 
  277        const char *type = 
find_attr(
"type", atts);
 
  278        const char *length = 
find_attr(
"length", atts);
 
  281        if (!type || !length)
 
  294        if (!strcmp(type, 
"sha1") || !strcmp(type, 
"sha-1"))
 
  296        else if (!strcmp(type, 
"zsync"))
 
  308        const char *type = 
find_attr(
"type", atts);
 
  311        if ((!strcmp(type, 
"sha1") || !strcmp(type, 
"sha-1")) && pd->
chksuml < 20)
 
  313        else if (!strcmp(type, 
"sha256") || !strcmp(type, 
"sha-256"))
 
  325        const char *piece = 
find_attr(
"piece", atts);
 
 
  339  return Digest::hexStringToUByteArray( 
str );
 
 
  373      if ( !pieceHash.size() )
 
  374        pieceHash.resize( pd->
piecel, 0 );
 
  375      pd->
piece.push_back( pieceHash );
 
 
  414  pd->
content.append( s, s+len );
 
 
  439  while (is.
stream().good())
 
  441      is.
stream().read(buf, 
sizeof(buf));
 
  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;
 
 
  458  if (xmlParseChunk(
pd->parser, buf, len, 0)) {
 
 
  466  if (xmlParseChunk(
pd->parser, NULL, 0, 1)) {
 
  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;
 
  511          size_t blkno = bl.
addBlock(off, size);
 
  512          if ( i < pd->sha1.size())
 
  515              if ( i < pd->zsync.size())
 
  517                  unsigned char *p = 
pd->zsync[i].data();
 
  518                  bl.
setRsum(blkno, 4, p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24, 
pd->blksize);
 
 
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.
Namespace intended to collect all environment variables we use.
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.
TInt strtonum(const C_Str &str)
Parsing numbers from string.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.