00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "syncml.h"
00023
00024 #include "syncml_internals.h"
00025 #include "sml_error_internals.h"
00026 #include "sml_parse_internals.h"
00027 #include "sml_command_internals.h"
00028 #include "sml_elements_internals.h"
00029 #include "sml_notification_internals.h"
00030
00031 #include "parser/sml_xml_assm.h"
00032 #include "parser/sml_xml_parse.h"
00033 #include "parser/sml_wbxml.h"
00034
00042
00050 SmlParser *smlParserNew(SmlMimeType type, unsigned int limit, SmlError **error)
00051 {
00052 smlTrace(TRACE_ENTRY, "%s(%i, %i, %p)", __func__, type, limit, error);
00053 CHECK_ERROR_REF
00054
00055 SmlParser *parser = smlTryMalloc0(sizeof(SmlParser), error);
00056 if (!parser)
00057 goto error;
00058
00059 parser->type = type;
00060 parser->limit = limit;
00061
00062 switch (type) {
00063 case SML_MIMETYPE_XML:
00064 if (!(parser->parser_userdata = smlXmlParserNew(&(parser->functions), error)))
00065 goto error_free_parser;
00066 break;
00067 case SML_MIMETYPE_SAN:
00068
00069 if (!(parser->parser_userdata = smlXmlParserNew(&(parser->functions), error)))
00070 goto error_free_parser;
00071 break;
00072 case SML_MIMETYPE_WBXML:
00073 #ifdef ENABLE_WBXML
00074 if (!(parser->parser_userdata = smlWbxmlParserNew(&(parser->functions), error)))
00075 goto error_free_parser;
00076 break;
00077 #else
00078 smlErrorSet(error, SML_ERROR_GENERIC, "Wbxml not enabled in this build");
00079 goto error_free_parser;
00080 #endif
00081 default:
00082 smlErrorSet(error, SML_ERROR_GENERIC, "Unknown parser type");
00083 goto error_free_parser;
00084 }
00085
00086 smlTrace(TRACE_EXIT, "%s: %p", __func__, parser);
00087 return parser;
00088
00089 error_free_parser:
00090 smlSafeFree((gpointer *)&parser);
00091 error:
00092 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00093 return NULL;
00094 }
00095
00096 void smlParserSetManager(SmlParser *parser, SmlManager *manager)
00097 {
00098 smlAssert(parser);
00099 smlAssert(manager);
00100 parser->manager = manager;
00101 }
00102
00108 void smlParserFree(SmlParser *parser)
00109 {
00110 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, parser);
00111 smlAssert(parser);
00112
00113 if (parser->functions.free)
00114 parser->functions.free(parser->parser_userdata);
00115
00116 smlSafeFree((gpointer *)&parser);
00117
00118 smlTrace(TRACE_EXIT, "%s", __func__);
00119 }
00120
00132 SmlBool smlParserStart(SmlParser *parser, const char *data, unsigned int size, SmlError **error)
00133 {
00134 smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, parser, data, size, error);
00135 CHECK_ERROR_REF
00136 smlAssert(parser);
00137 smlAssert(data);
00138 smlAssert(size);
00139 smlAssert(parser->functions.start);
00140 smlAssertMsg(parser->type != SML_MIMETYPE_SAN || parser->manager,
00141 SML_ASSERT_MSG_SAN_PARSE_REQUIRES_MANAGER);
00142
00143 if (parser->limit && size > parser->limit) {
00144 smlErrorSet(error, SML_ERROR_GENERIC, "Input data too large");
00145 goto error;
00146 }
00147
00148 if (parser->type == SML_MIMETYPE_SAN) {
00149
00150 smlTrace(TRACE_INTERNAL, "%s - detected an OMA DS 1.2 SAN", __func__);
00151
00152
00153 SmlNotification *san = smlNotificationParse(data, size, error);
00154 if (!san)
00155 goto error;
00156
00157
00158 smlNotificationSetManager(san, parser->manager);
00159 san->type = SML_MIMETYPE_XML;
00160 san->sessionType = SML_SESSION_TYPE_CLIENT;
00161 san->target = smlLocationNew("/", NULL, error);
00162 if (!san->target)
00163 goto error;
00164
00165
00166 char *xmlData = NULL;
00167 unsigned int xmlSize = 0;
00168 if (!smlNotificationAssemble11(san, &xmlData, &xmlSize, SML_VERSION_12, error))
00169 {
00170 smlNotificationFree(san);
00171 goto error;
00172 }
00173 smlTrace(TRACE_INTERNAL,
00174 "%s - converted OMA DS 1.2 SAN to SyncML 1.1 server alerted sync - %s",
00175 __func__, VA_STRING(xmlData));
00176
00177
00178 smlNotificationFree(san);
00179 san = NULL;
00180
00181
00182 if (!parser->functions.start(parser->parser_userdata, xmlData, xmlSize, error)) {
00183 smlSafeCFree(&xmlData);
00184 goto error;
00185 }
00186 smlSafeCFree(&xmlData);
00187 } else {
00188
00189 if (!parser->functions.start(parser->parser_userdata, data, size, error))
00190 goto error;
00191 }
00192
00193 smlTrace(TRACE_EXIT, "%s", __func__);
00194 return TRUE;
00195
00196 error:
00197 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00198 return FALSE;
00199 }
00200
00216 SmlBool smlParserGetHeader(SmlParser *parser, SmlHeader **header, SmlCred **cred, SmlError **error)
00217 {
00218 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, header, cred, error);
00219 CHECK_ERROR_REF
00220 smlAssert(parser);
00221 smlAssert(header);
00222 smlAssert(cred);
00223 smlAssert(parser->functions.get_header);
00224
00225 if (!parser->functions.get_header(parser->parser_userdata, header, cred, error))
00226 goto error;
00227
00228 smlTrace(TRACE_EXIT, "%s", __func__);
00229 return TRUE;
00230
00231 error:
00232 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00233 return FALSE;
00234 }
00235
00250 SmlParserResult smlParserGetCommand(SmlParser *parser, SmlCommand **cmd, SmlError **error)
00251 {
00252 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, cmd, error);
00253 CHECK_ERROR_REF
00254 smlAssert(parser);
00255 smlAssert(cmd);
00256 smlAssert(parser->functions.get_cmd);
00257 SmlParserResult result = SML_PARSER_RESULT_ERROR;
00258
00259 if (!(result = parser->functions.get_cmd(parser->parser_userdata, cmd, error)))
00260 goto error;
00261
00262 smlTrace(TRACE_EXIT, "%s: %i", __func__, result);
00263 return result;
00264
00265 error:
00266 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00267 return SML_PARSER_RESULT_ERROR;
00268 }
00269
00284 SmlBool smlParserGetStatus(SmlParser *parser, SmlStatus **status, SmlError **error)
00285 {
00286 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parser, status, error);
00287 CHECK_ERROR_REF
00288 smlAssert(parser);
00289 smlAssert(status);
00290 smlAssert(parser->functions.get_status);
00291
00292 if (!parser->functions.get_status(parser->parser_userdata, status, error))
00293 goto error;
00294
00295 smlTrace(TRACE_EXIT, "%s", __func__);
00296 return TRUE;
00297
00298 error:
00299 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00300 return FALSE;
00301 }
00302
00314 SmlBool smlParserEnd(SmlParser *parser, SmlBool *final, SmlBool *end, SmlError **error)
00315 {
00316 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, parser, final, end, error);
00317 CHECK_ERROR_REF
00318 smlAssert(parser);
00319 smlAssert(parser->functions.end);
00320
00321 if (!parser->functions.end(parser->parser_userdata, final, end, error))
00322 goto error;
00323
00324 smlTrace(TRACE_INTERNAL, "%s: Final %i, End %i", __func__, final ? *final : -1, end ? *end : -1);
00325
00326 smlTrace(TRACE_EXIT, "%s", __func__);
00327 return TRUE;
00328
00329 error:
00330 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00331 return FALSE;
00332 }
00333
00343
00352 SmlAssembler *smlAssemblerNew(SmlMimeType type, unsigned int limit, SmlError **error)
00353 {
00354 smlTrace(TRACE_ENTRY, "%s(%i, %i, %p)", __func__, type, limit, error);
00355 CHECK_ERROR_REF
00356
00357 SmlAssembler *assm = smlTryMalloc0(sizeof(SmlAssembler), error);
00358 if (!assm)
00359 goto error;
00360
00361 assm->type = type;
00362 assm->remoteMaxMsgSize = limit;
00363 assm->empty = TRUE;
00364 assm->remoteMaxObjSize = 0;
00365
00366 switch (type) {
00367 case SML_MIMETYPE_XML:
00368 if (!(assm->assm_userdata = smlXmlAssemblerNew(assm, &(assm->functions), error)))
00369 goto error_free_assm;
00370 break;
00371 case SML_MIMETYPE_WBXML:
00372 #ifdef ENABLE_WBXML
00373 if (!(assm->assm_userdata = smlWbxmlAssemblerNew(assm, &(assm->functions), error)))
00374 goto error_free_assm;
00375 break;
00376 #else
00377 smlErrorSet(error, SML_ERROR_GENERIC, "Wbxml not enabled in this build");
00378 goto error_free_assm;
00379 #endif
00380 default:
00381 smlErrorSet(error, SML_ERROR_GENERIC, "Unknown assembler type");
00382 goto error_free_assm;
00383 }
00384
00385 assm->options = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
00386
00387 smlTrace(TRACE_EXIT, "%s: %p", __func__, assm);
00388 return assm;
00389
00390 error_free_assm:
00391 smlSafeFree((gpointer *)&assm);
00392 error:
00393 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00394 return NULL;
00395 }
00396
00402 void smlAssemblerFree(SmlAssembler *assm)
00403 {
00404 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm);
00405 smlAssert(assm);
00406
00407 if (assm->functions.free)
00408 assm->functions.free(assm->assm_userdata);
00409
00410 g_hash_table_destroy(assm->options);
00411
00412 smlSafeFree((gpointer *)&assm);
00413
00414 smlTrace(TRACE_EXIT, "%s", __func__);
00415 }
00416
00428 SmlBool smlAssemblerStart(SmlAssembler *assm, SmlSession *session, SmlError **error)
00429 {
00430 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, session, error);
00431 CHECK_ERROR_REF
00432 smlAssert(assm);
00433 smlAssert(session);
00434 smlAssert(assm->functions.start);
00435
00436 if (!assm->functions.start(assm->assm_userdata, session, error))
00437 goto error;
00438
00439 smlTrace(TRACE_EXIT, "%s", __func__);
00440 return TRUE;
00441
00442 error:
00443 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00444 return FALSE;
00445 }
00446
00456 SmlBool smlAssemblerRun(SmlAssembler *assm, char **data, unsigned int *size, SmlBool *end, SmlBool final, SmlError **error)
00457 {
00458 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %i, %p)", __func__, assm, data, size, end, final, error);
00459 CHECK_ERROR_REF
00460 smlAssert(assm);
00461 smlAssert(data);
00462 smlAssert(size);
00463 smlAssert(assm->functions.run);
00464
00465 if (!assm->functions.run(assm->assm_userdata, data, size, end, final, smlAssemblerGetRemoteMaxMsgSize(assm), error))
00466 goto error;
00467
00468 smlTrace(TRACE_EXIT, "%s", __func__);
00469 return TRUE;
00470
00471 error:
00472 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00473 return FALSE;
00474 }
00475
00485 unsigned int smlAssemblerCheckSize(SmlAssembler *assm, SmlBool headeronly, SmlError **error)
00486 {
00487 smlTrace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, assm, headeronly, error);
00488 CHECK_ERROR_REF
00489 smlAssert(assm);
00490 smlAssert(assm->functions.check_size);
00491
00492 unsigned int size = 0;
00493 if (!(size = assm->functions.check_size(assm->assm_userdata, headeronly, error)))
00494 goto error;
00495
00496 smlTrace(TRACE_EXIT, "%s: %i", __func__, size);
00497 return size;
00498
00499 error:
00500 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00501 return 0;
00502 }
00503
00514 unsigned int smlAssemblerFlush(SmlAssembler *assm)
00515 {
00516 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm);
00517 smlAssert(assm);
00518 smlAssert(assm->functions.flush);
00519
00520 unsigned int ret = assm->functions.flush(assm->assm_userdata);
00521 assm->empty = TRUE;
00522
00523 smlTrace(TRACE_EXIT, "%s: %i", __func__, ret);
00524 return ret;
00525 }
00526
00527 void smlAssemblerRestoreCommands(SmlAssembler *assm)
00528 {
00529 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm);
00530 smlAssert(assm);
00531 smlAssert(assm->functions.restore_cmds);
00532
00533 assm->functions.restore_cmds(assm->assm_userdata);
00534 assm->empty = FALSE;
00535
00536 smlTrace(TRACE_EXIT, "%s", __func__);
00537 }
00538
00545 SmlBool smlAssemblerGetSpace(SmlAssembler *assm, int *space, SmlCommand *parent, SmlCommand *cmd, SmlError **error)
00546 {
00547 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p)", __func__, assm, space, parent, cmd, error);
00548 CHECK_ERROR_REF
00549 smlAssert(assm);
00550 smlAssert(space);
00551 smlAssert(cmd);
00552 smlAssert(assm->functions.start_cmd);
00553 smlAssert(assm->functions.rem_cmd);
00554 smlAssert(cmd->type == SML_COMMAND_TYPE_ADD || cmd->type == SML_COMMAND_TYPE_REPLACE);
00555 unsigned int parentID = 0;
00556
00557 int limit = smlAssemblerGetRemoteMaxMsgSize(assm);
00558 if (!limit) {
00559 *space = -1;
00560 smlTrace(TRACE_EXIT, "%s: No limit", __func__);
00561 return TRUE;
00562 }
00563
00564
00565 if (parent) {
00566 if (!parent->cmdID) {
00567 smlErrorSet(error, SML_ERROR_GENERIC, "Parent has to be added before");
00568 goto error;
00569 }
00570 parentID = parent->cmdID;
00571 }
00572
00573
00574 if (cmd->private.change.items)
00575 {
00576 guint i;
00577 for (i=0; i < g_list_length(cmd->private.change.items); i++)
00578 {
00579 SmlItem *item = g_list_nth_data(cmd->private.change.items, i);
00580 item->disabled = TRUE;
00581 }
00582 }
00583
00584 SmlBool noCmdID = FALSE;
00585 if (!cmd->cmdID) {
00586 noCmdID = TRUE;
00587
00588
00589 cmd->cmdID = 10000;
00590 }
00591
00592 if (!assm->functions.start_cmd(assm->assm_userdata, parentID, cmd, error))
00593 goto error_enable_item;
00594
00595
00596 int size = 0;
00597 if (!(size = smlAssemblerCheckSize(assm, FALSE, error)))
00598 goto error_remove;
00599
00600 if (limit <= size)
00601 *space = 0;
00602 else
00603 *space = limit - size - 10;
00604
00605
00606 if (!assm->functions.rem_cmd(assm->assm_userdata, parentID, error))
00607 goto error_remove;
00608
00609
00610 if (cmd->private.change.items)
00611 {
00612 guint i;
00613 for (i=0; i < g_list_length(cmd->private.change.items); i++)
00614 {
00615 SmlItem *item = g_list_nth_data(cmd->private.change.items, i);
00616 item->disabled = FALSE;
00617 }
00618 }
00619
00620 if (noCmdID)
00621 cmd->cmdID = 0;
00622
00623 smlTrace(TRACE_EXIT, "%s: %i", __func__, *space);
00624 return TRUE;
00625
00626 error_remove:
00627 assm->functions.rem_cmd(assm->assm_userdata, parentID, NULL);
00628 error_enable_item:
00629 if (cmd->private.change.items)
00630 {
00631 guint i;
00632 for (i=0; i < g_list_length(cmd->private.change.items); i++)
00633 {
00634 SmlItem *item = g_list_nth_data(cmd->private.change.items, i);
00635 item->disabled = FALSE;
00636 }
00637 }
00638 if (noCmdID)
00639 cmd->cmdID = 0;
00640 error:
00641 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00642 return FALSE;
00643 }
00644
00659 SmlAssemblerResult smlAssemblerStartCommand(SmlAssembler *assm, SmlCommand *parent, SmlCommand *cmd, SmlError **error)
00660 {
00661 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, assm, parent, cmd, error);
00662 CHECK_ERROR_REF
00663 smlAssert(assm);
00664 smlAssert(cmd);
00665 smlAssert(assm->functions.start_cmd);
00666 smlAssert(assm->functions.rem_cmd);
00667 unsigned int parentID = 0;
00668
00669
00670 if (parent) {
00671 if (!parent->cmdID) {
00672 smlErrorSet(error, SML_ERROR_GENERIC, "Parent has to be added before");
00673 goto error;
00674 }
00675 parentID = parent->cmdID;
00676 }
00677
00678 if (!assm->functions.start_cmd(assm->assm_userdata, parentID, cmd, error))
00679 goto error;
00680
00681
00682 int limit = smlAssemblerGetRemoteMaxMsgSize(assm);
00683 if (limit) {
00684
00685 int size = 0;
00686 if (!(size = smlAssemblerCheckSize(assm, FALSE, error)))
00687 goto error;
00688
00689 if (size > limit) {
00690
00691 if (!assm->functions.rem_cmd(assm->assm_userdata, parentID, error))
00692 goto error;
00693
00694 smlTrace(TRACE_EXIT, "%s: Mismatch", __func__);
00695 return SML_ASSEMBLER_RESULT_MISMATCH;
00696 }
00697 smlTrace(TRACE_INTERNAL, "%s: size %i, limit %i", __func__, size, limit);
00698 }
00699
00700 if (cmd->cmdID)
00701 assm->empty = FALSE;
00702
00703 smlTrace(TRACE_EXIT, "%s", __func__);
00704 return SML_ASSEMBLER_RESULT_OK;
00705
00706 error:
00707 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00708 return SML_ASSEMBLER_RESULT_ERROR;
00709 }
00710
00722 SmlBool smlAssemblerEndCommand(SmlAssembler *assm, SmlCommand *parent, SmlError **error)
00723 {
00724 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, parent, error);
00725 CHECK_ERROR_REF
00726 smlAssert(assm);
00727 smlAssert(assm->functions.end_cmd);
00728
00729 unsigned int parentID = 0;
00730
00731
00732 if (parent) {
00733 if (!parent->cmdID) {
00734 smlErrorSet(error, SML_ERROR_GENERIC, "Parent has to be added before");
00735 goto error;
00736 }
00737 parentID = parent->cmdID;
00738 }
00739
00740
00741 if (!assm->functions.end_cmd(assm->assm_userdata, parentID, error))
00742 goto error;
00743
00744 smlTrace(TRACE_EXIT, "%s", __func__);
00745 return TRUE;
00746
00747 error:
00748 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00749 return FALSE;
00750 }
00751
00762 SmlBool smlAssemblerAddHeader(SmlAssembler *assm, SmlSession *session, SmlError **error)
00763 {
00764 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, assm, session, error);
00765 CHECK_ERROR_REF
00766 smlAssert(assm);
00767 smlAssert(session);
00768 smlAssert(assm->functions.add_header);
00769
00770
00771 if (!assm->functions.add_header(assm->assm_userdata, session, error))
00772 goto error;
00773
00774
00775 unsigned int size = 0;
00776 if (!(size = smlAssemblerCheckSize(assm, TRUE, error)))
00777 goto error;
00778
00779
00780 if (smlAssemblerGetRemoteMaxMsgSize(assm) && size > smlAssemblerGetRemoteMaxMsgSize(assm)) {
00781 smlErrorSet(error, SML_ERROR_GENERIC, "Limit to small. Unable to fit a the header");
00782 goto error;
00783 }
00784
00785 smlTrace(TRACE_EXIT, "%s", __func__);
00786 return TRUE;
00787
00788 error:
00789 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00790 return FALSE;
00791 }
00792
00806 SmlAssemblerResult smlAssemblerReserveStatus(SmlAssembler *assm, unsigned int cmdRef, unsigned int msgRef, unsigned int cmdID, SmlError **error)
00807 {
00808 smlTrace(TRACE_ENTRY, "%s(%p, %i, %i, %i, %p)", __func__, assm, cmdRef, msgRef, cmdID, error);
00809 CHECK_ERROR_REF
00810 smlAssert(assm);
00811 smlAssert(assm->functions.reserve_status);
00812
00813
00814 if (!assm->functions.reserve_status(assm->assm_userdata, cmdRef, msgRef, cmdID, error))
00815 goto error;
00816
00817 smlTrace(TRACE_EXIT, "%s", __func__);
00818 return TRUE;
00819
00820 error:
00821 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00822 return FALSE;
00823 }
00824
00839 SmlAssemblerResult smlAssemblerAddStatusFull(SmlAssembler *assm, SmlStatus *status, SmlBool force, SmlError **error)
00840 {
00841 smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, assm, status, force, error);
00842 CHECK_ERROR_REF
00843 smlAssert(assm);
00844 smlAssert(status);
00845 smlAssert(assm->functions.add_status);
00846 smlAssert(assm->functions.rem_status);
00847
00848
00849 if (!assm->functions.add_status(assm->assm_userdata, status, error))
00850 goto error;
00851
00852 if (!force) {
00853
00854 int limit = smlAssemblerGetRemoteMaxMsgSize(assm);
00855 if (limit) {
00856
00857 int size = 0;
00858 if (!(size = smlAssemblerCheckSize(assm, FALSE, error)))
00859 goto error;
00860
00861 if (size > limit) {
00862
00863 if (!assm->functions.rem_status(assm->assm_userdata, error))
00864 goto error;
00865
00866 smlTrace(TRACE_EXIT, "%s: Mismatch", __func__);
00867 return SML_ASSEMBLER_RESULT_MISMATCH;
00868 }
00869 }
00870 }
00871
00872
00873
00874
00875 smlTrace(TRACE_EXIT, "%s", __func__);
00876 return SML_ASSEMBLER_RESULT_OK;
00877
00878 error:
00879 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00880 return SML_ASSEMBLER_RESULT_ERROR;
00881 }
00882
00883 SmlAssemblerResult smlAssemblerAddStatus(SmlAssembler *assm, SmlStatus *status, SmlError **error)
00884 {
00885 CHECK_ERROR_REF
00886 return smlAssemblerAddStatusFull(assm, status, FALSE, error);
00887 }
00888
00896 void smlAssemblerSetOption(SmlAssembler *assm, const char *optionname, const char *value)
00897 {
00898 smlTrace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, assm, VA_STRING(optionname), VA_STRING(value));
00899 smlAssert(assm);
00900 smlAssert(optionname);
00901
00902 g_hash_table_replace(assm->options, g_strdup(optionname), g_strdup(value));
00903
00904 smlTrace(TRACE_EXIT, "%s", __func__);
00905 }
00906
00914 const char *smlAssemblerGetOption(SmlAssembler *assm, const char *optionname)
00915 {
00916 smlTrace(TRACE_ENTRY, "%s(%p, %s)", __func__, assm, VA_STRING(optionname));
00917 smlAssert(assm);
00918 smlAssert(optionname);
00919
00920 const char *ret = g_hash_table_lookup(assm->options, optionname);
00921
00922 smlTrace(TRACE_EXIT, "%s: %s", __func__, VA_STRING(ret));
00923 return ret;
00924 }
00925
00926
00927 unsigned int smlAssemblerGetLimit(SmlAssembler *assm)
00928 {
00929 return smlAssemblerGetRemoteMaxMsgSize(assm);
00930 }
00931
00932 unsigned int smlAssemblerGetRemoteMaxMsgSize(SmlAssembler *assm)
00933 {
00934 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm);
00935 smlAssert(assm);
00936
00937 smlTrace(TRACE_EXIT, "%s: %i", __func__, assm->remoteMaxMsgSize);
00938 return assm->remoteMaxMsgSize;
00939 }
00940
00941
00942 void smlAssemblerSetRequestedLimit(SmlAssembler *assm, unsigned int limit)
00943 {
00944 smlAssemblerSetRemoteMaxMsgSize(assm, limit);
00945 }
00946
00947
00948 void smlAssemblerSetLimit(SmlAssembler *assm, unsigned int limit)
00949 {
00950 smlAssemblerSetRemoteMaxMsgSize(assm, limit);
00951 }
00952
00953 unsigned int smlAssemblerSetRemoteMaxMsgSize(SmlAssembler *assm, unsigned int limit)
00954 {
00955 smlTrace(TRACE_ENTRY, "%s(%p, %i)", __func__, assm, limit);
00956 smlAssert(assm);
00957
00958 if (limit == 0)
00959 {
00960
00961 assm->remoteMaxMsgSize = limit;
00962 } else {
00963 if (limit < assm->remoteMaxMsgSize || assm->remoteMaxMsgSize == 0)
00964 {
00965
00966 assm->remoteMaxMsgSize = limit;
00967 } else {
00968 smlTrace(TRACE_INTERNAL,
00969 "%s: using old limit (%d) because of large new limit (%d).",
00970 __func__, assm->remoteMaxMsgSize, limit);
00971 }
00972 }
00973
00974 smlTrace(TRACE_EXIT, "%s - %d", __func__, assm->remoteMaxMsgSize);
00975 return assm->remoteMaxMsgSize;
00976 }
00977
00978
00979 int smlAssemblerGetSendingMaxObjSize(SmlAssembler *assm)
00980 {
00981 return smlAssemblerGetRemoteMaxObjSize(assm);
00982 }
00983
00984
00985 int smlAssemblerGetRequestedMaxObjSize(SmlAssembler *assm)
00986 {
00987 return smlAssemblerGetRemoteMaxObjSize(assm);
00988 }
00989
00990
00991 unsigned int smlAssemblerGetRemoteMaxObjSize(SmlAssembler *assm)
00992 {
00993 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm);
00994 smlAssert(assm);
00995
00996 smlTrace(TRACE_EXIT, "%s: %i", __func__, assm->remoteMaxObjSize);
00997 return assm->remoteMaxObjSize;
00998 }
00999
01000
01001 void smlAssemblerSetRequestedMaxObjSize(SmlAssembler *assm, int limit)
01002 {
01003 smlAssemblerSetRemoteMaxObjSize(assm, limit);
01004 }
01005
01006
01007 void smlAssemblerSetSendingMaxObjSize(SmlAssembler *assm, int limit)
01008 {
01009 smlAssemblerSetRemoteMaxObjSize(assm, limit);
01010 }
01011
01012 unsigned int smlAssemblerSetRemoteMaxObjSize(SmlAssembler *assm, unsigned int limit)
01013 {
01014 smlTrace(TRACE_ENTRY, "%s(%p, %i)", __func__, assm, limit);
01015 smlAssert(assm);
01016
01017 if (limit == 0)
01018 {
01019
01020 assm->remoteMaxObjSize = limit;
01021 } else {
01022 if (limit < assm->remoteMaxObjSize || assm->remoteMaxObjSize == 0)
01023 {
01024
01025 assm->remoteMaxObjSize = limit;
01026 } else {
01027 smlTrace(TRACE_INTERNAL,
01028 "%s: using old limit (%d) because of large new limit (%d).",
01029 __func__, assm->remoteMaxObjSize, limit);
01030 }
01031 }
01032
01033 smlTrace(TRACE_EXIT, "%s - %d", __func__, assm->remoteMaxObjSize);
01034 return assm->remoteMaxObjSize;
01035 }
01036
01037 SmlBool smlAssemblerIsEmpty(SmlAssembler *assm)
01038 {
01039 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, assm);
01040 smlAssert(assm);
01041
01042 SmlBool ret = assm->empty;
01043
01044 smlTrace(TRACE_EXIT, "%s: %i", __func__, ret);
01045 return ret;
01046 }
01047
01053 SmlBool smlAssemblerIsStatusMissing(SmlAssembler *assm)
01054 {
01055 smlAssert(assm);
01056 smlAssert(assm->functions.missing_status);
01057
01058 SmlBool ret = assm->functions.missing_status(assm->assm_userdata);
01059
01060 return ret;
01061 }
01062
01063 SmlBool smlAssemblerGetNextCmdRef(SmlAssembler *assm, unsigned int *cmdRef, unsigned int *msgRef)
01064 {
01065 smlAssert(assm);
01066 smlAssert(cmdRef);
01067 smlAssert(msgRef);
01068 smlAssert(assm->functions.next_cmdref);
01069
01070 return assm->functions.next_cmdref(assm->assm_userdata, cmdRef, msgRef);
01071 }
01072