From: <dg...@su...> - 2009-02-17 11:18:14
|
Author: bellmich Date: Tue Feb 17 12:15:52 2009 New Revision: 930 URL: http://libsyncml.opensync.org/changeset/930 Log: added support for parsing and assembling SourceParent and SourceTarget (replaced several useless error messages by more expressive messages) Modified: trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_defines.h 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 Tue Feb 17 12:14:22 2009 (r929) +++ trunk/libsyncml/parser/sml_xml_assm.c Tue Feb 17 12:15:52 2009 (r930) @@ -322,8 +322,16 @@ } /* SourceParent */ + if (smlItemGetSourceParent(item)) { + if (!smlLocationAssemble(smlItemGetSourceParent(item), assm, SML_ELEMENT_SOURCE_PARENT, error)) + goto error; + } /* TargetParent */ + if (smlItemGetTargetParent(item)) { + if (!smlLocationAssemble(smlItemGetTargetParent(item), assm, SML_ELEMENT_TARGET_PARENT, error)) + goto error; + } /* Data */ if (smlItemHasData(item)) { Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Tue Feb 17 12:14:22 2009 (r929) +++ trunk/libsyncml/parser/sml_xml_parse.c Tue Feb 17 12:15:52 2009 (r930) @@ -197,7 +197,7 @@ while (1) { if (!_smlXmlParserStepData(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + smlErrorSet(error, SML_ERROR_GENERIC, "There is a missing node during the data parsing of %s.", name); goto error_free_writer; } @@ -378,9 +378,15 @@ } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE) && \ xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { break; + } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE_PARENT) && \ + xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { + break; + } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET_PARENT) && \ + xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { + break; } else if (xmlTextReaderNodeType(parser->reader) != XML_NODE_START) { smlErrorSet(error, SML_ERROR_GENERIC, - "The element %s is not a start node in locations (Target or Source).", + "The element %s is not a start node in locations (Target, Source, SourceParent or TargetParent).", xmlTextReaderConstName(parser->reader)); goto error_free_location; } @@ -640,7 +646,7 @@ } if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + smlErrorSet(error, SML_ERROR_GENERIC, "The first element inside of an Item structure cannot be parsed."); goto error_free_item; } @@ -669,6 +675,20 @@ smlItemSetTarget(item, target); smlLocationUnref(target); + } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE_PARENT)) { + SmlLocation *source = NULL; + if (!_smlLocationParse(&source, parser, error)) + goto error_free_item; + + smlItemSetSourceParent(item, source); + smlLocationUnref(source); + } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET_PARENT)) { + SmlLocation *target = NULL; + if (!_smlLocationParse(&target, parser, error)) + goto error_free_item; + + smlItemSetTargetParent(item, target); + smlLocationUnref(target); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { switch (type) { case SML_COMMAND_TYPE_ALERT: @@ -710,7 +730,7 @@ switch (type) { case SML_COMMAND_TYPE_ALERT: if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + smlErrorSet(error, SML_ERROR_GENERIC, "The next element after the starting Data element in an Item is missing."); goto error_free_item; } @@ -729,7 +749,7 @@ item->anchor = anchor; if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + smlErrorSet(error, SML_ERROR_GENERIC, "The closing Data element in an Item is missing."); goto error_free_item; } break; @@ -768,12 +788,12 @@ } continue; } else { - smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); + smlErrorSet(error, SML_ERROR_GENERIC, "The element Item does not support the child element %s.", xmlTextReaderConstName(parser->reader)); goto error_free_item; } if (!_smlXmlParserStep(parser)) { - smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); + smlErrorSet(error, SML_ERROR_GENERIC, "The next element in an Item structure is missing."); goto error_free_item; } } Modified: trunk/libsyncml/sml_defines.h ============================================================================== --- trunk/libsyncml/sml_defines.h Tue Feb 17 12:14:22 2009 (r929) +++ trunk/libsyncml/sml_defines.h Tue Feb 17 12:15:52 2009 (r930) @@ -39,6 +39,8 @@ #define SML_ELEMENT_SESSIONID "SessionID" #define SML_ELEMENT_TARGET "Target" #define SML_ELEMENT_SOURCE "Source" +#define SML_ELEMENT_SOURCE_PARENT "SourceParent" +#define SML_ELEMENT_TARGET_PARENT "TargetParent" #define SML_ELEMENT_LOCURI "LocURI" #define SML_ELEMENT_LOCNAME "LocName" #define SML_ELEMENT_RESPURI "RespURI" Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Tue Feb 17 12:14:22 2009 (r929) +++ trunk/libsyncml/sml_elements.c Tue Feb 17 12:15:52 2009 (r930) @@ -386,6 +386,12 @@ if (item->target) smlLocationUnref(item->target); + if (item->sourceParent) + smlLocationUnref(item->sourceParent); + + if (item->targetParent) + smlLocationUnref(item->targetParent); + if (item->anchor) smlAnchorFree(item->anchor); @@ -538,6 +544,38 @@ return item->target; } +void smlItemSetSourceParent(SmlItem *item, SmlLocation *sourceParent) +{ + smlAssert(item); + smlAssert(sourceParent); + + item->sourceParent = sourceParent; + smlLocationRef(sourceParent); +} + +SmlLocation *smlItemGetSourceParent(SmlItem *item) +{ + smlAssert(item); + + return item->sourceParent; +} + +void smlItemSetTargetParent(SmlItem *item, SmlLocation *targetParent) +{ + smlAssert(item); + smlAssert(targetParent); + + item->targetParent = targetParent; + smlLocationRef(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 Tue Feb 17 12:14:22 2009 (r929) +++ trunk/libsyncml/sml_elements.h Tue Feb 17 12:15:52 2009 (r930) @@ -66,6 +66,10 @@ 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 Tue Feb 17 12:14:22 2009 (r929) +++ trunk/libsyncml/sml_elements_internals.h Tue Feb 17 12:15:52 2009 (r930) @@ -48,6 +48,8 @@ SmlLocation *source; SmlLocation *target; + SmlLocation *sourceParent; + SmlLocation *targetParent; SmlAnchor *anchor; xmlBuffer *buffer; |