refactoring
authorTomas Mlcoch <xtojaj@gmail.com>
Sun, 26 May 2013 12:29:57 +0000 (14:29 +0200)
committerTomas Mlcoch <xtojaj@gmail.com>
Sun, 26 May 2013 12:29:57 +0000 (14:29 +0200)
src/xml_parser.h
src/xml_parser_filelists.c
src/xml_parser_internal.h

index 5863afd..14be9c0 100644 (file)
@@ -62,15 +62,6 @@ typedef int (*cr_XmlParserNewPkgCb)(cr_Package **pkg,
                                     void *cbdata,
                                     GError **err);
 
-/** Default callback for the new package.
- */
-int cr_newpkgcb(cr_Package **pkg,
-                const char *pkgId,
-                const char *name,
-                const char *arch,
-                void *cbdata,
-                GError **err);
-
 /** Parse filelists.xml. File could be compressed.
  * @param path          Path to filelists.xml (plain or compressed)
  * @param newpkgcb      Callback for new package (Called when new package
index fc4d6cd..9fcd438 100644 (file)
@@ -126,6 +126,10 @@ cr_start_handler(void *pdata, const char *element, const char **attr)
             else
                 g_set_error(&pd->err, CR_XML_PARSER_FIL_ERROR, CRE_CBINTERRUPTED,
                             "Parsing interrupted");
+        } else {
+            // If callback return CRE_OK but it simultaneously set
+            // the tmp_err then it's a programming error.
+            assert(tmp_err == NULL);
         }
 
         if (pd->pkg) {
@@ -272,7 +276,7 @@ cr_xml_parse_filelists(const char *path,
     assert(!messages || *messages == NULL);
     assert(!err || *err == NULL);
 
-    if (!newpkgcb)
+    if (!newpkgcb)  // Use default newpkgcb
         newpkgcb = cr_newpkgcb;
 
     f = cr_open(path, CR_CW_MODE_READ, CR_CW_AUTO_DETECT_COMPRESSION);
index fc66e96..ae8caef 100644 (file)
@@ -33,6 +33,7 @@ extern "C" {
 #define XML_BUFFER_SIZE         8192
 #define CONTENT_REALLOC_STEP    256
 
+/* File types in filelists.xml */
 typedef enum {
     FILE_FILE,
     FILE_DIR,
@@ -88,10 +89,19 @@ typedef struct _cr_ParserData {
     int last_file_type;
 } cr_ParserData;
 
+/** Malloc and initialize common part of XML parser data.
+ */
 cr_ParserData *cr_xml_parser_data();
 
+/** Frees XML parser data.
+ */
 char *cr_xml_parser_data_free(cr_ParserData *pd);
 
+/** Find attribute in list of attributes.
+ * @param name      Attribute name.
+ * @param attr      List of attributes of the tag
+ * @return          Value or NULL
+ */
 static inline const char *
 cr_find_attr(const char *name, const char **attr)
 {
@@ -104,8 +114,19 @@ cr_find_attr(const char *name, const char **attr)
     return NULL;
 }
 
+/** XML character handler
+ */
 void XMLCALL cr_char_handler(void *pdata, const XML_Char *s, int len);
 
+/** Default callback for the new package.
+ */
+int cr_newpkgcb(cr_Package **pkg,
+                const char *pkgId,
+                const char *name,
+                const char *arch,
+                void *cbdata,
+                GError **err);
+
 #ifdef __cplusplus
 }
 #endif