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>
59 const std::unordered_map<ParserState, std::vector<transition> > &
transitions () {
60 static std::unordered_map<ParserState, std::vector<transition> > map {
109static void XMLCALL
startElement(
void *userData,
const xmlChar *name,
const xmlChar **atts);
110static void XMLCALL
endElement(
void *userData,
const xmlChar *name);
111static void XMLCALL
characterData(
void *userData,
const xmlChar *s,
int len);
129 memset(&sax, 0,
sizeof(sax));
172 std::vector<MetalinkMirror>
urls;
196 for (; *atts; atts += 2)
198 if (!strcmp(
reinterpret_cast<const char*
>(*atts), txt))
199 return reinterpret_cast<const char*
>(atts[1]);
218 const auto currStateTrs = trMap.find( pd->
state );
219 if ( currStateTrs == trMap.end() )
223 auto foundTr = std::find_if( currStateTrs->second.begin(), currStateTrs->second.end(), [name](
const auto &tr ){
224 return tr.elementName == reinterpret_cast<const char *>(name);
227 if ( foundTr == currStateTrs->second.end() ) {
243 const char *priority =
find_attr(
"priority", atts);
244 const char *preference =
find_attr(
"preference", atts);
245 const char *maxconnections =
find_attr(
"maxconnections", atts);
247 auto &mirr = pd->
urls.emplace_back();
249 prio = str::strtonum<int>(priority);
251 prio = 101 - str::strtonum<int>(preference);
254 mirr.priority = prio;
256 if ( maxconnections )
257 mirr.maxConnections = str::strtonum<int>( maxconnections );
264 const char *type =
find_attr(
"type", atts);
265 const char *length =
find_attr(
"length", atts);
268 if (!type || !length)
273 blksize = str::strtonum<unsigned long>(length);
281 if (!strcmp(type,
"sha1") || !strcmp(type,
"sha-1"))
283 else if (!strcmp(type,
"zsync"))
295 const char *type =
find_attr(
"type", atts);
298 if ((!strcmp(type,
"sha1") || !strcmp(type,
"sha-1")) && pd->
chksuml < 20)
300 else if (!strcmp(type,
"sha256") || !strcmp(type,
"sha-256"))
312 const char *piece =
find_attr(
"piece", atts);
326 return Digest::hexStringToUByteArray(
str );
343 pd->
size = (off_t)str::strtonum<off_t>(pd->
content);
360 if ( !pieceHash.size() )
361 pieceHash.resize( pd->
piecel, 0 );
362 pd->
piece.push_back( pieceHash );
401 pd->
content.append( s, s+len );
417 MIL <<
"Begin parse " << filename << std::endl;
419 MIL <<
"End parse " << filename << std::endl;
428 while (is.
stream().good())
430 is.
stream().read(buf,
sizeof(buf));
442 if (xmlParseChunk(
pd->
parser, buf, len, 0)) {
450 if (xmlParseChunk(
pd->
parser, NULL, 0, 1)) {
454 stable_sort(
pd->
urls.begin(),
pd->
urls.end(), [](
const auto &
a,
const auto &
b ){
455 return a.priority < b.priority;
463 std::vector<Url> urls;
464 for (
const auto &mirr :
pd->
urls )
465 urls.push_back( mirr.url );
486 for (
size_t i = 0; i < nb; i++ )
494 size_t blkno = bl.
addBlock(off, size);
495 if ( i < pd->sha1.size())
498 if ( i < pd->zsync.size())
500 unsigned char *p =
pd->
zsync[i].data();
501 bl.
setRsum(blkno, 4, p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24,
pd->
blksize);
Base class for Exception.
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.