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_parse_internals.h"
00026 #include "sml_command_internals.h"
00027 #include "sml_session_internals.h"
00028 #include "sml_elements_internals.h"
00029 #include "sml_error_internals.h"
00030
00031 SmlCommandType smlCommandTypeFromString(const char *name, SmlError **error)
00032 {
00033 CHECK_ERROR_REF
00034 if (!name)
00035 return SML_COMMAND_TYPE_UNKNOWN;
00036
00037 if (!strcmp(name, SML_ELEMENT_ALERT)) {
00038 return SML_COMMAND_TYPE_ALERT;
00039 } else if (!strcmp(name, SML_ELEMENT_SYNC)) {
00040 return SML_COMMAND_TYPE_SYNC;
00041 } else if (!strcmp(name, SML_ELEMENT_PUT)) {
00042 return SML_COMMAND_TYPE_PUT;
00043 } else if (!strcmp(name, SML_ELEMENT_SYNCHDR)) {
00044 return SML_COMMAND_TYPE_HEADER;
00045 } else if (!strcmp(name, SML_ELEMENT_ADD)) {
00046 return SML_COMMAND_TYPE_ADD;
00047 } else if (!strcmp(name, SML_ELEMENT_REPLACE)) {
00048 return SML_COMMAND_TYPE_REPLACE;
00049 } else if (!strcmp(name, SML_ELEMENT_MAP)) {
00050 return SML_COMMAND_TYPE_MAP;
00051 } else if (!strcmp(name, SML_ELEMENT_DELETE)) {
00052 return SML_COMMAND_TYPE_DELETE;
00053 } else if (!strcmp(name, SML_ELEMENT_RESULTS)) {
00054 return SML_COMMAND_TYPE_RESULTS;
00055 } else if (!strcmp(name, SML_ELEMENT_GET)) {
00056 return SML_COMMAND_TYPE_GET;
00057 }
00058
00059 smlErrorSet(error, SML_ERROR_GENERIC, "Unknown command name \"%s\"", name);
00060 return SML_COMMAND_TYPE_UNKNOWN;
00061 }
00062
00063 const char *smlCommandTypeToString(SmlCommandType type, SmlError **error)
00064 {
00065 CHECK_ERROR_REF
00066 switch (type) {
00067 case SML_COMMAND_TYPE_ALERT:
00068 return SML_ELEMENT_ALERT;
00069 case SML_COMMAND_TYPE_SYNC:
00070 return SML_ELEMENT_SYNC;
00071 case SML_COMMAND_TYPE_PUT:
00072 return SML_ELEMENT_PUT;
00073 case SML_COMMAND_TYPE_HEADER:
00074 return SML_ELEMENT_SYNCHDR;
00075 case SML_COMMAND_TYPE_ADD:
00076 return SML_ELEMENT_ADD;
00077 case SML_COMMAND_TYPE_REPLACE:
00078 return SML_ELEMENT_REPLACE;
00079 case SML_COMMAND_TYPE_DELETE:
00080 return SML_ELEMENT_DELETE;
00081 case SML_COMMAND_TYPE_MAP:
00082 return SML_ELEMENT_MAP;
00083 case SML_COMMAND_TYPE_GET:
00084 return SML_ELEMENT_GET;
00085 case SML_COMMAND_TYPE_RESULTS:
00086 return SML_ELEMENT_RESULTS;
00087 default:
00088 ;
00089 }
00090
00091 smlErrorSet(error, SML_ERROR_GENERIC, "Unknown command type \"%i\"", type);
00092 return NULL;
00093 }
00094
00095 SmlStatus *smlStatusNew(SmlErrorType data, unsigned int cmdref, unsigned int msgref, SmlLocation *sourceref, SmlLocation *targetref, SmlCommandType type, SmlError **error)
00096 {
00097 smlTrace(TRACE_ENTRY, "%s(%i, %i, %i, %p, %p, %i, %p)", __func__, data, cmdref, msgref, sourceref, targetref, type, error);
00098 CHECK_ERROR_REF
00099 SmlStatus *status = smlTryMalloc0(sizeof(SmlStatus), error);
00100 if (!status)
00101 goto error;
00102
00103 status->refCount = 1;
00104 status->cmdRef = cmdref;
00105 status->msgRef = msgref;
00106 status->type = type;
00107 if (data != SML_ERROR_UNKNOWN)
00108 status->data = g_strdup_printf("%i", data);
00109
00110 if (sourceref) {
00111 status->sourceRef = sourceref;
00112 smlLocationRef(sourceref);
00113 }
00114
00115 if (targetref) {
00116 status->targetRef = targetref;
00117 smlLocationRef(targetref);
00118 }
00119
00120 smlTrace(TRACE_EXIT, "%s: %p", __func__, status);
00121 return status;
00122
00123 error:
00124 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00125 return NULL;
00126 }
00127
00128 SmlStatus *smlStatusRef(SmlStatus *status)
00129 {
00130 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, status);
00131 smlAssert(status);
00132
00133 g_atomic_int_inc(&(status->refCount));
00134
00135 smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, status->refCount);
00136 return status;
00137 }
00138
00139 void smlStatusUnref(SmlStatus *status)
00140 {
00141 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, status);
00142 smlAssert(status);
00143
00144 if (g_atomic_int_dec_and_test(&(status->refCount))) {
00145 smlTrace(TRACE_INTERNAL, "%s: Refcount == 0!", __func__);
00146
00147 if (status->sourceRef)
00148 smlLocationUnref(status->sourceRef);
00149
00150 if (status->targetRef)
00151 smlLocationUnref(status->targetRef);
00152
00153 if (status->data)
00154 smlSafeCFree(&(status->data));
00155
00156 if (status->anchor)
00157 smlAnchorFree(status->anchor);
00158
00159 if (status->item)
00160 smlItemUnref(status->item);
00161
00162 smlSafeFree((gpointer *)&status);
00163 }
00164
00165 smlTrace(TRACE_EXIT, "%s", __func__);
00166 }
00167
00168 SmlErrorType smlStatusGetCode(SmlStatus *status)
00169 {
00170 smlAssert(status);
00171 smlAssert(status->data);
00172 return atoi(status->data);
00173 }
00174
00175 SmlErrorClass smlStatusGetClass(SmlStatus *status)
00176 {
00177 smlAssert(status);
00178 smlAssert(status->data);
00179 return (atoi(status->data) / 100);
00180 }
00181
00182 SmlCommand *smlStatusGetResult(SmlStatus *status)
00183 {
00184 if (status->type == SML_COMMAND_TYPE_RESULTS)
00185 return status->result;
00186 return NULL;
00187 }
00188
00189 SmlBool smlStatusIsResult(SmlStatus *status)
00190 {
00191 return status->type == SML_COMMAND_TYPE_RESULTS ? TRUE : FALSE;
00192 }
00193
00194 SmlCommand *smlCommandNew(SmlCommandType type, SmlError **error)
00195 {
00196 smlTrace(TRACE_ENTRY, "%s(%i, %p)", __func__, type, error);
00197 CHECK_ERROR_REF
00198
00199 SmlCommand *cmd = smlTryMalloc0(sizeof(SmlCommand), error);
00200 if (!cmd)
00201 goto error;
00202
00203 cmd->refCount = 1;
00204 cmd->type = type;
00205
00206 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00207 return cmd;
00208
00209 error:
00210 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00211 return NULL;
00212 }
00213
00214 SmlStatus *smlCommandNewReply(const SmlCommand *cmd, SmlErrorType code, SmlError **error)
00215 {
00216 smlTrace(TRACE_ENTRY, "%s(%p, %i, %p)", __func__, cmd, code, error);
00217 CHECK_ERROR_REF
00218 smlAssert(cmd);
00219
00220 SmlStatus *reply = smlStatusNew(code, cmd->cmdID, cmd->msgID, cmd->source, cmd->target, cmd->type, error);
00221 if (!reply)
00222 goto error;
00223
00224 switch (cmd->type) {
00225 case SML_COMMAND_TYPE_ALERT:
00226 if (cmd->private.alert.anchor) {
00227 reply->anchor = smlAnchorNew(NULL, cmd->private.alert.anchor->next, error);
00228 if (!reply->anchor)
00229 goto error;
00230 }
00231 break;
00232 default:
00233 ;
00234 }
00235
00236 smlTrace(TRACE_EXIT, "%s: %p", __func__, reply);
00237 return reply;
00238
00239 error:
00240 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00241 return NULL;
00242 }
00243
00244 SmlCommand *smlCommandNewResult(SmlCommand *cmd, SmlLocation *source, char *data, unsigned int size, const char *contenttype, SmlError **error)
00245 {
00246 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %s, %p)", __func__, cmd, source, data, size, VA_STRING(contenttype), error);
00247 CHECK_ERROR_REF
00248 smlAssert(cmd);
00249
00250 SmlCommand *result = smlCommandNew(SML_COMMAND_TYPE_RESULTS, error);
00251 if (!result)
00252 goto error;
00253
00254 result->private.results.status = smlStatusNew(SML_NO_ERROR, cmd->cmdID, cmd->msgID, cmd->source, cmd->target, SML_COMMAND_TYPE_RESULTS, error);
00255 if (!result->private.results.status)
00256 goto error_free_cmd;
00257
00258 result->private.results.status->item = smlItemNewForData(data, size, error);
00259 smlSafeCFree(&data);
00260 if (!result->private.results.status->item)
00261 goto error_free_cmd;
00262
00263 result->private.results.status->item->contenttype = g_strdup(contenttype);
00264 result->private.results.status->item->source = smlLocationClone(source, error);
00265
00266 if (!result->private.results.status->item->source)
00267 goto error_free_cmd;
00268
00269 smlTrace(TRACE_EXIT, "%s: %p", __func__, result);
00270 return result;
00271
00272 error_free_cmd:
00273 smlCommandUnref(result);
00274 error:
00275 if (data)
00276 smlSafeCFree(&data);
00277 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00278 return NULL;
00279 }
00280
00281 SmlCommand *smlCommandRef(SmlCommand *cmd)
00282 {
00283 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, cmd);
00284 smlAssert(cmd);
00285
00286 g_atomic_int_inc(&(cmd->refCount));
00287
00288 smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, cmd->refCount);
00289 return cmd;
00290 }
00291
00292 void smlCommandUnref(SmlCommand *cmd)
00293 {
00294 smlTrace(TRACE_ENTRY, "%s(%p)", __func__, cmd);
00295 smlAssert(cmd);
00296
00297 if (g_atomic_int_dec_and_test(&(cmd->refCount))) {
00298 smlTrace(TRACE_INTERNAL, "%s: Refcount == 0!", __func__);
00299
00300 if (cmd->parent) {
00301 cmd->parent->children = g_list_remove(cmd->parent->children, cmd);
00302
00303 smlCommandUnref(cmd->parent);
00304 cmd->parent = NULL;
00305 }
00306
00307 switch (cmd->type) {
00308 case SML_COMMAND_TYPE_UNKNOWN:
00309 case SML_COMMAND_TYPE_HEADER:
00310 case SML_COMMAND_TYPE_SYNC:
00311 break;
00312 case SML_COMMAND_TYPE_ALERT:
00313 if (cmd->private.alert.anchor)
00314 smlAnchorFree(cmd->private.alert.anchor);
00315 if (cmd->private.alert.contentType)
00316 smlSafeCFree(&(cmd->private.alert.contentType));
00317 break;
00318 case SML_COMMAND_TYPE_PUT:
00319 case SML_COMMAND_TYPE_GET:
00320 if (cmd->private.access.type)
00321 smlSafeCFree(&(cmd->private.access.type));
00322
00323 if (cmd->private.access.item)
00324 smlItemUnref(cmd->private.access.item);
00325 break;
00326 case SML_COMMAND_TYPE_ADD:
00327 case SML_COMMAND_TYPE_REPLACE:
00328 case SML_COMMAND_TYPE_DELETE:
00329 if (cmd->private.change.items)
00330 {
00331 guint i;
00332 for (i = 0; i < g_list_length(cmd->private.change.items); i++)
00333 {
00334 SmlItem *item = g_list_nth_data(cmd->private.change.items, i);
00335 smlItemUnref(item);
00336 }
00337 g_list_free(cmd->private.change.items);
00338 }
00339 break;
00340 case SML_COMMAND_TYPE_MAP:
00341 while (cmd->private.map.items) {
00342 SmlMapItem *item = cmd->private.map.items->data;
00343 smlMapItemUnref(item);
00344 cmd->private.map.items = g_list_delete_link(cmd->private.map.items, cmd->private.map.items);
00345 }
00346 break;
00347 case SML_COMMAND_TYPE_RESULTS:
00348 if (cmd->private.results.status)
00349 smlStatusUnref(cmd->private.results.status);
00350 break;
00351 }
00352
00353 if (cmd->target)
00354 smlLocationUnref(cmd->target);
00355
00356 if (cmd->source)
00357 smlLocationUnref(cmd->source);
00358
00359 smlSafeFree((gpointer *)&cmd);
00360 }
00361
00362 smlTrace(TRACE_EXIT, "%s", __func__);
00363 }
00364
00365 SmlCommand *smlCommandNewChange(SmlChangeType type, const char *uid, const char *data, unsigned int size, const char *contenttype, SmlError **error)
00366 {
00367 smlTrace(TRACE_ENTRY, "%s(%i, %s, %p, %i, %s, %p)", __func__, type, VA_STRING(uid), data, size, VA_STRING(contenttype), error);
00368 CHECK_ERROR_REF
00369 SmlCommand *cmd = NULL;
00370
00371 switch (type) {
00372 case SML_CHANGE_ADD:
00373 cmd = smlCommandNew(SML_COMMAND_TYPE_ADD, error);
00374 break;
00375 case SML_CHANGE_REPLACE:
00376 cmd = smlCommandNew(SML_COMMAND_TYPE_REPLACE, error);
00377 break;
00378 case SML_CHANGE_DELETE:
00379 cmd = smlCommandNew(SML_COMMAND_TYPE_DELETE, error);
00380 break;
00381 default:
00382 smlErrorSet(error, SML_ERROR_GENERIC, "Unknown changetype");
00383 }
00384 if (!cmd)
00385 goto error;
00386
00387 SmlItem *item = smlItemNewForData(data, size, error);
00388 if (!item)
00389 goto error_free_cmd;
00390 cmd->private.change.items = g_list_append(NULL, item);
00391 if (!cmd->private.change.items)
00392 {
00393 smlItemUnref(item);
00394 goto error_free_cmd;
00395 }
00396
00397 SmlLocation *loc = smlLocationNew(uid, NULL, error);
00398 if (!loc)
00399 goto error_free_cmd;
00400
00401
00402
00403
00404
00405
00406
00407 item->source = loc;
00408 if (type != SML_CHANGE_ADD) {
00409
00410
00411
00412 smlLocationRef(loc);
00413 item->target = loc;
00414 }
00415
00416 item->contenttype = g_strdup(contenttype);
00417
00418 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00419 return cmd;
00420
00421 error_free_cmd:
00422 smlCommandUnref(cmd);
00423 error:
00424 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00425 return NULL;
00426 }
00427
00433 SmlCommand *smlCommandNewPartialChange(SmlChangeType type, const char *uid, const char *data, unsigned int complete_size, unsigned int partial_size, const char *contenttype, SmlError **error)
00434 {
00435 smlTrace(TRACE_ENTRY, "%s(%i, %s, %p, %i, %i, %s, %p)", __func__, type, VA_STRING(uid), data, complete_size, partial_size, VA_STRING(contenttype), error);
00436 CHECK_ERROR_REF
00437 SmlCommand *cmd = NULL;
00438
00439 switch (type) {
00440 case SML_CHANGE_ADD:
00441 cmd = smlCommandNew(SML_COMMAND_TYPE_ADD, error);
00442 break;
00443 case SML_CHANGE_REPLACE:
00444 cmd = smlCommandNew(SML_COMMAND_TYPE_REPLACE, error);
00445 break;
00446 case SML_CHANGE_DELETE:
00447 cmd = smlCommandNew(SML_COMMAND_TYPE_DELETE, error);
00448 break;
00449 default:
00450 smlErrorSet(error, SML_ERROR_GENERIC, "Unknown changetype");
00451 }
00452 if (!cmd)
00453 goto error;
00454 cmd->size = complete_size;
00455
00456 SmlItem *item = smlItemNewForData(data, partial_size, error);
00457 if (!item)
00458 goto error_free_cmd;
00459 cmd->private.change.items = g_list_append(NULL, item);
00460 if (!cmd->private.change.items)
00461 {
00462 smlItemUnref(item);
00463 goto error_free_cmd;
00464 }
00465
00466 SmlLocation *loc = smlLocationNew(uid, NULL, error);
00467 if (!loc)
00468 goto error_free_cmd;
00469
00470 if (type != SML_CHANGE_ADD)
00471 item->target = loc;
00472 else
00473 item->source = loc;
00474
00475 item->moreData = TRUE;
00476 item->contenttype = g_strdup(contenttype);
00477
00478 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00479 return cmd;
00480
00481 error_free_cmd:
00482 smlCommandUnref(cmd);
00483 error:
00484 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00485 return NULL;
00486 }
00487
00488 SmlCommand *smlCommandNewAlert(SmlAlertType type, SmlLocation *target, SmlLocation *source, const char *next, const char *last, const char *contenttype, SmlError **error)
00489 {
00490 smlTrace(TRACE_ENTRY, "%s(%i, %p, %p, %s, %s, %s, %p)", __func__, type, target, source, VA_STRING(next), VA_STRING(last), VA_STRING(contenttype), error);
00491 CHECK_ERROR_REF
00492
00493 SmlCommand *cmd = smlCommandNew(SML_COMMAND_TYPE_ALERT, error);
00494 if (!cmd)
00495 goto error;
00496
00497 if (target) {
00498 cmd->target = target;
00499 smlLocationRef(target);
00500 }
00501
00502 if (source) {
00503 cmd->source = source;
00504 smlLocationRef(source);
00505 }
00506
00507
00508
00509
00510
00511 if (type != SML_ALERT_NEXT_MESSAGE && type != SML_ALERT_TWO_WAY_BY_SERVER) {
00512
00513
00514
00515
00516
00517
00518 if (type == SML_ALERT_SLOW_SYNC) {
00519 if (last)
00520 smlTrace(TRACE_INTERNAL,
00521 "%s: removing last anchor (%s) from slow sync alert",
00522 __func__, VA_STRING(last));
00523 cmd->private.alert.anchor = smlAnchorNew(NULL, next, error);
00524 } else
00525 cmd->private.alert.anchor = smlAnchorNew(last, next, error);
00526 if (!cmd->private.alert.anchor)
00527 goto error;
00528 }
00529 cmd->private.alert.type = type;
00530 cmd->private.alert.contentType = g_strdup(contenttype);
00531
00532 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00533 return cmd;
00534
00535 error:
00536 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00537 return NULL;
00538 }
00539
00540 SmlCommand *smlCommandNewSync(SmlLocation *target, SmlLocation *source, unsigned int num_changes, SmlError **error)
00541 {
00542 smlTrace(TRACE_ENTRY, "%s(%p, %p, %i, %p)", __func__, target, source, num_changes, error);
00543 CHECK_ERROR_REF
00544 SmlCommand *cmd = smlCommandNew(SML_COMMAND_TYPE_SYNC, error);
00545 if (!cmd)
00546 goto error;
00547
00548 cmd->target = target;
00549 smlLocationRef(target);
00550
00551 cmd->source = source;
00552 smlLocationRef(source);
00553
00554 cmd->private.sync.numChanged = num_changes;
00555
00556 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00557 return cmd;
00558
00559 error:
00560 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00561 return NULL;
00562 }
00563
00564 SmlCommand *smlCommandNewPut(SmlLocation *target, SmlLocation *source, const char *data, unsigned int size, const char *contenttype, SmlError **error)
00565 {
00566 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %s, %p)", __func__, target, source, data, size, VA_STRING(contenttype), error);
00567 CHECK_ERROR_REF
00568
00569 SmlCommand *cmd = smlCommandNew(SML_COMMAND_TYPE_PUT, error);
00570 if (!cmd)
00571 goto error;
00572
00573 cmd->private.access.item = smlItemNewForData(data, size, error);
00574 if (!cmd->private.access.item)
00575 goto error_free_cmd;
00576
00577 if (target) {
00578 cmd->target = target;
00579 smlLocationRef(target);
00580 smlItemSetTarget(cmd->private.access.item, cmd->target);
00581 }
00582
00583 if (source) {
00584 cmd->source = source;
00585 smlLocationRef(source);
00586 smlItemSetSource(cmd->private.access.item, cmd->source);
00587 }
00588
00589 cmd->private.access.item->contenttype = g_strdup(contenttype);
00590
00591 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00592 return cmd;
00593
00594 error_free_cmd:
00595 smlCommandUnref(cmd);
00596 error:
00597 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00598 return NULL;
00599 }
00600
00601 SmlCommand *smlCommandNewGet(SmlLocation *target, const char *contenttype, SmlError **error)
00602 {
00603 smlTrace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, target, VA_STRING(contenttype), error);
00604 CHECK_ERROR_REF
00605 smlAssert(target);
00606
00607 SmlCommand *cmd = smlCommandNew(SML_COMMAND_TYPE_GET, error);
00608 if (!cmd)
00609 goto error;
00610
00611 cmd->private.access.item = smlItemNew(0, error);
00612 if (!cmd->private.access.item)
00613 goto error_free_cmd;
00614
00615 cmd->target = target;
00616 smlLocationRef(target);
00617 smlItemSetTarget(cmd->private.access.item, cmd->target);
00618
00619 cmd->private.access.item->contenttype = g_strdup(contenttype);
00620
00621 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00622 return cmd;
00623
00624 error_free_cmd:
00625 smlCommandUnref(cmd);
00626 error:
00627 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00628 return NULL;
00629 }
00630
00631 SmlCommand *smlCommandNewMap(SmlLocation *target, SmlLocation *source, SmlError **error)
00632 {
00633 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, target, source, error);
00634 CHECK_ERROR_REF
00635
00636 SmlCommand *cmd = smlCommandNew(SML_COMMAND_TYPE_MAP, error);
00637 if (!cmd)
00638 goto error;
00639
00640 cmd->target = target;
00641 smlLocationRef(target);
00642
00643 cmd->source = source;
00644 smlLocationRef(source);
00645
00646 smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd);
00647 return cmd;
00648
00649 error:
00650 smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error));
00651 return NULL;
00652 }
00653
00654 SmlBool smlCommandAddMapItem(SmlCommand *map, SmlMapItem *item, SmlError **error)
00655 {
00656 smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, map, item, error);
00657 CHECK_ERROR_REF
00658 smlAssert(map);
00659 smlAssert(map->type == SML_COMMAND_TYPE_MAP);
00660 smlAssert(item);
00661
00662 smlMapItemRef(item);
00663 map->private.map.items = g_list_append(map->private.map.items, item);
00664
00665 smlTrace(TRACE_EXIT, "%s", __func__);
00666 return TRUE;
00667 }
00668
00669 SmlAlertType smlAlertTypeConvert(unsigned int id, SmlError **error)
00670 {
00671 smlTrace(TRACE_ENTRY, "%s(%u, %p)", __func__, id, error);
00672 CHECK_ERROR_REF
00673
00674 if (id == 0 ||
00675 id == 100 ||
00676 (200 <= id && id <= 210) ||
00677 (221 <= id && id <= 223))
00678 {
00679 SmlAlertType result = (SmlAlertType) id;
00680 smlTrace(TRACE_EXIT, "%s - %u", __func__, result);
00681 return result;
00682 } else {
00683 smlErrorSet(error, SML_ERROR_GENERIC,
00684 "The unknown alert code %u was detected.", id);
00685 smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error));
00686 return SML_ALERT_UNKNOWN;
00687 }
00688 }
00689