Changeset 120

Show
Ignore:
Timestamp:
04/12/06 16:18:50 (3 years ago)
Author:
abauer
Message:

Finished most parts of large object handling

Added test cases for large object handling

Fixed several bugs

Added bug workarounds for certain phones

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/development-branch/libsyncml/objects/sml_auth.c

    r115 r120  
    7676                                 
    7777                                char **arr = g_strsplit(buffer, ":", 2); 
     78                                g_free(buffer); 
    7879                                 
    7980                                smlTrace(TRACE_INTERNAL, "Username \"%s\", Password \"%s\"", arr[0], arr[1]); 
     
    103104                goto error; 
    104105         
    105         if (!smlSessionSendReply(session, reply, &error)) 
    106                 goto error; 
     106        if (!smlSessionSendReply(session, reply, &error)) { 
     107                smlStatusUnref(reply); 
     108                goto error; 
     109        } 
     110         
     111        smlStatusUnref(reply); 
    107112         
    108113        smlTrace(TRACE_EXIT, "%s", __func__); 
  • branches/development-branch/libsyncml/objects/sml_devinf_obj.c

    r118 r120  
    211211         
    212212        if (agent->recvDevInf) { 
    213                 SmlDevInf *devinf = smlDevInfParse(agent->recvDevInf->private.access.item->data, agent->recvDevInf->private.access.item->size, error); 
     213                char *data = NULL; 
     214                unsigned int size = 0; 
     215                if (!smlItemGetData(agent->recvDevInf->private.access.item, &data, &size, error)) 
     216                        goto error; 
     217                 
     218                SmlDevInf *devinf = smlDevInfParse(data, size, error); 
    214219                if (!devinf) 
    215220                        goto error; 
  • branches/development-branch/libsyncml/objects/sml_ds_server.c

    r118 r120  
    323323                goto error; 
    324324         
     325        if (!smlManagerObjectRegister(server->manager, SML_COMMAND_TYPE_SYNC, session, server->location, NULL, smlDsSessionRecvSync, smlDsSessionRecvChange, dsession, error)) 
     326                goto error_free_dsession; 
     327         
     328        if (!smlManagerObjectRegister(server->manager, SML_COMMAND_TYPE_MAP, session, server->location, NULL, smlDsSessionRecvMap, NULL, dsession, error)) 
     329                goto error_free_dsession; 
     330         
     331        if (!smlManagerObjectRegister(server->manager, SML_COMMAND_TYPE_ALERT, session, server->location, NULL, smlDsSessionRecvAlert, NULL, dsession, error)) 
     332                goto error_free_dsession; 
     333         
    325334        if (!smlDsSessionSendAlert(dsession, type, last, next, callback, userdata, error)) 
    326                 goto error_free_session; 
     335                goto error_free_dsession; 
    327336         
    328337        smlTrace(TRACE_EXIT, "%s", __func__); 
    329338        return dsession; 
    330339 
    331 error_free_session: 
     340error_free_dsession: 
    332341        g_free(dsession); 
    333342error: 
     
    504513                                 * uid (if we are a client for example). If it is not given we use the 
    505514                                 * source uri. This has then to be translated by the sync engine of course */ 
    506                                 if (!dsession->changesCallback(dsession, cmd->private.change.type, item->target ? item->target->locURI : item->source->locURI, item->data, item->size, item->contenttype, dsession->changesCallbackUserdata, &error)) 
     515                                 
     516                                char *data = NULL; 
     517                                unsigned int size = 0; 
     518                                if (!smlItemGetData(item, &data, &size, &error)) 
     519                                        goto error; 
     520                                  
     521                                if (!dsession->changesCallback(dsession, cmd->private.change.type, item->target ? item->target->locURI : item->source->locURI, data, size, item->contenttype, dsession->changesCallbackUserdata, &error)) 
    507522                                        goto error; 
    508523                                                 
  • branches/development-branch/libsyncml/parser/sml_wbxml.c

    r116 r120  
    8181         
    8282        char *buffer = NULL; 
    83         if (!smlWbxmlConvertFrom(NULL, data, size, &buffer, error)) 
     83        WBXMLConvWBXML2XMLParams params = {WBXML_ENCODER_XML_GEN_COMPACT, WBXML_LANG_UNKNOWN, 0, FALSE}; 
     84        if (!smlWbxmlConvertFrom(&params, data, size, &buffer, error)) 
    8485                goto error; 
    8586        unsigned int buffer_size = strlen(buffer); 
  • branches/development-branch/libsyncml/parser/sml_xml_assm.c

    r116 r120  
    8181} 
    8282 
    83 SmlBool _smlXmlAssemblerAddData(SmlXmlAssembler *assm, const char *name, const char *value, SmlBool raw, SmlError **error) 
     83static SmlBool _smlXmlAssemblerAddData(SmlXmlAssembler *assm, const char *name, const char *value, unsigned int size, SmlBool raw, SmlError **error) 
    8484{ 
    8585        int rc = 0; 
     
    8888         
    8989        if (raw) 
    90                 rc = xmlTextWriterWriteRaw(assm->writer, (xmlChar *)value); 
     90                rc = xmlTextWriterWriteRawLen(assm->writer, (xmlChar *)value, size); 
    9191        else 
    92                 rc = xmlTextWriterWriteCDATA(assm->writer, (xmlChar *)value); 
     92                rc = xmlTextWriterWriteFormatCDATA(assm->writer, "%*s", size, (xmlChar *)value); 
    9393        if (rc < 0) { 
    9494                smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add data"); 
     
    102102} 
    103103 
    104 SmlBool _smlXmlAssemblerAddID(SmlXmlAssembler *assm, const char *name, unsigned int id, SmlError **error) 
     104static SmlBool _smlXmlAssemblerAddID(SmlXmlAssembler *assm, const char *name, unsigned int id, SmlError **error) 
    105105{ 
    106106        int rc = xmlTextWriterWriteFormatElement(assm->writer, (xmlChar *)name, "%i", id); 
     
    112112} 
    113113 
     114static SmlBool _smlXmlAssemblerAddIDNS(SmlXmlAssembler *assm, const char *prefix, const char *name, const char *uri, unsigned int id, SmlError **error) 
     115{ 
     116        int rc = xmlTextWriterWriteFormatElementNS(assm->writer, (xmlChar *)prefix, (xmlChar *)name, (xmlChar *)uri, "%i", id); 
     117        if (rc < 0) { 
     118                smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add id"); 
     119                return FALSE; 
     120        } 
     121        return TRUE; 
     122} 
     123 
    114124SmlBool smlLocationAssemble(SmlLocation *location, SmlXmlAssembler *assm, const char *name, SmlError **error) 
    115125{ 
     
    184194} 
    185195 
    186 SmlBool smlItemAssemble(SmlItem *item, SmlXmlAssembler *assm, SmlBool raw, SmlError **error) 
    187 { 
    188         smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, item, assm, raw, error); 
     196SmlBool smlItemAssemble(SmlItem *item, SmlXmlAssembler *assm, SmlBool raw, unsigned int complete_size, SmlError **error) 
     197{ 
     198        smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %i, %p)", __func__, item, assm, raw, complete_size, error); 
    189199        smlAssert(assm); 
    190200        smlAssert(item); 
    191                  
     201         
     202        if (assm->moreDataSet) { 
     203                smlErrorSet(error, SML_ERROR_GENERIC, "Trying to start a new item while last item had more data"); 
     204                goto error; 
     205        } 
     206         
    192207        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) 
    193208                goto error; 
    194209         
    195         if (item->source) { 
    196                 if (!smlLocationAssemble(item->source, assm, SML_ELEMENT_SOURCE, error)) 
    197                         goto error; 
    198         } 
    199          
    200         if (item->target) { 
    201                 if (!smlLocationAssemble(item->target, assm, SML_ELEMENT_TARGET, error)) 
    202                         goto error; 
    203         } 
    204          
    205         if (item->data) { 
    206                 if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, item->data, raw, error)) 
    207                         goto error; 
     210        if (smlItemGetSource(item)) { 
     211                if (!smlLocationAssemble(smlItemGetSource(item), assm, SML_ELEMENT_SOURCE, error)) 
     212                        goto error; 
     213        } 
     214         
     215        if (smlItemGetTarget(item)) { 
     216                if (!smlLocationAssemble(smlItemGetTarget(item), assm, SML_ELEMENT_TARGET, error)) 
     217                        goto error; 
     218        } 
     219         
     220        //Meta 
     221        if (complete_size) { 
     222                if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
     223                        goto error; 
     224                         
     225                if (!_smlXmlAssemblerAddIDNS(assm, NULL, SML_ELEMENT_SIZE, SML_NAMESPACE_METINF, complete_size, error)) 
     226                        goto error; 
     227         
     228                //META 
     229                if (!_smlXmlAssemblerEndNode(assm, error)) 
     230                        goto error; 
     231        } 
     232         
     233        if (smlItemHasData(item)) { 
     234                if (item->disabled) { 
     235                        if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, "", 0, raw, error)) 
     236                                goto error; 
     237                } else { 
     238                        char *data = NULL; 
     239                        unsigned int size = 0; 
     240                        if (!smlItemGetData(item, &data, &size, error)) 
     241                                goto error; 
     242                         
     243                        if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, raw, error)) 
     244                                goto error; 
     245                } 
     246        } 
     247         
     248        if (item->moreData) { 
     249                if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_MOREDATA, "", error)) 
     250                        goto error; 
     251                 
     252                assm->moreDataSet = TRUE; 
    208253        } 
    209254         
     
    257302                goto error; 
    258303         
    259         if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, cred->data, TRUE, error)) 
     304        if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, cred->data, strlen(cred->data), TRUE, error)) 
    260305                goto error; 
    261306         
     
    302347                goto error; 
    303348         
    304         if (!smlItemAssemble(change->private.access.item, assm, FALSE, error)) 
     349        if (!smlItemAssemble(change->private.access.item, assm, FALSE, 0, error)) 
    305350                goto error; 
    306351         
     
    340385                goto error; 
    341386         
     387        /*if (change->size) { 
     388                if (!_smlXmlAssemblerAddID(assm, SML_ELEMENT_SIZE, change->size, error)) 
     389                        goto error; 
     390        }*/ 
     391 
    342392        //META 
    343393        if (!_smlXmlAssemblerEndNode(assm, error)) 
     
    350400        } 
    351401         
    352         if (!smlItemAssemble(change->private.change.item, assm, FALSE, error)) 
     402        if (!smlItemAssemble(change->private.change.item, assm, FALSE, change->size, error)) 
    353403                goto error; 
    354404         
     
    371421                goto error; 
    372422        } 
     423         
     424         
     425        if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) 
     426                goto error; 
     427         
     428        if (!_smlXmlAssemblerAddIDNS(assm, NULL, SML_ELEMENT_MAXOBJSIZE, SML_NAMESPACE_METINF, 786432, error)) 
     429                goto error; 
     430         
     431        //META 
     432        if (!_smlXmlAssemblerEndNode(assm, error)) 
     433                goto error; 
    373434         
    374435        if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET, error)) 
     
    834895                goto error; 
    835896        } 
    836                  
     897         
     898        assm->moreDataSet = FALSE; 
     899         
    837900        xmlBufferFree(cmd->buffer); 
    838901        g_free(cmd); 
     
    10101073        switch (status->type) { 
    10111074                case SML_COMMAND_TYPE_ALERT: 
    1012                         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) 
    1013                                 goto error; 
    1014                          
    1015                         if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_DATA, error)) 
    1016                                 goto error; 
    1017                          
    1018                         if (!smlAnchorAssemble(status->anchor, assm, error)) 
    1019                                 goto error; 
    1020                          
    1021                         //DATA 
    1022                         if (!_smlXmlAssemblerEndNode(assm, error)) 
    1023                                 goto error; 
     1075                        if (status->anchor) { 
     1076                                if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) 
     1077                                        goto error; 
    10241078                                 
    1025                         //ITEM 
    1026                         if (!_smlXmlAssemblerEndNode(assm, error)) 
    1027                                 goto error; 
     1079                                if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_DATA, error)) 
     1080                                        goto error; 
     1081                                 
     1082                                if (!smlAnchorAssemble(status->anchor, assm, error)) 
     1083                                        goto error; 
     1084                                 
     1085                                //DATA 
     1086                                if (!_smlXmlAssemblerEndNode(assm, error)) 
     1087                                        goto error; 
     1088                                         
     1089                                //ITEM 
     1090                                if (!_smlXmlAssemblerEndNode(assm, error)) 
     1091                                        goto error; 
     1092                        } 
    10281093                        break; 
    10291094                case SML_COMMAND_TYPE_HEADER: 
     
    10761141                                goto error; 
    10771142                         
    1078                         if (!smlItemAssemble(status->item, assm, TRUE, error)) 
     1143                        if (!smlItemAssemble(status->item, assm, TRUE, 0, error)) 
    10791144                                goto error; 
    10801145                        break; 
     
    12061271        flush_list(assm->commands); 
    12071272        assm->commands = NULL; 
     1273         
     1274        assm->moreDataSet = FALSE; 
    12081275         
    12091276        smlTrace(TRACE_EXIT, "%s: %i", __func__, newid); 
     
    15261593} 
    15271594 
    1528 SmlBool smlXmlAssemblerNextCmdRef(SmlXmlAssembler *assm, unsigned int *cmdRef, unsigned int *msgRef, SmlError **error
    1529 { 
    1530         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, assm, cmdRef, msgRef, error); 
     1595SmlBool smlXmlAssemblerNextCmdRef(SmlXmlAssembler *assm, unsigned int *cmdRef, unsigned int *msgRef
     1596{ 
     1597        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmdRef, msgRef); 
    15311598        smlAssert(assm); 
    15321599        smlAssert(cmdRef); 
  • branches/development-branch/libsyncml/parser/sml_xml_assm_internals.h

    r101 r120  
    6969        unsigned int reserved_statuses; 
    7070        unsigned int added_statuses; 
     71         
     72        SmlBool moreDataSet; 
    7173}; 
    7274 
  • branches/development-branch/libsyncml/parser/sml_xml_parse.c

    <
    r116 r120  
    2929#include "sml_xml_parse_internals.h" 
    3030 
     31#define BUFFER_SIZE 500 
     32 
    3133/** 
    3234 * @defgroup Parser SyncML XML Parser 
     
    3739/*@{*/ 
    3840 
    39 SmlBool _smlXmlParserStep(SmlXmlParser *parser) 
     41static SmlBool _smlXmlParserStep(SmlXmlParser *parser) 
    4042{ 
    4143        SmlBool ret = FALSE; 
    4244        do { 
    43                 ret = xmlTextReaderRead(parser->reader) == 1 ? TRUE : FALSE; 
     45                ret = (xmlTextReaderRead(parser->reader) == 1) ? TRUE : FALSE; 
    4446        } while (ret && (xmlTextReaderNodeType(parser->reader) == XML_READER_TYPE_DOCUMENT_TYPE || \ 
    4547                xmlTextReaderNodeType(parser->reader) == XML_READER_TYPE_WHITESPACE || \ 
     
    4951} 
    5052 
    51 SmlBool _smlXmlParserExpectNode(SmlXmlParser *parser, int type, SmlBool empty, const char *name, SmlError **error) 
     53static SmlBool _smlXmlParserExpectNode(SmlXmlParser *parser, int type, SmlBool empty, const char *name, SmlError **error) 
    5254{ 
    5355        if (!_smlXmlParserStep(parser)) { 
     
    9193} 
    9294 
    93 SmlBool _smlXmlParserGetID(SmlXmlParser *parser, unsigned int *id, const char *name, SmlError **error) 
     95static SmlBool _smlXmlParserGetID(SmlXmlParser *parser, unsigned int *id, const char *name, SmlError **error) 
    9496{ 
    9597        smlAssert(parser); 
     
    115117} 
    116118 
    117 SmlBool _smlXmlParserGetString(SmlXmlParser *parser, char **string, const char *name, SmlError **error) 
     119static SmlBool _smlXmlParserGetString(SmlXmlParser *parser, char **string, const char *name, SmlError **error) 
    118120{ 
    119121        smlAssert(parser); 
     
    150152} 
    151153 
    152 SmlBool _smlXmlParserGetData(SmlXmlParser *parser, char **string, unsigned int *size, const char *name, SmlError **error) 
     154static SmlBool _smlXmlParserGetData(SmlXmlParser *parser, char **string, unsigned int *size, const char *name, SmlError **error) 
    153155{ 
    154156        smlAssert(parser); 
     
    161163        } 
    162164         
    163         xmlBuffer *buffer = xmlBufferCreate(); 
     165         
     166        xmlBuffer *buffer = xmlBufferCreateSize(BUFFER_SIZE); 
    164167        if (!buffer) { 
    165168                smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new buffer"); 
     
    221224        *string = (char *)xmlBufferContent(buffer); 
    222225        if (size) 
    223                 *size = xmlBufferLength(buffer); 
    224          
    225         (*string)[*size - 1] = 0; 
     226                *size = xmlBufferLength(buffer) - 1; 
    226227         
    227228        //Hack to avoid memory copy 
     
    313314 
    314315 
    315 SmlBool _smlLocationParse(SmlLocation **location, SmlXmlParser *parser, SmlError **error) 
     316static SmlBool _smlLocationParse(SmlLocation **location, SmlXmlParser *parser, SmlError **error) 
    316317{ 
    317318        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, location, parser, error); 
     
    375376} 
    376377 
    377 SmlBool _smlAnchorParse(SmlAnchor **anchor, SmlXmlParser *parser, SmlError **error) 
     378static SmlBool _smlAnchorParse(SmlAnchor **anchor, SmlXmlParser *parser, SmlError **error) 
    378379{ 
    379380        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, anchor, parser, error); 
     
    433434} 
    434435 
    435 SmlBool _smlCommandMetaParse(SmlXmlParser *parser, char **format, char **type, SmlAnchor **anchor, SmlError **error) 
    436 { 
    437         smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p)", __func__, parser, format, type, anchor, error); 
     436static SmlBool _smlCommandMetaParse(SmlXmlParser *parser, char **format, char **type, SmlAnchor **anchor, unsigned int *size, SmlError **error) 
     437{ 
     438        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p, %p)", __func__, parser, format, type, anchor, size, error); 
    438439        smlAssert(parser); 
    439440                 
     
    461462                        if (!_smlXmlParserGetString(parser, format, SML_ELEMENT_FORMAT, error)) 
    462463                                goto error; 
     464                } else if (size && !strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SIZE)) { 
     465                        if (!_smlXmlParserGetID(parser, size, SML_ELEMENT_SIZE, error)) 
     466                                goto error; 
    463467                } else { 
    464468                        smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node: %s", xmlTextReaderConstName(parser->reader)); 
     
    481485} 
    482486 
    483 SmlBool _smlCommandSyncMetaParse(SmlXmlParser *parser, unsigned int *maxobjsize, SmlError **error) 
     487static SmlBool _smlCommandSyncMetaParse(SmlXmlParser *parser, unsigned int *maxobjsize, SmlError **error) 
    484488{ 
    485489        smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, maxobjsize, error); 
     
    519523} 
    520524 
    521 SmlItem *_smlItemParse(SmlXmlParser *parser, SmlCommand *cmd, SmlCommandType type, SmlError **error) 
     525static SmlItem *_smlItemParse(SmlXmlParser *parser, SmlCommand *cmd, SmlCommandType type, SmlError **error) 
    522526{ 
    523527        smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, parser, cmd, type, error); 
    524528        smlAssert(parser); 
    525529         
    526         SmlItem *item = smlTryMalloc0(sizeof(SmlItem), error); 
     530        if (parser->gotMoreData) { 
     531                smlErrorSet(error, SML_ERROR_GENERIC, "Last item already had more data set"); 
     532                goto error; 
     533        } 
     534         
     535        SmlItem *item = smlItemNew(0, error); 
    527536        if (!item) 
    528537                goto error; 
    529538         
     539        if (!_smlXmlParserStep(parser)) { 
     540                smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); 
     541                goto error_free_item; 
     542        } 
     543         
    530544        while (1) { 
    531                 if (!_smlXmlParserStep(parser)) { 
    532                         smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); 
    533                         goto error_free_item; 
    534                 } 
    535                  
    536545                if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM) && \ 
    537546                xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { 
     
    543552                 
    544553                if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE)) { 
    545                         if (!_smlLocationParse(&item->source, parser, error)) 
     554                        SmlLocation *source = NULL; 
     555                        if (!_smlLocationParse(&source, parser, error)) 
    546556                                goto error_free_item; 
     557                         
     558                        smlItemSetSource(item, source); 
     559                        smlLocationUnref(source); 
    547560                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET)) { 
    548                         if (!_smlLocationParse(&item->target, parser, error)) 
     561                        SmlLocation *target = NULL; 
     562                        if (!_smlLocationParse(&target, parser, error)) 
    549563                                goto error_free_item; 
     564                         
     565                        smlItemSetTarget(item, target); 
     566                        smlLocationUnref(target); 
    550567                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { 
    551568                        switch (type) { 
    552569                                case SML_COMMAND_TYPE_ALERT: 
    553                                         if (!_smlCommandMetaParse(parser, NULL, NULL, &cmd->private.alert.anchor, error)) 
     570                                        if (!_smlCommandMetaParse(parser, NULL, NULL, &cmd->private.alert.anchor, NULL, error)) 
     571                                                goto error_free_item; 
     572                                        break; 
     573                                case SML_COMMAND_TYPE_ADD: 
     574                                case SML_COMMAND_TYPE_REPLACE: 
     575                                        if (!_smlCommandMetaParse(parser, NULL, NULL, NULL, &cmd->size, error)) 
    554576                                                goto error_free_item; 
    555577                                        break; 
     
    566588                                        } 
    567589                                         
    568                                         if (!_smlAnchorParse(&(item->anchor), parser, error)) 
     590                                        SmlAnchor *anchor = NULL; 
     591                                        if (!_smlAnchorParse(&anchor, parser, error)) 
    569592                                                goto error_free_item; 
     593                                         
     594                                        item->anchor = anchor; 
    570595                                         
    571596                                        if (!_smlXmlParserStep(parser)) { 
     
    574599                                        } 
    575600                                        break; 
    576                                 default: 
    577                                         if (!_smlXmlParserGetData(parser, &item->data, &item->size, SML_ELEMENT_DATA, error)) 
     601                                default:; 
     602                                        char *data = NULL; 
     603                                        unsigned int size = 0; 
     604                                        if (!_smlXmlParserGetData(parser, &data, &size, SML_ELEMENT_DATA, error)) 
    578605                                                goto error_free_item; 
     606                                         
     607                                        if (!smlItemAddData(item, data, size, error)) { 
     608                                                g_free(data); 
     609                                                goto error_free_item; 
     610                                        } 
     611                                         
     612                                        g_free(data); 
    579613                        } 
     614                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MOREDATA)) { 
     615                        if (parser->version == SML_VERSION_10) { 
     616                                smlErrorSet(error, SML_ERROR_GENERIC, "SyncML 1.0 does not allow MoreData"); 
     617                                goto error_free_item; 
     618                        } 
     619                         
     620                        item->moreData = TRUE; 
     621                        parser->gotMoreData = TRUE; 
     622                        if (!_smlXmlParserStep(parser)) { 
     623                                smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes2"); 
     624                                goto error_free_item; 
     625                        } 
     626                         
     627                        if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_MOREDATA) && \ 
     628                                xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { 
     629                                if (!_smlXmlParserStep(parser)) { 
     630                                        smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes3"); 
     631                                        goto error_free_item; 
     632                                } 
     633                        } 
     634                        continue; 
    580635                } else { 
    581636                        smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); 
    582637                        goto error_free_item; 
    583638                } 
     639                 
     640                if (!_smlXmlParserStep(parser)) { 
     641                        smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); 
     642                        goto error_free_item; 
     643                } 
    584644        } 
    585645         
     
    588648 
    589649error_free_item: 
    590         smlItemFree(item); 
     650        smlItemUnref(item); 
    591651error: 
    592652        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
     
    594654} 
    595655 
    596 SmlCred *_smlCredParse(SmlXmlParser *parser, SmlError **error) 
     656static SmlCred *_smlCredParse(SmlXmlParser *parser, SmlError **error) 
    597657{ 
    598658        smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); 
     
    620680                 
    621681                if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { 
    622                         if (!_smlCommandMetaParse(parser, &format, &type, NULL, error)) 
     682                        if (!_smlCommandMetaParse(parser, &format, &type, NULL, NULL, error)) 
    623683                                goto error_free_cred; 
    624684                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { 
     
    677737        smlAssert(name); 
    678738        char *contenttype = NULL; 
    679         SmlItem *item = NULL; 
    680739         
    681740        *cmd = smlCommandNew(type, error); 
     
    702761                                goto error_free_cmd; 
    703762                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM)) { 
    704                         item = _smlItemParse(parser, *cmd, SML_COMMAND_TYPE_SYNC, error); 
    705                         if (!item) 
     763                        (*cmd)->private.change.item = _smlItemParse(parser, *cmd, type, error); 
     764                        if (!(*cmd)->private.change.item) 
    706765                                goto error_free_cmd; 
    707766                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { 
    708                         if (!_smlCommandMetaParse(parser, NULL, &contenttype, NULL, error)) 
     767                        if (!_smlCommandMetaParse(parser, NULL, &contenttype, NULL, &(*cmd)->size, error)) 
    709768                                goto error_free_cmd; 
    710769                } else { 
     
    719778        } 
    720779         
    721         if (!item) { 
     780        if (!(*cmd)->private.change.item) { 
    722781                smlErrorSet(error, SML_ERROR_GENERIC, "No item set"); 
    723782                goto error_free_cmd; 
     
    725784         
    726785        if (contenttype) { 
    727                 item->contenttype = smlContentTypeFromString(contenttype, error); 
    728                 if (!item->contenttype) 
    729                         goto error_free_cmd; 
    730         } 
    731          
    732         (*cmd)->private.change.item = item; 
     786                (*cmd)->private.change.item->contenttype = smlContentTypeFromString(contenttype, error); 
     787                if (!(*cmd)->private.change.item->contenttype) 
     788                        goto error_free_cmd; 
     789        } 
     790         
     791        if ((*cmd)->size) 
     792                (*cmd)->private.change.item->size = (*cmd)->size; 
    733793         
    734794        switch (type) { 
     
    747807        } 
    748808         
    749         if (item->source) { 
    750                 (*cmd)->source = smlLocationClone(item->source, error); 
     809        if ((*cmd)->private.change.item->source) { 
     810                (*cmd)->source = smlLocationClone((*cmd)->private.change.item->source, error); 
    751811                if (!(*cmd)->source) 
    752812                        goto error_free_cmd; 
    753813        } 
    754814         
    755         if (item->target) { 
    756                 (*cmd)->target = smlLocationClone(item->target, error); 
     815        if ((*cmd)->private.change.item->target) { 
     816                (*cmd)->target = smlLocationClone((*cmd)->private.change.item->target, error); 
    757817                if (!(*cmd)->target) 
    758818                        goto error_free_cmd; 
     
    776836        if (contenttype) 
    777837                g_free(contenttype); 
    778         if (item) 
    779                 smlItemFree(item); 
     838        *cmd = NULL; 
    780839        smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 
    781840        return FALSE; 
     
    868927                        item->source = NULL; 
    869928                         
    870                         smlItemFree(item); 
     929                        smlItemUnref(item); 
    871930                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { 
    872931                        if (!_smlXmlParserGetID(parser, &((*cmd)->private.alert.type), SML_ELEMENT_DATA, error)) 
     
    9641023} 
    9651024 
    966 SmlMapItem *_smlMapItemParse(SmlXmlParser *parser, SmlError **error) 
     1025static SmlMapItem *_smlMapItemParse(SmlXmlParser *parser, SmlError **error) 
    9671026{ 
    9681027        smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); 
     
    11161175                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { 
    11171176                        char *format = NULL; 
    1118                         if (!_smlCommandMetaParse(parser, &format, &contenttype, NULL, error)) 
     1177                        if (!_smlCommandMetaParse(parser, &format, &contenttype, NULL, NULL, error)) 
    11191178                                goto error_free_cmd; 
    11201179                        g_free(format); 
     
    12441303        if (strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SYNCBODY) || \ 
    12451304                xmlTextReaderNodeType(parser->reader) != XML_NODE_CLOSE) { 
    1246                 smlErrorSet(error, SML_ERROR_GENERIC, "Wrong closings node"); 
     1305                smlErrorSet(error, SML_ERROR_GENERIC, "Wrong closing node"); 
    12471306                goto error; 
    12481307        } 
     
    12901349                goto error; 
    12911350        } 
     1351         
     1352        parser->version = SML_VERSION_UNKNOWN; 
    12921353         
    12931354        *header = smlTryMalloc0(sizeof(SmlHeader), error); 
     
    13121373                        if (!_smlSyncHeaderParseDTD(&((*header)->version), parser, error)) 
    13131374                                goto error_free_header; 
     1375                        parser->version = (*header)->version; 
    13141376                } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_VERPROTO)) { 
    13151377                        if (!_smlSyncHeaderParseProto(&((*header)->protocol), parser, error)) 
     
    15081570        if (item && (*status)->type != SML_COMMAND_TYPE_ALERT) { 
    15091571                smlErrorSet(error, SML_ERROR_GENERIC, "Got wrong item"); 
    1510                 smlItemFree(item); 
     1572                smlItemUnref(item); 
    15111573                goto error_free_status; 
    15121574        } 
     
    15151577                (*status)->anchor = item->anchor; 
    15161578                item->anchor = NULL; 
    1517                 smlItemFree(item); 
     1579                smlItemUnref(item);