From 8256aa32175a6e51ef78d13bd5151f7f1fa359f3 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Wed, 18 Sep 2013 15:13:27 +0200 Subject: [PATCH] misc: Add default implementation of xml warning callback. --- src/load_metadata.c | 18 +++--------------- src/locate_metadata.c | 16 ++-------------- src/misc.c | 12 ++++++++++++ src/misc.h | 12 ++++++++++++ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/load_metadata.c b/src/load_metadata.c index 682d4dc..35b0e1c 100644 --- a/src/load_metadata.c +++ b/src/load_metadata.c @@ -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) { diff --git a/src/locate_metadata.c b/src/locate_metadata.c index 912f5f1..c1a7669 100644 --- a/src/locate_metadata.c +++ b/src/locate_metadata.c @@ -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); diff --git a/src/misc.c b/src/misc.c index 4ea08fc..be1d611 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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); +} diff --git a/src/misc.h b/src/misc.h index 46d771d..2de9550 100644 --- a/src/misc.h +++ b/src/misc.h @@ -28,6 +28,7 @@ extern "C" { #include #include #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 -- 2.7.4