From: <svn...@op...> - 2009-07-09 10:33:53
|
Author: bellmich Date: Thu Jul 9 12:33:42 2009 New Revision: 1161 URL: http://libsyncml.opensync.org/changeset/1161 Log: migrated parser/sml_xml_parser from SmlError to GError Modified: trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/parser/sml_xml_parse.h trunk/libsyncml/parser/sml_xml_parse_internals.h Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Wed Jul 8 17:23:22 2009 (r1160) +++ trunk/libsyncml/parser/sml_xml_parse.c Thu Jul 9 12:33:42 2009 (r1161) @@ -33,9 +33,9 @@ #define BUFFER_SIZE 500 -static SmlBool _smlXmlParserStep(SmlXmlParser *parser) +static gboolean _smlXmlParserStep(SmlXmlParser *parser) { - SmlBool ret = FALSE; + gboolean ret = FALSE; do { ret = (xmlTextReaderRead(parser->reader) == 1) ? TRUE : FALSE; } while (ret && (xmlTextReaderNodeType(parser->reader) == XML_READER_TYPE_DOCUMENT_TYPE || \ @@ -45,9 +45,9 @@ return ret; } -static SmlBool _smlXmlParserStepData(SmlXmlParser *parser) +static gboolean _smlXmlParserStepData(SmlXmlParser *parser) { - SmlBool ret = FALSE; + gboolean ret = FALSE; do { ret = (xmlTextReaderRead(parser->reader) == 1) ? TRUE : FALSE; } while (ret && (xmlTextReaderNodeType(parser->reader) == XML_READER_TYPE_DOCUMENT_TYPE || \ @@ -56,7 +56,7 @@ return ret; } -static SmlBool _smlXmlSkipNode(SmlXmlParser *parser) +static gboolean _smlXmlSkipNode(SmlXmlParser *parser) { int node_type; @@ -75,16 +75,21 @@ return TRUE; } -static SmlBool _smlXmlParserExpectNode(SmlXmlParser *parser, int type, SmlBool empty, const char *name, SmlError **error) +static gboolean +_smlXmlParserExpectNode (SmlXmlParser *parser, + int type, + gboolean empty, + const gchar *name, + GError **error) { CHECK_ERROR_REF if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No node at all"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No node at all"); return FALSE; } if (xmlTextReaderNodeType(parser->reader) != type) { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong node type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong node type"); return FALSE; } @@ -94,38 +99,42 @@ case XML_NODE_CLOSE: if (name) { if (!xmlTextReaderConstName(parser->reader)) { - smlErrorSet(error, SML_ERROR_GENERIC, "no name"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "no name"); return FALSE; } if (strcmp((char *)xmlTextReaderConstName(parser->reader), name)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Wrong name"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Wrong name"); return FALSE; } } break; case XML_NODE_TEXT: if (!empty && !xmlTextReaderConstName(parser->reader)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Empty."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Empty."); return FALSE; } break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown node type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown node type"); return FALSE; } return TRUE; } -static SmlBool _smlXmlParserGetID(SmlXmlParser *parser, unsigned int *id, const char *name, SmlError **error) +static gboolean +_smlXmlParserGetID (SmlXmlParser *parser, + guint64 *id, + const gchar *name, + GError **error) { CHECK_ERROR_REF smlAssert(parser); smlAssert(id); if (*id) { - smlErrorSet(error, SML_ERROR_GENERIC, "Id already set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Id already set"); goto error; } @@ -138,19 +147,22 @@ goto error; return TRUE; - error: return FALSE; } -static SmlBool _smlXmlParserGetString(SmlXmlParser *parser, char **string, const char *name, SmlError **error) +static gboolean +_smlXmlParserGetString (SmlXmlParser *parser, + gchar **string, + const gchar *name, + GError **error) { CHECK_ERROR_REF smlAssert(parser); smlAssert(string); if (*string) { - smlErrorSet(error, SML_ERROR_GENERIC, "string already set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "string already set"); goto error; } @@ -161,7 +173,7 @@ } if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No node at all"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No node at all"); goto error_clear; } @@ -173,7 +185,7 @@ } else if (xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { *string = g_strdup(""); } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong node type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong node type"); goto error_clear; } @@ -185,7 +197,12 @@ return FALSE; } -static SmlBool _smlXmlParserGetData(SmlXmlParser *parser, char **string, unsigned int *size, const char *name, SmlError **error) +static gboolean +_smlXmlParserGetData (SmlXmlParser *parser, + gchar **string, + gsize *size, + const gchar *name, + GError **error) { CHECK_ERROR_REF smlAssert(parser); @@ -193,20 +210,20 @@ int rc = 0; if (*string) { - smlErrorSet(error, SML_ERROR_GENERIC, "string already set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "string already set"); return FALSE; } xmlBuffer *buffer = xmlBufferCreateSize(BUFFER_SIZE); if (!buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new buffer"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to create new buffer"); goto error; } xmlTextWriter *writer = xmlNewTextWriterMemory(buffer, 0); if (!writer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new writer"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to create new writer"); goto error_free_buffer; } @@ -216,7 +233,8 @@ while (1) { if (!_smlXmlParserStepData(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "There is a missing node during the data parsing of %s.", name); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "There is a missing node during the data parsing of %s.", name); goto error_free_writer; } @@ -229,7 +247,8 @@ rc = xmlTextWriterEndElement(writer); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to end node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to end node"); goto error_free_writer; } break; @@ -240,7 +259,7 @@ rc = xmlTextWriterWriteElementNS(writer, NULL, xmlTextReaderConstName(parser->reader), NULL, (const xmlChar*)""); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to start node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to start node"); goto error_free_writer; } break; @@ -248,19 +267,19 @@ case XML_NODE_TEXT: rc = xmlTextWriterWriteRaw(writer, xmlTextReaderConstValue(parser->reader)); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add string"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to add string"); goto error_free_writer; } break; case XML_READER_TYPE_SIGNIFICANT_WHITESPACE: rc = xmlTextWriterWriteRaw(writer, xmlTextReaderConstValue(parser->reader)); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add string"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to add string"); goto error_free_writer; } break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown node type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown node type"); goto error_free_writer; } } @@ -292,7 +311,10 @@ return FALSE; } -static SmlBool _smlSyncHeaderParseDTD(SmlProtocolVersion *version, SmlXmlParser *parser, SmlError **error) +static gboolean +_smlSyncHeaderParseDTD (SmlProtocolVersion *version, + SmlXmlParser *parser, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, version, parser, error); CHECK_ERROR_REF @@ -300,8 +322,8 @@ smlAssert(version); if (*version) { - smlErrorSet(error, SML_ERROR_GENERIC, "dtd already set"); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "dtd already set"); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } @@ -317,21 +339,23 @@ *version = SML_VERSION_12; else { smlSafeCFree(&dtd); - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown VerDTD"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown VerDTD"); goto error; } smlSafeCFree(&dtd); smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: *version = SML_VERSION_UNKNOWN; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlSyncHeaderParseProto(SmlProtocolType *type, SmlXmlParser *parser, SmlError **error) +static gboolean +_smlSyncHeaderParseProto (SmlProtocolType *type, + SmlXmlParser *parser, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, type, parser, error); CHECK_ERROR_REF @@ -339,8 +363,8 @@ smlAssert(type); if (*type) { - smlErrorSet(error, SML_ERROR_GENERIC, "protocol already set"); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "protocol already set"); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } @@ -352,44 +376,45 @@ *type = SML_PROTOCOL_SYNCML; else { smlSafeCFree(&proto); - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown VerProto"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown VerProto"); goto error; } smlSafeCFree(&proto); smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: *type = SML_PROTOCOL_UNKNOWN; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlLocationParse(SmlLocation **location, SmlXmlParser *parser, SmlError **error) +static gboolean +_smlLocationParse (SmlLocation **location, + SmlXmlParser *parser, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, location, parser, error); CHECK_ERROR_REF smlAssert(parser); smlAssert(location); - GError *gerror = NULL; if (*location) { - smlErrorSet(error, SML_ERROR_GENERIC, "Location already set"); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Location already set"); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } *location = sml_location_new(); if (!location) { - smlErrorSet(error, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); goto error; } while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -406,7 +431,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in locations (Target, Source, SourceParent or TargetParent).", xmlTextReaderConstName(parser->reader)); goto error; @@ -416,7 +441,7 @@ gchar *uri = NULL; if (!_smlXmlParserGetString(parser, &uri, SML_ELEMENT_LOCURI, error)) goto error; - if (!sml_location_set_uri(*location, uri, &gerror)) { + if (!sml_location_set_uri(*location, uri, error)) { g_free(uri); goto error; } @@ -425,35 +450,36 @@ gchar *name = NULL; if (!_smlXmlParserGetString(parser, &name, SML_ELEMENT_LOCNAME, error)) goto error; - if (!sml_location_set_name(*location, name, &gerror)) { + if (!sml_location_set_name(*location, name, error)) { g_free(name); goto error; } g_free(name); } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node. expected SyncHdr"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node. expected SyncHdr"); goto error; } } if (!sml_location_get_uri(*location)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No locURI set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No locURI set"); goto error; } smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: if (*location) g_object_unref(*location); *location = NULL; - GERROR_TO_SML_ERROR(gerror,error) - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlAnchorParse(SmlAnchor **anchor, SmlXmlParser *parser, SmlError **error) +static gboolean +_smlAnchorParse (SmlAnchor **anchor, + SmlXmlParser *parser, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, anchor, parser, error); CHECK_ERROR_REF @@ -461,8 +487,8 @@ smlAssert(anchor); if (*anchor) { - smlErrorSet(error, SML_ERROR_GENERIC, "anchor already set"); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "anchor already set"); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } @@ -472,7 +498,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_anchor; } @@ -480,7 +506,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Anchor.", xmlTextReaderConstName(parser->reader)); goto error_free_anchor; @@ -493,13 +519,13 @@ if (!_smlXmlParserGetString(parser, &((*anchor)->last), SML_ELEMENT_LAST, error)) goto error_free_anchor; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node"); goto error_free_anchor; } } if (!(*anchor)->next) { - smlErrorSet(error, SML_ERROR_GENERIC, "No next set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No next set"); goto error_free_anchor; } @@ -510,11 +536,16 @@ smlAnchorFree(*anchor); error: *anchor = NULL; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlChalMetaParse(SmlXmlParser *parser, char **format, char **type, char **nonce, SmlError **error) +static gboolean +_smlChalMetaParse (SmlXmlParser *parser, + gchar **format, + gchar **type, + gchar **nonce, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p, %p, %p)", __func__, parser, format, type, nonce, error); CHECK_ERROR_REF @@ -522,7 +553,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -530,7 +561,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Chal/Meta.", xmlTextReaderConstName(parser->reader)); goto error; @@ -546,7 +577,7 @@ if (!_smlXmlParserGetString(parser, nonce, SML_ELEMENT_NEXTNONCE, error)) goto error; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node: %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node: %s", xmlTextReaderConstName(parser->reader)); goto error; } } @@ -562,18 +593,25 @@ if (type) *type = NULL; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlCommandMetaParse(SmlXmlParser *parser, char **format, char **type, SmlAnchor **anchor, unsigned int *size, int *maxobjsize, SmlError **error) +static gboolean +_smlCommandMetaParse (SmlXmlParser *parser, + gchar **format, + gchar **type, + SmlAnchor **anchor, + gsize *size, + gsize *maxobjsize, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p, %p, %p)", __func__, parser, format, type, anchor, size, maxobjsize, error); CHECK_ERROR_REF smlAssert(parser); if (maxobjsize) - *maxobjsize = -1; + *maxobjsize = 0; if (xmlTextReaderIsEmptyElement(parser->reader)) { @@ -584,7 +622,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -592,7 +630,7 @@ /* Ignored for now */ smlTrace(TRACE_INTERNAL, "%s: Skipping mem node"); if (!_smlXmlSkipNode(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to skip mem node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to skip mem node"); goto error; } } @@ -601,7 +639,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Command/Meta.", xmlTextReaderConstName(parser->reader)); goto error; @@ -623,15 +661,17 @@ goto error; smlSafeCFree(&mark); } else if (size && !strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SIZE)) { - if (!_smlXmlParserGetID(parser, size, SML_ELEMENT_SIZE, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_SIZE, error)) goto error; + *size = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MAXOBJSIZE)) { /* MaxObjSize must be parsed even if there is no maxobjsize pointer */ - unsigned int loc_maxobjsize = 0; - if (!_smlXmlParserGetID(parser, &loc_maxobjsize, SML_ELEMENT_MAXOBJSIZE, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_MAXOBJSIZE, error)) goto error; if (maxobjsize) - *maxobjsize = loc_maxobjsize; + *maxobjsize = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_VERSION)) { /* Ignore the version for now */ char *version = NULL; @@ -639,7 +679,7 @@ goto error; smlSafeCFree(&version); } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node for meta information: %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node for meta information: %s", xmlTextReaderConstName(parser->reader)); goto error; } } @@ -654,21 +694,24 @@ *anchor = NULL; if (type) *type = NULL; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlItem *_smlItemParse(SmlXmlParser *parser, SmlCommand *cmd, SmlCommandType type, SmlError **error) +static SmlItem* +_smlItemParse (SmlXmlParser *parser, + SmlCommand *cmd, + SmlCommandType type, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, parser, cmd, type, error); CHECK_ERROR_REF smlAssert(parser); - GError *gerror = NULL; SmlItem *item = NULL; if (parser->gotMoreData) { - smlErrorSet(error, SML_ERROR_GENERIC, "Last item already had more data set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Last item already had more data set"); goto error; } @@ -684,7 +727,7 @@ } if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "The first element inside of an Item structure cannot be parsed."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The first element inside of an Item structure cannot be parsed."); goto error; } @@ -693,7 +736,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Item.", xmlTextReaderConstName(parser->reader)); goto error; @@ -706,7 +749,7 @@ if (smlItemGetSource(item)) { /* SourceParent already parsed */ - if (!sml_location_set_parent_uri(source, sml_location_get_parent_uri(smlItemGetSource(item)), &gerror)) + if (!sml_location_set_parent_uri(source, sml_location_get_parent_uri(smlItemGetSource(item)), error)) goto error; } @@ -719,7 +762,7 @@ if (smlItemGetTarget(item)) { /* TargetParent already parsed */ - if (!sml_location_set_parent_uri(target, sml_location_get_parent_uri(smlItemGetTarget(item)), &gerror)) + if (!sml_location_set_parent_uri(target, sml_location_get_parent_uri(smlItemGetTarget(item)), error)) goto error; } @@ -732,16 +775,16 @@ if (smlItemGetSource(item)) { /* Source already parsed */ - if (!sml_location_set_parent_uri(smlItemGetSource(item), sml_location_get_uri(source), &gerror)) + if (!sml_location_set_parent_uri(smlItemGetSource(item), sml_location_get_uri(source), error)) goto error; } else { /* there is no source object until now */ smlItemSetSource(item, source); /* copy uri to parent_uri property */ - if (!sml_location_set_parent_uri(source, sml_location_get_uri(source), &gerror)) + if (!sml_location_set_parent_uri(source, sml_location_get_uri(source), error)) goto error; /* delete uri property */ - if (!sml_location_set_uri(source, NULL, &gerror)) + if (!sml_location_set_uri(source, NULL, error)) goto error; } @@ -753,16 +796,16 @@ if (smlItemGetTarget(item)) { /* Target already parsed */ - if (!sml_location_set_parent_uri(smlItemGetTarget(item), sml_location_get_uri(target), &gerror)) + if (!sml_location_set_parent_uri(smlItemGetTarget(item), sml_location_get_uri(target), error)) goto error; } else { /* there is no target object until now */ smlItemSetTarget(item, target); /* copy uri to parent_uri property */ - if (!sml_location_set_parent_uri(target, sml_location_get_uri(target), &gerror)) + if (!sml_location_set_parent_uri(target, sml_location_get_uri(target), error)) goto error; /* delete uri property */ - if (!sml_location_set_uri(target, NULL, &gerror)) + if (!sml_location_set_uri(target, NULL, error)) goto error; } @@ -801,7 +844,7 @@ goto error; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown command type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown command type"); goto error; } } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { @@ -814,7 +857,7 @@ switch (type) { case SML_COMMAND_TYPE_ALERT: if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "The next element after the starting Data element in an Item is missing."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The next element after the starting Data element in an Item is missing."); goto error; } @@ -846,7 +889,7 @@ item->anchor = anchor; if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "The closing Data element in an Item is missing."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The closing Data element in an Item is missing."); goto error; } break; @@ -866,32 +909,32 @@ } } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MOREDATA)) { if (parser->version == SML_VERSION_10) { - smlErrorSet(error, SML_ERROR_GENERIC, "SyncML 1.0 does not allow MoreData"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "SyncML 1.0 does not allow MoreData"); goto error; } item->moreData = TRUE; parser->gotMoreData = TRUE; if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes2"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes2"); goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MOREDATA) && \ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes3"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes3"); goto error; } } continue; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "The element Item does not support the child element %s.", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element Item does not support the child element %s.", xmlTextReaderConstName(parser->reader)); goto error; } if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "The next element in an Item structure is missing."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The next element in an Item structure is missing."); goto error; } } @@ -902,12 +945,13 @@ error: if (item) smlItemUnref(item); - GERROR_TO_SML_ERROR(gerror,error) - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -static SmlCred *_smlCredParse(SmlXmlParser *parser, SmlError **error) +static SmlCred* +_smlCredParse (SmlXmlParser *parser, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); CHECK_ERROR_REF @@ -919,7 +963,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -927,7 +971,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Cred.", xmlTextReaderConstName(parser->reader)); goto error; @@ -940,7 +984,7 @@ if (!_smlXmlParserGetString(parser, &data, SML_ELEMENT_DATA, error)) goto error; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); goto error; } } @@ -957,19 +1001,21 @@ if (type) smlSafeCFree(&type); - if (!smlErrorIsSet(error)) + if (!(*error)) { smlTrace(TRACE_EXIT, "%s: %p", __func__, cred); return cred; } else { if (cred) smlCredUnref(cred); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } } -static SmlChal *_smlChalParse(SmlXmlParser *parser, SmlError **error) +static SmlChal* +_smlChalParse (SmlXmlParser *parser, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); CHECK_ERROR_REF @@ -980,7 +1026,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -988,7 +1034,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Chal.", xmlTextReaderConstName(parser->reader)); goto error; @@ -998,13 +1044,13 @@ if (!_smlChalMetaParse(parser, &format, &type, &nonce, error)) goto error; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); goto error; } } if (format && strcmp(format, SML_BASE64)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown format"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown format"); goto error; } @@ -1014,7 +1060,7 @@ } else if (!strcmp(type, SML_AUTH_MD5)) { auth = SML_AUTH_TYPE_MD5; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown type"); goto error; } @@ -1036,7 +1082,6 @@ smlTrace(TRACE_EXIT, "%s: %p", __func__, chal); return chal; - error: if (format) smlSafeCFree(&format); @@ -1044,17 +1089,21 @@ smlSafeCFree(&type); if (nonce) smlSafeCFree(&nonce); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -static SmlBool _smlChangeParse(SmlXmlParser *parser, SmlCommand **cmd, SmlCommandType type, const char *name, SmlError **error) +static gboolean +_smlChangeParse (SmlXmlParser *parser, + SmlCommand **cmd, + SmlCommandType type, + const gchar *name, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %i, %s, %p)", __func__, parser, type, VA_STRING(name), error); CHECK_ERROR_REF smlAssert(parser); smlAssert(name); - GError *gerror = NULL; char *contenttype = NULL; *cmd = smlCommandNew(type, error); @@ -1064,7 +1113,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -1072,15 +1121,17 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in %s.", xmlTextReaderConstName(parser->reader), name); goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_CMDID, error)) goto error; + (*cmd)->cmdID = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { SmlItem *item = _smlItemParse(parser, *cmd, type, error); if (!item) @@ -1089,26 +1140,26 @@ if (!(*cmd)->private.change.items) { smlItemUnref(item); - smlErrorSet(error, SML_ERROR_GENERIC, "g_list_append for item list of change command failed."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "g_list_append for item list of change command failed."); goto error; } } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { if (!_smlCommandMetaParse(parser, NULL, &contenttype, NULL, &(*cmd)->size, NULL, error)) goto error; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node"); goto error; } } if (!(*cmd)->cmdID) { - smlErrorSet(error, SML_ERROR_GENERIC, "No cmdid set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No cmdid set"); goto error; } if (!(*cmd)->private.change.items || !g_list_length((*cmd)->private.change.items)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No items set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No items set"); goto error; } @@ -1142,7 +1193,7 @@ (*cmd)->private.change.type = SML_CHANGE_DELETE; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown change type set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown change type set"); goto error; } @@ -1150,7 +1201,7 @@ { SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); if (item->source) { - (*cmd)->source = sml_location_clone(item->source, &gerror); + (*cmd)->source = sml_location_clone(item->source, error); if (!(*cmd)->source) goto error; } @@ -1160,7 +1211,7 @@ { SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); if (item->target) { - (*cmd)->target = sml_location_clone(item->target, &gerror); + (*cmd)->target = sml_location_clone(item->target, error); if (!(*cmd)->target) goto error; } @@ -1168,25 +1219,28 @@ /* Step once more */ if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } smlTrace(TRACE_EXIT, "%s: %p", __func__, *cmd); return TRUE; - error: if (*cmd) smlCommandUnref(*cmd); *cmd = NULL; if (contenttype) smlSafeCFree(&contenttype); - GERROR_TO_SML_ERROR(gerror,error) - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlMessageParseSynchdrMeta(SmlXmlParser *parser, unsigned int *maxmsgsize, unsigned int *maxobjsize, char **emi, SmlError **error) +static gboolean +_smlMessageParseSynchdrMeta (SmlXmlParser *parser, + gsize *maxmsgsize, + gsize *maxobjsize, + gchar **emi, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, parser, maxmsgsize, maxobjsize, error); CHECK_ERROR_REF @@ -1195,10 +1249,9 @@ smlAssert(maxobjsize); smlAssert(emi); - while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -1206,49 +1259,55 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in SyncHdr/Meta.", xmlTextReaderConstName(parser->reader)); goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MAXMSGSIZE)) { - if (!_smlXmlParserGetID(parser, maxmsgsize, SML_ELEMENT_MAXMSGSIZE, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_MAXMSGSIZE, error)) goto error; + *maxmsgsize = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MAXOBJSIZE)) { - if (!_smlXmlParserGetID(parser, maxobjsize, SML_ELEMENT_MAXOBJSIZE, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_MAXOBJSIZE, error)) goto error; + *maxobjsize = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_EMI)) { if (!_smlXmlParserGetString(parser, emi, SML_ELEMENT_EMI, error)) goto error; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node. expected MaxMsgSize, MaxObjSize or EMI. Instead of that: %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node. expected MaxMsgSize, MaxObjSize or EMI. Instead of that: %s", xmlTextReaderConstName(parser->reader)); goto error; } } if (!(*maxmsgsize) && !(*maxobjsize)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No maxmsgsize set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No maxmsgsize set"); goto error; } smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: *maxmsgsize = 0; *maxobjsize = 0; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlAlertParse(SmlXmlParser *parser, SmlCommand **cmd, SmlError **error) +static gboolean +_smlAlertParse (SmlXmlParser *parser, + SmlCommand **cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, cmd, error); CHECK_ERROR_REF smlAssert(parser); smlAssert(cmd); - + *cmd = smlCommandNew(SML_COMMAND_TYPE_ALERT, error); if (!*cmd) goto error; @@ -1257,7 +1316,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_cmd; } @@ -1265,15 +1324,17 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Alert.", xmlTextReaderConstName(parser->reader)); goto error_free_cmd; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_CMDID, error)) goto error_free_cmd; + (*cmd)->cmdID = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { SmlItem *item = _smlItemParse(parser, (*cmd), SML_COMMAND_TYPE_ALERT, error); if (!item) @@ -1286,7 +1347,7 @@ smlItemUnref(item); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { - unsigned int id = 0; + guint64 id = 0; if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_DATA, error)) goto error_free_cmd; (*cmd)->private.alert.type = smlAlertTypeConvert(id, error); @@ -1294,19 +1355,19 @@ *error != NULL) goto error_free_cmd; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); goto error_free_cmd; } } if (!(*cmd)->private.alert.type) { - smlErrorSet(error, SML_ERROR_GENERIC, "No alert type set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No alert type set"); goto error_free_cmd; } /* Step once more */ if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_cmd; } @@ -1317,11 +1378,14 @@ smlCommandUnref(*cmd); error: *cmd = NULL; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlParserResult _smlCommandSyncParse(SmlXmlParser *parser, SmlCommand **cmd, SmlError **error) +static SmlParserResult +_smlCommandSyncParse (SmlXmlParser *parser, + SmlCommand **cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, cmd, error); CHECK_ERROR_REF @@ -1335,14 +1399,14 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_cmd; } if (xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE && !strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SYNC)) break; else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Sync.", xmlTextReaderConstName(parser->reader)); goto error_free_cmd; @@ -1354,8 +1418,10 @@ break; if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_CMDID, error)) goto error_free_cmd; + (*cmd)->cmdID = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { SmlItem *item = _smlItemParse(parser, (*cmd), SML_COMMAND_TYPE_SYNC, error); if (!item) @@ -1370,11 +1436,13 @@ if (!_smlLocationParse(&(*cmd)->source, parser, error)) goto error_free_cmd; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_NUMBEROFCHANGES)) { + guint64 id = 0; (*cmd)->private.sync.hasNumChanged = TRUE; - if (!_smlXmlParserGetID(parser, &((*cmd)->private.sync.numChanged), SML_ELEMENT_NUMBEROFCHANGES, error)) + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_NUMBEROFCHANGES, error)) goto error_free_cmd; + (*cmd)->private.sync.numChanged = id; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node: %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node: %s", xmlTextReaderConstName(parser->reader)); goto error_free_cmd; } } @@ -1386,11 +1454,13 @@ smlCommandUnref(*cmd); error: *cmd = NULL; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlMapItem *_smlMapItemParse(SmlXmlParser *parser, SmlError **error) +static SmlMapItem* +_smlMapItemParse (SmlXmlParser *parser, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); CHECK_ERROR_REF @@ -1403,7 +1473,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_item; } @@ -1411,7 +1481,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in MapItem.", xmlTextReaderConstName(parser->reader)); goto error_free_item; @@ -1424,7 +1494,7 @@ if (!_smlLocationParse(&item->target, parser, error)) goto error_free_item; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); goto error_free_item; } } @@ -1435,11 +1505,14 @@ error_free_item: smlMapItemUnref(item); error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -static SmlBool _smlCommandMapParse(SmlXmlParser *parser, SmlCommand **cmd, SmlError **error) +static gboolean +_smlCommandMapParse (SmlXmlParser *parser, + SmlCommand **cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, cmd, error); CHECK_ERROR_REF @@ -1453,7 +1526,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_cmd; } @@ -1461,15 +1534,17 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Map.", xmlTextReaderConstName(parser->reader)); goto error_free_cmd; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_CMDID, error)) goto error_free_cmd; + (*cmd)->cmdID = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MAPITEM)) { SmlMapItem *item = _smlMapItemParse(parser, error); if (!item) @@ -1482,14 +1557,14 @@ if (!_smlLocationParse(&(*cmd)->source, parser, error)) goto error_free_cmd; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node"); goto error_free_cmd; } } /* Step once more */ if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_cmd; } @@ -1500,11 +1575,15 @@ smlCommandUnref(*cmd); error: *cmd = NULL; - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlCommandAccessParse(SmlXmlParser *parser, SmlCommand **cmd, SmlCommandType type, SmlError **error) +static gboolean +_smlCommandAccessParse (SmlXmlParser *parser, + SmlCommand **cmd, + SmlCommandType type, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, parser, cmd, type, error); CHECK_ERROR_REF @@ -1519,7 +1598,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_cmd; } @@ -1530,15 +1609,17 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Put or Get.", xmlTextReaderConstName(parser->reader)); goto error_free_cmd; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_CMDID, error)) goto error_free_cmd; + (*cmd)->cmdID = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { (*cmd)->private.access.item = _smlItemParse(parser, (*cmd), (*cmd)->type, error); if (!(*cmd)->private.access.item) @@ -1554,13 +1635,13 @@ goto error_free_cmd; if (format) smlSafeCFree(&format); } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node"); goto error_free_cmd; } } if (!(*cmd)->private.access.item) { - smlErrorSet(error, SML_ERROR_GENERIC, "Put/Get is missing item"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Put/Get is missing item"); goto error_free_cmd; } @@ -1574,7 +1655,7 @@ /* Step once more */ if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error_free_cmd; } @@ -1587,17 +1668,19 @@ *cmd = NULL; if (contenttype) smlSafeCFree(&contenttype); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlResultsParse(SmlXmlParser *parser, SmlCommand **cmd, SmlError **error) +static gboolean +_smlResultsParse (SmlXmlParser *parser, + SmlCommand **cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, cmd, error); CHECK_ERROR_REF smlAssert(parser); smlAssert(cmd); - GError *gerror = NULL; char *contenttype = NULL; char *locURI = NULL; @@ -1615,7 +1698,7 @@ while (1) { if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -1623,7 +1706,7 @@ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The element %s is not a start node in Results.", xmlTextReaderConstName(parser->reader)); goto error; @@ -1631,19 +1714,25 @@ if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDID)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->cmdID), SML_ELEMENT_CMDID, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_CMDID, error)) goto error; + (*cmd)->cmdID = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MSGREF)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->private.results.status->msgRef), SML_ELEMENT_MSGREF, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_MSGREF, error)) goto error; + (*cmd)->private.results.status->msgRef = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_CMDREF)) { - if (!_smlXmlParserGetID(parser, &((*cmd)->private.results.status->cmdRef), SML_ELEMENT_CMDREF, error)) + guint64 id = 0; + if (!_smlXmlParserGetID(parser, &id, SML_ELEMENT_CMDREF, error)) goto error; + (*cmd)->private.results.status->cmdRef = id; } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCEREF)) { if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_SOURCEREF, error)) goto error; - (*cmd)->private.results.status->sourceRef = sml_location_new_with_options(locURI, NULL, &gerror); + (*cmd)->private.results.status->sourceRef = sml_location_new_with_options(locURI, NULL, error); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->sourceRef) goto error; @@ -1651,7 +1740,7 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_TARGETREF, error)) goto error; - (*cmd)->private.results.status->targetRef = sml_location_new_with_options(locURI, NULL, &gerror); + (*cmd)->private.results.status->targetRef = sml_location_new_with_options(locURI, NULL, error); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->targetRef) goto error; @@ -1671,13 +1760,13 @@ goto error; if (format) smlSafeCFree(&format); } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node"); goto error; } } if (!(*cmd)->private.results.status->item) { - smlErrorSet(error, SML_ERROR_GENERIC, "Result is missing item"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Result is missing item"); goto error; } @@ -1685,7 +1774,7 @@ * a content type set */ if (!(*cmd)->private.results.status->item->contenttype) { if (!contenttype) { - smlErrorSet(error, SML_ERROR_GENERIC, "Result is missing content type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Result is missing content type"); goto error; } @@ -1697,7 +1786,7 @@ /* Step once more */ if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); goto error; } @@ -1710,15 +1799,16 @@ *cmd = NULL; if (contenttype) smlSafeCFree(&contenttype); - GERROR_TO_SML_ERROR(gerror,error) - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlXmlParserFixBrokenItemData( - const char *data, unsigned int size, - char **fixed_data, unsigned int *fixed_size, - SmlError **error) +static gboolean +_smlXmlParserFixBrokenItemData (const gchar *data, + gsize size, + gchar **fixed_data, + gsize *fixed_size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %d, %p, %p, %p)", __func__, data, size, fixed_data, fixed_size, error); CHECK_ERROR_REF @@ -1742,7 +1832,7 @@ *fixed_data = smlTryMalloc0(size + 1, error); if (!*fixed_data) { - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } memcpy(*fixed_data, data, size); @@ -1774,22 +1864,22 @@ /* convert the whole strong to UTF-8 */ smlTrace(TRACE_INTERNAL, "%s: Converting %d bytes ...", __func__, last_utf16 - position + 1); - GError *gerror = NULL; size_t read_bytes = 0; size_t written_bytes = 0; gchar *conv_string = g_convert( position, (last_utf16 - position + 1), "UTF-8", "UTF-16", &read_bytes, &written_bytes, - &gerror); - if (gerror != NULL) + error); + if (error != NULL) { - smlErrorSet( - error, SML_ERROR_GENERIC, - "Character conversion from UTF-16 to UTF-8 failed. %s", - gerror->message); - g_error_free(gerror); - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + GError *ext = NULL; + g_set_error(&ext, SML_ERROR, SML_ERROR_GENERIC, + "Character conversion from UTF-16 to UTF-8 failed. %s", + (*error)->message); + g_error_free(*error); + *error = ext; + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } smlTrace(TRACE_INTERNAL, "%s: read %d --> written %d --> %d ::= %s", __func__, read_bytes, written_bytes, strlen(conv_string), conv_string); @@ -1798,7 +1888,7 @@ char *new_data = smlTryMalloc0(*fixed_size - read_bytes + written_bytes + 1, error); if (!new_data) { - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } memcpy(new_data, *fixed_data, (size_t) position - (size_t) *fixed_data); @@ -1935,7 +2025,7 @@ char *new_data = smlTryMalloc0(*fixed_size + strlen("<![CDATA[]]>") + 1, error); if (!new_data) { - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } size_t before_size = limit_data_start + strlen("<Data>") - *fixed_data; @@ -1970,7 +2060,9 @@ return TRUE; } -SmlDevInfDevTyp _smlParseDevInfDevType(const char *name, SmlError **error) +SmlDevInfDevTyp +_smlParseDevInfDevType (const gchar *name, + GError **error) { CHECK_ERROR_REF @@ -1989,12 +2081,15 @@ } else if (!strcmp(name, SML_ELEMENT_DEVTYP_WORKSTATION)) { return SML_DEVINF_DEVTYP_WORKSTATION; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "The device information DevTyp \"%s\" is unknown.", name); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "The device information DevTyp \"%s\" is unknown.", name); return SML_DEVINF_DEVTYP_UNKNOWN; } } -SmlDevInfSyncCap _smlParseDevInfSyncCap(unsigned int id, SmlError **error) +SmlDevInfSyncCap +_smlParseDevInfSyncCap (guint id, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%u, %p)", __func__, id, error); CHECK_ERROR_REF @@ -2024,9 +2119,9 @@ result = SML_DEVINF_SYNCTYPE_SERVER_ALERTED_SYNC; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, - "The synchronization type %u is unknwon.", id); - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "The synchronization type %u is unknwon.", id); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return SML_DEVINF_SYNCTYPE_UNKNOWN; break; } @@ -2034,7 +2129,9 @@ return result; } -SmlDevInfCTCapType _smlParseDevInfCTCapType(const char *name, SmlError **error) +SmlDevInfCTCapType +_smlParseDevInfCTCapType (const gchar *name, + GError **error) { CHECK_ERROR_REF @@ -2066,8 +2163,9 @@ return SML_DEVINF_CTCAP_MAXSIZE; } - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown ctcap type name \"%s\"", name); - smlTrace(TRACE_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unknown ctcap type name \"%s\"", name); + smlTrace(TRACE_ERROR, "%s - %s", __func__, (*error)->message); return SML_DEVINF_CTCAP_UNKNOWN; } @@ -2077,7 +2175,11 @@ * This will set everything up and parse until the SyncHdr * */ -SmlBool smlXmlParserStart(SmlXmlParser *parser, const char *data, unsigned int size, SmlError **error) +gboolean +smlXmlParserStart (SmlXmlParser *parser, + const gchar *data, + gsize size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, parser, data, size, error); CHECK_ERROR_REF @@ -2097,7 +2199,7 @@ if (! _smlXmlParserFixBrokenItemData( data, size, &(parser->data), &(parser->size), error)) { - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } @@ -2111,7 +2213,8 @@ /* Create the new parser */ parser->reader = xmlReaderForMemory(parser->data, parser->size, "/", NULL, XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOCDATA); if (!parser->reader) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new reader"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to create new reader"); goto error; } xmlSubstituteEntitiesDefault(1); @@ -2133,29 +2236,33 @@ parser->reader = NULL; if (parser->data) smlSafeCFree(&(parser->data)); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlParserEnd(SmlXmlParser *parser, SmlBool *final, SmlBool *end, SmlError **error) +gboolean +smlXmlParserEnd (SmlXmlParser *parser, + gboolean *final, + gboolean *end, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, parser, final, end, error); CHECK... [truncated message content] |