From 45051a2d6c058228db7da20049dde2ef6a670a72 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Tue, 1 Jul 2008 16:59:39 +0200 Subject: [PATCH] More GErrorizing. --- src/mm-string-utils.c | 93 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/src/mm-string-utils.c b/src/mm-string-utils.c index 0d0ee07..19373d2 100644 --- a/src/mm-string-utils.c +++ b/src/mm-string-utils.c @@ -79,6 +79,18 @@ set_value_error (int res, GError **error) } static void +set_filter_param_error (int res, GError **error) +{ + set_error (res, error, "FilterParam"); +} + +static void +set_operator_error (int res, GError **error) +{ + set_error (res, error, "ComparisionOperator"); +} + +static void serialize_value (xmlTextWriterPtr writer, GValue *v) { xmlChar *safe; @@ -185,8 +197,9 @@ add_filter_param_to_xml (MMFilterParam *fp, xmlTextWriterEndElement (writer); } -static int -unserialize_operator (xmlTextReaderPtr reader, MMComparisionOperator *op) +static void +unserialize_operator (xmlTextReaderPtr reader, MMComparisionOperator *op, + GError **error) { const xmlChar * op_string; gboolean found = FALSE; @@ -194,15 +207,17 @@ unserialize_operator (xmlTextReaderPtr reader, MMComparisionOperator *op) /* we should be on */ if (xmlStrcmp (xmlTextReaderConstName (reader), BAD_CAST ("op")) != 0) { - g_warning ("Error while parsing the serialized xml opeator"); - return -1; + g_set_error (error, MM_XML_ERROR_QUARK, MM_XML_ERROR_UNEXPECTED_NODE, + "Error while parsing the serialized xml opeator: the xml reader " + "does not point to a ComparisionOperator"); + return; } /* move on to the content */ res = xmlTextReaderRead (reader); if (res <= 0) { - g_warning ("Error while parsing the serialized xml operator"); - return res; + set_operator_error (res, error); + return; } op_string = xmlTextReaderConstValue (reader); @@ -213,17 +228,15 @@ unserialize_operator (xmlTextReaderPtr reader, MMComparisionOperator *op) } } + /* move to */ + res = xmlTextReaderRead (reader); + if (res <= 0) { + set_operator_error (res, error); + return; + } + if (found) { *op = operator_grid[idx].op; - res = xmlTextReaderRead (reader); - if (res <= 0) { - g_warning ("Error while parsing the serialized xml operator"); - return res; - } - return xmlTextReaderRead (reader); - } else { - g_warning ("Error while parsing the serialized xml operator"); - return -1; } } @@ -355,40 +368,62 @@ unserialize_filter_param (xmlTextReaderPtr reader, GError **error) MMAttribute *attribute = NULL; MMComparisionOperator op = MM_COMP_NONE; GValue *val = NULL; - MMFilterParam *fp; + MMFilterParam *fp = NULL; res = xmlTextReaderRead (reader); + if (res <= 0) { + set_filter_param_error (res, error); + goto out; + } + /* we're either on or if the object is empty */ while (!((xmlTextReaderNodeType (reader) == XML_READER_TYPE_END_ELEMENT) && xmlStrcmp (xmlTextReaderConstName (reader), BAD_CAST ("filter-param")) == 0) && res > 0) { unserialize_attribute (reader, &attribute, error); + if (error) { + goto out; + } + res = xmlTextReaderRead (reader); if (res <= 0) { - break; + set_filter_param_error (res, error); + goto out; } + /* we're now on */ val = mm_create_gvalue_for_attribute (attribute); unserialize_value (reader, val, error); + if (error) { + goto out; + } + res = xmlTextReaderRead (reader); if (res <= 0) { - break; + set_filter_param_error (res, error); + goto out; } - res = unserialize_operator (reader, &op); - if (res <= 0) { - break; + /* we're now on */ + unserialize_operator (reader, &op, error); + if (error) { + goto out; } - } - if (res == -1) { - g_warning ("Error while parsing the serialized xml filter param"); - return NULL; + /* move after */ + res = xmlTextReaderRead (reader); + if (res <= 0) { + set_filter_param_error (res, error); + goto out; + } } - if (attribute == NULL || op == MM_COMP_NONE || val == NULL) { - g_warning ("Error while parsing the serialized xml filter param"); - return NULL; + /* if we're here, everything in the unserialize sub-operations went well */ + fp = mm_filter_param_new (attribute, val, op); + +out: + if (val) { + g_value_unset (val); + g_free (val); } - fp = mm_filter_param_new (attribute, val, op); return fp; } -- 2.11.4.GIT