From: <svn...@op...> - 2009-07-08 15:16:56
|
Author: bellmich Date: Wed Jul 8 17:16:46 2009 New Revision: 1159 URL: http://libsyncml.opensync.org/changeset/1159 Log: migrated parser/sml_xml_assm from SmlError to GError Modified: trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_assm_internals.h Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Wed Jul 8 16:18:21 2009 (r1158) +++ trunk/libsyncml/parser/sml_xml_assm.c Wed Jul 8 17:16:46 2009 (r1159) @@ -40,7 +40,11 @@ */ /*@{*/ -static SmlBool _smlXmlAssemblerStartNodeNS(SmlXmlAssembler *assm, const char *name, const char *uri, SmlError **error) +static gboolean +_smlXmlAssemblerStartNodeNS (SmlXmlAssembler *assm, + const gchar *name, + const gchar *uri, + GError **error) { CHECK_ERROR_REF smlAssert(assm); @@ -50,53 +54,78 @@ smlTrace(TRACE_INTERNAL, "%s: Starting \"%s\"", __func__, VA_STRING(name)); int rc = xmlTextWriterStartElementNS(assm->writer, NULL, (xmlChar *)name, (xmlChar *)uri); 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"); return FALSE; } return TRUE; } -static SmlBool _smlXmlAssemblerStartNode(SmlXmlAssembler *assm, const char *name, SmlError **error) +static gboolean +_smlXmlAssemblerStartNode (SmlXmlAssembler *assm, + const gchar *name, + GError **error) { CHECK_ERROR_REF return _smlXmlAssemblerStartNodeNS(assm, name, NULL, error); } -static SmlBool _smlXmlAssemblerEndNode(SmlXmlAssembler *assm, SmlError **error) +static gboolean +_smlXmlAssemblerEndNode (SmlXmlAssembler *assm, + GError **error) { CHECK_ERROR_REF smlTrace(TRACE_INTERNAL, "%s: Ending node", __func__); int rc = xmlTextWriterEndElement(assm->writer); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to end node (%d).", rc); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to end node (%d).", rc); return FALSE; } return TRUE; } -static SmlBool _smlXmlAssemblerAddStringNS(SmlXmlAssembler *assm, const char *name, const char *uri, const char *value, SmlError **error) +static gboolean +_smlXmlAssemblerAddStringNS (SmlXmlAssembler *assm, + const gchar *name, + const gchar *uri, + const gchar *value, + GError **error) { CHECK_ERROR_REF int rc = xmlTextWriterWriteElementNS(assm->writer, NULL, (xmlChar *)name, (xmlChar *)uri, (xmlChar *)value); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add string (%d - %s:%s -> %s).", rc, VA_STRING(uri), VA_STRING(name), VA_STRING(value)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to add string (%d - %s:%s -> %s).", + rc, VA_STRING(uri), VA_STRING(name), VA_STRING(value)); return FALSE; } return TRUE; } -static SmlBool _smlXmlAssemblerAddString(SmlXmlAssembler *assm, const char *name, const char *value, SmlError **error) +static gboolean +_smlXmlAssemblerAddString (SmlXmlAssembler *assm, + const gchar *name, + const gchar *value, + GError **error) { CHECK_ERROR_REF int rc = xmlTextWriterWriteElement(assm->writer, (xmlChar *)name, (xmlChar *)value); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add pure string (%d - %s -> %s).", rc, VA_STRING(name), VA_STRING(value)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to add pure string (%d - %s -> %s).", + rc, VA_STRING(name), VA_STRING(value)); return FALSE; } return TRUE; } -static SmlBool _smlXmlAssemblerAddData(SmlXmlAssembler *assm, const char *name, const char *value, unsigned int size, SmlBool raw, SmlError **error) +static gboolean +_smlXmlAssemblerAddData (SmlXmlAssembler *assm, + const gchar *name, + const gchar *value, + gsize size, + gboolean raw, + GError **error) { CHECK_ERROR_REF int rc = 0; @@ -109,7 +138,8 @@ rc = xmlTextWriterWriteFormatCDATA(assm->writer, "%*s", size, (xmlChar *)value); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add data (%d).", rc); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to add data (%d).", rc); return FALSE; } @@ -119,35 +149,47 @@ return TRUE; } -static SmlBool _smlXmlAssemblerAddID(SmlXmlAssembler *assm, const char *name, unsigned int id, SmlError **error) +static gboolean +_smlXmlAssemblerAddID (SmlXmlAssembler *assm, + const gchar *name, + gsize id, + GError **error) { CHECK_ERROR_REF int rc = xmlTextWriterWriteFormatElement(assm->writer, (xmlChar *)name, "%i", id); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add id"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to add id"); return FALSE; } return TRUE; } -static SmlBool _smlXmlAssemblerAddIDNS(SmlXmlAssembler *assm, const char *name, const char *uri, unsigned int id, SmlError **error) +static gboolean +_smlXmlAssemblerAddIDNS (SmlXmlAssembler *assm, + const gchar *name, + const gchar *uri, + gsize id, + GError **error) { CHECK_ERROR_REF int rc = xmlTextWriterWriteFormatElementNS(assm->writer, NULL, (xmlChar *)name, (xmlChar *)uri, "%i", id); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add id"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to add id"); return FALSE; } return TRUE; } -static SmlBool _smlAssembleUseMaxObjSize(SmlXmlAssembler *assm) +static gboolean +_smlAssembleUseMaxObjSize (SmlXmlAssembler *assm) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm); /* check the configuration */ const char *opt = smlAssemblerGetOption(assm->assembler, "USE_LARGEOBJECTS"); - SmlBool supportsLargeObjects = (opt && !atoi(opt)) ? FALSE : TRUE; + gboolean supportsLargeObjects = (opt && !atoi(opt)) ? FALSE : TRUE; /* server should react only the client behavior */ if (assm->session->sessionType == SML_SESSION_TYPE_SERVER) @@ -172,7 +214,9 @@ return supportsLargeObjects; } -static SmlBool _smlAssembleMaxObjSize(SmlXmlAssembler *assm, SmlError **error) +static gboolean +_smlAssembleMaxObjSize (SmlXmlAssembler *assm, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm); CHECK_ERROR_REF @@ -200,13 +244,14 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static const char *_smlAssembleDevInfDevType(SmlDevInfDevTyp type, SmlError **error) +static const gchar* +_smlAssembleDevInfDevType (SmlDevInfDevTyp type, + GError **error) { CHECK_ERROR_REF @@ -226,14 +271,20 @@ case SML_DEVINF_DEVTYP_WORKSTATION: return SML_ELEMENT_DEVTYP_WORKSTATION; default: - smlErrorSet(error, SML_ERROR_GENERIC, "The devince information DevTyp \"%i\" is unknown.", type); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "The devince information DevTyp \"%i\" is unknown.", + type); /* fall through! */ } return NULL; } -SmlBool smlLocationAssemble(SmlLocation *location, SmlXmlAssembler *assm, const char *name, SmlError **error) +gboolean +smlLocationAssemble (SmlLocation *location, + SmlXmlAssembler *assm, + const gchar *name, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %s, %p)", __func__, location, assm, VA_STRING(name), error); CHECK_ERROR_REF @@ -249,7 +300,8 @@ (strcmp(SML_ELEMENT_SOURCE_PARENT, name) == 0 || strcmp(SML_ELEMENT_TARGET_PARENT, name) == 0)) { if (!sml_location_get_parent_uri(location)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No parent URI set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "No parent URI set"); goto error; } @@ -258,7 +310,8 @@ } else { if (!sml_location_get_uri(location)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No location URI set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "No location URI set"); goto error; } @@ -278,15 +331,17 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlAnchorAssemble(SmlAnchor *anchor, SmlXmlAssembler *assm, SmlError **error) +gboolean +smlAnchorAssemble (SmlAnchor *anchor, + SmlXmlAssembler *assm, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, anchor, assm, error); CHECK_ERROR_REF @@ -305,7 +360,7 @@ goto error; 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; } @@ -326,13 +381,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlItemAssemble(SmlItem *item, SmlXmlAssembler *assm, SmlError **error) +gboolean +smlItemAssemble (SmlItem *item, + SmlXmlAssembler *assm, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, item, assm, error); CHECK_ERROR_REF @@ -340,7 +397,8 @@ smlAssert(item); if (assm->moreDataSet) { - smlErrorSet(error, SML_ERROR_GENERIC, "Trying to start a new item while last item had more data"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Trying to start a new item while last item had more data"); goto error; } @@ -402,13 +460,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlCredAssemble(SmlCred *cred, SmlXmlAssembler *assm, SmlError **error) +gboolean +smlCredAssemble (SmlCred *cred, + SmlXmlAssembler *assm, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, cred, assm, error); CHECK_ERROR_REF @@ -428,7 +488,8 @@ goto error; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "SyncML credential: Unknown format %d.", cred->format); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "SyncML credential: Unknown format %d.", cred->format); goto error; } @@ -442,7 +503,8 @@ goto error; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown format"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unknown format"); goto error; } @@ -458,13 +520,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlAccessAssemble(SmlXmlAssembler *assm, SmlCommand *change, SmlError **error) +gboolean +smlAccessAssemble (SmlXmlAssembler *assm, + SmlCommand *change, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, change, error); CHECK_ERROR_REF @@ -472,12 +536,12 @@ smlAssert(assm); if (!change->private.access.item) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing item"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing item"); goto error; } if (!change->private.access.item->contenttype) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing contenttype"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing contenttype"); goto error; } @@ -497,13 +561,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlChangeAssemble(SmlXmlAssembler *assm, SmlCommand *change, SmlError **error) +gboolean +smlChangeAssemble (SmlXmlAssembler *assm, + SmlCommand *change, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, change, error); CHECK_ERROR_REF @@ -512,7 +578,7 @@ if (!change->private.change.items || !g_list_length(change->private.change.items)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing items"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing items"); goto error; } @@ -521,11 +587,13 @@ SmlItem *item = g_list_nth_data(change->private.change.items, 0); if (!item) { - smlErrorSet(error, SML_ERROR_GENERIC, "One item of the item list is NULL."); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "One item of the item list is NULL."); goto error; } if (!item->contenttype) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing contenttype"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Missing contenttype"); goto error; } @@ -539,7 +607,7 @@ /* We will add the max obj size node, if USE_LARGEOBJECTS is true or not set at all. * And the remote side must have set a maxobjsize if we are a server */ const char *opt = smlAssemblerGetOption(assm->assembler, "USE_LARGEOBJECTS"); - SmlBool supportsLargeObjects = (opt && !atoi(opt)) ? FALSE : TRUE; + gboolean supportsLargeObjects = (opt && !atoi(opt)) ? FALSE : TRUE; smlTrace(TRACE_INTERNAL, "%s: Large object: use %i, server %i, requestedSize %i", __func__, supportsLargeObjects, assm->session->sessionType == SML_SESSION_TYPE_SERVER ? 1 : 0, smlAssemblerGetRemoteMaxObjSize(assm->assembler)); @@ -614,13 +682,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlSyncAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) +gboolean +smlSyncAssemble (SmlXmlAssembler *assm, + SmlCommand *cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmd, error); CHECK_ERROR_REF @@ -628,7 +698,7 @@ smlAssert(assm); if (!cmd->target) { - smlErrorSet(error, SML_ERROR_GENERIC, "No target set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No target set"); goto error; } @@ -642,7 +712,7 @@ goto error; if (!cmd->source) { - smlErrorSet(error, SML_ERROR_GENERIC, "No source set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No source set"); goto error; } @@ -662,7 +732,7 @@ } const char *opt = smlAssemblerGetOption(assm->assembler, "USE_NUMBEROFCHANGES"); - SmlBool supportsNumberOfChanges = (opt && !atoi(opt)) ? FALSE : TRUE; + gboolean supportsNumberOfChanges = (opt && !atoi(opt)) ? FALSE : TRUE; if (supportsNumberOfChanges && assm->session->version != SML_VERSION_10) { if (!_smlXmlAssemblerAddID(assm, SML_ELEMENT_NUMBEROFCHANGES, cmd->private.sync.numChanged, error)) goto error; @@ -670,13 +740,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlMapItemAssemble(SmlXmlAssembler *assm, SmlMapItem *item, SmlError **error) +gboolean +smlMapItemAssemble (SmlXmlAssembler *assm, + SmlMapItem *item, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, item, error); CHECK_ERROR_REF @@ -702,13 +774,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlMapAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) +gboolean +smlMapAssemble (SmlXmlAssembler *assm, + SmlCommand *cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmd, error); CHECK_ERROR_REF @@ -716,7 +790,7 @@ smlAssert(assm); if (!cmd->target) { - smlErrorSet(error, SML_ERROR_GENERIC, "No target set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No target set"); goto error; } @@ -724,7 +798,7 @@ goto error; if (!cmd->source) { - smlErrorSet(error, SML_ERROR_GENERIC, "No source set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No source set"); goto error; } @@ -740,13 +814,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlAlertAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) +gboolean +smlAlertAssemble (SmlXmlAssembler *assm, + SmlCommand *cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmd, error); CHECK_ERROR_REF @@ -784,7 +860,7 @@ } else { // NEXT MESSAGE alerts does not need a source/target if (cmd->private.alert.type != SML_ALERT_NEXT_MESSAGE) { - smlErrorSet(error, SML_ERROR_GENERIC, "No source set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No source set"); goto error; } } @@ -804,7 +880,7 @@ /* Begin of META */ - SmlBool meta = FALSE; + gboolean meta = FALSE; if (cmd->private.alert.contentType) meta = TRUE; if (cmd->private.alert.anchor) @@ -839,13 +915,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlResultsAssemble(SmlXmlAssembler *assm, SmlCommand *cmd, SmlError **error) +gboolean +smlResultsAssemble (SmlXmlAssembler *assm, + SmlCommand *cmd, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmd, error); CHECK_ERROR_REF @@ -892,11 +970,14 @@ return TRUE; error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerAddHeader(SmlXmlAssembler *assm, SmlSession *session, SmlError **error) +gboolean +smlXmlAssemblerAddHeader (SmlXmlAssembler *assm, + SmlSession *session, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, session, error); CHECK_ERROR_REF @@ -913,13 +994,14 @@ /* We first start a new writer that will write our header into a buffer */ assm->header_buffer = xmlBufferCreateSize(BUFFER_SIZE); if (!assm->header_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; } assm->writer = xmlNewTextWriterMemory(assm->header_buffer, 0); if (!assm->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; } @@ -927,12 +1009,12 @@ goto error; if (!session->protocol) { - smlErrorSet(error, SML_ERROR_GENERIC, "No version set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No version set"); goto error; } if (!session->version) { - smlErrorSet(error, SML_ERROR_GENERIC, "No dtd set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No dtd set"); goto error; } @@ -961,17 +1043,19 @@ goto error; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown version"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unknown version"); goto error; } break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown protocol"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unknown protocol"); goto error; } if (session->sessionID) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_SESSIONID, session->sessionID, error)) + if (!_smlXmlAssemblerAddID(assm, SML_ELEMENT_SESSIONID, session->sessionID, error)) goto error; } @@ -1021,13 +1105,13 @@ /* Large object support is enabled. */ if (smlSessionGetLocalMaxMsgSize(session) < 1) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "MaxMsgSize must be set."); goto error; } if (smlSessionGetLocalMaxObjSize(session) < 1) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "MaxObjSize must be set."); goto error; } @@ -1056,7 +1140,7 @@ /* Now close the buffer and get the content */ if (xmlTextWriterEndDocument(assm->writer) < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to end writer"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to end writer"); goto error; } @@ -1066,7 +1150,6 @@ g_mutex_unlock(assm->mutex); smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: if (assm->writer) { xmlFreeTextWriter(assm->writer); @@ -1077,33 +1160,39 @@ assm->header_buffer = NULL; } g_mutex_unlock(assm->mutex); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerStartCommand(SmlXmlAssembler *assm, unsigned int parentID, SmlCommand *cmd, SmlError **error) +gboolean +smlXmlAssemblerStartCommand (SmlXmlAssembler *assm, + gsize parentID, + SmlCommand *cmd, + GError **error) { CHECK_ERROR_REF smlAssert(assm); smlAssert(cmd); + + SmlXmlAssemblerCommand *assmcmd = NULL; if (cmd->type == SML_COMMAND_TYPE_UNKNOWN) { - smlErrorSet(error, SML_ERROR_GENERIC, "No cmd set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No cmd set"); goto error; } if (!cmd->cmdID) { - smlErrorSet(error, SML_ERROR_GENERIC, "No cmd ID set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No cmd ID set"); goto error; } /* Lets see if there already was a header before */ if (!assm->header_buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Header not yet added"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Header not yet added"); goto error; } - SmlXmlAssemblerCommand *assmcmd = smlTryMalloc0(sizeof(SmlXmlAssemblerCommand), error); + assmcmd = smlTryMalloc0(sizeof(SmlXmlAssemblerCommand), error); if (!assmcmd) goto error; assmcmd->nodeType = SML_ASSEMBLER_NODE_OPEN; @@ -1125,57 +1214,60 @@ /* We first start a new parent writer that will write our command into a buffer */ assmcmd->buffer = xmlBufferCreateSize(BUFFER_SIZE); if (!assmcmd->buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new buffer"); - goto error_free_cmd; + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to create new buffer"); + goto error; } assm->writer = xmlNewTextWriterMemory(assmcmd->buffer, 0); if (!assm->writer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new writer"); - goto error_free_buffer; + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to create new writer"); + goto error; } /* We start without the root node */ if (!_smlXmlAssemblerAddID(assm, SML_ELEMENT_CMDID, cmd->cmdID, error)) - goto error_free_writer; + goto error; switch (cmd->type) { case SML_COMMAND_TYPE_ALERT: if (!smlAlertAssemble(assm, cmd, error)) - goto error_free_writer; + goto error; break; case SML_COMMAND_TYPE_SYNC: if (!smlSyncAssemble(assm, cmd, error)) - goto error_free_writer; + goto error; break; case SML_COMMAND_TYPE_ADD: case SML_COMMAND_TYPE_REPLACE: case SML_COMMAND_TYPE_DELETE: if (!smlChangeAssemble(assm, cmd, error)) - goto error_free_writer; + goto error; break; case SML_COMMAND_TYPE_PUT: case SML_COMMAND_TYPE_GET: if (!smlAccessAssemble(assm, cmd, error)) - goto error_free_writer; + goto error; break; case SML_COMMAND_TYPE_MAP: if (!smlMapAssemble(assm, cmd, error)) - goto error_free_writer; + goto error; break; case SML_COMMAND_TYPE_RESULTS: if (!smlResultsAssemble(assm, cmd, error)) - goto error_free_writer; + goto error; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown command type"); - goto error_free_writer; + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unknown command type"); + goto error; } /* Now close the buffer */ if (xmlTextWriterEndDocument(assm->writer) < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to end writer"); - goto error_free_writer; + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to end writer"); + goto error; } xmlFreeTextWriter(assm->writer); @@ -1185,26 +1277,33 @@ *appendto = g_list_append(*appendto, assmcmd); return TRUE; - -error_free_writer: - xmlFreeTextWriter(assm->writer); - assm->writer = NULL; -error_free_buffer: - xmlBufferFree(assmcmd->buffer); -error_free_cmd: - smlSafeFree((gpointer *)&assmcmd); error: + if (assm->writer) { + xmlFreeTextWriter(assm->writer); + assm->writer = NULL; + } + if (assmcmd) { + if (assmcmd->buffer) { + xmlBufferFree(assmcmd->buffer); + assmcmd->buffer = NULL; + } + smlSafeFree((gpointer *)&assmcmd); + } return FALSE; } -SmlBool smlXmlAssemblerEndCommand(SmlXmlAssembler *assm, unsigned int parentID, SmlError **error) +gboolean +smlXmlAssemblerEndCommand (SmlXmlAssembler *assm, + gsize parentID, + GError **error) { CHECK_ERROR_REF smlAssert(assm); /* Lets see if there already was a header before */ if (!assm->header_buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Header not yet added"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Header not yet added"); goto error; } @@ -1229,12 +1328,14 @@ *appendto = g_list_append(*appendto, assmcmd); return TRUE; - error: return FALSE; } -SmlBool smlXmlAssemblerRemCommand(SmlXmlAssembler *assm, unsigned int parentID, SmlError **error) +gboolean +smlXmlAssemblerRemCommand (SmlXmlAssembler *assm, + gsize parentID, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, assm, parentID, error); CHECK_ERROR_REF @@ -1253,7 +1354,7 @@ } if (!*removefrom) { - smlErrorSet(error, SML_ERROR_GENERIC, "Nothing to remove"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Nothing to remove"); goto error; } @@ -1261,7 +1362,8 @@ SmlXmlAssemblerCommand *cmd = b->data; *removefrom = g_list_delete_link(*removefrom, b); if (cmd->nodeType != SML_ASSEMBLER_NODE_OPEN) { - smlErrorSet(error, SML_ERROR_GENERIC, "Trying to remove not a starting command"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Trying to remove not a starting command"); goto error; } @@ -1272,20 +1374,22 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerRemStatus(SmlXmlAssembler *assm, SmlError **error) +gboolean +smlXmlAssemblerRemStatus (SmlXmlAssembler *assm, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, assm, error); CHECK_ERROR_REF smlAssert(assm); if (!assm->statuses) { - smlErrorSet(error, SML_ERROR_GENERIC, "Trying to remove status but no status available"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Trying to remove status but no status available"); goto error; } @@ -1308,13 +1412,17 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerReserveStatus(SmlXmlAssembler *assm, unsigned int cmdRef, unsigned int msgRef, unsigned int cmdID, SmlError **error) +gboolean +smlXmlAssemblerReserveStatus (SmlXmlAssembler *assm, + gsize cmdRef, + gsize msgRef, + gsize cmdID, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %i, %i, %i, %p)", __func__, assm, cmdRef, msgRef, cmdID, error); CHECK_ERROR_REF @@ -1337,13 +1445,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerAddStatus(SmlXmlAssembler *assm, SmlStatus *status, SmlError **error) +gboolean +smlXmlAssemblerAddStatus (SmlXmlAssembler *assm, + SmlStatus *status, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, status, error); CHECK_ERROR_REF @@ -1358,18 +1468,18 @@ goto error; if (!status->msgRef) { - smlErrorSet(error, SML_ERROR_GENERIC, "No msgref set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No msgref set"); goto error; } if (status->type == SML_COMMAND_TYPE_UNKNOWN) { - smlErrorSet(error, SML_ERROR_GENERIC, "No cmd set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No cmd set"); goto error; } /* Lets see if there already was a header before */ if (!assm->header_buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Header not yet added"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Header not yet added"); goto error; } @@ -1383,30 +1493,30 @@ } if (!res) { - smlErrorSet(error, SML_ERROR_GENERIC, "Status not reserved"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Status not reserved"); goto error; } if (!res->cmdID) { - smlErrorSet(error, SML_ERROR_GENERIC, "No cmd ID set"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No cmd ID set"); goto error; } if (res->buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Status already added"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Status already added"); goto error; } /* We first start a new writer that will write our status into a buffer */ res->buffer = xmlBufferCreateSize(BUFFER_SIZE); if (!res->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; } assm->writer = xmlNewTextWriterMemory(res->buffer, 0); if (!assm->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; } @@ -1472,7 +1582,7 @@ goto error; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown auth type"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown auth type"); goto error; } @@ -1518,7 +1628,7 @@ /* Now close the buffer and get the content */ if (xmlTextWriterEndDocument(assm->writer) < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to end writer"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to end writer"); goto error_free_writer; } @@ -1539,11 +1649,12 @@ res->buffer = NULL; error: g_mutex_unlock(assm->mutex); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerMissingStatus(SmlXmlAssembler *assm) +gboolean +smlXmlAssemblerMissingStatus (SmlXmlAssembler *assm) { smlAssert(assm); @@ -1553,7 +1664,8 @@ return FALSE; } -static void flush_list(GList *list) +static void +flush_list(GList *list) { GList *l = NULL; for (l = list; l; l = l->next) { @@ -1569,7 +1681,8 @@ g_list_free(list); } -void smlXmlAssemblerFree(SmlXmlAssembler *assm) +void +smlXmlAssemblerFree (SmlXmlAssembler *assm) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm); smlAssert(assm); @@ -1600,13 +1713,14 @@ /* This function returns the highest command id that is still in the * assembler after flushing which is: number of statuses + 1 */ -unsigned int smlXmlAssemblerFlush(SmlXmlAssembler *assm) +gsize +smlXmlAssemblerFlush (SmlXmlAssembler *assm) { smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm); smlAssert(assm); unsigned int newid = 1; - SmlBool missing = FALSE; + gboolean missing = FALSE; /* Remove the statuses */ GList *s = NULL; @@ -1648,7 +1762,10 @@ return newid; } -SmlBool smlXmlAssemblerStart(SmlXmlAssembler *assm, SmlSession *session, SmlError **error) +gboolean +smlXmlAssemblerStart (SmlXmlAssembler *assm, + SmlSession *session, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, session, error); CHECK_ERROR_REF @@ -1664,7 +1781,9 @@ } -SmlBool smlXmlAssemblerEnd(SmlXmlAssembler *assm, SmlError **error) +gboolean +smlXmlAssemblerEnd (SmlXmlAssembler *assm, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, assm, error); CHECK_ERROR_REF @@ -1676,27 +1795,29 @@ goto error; if (_smlXmlAssemblerEndNode(assm, NULL)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Extra node open"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Extra node open"); goto error; } g_mutex_unlock(assm->mutex); smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: g_mutex_unlock(assm->mutex); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerAddChildren(SmlXmlAssembler *assm, GList *b, SmlError **error) +gboolean +smlXmlAssemblerAddChildren (SmlXmlAssembler *assm, + GList *b, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, b, error); CHECK_ERROR_REF smlAssert(assm); const char *opt = smlAssemblerGetOption(assm->assembler, "ONLY_REPLACE"); - SmlBool onlyReplace = (opt && atoi(opt)) ? TRUE : FALSE; + gboolean onlyReplace = (opt && atoi(opt)) ? TRUE : FALSE; SmlXmlAssemblerCommand *cmd = NULL; const char *cmdname = NULL; @@ -1721,7 +1842,8 @@ int rc = xmlTextWriterWriteRawLen(assm->writer, xmlBufferContent(cmd->buffer), xmlBufferLength(cmd->buffer)); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to write raw node data (%d).", rc); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to write raw node data (%d).", rc); goto error; } @@ -1744,13 +1866,20 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlAssemblerRunFull(SmlXmlAssembler *assm, char **data, unsigned int *size, SmlBool *end, SmlBool final, SmlBool check, unsigned int maxsize, SmlError **error) +gboolean +smlXmlAssemblerRunFull (SmlXmlAssembler *assm, + gchar **data, + gsize *size, + gboolean *end, + gboolean final, + gboolean check, + gsize maxsize, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %i, %i, %i, %p)", __func__, assm, data, size, end, final, check, maxsize, error); CHECK_ERROR_REF @@ -1763,7 +1892,7 @@ /* Return an error if there is no header */ if (!assm->header_buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "No header available"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No header available"); goto error; } @@ -1771,14 +1900,16 @@ * statuses have been reserved, at least the first status * must be added */ if (check && !assm->statuses && !assm->commands) { - smlErrorSet(error, SML_ERROR_GENERIC, "No status/command available"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "No status/command available"); goto error; } if (check && assm->statuses && final) { SmlXmlAssemblerStatus *status = assm->statuses->data; if (!status->buffer) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing the first status with cmdRef %i", status->cmdRef); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Missing the first status with cmdRef %i", + status->cmdRef); goto error; } } @@ -1786,13 +1917,13 @@ /* Create the final buffer and writer */ 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; } assm->writer = xmlNewTextWriterMemory(buffer, 0); if (!assm->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; } @@ -1801,7 +1932,7 @@ * is explicitly added to support buggy XML parsers. */ if (xmlTextWriterStartDocument(assm->writer, NULL, "UTF-8", NULL) < 0) { - 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_writer; } @@ -1823,14 +1954,15 @@ goto error_free_writer; break; default: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown version"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown version"); goto error_free_writer; } /* Add the header */ int rc = xmlTextWriterWriteRawLen(assm->writer, xmlBufferContent(assm->header_buffer), xmlBufferLength(assm->header_buffer)); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to write raw header data (%d).", rc); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to write raw header data (%d).", rc); goto error_free_writer; } @@ -1844,14 +1976,15 @@ /* Add the statuses */ GList *b = NULL; - SmlBool missingstatus = FALSE; + gboolean missingstatus = FALSE; smlTrace(TRACE_INTERNAL, "%s: Now adding %i statuses", __func__, g_list_length(assm->statuses)); for (b = assm->statuses; b; b = b->next) { SmlXmlAssemblerStatus *status = b->data; if (!status->buffer || xmlBufferLength(status->buffer) == 0) { if (status->cmdRef == 0 && check) { - smlErrorSet(error, SML_ERROR_GENERIC, "Reserved status 0 has not been added"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Reserved status 0 has not been added"); goto error_free_writer; } smlTrace(TRACE_INTERNAL, "%s: Reserved status %i is missing", @@ -1865,16 +1998,18 @@ // break; rc = xmlTextWriterWriteRawLen(assm->writer, xmlBufferContent(status->buffer), xmlBufferLength(status->buffer)); if (rc < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to write raw status data (%d - %d of %d: %s).", - rc, xmlBufferLength(status->buffer), - buffersize, xmlBufferContent(status->buffer)); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to write raw status data (%d - %d of %d: %s).", + rc, xmlBufferLength(status->buffer), + buffersize, xmlBufferContent(status->buffer)); goto error_free_writer; } } /* We cannot have missing statuses when its final. And we cannot add commands */ if (missingstatus && final && check) { - smlErrorSet(error, SML_ERROR_GENERIC, "Reserved status has not been added"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Reserved status has not been added"); goto error_free_writer; } @@ -1897,7 +2032,7 @@ goto error_free_writer; if (xmlTextWriterEndDocument(assm->writer) < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to end writer"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unable to end writer"); goto error; } @@ -1930,13 +2065,13 @@ xmlBufferFree(buffer); error: g_mutex_unlock(assm->mutex); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static unsigned int calc_list(GList *list) +static gsize calc_list(GList *list) { - unsigned int size = 0; + gsize size = 0; for (; list; list = list->next) { SmlXmlAssemblerCommand *cmd = list->data; @@ -1951,20 +2086,30 @@ return size; } -SmlBool smlXmlAssemblerRun(SmlXmlAssembler *assm, char **data, unsigned int *size, SmlBool *end, SmlBool final, unsigned int maxsize, SmlError **error) +gboolean +smlXmlAssemblerRun (SmlXmlAssembler *assm, + gchar **data, + gsize *size, + gboolean *end, + gboolean final, + gsize maxsize, + GError **error) { CHECK_ERROR_REF - SmlBool ans = smlXmlAssemblerRunFull(assm, data, size, end, final, TRUE, maxsize, error); + gboolean ans = smlXmlAssemblerRunFull(assm, data, size, end, final, TRUE, maxsize, error); if (ans) smlLog("sent-%i.xml", *data, *size); else - smlTrace(TRACE_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_ERROR, "%s - %s", __func__, (*error)->message); return ans; } -unsigned int smlXmlAssemblerCheckSize(SmlXmlAssembler *assm, SmlBool headeronly, SmlError **error) +gsize +smlXmlAssemblerCheckSize (SmlXmlAssembler *assm, + gboolean headeronly, + GError **error) { CHECK_ERROR_REF smlAssert(assm); @@ -1996,7 +2141,10 @@ return size; } -SmlBool smlXmlAssemblerNextCmdRef(SmlXmlAssembler *assm, unsigned int *cmdRef, unsigned int *msgRef) +gboolean +smlXmlAssemblerNextCmdRef (SmlXmlAssembler *assm, + gsize *cmdRef, + gsize *msgRef) { smlAssert(assm); smlAssert(cmdRef); @@ -2023,7 +2171,10 @@ * @return The new assembler or NULL in the case of an error * */ -SmlXmlAssembler *smlXmlAssemblerNew(SmlAssembler *assembler, SmlAssemblerFunctions *functions, SmlError **error) +SmlXmlAssembler* +smlXmlAssemblerNew (SmlAssembler *assembler, + SmlAssemblerFunctions *functions, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assembler, functions, error); CHECK_ERROR_REF @@ -2058,13 +2209,19 @@ error_mutex: smlSafeFree((gpointer *)&assm); - smlErrorSet(error, SML_ERROR_GENERIC, "%s - Cannot create new mutex.", __func__); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "%s - Cannot create new mutex.", __func__); error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; } -static SmlBool _smlXmlDevInfDataStoreAssembleRxTx(SmlXmlAssembler *assm, const char *element, const char *cttype, const char *version, SmlError **error) +static gboolean +_smlXmlDevInfDataStoreAssembleRxTx (SmlXmlAssembler *assm, + const gchar *element, + const gchar *cttype, + const gchar *version, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %s, %p)", __func__, assm, VA_STRING(element), VA_STRING(cttype), VA_STRING(version), error); CHECK_ERROR_REF @@ -2086,17 +2243,16 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlXmlDevInfDataStoreAssembleCTCap( - SmlXmlAssembler *assm, - SmlDevInfCTCap *ctcap, - SmlBool flat, - SmlError **error) +static gboolean +_smlXmlDevInfDataStoreAssembleCTCap (SmlXmlAssembler *assm, + SmlDevInfCTCap *ctcap, + gboolean flat, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, assm, ctcap, error); CHECK_ERROR_REF @@ -2270,17 +2426,16 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -static SmlBool _smlXmlDevInfDataStoreAssemble( - SmlXmlAssembler *assm, - SmlDevInfDataStore *datastore, - SmlDevInf *devinf, - SmlError **error) +static gboolean +_smlXmlDevInfDataStoreAssemble (SmlXmlAssembler *assm, + SmlDevInfDataStore *datastore, + SmlDevInf *devinf, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, assm, datastore, devinf, error); CHECK_ERROR_REF @@ -2288,14 +2443,9 @@ smlAssert(assm); GList *contentTypes = NULL; - GError *gerror = NULL; - if (!sml_dev_inf_data_store_is_compliant(datastore, &gerror)) { - smlErrorSet(error, gerror->code, "%s", gerror->message); - g_error_free(gerror); - gerror = NULL; + if (!sml_dev_inf_data_store_is_compliant(datastore, error)) goto error; - } // Datastore if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_DATASTORE, error)) @@ -2458,13 +2608,17 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -SmlBool smlXmlDevInfAssemble(SmlDevInf *devinf, SmlDevInfVersion version, char **data, unsigned int *size, SmlError **error) +gboolean +smlXmlDevInfAssemble (SmlDevInf *devinf, + SmlDevInfVersion version, + gchar **data, + gsize *size, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %i, %p, %p, %p)", __func__, devinf, version, data, size, error); CHECK_ERROR_REF @@ -2488,13 +2642,15 @@ /* We first start a new parent writer that will write our command into a buffer */ 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_free_assm; } assm->writer = xmlNewTextWriterMemory(buffer, 0); if (!assm->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; } @@ -2517,7 +2673,8 @@ goto error_free_writer; break; case SML_DEVINF_VERSION_UNKNOWN: - smlErrorSet(error, SML_ERROR_GENERIC, "Unknown devinf version"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unknown devinf version"); goto error_free_writer; break; } @@ -2622,7 +2779,8 @@ /* Now close the buffer */ if (xmlTextWriterEndDocument(assm->writer) < 0) { - smlErrorSet(error, SML_ERROR_GENERIC, "Unable to end writer"); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Unable to end writer"); goto error_free_writer; } @@ -2649,12 +2807,13 @@ error_free_assm: smlSafeFree((gpointer *)&assm); error: - g_warning("%s: %s", __func__, smlErrorPrint(error)); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + g_warning("%s: %s", __func__, (*error)->message); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } -void smlXmlAssemblerRestoreCommands(SmlXmlAssembler *assm) +void +smlXmlAssemblerRestoreCommands (SmlXmlAssembler *assm) { smlTrace(TRACE_ENTRY, "%s", __func__); smlAssert(assm->commands == NULL); Modified: trunk/libsyncml/parser/sml_xml_assm_internals.h ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm_internals.h Wed Jul 8 16:18:21 2009 (r1158) +++ trunk/libsyncml/parser/sml_xml_assm_internals.h Wed Jul 8 17:16:46 2009 (r1159) @@ -1,7 +1,7 @@ /* * libsyncml - A syncml protocol implementation * Copyright (C) 2005 Armin Bauer <arm...@op...> - * Copyright (C) 2008 Michael Bell <mic...@op...> + * Copyright (C) 2008-2009 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -50,19 +50,19 @@ /** The type of the node. Either a opening or a closing node */ SmlXmlAssemblerNodeType nodeType; /** The command id. Needed if you want to add children */ - unsigned int cmdID; + gsize cmdID; GList *children; } SmlXmlAssemblerCommand; typedef struct SmlXmlAssemblerStatus { /** The type of the command. Used the make the opening and closing tags */ - unsigned int cmdRef; + gsize cmdRef; - unsigned int msgRef; + gsize msgRef; /** The buffer that holds the assembled data of this status */ xmlBuffer *buffer; /** The command id.*/ - unsigned int cmdID; + gsize cmdID; } SmlXmlAssemblerStatus; struct SmlXmlAssembler { @@ -77,19 +77,19 @@ SmlAssembler *assembler; GMutex *mutex; - unsigned int reserved_statuses; - unsigned int added_statuses; + gsize reserved_statuses; + gsize added_statuses; - SmlBool moreDataSet; + gboolean moreDataSet; }; -SmlBool smlAssemblerStartNode(SmlAssembler *assm, const char *name, SmlError **error); -SmlBool smlAssemblerStartNodeNS(SmlAssembler *assm, const char *prefix, const char *name, const char *uri, SmlError **error); -SmlBool smlAssemblerEndNode(SmlAssembler *assm, SmlError **error); -SmlBool smlAssemblerAddString(SmlAssembler *assm, const char *name, const char *value, SmlError **error); -SmlBool smlAssemblerAddStringNS(SmlAssembler *assm, const char *prefix, const char *name, const char *uri, const char *value, SmlError **error); -SmlBool smlAssemblerAddID(SmlAssembler *assm, const char *name, unsigned int id, SmlError **error); -SmlBool smlAssemblerAddData(SmlAssembler *assm, const char *name, const char *value, SmlError **error); +gboolean smlAssemblerStartNode (SmlAssembler *assm, const gchar *name, GError **error); +gboolean smlAssemblerStartNodeNS (SmlAssembler *assm, const gchar *prefix, const gchar *name, const gchar *uri, GError **error); +gboolean smlAssemblerEndNode (SmlAssembler *assm, GError **error); +gboolean smlAssemblerAddString (SmlAssembler *assm, const gchar *name, const gchar *value, GError **error); +gboolean smlAssemblerAddStringNS (SmlAssembler *assm, const gchar *prefix, const gchar *name, const gchar *uri, const gchar *value, GError **error); +gboolean smlAssemblerAddID (SmlAssembler *assm, const gchar *name, gsize id, GError **error); +gboolean smlAssemblerAddData (SmlAssembler *assm, const gchar *name, const gchar *value, GError **error); #endif //_SML_XML_ASSM_INTERNALS_H_ /*@}*/ |