From 97bc5a7eda827882bb284756926a250ea3929680 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Thu, 30 May 2013 14:12:50 +0200 Subject: [PATCH] xml_parser_internal: Add cr_xml_parser_strtoll. --- src/xml_parser.c | 27 +++++++++++++++++++++++++++ src/xml_parser_internal.h | 26 ++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/xml_parser.c b/src/xml_parser.c index e169619..cb64520 100644 --- a/src/xml_parser.c +++ b/src/xml_parser.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "error.h" #include "xml_parser.h" #include "xml_parser_internal.h" @@ -91,6 +92,32 @@ cr_xml_parser_warning(cr_ParserData *pd, return ret; } +gint64 +cr_xml_parser_strtoll(cr_ParserData *pd, + const char *nptr, + unsigned int base) +{ + gint64 val; + char *endptr; + + assert(pd); + assert(base <= 36 && base != 1); + + if (!nptr) + return 0; + + val = g_ascii_strtoll(nptr, &endptr, base); + + if ((val == G_MAXINT64 || val == G_MININT64) && errno == ERANGE) + cr_xml_parser_warning(pd, CR_XML_WARNING_BADATTRVAL, + "Correct integer value \"%s\" caused overflow", nptr); + else if (val == 0 && endptr) + cr_xml_parser_warning(pd, CR_XML_WARNING_BADATTRVAL, + "Conversion of \"%s\" to integer failed", nptr); + + return val; +} + int cr_newpkgcb(cr_Package **pkg, const char *pkgId, diff --git a/src/xml_parser_internal.h b/src/xml_parser_internal.h index 8647774..70fda04 100644 --- a/src/xml_parser_internal.h +++ b/src/xml_parser_internal.h @@ -93,9 +93,25 @@ typedef struct _cr_ParserData { cr_Package *pkg; /*!< The package which is currently loaded. */ - /* Filelists related stuff */ + /* Primary related stuff */ + + int do_files; /*!< + If == 0 then parser will ignore files elements in the primary.xml. + This is useful when you are inteding parse primary.xml as well as + filelists.xml. In this case files will be filled from filelists.xml. + If you are inteding parse only the primary.xml then it coud be useful + to parse files in primary. + If you parse files from both a primary.xml and a filelists.xml + then some files in package object will be duplicated! */ + + /* Filelists + Primary related stuff */ + + cr_FileType last_file_type; + + /* Other related stuff */ + + cr_ChangelogEntry *changelog; - int last_file_type; } cr_ParserData; /** Malloc and initialize common part of XML parser data. @@ -136,6 +152,12 @@ int cr_xml_parser_warning(cr_ParserData *pd, const char *msg, ...); +/** strtoll with ability to call warning cb if error during conversion. + */ +gint64 cr_xml_parser_strtoll(cr_ParserData *pd, + const char *nptr, + unsigned int base); + /** Default callback for the new package. */ int cr_newpkgcb(cr_Package **pkg, -- 2.7.4