From: <svn...@op...> - 2009-08-07 17:52:52
|
Author: bellmich Date: Fri Aug 7 19:52:39 2009 New Revision: 1243 URL: http://libsyncml.opensync.org/changeset/1243 Log: - adapted to reduced SmlLocation API - integrated SmlChangeItem API Modified: trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_notification.c trunk/libsyncml/sml_session.c Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/parser/sml_xml_assm.c Fri Aug 7 19:52:39 2009 (r1243) @@ -26,6 +26,7 @@ #include "libsyncml/sml_error_internals.h" #include "libsyncml/data_sync_api/sml_map_item_internals.h" +#include "libsyncml/data_sync_api/sml_change_item_internals.h" #include "sml_xml_assm_internals.h" #include <string.h> @@ -419,35 +420,153 @@ } /* SourceParent */ - if (sml_location_get_parent_uri(smlItemGetSource(item))) { + if (smlItemGetSource(item) && + sml_location_get_parent_uri(smlItemGetSource(item))) { if (!smlLocationAssemble(smlItemGetSource(item), assm, SML_ELEMENT_SOURCE_PARENT, error)) goto error; } /* TargetParent */ - if (sml_location_get_parent_uri(smlItemGetTarget(item))) { + if (smlItemGetTarget(item) && + sml_location_get_parent_uri(smlItemGetTarget(item))) { if (!smlLocationAssemble(smlItemGetTarget(item), assm, SML_ELEMENT_TARGET_PARENT, error)) goto error; } /* Data */ if (smlItemHasData(item)) { - if (item->disabled) { - if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, "", 0, item->raw, error)) - goto error; + char *data = NULL; + gsize size = 0; + if (!smlItemGetData(item, &data, &size, error)) + goto error; + + if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, item->raw, error)) + goto error; + } + + /* MoreData */ + if (item->moreData) { + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_MOREDATA, "", error)) + goto error; + + assm->moreDataSet = TRUE; + } + + /* End of Item */ + if (!_smlXmlAssemblerEndNode(assm, error)) + goto error; + + smlTrace(TRACE_EXIT, "%s", __func__); + return TRUE; +error: + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); + return FALSE; +} + +gboolean +smlChangeItemAssemble (SmlChangeItem *item, + SmlXmlAssembler *assm, + GError **error) +{ + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, item, assm, error); + CHECK_ERROR_REF + smlAssert(assm); + smlAssert(item); + + if (assm->moreDataSet) { + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Trying to start a new item while last item had more data"); + goto error; + } + + /* Begin of Item */ + if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) + goto error; + + /* Item has to deal with four different situations: + * 1. If this is a new item but the remote peer only supports + * the Replace command and the local peer is an OMA DS + * server then the ID/location must be send as target. + * If the local peer is an OMA DS client then nothing + * changes. FYI an OMA DS server must support the Add + * command. + * => Target must be set (Target is the former Source) + * 2. If this is a new item then the local peer only knows + * the ID of the item. + * => Source must be set + * 3. If this is a changed or deleted item and the local peer + * is an OMA DS server then the item must reference the ID + * of the remote peer because of the submitted map. Please + * not that the remote peer as an OMA DS client must only + * know its own ID of the item. The mapping of locations + * (IDs) is the exclusive job of the OMA DS server. + * => Target must be set (Source is optional) + * 4. If this is a changed or deleted item and the local peer + * is an OMA DS client then the item must reference the ID + * of the local peer only because the mapping of locations + * (IDs) must be done by the OMA DS server. + * => Source must be set + */ + gboolean fillSource = TRUE; + SmlSessionType sessionType = assm->session->sessionType; + const char *opt = smlAssemblerGetOption(assm->assembler, "ONLY_REPLACE"); + if (sml_change_item_get_action(item) == SML_CHANGE_ADD) + { + if (opt && atoi(opt) && /* remote peer supports ONLY_REPLACE */ + sessionType == SML_SESSION_TYPE_SERVER) { + /* only Target must be set */ + fillSource = FALSE; } else { - char *data = NULL; - gsize size = 0; - if (!smlItemGetData(item, &data, &size, error)) - goto error; - - if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, item->raw, error)) - goto error; + /* only Source must be set */ + fillSource = TRUE; + } + } else { + if (sessionType == SML_SESSION_TYPE_SERVER) { + /* Target must be set */ + fillSource = FALSE; + } else { + /* only Source must be set */ + fillSource = TRUE; } } + + /* Target */ + if (!fillSource && sml_change_item_get_location(item)) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_TARGET, error)) + goto error; + } + + /* Source */ + if (fillSource && sml_change_item_get_location(item)) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_SOURCE, error)) + goto error; + } + + /* SourceParent */ + if (fillSource && sml_change_item_get_location(item) && + sml_location_get_parent_uri(sml_change_item_get_location(item))) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_SOURCE_PARENT, error)) + goto error; + } + + /* TargetParent */ + if (!fillSource && sml_change_item_get_location(item) && + sml_location_get_parent_uri(sml_change_item_get_location(item))) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_TARGET_PARENT, error)) + goto error; + } + + /* Data */ + if (sml_change_item_get_data(item)) { + const gchar *data = sml_change_item_get_data(item); + gsize size = strlen(data);; + + if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, FALSE, error)) + goto error; + } /* MoreData */ - if (item->moreData) { + if (sml_change_item_get_missing_data(item)) { if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_MOREDATA, "", error)) goto error; @@ -584,14 +703,14 @@ /* libsyncml only supports one item per change command */ smlAssert(g_list_length(change->private.change.items) == 1); - SmlItem *item = g_list_nth_data(change->private.change.items, 0); + SmlChangeItem *item = g_list_nth_data(change->private.change.items, 0); if (!item) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "One item of the item list is NULL."); goto error; } - if (!item->contenttype) { + if (!sml_change_item_get_content_type(item)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing contenttype"); goto error; @@ -601,7 +720,7 @@ if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) goto error; - if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, item->contenttype, error)) + if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, sml_change_item_get_content_type(item), error)) goto error; /* We will add the max obj size node, if USE_LARGEOBJECTS is true or not set at all. @@ -622,62 +741,7 @@ //Item(s) - /* Item has to deal with four different situations: - * 1. If this is a new item but the remote peer only supports - * the Replace command and the local peer is an OMA DS - * server then the ID/location must be send as target. - * If the local peer is an OMA DS client then nothing - * changes. FYI an OMA DS server must support the Add - * command. - * => Target must be set (Target is the former Source) - * 2. If this is a new item then the local peer only knows - * the ID of the item. - * => Source must be set - * 3. If this is a changed or deleted item and the local peer - * is an OMA DS server then the item must reference the ID - * of the remote peer because of the submitted map. Please - * not that the remote peer as an OMA DS client must only - * know its own ID of the item. The mapping of locations - * (IDs) is the exclusive job of the OMA DS server. - * => Target must be set (Source is optional) - * 4. If this is a changed or deleted item and the local peer - * is an OMA DS client then the item must reference the ID - * of the local peer only because the mapping of locations - * (IDs) must be done by the OMA DS server. - * => Source must be set - */ - SmlSessionType sessionType = assm->session->sessionType; - opt = smlAssemblerGetOption(assm->assembler, "ONLY_REPLACE"); - if (change->type == SML_COMMAND_TYPE_ADD) - { - if (opt && atoi(opt) && /* remote peer supports ONLY_REPLACE */ - sessionType == SML_SESSION_TYPE_SERVER) { - /* only Target must be set */ - if (item->target) - g_object_unref(item->target); - item->target = item->source; - item->source = NULL; - } else { - /* only Source must be set */ - if (item->target) - g_object_unref(item->target); - item->target = NULL; - } - } else { - if (sessionType == SML_SESSION_TYPE_SERVER) { - /* Target must be set */ - if (item->source) - g_object_unref(item->source); - item->source = NULL; - } else { - /* only Source must be set */ - if (item->target) - g_object_unref(item->target); - item->target = NULL; - } - } - - if (!smlItemAssemble(item, assm, error)) + if (!smlChangeItemAssemble(item, assm, error)) goto error; smlTrace(TRACE_EXIT, "%s", __func__); @@ -866,13 +930,13 @@ } /* SourceParent */ - if (sml_location_get_parent_uri(cmd->source)) { + if (cmd->source && sml_location_get_parent_uri(cmd->source)) { if (!smlLocationAssemble(cmd->source, assm, SML_ELEMENT_SOURCE_PARENT, error)) goto error; } /* TargetParent */ - if (sml_location_get_parent_uri(cmd->target)) { + if (cmd->target && sml_location_get_parent_uri(cmd->target)) { if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET_PARENT, error)) goto error; } Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/parser/sml_xml_parse.c Fri Aug 7 19:52:39 2009 (r1243) @@ -24,7 +24,8 @@ #include <libsyncml/sml_command_internals.h> #include <libsyncml/sml_session_internals.h> #include "libsyncml/sml_error_internals.h" -#include "libsyncml/data_sync_api/sml_location_internals.h" +#include "libsyncml/data_sync_api/sml_location.h" +#include "libsyncml/data_sync_api/sml_change_item_internals.h" #include "sml_xml_parse_internals.h" #include <string.h> @@ -439,19 +440,13 @@ gchar *uri = NULL; if (!_smlXmlParserGetString(parser, &uri, SML_ELEMENT_LOCURI, error)) goto error; - if (!sml_location_set_uri(*location, uri, error)) { - g_free(uri); - goto error; - } + sml_location_set_uri(*location, uri); g_free(uri); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_LOCNAME)) { gchar *name = NULL; if (!_smlXmlParserGetString(parser, &name, SML_ELEMENT_LOCNAME, error)) goto error; - if (!sml_location_set_name(*location, name, error)) { - g_free(name); - goto error; - } + sml_location_set_name(*location, name); g_free(name); } else { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node. expected SyncHdr"); @@ -747,8 +742,7 @@ if (smlItemGetSource(item)) { /* SourceParent already parsed */ - if (!sml_location_set_parent_uri(source, sml_location_get_parent_uri(smlItemGetSource(item)), error)) - goto error; + sml_location_set_parent_uri(source, sml_location_get_parent_uri(smlItemGetSource(item))); } smlItemSetSource(item, source); @@ -760,8 +754,7 @@ if (smlItemGetTarget(item)) { /* TargetParent already parsed */ - if (!sml_location_set_parent_uri(target, sml_location_get_parent_uri(smlItemGetTarget(item)), error)) - goto error; + sml_location_set_parent_uri(target, sml_location_get_parent_uri(smlItemGetTarget(item))); } smlItemSetTarget(item, target); @@ -773,17 +766,14 @@ if (smlItemGetSource(item)) { /* Source already parsed */ - if (!sml_location_set_parent_uri(smlItemGetSource(item), sml_location_get_uri(source), error)) - goto error; + sml_location_set_parent_uri(smlItemGetSource(item), sml_location_get_uri(source)); } 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), error)) - goto error; + sml_location_set_parent_uri(source, sml_location_get_uri(source)); /* delete uri property */ - if (!sml_location_set_uri(source, NULL, error)) - goto error; + sml_location_set_uri(source, NULL); } g_object_unref(source); @@ -794,17 +784,14 @@ if (smlItemGetTarget(item)) { /* Target already parsed */ - if (!sml_location_set_parent_uri(smlItemGetTarget(item), sml_location_get_uri(target), error)) - goto error; + sml_location_set_parent_uri(smlItemGetTarget(item), sml_location_get_uri(target)); } 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), error)) - goto error; + sml_location_set_parent_uri(target, sml_location_get_uri(target)); /* delete uri property */ - if (!sml_location_set_uri(target, NULL, error)) - goto error; + sml_location_set_uri(target, NULL); } g_object_unref(target); @@ -1103,12 +1090,29 @@ smlAssert(parser); smlAssert(name); char *contenttype = NULL; + SmlLocation *source = NULL; + SmlLocation *target = NULL; *cmd = smlCommandNew(type, error); if (!*cmd) goto error; (*cmd)->refCount = 1; + switch (type) { + case SML_COMMAND_TYPE_ADD: + (*cmd)->private.change.type = SML_CHANGE_ADD; + break; + case SML_COMMAND_TYPE_REPLACE: + (*cmd)->private.change.type = SML_CHANGE_REPLACE; + break; + case SML_COMMAND_TYPE_DELETE: + (*cmd)->private.change.type = SML_CHANGE_DELETE; + break; + default: + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown change type set"); + goto error; + } + while (1) { if (!_smlXmlParserStep(parser)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); @@ -1134,10 +1138,72 @@ SmlItem *item = _smlItemParse(parser, *cmd, type, error); if (!item) goto error; - (*cmd)->private.change.items = g_list_append((*cmd)->private.change.items, item); + + /* convert SmlItem to SmlChangeItem */ + + SmlChangeItem *citem = sml_change_item_new(); + if (!citem) { + smlItemUnref(item); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new instance of SmlChangeItem - out of memory."); + goto error; + } + sml_change_item_set_action(citem, (*cmd)->private.change.type); + + /* message from OMA DS client: + * - ADD + source URI => automatically mapped item + * - REPLACE/DELETE + source/target URI => mapped item + * message from OMA DS server: + * - ADD + source/target URI => not yet mapped item + * - REPLACE/DELETE + target URI => mapped item + * => first check the target URI for a finally mapped item + * => second check the source URI for a not yet mapped item + */ + if (smlItemGetTarget(item)) { + if (!sml_change_item_set_location(citem, smlItemGetTarget(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + } else { + if (!sml_change_item_set_location(citem, smlItemGetSource(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + } + if (smlItemGetContent(item) && + !sml_change_item_set_data(citem, smlItemGetContent(item), smlItemGetSize(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + if (smlItemGetContentType(item) && + !sml_change_item_set_content_type(citem, smlItemGetContentType(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + if (smlItemGetMoreData(item)) { + sml_change_item_set_missing_data(citem, TRUE); + sml_change_item_set_planned_size(citem, (*cmd)->size); + } + if (!source && smlItemGetSource(item)) { + source = smlItemGetSource(item); + g_object_ref(source); + } + if (!target && smlItemGetTarget(item)) { + target = smlItemGetTarget(item); + g_object_ref(target); + } + smlItemUnref(item); + item = NULL; + + /* add item to list of items */ + + (*cmd)->private.change.items = g_list_append((*cmd)->private.change.items, citem); if (!(*cmd)->private.change.items) { - smlItemUnref(item); + g_object_unref(citem); g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "g_list_append for item list of change command failed."); goto error; } @@ -1165,54 +1231,35 @@ guint i; for (i=0; i < g_list_length((*cmd)->private.change.items); i++) { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, i); - if (item->contenttype == NULL && contenttype) { - item->contenttype = g_strdup(contenttype); + SmlChangeItem *item = g_list_nth_data((*cmd)->private.change.items, i); + if (sml_change_item_get_content_type(item) == NULL && + contenttype && + !sml_change_item_set_content_type(item, contenttype, error)) { + goto error; } } if (contenttype) smlSafeCFree(&contenttype); - for (i=0; i < g_list_length((*cmd)->private.change.items); i++) - { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, i); - if ((*cmd)->size && !item->size) - item->size = (*cmd)->size; - } + //for (i=0; i < g_list_length((*cmd)->private.change.items); i++) + //{ + // SmlItem *item = g_list_nth_data((*cmd)->private.change.items, i); + // if ((*cmd)->size && !item->size) + // item->size = (*cmd)->size; + //} - switch (type) { - case SML_COMMAND_TYPE_ADD: - (*cmd)->private.change.type = SML_CHANGE_ADD; - break; - case SML_COMMAND_TYPE_REPLACE: - (*cmd)->private.change.type = SML_CHANGE_REPLACE; - break; - case SML_COMMAND_TYPE_DELETE: - (*cmd)->private.change.type = SML_CHANGE_DELETE; - break; - default: - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown change type set"); - goto error; - } - - if (!(*cmd)->source) + if (!(*cmd)->source && source) { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); - if (item->source) { - (*cmd)->source = sml_location_clone(item->source, error); - if (!(*cmd)->source) - goto error; - } + (*cmd)->source = sml_location_clone(source); + g_object_unref(source); + source = NULL; } - if (!(*cmd)->target) + if (!(*cmd)->target && target) { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); - if (item->target) { - (*cmd)->target = sml_location_clone(item->target, error); - if (!(*cmd)->target) - goto error; - } + (*cmd)->target = sml_location_clone(target); + g_object_unref(target); + target = NULL; } /* Step once more */ @@ -1229,6 +1276,10 @@ *cmd = NULL; if (contenttype) smlSafeCFree(&contenttype); + if (source) + g_object_unref(source); + if (target) + g_object_unref(target); smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } @@ -1743,7 +1794,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_SOURCEREF, error)) goto error; - (*cmd)->private.results.status->sourceRef = sml_location_new_with_options(locURI, NULL, error); + (*cmd)->private.results.status->sourceRef = sml_location_new(); + sml_location_set_uri((*cmd)->private.results.status->sourceRef, locURI); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->sourceRef) goto error; @@ -1751,7 +1803,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_TARGETREF, error)) goto error; - (*cmd)->private.results.status->targetRef = sml_location_new_with_options(locURI, NULL, error); + (*cmd)->private.results.status->targetRef = sml_location_new(); + sml_location_set_uri((*cmd)->private.results.status->targetRef, locURI); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->targetRef) goto error; @@ -2610,7 +2663,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_SOURCEREF, error)) goto error; - (*status)->sourceRef = sml_location_new_with_options(locURI, NULL, error); + (*status)->sourceRef = sml_location_new(); + sml_location_set_uri((*status)->sourceRef, locURI); smlSafeCFree(&locURI); if (!(*status)->sourceRef) goto error; @@ -2618,7 +2672,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_TARGETREF, error)) goto error; - (*status)->targetRef = sml_location_new_with_options(locURI, NULL, error); + (*status)->targetRef = sml_location_new(); + sml_location_set_uri((*status)->targetRef, locURI); smlSafeCFree(&locURI); if (!(*status)->targetRef) goto error; Modified: trunk/libsyncml/sml_notification.c ============================================================================== --- trunk/libsyncml/sml_notification.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/sml_notification.c Fri Aug 7 19:52:39 2009 (r1243) @@ -27,7 +27,7 @@ #include "sml_transport.h" #include "sml_md5.h" -#include "data_sync_api/sml_location_internals.h" +#include "data_sync_api/sml_location.h" SmlNotification* smlNotificationNew (SmlNotificationVersion version, @@ -56,9 +56,8 @@ san->sessionType = SML_SESSION_TYPE_SERVER; san->manager = NULL; - san->target = sml_location_new_with_options(target, NULL, error); - if (!san->target) - goto error; + san->target = sml_location_new(); + sml_location_set_uri(san->target, target); smlTrace(TRACE_EXIT, "%s: %p", __func__, san); return san; @@ -385,16 +384,14 @@ */ smlAssert(san->manager); - GError *gerror = NULL; SmlAssembler *assm = NULL; SmlLocation *source = NULL; SmlSession *session = NULL; SmlSanAlert *alert = NULL; SmlCommand *cmd = NULL; - source = sml_location_new_with_options(san->identifier, NULL, &gerror); - if (!source) - goto error; + source = sml_location_new(); + sml_location_set_uri(source, san->identifier); session = smlSessionNew(san->sessionType, san->type, version, SML_PROTOCOL_SYNCML, san->target, source, smlManagerGetNewSessionID(san->manager), 0, error); if (!session) { @@ -419,9 +416,8 @@ alert = a->data; - SmlLocation *loc = sml_location_new_with_options(alert->serverURI, NULL, &gerror); - if (!loc) - goto error; + SmlLocation *loc = sml_location_new(); + sml_location_set_uri(loc, alert->serverURI); cmd = smlCommandNewAlert(SML_ALERT_TWO_WAY_BY_SERVER, NULL, loc, NULL, NULL, alert->contenttype, error); if (!cmd) { Modified: trunk/libsyncml/sml_session.c ============================================================================== --- trunk/libsyncml/sml_session.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/sml_session.c Fri Aug 7 19:52:39 2009 (r1243) @@ -31,7 +31,8 @@ #include "sml_transport.h" #include "objects/sml_auth.h" -#include "data_sync_api/sml_location_internals.h" +#include "data_sync_api/sml_location.h" +#include "data_sync_api/sml_change_item_internals.h" /** * @defgroup SmlSessionPrivate SyncML Session Private API @@ -227,10 +228,9 @@ SmlCommand *parent, gsize space, gsize start, - gsize complete_size, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %i, %i, %p)", __func__, session, orig_cmd, parent, space, start, complete_size, error); + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %i, %p)", __func__, session, orig_cmd, parent, space, start, error); CHECK_ERROR_REF /* This library must not send more than one item per change * command. This is compliant with all specification and only a @@ -243,13 +243,10 @@ if (!size) goto error; - // FIXME: should we add an assertion here to guarantee - // FIXME: that size and complete_size are equal - if (space < size - start) { /* We need to create a new command. But we only send as much data as space * is available */ - frag_cmd = smlCommandGetFragment(orig_cmd, start, space, complete_size, error); + frag_cmd = smlCommandGetFragment(orig_cmd, start, space, error); if (!frag_cmd) goto error; @@ -262,7 +259,7 @@ */ /* create fragmentation command */ - frag_cmd = smlCommandGetFragment(orig_cmd, start, size - start, complete_size, error); + frag_cmd = smlCommandGetFragment(orig_cmd, start, size - start, error); if (!frag_cmd) goto error; @@ -328,11 +325,9 @@ */ //smlAssert(g_list_length(cmd->private.change.items) == 1); - char *data = NULL; - gsize size = 0; - SmlItem *item = smlCommandGetNthChange(cmd, 0); - if (!smlItemGetData(item, &data, &size, error)) - goto error; + SmlChangeItem *item = smlCommandGetNthChange(cmd, 0); + smlAssert(sml_change_item_get_data(item)); + gsize size = strlen(sml_change_item_get_data(item)); /* If max obj size is not unlimited (0), and the size of the item is larger * than the max obj size, we have to return an error */ @@ -347,12 +342,12 @@ if (!session->frag_command) smlCommandSetSize(cmd, size); - smlItemSetMoreData(item, TRUE); + sml_change_item_set_missing_data(item, TRUE); gssize space = 0; if (!smlAssemblerGetSpace(session->assembler, &space, parent, cmd, error)) goto error; smlCommandSetSize(cmd, 0); - smlItemSetMoreData(item, FALSE); + sml_change_item_set_missing_data(item, FALSE); /* Check if item data fits into the current message */ if (session->frag_command || @@ -373,7 +368,7 @@ session->frag_userdata = userdata; } - if (!(cmd = _smlSessionFragmentSend(session, session->frag_command, parent, space, session->frag_size, size, error))) + if (!(cmd = _smlSessionFragmentSend(session, session->frag_command, parent, space, session->frag_size, error))) goto error; callback = _smlSessionFragmentStatus; @@ -385,7 +380,7 @@ * reference must be determined again. */ item = smlCommandGetNthChange(cmd, 0); - if (smlItemGetMoreData(item) == FALSE) { + if (sml_change_item_get_missing_data(item) == FALSE) { smlTrace(TRACE_INTERNAL, "%s: This is the last chunk", __func__); callback = session->frag_callback; @@ -712,12 +707,9 @@ } /* build the new target and publish it*/ - session->target = sml_location_new_with_options( - smlHeaderGetResponseURI(header), - sml_location_get_name(session->orgTarget), - error); - if (!session->target) - goto error; + session->target = sml_location_new(); + sml_location_set_uri(session->target, smlHeaderGetResponseURI(header)); + sml_location_set_name(session->target, sml_location_get_name(session->orgTarget)); smlSessionDispatchEvent(session, SML_SESSION_EVENT_RESPONSE_URI, NULL, NULL, NULL, NULL); smlTrace(TRACE_INTERNAL, "%s: RespURI: %s, Target: %s", __func__, VA_STRING(sml_location_get_uri(session->target)), @@ -741,8 +733,7 @@ smlTrace(TRACE_INTERNAL, "%s: update session target to header source %s", __func__, header_source); - if (!sml_location_set_uri(session->target, header_source, error)) - goto error; + sml_location_set_uri(session->target, header_source); } } smlTrace(TRACE_EXIT, "%s", __func__); @@ -1223,7 +1214,7 @@ /* Here we catch changes with moreData set */ if (smlCommandGetType(cmd) == SML_COMMAND_TYPE_ADD || smlCommandGetType(cmd) == SML_COMMAND_TYPE_REPLACE) { - SmlItem *lastItem = smlCommandGetNthChange(cmd, smlCommandGetNumChanges(cmd)-1); + SmlChangeItem *lastItem = smlCommandGetNthChange(cmd, smlCommandGetNumChanges(cmd)-1); if (session->incomingBuffer) { /* There is a command in the incoming buffer. @@ -1250,17 +1241,13 @@ * This includes the moreData flag. * This is a chunk of the previous item in the buffer. */ - char *data = NULL; - gsize size = 0; - SmlItem *item = smlCommandGetNthChange(cmd, 0); + SmlChangeItem *item = smlCommandGetNthChange(cmd, 0); if (!item) goto error; - if (!smlItemGetData(item, &data, &size, error)) - goto error; lastItem = smlCommandGetNthChange(session->incomingBuffer, smlCommandGetNumChanges(session->incomingBuffer) -1); - if (!smlItemAddData(lastItem, data, size, error)) + if (!sml_change_item_attach_fragment(lastItem, item, error)) goto error; - smlItemSetMoreData(lastItem, smlItemGetMoreData(item)); + sml_change_item_set_missing_data(lastItem, sml_change_item_get_missing_data(item)); //smlTrace(TRACE_INTERNAL, // "%s: Appended %i to buffer. Buffer size: %i. Required: %i", // __func__, size, @@ -1274,14 +1261,18 @@ /* If the last item of the command is complete * then the command must be prepared for dispatching. */ - lastItem = smlCommandGetNthChange(session->incomingBuffer, smlCommandGetNumChanges(session->incomingBuffer) -1); - if (!smlItemGetMoreData(lastItem)) { + /* FIXME: Why do we request lastItem for a second time? */ + //lastItem = smlCommandGetNthChange(session->incomingBuffer, smlCommandGetNumChanges(session->incomingBuffer) -1); + if (!sml_change_item_get_missing_data(lastItem)) { smlTrace(TRACE_INTERNAL, "%s: Command buffer complete. Dispatching.", __func__); /* check if the item size is correct */ - if (!smlItemCheck(lastItem)) { + if (sml_change_item_get_planned_size(lastItem) && + (!sml_change_item_get_data(lastItem) || + sml_change_item_get_planned_size(lastItem) != strlen(sml_change_item_get_data(lastItem)))) + { /* We have a size mismatch */ SmlStatus *reply = smlCommandNewReply(cmd, SML_ERROR_SIZE_MISMATCH, error); if (!reply) @@ -1304,7 +1295,7 @@ smlCommandUnref(session->incomingBuffer); session->incomingBuffer = NULL; } - } else if (smlItemGetMoreData(lastItem)) { + } else if (sml_change_item_get_missing_data(lastItem)) { /* There is no buffered command yet. * The new command is copied to the buffer. * This is done by reference copy and @@ -1316,6 +1307,7 @@ "First MoreData item didn't have size set"); goto error; } + smlAssert(sml_change_item_get_planned_size(lastItem)); session->incomingBuffer = cmd; smlCommandRef(cmd); @@ -1323,14 +1315,14 @@ // __func__, // xmlBufferLength(lastItem->buffer), // lastItem->size); - - char *bin = smlPrintBinary(smlItemGetContent(lastItem), smlItemGetSize(lastItem)); + const char *data = sml_change_item_get_data(lastItem); + char *bin = smlPrintBinary(data, strlen(data)); smlTrace(TRACE_INTERNAL, "%s: Content so far: %s\n", __func__, VA_STRING(bin)); smlSafeCFree(&bin); } - if (smlItemGetMoreData(lastItem) == TRUE) { + if (sml_change_item_get_missing_data(lastItem) == TRUE) { smlTrace(TRACE_INTERNAL, "%s: Got item with moreData %i", __func__, smlCommandGetMessageID(cmd)); @@ -1819,10 +1811,7 @@ smlCredUnref(session->cred); session->cred = cred; if (smlCredGetUsername(cred)) { - GError *error = NULL; - sml_location_set_name(session->source, smlCredGetUsername(cred), &error); - if (error) - g_error_free(error); + sml_location_set_name(session->source, smlCredGetUsername(cred)); } smlCredRef(session->cred); } |