xml_parser_internal: Add cr_xml_parser_strtoll.
authorTomas Mlcoch <tmlcoch@redhat.com>
Thu, 30 May 2013 12:12:50 +0000 (14:12 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Thu, 30 May 2013 12:13:08 +0000 (14:13 +0200)
src/xml_parser.c
src/xml_parser_internal.h

index e169619..cb64520 100644 (file)
@@ -1,6 +1,7 @@
 #include <glib.h>
 #include <glib/gprintf.h>
 #include <assert.h>
+#include <errno.h>
 #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,
index 8647774..70fda04 100644 (file)
@@ -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,