misc: Add default implementation of xml warning callback.
authorTomas Mlcoch <tmlcoch@redhat.com>
Wed, 18 Sep 2013 13:13:27 +0000 (15:13 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Wed, 18 Sep 2013 13:13:27 +0000 (15:13 +0200)
src/load_metadata.c
src/locate_metadata.c
src/misc.c
src/misc.h

index 682d4dc..35b0e1c 100644 (file)
@@ -134,18 +134,6 @@ typedef struct {
 } cr_CbData;
 
 static int
-warning_cb(cr_XmlParserWarningType type,
-           char *msg,
-           void *cbdata,
-           GError **err)
-{
-    CR_UNUSED(type);
-    CR_UNUSED(err);
-
-    g_warning("%s: %s", cbdata, msg);
-}
-
-static int
 primary_newpkgcb(cr_Package **pkg,
          const char *pkgId,
          const char *name,
@@ -272,7 +260,7 @@ cr_load_xml_files(GHashTable *hashtable,
                          &cb_data,
                          primary_pkgcb,
                          &cb_data,
-                         warning_cb,
+                         cr_warning_cb,
                          "Primary XML parser",
                          (filelists_xml_path) ? 0 : 1,
                          &tmp_err);
@@ -289,7 +277,7 @@ cr_load_xml_files(GHashTable *hashtable,
                                &cb_data,
                                pkgcb,
                                &cb_data,
-                               warning_cb,
+                               cr_warning_cb,
                                "Filelists XML parser",
                                &tmp_err);
         if (tmp_err) {
@@ -306,7 +294,7 @@ cr_load_xml_files(GHashTable *hashtable,
                            &cb_data,
                            pkgcb,
                            &cb_data,
-                           warning_cb,
+                           cr_warning_cb,
                            "Other XML parser",
                            &tmp_err);
         if (tmp_err) {
index 912f5f1..c1a7669 100644 (file)
@@ -65,19 +65,6 @@ cr_metadatalocation_free(struct cr_MetadataLocation *ml)
     g_free(ml);
 }
 
-static int
-warning_cb(cr_XmlParserWarningType type,
-           char *msg,
-           void *cbdata,
-           GError **err)
-{
-    CR_UNUSED(type);
-    CR_UNUSED(cbdata);
-    CR_UNUSED(err);
-
-    g_warning("Repomd xml parser: %s", msg);
-}
-
 static struct cr_MetadataLocation *
 cr_parse_repomd(const char *repomd_path,
                 const char *repopath,
@@ -88,7 +75,8 @@ cr_parse_repomd(const char *repomd_path,
     GError *tmp_err = NULL;
     cr_Repomd *repomd = cr_repomd_new();
 
-    cr_xml_parse_repomd(repomd_path, repomd, warning_cb, NULL, &tmp_err);
+    cr_xml_parse_repomd(repomd_path, repomd, cr_warning_cb,
+                        "Repomd xml parser", &tmp_err);
     if (tmp_err) {
         g_error("%s: %s", __func__, tmp_err->message);
         g_error_free(tmp_err);
index 4ea08fc..be1d611 100644 (file)
@@ -969,3 +969,15 @@ cr_cmp_evr(const char *e1, const char *v1, const char *r1,
     rc = cr_compare_values(r1, r2);
     return rc;
 }
+
+int
+cr_warning_cb(cr_XmlParserWarningType type,
+           char *msg,
+           void *cbdata,
+           GError **err)
+{
+    CR_UNUSED(type);
+    CR_UNUSED(err);
+
+    g_warning("%s: %s", cbdata, msg);
+}
index 46d771d..2de9550 100644 (file)
@@ -28,6 +28,7 @@ extern "C" {
 #include <string.h>
 #include <curl/curl.h>
 #include "compression_wrapper.h"
+#include "xml_parser.h"
 
 /** \defgroup   misc    Miscellaneous useful functions and macros.
  *  \addtogroup misc
@@ -313,6 +314,17 @@ cr_safe_string_chunk_insert_const(GStringChunk *chunk, const char *str)
     return g_string_chunk_insert_const(chunk, str);
 }
 
+/** Warning callback for xml parser warnings.
+ * For use in xml parsers like primary, filelists, other or repomd parser.
+ * Name of the parser should be passed as a string via
+ * warning callback data (warningcb_data) argument of the parser.
+ */
+int
+cr_warning_cb(cr_XmlParserWarningType type,
+           char *msg,
+           void *cbdata,
+           GError **err);
+
 /** @} */
 
 #ifdef __cplusplus