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 {
109 static void XMLCALL
startElement(
void *userData,
const xmlChar *name,
const xmlChar **atts);
110 static void XMLCALL
endElement(
void *userData,
const xmlChar *name);
111 static void XMLCALL
characterData(
void *userData,
const xmlChar *s,
int len);
126 content.reserve( 256 );
129 memset(&sax, 0,
sizeof(sax));
139 parentStates.push( state );
147 state = parentStates.top();
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]);
205 startElement(
void *userData,
const xmlChar *name,
const xmlChar **atts)
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);
329 #define c2h(c) (((c)>='0' && (c)<='9') ? ((c)-'0') \ 330 : ((c)>='a' && (c)<='f') ? ((c)-('a'-10)) \ 331 : ((c)>='A' && (c)<='F') ? ((c)-('A'-10)) \ 340 bytes.back() = (bytes.back() << 4) | v;
360 pd->
size = (off_t)str::strtonum<off_t>(pd->
content);
377 if ( !pieceHash.size() )
378 pieceHash.resize( pd->
piecel, 0 );
379 pd->
piece.push_back( pieceHash );
418 pd->
content.append( s, s+len );
422 MetaLinkParser::MetaLinkParser()
443 while (is.
stream().good())
445 is.
stream().read(buf,
sizeof(buf));
457 if (xmlParseChunk(
pd->
parser, buf, len, 0)) {
465 if (xmlParseChunk(
pd->
parser, NULL, 0, 1)) {
469 stable_sort(
pd->
urls.begin(),
pd->
urls.end(), [](
const auto &a,
const auto &b ){
470 return a.priority < b.priority;
478 std::vector<Url> urls;
479 for (
const auto &mirr :
pd->
urls )
480 urls.push_back( mirr.url );
501 for (
size_t i = 0; i < nb; i++ )
509 size_t blkno = bl.
addBlock(off, size);
510 if ( i < pd->sha1.size())
513 if ( i < pd->zsync.size())
515 unsigned char *p =
pd->
zsync[i].data();
516 bl.
setRsum(blkno, 4, p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24,
pd->
blksize);
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Base class for Exception.
std::vector< unsigned char > ByteArray