From: <svn...@op...> - 2009-07-01 14:40:42
|
Author: bellmich Date: Wed Jul 1 16:40:35 2009 New Revision: 1140 URL: http://libsyncml.opensync.org/changeset/1140 Log: The complete location information is managed in one object. Even TargetParent and SourceParent are not managed by separate location objects. Modified: trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_elements_internals.h Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Wed Jul 1 15:48:22 2009 (r1139) +++ trunk/libsyncml/parser/sml_xml_assm.c Wed Jul 1 16:40:35 2009 (r1140) @@ -245,17 +245,30 @@ goto error; } - if (!sml_location_get_uri(location)) { - smlErrorSet(error, SML_ERROR_GENERIC, "No locURI set"); - goto error; - } + if (name && + (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"); + goto error; + } - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCURI, sml_location_get_uri(location), error)) - goto error; + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCURI, sml_location_get_parent_uri(location), error)) + goto error; + + } else { + if (!sml_location_get_uri(location)) { + smlErrorSet(error, SML_ERROR_GENERIC, "No location URI set"); + goto error; + } - if (sml_location_get_name(location)) { - if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCNAME, sml_location_get_name(location), error)) + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCURI, sml_location_get_uri(location), error)) goto error; + + if (sml_location_get_name(location)) { + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_LOCNAME, sml_location_get_name(location), error)) + goto error; + } } if (name) { @@ -348,14 +361,14 @@ } /* SourceParent */ - if (smlItemGetSourceParent(item)) { - if (!smlLocationAssemble(smlItemGetSourceParent(item), assm, SML_ELEMENT_SOURCE_PARENT, error)) + if (sml_location_get_parent_uri(smlItemGetSource(item))) { + if (!smlLocationAssemble(smlItemGetSource(item), assm, SML_ELEMENT_SOURCE_PARENT, error)) goto error; } /* TargetParent */ - if (smlItemGetTargetParent(item)) { - if (!smlLocationAssemble(smlItemGetTargetParent(item), assm, SML_ELEMENT_TARGET_PARENT, error)) + if (sml_location_get_parent_uri(smlItemGetTarget(item))) { + if (!smlLocationAssemble(smlItemGetTarget(item), assm, SML_ELEMENT_TARGET_PARENT, error)) goto error; } @@ -777,8 +790,17 @@ } /* SourceParent */ + if (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 (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET_PARENT, error)) + goto error; + } + /* Begin of META */ Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Wed Jul 1 15:48:22 2009 (r1139) +++ trunk/libsyncml/parser/sml_xml_parse.c Wed Jul 1 16:40:35 2009 (r1140) @@ -664,12 +664,15 @@ 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"); goto error; } - SmlItem *item = smlItemNew(0, error); + item = smlItemNew(0, error); if (!item) goto error; @@ -682,7 +685,7 @@ if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "The first element inside of an Item structure cannot be parsed."); - goto error_free_item; + goto error; } while (1) { @@ -693,36 +696,76 @@ smlErrorSet(error, SML_ERROR_GENERIC, "The element %s is not a start node in Item.", xmlTextReaderConstName(parser->reader)); - goto error_free_item; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE)) { SmlLocation *source = NULL; if (!_smlLocationParse(&source, parser, error)) - goto error_free_item; + goto error; + + if (smlItemGetSource(item)) { + /* SourceParent already parsed */ + if (!sml_location_set_parent_uri(source, sml_location_get_parent_uri(smlItemGetSource(item)), &gerror)) + goto error; + } smlItemSetSource(item, source); g_object_unref(source); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET)) { SmlLocation *target = NULL; if (!_smlLocationParse(&target, parser, error)) - goto error_free_item; + goto error; + + if (smlItemGetTarget(item)) { + /* TargetParent already parsed */ + if (!sml_location_set_parent_uri(target, sml_location_get_parent_uri(smlItemGetTarget(item)), &gerror)) + goto error; + } smlItemSetTarget(item, target); g_object_unref(target); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE_PARENT)) { SmlLocation *source = NULL; if (!_smlLocationParse(&source, parser, error)) - goto error_free_item; + goto error; - smlItemSetSourceParent(item, source); + if (smlItemGetSource(item)) { + /* Source already parsed */ + if (!sml_location_set_parent_uri(smlItemGetSource(item), sml_location_get_uri(source), &gerror)) + 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)) + goto error; + /* delete uri property */ + if (!sml_location_set_uri(source, NULL, &gerror)) + goto error; + } + g_object_unref(source); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET_PARENT)) { SmlLocation *target = NULL; if (!_smlLocationParse(&target, parser, error)) - goto error_free_item; + goto error; - smlItemSetTargetParent(item, target); + if (smlItemGetTarget(item)) { + /* Target already parsed */ + if (!sml_location_set_parent_uri(smlItemGetTarget(item), sml_location_get_uri(target), &gerror)) + 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)) + goto error; + /* delete uri property */ + if (!sml_location_set_uri(target, NULL, &gerror)) + goto error; + } + g_object_unref(target); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { switch (type) { @@ -734,32 +777,32 @@ * FIXME: Can we ignore the content? */ if (!_smlCommandMetaParse(parser, NULL, NULL, NULL, NULL, NULL, error)) - goto error_free_item; + goto error; } else { /* Some phones send the maxobjsize in the alert */ if (!_smlCommandMetaParse(parser, NULL, &(cmd->private.alert.contentType), &cmd->private.alert.anchor, NULL, &(cmd->private.alert.maxObjSize), error)) - goto error_free_item; + goto error; } break; case SML_COMMAND_TYPE_ADD: case SML_COMMAND_TYPE_DELETE: case SML_COMMAND_TYPE_REPLACE: if (!_smlCommandMetaParse(parser, NULL, &(item->contenttype), NULL, &cmd->size, NULL, error)) - goto error_free_item; + goto error; break; case SML_COMMAND_TYPE_RESULTS: case SML_COMMAND_TYPE_PUT:; /* Some phones send the type information for the devinf put * not in the put itself but in the item */ if (!_smlCommandMetaParse(parser, NULL, &(item->contenttype), NULL, NULL, NULL, error)) - goto error_free_item; + goto error; if (!item->contenttype) - goto error_free_item; + goto error; break; default: smlErrorSet(error, SML_ERROR_GENERIC, "Unknown command type"); - goto error_free_item; + goto error; } } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { /* Do nothing if the Data element is empty. @@ -772,7 +815,7 @@ 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."); - goto error_free_item; + goto error; } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA) && @@ -793,29 +836,29 @@ */ anchor = smlTryMalloc0(sizeof(SmlAnchor), error); if (!anchor) - goto error_free_item; + goto error; anchor->next = g_strdup((char *)xmlTextReaderConstValue(parser->reader)); } else { /* normal behaviour with anchor copy */ if (!_smlAnchorParse(&anchor, parser, error)) - goto error_free_item; + goto error; } item->anchor = anchor; if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "The closing Data element in an Item is missing."); - goto error_free_item; + goto error; } break; default:; char *data = NULL; unsigned int size = 0; if (!_smlXmlParserGetData(parser, &data, &size, SML_ELEMENT_DATA, error)) - goto error_free_item; + goto error; if (!smlItemAddData(item, data, size, error)) { smlSafeCFree(&data); - goto error_free_item; + goto error; } smlSafeCFree(&data); @@ -824,41 +867,42 @@ } 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"); - goto error_free_item; + goto error; } item->moreData = TRUE; parser->gotMoreData = TRUE; if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes2"); - goto error_free_item; + 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"); - goto error_free_item; + goto error; } } continue; } else { smlErrorSet(error, SML_ERROR_GENERIC, "The element Item does not support the child element %s.", xmlTextReaderConstName(parser->reader)); - goto error_free_item; + goto error; } if (!_smlXmlParserStep(parser)) { smlErrorSet(error, SML_ERROR_GENERIC, "The next element in an Item structure is missing."); - goto error_free_item; + goto error; } } smlTrace(TRACE_EXIT, "%s", __func__); return item; -error_free_item: - smlItemUnref(item); error: + if (item) + smlItemUnref(item); + GERROR_TO_SML_ERROR(gerror,error) smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); return NULL; } Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Wed Jul 1 15:48:22 2009 (r1139) +++ trunk/libsyncml/sml_elements.c Wed Jul 1 16:40:35 2009 (r1140) @@ -157,12 +157,6 @@ if (item->target) g_object_unref(item->target); - if (item->sourceParent) - g_object_unref(item->sourceParent); - - if (item->targetParent) - g_object_unref(item->targetParent); - if (item->anchor) smlAnchorFree(item->anchor); @@ -316,38 +310,6 @@ return item->target; } -void smlItemSetSourceParent(SmlItem *item, SmlLocation *sourceParent) -{ - smlAssert(item); - smlAssert(sourceParent); - - item->sourceParent = sourceParent; - g_object_ref(sourceParent); -} - -SmlLocation *smlItemGetSourceParent(SmlItem *item) -{ - smlAssert(item); - - return item->sourceParent; -} - -void smlItemSetTargetParent(SmlItem *item, SmlLocation *targetParent) -{ - smlAssert(item); - smlAssert(targetParent); - - item->targetParent = targetParent; - g_object_ref(targetParent); -} - -SmlLocation *smlItemGetTargetParent(SmlItem *item) -{ - smlAssert(item); - - return item->targetParent; -} - void smlItemSetRaw(SmlItem *item, SmlBool raw) { smlAssert(item); Modified: trunk/libsyncml/sml_elements.h ============================================================================== --- trunk/libsyncml/sml_elements.h Wed Jul 1 15:48:22 2009 (r1139) +++ trunk/libsyncml/sml_elements.h Wed Jul 1 16:40:35 2009 (r1140) @@ -54,10 +54,6 @@ SmlLocation *smlItemGetSource(SmlItem *item); void smlItemSetTarget(SmlItem *item, SmlLocation *target); SmlLocation *smlItemGetTarget(SmlItem *item); -void smlItemSetSourceParent(SmlItem *item, SmlLocation *sourceParent); -SmlLocation *smlItemGetSourceParent(SmlItem *item); -void smlItemSetTargetParent(SmlItem *item, SmlLocation *targeParent); -SmlLocation *smlItemGetTargetParent(SmlItem *item); void smlItemSetRaw(SmlItem *item, SmlBool raw); void smlHeaderFree(SmlHeader *header); Modified: trunk/libsyncml/sml_elements_internals.h ============================================================================== --- trunk/libsyncml/sml_elements_internals.h Wed Jul 1 15:48:22 2009 (r1139) +++ trunk/libsyncml/sml_elements_internals.h Wed Jul 1 16:40:35 2009 (r1140) @@ -42,8 +42,6 @@ SmlLocation *source; SmlLocation *target; - SmlLocation *sourceParent; - SmlLocation *targetParent; SmlAnchor *anchor; xmlBuffer *buffer; |