Changeset 120
- Timestamp:
- 04/12/06 16:18:50 (3 years ago)
- Files:
-
- branches/development-branch/libsyncml/objects/sml_auth.c (modified) (2 diffs)
- branches/development-branch/libsyncml/objects/sml_devinf_obj.c (modified) (1 diff)
- branches/development-branch/libsyncml/objects/sml_ds_server.c (modified) (2 diffs)
- branches/development-branch/libsyncml/parser/sml_wbxml.c (modified) (1 diff)
- branches/development-branch/libsyncml/parser/sml_xml_assm.c (modified) (15 diffs)
- branches/development-branch/libsyncml/parser/sml_xml_assm_internals.h (modified) (1 diff)
- branches/development-branch/libsyncml/parser/sml_xml_parse.c (modified) (34 diffs)
- branches/development-branch/libsyncml/parser/sml_xml_parse_internals.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_command.c (modified) (10 diffs)
- branches/development-branch/libsyncml/sml_command.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_command_internals.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_defines.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_devinf.c (modified) (2 diffs)
- branches/development-branch/libsyncml/sml_elements.c (modified) (1 diff)
- branches/development-branch/libsyncml/sml_elements.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_elements_internals.h (modified) (2 diffs)
- branches/development-branch/libsyncml/sml_error.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_manager.c (modified) (6 diffs)
- branches/development-branch/libsyncml/sml_manager_internals.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_parse.c (modified) (4 diffs)
- branches/development-branch/libsyncml/sml_parse.h (modified) (3 diffs)
- branches/development-branch/libsyncml/sml_session.c (modified) (20 diffs)
- branches/development-branch/libsyncml/sml_session.h (modified) (1 diff)
- branches/development-branch/libsyncml/sml_session_internals.h (modified) (2 diffs)
- branches/development-branch/libsyncml/sml_support.c (modified) (3 diffs)
- branches/development-branch/libsyncml/sml_support.h (modified) (1 diff)
- branches/development-branch/tests (modified) (1 prop)
- branches/development-branch/tests/Makefile.am (modified) (2 diffs)
- branches/development-branch/tests/check_session.c (modified) (8 diffs)
- branches/development-branch/tests/check_sync.c (modified) (9 diffs)
- branches/development-branch/tests/check_xml_assembler.c (modified) (2 diffs)
- branches/development-branch/tests/check_xml_parser.c (modified) (2 diffs)
- branches/development-branch/tests/valgrind.supp (modified) (1 diff)
- branches/development-branch/tools/syncml-obex-client.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/development-branch/libsyncml/objects/sml_auth.c
r115 r120 76 76 77 77 char **arr = g_strsplit(buffer, ":", 2); 78 g_free(buffer); 78 79 79 80 smlTrace(TRACE_INTERNAL, "Username \"%s\", Password \"%s\"", arr[0], arr[1]); … … 103 104 goto error; 104 105 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); 107 112 108 113 smlTrace(TRACE_EXIT, "%s", __func__); branches/development-branch/libsyncml/objects/sml_devinf_obj.c
r118 r120 211 211 212 212 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); 214 219 if (!devinf) 215 220 goto error; branches/development-branch/libsyncml/objects/sml_ds_server.c
r118 r120 323 323 goto error; 324 324 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 325 334 if (!smlDsSessionSendAlert(dsession, type, last, next, callback, userdata, error)) 326 goto error_free_ session;335 goto error_free_dsession; 327 336 328 337 smlTrace(TRACE_EXIT, "%s", __func__); 329 338 return dsession; 330 339 331 error_free_ session:340 error_free_dsession: 332 341 g_free(dsession); 333 342 error: … … 504 513 * uid (if we are a client for example). If it is not given we use the 505 514 * 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)) 507 522 goto error; 508 523 branches/development-branch/libsyncml/parser/sml_wbxml.c
r116 r120 81 81 82 82 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(¶ms, data, size, &buffer, error)) 84 85 goto error; 85 86 unsigned int buffer_size = strlen(buffer); branches/development-branch/libsyncml/parser/sml_xml_assm.c
r116 r120 81 81 } 82 82 83 SmlBool _smlXmlAssemblerAddData(SmlXmlAssembler *assm, const char *name, const char *value, SmlBool raw, SmlError **error)83 static SmlBool _smlXmlAssemblerAddData(SmlXmlAssembler *assm, const char *name, const char *value, unsigned int size, SmlBool raw, SmlError **error) 84 84 { 85 85 int rc = 0; … … 88 88 89 89 if (raw) 90 rc = xmlTextWriterWriteRaw (assm->writer, (xmlChar *)value);90 rc = xmlTextWriterWriteRawLen(assm->writer, (xmlChar *)value, size); 91 91 else 92 rc = xmlTextWriterWrite CDATA(assm->writer, (xmlChar *)value);92 rc = xmlTextWriterWriteFormatCDATA(assm->writer, "%*s", size, (xmlChar *)value); 93 93 if (rc < 0) { 94 94 smlErrorSet(error, SML_ERROR_GENERIC, "Unable to add data"); … … 102 102 } 103 103 104 SmlBool _smlXmlAssemblerAddID(SmlXmlAssembler *assm, const char *name, unsigned int id, SmlError **error)104 static SmlBool _smlXmlAssemblerAddID(SmlXmlAssembler *assm, const char *name, unsigned int id, SmlError **error) 105 105 { 106 106 int rc = xmlTextWriterWriteFormatElement(assm->writer, (xmlChar *)name, "%i", id); … … 112 112 } 113 113 114 static 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 114 124 SmlBool smlLocationAssemble(SmlLocation *location, SmlXmlAssembler *assm, const char *name, SmlError **error) 115 125 { … … 184 194 } 185 195 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);196 SmlBool 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); 189 199 smlAssert(assm); 190 200 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 192 207 if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) 193 208 goto error; 194 209 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; 208 253 } 209 254 … … 257 302 goto error; 258 303 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)) 260 305 goto error; 261 306 … … 302 347 goto error; 303 348 304 if (!smlItemAssemble(change->private.access.item, assm, FALSE, error))349 if (!smlItemAssemble(change->private.access.item, assm, FALSE, 0, error)) 305 350 goto error; 306 351 … … 340 385 goto error; 341 386 387 /*if (change->size) { 388 if (!_smlXmlAssemblerAddID(assm, SML_ELEMENT_SIZE, change->size, error)) 389 goto error; 390 }*/ 391 342 392 //META 343 393 if (!_smlXmlAssemblerEndNode(assm, error)) … … 350 400 } 351 401 352 if (!smlItemAssemble(change->private.change.item, assm, FALSE, error))402 if (!smlItemAssemble(change->private.change.item, assm, FALSE, change->size, error)) 353 403 goto error; 354 404 … … 371 421 goto error; 372 422 } 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; 373 434 374 435 if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET, error)) … … 834 895 goto error; 835 896 } 836 897 898 assm->moreDataSet = FALSE; 899 837 900 xmlBufferFree(cmd->buffer); 838 901 g_free(cmd); … … 1010 1073 switch (status->type) { 1011 1074 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; 1024 1078 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 } 1028 1093 break; 1029 1094 case SML_COMMAND_TYPE_HEADER: … … 1076 1141 goto error; 1077 1142 1078 if (!smlItemAssemble(status->item, assm, TRUE, error))1143 if (!smlItemAssemble(status->item, assm, TRUE, 0, error)) 1079 1144 goto error; 1080 1145 break; … … 1206 1271 flush_list(assm->commands); 1207 1272 assm->commands = NULL; 1273 1274 assm->moreDataSet = FALSE; 1208 1275 1209 1276 smlTrace(TRACE_EXIT, "%s: %i", __func__, newid); … … 1526 1593 } 1527 1594 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);1595 SmlBool smlXmlAssemblerNextCmdRef(SmlXmlAssembler *assm, unsigned int *cmdRef, unsigned int *msgRef) 1596 { 1597 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, cmdRef, msgRef); 1531 1598 smlAssert(assm); 1532 1599 smlAssert(cmdRef); branches/development-branch/libsyncml/parser/sml_xml_assm_internals.h
r101 r120 69 69 unsigned int reserved_statuses; 70 70 unsigned int added_statuses; 71 72 SmlBool moreDataSet; 71 73 }; 72 74 branches/development-branch/libsyncml/parser/sml_xml_parse.c
r116 r120 29 29 #include "sml_xml_parse_internals.h" 30 30 31 #define BUFFER_SIZE 500 32 31 33 /** 32 34 * @defgroup Parser SyncML XML Parser … … 37 39 /*@{*/ 38 40 39 SmlBool _smlXmlParserStep(SmlXmlParser *parser)41 static SmlBool _smlXmlParserStep(SmlXmlParser *parser) 40 42 { 41 43 SmlBool ret = FALSE; 42 44 do { 43 ret = xmlTextReaderRead(parser->reader) == 1? TRUE : FALSE;45 ret = (xmlTextReaderRead(parser->reader) == 1) ? TRUE : FALSE; 44 46 } while (ret && (xmlTextReaderNodeType(parser->reader) == XML_READER_TYPE_DOCUMENT_TYPE || \ 45 47 xmlTextReaderNodeType(parser->reader) == XML_READER_TYPE_WHITESPACE || \ … … 49 51 } 50 52 51 SmlBool _smlXmlParserExpectNode(SmlXmlParser *parser, int type, SmlBool empty, const char *name, SmlError **error)53 static SmlBool _smlXmlParserExpectNode(SmlXmlParser *parser, int type, SmlBool empty, const char *name, SmlError **error) 52 54 { 53 55 if (!_smlXmlParserStep(parser)) { … … 91 93 } 92 94 93 SmlBool _smlXmlParserGetID(SmlXmlParser *parser, unsigned int *id, const char *name, SmlError **error)95 static SmlBool _smlXmlParserGetID(SmlXmlParser *parser, unsigned int *id, const char *name, SmlError **error) 94 96 { 95 97 smlAssert(parser); … … 115 117 } 116 118 117 SmlBool _smlXmlParserGetString(SmlXmlParser *parser, char **string, const char *name, SmlError **error)119 static SmlBool _smlXmlParserGetString(SmlXmlParser *parser, char **string, const char *name, SmlError **error) 118 120 { 119 121 smlAssert(parser); … … 150 152 } 151 153 152 SmlBool _smlXmlParserGetData(SmlXmlParser *parser, char **string, unsigned int *size, const char *name, SmlError **error)154 static SmlBool _smlXmlParserGetData(SmlXmlParser *parser, char **string, unsigned int *size, const char *name, SmlError **error) 153 155 { 154 156 smlAssert(parser); … … 161 163 } 162 164 163 xmlBuffer *buffer = xmlBufferCreate(); 165 166 xmlBuffer *buffer = xmlBufferCreateSize(BUFFER_SIZE); 164 167 if (!buffer) { 165 168 smlErrorSet(error, SML_ERROR_GENERIC, "Unable to create new buffer"); … … 221 224 *string = (char *)xmlBufferContent(buffer); 222 225 if (size) 223 *size = xmlBufferLength(buffer); 224 225 (*string)[*size - 1] = 0; 226 *size = xmlBufferLength(buffer) - 1; 226 227 227 228 //Hack to avoid memory copy … … 313 314 314 315 315 SmlBool _smlLocationParse(SmlLocation **location, SmlXmlParser *parser, SmlError **error)316 static SmlBool _smlLocationParse(SmlLocation **location, SmlXmlParser *parser, SmlError **error) 316 317 { 317 318 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, location, parser, error); … … 375 376 } 376 377 377 SmlBool _smlAnchorParse(SmlAnchor **anchor, SmlXmlParser *parser, SmlError **error)378 static SmlBool _smlAnchorParse(SmlAnchor **anchor, SmlXmlParser *parser, SmlError **error) 378 379 { 379 380 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, anchor, parser, error); … … 433 434 } 434 435 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);436 static 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); 438 439 smlAssert(parser); 439 440 … … 461 462 if (!_smlXmlParserGetString(parser, format, SML_ELEMENT_FORMAT, error)) 462 463 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; 463 467 } else { 464 468 smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node: %s", xmlTextReaderConstName(parser->reader)); … … 481 485 } 482 486 483 SmlBool _smlCommandSyncMetaParse(SmlXmlParser *parser, unsigned int *maxobjsize, SmlError **error)487 static SmlBool _smlCommandSyncMetaParse(SmlXmlParser *parser, unsigned int *maxobjsize, SmlError **error) 484 488 { 485 489 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, maxobjsize, error); … … 519 523 } 520 524 521 SmlItem *_smlItemParse(SmlXmlParser *parser, SmlCommand *cmd, SmlCommandType type, SmlError **error)525 static SmlItem *_smlItemParse(SmlXmlParser *parser, SmlCommand *cmd, SmlCommandType type, SmlError **error) 522 526 { 523 527 smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, parser, cmd, type, error); 524 528 smlAssert(parser); 525 529 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); 527 536 if (!item) 528 537 goto error; 529 538 539 if (!_smlXmlParserStep(parser)) { 540 smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); 541 goto error_free_item; 542 } 543 530 544 while (1) { 531 if (!_smlXmlParserStep(parser)) {532 smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes");533 goto error_free_item;534 }535 536 545 if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_ITEM) && \ 537 546 xmlTextReaderNodeType(parser->reader) == XML_NODE_CLOSE) { … … 543 552 544 553 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)) 546 556 goto error_free_item; 557 558 smlItemSetSource(item, source); 559 smlLocationUnref(source); 547 560 } 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)) 549 563 goto error_free_item; 564 565 smlItemSetTarget(item, target); 566 smlLocationUnref(target); 550 567 } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { 551 568 switch (type) { 552 569 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)) 554 576 goto error_free_item; 555 577 break; … … 566 588 } 567 589 568 if (!_smlAnchorParse(&(item->anchor), parser, error)) 590 SmlAnchor *anchor = NULL; 591 if (!_smlAnchorParse(&anchor, parser, error)) 569 592 goto error_free_item; 593 594 item->anchor = anchor; 570 595 571 596 if (!_smlXmlParserStep(parser)) { … … 574 599 } 575 600 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)) 578 605 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); 579 613 } 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; 580 635 } else { 581 636 smlErrorSet(error, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); 582 637 goto error_free_item; 583 638 } 639 640 if (!_smlXmlParserStep(parser)) { 641 smlErrorSet(error, SML_ERROR_GENERIC, "Missing nodes"); 642 goto error_free_item; 643 } 584 644 } 585 645 … … 588 648 589 649 error_free_item: 590 smlItem Free(item);650 smlItemUnref(item); 591 651 error: 592 652 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); … … 594 654 } 595 655 596 SmlCred *_smlCredParse(SmlXmlParser *parser, SmlError **error)656 static SmlCred *_smlCredParse(SmlXmlParser *parser, SmlError **error) 597 657 { 598 658 smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); … … 620 680 621 681 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)) 623 683 goto error_free_cred; 624 684 } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { … … 677 737 smlAssert(name); 678 738 char *contenttype = NULL; 679 SmlItem *item = NULL;680 739 681 740 *cmd = smlCommandNew(type, error); … … 702 761 goto error_free_cmd; 703 762 } 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) 706 765 goto error_free_cmd; 707 766 } 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)) 709 768 goto error_free_cmd; 710 769 } else { … … 719 778 } 720 779 721 if (! item) {780 if (!(*cmd)->private.change.item) { 722 781 smlErrorSet(error, SML_ERROR_GENERIC, "No item set"); 723 782 goto error_free_cmd; … … 725 784 726 785 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; 733 793 734 794 switch (type) { … … 747 807 } 748 808 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); 751 811 if (!(*cmd)->source) 752 812 goto error_free_cmd; 753 813 } 754 814 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); 757 817 if (!(*cmd)->target) 758 818 goto error_free_cmd; … … 776 836 if (contenttype) 777 837 g_free(contenttype); 778 if (item) 779 smlItemFree(item); 838 *cmd = NULL; 780 839 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); 781 840 return FALSE; … … 868 927 item->source = NULL; 869 928 870 smlItem Free(item);929 smlItemUnref(item); 871 930 } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_DATA)) { 872 931 if (!_smlXmlParserGetID(parser, &((*cmd)->private.alert.type), SML_ELEMENT_DATA, error)) … … 964 1023 } 965 1024 966 SmlMapItem *_smlMapItemParse(SmlXmlParser *parser, SmlError **error)1025 static SmlMapItem *_smlMapItemParse(SmlXmlParser *parser, SmlError **error) 967 1026 { 968 1027 smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, parser, error); … … 1116 1175 } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_META)) { 1117 1176 char *format = NULL; 1118 if (!_smlCommandMetaParse(parser, &format, &contenttype, NULL, error))1177 if (!_smlCommandMetaParse(parser, &format, &contenttype, NULL, NULL, error)) 1119 1178 goto error_free_cmd; 1120 1179 g_free(format); … … 1244 1303 if (strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SYNCBODY) || \ 1245 1304 xmlTextReaderNodeType(parser->reader) != XML_NODE_CLOSE) { 1246 smlErrorSet(error, SML_ERROR_GENERIC, "Wrong closing snode");1305 smlErrorSet(error, SML_ERROR_GENERIC, "Wrong closing node"); 1247 1306 goto error; 1248 1307 } … … 1290 1349 goto error; 1291 1350 } 1351 1352 parser->version = SML_VERSION_UNKNOWN; 1292 1353 1293 1354 *header = smlTryMalloc0(sizeof(SmlHeader), error); … … 1312 1373 if (!_smlSyncHeaderParseDTD(&((*header)->version), parser, error)) 1313 1374 goto error_free_header; 1375 parser->version = (*header)->version; 1314 1376 } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_VERPROTO)) { 1315 1377 if (!_smlSyncHeaderParseProto(&((*header)->protocol), parser, error)) … … 1508 1570 if (item && (*status)->type != SML_COMMAND_TYPE_ALERT) { 1509 1571 smlErrorSet(error, SML_ERROR_GENERIC, "Got wrong item"); 1510 smlItem Free(item);1572 smlItemUnref(item); 1511 1573 goto error_free_status; 1512 1574 } … … 1515 1577 (*status)->anchor = item->anchor; 1516 1578 item->anchor = NULL; 1517 smlItem Free(item);1579 smlItemUnref(item); <
