You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
(56) |
Apr
(109) |
May
(15) |
Jun
(3) |
Jul
(37) |
Aug
(96) |
Sep
(40) |
Oct
(4) |
Nov
(54) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(47) |
Feb
(30) |
Mar
(102) |
Apr
(120) |
May
(68) |
Jun
(54) |
Jul
(53) |
Aug
(122) |
Sep
(190) |
Oct
(71) |
Nov
(85) |
Dec
(108) |
2007 |
Jan
(72) |
Feb
(190) |
Mar
(53) |
Apr
(101) |
May
(145) |
Jun
(148) |
Jul
(167) |
Aug
(143) |
Sep
(23) |
Oct
(198) |
Nov
(223) |
Dec
(195) |
2008 |
Jan
(100) |
Feb
(129) |
Mar
(79) |
Apr
(77) |
May
(34) |
Jun
(95) |
Jul
(112) |
Aug
(160) |
Sep
(82) |
Oct
(124) |
Nov
(199) |
Dec
(355) |
2009 |
Jan
(436) |
Feb
(89) |
Mar
(298) |
Apr
(189) |
May
(33) |
Jun
(88) |
Jul
(105) |
Aug
(44) |
Sep
(181) |
Oct
(87) |
Nov
(75) |
Dec
(1) |
2010 |
Jan
(63) |
Feb
(21) |
Mar
(3) |
Apr
(1) |
May
(1) |
Jun
(3) |
Jul
(26) |
Aug
(37) |
Sep
(26) |
Oct
(15) |
Nov
(13) |
Dec
|
From: <svn...@op...> - 2009-08-07 17:53:49
|
Author: bellmich Date: Fri Aug 7 19:53:35 2009 New Revision: 1244 URL: http://libsyncml.opensync.org/changeset/1244 Log: - adapted to reduced SmlLocation API - integrated SmlChangeItem (replaces SmlDataSyncChange) Modified: trunk/libsyncml/data_sync_api/data_sync.c trunk/libsyncml/data_sync_api/data_sync.h Modified: trunk/libsyncml/data_sync_api/data_sync.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.c Fri Aug 7 19:52:39 2009 (r1243) +++ trunk/libsyncml/data_sync_api/data_sync.c Fri Aug 7 19:53:35 2009 (r1244) @@ -39,6 +39,7 @@ #include "data_sync_loop.h" #include "transport.h" #include "libsyncml/objects/sml_ds_server.h" +#include "libsyncml/data_sync_api/sml_change_item_internals.h" /* ********************************* */ /* object creation and configuration */ @@ -614,20 +615,23 @@ smlAssert(type); /* create a new change */ - SmlDataSyncChange *change = smlTryMalloc0(sizeof(SmlDataSyncChange), error); - if (!change) - goto error; + SmlChangeItem *change = sml_change_item_new(); /* fill the new change */ - change->type = type; - change->name = g_strdup(name); - change->userdata = userdata; + sml_change_item_set_action(change, type); + SmlLocation *loc = sml_location_new(); + sml_location_set_uri(loc, name); + if (!sml_change_item_set_location(change, loc, error)) + goto error; + sml_change_item_set_userdata (change, userdata); /* determine the datastore */ - change->datastore = smlDataSyncGetDatastoreFromSource(dsObject, source, error); - if (!change->datastore) + SmlDataSyncDatastore *datastore = smlDataSyncGetDatastoreFromSource(dsObject, source, error); + if (!datastore) + goto error; + sml_change_item_set_data_store(change, datastore); + if (!sml_change_item_set_content_type(change, datastore->contentType, error)) goto error; - SmlDataSyncDatastore *datastore = change->datastore; /* copy data */ if (data) { @@ -647,23 +651,12 @@ appClassLength == strlen(SML_CONTENT_TYPE_AUDIO) ) ) { /* binary data must be base64 encoded */ - change->data = g_base64_encode((const unsigned char *) data, size); - if (!change->data) { - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, - "The base 64 encoding of glib failed."); + if (!sml_change_item_set_binary_data(change, data, size, error)) goto error; - } - change->size = strlen(change->data); } else { - change->data = smlTryMalloc0(size+1, error); - if (!change->data) + if (!sml_change_item_set_data(change, data, size, error)) goto error; - memcpy(change->data, data, size); - change->size = size; } - } else { - change->data = NULL; - change->size = 0; } /* append change to datastore */ @@ -731,14 +724,10 @@ int i = 0; for (i = 0; i < num; i++) { - SmlDataSyncChange *change = g_list_nth_data(datastore->changes, i); + SmlChangeItem *change = g_list_nth_data(datastore->changes, i); if (!smlDsSessionQueueChange( datastore->session, - change->type, - change->name, - change->data, - change->size, - datastore->contentType, + change, smlDataSyncChangeStatusCallback, change, error)) @@ -929,15 +918,11 @@ smlDsServerFree(datastore->server); while(datastore->changes) { - SmlDataSyncChange *change = datastore->changes->data; + SmlChangeItem *change = datastore->changes->data; datastore->changes = g_list_remove( datastore->changes, change); - if (change->name) - smlSafeCFree(&(change->name)); - if (change->data) - smlSafeCFree(&(change->data)); - smlSafeFree((gpointer *)&change); + g_object_unref(change); } smlSafeFree((gpointer *)&datastore); Modified: trunk/libsyncml/data_sync_api/data_sync.h ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.h Fri Aug 7 19:52:39 2009 (r1243) +++ trunk/libsyncml/data_sync_api/data_sync.h Fri Aug 7 19:53:35 2009 (r1244) @@ -204,6 +204,7 @@ /*! @brief This internal structure represents exactly one change. */ +/* typedef struct SmlDataSyncChange { SmlDataSyncDatastore *datastore; SmlChangeType type; @@ -212,6 +213,7 @@ gsize size; void *userdata; } SmlDataSyncChange; +*/ void smlDataSyncSendEvent( SmlDataSyncObject *dsObject, |
From: <svn...@op...> - 2009-08-07 17:52:52
|
Author: bellmich Date: Fri Aug 7 19:52:39 2009 New Revision: 1243 URL: http://libsyncml.opensync.org/changeset/1243 Log: - adapted to reduced SmlLocation API - integrated SmlChangeItem API Modified: trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_notification.c trunk/libsyncml/sml_session.c Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/parser/sml_xml_assm.c Fri Aug 7 19:52:39 2009 (r1243) @@ -26,6 +26,7 @@ #include "libsyncml/sml_error_internals.h" #include "libsyncml/data_sync_api/sml_map_item_internals.h" +#include "libsyncml/data_sync_api/sml_change_item_internals.h" #include "sml_xml_assm_internals.h" #include <string.h> @@ -419,35 +420,153 @@ } /* SourceParent */ - if (sml_location_get_parent_uri(smlItemGetSource(item))) { + if (smlItemGetSource(item) && + sml_location_get_parent_uri(smlItemGetSource(item))) { if (!smlLocationAssemble(smlItemGetSource(item), assm, SML_ELEMENT_SOURCE_PARENT, error)) goto error; } /* TargetParent */ - if (sml_location_get_parent_uri(smlItemGetTarget(item))) { + if (smlItemGetTarget(item) && + sml_location_get_parent_uri(smlItemGetTarget(item))) { if (!smlLocationAssemble(smlItemGetTarget(item), assm, SML_ELEMENT_TARGET_PARENT, error)) goto error; } /* Data */ if (smlItemHasData(item)) { - if (item->disabled) { - if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, "", 0, item->raw, error)) - goto error; + char *data = NULL; + gsize size = 0; + if (!smlItemGetData(item, &data, &size, error)) + goto error; + + if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, item->raw, error)) + goto error; + } + + /* MoreData */ + if (item->moreData) { + if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_MOREDATA, "", error)) + goto error; + + assm->moreDataSet = TRUE; + } + + /* End of Item */ + if (!_smlXmlAssemblerEndNode(assm, error)) + goto error; + + smlTrace(TRACE_EXIT, "%s", __func__); + return TRUE; +error: + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); + return FALSE; +} + +gboolean +smlChangeItemAssemble (SmlChangeItem *item, + SmlXmlAssembler *assm, + GError **error) +{ + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, item, assm, error); + CHECK_ERROR_REF + smlAssert(assm); + smlAssert(item); + + if (assm->moreDataSet) { + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, + "Trying to start a new item while last item had more data"); + goto error; + } + + /* Begin of Item */ + if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_ITEM, error)) + goto error; + + /* Item has to deal with four different situations: + * 1. If this is a new item but the remote peer only supports + * the Replace command and the local peer is an OMA DS + * server then the ID/location must be send as target. + * If the local peer is an OMA DS client then nothing + * changes. FYI an OMA DS server must support the Add + * command. + * => Target must be set (Target is the former Source) + * 2. If this is a new item then the local peer only knows + * the ID of the item. + * => Source must be set + * 3. If this is a changed or deleted item and the local peer + * is an OMA DS server then the item must reference the ID + * of the remote peer because of the submitted map. Please + * not that the remote peer as an OMA DS client must only + * know its own ID of the item. The mapping of locations + * (IDs) is the exclusive job of the OMA DS server. + * => Target must be set (Source is optional) + * 4. If this is a changed or deleted item and the local peer + * is an OMA DS client then the item must reference the ID + * of the local peer only because the mapping of locations + * (IDs) must be done by the OMA DS server. + * => Source must be set + */ + gboolean fillSource = TRUE; + SmlSessionType sessionType = assm->session->sessionType; + const char *opt = smlAssemblerGetOption(assm->assembler, "ONLY_REPLACE"); + if (sml_change_item_get_action(item) == SML_CHANGE_ADD) + { + if (opt && atoi(opt) && /* remote peer supports ONLY_REPLACE */ + sessionType == SML_SESSION_TYPE_SERVER) { + /* only Target must be set */ + fillSource = FALSE; } else { - char *data = NULL; - gsize size = 0; - if (!smlItemGetData(item, &data, &size, error)) - goto error; - - if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, item->raw, error)) - goto error; + /* only Source must be set */ + fillSource = TRUE; + } + } else { + if (sessionType == SML_SESSION_TYPE_SERVER) { + /* Target must be set */ + fillSource = FALSE; + } else { + /* only Source must be set */ + fillSource = TRUE; } } + + /* Target */ + if (!fillSource && sml_change_item_get_location(item)) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_TARGET, error)) + goto error; + } + + /* Source */ + if (fillSource && sml_change_item_get_location(item)) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_SOURCE, error)) + goto error; + } + + /* SourceParent */ + if (fillSource && sml_change_item_get_location(item) && + sml_location_get_parent_uri(sml_change_item_get_location(item))) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_SOURCE_PARENT, error)) + goto error; + } + + /* TargetParent */ + if (!fillSource && sml_change_item_get_location(item) && + sml_location_get_parent_uri(sml_change_item_get_location(item))) { + if (!smlLocationAssemble(sml_change_item_get_location(item), assm, SML_ELEMENT_TARGET_PARENT, error)) + goto error; + } + + /* Data */ + if (sml_change_item_get_data(item)) { + const gchar *data = sml_change_item_get_data(item); + gsize size = strlen(data);; + + if (!_smlXmlAssemblerAddData(assm, SML_ELEMENT_DATA, data, size, FALSE, error)) + goto error; + } /* MoreData */ - if (item->moreData) { + if (sml_change_item_get_missing_data(item)) { if (!_smlXmlAssemblerAddString(assm, SML_ELEMENT_MOREDATA, "", error)) goto error; @@ -584,14 +703,14 @@ /* libsyncml only supports one item per change command */ smlAssert(g_list_length(change->private.change.items) == 1); - SmlItem *item = g_list_nth_data(change->private.change.items, 0); + SmlChangeItem *item = g_list_nth_data(change->private.change.items, 0); if (!item) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "One item of the item list is NULL."); goto error; } - if (!item->contenttype) { + if (!sml_change_item_get_content_type(item)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing contenttype"); goto error; @@ -601,7 +720,7 @@ if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_META, error)) goto error; - if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, item->contenttype, error)) + if (!_smlXmlAssemblerAddStringNS(assm, SML_ELEMENT_TYPE, SML_NAMESPACE_METINF, sml_change_item_get_content_type(item), error)) goto error; /* We will add the max obj size node, if USE_LARGEOBJECTS is true or not set at all. @@ -622,62 +741,7 @@ //Item(s) - /* Item has to deal with four different situations: - * 1. If this is a new item but the remote peer only supports - * the Replace command and the local peer is an OMA DS - * server then the ID/location must be send as target. - * If the local peer is an OMA DS client then nothing - * changes. FYI an OMA DS server must support the Add - * command. - * => Target must be set (Target is the former Source) - * 2. If this is a new item then the local peer only knows - * the ID of the item. - * => Source must be set - * 3. If this is a changed or deleted item and the local peer - * is an OMA DS server then the item must reference the ID - * of the remote peer because of the submitted map. Please - * not that the remote peer as an OMA DS client must only - * know its own ID of the item. The mapping of locations - * (IDs) is the exclusive job of the OMA DS server. - * => Target must be set (Source is optional) - * 4. If this is a changed or deleted item and the local peer - * is an OMA DS client then the item must reference the ID - * of the local peer only because the mapping of locations - * (IDs) must be done by the OMA DS server. - * => Source must be set - */ - SmlSessionType sessionType = assm->session->sessionType; - opt = smlAssemblerGetOption(assm->assembler, "ONLY_REPLACE"); - if (change->type == SML_COMMAND_TYPE_ADD) - { - if (opt && atoi(opt) && /* remote peer supports ONLY_REPLACE */ - sessionType == SML_SESSION_TYPE_SERVER) { - /* only Target must be set */ - if (item->target) - g_object_unref(item->target); - item->target = item->source; - item->source = NULL; - } else { - /* only Source must be set */ - if (item->target) - g_object_unref(item->target); - item->target = NULL; - } - } else { - if (sessionType == SML_SESSION_TYPE_SERVER) { - /* Target must be set */ - if (item->source) - g_object_unref(item->source); - item->source = NULL; - } else { - /* only Source must be set */ - if (item->target) - g_object_unref(item->target); - item->target = NULL; - } - } - - if (!smlItemAssemble(item, assm, error)) + if (!smlChangeItemAssemble(item, assm, error)) goto error; smlTrace(TRACE_EXIT, "%s", __func__); @@ -866,13 +930,13 @@ } /* SourceParent */ - if (sml_location_get_parent_uri(cmd->source)) { + if (cmd->source && sml_location_get_parent_uri(cmd->source)) { if (!smlLocationAssemble(cmd->source, assm, SML_ELEMENT_SOURCE_PARENT, error)) goto error; } /* TargetParent */ - if (sml_location_get_parent_uri(cmd->target)) { + if (cmd->target && sml_location_get_parent_uri(cmd->target)) { if (!smlLocationAssemble(cmd->target, assm, SML_ELEMENT_TARGET_PARENT, error)) goto error; } Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/parser/sml_xml_parse.c Fri Aug 7 19:52:39 2009 (r1243) @@ -24,7 +24,8 @@ #include <libsyncml/sml_command_internals.h> #include <libsyncml/sml_session_internals.h> #include "libsyncml/sml_error_internals.h" -#include "libsyncml/data_sync_api/sml_location_internals.h" +#include "libsyncml/data_sync_api/sml_location.h" +#include "libsyncml/data_sync_api/sml_change_item_internals.h" #include "sml_xml_parse_internals.h" #include <string.h> @@ -439,19 +440,13 @@ gchar *uri = NULL; if (!_smlXmlParserGetString(parser, &uri, SML_ELEMENT_LOCURI, error)) goto error; - if (!sml_location_set_uri(*location, uri, error)) { - g_free(uri); - goto error; - } + sml_location_set_uri(*location, uri); g_free(uri); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_LOCNAME)) { gchar *name = NULL; if (!_smlXmlParserGetString(parser, &name, SML_ELEMENT_LOCNAME, error)) goto error; - if (!sml_location_set_name(*location, name, error)) { - g_free(name); - goto error; - } + sml_location_set_name(*location, name); g_free(name); } else { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node. expected SyncHdr"); @@ -747,8 +742,7 @@ if (smlItemGetSource(item)) { /* SourceParent already parsed */ - if (!sml_location_set_parent_uri(source, sml_location_get_parent_uri(smlItemGetSource(item)), error)) - goto error; + sml_location_set_parent_uri(source, sml_location_get_parent_uri(smlItemGetSource(item))); } smlItemSetSource(item, source); @@ -760,8 +754,7 @@ if (smlItemGetTarget(item)) { /* TargetParent already parsed */ - if (!sml_location_set_parent_uri(target, sml_location_get_parent_uri(smlItemGetTarget(item)), error)) - goto error; + sml_location_set_parent_uri(target, sml_location_get_parent_uri(smlItemGetTarget(item))); } smlItemSetTarget(item, target); @@ -773,17 +766,14 @@ if (smlItemGetSource(item)) { /* Source already parsed */ - if (!sml_location_set_parent_uri(smlItemGetSource(item), sml_location_get_uri(source), error)) - goto error; + sml_location_set_parent_uri(smlItemGetSource(item), sml_location_get_uri(source)); } else { /* there is no source object until now */ smlItemSetSource(item, source); /* copy uri to parent_uri property */ - if (!sml_location_set_parent_uri(source, sml_location_get_uri(source), error)) - goto error; + sml_location_set_parent_uri(source, sml_location_get_uri(source)); /* delete uri property */ - if (!sml_location_set_uri(source, NULL, error)) - goto error; + sml_location_set_uri(source, NULL); } g_object_unref(source); @@ -794,17 +784,14 @@ if (smlItemGetTarget(item)) { /* Target already parsed */ - if (!sml_location_set_parent_uri(smlItemGetTarget(item), sml_location_get_uri(target), error)) - goto error; + sml_location_set_parent_uri(smlItemGetTarget(item), sml_location_get_uri(target)); } else { /* there is no target object until now */ smlItemSetTarget(item, target); /* copy uri to parent_uri property */ - if (!sml_location_set_parent_uri(target, sml_location_get_uri(target), error)) - goto error; + sml_location_set_parent_uri(target, sml_location_get_uri(target)); /* delete uri property */ - if (!sml_location_set_uri(target, NULL, error)) - goto error; + sml_location_set_uri(target, NULL); } g_object_unref(target); @@ -1103,12 +1090,29 @@ smlAssert(parser); smlAssert(name); char *contenttype = NULL; + SmlLocation *source = NULL; + SmlLocation *target = NULL; *cmd = smlCommandNew(type, error); if (!*cmd) goto error; (*cmd)->refCount = 1; + switch (type) { + case SML_COMMAND_TYPE_ADD: + (*cmd)->private.change.type = SML_CHANGE_ADD; + break; + case SML_COMMAND_TYPE_REPLACE: + (*cmd)->private.change.type = SML_CHANGE_REPLACE; + break; + case SML_COMMAND_TYPE_DELETE: + (*cmd)->private.change.type = SML_CHANGE_DELETE; + break; + default: + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown change type set"); + goto error; + } + while (1) { if (!_smlXmlParserStep(parser)) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Missing nodes"); @@ -1134,10 +1138,72 @@ SmlItem *item = _smlItemParse(parser, *cmd, type, error); if (!item) goto error; - (*cmd)->private.change.items = g_list_append((*cmd)->private.change.items, item); + + /* convert SmlItem to SmlChangeItem */ + + SmlChangeItem *citem = sml_change_item_new(); + if (!citem) { + smlItemUnref(item); + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new instance of SmlChangeItem - out of memory."); + goto error; + } + sml_change_item_set_action(citem, (*cmd)->private.change.type); + + /* message from OMA DS client: + * - ADD + source URI => automatically mapped item + * - REPLACE/DELETE + source/target URI => mapped item + * message from OMA DS server: + * - ADD + source/target URI => not yet mapped item + * - REPLACE/DELETE + target URI => mapped item + * => first check the target URI for a finally mapped item + * => second check the source URI for a not yet mapped item + */ + if (smlItemGetTarget(item)) { + if (!sml_change_item_set_location(citem, smlItemGetTarget(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + } else { + if (!sml_change_item_set_location(citem, smlItemGetSource(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + } + if (smlItemGetContent(item) && + !sml_change_item_set_data(citem, smlItemGetContent(item), smlItemGetSize(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + if (smlItemGetContentType(item) && + !sml_change_item_set_content_type(citem, smlItemGetContentType(item), error)) { + smlItemUnref(item); + g_object_unref(citem); + goto error; + } + if (smlItemGetMoreData(item)) { + sml_change_item_set_missing_data(citem, TRUE); + sml_change_item_set_planned_size(citem, (*cmd)->size); + } + if (!source && smlItemGetSource(item)) { + source = smlItemGetSource(item); + g_object_ref(source); + } + if (!target && smlItemGetTarget(item)) { + target = smlItemGetTarget(item); + g_object_ref(target); + } + smlItemUnref(item); + item = NULL; + + /* add item to list of items */ + + (*cmd)->private.change.items = g_list_append((*cmd)->private.change.items, citem); if (!(*cmd)->private.change.items) { - smlItemUnref(item); + g_object_unref(citem); g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "g_list_append for item list of change command failed."); goto error; } @@ -1165,54 +1231,35 @@ guint i; for (i=0; i < g_list_length((*cmd)->private.change.items); i++) { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, i); - if (item->contenttype == NULL && contenttype) { - item->contenttype = g_strdup(contenttype); + SmlChangeItem *item = g_list_nth_data((*cmd)->private.change.items, i); + if (sml_change_item_get_content_type(item) == NULL && + contenttype && + !sml_change_item_set_content_type(item, contenttype, error)) { + goto error; } } if (contenttype) smlSafeCFree(&contenttype); - for (i=0; i < g_list_length((*cmd)->private.change.items); i++) - { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, i); - if ((*cmd)->size && !item->size) - item->size = (*cmd)->size; - } + //for (i=0; i < g_list_length((*cmd)->private.change.items); i++) + //{ + // SmlItem *item = g_list_nth_data((*cmd)->private.change.items, i); + // if ((*cmd)->size && !item->size) + // item->size = (*cmd)->size; + //} - switch (type) { - case SML_COMMAND_TYPE_ADD: - (*cmd)->private.change.type = SML_CHANGE_ADD; - break; - case SML_COMMAND_TYPE_REPLACE: - (*cmd)->private.change.type = SML_CHANGE_REPLACE; - break; - case SML_COMMAND_TYPE_DELETE: - (*cmd)->private.change.type = SML_CHANGE_DELETE; - break; - default: - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown change type set"); - goto error; - } - - if (!(*cmd)->source) + if (!(*cmd)->source && source) { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); - if (item->source) { - (*cmd)->source = sml_location_clone(item->source, error); - if (!(*cmd)->source) - goto error; - } + (*cmd)->source = sml_location_clone(source); + g_object_unref(source); + source = NULL; } - if (!(*cmd)->target) + if (!(*cmd)->target && target) { - SmlItem *item = g_list_nth_data((*cmd)->private.change.items, 0); - if (item->target) { - (*cmd)->target = sml_location_clone(item->target, error); - if (!(*cmd)->target) - goto error; - } + (*cmd)->target = sml_location_clone(target); + g_object_unref(target); + target = NULL; } /* Step once more */ @@ -1229,6 +1276,10 @@ *cmd = NULL; if (contenttype) smlSafeCFree(&contenttype); + if (source) + g_object_unref(source); + if (target) + g_object_unref(target); smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } @@ -1743,7 +1794,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_SOURCEREF, error)) goto error; - (*cmd)->private.results.status->sourceRef = sml_location_new_with_options(locURI, NULL, error); + (*cmd)->private.results.status->sourceRef = sml_location_new(); + sml_location_set_uri((*cmd)->private.results.status->sourceRef, locURI); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->sourceRef) goto error; @@ -1751,7 +1803,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_TARGETREF, error)) goto error; - (*cmd)->private.results.status->targetRef = sml_location_new_with_options(locURI, NULL, error); + (*cmd)->private.results.status->targetRef = sml_location_new(); + sml_location_set_uri((*cmd)->private.results.status->targetRef, locURI); smlSafeCFree(&locURI); if (!(*cmd)->private.results.status->targetRef) goto error; @@ -2610,7 +2663,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_SOURCEREF, error)) goto error; - (*status)->sourceRef = sml_location_new_with_options(locURI, NULL, error); + (*status)->sourceRef = sml_location_new(); + sml_location_set_uri((*status)->sourceRef, locURI); smlSafeCFree(&locURI); if (!(*status)->sourceRef) goto error; @@ -2618,7 +2672,8 @@ if (!_smlXmlParserGetString(parser, &locURI, SML_ELEMENT_TARGETREF, error)) goto error; - (*status)->targetRef = sml_location_new_with_options(locURI, NULL, error); + (*status)->targetRef = sml_location_new(); + sml_location_set_uri((*status)->targetRef, locURI); smlSafeCFree(&locURI); if (!(*status)->targetRef) goto error; Modified: trunk/libsyncml/sml_notification.c ============================================================================== --- trunk/libsyncml/sml_notification.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/sml_notification.c Fri Aug 7 19:52:39 2009 (r1243) @@ -27,7 +27,7 @@ #include "sml_transport.h" #include "sml_md5.h" -#include "data_sync_api/sml_location_internals.h" +#include "data_sync_api/sml_location.h" SmlNotification* smlNotificationNew (SmlNotificationVersion version, @@ -56,9 +56,8 @@ san->sessionType = SML_SESSION_TYPE_SERVER; san->manager = NULL; - san->target = sml_location_new_with_options(target, NULL, error); - if (!san->target) - goto error; + san->target = sml_location_new(); + sml_location_set_uri(san->target, target); smlTrace(TRACE_EXIT, "%s: %p", __func__, san); return san; @@ -385,16 +384,14 @@ */ smlAssert(san->manager); - GError *gerror = NULL; SmlAssembler *assm = NULL; SmlLocation *source = NULL; SmlSession *session = NULL; SmlSanAlert *alert = NULL; SmlCommand *cmd = NULL; - source = sml_location_new_with_options(san->identifier, NULL, &gerror); - if (!source) - goto error; + source = sml_location_new(); + sml_location_set_uri(source, san->identifier); session = smlSessionNew(san->sessionType, san->type, version, SML_PROTOCOL_SYNCML, san->target, source, smlManagerGetNewSessionID(san->manager), 0, error); if (!session) { @@ -419,9 +416,8 @@ alert = a->data; - SmlLocation *loc = sml_location_new_with_options(alert->serverURI, NULL, &gerror); - if (!loc) - goto error; + SmlLocation *loc = sml_location_new(); + sml_location_set_uri(loc, alert->serverURI); cmd = smlCommandNewAlert(SML_ALERT_TWO_WAY_BY_SERVER, NULL, loc, NULL, NULL, alert->contenttype, error); if (!cmd) { Modified: trunk/libsyncml/sml_session.c ============================================================================== --- trunk/libsyncml/sml_session.c Fri Aug 7 19:51:18 2009 (r1242) +++ trunk/libsyncml/sml_session.c Fri Aug 7 19:52:39 2009 (r1243) @@ -31,7 +31,8 @@ #include "sml_transport.h" #include "objects/sml_auth.h" -#include "data_sync_api/sml_location_internals.h" +#include "data_sync_api/sml_location.h" +#include "data_sync_api/sml_change_item_internals.h" /** * @defgroup SmlSessionPrivate SyncML Session Private API @@ -227,10 +228,9 @@ SmlCommand *parent, gsize space, gsize start, - gsize complete_size, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %i, %i, %p)", __func__, session, orig_cmd, parent, space, start, complete_size, error); + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %i, %i, %p)", __func__, session, orig_cmd, parent, space, start, error); CHECK_ERROR_REF /* This library must not send more than one item per change * command. This is compliant with all specification and only a @@ -243,13 +243,10 @@ if (!size) goto error; - // FIXME: should we add an assertion here to guarantee - // FIXME: that size and complete_size are equal - if (space < size - start) { /* We need to create a new command. But we only send as much data as space * is available */ - frag_cmd = smlCommandGetFragment(orig_cmd, start, space, complete_size, error); + frag_cmd = smlCommandGetFragment(orig_cmd, start, space, error); if (!frag_cmd) goto error; @@ -262,7 +259,7 @@ */ /* create fragmentation command */ - frag_cmd = smlCommandGetFragment(orig_cmd, start, size - start, complete_size, error); + frag_cmd = smlCommandGetFragment(orig_cmd, start, size - start, error); if (!frag_cmd) goto error; @@ -328,11 +325,9 @@ */ //smlAssert(g_list_length(cmd->private.change.items) == 1); - char *data = NULL; - gsize size = 0; - SmlItem *item = smlCommandGetNthChange(cmd, 0); - if (!smlItemGetData(item, &data, &size, error)) - goto error; + SmlChangeItem *item = smlCommandGetNthChange(cmd, 0); + smlAssert(sml_change_item_get_data(item)); + gsize size = strlen(sml_change_item_get_data(item)); /* If max obj size is not unlimited (0), and the size of the item is larger * than the max obj size, we have to return an error */ @@ -347,12 +342,12 @@ if (!session->frag_command) smlCommandSetSize(cmd, size); - smlItemSetMoreData(item, TRUE); + sml_change_item_set_missing_data(item, TRUE); gssize space = 0; if (!smlAssemblerGetSpace(session->assembler, &space, parent, cmd, error)) goto error; smlCommandSetSize(cmd, 0); - smlItemSetMoreData(item, FALSE); + sml_change_item_set_missing_data(item, FALSE); /* Check if item data fits into the current message */ if (session->frag_command || @@ -373,7 +368,7 @@ session->frag_userdata = userdata; } - if (!(cmd = _smlSessionFragmentSend(session, session->frag_command, parent, space, session->frag_size, size, error))) + if (!(cmd = _smlSessionFragmentSend(session, session->frag_command, parent, space, session->frag_size, error))) goto error; callback = _smlSessionFragmentStatus; @@ -385,7 +380,7 @@ * reference must be determined again. */ item = smlCommandGetNthChange(cmd, 0); - if (smlItemGetMoreData(item) == FALSE) { + if (sml_change_item_get_missing_data(item) == FALSE) { smlTrace(TRACE_INTERNAL, "%s: This is the last chunk", __func__); callback = session->frag_callback; @@ -712,12 +707,9 @@ } /* build the new target and publish it*/ - session->target = sml_location_new_with_options( - smlHeaderGetResponseURI(header), - sml_location_get_name(session->orgTarget), - error); - if (!session->target) - goto error; + session->target = sml_location_new(); + sml_location_set_uri(session->target, smlHeaderGetResponseURI(header)); + sml_location_set_name(session->target, sml_location_get_name(session->orgTarget)); smlSessionDispatchEvent(session, SML_SESSION_EVENT_RESPONSE_URI, NULL, NULL, NULL, NULL); smlTrace(TRACE_INTERNAL, "%s: RespURI: %s, Target: %s", __func__, VA_STRING(sml_location_get_uri(session->target)), @@ -741,8 +733,7 @@ smlTrace(TRACE_INTERNAL, "%s: update session target to header source %s", __func__, header_source); - if (!sml_location_set_uri(session->target, header_source, error)) - goto error; + sml_location_set_uri(session->target, header_source); } } smlTrace(TRACE_EXIT, "%s", __func__); @@ -1223,7 +1214,7 @@ /* Here we catch changes with moreData set */ if (smlCommandGetType(cmd) == SML_COMMAND_TYPE_ADD || smlCommandGetType(cmd) == SML_COMMAND_TYPE_REPLACE) { - SmlItem *lastItem = smlCommandGetNthChange(cmd, smlCommandGetNumChanges(cmd)-1); + SmlChangeItem *lastItem = smlCommandGetNthChange(cmd, smlCommandGetNumChanges(cmd)-1); if (session->incomingBuffer) { /* There is a command in the incoming buffer. @@ -1250,17 +1241,13 @@ * This includes the moreData flag. * This is a chunk of the previous item in the buffer. */ - char *data = NULL; - gsize size = 0; - SmlItem *item = smlCommandGetNthChange(cmd, 0); + SmlChangeItem *item = smlCommandGetNthChange(cmd, 0); if (!item) goto error; - if (!smlItemGetData(item, &data, &size, error)) - goto error; lastItem = smlCommandGetNthChange(session->incomingBuffer, smlCommandGetNumChanges(session->incomingBuffer) -1); - if (!smlItemAddData(lastItem, data, size, error)) + if (!sml_change_item_attach_fragment(lastItem, item, error)) goto error; - smlItemSetMoreData(lastItem, smlItemGetMoreData(item)); + sml_change_item_set_missing_data(lastItem, sml_change_item_get_missing_data(item)); //smlTrace(TRACE_INTERNAL, // "%s: Appended %i to buffer. Buffer size: %i. Required: %i", // __func__, size, @@ -1274,14 +1261,18 @@ /* If the last item of the command is complete * then the command must be prepared for dispatching. */ - lastItem = smlCommandGetNthChange(session->incomingBuffer, smlCommandGetNumChanges(session->incomingBuffer) -1); - if (!smlItemGetMoreData(lastItem)) { + /* FIXME: Why do we request lastItem for a second time? */ + //lastItem = smlCommandGetNthChange(session->incomingBuffer, smlCommandGetNumChanges(session->incomingBuffer) -1); + if (!sml_change_item_get_missing_data(lastItem)) { smlTrace(TRACE_INTERNAL, "%s: Command buffer complete. Dispatching.", __func__); /* check if the item size is correct */ - if (!smlItemCheck(lastItem)) { + if (sml_change_item_get_planned_size(lastItem) && + (!sml_change_item_get_data(lastItem) || + sml_change_item_get_planned_size(lastItem) != strlen(sml_change_item_get_data(lastItem)))) + { /* We have a size mismatch */ SmlStatus *reply = smlCommandNewReply(cmd, SML_ERROR_SIZE_MISMATCH, error); if (!reply) @@ -1304,7 +1295,7 @@ smlCommandUnref(session->incomingBuffer); session->incomingBuffer = NULL; } - } else if (smlItemGetMoreData(lastItem)) { + } else if (sml_change_item_get_missing_data(lastItem)) { /* There is no buffered command yet. * The new command is copied to the buffer. * This is done by reference copy and @@ -1316,6 +1307,7 @@ "First MoreData item didn't have size set"); goto error; } + smlAssert(sml_change_item_get_planned_size(lastItem)); session->incomingBuffer = cmd; smlCommandRef(cmd); @@ -1323,14 +1315,14 @@ // __func__, // xmlBufferLength(lastItem->buffer), // lastItem->size); - - char *bin = smlPrintBinary(smlItemGetContent(lastItem), smlItemGetSize(lastItem)); + const char *data = sml_change_item_get_data(lastItem); + char *bin = smlPrintBinary(data, strlen(data)); smlTrace(TRACE_INTERNAL, "%s: Content so far: %s\n", __func__, VA_STRING(bin)); smlSafeCFree(&bin); } - if (smlItemGetMoreData(lastItem) == TRUE) { + if (sml_change_item_get_missing_data(lastItem) == TRUE) { smlTrace(TRACE_INTERNAL, "%s: Got item with moreData %i", __func__, smlCommandGetMessageID(cmd)); @@ -1819,10 +1811,7 @@ smlCredUnref(session->cred); session->cred = cred; if (smlCredGetUsername(cred)) { - GError *error = NULL; - sml_location_set_name(session->source, smlCredGetUsername(cred), &error); - if (error) - g_error_free(error); + sml_location_set_name(session->source, smlCredGetUsername(cred)); } smlCredRef(session->cred); } |
From: <svn...@op...> - 2009-08-07 17:51:32
|
Author: bellmich Date: Fri Aug 7 19:51:18 2009 New Revision: 1242 URL: http://libsyncml.opensync.org/changeset/1242 Log: SmlChangeType is part of SmlChangeItem interface. Modified: trunk/libsyncml/data_sync_api/defines.h trunk/libsyncml/data_sync_api/standard.h Modified: trunk/libsyncml/data_sync_api/defines.h ============================================================================== --- trunk/libsyncml/data_sync_api/defines.h Fri Aug 7 19:50:00 2009 (r1241) +++ trunk/libsyncml/data_sync_api/defines.h Fri Aug 7 19:51:18 2009 (r1242) @@ -70,13 +70,6 @@ } SmlAlertType; typedef enum { - SML_CHANGE_UNKNOWN = 0, - SML_CHANGE_ADD = 1, - SML_CHANGE_REPLACE = 2, - SML_CHANGE_DELETE = 3 -} SmlChangeType; - -typedef enum { SML_TRANSPORT_HTTP_SERVER = 1, SML_TRANSPORT_HTTP_CLIENT = 2, SML_TRANSPORT_OBEX_CLIENT = 3, Modified: trunk/libsyncml/data_sync_api/standard.h ============================================================================== --- trunk/libsyncml/data_sync_api/standard.h Fri Aug 7 19:50:00 2009 (r1241) +++ trunk/libsyncml/data_sync_api/standard.h Fri Aug 7 19:51:18 2009 (r1242) @@ -35,6 +35,7 @@ #include <libsyncml/data_sync_api/defines.h> #include <libsyncml/data_sync_api/sml_location.h> +#include <libsyncml/data_sync_api/sml_change_item.h> #include <libsyncml/data_sync_api/sml_map_item.h> #ifdef __cplusplus |
From: <svn...@op...> - 2009-08-07 17:50:14
|
Author: bellmich Date: Fri Aug 7 19:50:00 2009 New Revision: 1241 URL: http://libsyncml.opensync.org/changeset/1241 Log: adapted HTTP client transport to reduced SmlLocation API Modified: trunk/libsyncml/data_sync_api/transport_http_client.c Modified: trunk/libsyncml/data_sync_api/transport_http_client.c ============================================================================== --- trunk/libsyncml/data_sync_api/transport_http_client.c Fri Aug 7 19:49:19 2009 (r1240) +++ trunk/libsyncml/data_sync_api/transport_http_client.c Fri Aug 7 19:50:00 2009 (r1241) @@ -86,20 +86,10 @@ /* create session */ target = sml_location_new(); - if (!target) { - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - goto error; - } - if (!sml_location_set_uri(target, dsObject->target, error)) - g_object_unref(target); + sml_location_set_uri(target, dsObject->target); source = sml_location_new(); - if (!source) { - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - goto error; - } - if (!sml_location_set_uri(source, dsObject->identifier, error)) - g_object_unref(source); + sml_location_set_uri(source, dsObject->identifier); gsize sessionString = smlManagerGetNewSessionID(dsObject->manager); dsObject->session = smlSessionNew(SML_SESSION_TYPE_CLIENT, |
From: <svn...@op...> - 2009-08-07 17:49:32
|
Author: bellmich Date: Fri Aug 7 19:49:19 2009 New Revision: 1240 URL: http://libsyncml.opensync.org/changeset/1240 Log: adapted OMA DS client and server implementation to reduced SmlLocation API Modified: trunk/libsyncml/data_sync_api/data_sync_client.c trunk/libsyncml/data_sync_api/data_sync_server.c Modified: trunk/libsyncml/data_sync_api/data_sync_client.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_client.c Fri Aug 7 19:48:10 2009 (r1239) +++ trunk/libsyncml/data_sync_api/data_sync_client.c Fri Aug 7 19:49:19 2009 (r1240) @@ -127,10 +127,7 @@ "Cannot create new SmlLocation object - out of memory."); goto error; } - if (!sml_location_set_uri(source, datastore->sourceUri, &error)) { - g_object_unref(source); - goto error; - } + sml_location_set_uri(source, datastore->sourceUri); SmlCommand *alert = NULL; alert = smlCommandNewAlert( SML_ALERT_SLOW_SYNC, @@ -342,8 +339,7 @@ g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); goto error; } - if (!sml_location_set_uri(loc, datastore->sourceUri, error)) - goto error; + sml_location_set_uri(loc, datastore->sourceUri); datastore->server = smlDsClientNew(datastore->contentType, loc, loc, error); g_object_unref(loc); Modified: trunk/libsyncml/data_sync_api/data_sync_server.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_server.c Fri Aug 7 19:48:10 2009 (r1239) +++ trunk/libsyncml/data_sync_api/data_sync_server.c Fri Aug 7 19:49:19 2009 (r1240) @@ -258,8 +258,7 @@ g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); goto error; } - if (!sml_location_set_uri(loc, datastore->sourceUri, error)) - goto error; + sml_location_set_uri(loc, datastore->sourceUri); datastore->server = smlDsServerNew(datastore->contentType, loc, error); if (!datastore->server) { |
From: <svn...@op...> - 2009-08-07 17:48:19
|
Author: bellmich Date: Fri Aug 7 19:48:10 2009 New Revision: 1239 URL: http://libsyncml.opensync.org/changeset/1239 Log: - integrated SmlChangeItem interface (replaced SmlDataSyncChange) - fixed bug in event callback (error is a const) which can lead to SegFaults Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.c trunk/libsyncml/data_sync_api/data_sync_callbacks.h Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.c Fri Aug 7 19:46:04 2009 (r1238) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.c Fri Aug 7 19:48:10 2009 (r1239) @@ -30,6 +30,7 @@ #include "data_sync_devinf.h" #include "libsyncml/objects/sml_ds_server.h" #include "libsyncml/sml_manager.h" +#include "sml_change_item_internals.h" /* **************************************** */ /* ***** Management Callbacks ***** */ @@ -39,13 +40,14 @@ SmlManager *manager, SmlManagerEventType type, SmlSession *session, - GError *error, + const GError *error, void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %i, %p, %p, %p)", __func__, manager, type, session, error, userdata); SmlDataSyncObject *dsObject = userdata; smlAssert(dsObject); GList *o = NULL; + GError *locerror = NULL; /* FIXME: Is this lock really needed? */ /* FIXME: Who is allowed to call smlManagerDispatch? */ /* FIXME: The SmlManager must be synchronized and not the callback. */ @@ -91,7 +93,7 @@ dsObject, anchor, datastore->localNext, dsObject->setAnchorUserdata, - &error)) + &locerror)) goto error; anchor = g_strdup_printf( "remoteanchor%s", @@ -100,7 +102,7 @@ dsObject, anchor, datastore->remoteNext, dsObject->setAnchorUserdata, - &error)) + &locerror)) goto error; } } @@ -189,7 +191,7 @@ /* prepare credential */ SmlCred *cred = smlCredNewAuth(dsObject->authType, dsObject->username, dsObject->password, - &error); + &locerror); if (!cred) goto error; smlSessionRegisterCred(dsObject->session, cred); @@ -230,9 +232,9 @@ * the own device information is send and * the remote ones is requested. */ - if (!smlDataSyncManageDevInf(dsObject, TRUE, &error)) + if (!smlDataSyncManageDevInf(dsObject, TRUE, &locerror)) goto error; - if (!smlSessionFlush(dsObject->session, TRUE, &error)) + if (!smlSessionFlush(dsObject->session, TRUE, &locerror)) goto error; break; case SML_PACKAGE_2: /* alerts received by server */ @@ -242,10 +244,10 @@ * the own device information is send and * the remote ones is requested. */ - if (!smlDataSyncManageDevInf(dsObject, TRUE, &error)) + if (!smlDataSyncManageDevInf(dsObject, TRUE, &locerror)) goto error; - if (!smlSessionFlush(dsObject->session, TRUE, &error)) + if (!smlSessionFlush(dsObject->session, TRUE, &locerror)) goto error; smlDataSyncSendEvent( @@ -263,16 +265,16 @@ dsObject->eventUserdata, NULL); break; case SML_PACKAGE_5: /* syncs received by client */ - if (!smlDataSyncSendMap(dsObject, &error)) + if (!smlDataSyncSendMap(dsObject, &locerror)) goto error; - if (!smlSessionFlush(dsObject->session, TRUE, &error)) + if (!smlSessionFlush(dsObject->session, TRUE, &locerror)) goto error; smlDataSyncSendEvent( dsObject, SML_DATA_SYNC_EVENT_GOT_ALL_CHANGES, dsObject->eventUserdata, NULL); break; case SML_PACKAGE_6: /* map received by server */ - if (!smlSessionFlush(dsObject->session, TRUE, &error)) + if (!smlSessionFlush(dsObject->session, TRUE, &locerror)) goto error; break; case SML_PACKAGE_END: /* end received by client */ @@ -280,7 +282,7 @@ /* auto disconnect by library */ break; default: - g_set_error(&error, SML_ERROR, SML_ERROR_NOT_IMPLEMENTED, + g_set_error(&locerror, SML_ERROR, SML_ERROR_NOT_IMPLEMENTED, "The package %d is actually not supported.", dsObject->actualPackage); goto error; @@ -292,8 +294,8 @@ SmlLink *link_ = smlManagerSessionGetLink( dsObject->manager, dsObject->session, - &error); - if (!link_ && error) + &locerror); + if (!link_ && locerror) goto error; /* OBEX is a stateful protocol and the client should * init the disconnect. The problem is what happens @@ -302,7 +304,7 @@ * if (dsObject->tspType != SML_TRANSPORT_OBEX_SERVER && * !smlTransportDisconnect(dsObject->tsp, link, &error)) */ - if (!smlTransportDisconnect(dsObject->tsp, link_, &error)) + if (!smlTransportDisconnect(dsObject->tsp, link_, &locerror)) { if (link_) smlLinkDeref(link_); @@ -338,11 +340,19 @@ return; error: g_mutex_unlock(dsObject->managerMutex); + if (error && locerror) { + /* The locerror is only a resulting error from the original error. */ + g_error_free(locerror); + locerror = NULL; + } + if (locerror) + error = locerror; smlDataSyncSendEvent( dsObject, SML_DATA_SYNC_EVENT_ERROR, dsObject->eventUserdata, error); smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, error->message); - g_error_free(error); + if (locerror) + g_error_free(locerror); } /* *************************************** */ @@ -532,30 +542,29 @@ gboolean smlDataSyncChangeCallback( SmlDsSession *dsession, - SmlChangeType type, - const gchar *uid, - gchar *data, - gsize size, - const gchar *contenttype, + SmlChangeItem *item, void *userdata, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%p, %i, %s, %p, %i, %s, %p, %p)", __func__, dsession, type, VA_STRING(uid), data, size, VA_STRING(contenttype), userdata, error); + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, dsession, item, userdata, error); CHECK_ERROR_REF SmlDataSyncDatastore *datastore = userdata; - smlAssert(type); + smlAssert(item); + smlAssert(sml_change_item_get_action(item)); smlAssert(datastore); smlAssert(datastore->dsObject); smlAssert(datastore->dsObject->changeCallback); /* some mobiles sends replace commands during slow-sync */ if (datastore->alertType == SML_ALERT_SLOW_SYNC && - type == SML_CHANGE_REPLACE) - type = SML_CHANGE_ADD; + sml_change_item_get_action(item) == SML_CHANGE_REPLACE) + sml_change_item_set_action(item, SML_CHANGE_ADD); /* decode base64 data if necessary */ + gchar *data = NULL; + gsize length = 0; size_t appClassLength = ((size_t) index(datastore->contentType, '/')) - ((size_t) datastore->contentType); if ( ( strstr(datastore->contentType, SML_CONTENT_TYPE_APPLICATION) == datastore->contentType && @@ -570,22 +579,23 @@ appClassLength == strlen(SML_CONTENT_TYPE_AUDIO) ) ) { /* binary data must be base64 encoded */ - char *b64data = data; - size_t length = 0; - data = (char *) g_base64_decode(b64data, &length); - size = length; - smlSafeCFree(&b64data); + data = (char *) g_base64_decode(sml_change_item_get_data(item), &length); if (!data) { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The base 64 decoding of glib failed."); goto error; } + } else { + data = g_strdup(sml_change_item_get_data(item)); + length = strlen(data); } /* perform callback */ if (!datastore->dsObject->changeCallback( datastore->dsObject, datastore->sourceUri, - type, uid, data, size, + sml_change_item_get_action(item), + sml_location_get_uri(sml_change_item_get_location(item)), + data, length, datastore->dsObject->changeUserdata, error)) goto error; @@ -608,8 +618,8 @@ GError *error = NULL; smlAssert(userdata); - SmlDataSyncChange *change = userdata; - SmlDataSyncDatastore *datastore = change->datastore; + SmlChangeItem *change = userdata; + SmlDataSyncDatastore *datastore = sml_change_item_get_data_store(change); SmlDataSyncObject *dsObject = datastore->dsObject; smlAssert(dsObject); @@ -617,7 +627,7 @@ !dsObject->changeStatusCallback( dsObject, smlStatusGetCode(status), - change->userdata, &error)) + sml_change_item_get_userdata(change), &error)) goto error; smlTrace(TRACE_EXIT, "%s", __func__); Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.h ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.h Fri Aug 7 19:46:04 2009 (r1238) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.h Fri Aug 7 19:48:10 2009 (r1239) @@ -31,7 +31,7 @@ SmlManager *manager, SmlManagerEventType type, SmlSession *session, - GError *error, + const GError *error, void *userdata); /* *************************************** */ @@ -75,11 +75,7 @@ gboolean smlDataSyncChangeCallback( SmlDsSession *dsession, - SmlChangeType type, - const gchar *uid, - gchar *data, - gsize size, - const gchar *contenttype, + SmlChangeItem *item, void *userdata, GError **error); |
From: <svn...@op...> - 2009-08-07 17:46:23
|
Author: bellmich Date: Fri Aug 7 19:46:04 2009 New Revision: 1238 URL: http://libsyncml.opensync.org/changeset/1238 Log: fixed comment Modified: trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c.tmpl Modified: trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c.tmpl ============================================================================== --- trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c.tmpl Fri Aug 7 19:45:42 2009 (r1237) +++ trunk/libsyncml/dev_inf_api/sml_dev_inf_enum_types.c.tmpl Fri Aug 7 19:46:04 2009 (r1238) @@ -2,7 +2,7 @@ /* WARNING: This file was generated by glib-mkenums. * WARNING: - * WARNING: glib-mkenums --template sml_dev_inf_enum_types.h.tmpl *.h > sml_dev_inf_enum_types.h + * WARNING: glib-mkenums --template sml_dev_inf_enum_types.c.tmpl *.h > sml_dev_inf_enum_types.c * WARNING: * WARNING: If you need to update this file then please run the command again. */ |
From: <svn...@op...> - 2009-08-07 17:45:51
|
Author: bellmich Date: Fri Aug 7 19:45:42 2009 New Revision: 1237 URL: http://libsyncml.opensync.org/changeset/1237 Log: - adapted to reduced SmlLocation API - removed useless smlCommandNewPartialChange - removed no longer needed Disable/EnableChanges feature - integrated SmlChangeItem API Modified: trunk/libsyncml/sml_command.c trunk/libsyncml/sml_command.h Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Fri Aug 7 19:42:46 2009 (r1236) +++ trunk/libsyncml/sml_command.c Fri Aug 7 19:45:42 2009 (r1237) @@ -25,6 +25,7 @@ #include "sml_support.h" #include "parser/sml_xml_assm.h" +#include <libsyncml/data_sync_api/sml_change_item_internals.h> SmlCommandType smlCommandTypeFromString (const gchar *name, @@ -413,8 +414,8 @@ guint i; for (i = 0; i < g_list_length(cmd->private.change.items); i++) { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - smlItemUnref(item); + SmlChangeItem *item = g_list_nth_data(cmd->private.change.items, i); + g_object_unref(item); } g_list_free(cmd->private.change.items); } @@ -445,18 +446,14 @@ } SmlCommand* -smlCommandNewChange (SmlChangeType type, - const gchar *uid, - const gchar *data, - gsize size, - const gchar *contenttype, +smlCommandNewChange (SmlChangeItem *item, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%i, %s, %p, %i, %s, %p)", __func__, type, VA_STRING(uid), data, size, VA_STRING(contenttype), error); + smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, item, error); CHECK_ERROR_REF SmlCommand *cmd = NULL; - switch (type) { + switch (sml_change_item_get_action(item)) { case SML_CHANGE_ADD: cmd = smlCommandNew(SML_COMMAND_TYPE_ADD, error); break; @@ -472,23 +469,12 @@ if (!cmd) goto error; - SmlItem *item = smlItemNewForData(data, size, error); - if (!item) - goto error; cmd->private.change.items = g_list_append(NULL, item); if (!cmd->private.change.items) { - smlItemUnref(item); goto error; } - - SmlLocation *loc = sml_location_new(); - if (!loc) { - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - goto error; - } - if (!sml_location_set_uri(loc, uid, error)) - goto error; + g_object_ref(item); /* The usage of target and source depends on the role of the * local peer. We cannot determine if the local peer is an @@ -496,96 +482,9 @@ * smlDsSessionQueueChange. So the correct usage of target * and source must be ensured by the XML assembler. */ - smlItemSetSource(item, loc); - if (type != SML_CHANGE_ADD) { - /* If this is an Add command then nobody knows - * which ID the remote peer will be use for this item. - */ - g_object_ref(loc); - smlItemSetTarget(item, loc); - } - g_object_unref(loc); - - if (!smlItemSetContentType(item, contenttype, error)) - goto error; - - smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd); - return cmd; - -error: - if (cmd) - smlCommandUnref(cmd); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); - return NULL; -} - -/** Send a fragmented change. You can use this command to fragment a very large change into several - * objects. - * @param complete_size The overall size of the object. must be the sum over all partial_sizes - * @param partial_size The size of this part. - */ -SmlCommand* -smlCommandNewPartialChange (SmlChangeType type, - const gchar *uid, - const gchar *data, - gsize complete_size, - gsize partial_size, - const gchar *contenttype, - GError **error) -{ - 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); - CHECK_ERROR_REF - SmlCommand *cmd = NULL; - - switch (type) { - case SML_CHANGE_ADD: - cmd = smlCommandNew(SML_COMMAND_TYPE_ADD, error); - break; - case SML_CHANGE_REPLACE: - cmd = smlCommandNew(SML_COMMAND_TYPE_REPLACE, error); - break; - case SML_CHANGE_DELETE: - cmd = smlCommandNew(SML_COMMAND_TYPE_DELETE, error); - break; - default: - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown changetype"); - } - if (!cmd) - goto error; - cmd->size = complete_size; - - SmlItem *item = smlItemNewForData(data, partial_size, error); - if (!item) - goto error; - cmd->private.change.items = g_list_append(NULL, item); - if (!cmd->private.change.items) - { - smlItemUnref(item); - goto error; - } - - SmlLocation *loc = sml_location_new(); - if (!loc) { - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - goto error; - } - if (!sml_location_set_uri(loc, uid, error)) - goto error; - - if (type != SML_CHANGE_ADD) { - smlItemSetTarget(item, loc); - } else { - smlItemSetSource(item, loc); - } - g_object_unref(loc); - - smlItemSetMoreData(item, TRUE); - if (!smlItemSetContentType(item, contenttype, error)) - goto error; smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd); return cmd; - error: if (cmd) smlCommandUnref(cmd); @@ -777,14 +676,11 @@ } if (version == SML_DEVINF_VERSION_10) { - if (!sml_location_set_uri(source, "./devinf10", error)) - goto error; + sml_location_set_uri(source, "./devinf10"); } else if (version == SML_DEVINF_VERSION_12) { - if (!sml_location_set_uri(source, "./devinf12", error)) - goto error; + sml_location_set_uri(source, "./devinf12"); } else { - if (!sml_location_set_uri(source, "./devinf11", error)) - goto error; + sml_location_set_uri(source, "./devinf11"); } SmlCommand *result = smlCommandNewResult(cmd, source, data, size, SML_ELEMENT_DEVINF_XML, error); @@ -829,14 +725,11 @@ } if (version == SML_DEVINF_VERSION_10) { - if (!sml_location_set_uri(source, "./devinf10", error)) - goto error; + sml_location_set_uri(source, "./devinf10"); } else if (version == SML_DEVINF_VERSION_12) { - if (!sml_location_set_uri(source, "./devinf12", error)) - goto error; + sml_location_set_uri(source, "./devinf12"); } else { - if (!sml_location_set_uri(source, "./devinf11", error)) - goto error; + sml_location_set_uri(source, "./devinf11"); } if (!source) @@ -887,14 +780,11 @@ } if (version == SML_DEVINF_VERSION_10) { - if (!sml_location_set_uri(target, "./devinf10", error)) - goto error; + sml_location_set_uri(target, "./devinf10"); } else if (version == SML_DEVINF_VERSION_12) { - if (!sml_location_set_uri(target, "./devinf12", error)) - goto error; + sml_location_set_uri(target, "./devinf12"); } else { - if (!sml_location_set_uri(target, "./devinf11", error)) - goto error; + sml_location_set_uri(target, "./devinf11"); } if (!target) @@ -1113,38 +1003,6 @@ return cmd->private.alert.anchor; } -void -smlCommandDisableChanges (SmlCommand *cmd) -{ - smlAssert(cmd); - - if (cmd->private.change.items) - { - guint i; - for (i=0; i < g_list_length(cmd->private.change.items); i++) - { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - smlItemSetDisable(item, TRUE); - } - } -} - -void -smlCommandEnableChanges (SmlCommand *cmd) -{ - smlAssert(cmd); - - if (cmd->private.change.items) - { - guint i; - for (i=0; i < g_list_length(cmd->private.change.items); i++) - { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - smlItemSetDisable(item, FALSE); - } - } -} - /* NumberOfChanges in sync command */ gsize smlCommandGetNumberOfChanges (SmlCommand *cmd) @@ -1160,7 +1018,7 @@ return g_list_length(cmd->private.change.items); } -SmlItem* +SmlChangeItem* smlCommandGetNthChange (SmlCommand *cmd, gsize n) { @@ -1185,44 +1043,34 @@ } gsize -smlCommandGetNthItemSize (SmlCommand *orig_cmd, +smlCommandGetNthItemSize (SmlCommand *cmd, gsize n, GError **error) { - smlAssert(orig_cmd); - - char *data = NULL; - gsize size = 0; + smlAssert(cmd); - SmlItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, n); - if (!smlItemGetData(orig_item, &data, &size, error)) - goto error; - return size; -error: - return 0; + SmlChangeItem *item = g_list_nth_data(cmd->private.change.items, n); + if (!sml_change_item_get_data(item)) + return 0; + return strlen(sml_change_item_get_data(item)); } SmlCommand* smlCommandGetFragment (SmlCommand *orig_cmd, gsize start, gsize space, - gsize complete_size, GError **error) { smlAssert(orig_cmd); - gchar *data = NULL; - gsize size = 0; - SmlItem *frag_item = NULL; + SmlChangeItem *frag_item = NULL; SmlCommand *frag_cmd = NULL; - SmlItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, 0); - if (!smlItemGetData(orig_item, &data, &size, error)) - goto error; + SmlChangeItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, 0); /* create item fragment */ - frag_item = smlItemGetFragment(orig_item, start, space, error); + frag_item = sml_change_item_get_fragment(orig_item, start, space, error); if (!frag_item) goto error; @@ -1244,14 +1092,14 @@ * command. */ if (start == 0) - frag_cmd->size = complete_size; + frag_cmd->size = strlen(sml_change_item_get_data(orig_item)); return frag_cmd; error: if (frag_cmd) smlCommandUnref(frag_cmd); if (frag_item) - smlItemUnref(frag_item); + g_object_unref(frag_item); return NULL; } @@ -1271,7 +1119,7 @@ smlAssert(target); while(1) { - SmlItem *item = g_list_nth_data(source->private.change.items, start); + SmlChangeItem *item = g_list_nth_data(source->private.change.items, start); if (!item) return; target->private.change.items = g_list_append(target->private.change.items, item); @@ -1283,7 +1131,7 @@ smlCommandFreeFirstChange (SmlCommand *cmd) { smlAssert(cmd); - SmlItem *first = smlCommandGetNthChange(cmd, 0); + SmlChangeItem *first = smlCommandGetNthChange(cmd, 0); cmd->private.change.items = g_list_remove(cmd->private.change.items, first); - smlItemUnref(first); + g_object_unref(first); } Modified: trunk/libsyncml/sml_command.h ============================================================================== --- trunk/libsyncml/sml_command.h Fri Aug 7 19:42:46 2009 (r1236) +++ trunk/libsyncml/sml_command.h Fri Aug 7 19:45:42 2009 (r1237) @@ -32,6 +32,7 @@ #include <libsyncml/syncml.h> #include <libsyncml/dev_inf_api/sml_dev_inf.h> +#include <libsyncml/data_sync_api/sml_change_item.h> #include "sml_elements.h" typedef struct SmlCommand SmlCommand; @@ -61,8 +62,7 @@ SmlCommand* smlCommandNewAlert (SmlAlertType type, SmlLocation *target, SmlLocation *source, const gchar *next, const gchar *last, const gchar *contenttype, GError **error); SmlCommand* smlCommandNewSync (SmlLocation *target, SmlLocation *source, gsize num_changes, GError **error); -SmlCommand* smlCommandNewChange (SmlChangeType type, const gchar *uid, const gchar *data, gsize size, const gchar *contenttype, GError **error); -SmlCommand* smlCommandNewPartialChange (SmlChangeType type, const gchar *uid, const gchar *data, gsize complete_size, gsize partial_size, const gchar *contenttype, GError **error); +SmlCommand* smlCommandNewChange (SmlChangeItem *item, GError **error); SmlCommand* smlCommandNewResult (SmlCommand *cmd, SmlLocation *source, gchar *data, gsize size, const gchar *contenttype, GError **error); SmlCommand* smlCommandNewPut (SmlLocation *target, SmlLocation *source, const gchar *data, gsize size, const gchar *contenttype, GError **error); SmlCommand* smlCommandNewGet (SmlLocation *target, const gchar *contenttype, GError **error); @@ -96,20 +96,18 @@ G_CONST_RETURN gchar *smlCommandTypeToString(SmlCommandType type, GError **error); -void smlCommandDisableChanges (SmlCommand *cmd); -void smlCommandEnableChanges (SmlCommand *cmd); -gsize smlCommandGetNumberOfChanges (SmlCommand *cmd); /* NumberOfChanges in sync command */ -gsize smlCommandGetNumChanges (SmlCommand *cmd); /* number of items in change command */ -SmlItem* smlCommandGetNthChange (SmlCommand *cmd, gsize n); -gsize smlCommandGetNumMappings (SmlCommand *cmd); /* number of items in change command */ -SmlMapItem* smlCommandGetNthMapping (SmlCommand *cmd, gsize n); +gsize smlCommandGetNumberOfChanges (SmlCommand *cmd); /* NumberOfChanges in sync command */ +gsize smlCommandGetNumChanges (SmlCommand *cmd); /* number of items in change command */ +SmlChangeItem* smlCommandGetNthChange (SmlCommand *cmd, gsize n); +gsize smlCommandGetNumMappings (SmlCommand *cmd); /* number of items in change command */ +SmlMapItem* smlCommandGetNthMapping (SmlCommand *cmd, gsize n); SmlStatus* smlCommandResultsGetStatus (SmlCommand *cmd); void smlCommandTransferItems (SmlCommand *source, SmlCommand *target, gsize start); void smlCommandFreeFirstChange (SmlCommand *cmd); gsize smlCommandGetNthItemSize (SmlCommand *orig_cmd, gsize n, GError **error); -SmlCommand* smlCommandGetFragment (SmlCommand *orig_cmd, gsize start, gsize space, gsize complete_size, GError **error); +SmlCommand* smlCommandGetFragment (SmlCommand *orig_cmd, gsize start, gsize space, GError **error); #endif //_SML_COMMAND_H_ |
From: <svn...@op...> - 2009-08-07 17:42:59
|
Author: bellmich Date: Fri Aug 7 19:42:46 2009 New Revision: 1236 URL: http://libsyncml.opensync.org/changeset/1236 Log: added missing include Modified: trunk/libsyncml/sml_support.c Modified: trunk/libsyncml/sml_support.c ============================================================================== --- trunk/libsyncml/sml_support.c Fri Aug 7 19:42:16 2009 (r1235) +++ trunk/libsyncml/sml_support.c Fri Aug 7 19:42:46 2009 (r1236) @@ -27,6 +27,10 @@ #include <sys/types.h> #include <unistd.h> +#ifndef _WIN32 +#include <pthread.h> +#endif + GPrivate* current_tabs = NULL; #define G_ERRORCHECK_MUTEXES |
From: <svn...@op...> - 2009-08-07 17:42:29
|
Author: bellmich Date: Fri Aug 7 19:42:16 2009 New Revision: 1235 URL: http://libsyncml.opensync.org/changeset/1235 Log: - moved two functions to public (internal) API - fixed callback interface (missing const provocated an error in DS API) Modified: trunk/libsyncml/sml_manager.h trunk/libsyncml/sml_manager_internals.h Modified: trunk/libsyncml/sml_manager.h ============================================================================== --- trunk/libsyncml/sml_manager.h Fri Aug 7 19:40:49 2009 (r1234) +++ trunk/libsyncml/sml_manager.h Fri Aug 7 19:42:16 2009 (r1235) @@ -52,7 +52,7 @@ /* Always include callbacks after the inclusion of the header files. */ -typedef void (* SmlManagerEventCb) (SmlManager *manager, SmlManagerEventType type, SmlSession *session, GError *error, void *userdata); +typedef void (* SmlManagerEventCb) (SmlManager *manager, SmlManagerEventType type, SmlSession *session, const GError *error, void *userdata); typedef void (* SmlCommandCb) (SmlSession *session, SmlCommand *cmd, void *userdata); typedef void (* SmlHeaderCb) (SmlSession *session, SmlHeader *header, SmlCred *cred, void *userdata); @@ -91,6 +91,9 @@ SmlLink* smlManagerSessionGetLink (SmlManager *manager, SmlSession *session, GError **error); +void smlManagerSessionFinalLockRef (SmlManager *manager, SmlSession *session); +void smlManagerSessionFinalLockUnref (SmlManager *manager, SmlSession *session); + #endif //_SML_MANAGER_H /*@}*/ Modified: trunk/libsyncml/sml_manager_internals.h ============================================================================== --- trunk/libsyncml/sml_manager_internals.h Fri Aug 7 19:40:49 2009 (r1234) +++ trunk/libsyncml/sml_manager_internals.h Fri Aug 7 19:42:16 2009 (r1235) @@ -80,9 +80,6 @@ gchar *contentType; }; -void smlManagerSessionFinalLockRef (SmlManager *manager, SmlSession *session); -void smlManagerSessionFinalLockUnref (SmlManager *manager, SmlSession *session); - #endif //_SML_MANAGER_INTERNALS_H /*@}*/ |
From: <svn...@op...> - 2009-08-07 17:41:03
|
Author: bellmich Date: Fri Aug 7 19:40:49 2009 New Revision: 1234 URL: http://libsyncml.opensync.org/changeset/1234 Log: - updated to reduced SmlLocation API - removed disabled changes feature (replaced with easier direct space calculation) Modified: trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_elements_internals.h trunk/libsyncml/sml_parse.c Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Fri Aug 7 19:38:36 2009 (r1233) +++ trunk/libsyncml/sml_elements.c Fri Aug 7 19:40:49 2009 (r1234) @@ -26,7 +26,7 @@ #include "sml_parse.h" #include "sml_command.h" -#include "data_sync_api/sml_location_internals.h" +#include "data_sync_api/sml_location.h" SmlAnchor* smlAnchorNew (const gchar *last, @@ -370,13 +370,6 @@ } void -smlItemSetDisable (SmlItem *item, - gboolean disable) -{ - item->disabled = disable; -} - -void smlItemSetSource (SmlItem *item, SmlLocation *source) { Modified: trunk/libsyncml/sml_elements.h ============================================================================== --- trunk/libsyncml/sml_elements.h Fri Aug 7 19:38:36 2009 (r1233) +++ trunk/libsyncml/sml_elements.h Fri Aug 7 19:40:49 2009 (r1234) @@ -67,7 +67,6 @@ gsize smlItemGetSize (SmlItem *item); const char* smlItemGetContent (SmlItem *item); gboolean smlItemStealData (SmlItem *item, gchar **data, gsize *size, GError **error); -void smlItemSetDisable (SmlItem *item, gboolean disable); void smlItemSetMoreData (SmlItem *item, gboolean enable); gboolean smlItemGetMoreData (SmlItem *item); Modified: trunk/libsyncml/sml_elements_internals.h ============================================================================== --- trunk/libsyncml/sml_elements_internals.h Fri Aug 7 19:38:36 2009 (r1233) +++ trunk/libsyncml/sml_elements_internals.h Fri Aug 7 19:40:49 2009 (r1234) @@ -52,7 +52,6 @@ gchar *contenttype; gboolean moreData; - gboolean disabled; /** If set to true, libsyncml will omit the cdata tags */ gboolean raw; }; Modified: trunk/libsyncml/sml_parse.c ============================================================================== --- trunk/libsyncml/sml_parse.c Fri Aug 7 19:38:36 2009 (r1233) +++ trunk/libsyncml/sml_parse.c Fri Aug 7 19:40:49 2009 (r1234) @@ -30,7 +30,7 @@ #include "sml_elements.h" #include "sml_notification.h" -#include "data_sync_api/sml_location_internals.h" +#include "data_sync_api/sml_location.h" #include "parser/sml_xml_assm.h" #include "parser/sml_xml_parse.h" @@ -171,9 +171,8 @@ smlNotificationSetManager(san, parser->manager); smlNotificationSetMimeType(san, SML_MIMETYPE_XML); smlNotificationSetSessionType(san, SML_SESSION_TYPE_CLIENT); - SmlLocation *target = sml_location_new_with_options("/", NULL, error); - if (!target) - goto error; + SmlLocation *target = sml_location_new(); + sml_location_set_uri(target, "/"); smlNotificationSetTarget(san, target); g_object_unref(target); target = NULL; @@ -596,6 +595,11 @@ smlAssert(assm->functions.start_cmd); smlAssert(assm->functions.rem_cmd); smlAssert(smlCommandGetType(cmd) == SML_COMMAND_TYPE_ADD || smlCommandGetType(cmd) == SML_COMMAND_TYPE_REPLACE); + /* only one change per command is supported by libsyncml + * It is possible to parse commands with more items + * but it is not supported to send more items than one + */ + smlAssert(smlCommandGetNumChanges(cmd) == 1); unsigned int parentID = 0; gsize limit = smlAssemblerGetRemoteMaxMsgSize(assm); @@ -614,10 +618,6 @@ parentID = smlCommandGetID(parent); } - /* disable the items */ - smlCommandDisableChanges(cmd); - - gboolean noCmdID = FALSE; if (!smlCommandGetID(cmd)) { noCmdID = TRUE; @@ -635,6 +635,12 @@ int size = 0; if (!(size = smlAssemblerCheckSize(assm, FALSE, error))) goto error_remove; + + /* Now calculate the size without the data of the item. + * The data can be splitted into several chunks. + * Please see SupportLargeObj and MoreData. + */ + size -= strlen(sml_change_item_get_data(smlCommandGetNthChange(cmd, 0))); if (limit <= size) *space = 0; @@ -645,9 +651,6 @@ if (!assm->functions.rem_cmd(assm->assm_userdata, parentID, error)) goto error_remove; - /* enable the items again */ - smlCommandEnableChanges(cmd); - if (noCmdID) smlCommandSetID(cmd, 0); @@ -657,7 +660,6 @@ error_remove: assm->functions.rem_cmd(assm->assm_userdata, parentID, NULL); error_enable_item: - smlCommandEnableChanges(cmd); if (noCmdID) smlCommandSetID(cmd, 0); error: |
From: <svn...@op...> - 2009-08-07 17:38:50
|
Author: bellmich Date: Fri Aug 7 19:38:36 2009 New Revision: 1233 URL: http://libsyncml.opensync.org/changeset/1233 Log: updated to reduced SmlLocation API Modified: trunk/libsyncml/objects/sml_devinf_obj.c Modified: trunk/libsyncml/objects/sml_devinf_obj.c ============================================================================== --- trunk/libsyncml/objects/sml_devinf_obj.c Fri Aug 7 19:37:52 2009 (r1232) +++ trunk/libsyncml/objects/sml_devinf_obj.c Fri Aug 7 19:38:36 2009 (r1233) @@ -30,7 +30,7 @@ #include <libsyncml/sml_elements.h> #include <libsyncml/sml_command.h> #include "libsyncml/parser/sml_xml_parse.h" -#include "libsyncml/data_sync_api/sml_location_internals.h" +#include "libsyncml/data_sync_api/sml_location.h" #ifdef WIN32 #include <windef.h> @@ -616,17 +616,14 @@ SmlLocation *devinf11 = NULL; SmlLocation *devinf12 = NULL; - devinf12 = sml_location_new_with_options("./devinf12", NULL, error); - if (!devinf12) - goto error; + devinf12 = sml_location_new(); + sml_location_set_uri(devinf12, "./devinf12"); - devinf11 = sml_location_new_with_options("./devinf11", NULL, error); - if (!devinf12) - goto error; + devinf11 = sml_location_new(); + sml_location_set_uri(devinf11, "./devinf11"); - devinf10 = sml_location_new_with_options("./devinf10", NULL, error); - if (!devinf12) - goto error; + devinf10 = sml_location_new(); + sml_location_set_uri(devinf10, "./devinf10"); /* PUT callbacks * |
From: <svn...@op...> - 2009-08-07 17:38:06
|
Author: bellmich Date: Fri Aug 7 19:37:52 2009 New Revision: 1232 URL: http://libsyncml.opensync.org/changeset/1232 Log: fixed a warning because of a missing include Modified: trunk/libsyncml/objects/sml_auth.c Modified: trunk/libsyncml/objects/sml_auth.c ============================================================================== --- trunk/libsyncml/objects/sml_auth.c Fri Aug 7 19:36:58 2009 (r1231) +++ trunk/libsyncml/objects/sml_auth.c Fri Aug 7 19:37:52 2009 (r1232) @@ -27,6 +27,7 @@ #include <libsyncml/sml_session.h> #include <libsyncml/sml_elements.h> #include <libsyncml/sml_command.h> +#include <libsyncml/sml_md5.h> #include <string.h> |
From: <svn...@op...> - 2009-08-07 17:37:11
|
Author: bellmich Date: Fri Aug 7 19:36:58 2009 New Revision: 1231 URL: http://libsyncml.opensync.org/changeset/1231 Log: updated SmlLocation If something is out of memory then it is a good idea to use g_error because this is a fatal event. Deleted: trunk/libsyncml/data_sync_api/sml_location_internals.h Modified: trunk/libsyncml/data_sync_api/sml_location.c trunk/libsyncml/data_sync_api/sml_location.h trunk/tests/check_data_sync_api_location.c Modified: trunk/libsyncml/data_sync_api/sml_location.c ============================================================================== --- trunk/libsyncml/data_sync_api/sml_location.c Fri Aug 7 19:35:36 2009 (r1230) +++ trunk/libsyncml/data_sync_api/sml_location.c Fri Aug 7 19:36:58 2009 (r1231) @@ -18,8 +18,7 @@ * Boston, MA 02110-1301 USA */ -#include "sml_location_internals.h" -#include "../sml_error_internals.h" +#include "sml_location.h" #include <string.h> G_DEFINE_TYPE (SmlLocation, sml_location, G_TYPE_OBJECT) @@ -173,36 +172,6 @@ } /** - * sml_location_new_with_options: - * - * Creates a new instance of #SmlLocation. - * - * Return value: the newly created #SmlLocation instance - */ -SmlLocation* -sml_location_new_with_options (const gchar* uid, - const gchar* name, - GError **error) -{ - CHECK_ERROR_REF - - SmlLocation *loc = sml_location_new(); - sml_return_val_error_if_fail (SML_IS_LOCATION (loc), NULL, error, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - - if (!sml_location_set_uri(loc, uid, error)) { - g_object_unref(loc); - return NULL; - } - - if (!sml_location_set_name(loc, name, error)) { - g_object_unref(loc); - return NULL; - } - - return loc; -} - -/** * sml_location_get_uri: * @self: A #SmlLocation * @@ -224,13 +193,11 @@ * * Sets the URI property. */ -gboolean +void sml_location_set_uri (SmlLocation *self, - const gchar* uri, - GError **error) + const gchar* uri) { - CHECK_ERROR_REF - sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + g_assert(SML_IS_LOCATION (self)); /* normalize the URI */ if (uri && strlen(uri) == 0) @@ -238,9 +205,8 @@ g_free (self->priv->uri); self->priv->uri = g_strdup (uri); - sml_return_val_error_if_fail (!uri || self->priv->uri, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the URI - out of memory."); - - return TRUE; + if (uri && !self->priv->uri) + g_error("Cannot copy the URI - out of memory."); } /** @@ -265,13 +231,11 @@ * * Sets the name property. */ -gboolean +void sml_location_set_name (SmlLocation *self, - const gchar* name, - GError **error) + const gchar* name) { - CHECK_ERROR_REF - sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + g_assert(SML_IS_LOCATION (self)); /* normalize the name */ if (name && strlen(name) == 0) @@ -279,9 +243,8 @@ g_free (self->priv->name); self->priv->name = g_strdup (name); - sml_return_val_error_if_fail (!name || self->priv->name, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the name - out of memory."); - - return TRUE; + if (name && !self->priv->name) + g_error("Cannot copy the name - out of memory."); } /** @@ -306,13 +269,11 @@ * * Sets the parentURI property. */ -gboolean +void sml_location_set_parent_uri (SmlLocation *self, - const gchar* parent_uri, - GError **error) + const gchar* parent_uri) { - CHECK_ERROR_REF - sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + g_assert(SML_IS_LOCATION (self)); /* normalize the parent URI */ if (parent_uri && strlen(parent_uri) == 0) @@ -320,9 +281,8 @@ g_free (self->priv->parent_uri); self->priv->parent_uri = g_strdup (parent_uri); - sml_return_val_error_if_fail (!parent_uri || self->priv->parent_uri, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the parent URI - out of memory."); - - return TRUE; + if (parent_uri && !self->priv->parent_uri) + g_error("Cannot copy the parent URI - out of memory."); } /** @@ -332,26 +292,19 @@ * */ SmlLocation* -sml_location_clone (SmlLocation *self, - GError **error) +sml_location_clone (SmlLocation *self) { - CHECK_ERROR_REF - sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + g_assert(self); SmlLocation *loc = sml_location_new(); - sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - if (self->priv->uri && !sml_location_set_uri(loc, self->priv->uri, error)) { - g_object_unref(loc); - return NULL; - } - if (self->priv->name && !sml_location_set_name(loc, self->priv->name, error)) { - g_object_unref(loc); - return NULL; - } - if (self->priv->parent_uri && !sml_location_set_parent_uri(loc, self->priv->parent_uri, error)) { - g_object_unref(loc); - return NULL; - } + if (!loc) + g_error("Cannot create new SmlLocation object - out of memory."); + if (self->priv->uri) + sml_location_set_uri(loc, self->priv->uri); + if (self->priv->name) + sml_location_set_name(loc, self->priv->name); + if (self->priv->parent_uri) + sml_location_set_parent_uri(loc, self->priv->parent_uri); return loc; } @@ -365,32 +318,33 @@ static gchar* _sml_location_strreplace (const gchar *input, const gchar *needle, - const gchar *replacement, - GError **error) + const gchar *replacement) { - CHECK_ERROR_REF - sml_return_val_error_if_fail (input, NULL, error, SML_ERROR_GENERIC, "There must be an input string."); - sml_return_val_error_if_fail (strlen(input) > 0, NULL, error, SML_ERROR_GENERIC, "The input string cannot be an empty string."); - sml_return_val_error_if_fail (needle, NULL, error, SML_ERROR_GENERIC, "There must be a needle string."); - sml_return_val_error_if_fail (strlen(needle) > 0, NULL, error, SML_ERROR_GENERIC, "The needle string cannot be an empty string."); + g_assert(input); + g_assert(strlen(input) > 0); + g_assert(needle); + g_assert(strlen(needle) > 0); /* normalize the replacement string */ if (replacement != NULL && strlen(replacement) == 0) replacement = NULL; gchar *output = g_strdup(input); - sml_return_val_error_if_fail (output, NULL, error, SML_ERROR_GENERIC, "Cannot duplicate input string - out of memory."); + if (!output) + g_error("Cannot duplicate input string - out of memory."); /* loop until there is no needle */ while (g_strrstr(output, needle)) { /* copy the string until the position of the needle */ gchar *prefix = g_strndup(output, g_strrstr(output, needle) - output); - sml_return_val_error_if_fail (prefix, NULL, error, SML_ERROR_GENERIC, "Cannot copy string before the needle - out of memory."); + if (!prefix) + g_error("Cannot copy string before the needle - out of memory."); /* concatenate prefix of needle, replacement and suffix of needle */ gchar *buffer2 = g_strconcat(prefix, replacement ? replacement : "", g_strrstr(output, needle) + strlen(needle), NULL); - sml_return_val_error_if_fail (buffer2, NULL, error, SML_ERROR_GENERIC, "Cannot create new string with replacement - out of memory."); + if (!buffer2) + g_error("Cannot create new string with replacement - out of memory."); /* cleanup */ g_free(prefix); @@ -402,22 +356,16 @@ } static gchar* -_sml_location_get_normalized_uri (const gchar *uri, - GError **error) +_sml_location_get_normalized_uri (const gchar *uri) { - CHECK_ERROR_REF - sml_return_val_error_if_fail (uri, NULL, error, SML_ERROR_GENERIC, "There must be an URI."); - sml_return_val_error_if_fail (strlen(uri) > 0, NULL, error, SML_ERROR_GENERIC, "The URI cannot be an empty string."); + g_assert(uri); + g_assert(strlen(uri) > 0); /* remove ./ (e.g. "./Contacts" will be "Contacts") */ - gchar *buffer = _sml_location_strreplace(uri, "./", "", error); - if (!buffer) - return NULL; + gchar *buffer = _sml_location_strreplace(uri, "./", ""); /* replace // from Windows-like systems (e.g. "//Contacts" will be "/Contacts") */ - gchar *buffer2 = _sml_location_strreplace(buffer, "//", "/", error); - if (!buffer2) - return NULL; + gchar *buffer2 = _sml_location_strreplace(buffer, "//", "/"); /* cleanup */ g_free(buffer); @@ -441,11 +389,9 @@ * Return value: */ G_CONST_RETURN gchar* -sml_location_get_full_uri (SmlLocation *self, - GError **error) +sml_location_get_full_uri (SmlLocation *self) { - CHECK_ERROR_REF - sml_return_val_error_if_fail (SML_IS_LOCATION (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlLocation object."); + g_assert(SML_IS_LOCATION (self)); /* cleanup cache */ if (self->priv->full_uri) { @@ -456,20 +402,14 @@ /* normalize URI */ gchar *path = NULL; if (self->priv->uri) { - path = _sml_location_get_normalized_uri(self->priv->uri, error); - if (!path) - return NULL; + path = _sml_location_get_normalized_uri(self->priv->uri); } /* add parent (e.g. TargetRef or SourceRef from hierarchical sync) */ if (self->priv->parent_uri) { /* normalize parent */ - gchar *parent_uri = _sml_location_get_normalized_uri(self->priv->parent_uri, error); - if (!parent_uri) { - g_free(path); - return NULL; - } + gchar *parent_uri = _sml_location_get_normalized_uri(self->priv->parent_uri); /* ensure absolute URI */ if (path && !g_path_is_absolute(path)) { @@ -477,8 +417,7 @@ g_free(path); path = absolute; if (!path) - g_free(parent_uri); - sml_return_val_error_if_fail (path, NULL, error, SML_ERROR_GENERIC, "Cannot add '/' as prefix - out of memory."); + g_error("Cannot add '/' as prefix - out of memory."); } /* prepend the parent */ @@ -486,11 +425,12 @@ g_free(path); g_free(parent_uri); path = parent; - sml_return_val_error_if_fail (path, NULL, error, SML_ERROR_GENERIC, "Cannot add parent as prefix - out of memory."); + if (!path) + g_error("Cannot add parent as prefix - out of memory."); } /* cache the result */ - self->priv->full_uri = _sml_location_get_normalized_uri(path, error); + self->priv->full_uri = _sml_location_get_normalized_uri(path); g_free(path); return self->priv->full_uri; @@ -506,9 +446,8 @@ sml_location_is_equal (SmlLocation *self, SmlLocation *loc) { - g_return_val_if_fail (SML_IS_LOCATION (self), FALSE); + g_assert(self); - GError *error = NULL; gboolean ret = FALSE; if (!loc) @@ -516,19 +455,8 @@ /* normalization */ - const char *loc_path = sml_location_get_full_uri(loc, &error); - if (!loc_path) { - g_warning("%s", error->message); - g_error_free(error); - return FALSE; - } - - const char *self_path = sml_location_get_full_uri(self, &error); - if (!self_path) { - g_warning("%s", error->message); - g_error_free(error); - return FALSE; - } + const char *loc_path = sml_location_get_full_uri(loc); + const char *self_path = sml_location_get_full_uri(self); /* comparison */ Modified: trunk/libsyncml/data_sync_api/sml_location.h ============================================================================== --- trunk/libsyncml/data_sync_api/sml_location.h Fri Aug 7 19:35:36 2009 (r1230) +++ trunk/libsyncml/data_sync_api/sml_location.h Fri Aug 7 19:36:58 2009 (r1231) @@ -53,14 +53,14 @@ GType sml_location_get_type (void); SmlLocation* sml_location_new (void); G_CONST_RETURN gchar* sml_location_get_uri (SmlLocation *self); -gboolean sml_location_set_uri (SmlLocation *self, const gchar* uri, GError **error); +void sml_location_set_uri (SmlLocation *self, const gchar* uri); G_CONST_RETURN gchar* sml_location_get_name (SmlLocation *self); -gboolean sml_location_set_name (SmlLocation *self, const gchar* name, GError **error); +void sml_location_set_name (SmlLocation *self, const gchar* name); G_CONST_RETURN gchar* sml_location_get_parent_uri (SmlLocation *self); -gboolean sml_location_set_parent_uri (SmlLocation *self, const gchar* parent_uri, GError **error); -SmlLocation* sml_location_clone (SmlLocation *self, GError **error); +void sml_location_set_parent_uri (SmlLocation *self, const gchar* parent_uri); +SmlLocation* sml_location_clone (SmlLocation *self); gboolean sml_location_is_equal (SmlLocation *self, SmlLocation *loc); -G_CONST_RETURN gchar* sml_location_get_full_uri (SmlLocation *self, GError **error); +G_CONST_RETURN gchar* sml_location_get_full_uri (SmlLocation *self); G_END_DECLS Modified: trunk/tests/check_data_sync_api_location.c ============================================================================== --- trunk/tests/check_data_sync_api_location.c Fri Aug 7 19:35:36 2009 (r1230) +++ trunk/tests/check_data_sync_api_location.c Fri Aug 7 19:36:58 2009 (r1231) @@ -35,24 +35,21 @@ START_TEST (location_uri) { setup_testbed(NULL); - GError *error = NULL; + SmlLocation *location = sml_location_new(); sml_fail_unless(location != NULL, NULL); sml_fail_unless(sml_location_get_uri(location) == NULL, "The default URI must be NULL."); - sml_fail_unless(sml_location_set_uri(location, NULL, &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(location, NULL); sml_fail_unless(sml_location_get_uri(location) == NULL, "The URI must still be NULL."); - sml_fail_unless(sml_location_set_uri(location, "http://localhost", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(location, "http://localhost"); const gchar *uri = sml_location_get_uri(location); sml_fail_unless(uri != NULL, "The URI is now set."); sml_fail_unless(strcmp(uri, "http://localhost") == 0, "The URI must be set to http://localhost."); - sml_fail_unless(sml_location_set_uri(location, NULL, &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(location, NULL); sml_fail_unless(sml_location_get_uri(location) == NULL, "The URI must be NULL again."); g_object_unref(location); @@ -62,24 +59,21 @@ START_TEST (location_name) { setup_testbed(NULL); - GError *error = NULL; + SmlLocation *location = sml_location_new(); sml_fail_unless(location != NULL, NULL); sml_fail_unless(sml_location_get_name(location) == NULL, "The default name must be NULL."); - sml_fail_unless(sml_location_set_name(location, NULL, &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_name(location, NULL); sml_fail_unless(sml_location_get_name(location) == NULL, "The name must still be NULL."); - sml_fail_unless(sml_location_set_name(location, "John Doe", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_name(location, "John Doe"); const gchar *name = sml_location_get_name(location); sml_fail_unless(name != NULL, "The name is now set."); sml_fail_unless(strcmp(name, "John Doe") == 0, "The name must be set to 'John Doe'."); - sml_fail_unless(sml_location_set_name(location, NULL, &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_name(location, NULL); sml_fail_unless(sml_location_get_name(location) == NULL, "The name must be NULL again."); g_object_unref(location); @@ -89,24 +83,21 @@ START_TEST (location_parent_uri) { setup_testbed(NULL); - GError *error = NULL; + SmlLocation *location = sml_location_new(); sml_fail_unless(location != NULL, NULL); sml_fail_unless(sml_location_get_parent_uri(location) == NULL, "The default parent URI must be NULL."); - sml_fail_unless(sml_location_set_parent_uri(location, NULL, &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(location, NULL); sml_fail_unless(sml_location_get_parent_uri(location) == NULL, "The parent URI must still be NULL."); - sml_fail_unless(sml_location_set_parent_uri(location, "http://localhost", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(location, "http://localhost"); const gchar *parent_uri = sml_location_get_parent_uri(location); sml_fail_unless(parent_uri != NULL, "The parent URI is now set."); sml_fail_unless(strcmp(parent_uri, "http://localhost") == 0, "The parent URI must be set to http://localhost."); - sml_fail_unless(sml_location_set_parent_uri(location, NULL, &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(location, NULL); sml_fail_unless(sml_location_get_parent_uri(location) == NULL, "The parent URI must be NULL again."); g_object_unref(location); @@ -117,17 +108,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc, "./test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc2, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc2, "./test"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -140,17 +127,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc, "./test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc2, "./test2", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc2, "./test2"); sml_fail_unless(!sml_location_is_equal(objloc, objloc2), NULL); @@ -163,17 +146,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc, "/test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc2, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc2, "/test"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -186,17 +165,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc, "/test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_uri(objloc2, "/test2", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_uri(objloc2, "/test2"); sml_fail_unless(!sml_location_is_equal(objloc, objloc2), NULL); @@ -209,17 +184,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "./test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "./test"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -232,17 +203,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "./test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "./test2", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "./test2"); sml_fail_unless(!sml_location_is_equal(objloc, objloc2), NULL); @@ -255,17 +222,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "/test"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -278,17 +241,13 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "/test2", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "/test2"); sml_fail_unless(!sml_location_is_equal(objloc, objloc2), NULL); @@ -301,19 +260,15 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/test"); + sml_location_set_uri(objloc, "./test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc2, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "/test"); + sml_location_set_uri(objloc2, "./test"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -326,19 +281,15 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc, "test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/test"); + sml_location_set_uri(objloc, "test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "/test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc2, "./test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "/test"); + sml_location_set_uri(objloc2, "./test"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -351,19 +302,15 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/test/asd", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc, "test/", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/test/asd"); + sml_location_set_uri(objloc, "test/"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "/test/.//asd//", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc2, "././test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "/test/.//asd//"); + sml_location_set_uri(objloc2, "././test"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -376,19 +323,15 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/test/asd2", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc, "test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/test/asd2"); + sml_location_set_uri(objloc, "test"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "/test/.//asd//", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc2, "././test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "/test/.//asd//"); + sml_location_set_uri(objloc2, "././test"); sml_fail_unless(!sml_location_is_equal(objloc, objloc2), NULL); @@ -401,19 +344,15 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/test/asd", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc, "tes3t", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/test/asd"); + sml_location_set_uri(objloc, "tes3t"); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, "/test/.//asd//", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc2, "././test", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, "/test/.//asd//"); + sml_location_set_uri(objloc2, "././test"); sml_fail_unless(!sml_location_is_equal(objloc, objloc2), NULL); @@ -426,19 +365,15 @@ { setup_testbed(NULL); - GError *error = NULL; - SmlLocation *objloc = sml_location_new(); sml_fail_unless(objloc != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc, "/", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc, "", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc, "/"); + sml_location_set_uri(objloc, ""); SmlLocation *objloc2 = sml_location_new(); sml_fail_unless(objloc2 != NULL, NULL); - sml_fail_unless(sml_location_set_parent_uri(objloc2, ".//", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(sml_location_set_uri(objloc2, "///", &error), "%s", error?error->message:"No GError set."); - sml_fail_unless(error == NULL, NULL); + sml_location_set_parent_uri(objloc2, ".//"); + sml_location_set_uri(objloc2, "///"); sml_fail_unless(sml_location_is_equal(objloc, objloc2), NULL); @@ -451,11 +386,10 @@ { setup_testbed(NULL); - GError *error = NULL; SmlLocation *loc = sml_location_new(); sml_fail_unless(loc != NULL, NULL); - sml_fail_unless(sml_location_set_uri(loc, "test", &error), "%s", error?error->message:"No GError set."); + sml_location_set_uri(loc, "test"); g_object_ref(loc); |
From: <svn...@op...> - 2009-08-07 17:35:50
|
Author: bellmich Date: Fri Aug 7 19:35:36 2009 New Revision: 1230 URL: http://libsyncml.opensync.org/changeset/1230 Log: updated SmlChangeItem stuff to replace SmlDataSyncChange It is necessary to rename this object to SmlDataSyncChangeItem before a release. Added: trunk/libsyncml/data_sync_api/glib_mkenums.sh trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.c trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.c.tmpl trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.h trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.h.tmpl Modified: trunk/libsyncml/data_sync_api/sml_change_item.c trunk/libsyncml/data_sync_api/sml_change_item.h trunk/libsyncml/data_sync_api/sml_change_item_internals.h Added: trunk/libsyncml/data_sync_api/glib_mkenums.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/glib_mkenums.sh Fri Aug 7 19:35:36 2009 (r1230) @@ -0,0 +1,6 @@ +glib-mkenums \ + --fhead "#ifndef __SML_DEV_INF_ENUM_TYPES_H\n#define __SML_DEV_INF_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \ + --fprod "/* enumeration types from \"@filename@\" */\n" \ + --vhead "GType @EnumName@ (void);\n#define @EnumName@ (@EnumName@())\n" \ + --ftail "G_END_DECLS\n\n#endif /* __SML_DEV_INF_ENUM_TYPES_H__ */" \ + sml_dev_inf.h Modified: trunk/libsyncml/data_sync_api/sml_change_item.c ============================================================================== --- trunk/libsyncml/data_sync_api/sml_change_item.c Tue Aug 4 17:27:43 2009 (r1229) +++ trunk/libsyncml/data_sync_api/sml_change_item.c Fri Aug 7 19:35:36 2009 (r1230) @@ -19,6 +19,7 @@ */ #include "sml_change_item_internals.h" +#include "sml_data_sync_enum_types.h" #include "../sml_error_internals.h" #include <string.h> @@ -27,22 +28,26 @@ enum { PROP_0, - PROP_REMOTE, - PROP_LOCAL, + PROP_TYPE, + PROP_LOCATION, PROP_DATA, PROP_PLANNED_SIZE, PROP_CONTENT_TYPE, - PROP_MISSING_DATA + PROP_MISSING_DATA, + PROP_DATA_STORE, + PROP_USERDATA }; struct _SmlChangeItemPrivate { - SmlLocation* remote; - SmlLocation* local; - gchar* data; - guint64 planned_size; - gchar* content_type; - gboolean missing_data; + SmlChangeType type; + SmlLocation* loc; + gchar* data; + guint64 planned_size; + gchar* content_type; + gboolean missing_data; + SmlDataSyncDatastore* data_store; + void* userdata; }; static void @@ -52,11 +57,11 @@ GParamSpec *pspec) { switch (property_id) { - case PROP_REMOTE: - g_value_set_object (value, SML_CHANGE_ITEM (object)->priv->remote); + case PROP_TYPE: + g_value_set_enum (value, SML_CHANGE_ITEM (object)->priv->type); break; - case PROP_LOCAL: - g_value_set_object (value, SML_CHANGE_ITEM (object)->priv->local); + case PROP_LOCATION: + g_value_set_object (value, SML_CHANGE_ITEM (object)->priv->loc); break; case PROP_DATA: g_value_set_string (value, SML_CHANGE_ITEM (object)->priv->data); @@ -70,6 +75,12 @@ case PROP_MISSING_DATA: g_value_set_boolean (value, SML_CHANGE_ITEM (object)->priv->missing_data); break; + case PROP_DATA_STORE: + g_value_set_pointer (value, SML_CHANGE_ITEM (object)->priv->data_store); + break; + case PROP_USERDATA: + g_value_set_pointer (value, SML_CHANGE_ITEM (object)->priv->userdata); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -82,17 +93,14 @@ GParamSpec *pspec) { switch (property_id) { - case PROP_REMOTE: - if (SML_CHANGE_ITEM (object)->priv->remote) - g_object_unref (SML_CHANGE_ITEM (object)->priv->remote); - SML_CHANGE_ITEM (object)->priv->remote = SML_LOCATION (value); - g_object_ref(SML_CHANGE_ITEM (object)->priv->remote); - break; - case PROP_LOCAL: - if (SML_CHANGE_ITEM (object)->priv->local) - g_object_unref (SML_CHANGE_ITEM (object)->priv->local); - SML_CHANGE_ITEM (object)->priv->local = SML_LOCATION (value); - g_object_ref(SML_CHANGE_ITEM (object)->priv->local); + case PROP_TYPE: + SML_CHANGE_ITEM (object)->priv->type = g_value_get_enum (value); + break; + case PROP_LOCATION: + if (SML_CHANGE_ITEM (object)->priv->loc) + g_object_unref (SML_CHANGE_ITEM (object)->priv->loc); + SML_CHANGE_ITEM (object)->priv->loc = SML_LOCATION (value); + g_object_ref(SML_CHANGE_ITEM (object)->priv->loc); break; case PROP_DATA: g_free (SML_CHANGE_ITEM (object)->priv->data); @@ -108,6 +116,12 @@ case PROP_MISSING_DATA: SML_CHANGE_ITEM (object)->priv->missing_data = g_value_get_boolean (value); break; + case PROP_DATA_STORE: + SML_CHANGE_ITEM (object)->priv->data_store = (SmlDataSyncDatastore *) g_value_get_pointer(value); + break; + case PROP_USERDATA: + SML_CHANGE_ITEM (object)->priv->userdata = (void *) g_value_get_pointer(value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -117,18 +131,17 @@ sml_change_item_finalize (GObject *object) { SmlChangeItem *self = (SmlChangeItem *) object; - if (self->priv->remote) - g_object_unref(self->priv->remote); - if (self->priv->local) - g_object_unref(self->priv->local); + if (self->priv->loc) + g_object_unref(self->priv->loc); g_free(self->priv->data); g_free(self->priv->content_type); /* all pointers must be NULL */ - self->priv->remote = NULL; - self->priv->local = NULL; + self->priv->loc = NULL; self->priv->data = NULL; self->priv->planned_size = 0; self->priv->content_type = NULL; + self->priv->data_store = NULL; + self->priv->userdata = NULL; G_OBJECT_CLASS (sml_change_item_parent_class)->finalize (object); } @@ -144,27 +157,15 @@ object_class->finalize = sml_change_item_finalize; /** - * SmlChangeItem:remote: + * SmlChangeItem:location: * - * The remote SmlLocation property. + * The location property. */ g_object_class_install_property (object_class, - PROP_REMOTE, - g_param_spec_object ("remote", - "remote SmlLocation", - "remote SmlLocation", - G_TYPE_OBJECT, - G_PARAM_READWRITE)); - /** - * SmlChangeItem:local: - * - * The local SmlLocation property. - */ - g_object_class_install_property (object_class, - PROP_LOCAL, - g_param_spec_object ("local", - "local SmlLocation", - "local SmlLocation", + PROP_LOCATION, + g_param_spec_object ("location", + "location", + "location", G_TYPE_OBJECT, G_PARAM_READWRITE)); /** @@ -217,6 +218,17 @@ "MoreData flag", FALSE, G_PARAM_READWRITE)); + /** + * SmlChangeItem:data_store: + * + * The data store property. + */ + g_object_class_install_property (object_class, + PROP_DATA_STORE, + g_param_spec_pointer ("data_store", + "data store", + "the used data store", + G_PARAM_READWRITE)); } @@ -242,78 +254,40 @@ } /** - * sml_change_item_get_remote: - * @self: A #SmlChangeItem - * - * Gets the remote SmlLocation property. - * - * Return value: - */ -SmlLocation* -sml_change_item_get_remote (SmlChangeItem *self) -{ - g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), NULL); - return self->priv->remote; -} - -/** - * sml_change_item_set_remote: - * @self: A #SmlChangeItem - * @remote: - * - * Sets the remote SmlLocation property. - */ -gboolean -sml_change_item_set_remote (SmlChangeItem *self, - SmlLocation* remote, - GError **error) -{ - sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); - sml_return_val_error_if_fail (!remote || sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "The location must have an URI."); - - if (self->priv->remote) - g_object_unref (self->priv->remote); - self->priv->remote = remote; - if (remote) - g_object_ref (remote); - return TRUE; -} - -/** - * sml_change_item_get_local: + * sml_change_item_get_location: * @self: A #SmlChangeItem * - * Gets the local SmlLocation property. + * Gets the location property. * * Return value: */ SmlLocation* -sml_change_item_get_local (SmlChangeItem *self) +sml_change_item_get_location (SmlChangeItem *self) { g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), NULL); - return self->priv->local; + return self->priv->loc; } /** - * sml_change_item_set_local: + * sml_change_item_set_location: * @self: A #SmlChangeItem - * @local: + * @loc: * - * Sets the local SmlLocation property. + * Sets the location property. */ gboolean -sml_change_item_set_local (SmlChangeItem *self, - SmlLocation* local, - GError **error) +sml_change_item_set_location (SmlChangeItem *self, + SmlLocation* loc, + GError **error) { sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); - sml_return_val_error_if_fail (!local || sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "The location must have an URI."); + sml_return_val_error_if_fail (!loc || sml_location_get_uri(loc), FALSE, error, SML_ERROR_GENERIC, "The location must have an URI."); - if (self->priv->local) - g_object_unref (self->priv->local); - self->priv->local = local; - if (local) - g_object_ref (local); + if (self->priv->loc) + g_object_unref (self->priv->loc); + self->priv->loc = loc; + if (loc) + g_object_ref (loc); return TRUE; } @@ -364,6 +338,31 @@ } /** + * sml_change_item_set_binary_data: + * @self: A #SmlChangeItem + * @data: + * @size: + * + * Sets the data property. + */ +gboolean +sml_change_item_set_binary_data (SmlChangeItem *self, + const gchar* data, + gsize size, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); + sml_return_val_error_if_fail (size, FALSE, error, SML_ERROR_GENERIC, "The size must be present."); + + g_free (self->priv->data); + self->priv->data = g_base64_encode((const unsigned char *) data, size); + if (!self->priv->data) + g_error("The base 64 encoding of glib failed."); + + return TRUE; +} + +/** * sml_change_item_get_planned_size: * @self: A #SmlChangeItem * @@ -463,6 +462,96 @@ } /** + * sml_change_item_get_action: + * @self: A #SmlChangeItem + * + * Gets the change type property. + * + * Return value: + */ +SmlChangeType +sml_change_item_get_action (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), FALSE); + return self->priv->type; +} + +/** + * sml_change_item_set_action: + * @self: A #SmlChangeItem + * @missing_data: + * + * Sets the change type property. + */ +void +sml_change_item_set_action (SmlChangeItem *self, + SmlChangeType type) +{ + g_return_if_fail (SML_IS_CHANGE_ITEM (self)); + self->priv->type = type; +} + +/** + * sml_change_item_get_data_store: + * @self: A #SmlChangeItem + * + * Gets the data store property. + * + * Return value: + */ +SmlDataSyncDatastore* +sml_change_item_get_data_store (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), FALSE); + return self->priv->data_store; +} + +/** + * sml_change_item_set_data_store: + * @self: A #SmlChangeItem + * @ds: + * + * Sets the change type property. + */ +void +sml_change_item_set_data_store (SmlChangeItem *self, + SmlDataSyncDatastore *ds) +{ + g_return_if_fail (SML_IS_CHANGE_ITEM (self)); + self->priv->data_store = ds; +} + +/** + * sml_change_item_get_userdata: + * @self: A #SmlChangeItem + * + * Gets the userdata property. + * + * Return value: + */ +void* +sml_change_item_get_userdata (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), FALSE); + return self->priv->userdata; +} + +/** + * sml_change_item_set_userdata: + * @self: A #SmlChangeItem + * @userdata: + * + * Sets the userdata property. + */ +void +sml_change_item_set_userdata (SmlChangeItem *self, + void *userdata) +{ + g_return_if_fail (SML_IS_CHANGE_ITEM (self)); + self->priv->userdata = userdata; +} + +/** * sml_change_item_get_fragment: * @self: A #SmlChangeItem * @@ -492,11 +581,8 @@ else sml_change_item_set_missing_data(frag, FALSE); - if (sml_change_item_get_remote(self) != NULL && - !sml_change_item_set_remote(frag, sml_change_item_get_remote(self), error)) - goto error; - if (sml_change_item_get_local(self) != NULL && - !sml_change_item_set_local(frag, sml_change_item_get_local(self), error)) + if (sml_change_item_get_location(self) != NULL && + !sml_change_item_set_location(frag, sml_change_item_get_location(self), error)) goto error; if (sml_change_item_get_content_type(self) != NULL && @@ -529,7 +615,7 @@ (self->priv->content_type && frag->priv->content_type && strcmp(self->priv->content_type, frag->priv->content_type) == 0), FALSE, error, SML_ERROR_GENERIC, "The content-types do not match."); - sml_return_val_error_if_fail (strlen(self->priv->data) < self->priv->planned_size, FALSE, error, SML_ERROR_GENERIC, "The data is already complete."); + sml_return_val_error_if_fail (strlen(self->priv->data) <= self->priv->planned_size, FALSE, error, SML_ERROR_GENERIC, "The data is already complete."); sml_return_val_error_if_fail (strlen(self->priv->data)+strlen(frag->priv->data) <= self->priv->planned_size, FALSE, error, SML_ERROR_GENERIC, "The fragment is too large."); Modified: trunk/libsyncml/data_sync_api/sml_change_item.h ============================================================================== --- trunk/libsyncml/data_sync_api/sml_change_item.h Tue Aug 4 17:27:43 2009 (r1229) +++ trunk/libsyncml/data_sync_api/sml_change_item.h Fri Aug 7 19:35:36 2009 (r1230) @@ -23,9 +23,17 @@ #include <glib-object.h> #include <libsyncml/data_sync_api/sml_location.h> +#include <libsyncml/data_sync_api/defines.h> G_BEGIN_DECLS +typedef enum { + SML_CHANGE_UNKNOWN = 0, + SML_CHANGE_ADD = 1, + SML_CHANGE_REPLACE = 2, + SML_CHANGE_DELETE = 3 +} SmlChangeType; + #define SML_TYPE_CHANGE_ITEM (sml_change_item_get_type()) #define SML_CHANGE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_CHANGE_ITEM, SmlChangeItem)) #define SML_CHANGE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_CHANGE_ITEM, SmlChangeItemClass)) @@ -52,12 +60,15 @@ GType sml_change_item_get_type (void); SmlChangeItem* sml_change_item_new (void); -SmlLocation* sml_change_item_get_remote (SmlChangeItem *self); -gboolean sml_change_item_set_remote (SmlChangeItem *self, SmlLocation* remote, GError **error); -SmlLocation* sml_change_item_get_local (SmlChangeItem *self); -gboolean sml_change_item_set_local (SmlChangeItem *self, SmlLocation* local, GError **error); +SmlLocation* sml_change_item_get_location (SmlChangeItem *self); +gboolean sml_change_item_set_location (SmlChangeItem *self, SmlLocation* remote, GError **error); G_CONST_RETURN gchar* sml_change_item_get_data (SmlChangeItem *self); gboolean sml_change_item_set_data (SmlChangeItem *self, const gchar *data, gsize size, GError **error); +gboolean sml_change_item_set_binary_data (SmlChangeItem *self, const gchar *data, gsize size, GError **error); +G_CONST_RETURN gchar* sml_change_item_get_content_type (SmlChangeItem *self); +gboolean sml_change_item_set_content_type (SmlChangeItem *self, const gchar* content_type, GError **error); +SmlChangeType sml_change_item_get_action (SmlChangeItem *self); +void sml_change_item_set_action (SmlChangeItem *self, SmlChangeType kind); G_END_DECLS Modified: trunk/libsyncml/data_sync_api/sml_change_item_internals.h ============================================================================== --- trunk/libsyncml/data_sync_api/sml_change_item_internals.h Tue Aug 4 17:27:43 2009 (r1229) +++ trunk/libsyncml/data_sync_api/sml_change_item_internals.h Fri Aug 7 19:35:36 2009 (r1230) @@ -23,17 +23,20 @@ #include <glib-object.h> #include <libsyncml/data_sync_api/sml_change_item.h> +#include <libsyncml/data_sync_api/data_sync.h> G_BEGIN_DECLS gsize sml_change_item_get_planned_size (SmlChangeItem *self); void sml_change_item_set_planned_size (SmlChangeItem *self, gsize planned_size); -G_CONST_RETURN gchar* sml_change_item_get_content_type (SmlChangeItem *self); -gboolean sml_change_item_set_content_type (SmlChangeItem *self, const gchar* content_type, GError **error); gboolean sml_change_item_get_missing_data (SmlChangeItem *self); void sml_change_item_set_missing_data (SmlChangeItem *self, gboolean missing_data); gboolean sml_change_item_attach_fragment (SmlChangeItem *self, SmlChangeItem *fragment, GError **error); SmlChangeItem* sml_change_item_get_fragment (SmlChangeItem *self, gsize start, gsize max_size, GError **error); +void* sml_change_item_get_userdata (SmlChangeItem *self); +void sml_change_item_set_userdata (SmlChangeItem *self, void *userdata); +SmlDataSyncDatastore* sml_change_item_get_data_store (SmlChangeItem *self); +void sml_change_item_set_data_store (SmlChangeItem *self, SmlDataSyncDatastore *ds); G_END_DECLS Added: trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.c Fri Aug 7 19:35:36 2009 (r1230) @@ -0,0 +1,36 @@ + +/* Generated data (by glib-mkenums) */ + + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_data_sync_enum_types.c.tmpl *.h > sml_data_sync_enum_types.c + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + + +/* enumerations from "sml_change_item.h" */ + +#include <libsyncml/data_sync_api/sml_change_item.h> + +GType +sml_change_type_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY (etype == 0)) { + static const GEnumValue values[] = { + { SML_CHANGE_UNKNOWN, "SML_CHANGE_UNKNOWN", "unknown" }, + { SML_CHANGE_ADD, "SML_CHANGE_ADD", "add" }, + { SML_CHANGE_REPLACE, "SML_CHANGE_REPLACE", "replace" }, + { SML_CHANGE_DELETE, "SML_CHANGE_DELETE", "delete" }, + { 0, NULL, NULL } + }; + etype = g_enum_register_static (g_intern_static_string ("SmlChangeType"), values); + } + return etype; +} + + +/* Generated data ends here */ + Added: trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.c.tmpl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.c.tmpl Fri Aug 7 19:35:36 2009 (r1230) @@ -0,0 +1,44 @@ +/*** BEGIN file-header ***/ + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_data_sync_enum_types.c.tmpl *.h > sml_data_sync_enum_types.c + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ + +#include <libsyncml/data_sync_api/@filename@> + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type (void) +{ + static GType etype = 0; + if (G_UNLIKELY (etype == 0)) { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + etype = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); + } + return etype; +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ Added: trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.h Fri Aug 7 19:35:36 2009 (r1230) @@ -0,0 +1,26 @@ + +/* Generated data (by glib-mkenums) */ + +#ifndef __SML_DATA_SYNC_ENUM_TYPES_H__ +#define __SML_DATA_SYNC_ENUM_TYPES_H__ + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_data_sync_enum_types.h.tmpl *.h > sml_data_sync_enum_types.h + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + +#include <glib-object.h> + +G_BEGIN_DECLS + +/* enumerations from "sml_change_item.h" */ +GType sml_change_type_get_type (void) G_GNUC_CONST; +#define SML_DATA_SYNC_TYPE_CHANGE_TYPE (sml_change_type_get_type ()) +G_END_DECLS + +#endif /* __SML_DATA_SYNC_ENUM_TYPES_H__ */ + +/* Generated data ends here */ + Added: trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.h.tmpl ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_enum_types.h.tmpl Fri Aug 7 19:35:36 2009 (r1230) @@ -0,0 +1,31 @@ +/*** BEGIN file-header ***/ +#ifndef __SML_DATA_SYNC_ENUM_TYPES_H__ +#define __SML_DATA_SYNC_ENUM_TYPES_H__ + +/* WARNING: This file was generated by glib-mkenums. + * WARNING: + * WARNING: glib-mkenums --template sml_data_sync_enum_types.h.tmpl *.h > sml_data_sync_enum_types.h + * WARNING: + * WARNING: If you need to update this file then please run the command again. + */ + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define SML_DATA_SYNC_TYPE_@ENUMSHORT@ (@enum_name@_get_type ()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +#endif /* __SML_DATA_SYNC_ENUM_TYPES_H__ */ +/*** END file-tail ***/ |
From: <svn...@op...> - 2009-08-04 15:28:00
|
Author: bellmich Date: Tue Aug 4 17:27:43 2009 New Revision: 1229 URL: http://libsyncml.opensync.org/changeset/1229 Log: fix the usage of g_type_init If the normal setup is used then the normal exceptions for Valgrind work. Modified: trunk/tests/check_dev_inf.c trunk/tests/check_dev_inf_content_type.c trunk/tests/check_dev_inf_ctcap.c trunk/tests/check_dev_inf_data_store.c trunk/tests/check_dev_inf_prop_param.c trunk/tests/check_dev_inf_property.c Modified: trunk/tests/check_dev_inf.c ============================================================================== --- trunk/tests/check_dev_inf.c Tue Aug 4 17:00:22 2009 (r1228) +++ trunk/tests/check_dev_inf.c Tue Aug 4 17:27:43 2009 (r1229) @@ -24,7 +24,7 @@ START_TEST (dev_inf_create) { - g_type_init(); + setup_testbed(NULL); SmlDevInf *devinf = sml_dev_inf_new(); sml_fail_unless(devinf != NULL, NULL); @@ -34,7 +34,7 @@ START_TEST (dev_inf_references) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = sml_dev_inf_new(); @@ -56,7 +56,7 @@ START_TEST (dev_inf_enforce_ver_dtd) { - g_type_init(); + setup_testbed(NULL); SmlDevInf *devinf = sml_dev_inf_new(); sml_fail_unless(devinf != NULL, NULL); @@ -84,7 +84,7 @@ START_TEST (dev_inf_enforce_dev_id) { - g_type_init(); + setup_testbed(NULL); const gchar* devid = NULL; GError *error = NULL; @@ -128,7 +128,7 @@ START_TEST (dev_inf_enforce_dev_typ) { - g_type_init(); + setup_testbed(NULL); SmlDevInf *devinf = sml_dev_inf_new(); sml_fail_unless(devinf != NULL, NULL); @@ -153,7 +153,7 @@ START_TEST (dev_inf_option_man) { - g_type_init(); + setup_testbed(NULL); const gchar* man = NULL; GError *error = NULL; @@ -182,7 +182,7 @@ START_TEST (dev_inf_option_mod) { - g_type_init(); + setup_testbed(NULL); const gchar* mod = NULL; GError *error = NULL; @@ -211,7 +211,7 @@ START_TEST (dev_inf_option_oem) { - g_type_init(); + setup_testbed(NULL); const gchar* oem = NULL; GError *error = NULL; @@ -240,7 +240,7 @@ START_TEST (dev_inf_option_fwv) { - g_type_init(); + setup_testbed(NULL); const gchar* fwv = NULL; GError *error = NULL; @@ -274,7 +274,7 @@ START_TEST (dev_inf_option_swv) { - g_type_init(); + setup_testbed(NULL); const gchar* swv = NULL; GError *error = NULL; @@ -308,7 +308,7 @@ START_TEST (dev_inf_option_hwv) { - g_type_init(); + setup_testbed(NULL); const gchar* hwv = NULL; GError *error = NULL; @@ -342,7 +342,7 @@ START_TEST (dev_inf_option_support_utc) { - g_type_init(); + setup_testbed(NULL); SmlDevInf *devinf = sml_dev_inf_new(); sml_fail_unless(devinf != NULL, NULL); @@ -359,7 +359,7 @@ START_TEST (dev_inf_option_support_large_objs) { - g_type_init(); + setup_testbed(NULL); SmlDevInf *devinf = sml_dev_inf_new(); sml_fail_unless(devinf != NULL, NULL); @@ -376,7 +376,7 @@ START_TEST (dev_inf_option_support_number_of_changes) { - g_type_init(); + setup_testbed(NULL); SmlDevInf *devinf = sml_dev_inf_new(); sml_fail_unless(devinf != NULL, NULL); @@ -393,7 +393,7 @@ START_TEST (dev_inf_enforce_data_stores) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = sml_dev_inf_new(); @@ -448,7 +448,7 @@ START_TEST (dev_inf_enforce_ctcaps) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = sml_dev_inf_new(); @@ -509,7 +509,7 @@ START_TEST (dev_inf_compliance_error) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = sml_dev_inf_new(); @@ -553,7 +553,7 @@ START_TEST (dev_inf_compliance_1_0) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; @@ -619,7 +619,7 @@ START_TEST (dev_inf_compliance_1_1) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; @@ -685,7 +685,7 @@ START_TEST (dev_inf_compliance_1_2) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; @@ -784,7 +784,7 @@ START_TEST (dev_inf_overdefined_1_0) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; @@ -819,7 +819,7 @@ START_TEST (dev_inf_filtered_1_0) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; @@ -854,7 +854,7 @@ START_TEST (dev_inf_server_1_0) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; @@ -877,7 +877,7 @@ START_TEST (dev_inf_server_1_1) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; @@ -945,7 +945,7 @@ START_TEST (dev_inf_server_1_2) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInf *devinf = NULL; Modified: trunk/tests/check_dev_inf_content_type.c ============================================================================== --- trunk/tests/check_dev_inf_content_type.c Tue Aug 4 17:00:22 2009 (r1228) +++ trunk/tests/check_dev_inf_content_type.c Tue Aug 4 17:27:43 2009 (r1229) @@ -24,7 +24,7 @@ START_TEST (dev_inf_content_type_create) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); @@ -47,7 +47,7 @@ START_TEST (dev_inf_content_type_empty_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); @@ -62,7 +62,7 @@ START_TEST (dev_inf_content_type_filled_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new("text/x-vCalendar", "1.0", &error); @@ -77,7 +77,7 @@ START_TEST (dev_inf_content_type_references) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new("text/x-vCalendar", "1.0", &error); Modified: trunk/tests/check_dev_inf_ctcap.c ============================================================================== --- trunk/tests/check_dev_inf_ctcap.c Tue Aug 4 17:00:22 2009 (r1228) +++ trunk/tests/check_dev_inf_ctcap.c Tue Aug 4 17:27:43 2009 (r1229) @@ -24,7 +24,7 @@ START_TEST (dev_inf_ctcap_create) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; @@ -47,7 +47,7 @@ START_TEST (dev_inf_ctcap_empty_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); @@ -90,7 +90,7 @@ START_TEST (dev_inf_ctcap_empty_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); @@ -137,7 +137,7 @@ START_TEST (dev_inf_ctcap_filled_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); @@ -179,7 +179,7 @@ START_TEST (dev_inf_ctcap_filled_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); @@ -239,7 +239,7 @@ START_TEST (dev_inf_ctcap_references) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfContentType *ct = sml_dev_inf_content_type_new(NULL, NULL, &error); Modified: trunk/tests/check_dev_inf_data_store.c ============================================================================== --- trunk/tests/check_dev_inf_data_store.c Tue Aug 4 17:00:22 2009 (r1228) +++ trunk/tests/check_dev_inf_data_store.c Tue Aug 4 17:27:43 2009 (r1229) @@ -24,7 +24,7 @@ START_TEST (dev_inf_data_store_create) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfDataStore *datastore = sml_dev_inf_data_store_new(NULL, &error); @@ -41,7 +41,7 @@ START_TEST (dev_inf_data_store_empty_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfDataStore *datastore = sml_dev_inf_data_store_new("Contacts", &error); @@ -102,7 +102,7 @@ START_TEST (dev_inf_data_store_empty_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfDataStore *datastore = sml_dev_inf_data_store_new("Contacts", &error); @@ -215,7 +215,7 @@ START_TEST (dev_inf_data_store_filled_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfDataStore *datastore = sml_dev_inf_data_store_new("Contacts", &error); @@ -281,7 +281,7 @@ START_TEST (dev_inf_data_store_filled_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfDataStore *datastore = sml_dev_inf_data_store_new("Contacts", &error); @@ -388,7 +388,7 @@ START_TEST (dev_inf_data_store_compliance) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfDataStore *datastore = sml_dev_inf_data_store_new("Contacts", &error); @@ -475,7 +475,7 @@ START_TEST (dev_inf_data_store_references) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfDataStore *datastore = sml_dev_inf_data_store_new("Contacts", &error); Modified: trunk/tests/check_dev_inf_prop_param.c ============================================================================== --- trunk/tests/check_dev_inf_prop_param.c Tue Aug 4 17:00:22 2009 (r1228) +++ trunk/tests/check_dev_inf_prop_param.c Tue Aug 4 17:27:43 2009 (r1229) @@ -24,7 +24,7 @@ START_TEST (dev_inf_prop_param_create) { - g_type_init(); + setup_testbed(NULL); SmlDevInfPropParam *propParam = sml_dev_inf_prop_param_new(); sml_fail_unless(propParam != NULL, NULL); @@ -34,7 +34,7 @@ START_TEST (dev_inf_prop_param_empty_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfPropParam *propParam = sml_dev_inf_prop_param_new(); @@ -90,7 +90,7 @@ START_TEST (dev_inf_prop_param_empty_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfPropParam *propParam = sml_dev_inf_prop_param_new(); @@ -163,7 +163,7 @@ START_TEST (dev_inf_prop_param_filled_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfPropParam *propParam = sml_dev_inf_prop_param_new(); @@ -181,7 +181,7 @@ START_TEST (dev_inf_prop_param_filled_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfPropParam *propParam = sml_dev_inf_prop_param_new(); @@ -222,7 +222,7 @@ START_TEST (dev_inf_prop_param_references) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfPropParam *propParam = sml_dev_inf_prop_param_new(); Modified: trunk/tests/check_dev_inf_property.c ============================================================================== --- trunk/tests/check_dev_inf_property.c Tue Aug 4 17:00:22 2009 (r1228) +++ trunk/tests/check_dev_inf_property.c Tue Aug 4 17:27:43 2009 (r1229) @@ -26,7 +26,7 @@ START_TEST (dev_inf_property_create) { - g_type_init(); + setup_testbed(NULL); SmlDevInfProperty *prop = sml_dev_inf_property_new(); sml_fail_unless(prop != NULL, NULL); @@ -36,7 +36,7 @@ START_TEST (dev_inf_property_empty_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfProperty *prop = sml_dev_inf_property_new(); @@ -106,7 +106,7 @@ START_TEST (dev_inf_property_empty_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfProperty *prop = sml_dev_inf_property_new(); @@ -200,7 +200,7 @@ START_TEST (dev_inf_property_size_integrity) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfProperty *prop = sml_dev_inf_property_new(); @@ -237,7 +237,7 @@ START_TEST (dev_inf_property_filled_set) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfProperty *prop = sml_dev_inf_property_new(); @@ -275,7 +275,7 @@ START_TEST (dev_inf_property_filled_get) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfProperty *prop = sml_dev_inf_property_new(); @@ -362,7 +362,7 @@ START_TEST (dev_inf_property_references) { - g_type_init(); + setup_testbed(NULL); GError *error = NULL; SmlDevInfProperty *prop = sml_dev_inf_property_new(); |
From: <svn...@op...> - 2009-08-04 15:00:39
|
Author: bellmich Date: Tue Aug 4 17:00:22 2009 New Revision: 1228 URL: http://libsyncml.opensync.org/changeset/1228 Log: fixed memory leak in test Modified: trunk/tests/check_data_sync_api_change_item.c Modified: trunk/tests/check_data_sync_api_change_item.c ============================================================================== --- trunk/tests/check_data_sync_api_change_item.c Tue Aug 4 17:00:02 2009 (r1227) +++ trunk/tests/check_data_sync_api_change_item.c Tue Aug 4 17:00:22 2009 (r1228) @@ -677,6 +677,7 @@ g_error_free(error); error = NULL; + g_object_unref(frag); g_object_unref(item); } END_TEST |
From: <svn...@op...> - 2009-08-04 15:00:14
|
Author: bellmich Date: Tue Aug 4 17:00:02 2009 New Revision: 1227 URL: http://libsyncml.opensync.org/changeset/1227 Log: added some missing return values (discovered during memory debugging) Modified: trunk/libsyncml/data_sync_api/sml_change_item.c Modified: trunk/libsyncml/data_sync_api/sml_change_item.c ============================================================================== --- trunk/libsyncml/data_sync_api/sml_change_item.c Tue Aug 4 16:47:02 2009 (r1226) +++ trunk/libsyncml/data_sync_api/sml_change_item.c Tue Aug 4 17:00:02 2009 (r1227) @@ -276,6 +276,7 @@ self->priv->remote = remote; if (remote) g_object_ref (remote); + return TRUE; } /** @@ -313,6 +314,7 @@ self->priv->local = local; if (local) g_object_ref (local); + return TRUE; } /** |
From: <svn...@op...> - 2009-08-04 14:47:16
|
Author: bellmich Date: Tue Aug 4 16:47:02 2009 New Revision: 1226 URL: http://libsyncml.opensync.org/changeset/1226 Log: added missing include to fix warnings from FreeBSD Modified: trunk/tests/check_data_sync_api_change_item.c Modified: trunk/tests/check_data_sync_api_change_item.c ============================================================================== --- trunk/tests/check_data_sync_api_change_item.c Tue Aug 4 16:35:52 2009 (r1225) +++ trunk/tests/check_data_sync_api_change_item.c Tue Aug 4 16:47:02 2009 (r1226) @@ -21,6 +21,7 @@ #include "tests/support.h" #include <libsyncml/data_sync_api/sml_change_item_internals.h> +#include <string.h> START_TEST (change_item_new) { |
From: <svn...@op...> - 2009-08-04 14:36:13
|
Author: bellmich Date: Tue Aug 4 16:35:52 2009 New Revision: 1225 URL: http://libsyncml.opensync.org/changeset/1225 Log: added SmlChangeItem including tests The integration into the API itself is not done until now. Added: trunk/libsyncml/data_sync_api/sml_change_item.c trunk/libsyncml/data_sync_api/sml_change_item.h trunk/libsyncml/data_sync_api/sml_change_item_internals.h trunk/tests/check_data_sync_api_change_item.c Modified: trunk/libsyncml/CMakeLists.txt trunk/tests/CMakeLists.txt Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Sat Aug 1 17:23:46 2009 (r1224) +++ trunk/libsyncml/CMakeLists.txt Tue Aug 4 16:35:52 2009 (r1225) @@ -24,6 +24,7 @@ data_sync_api/data_sync_client.c data_sync_api/data_sync_server.c data_sync_api/sml_location.c + data_sync_api/sml_change_item.c data_sync_api/sml_map_item.c data_sync_api/transport_http_client.c data_sync_api/transport_http_server.c @@ -79,6 +80,7 @@ INSTALL( FILES data_sync_api/sml_location.h + data_sync_api/sml_change_item.h data_sync_api/sml_map_item.h data_sync_api/defines.h data_sync_api/standard.h Added: trunk/libsyncml/data_sync_api/sml_change_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_change_item.c Tue Aug 4 16:35:52 2009 (r1225) @@ -0,0 +1,549 @@ +/* sml_change_item.c + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "sml_change_item_internals.h" +#include "../sml_error_internals.h" +#include <string.h> + +G_DEFINE_TYPE (SmlChangeItem, sml_change_item, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_REMOTE, + PROP_LOCAL, + PROP_DATA, + PROP_PLANNED_SIZE, + PROP_CONTENT_TYPE, + PROP_MISSING_DATA +}; + +struct _SmlChangeItemPrivate +{ + SmlLocation* remote; + SmlLocation* local; + gchar* data; + guint64 planned_size; + gchar* content_type; + gboolean missing_data; +}; + +static void +sml_change_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + g_value_set_object (value, SML_CHANGE_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + g_value_set_object (value, SML_CHANGE_ITEM (object)->priv->local); + break; + case PROP_DATA: + g_value_set_string (value, SML_CHANGE_ITEM (object)->priv->data); + break; + case PROP_PLANNED_SIZE: + g_value_set_uint64 (value, SML_CHANGE_ITEM (object)->priv->planned_size); + break; + case PROP_CONTENT_TYPE: + g_value_set_string (value, SML_CHANGE_ITEM (object)->priv->content_type); + break; + case PROP_MISSING_DATA: + g_value_set_boolean (value, SML_CHANGE_ITEM (object)->priv->missing_data); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_change_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + if (SML_CHANGE_ITEM (object)->priv->remote) + g_object_unref (SML_CHANGE_ITEM (object)->priv->remote); + SML_CHANGE_ITEM (object)->priv->remote = SML_LOCATION (value); + g_object_ref(SML_CHANGE_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + if (SML_CHANGE_ITEM (object)->priv->local) + g_object_unref (SML_CHANGE_ITEM (object)->priv->local); + SML_CHANGE_ITEM (object)->priv->local = SML_LOCATION (value); + g_object_ref(SML_CHANGE_ITEM (object)->priv->local); + break; + case PROP_DATA: + g_free (SML_CHANGE_ITEM (object)->priv->data); + SML_CHANGE_ITEM (object)->priv->data = g_strdup (g_value_get_string (value)); + break; + case PROP_PLANNED_SIZE: + SML_CHANGE_ITEM (object)->priv->planned_size = g_value_get_uint64 (value); + break; + case PROP_CONTENT_TYPE: + g_free (SML_CHANGE_ITEM (object)->priv->content_type); + SML_CHANGE_ITEM (object)->priv->content_type = g_strdup (g_value_get_string (value)); + break; + case PROP_MISSING_DATA: + SML_CHANGE_ITEM (object)->priv->missing_data = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_change_item_finalize (GObject *object) +{ + SmlChangeItem *self = (SmlChangeItem *) object; + if (self->priv->remote) + g_object_unref(self->priv->remote); + if (self->priv->local) + g_object_unref(self->priv->local); + g_free(self->priv->data); + g_free(self->priv->content_type); + /* all pointers must be NULL */ + self->priv->remote = NULL; + self->priv->local = NULL; + self->priv->data = NULL; + self->priv->planned_size = 0; + self->priv->content_type = NULL; + G_OBJECT_CLASS (sml_change_item_parent_class)->finalize (object); +} + +static void +sml_change_item_class_init (SmlChangeItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlChangeItemPrivate)); + + object_class->get_property = sml_change_item_get_property; + object_class->set_property = sml_change_item_set_property; + object_class->finalize = sml_change_item_finalize; + + /** + * SmlChangeItem:remote: + * + * The remote SmlLocation property. + */ + g_object_class_install_property (object_class, + PROP_REMOTE, + g_param_spec_object ("remote", + "remote SmlLocation", + "remote SmlLocation", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + /** + * SmlChangeItem:local: + * + * The local SmlLocation property. + */ + g_object_class_install_property (object_class, + PROP_LOCAL, + g_param_spec_object ("local", + "local SmlLocation", + "local SmlLocation", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + /** + * SmlChangeItem:data: + * + * The property. + */ + g_object_class_install_property (object_class, + PROP_DATA, + g_param_spec_string ("data", + "data", + "", + NULL, + G_PARAM_READWRITE)); + /** + * SmlChangeItem:planned_size: + * + * The property. + */ + g_object_class_install_property (object_class, + PROP_PLANNED_SIZE, + g_param_spec_uint64 ("planned_size", + "planned size", + "", + 0, + G_MAXUINT64, + 0, + G_PARAM_READWRITE)); + /** + * SmlChangeItem:content_type: + * + * The property. + */ + g_object_class_install_property (object_class, + PROP_CONTENT_TYPE, + g_param_spec_string ("content_type", + "content-type", + "", + NULL, + G_PARAM_READWRITE)); + /** + * SmlChangeItem:missing_data: + * + * The MoreData flag property. + */ + g_object_class_install_property (object_class, + PROP_MISSING_DATA, + g_param_spec_boolean ("missing_data", + "MoreData flag", + "MoreData flag", + FALSE, + G_PARAM_READWRITE)); + +} + +static void +sml_change_item_init (SmlChangeItem *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_CHANGE_ITEM, + SmlChangeItemPrivate); +} + +/** + * sml_change_item_new: + * + * Creates a new instance of #SmlChangeItem. + * + * Return value: the newly created #SmlChangeItem instance + */ +SmlChangeItem* +sml_change_item_new (void) +{ + return g_object_new (SML_TYPE_CHANGE_ITEM, NULL); +} + +/** + * sml_change_item_get_remote: + * @self: A #SmlChangeItem + * + * Gets the remote SmlLocation property. + * + * Return value: + */ +SmlLocation* +sml_change_item_get_remote (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), NULL); + return self->priv->remote; +} + +/** + * sml_change_item_set_remote: + * @self: A #SmlChangeItem + * @remote: + * + * Sets the remote SmlLocation property. + */ +gboolean +sml_change_item_set_remote (SmlChangeItem *self, + SmlLocation* remote, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); + sml_return_val_error_if_fail (!remote || sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "The location must have an URI."); + + if (self->priv->remote) + g_object_unref (self->priv->remote); + self->priv->remote = remote; + if (remote) + g_object_ref (remote); +} + +/** + * sml_change_item_get_local: + * @self: A #SmlChangeItem + * + * Gets the local SmlLocation property. + * + * Return value: + */ +SmlLocation* +sml_change_item_get_local (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), NULL); + return self->priv->local; +} + +/** + * sml_change_item_set_local: + * @self: A #SmlChangeItem + * @local: + * + * Sets the local SmlLocation property. + */ +gboolean +sml_change_item_set_local (SmlChangeItem *self, + SmlLocation* local, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); + sml_return_val_error_if_fail (!local || sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "The location must have an URI."); + + if (self->priv->local) + g_object_unref (self->priv->local); + self->priv->local = local; + if (local) + g_object_ref (local); +} + +/** + * sml_change_item_get_data: + * @self: A #SmlChangeItem + * + * Gets the data property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_change_item_get_data (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), NULL); + return self->priv->data; +} + +/** + * sml_change_item_set_data: + * @self: A #SmlChangeItem + * @data: + * @size: + * + * Sets the data property. + */ +gboolean +sml_change_item_set_data (SmlChangeItem *self, + const gchar* data, + gsize size, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); + sml_return_val_error_if_fail (data != NULL, FALSE, error, SML_ERROR_GENERIC, "The data must be different from NULL."); + sml_return_val_error_if_fail (strlen(data), FALSE, error, SML_ERROR_GENERIC, "The data must not be the empty word."); + + /* if the size is not set then we copy the whole string */ + + if (!size) + size = strlen(data); + + g_free (self->priv->data); + self->priv->data = g_strndup(data, size); + + sml_return_val_error_if_fail (self->priv->data, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the data - out of memory."); + + return TRUE; +} + +/** + * sml_change_item_get_planned_size: + * @self: A #SmlChangeItem + * + * Gets the planned size property. + * + * Return value: + */ +gsize +sml_change_item_get_planned_size (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), 0); + return self->priv->planned_size; +} + +/** + * sml_change_item_set_planned_size: + * @self: A #SmlChangeItem + * @planned_size: + * + * Sets the planned size property. + */ +void +sml_change_item_set_planned_size (SmlChangeItem *self, + gsize planned_size) +{ + g_return_if_fail (SML_IS_CHANGE_ITEM (self)); + self->priv->planned_size = planned_size; +} + +/** + * sml_change_item_get_content_type: + * @self: A #SmlChangeItem + * + * Gets the content-type property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_change_item_get_content_type (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), NULL); + return self->priv->content_type; +} + +/** + * sml_change_item_set_content_type: + * @self: A #SmlChangeItem + * @content_type: + * + * Sets the content-type property. + */ +gboolean +sml_change_item_set_content_type (SmlChangeItem *self, + const gchar* content_type, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); + sml_return_val_error_if_fail (content_type != NULL, FALSE, error, SML_ERROR_GENERIC, "The content-type must be different from NULL."); + sml_return_val_error_if_fail (strlen(content_type), FALSE, error, SML_ERROR_GENERIC, "The content-type must be different from the empty word."); + + g_free (self->priv->content_type); + self->priv->content_type = g_strdup (content_type); + + sml_return_val_error_if_fail (self->priv->content_type, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the content-type - out of memory."); + + return TRUE; +} + +/** + * sml_change_item_get_missing_data: + * @self: A #SmlChangeItem + * + * Gets the MoreData flag property. + * + * Return value: + */ +gboolean +sml_change_item_get_missing_data (SmlChangeItem *self) +{ + g_return_val_if_fail (SML_IS_CHANGE_ITEM (self), FALSE); + return self->priv->missing_data; +} + +/** + * sml_change_item_set_missing_data: + * @self: A #SmlChangeItem + * @missing_data: + * + * Sets the MoreData flag property. + */ +void +sml_change_item_set_missing_data (SmlChangeItem *self, + gboolean missing_data) +{ + g_return_if_fail (SML_IS_CHANGE_ITEM (self)); + self->priv->missing_data = missing_data; +} + +/** + * sml_change_item_get_fragment: + * @self: A #SmlChangeItem + * + * + */ +SmlChangeItem* +sml_change_item_get_fragment (SmlChangeItem *self, + gsize start, + gsize max_size, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), NULL, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); + sml_return_val_error_if_fail (self->priv->data, NULL, error, SML_ERROR_GENERIC, "There must be some data."); + sml_return_val_error_if_fail (max_size, NULL, error, SML_ERROR_GENERIC, "There is no maximum size set."); + + SmlChangeItem *frag = sml_change_item_new(); + sml_return_val_error_if_fail (frag, NULL, error, SML_ERROR_GENERIC, "Cannot create new instance of SmlChangeItem - out of memory."); + + if (start == 0 && max_size < strlen(self->priv->data)) + sml_change_item_set_planned_size(frag, strlen(self->priv->data)); + + if (!sml_change_item_set_data(frag, self->priv->data + start, max_size, error)) + goto error; + + if (start + max_size < strlen(self->priv->data)) + sml_change_item_set_missing_data(frag, TRUE); + else + sml_change_item_set_missing_data(frag, FALSE); + + if (sml_change_item_get_remote(self) != NULL && + !sml_change_item_set_remote(frag, sml_change_item_get_remote(self), error)) + goto error; + if (sml_change_item_get_local(self) != NULL && + !sml_change_item_set_local(frag, sml_change_item_get_local(self), error)) + goto error; + + if (sml_change_item_get_content_type(self) != NULL && + !sml_change_item_set_content_type(frag, sml_change_item_get_content_type(self), error)) + goto error; + + return frag; +error: + if (frag) + g_object_unref(frag); + return NULL; +} + +/** + * sml_change_item_attach_fragment: + * @self: A #SmlChangeItem + * + * + */ +gboolean +sml_change_item_attach_fragment (SmlChangeItem *self, + SmlChangeItem *frag, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlChangeItem object."); + sml_return_val_error_if_fail (SML_IS_CHANGE_ITEM (frag), FALSE, error, SML_ERROR_GENERIC, "There must be a fragmentation object."); + sml_return_val_error_if_fail (frag->priv->data, FALSE, error, SML_ERROR_GENERIC, "The fragment does not contain any data."); + sml_return_val_error_if_fail (strlen(frag->priv->data), FALSE, error, SML_ERROR_GENERIC, "The fragment does only contain an empty string."); + sml_return_val_error_if_fail ((!self->priv->content_type && !frag->priv->content_type) || + (self->priv->content_type && frag->priv->content_type && + strcmp(self->priv->content_type, frag->priv->content_type) == 0), + FALSE, error, SML_ERROR_GENERIC, "The content-types do not match."); + sml_return_val_error_if_fail (strlen(self->priv->data) < self->priv->planned_size, FALSE, error, SML_ERROR_GENERIC, "The data is already complete."); + sml_return_val_error_if_fail (strlen(self->priv->data)+strlen(frag->priv->data) <= self->priv->planned_size, + FALSE, error, SML_ERROR_GENERIC, "The fragment is too large."); + + gchar *complete = NULL; + if (self->priv->data) + complete = g_strconcat(self->priv->data, frag->priv->data, NULL); + else + complete = g_strdup(frag->priv->data); + sml_return_val_error_if_fail (complete, FALSE, error, SML_ERROR_GENERIC, "Cannot copy the fragment - out of memory."); + + g_free(self->priv->data); + self->priv->data = complete; + + if (self->priv->planned_size && self->priv->planned_size == strlen(self->priv->data)) + self->priv->missing_data = FALSE; + + return TRUE; +} + Added: trunk/libsyncml/data_sync_api/sml_change_item.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_change_item.h Tue Aug 4 16:35:52 2009 (r1225) @@ -0,0 +1,64 @@ +/* sml_change_item.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_CHANGE_ITEM_H__ +#define __SML_CHANGE_ITEM_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_location.h> + +G_BEGIN_DECLS + +#define SML_TYPE_CHANGE_ITEM (sml_change_item_get_type()) +#define SML_CHANGE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_CHANGE_ITEM, SmlChangeItem)) +#define SML_CHANGE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_CHANGE_ITEM, SmlChangeItemClass)) +#define SML_IS_CHANGE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_CHANGE_ITEM)) +#define SML_IS_CHANGE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_CHANGE_ITEM)) +#define SML_CHANGE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_CHANGE_ITEM, SmlChangeItemClass)) + +typedef struct _SmlChangeItem SmlChangeItem; +typedef struct _SmlChangeItemClass SmlChangeItemClass; +typedef struct _SmlChangeItemPrivate SmlChangeItemPrivate; + +struct _SmlChangeItem +{ + GObject parent; + + /*< private >*/ + SmlChangeItemPrivate *priv; +}; + +struct _SmlChangeItemClass +{ + GObjectClass parent_class; +}; + +GType sml_change_item_get_type (void); +SmlChangeItem* sml_change_item_new (void); +SmlLocation* sml_change_item_get_remote (SmlChangeItem *self); +gboolean sml_change_item_set_remote (SmlChangeItem *self, SmlLocation* remote, GError **error); +SmlLocation* sml_change_item_get_local (SmlChangeItem *self); +gboolean sml_change_item_set_local (SmlChangeItem *self, SmlLocation* local, GError **error); +G_CONST_RETURN gchar* sml_change_item_get_data (SmlChangeItem *self); +gboolean sml_change_item_set_data (SmlChangeItem *self, const gchar *data, gsize size, GError **error); + +G_END_DECLS + +#endif /* __SML_CHANGE_ITEM_H__ */ Added: trunk/libsyncml/data_sync_api/sml_change_item_internals.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_change_item_internals.h Tue Aug 4 16:35:52 2009 (r1225) @@ -0,0 +1,40 @@ +/* sml_change_item_internals.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_CHANGE_ITEM_INTERNALS_H__ +#define __SML_CHANGE_ITEM_INTERNALS_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_change_item.h> + +G_BEGIN_DECLS + +gsize sml_change_item_get_planned_size (SmlChangeItem *self); +void sml_change_item_set_planned_size (SmlChangeItem *self, gsize planned_size); +G_CONST_RETURN gchar* sml_change_item_get_content_type (SmlChangeItem *self); +gboolean sml_change_item_set_content_type (SmlChangeItem *self, const gchar* content_type, GError **error); +gboolean sml_change_item_get_missing_data (SmlChangeItem *self); +void sml_change_item_set_missing_data (SmlChangeItem *self, gboolean missing_data); +gboolean sml_change_item_attach_fragment (SmlChangeItem *self, SmlChangeItem *fragment, GError **error); +SmlChangeItem* sml_change_item_get_fragment (SmlChangeItem *self, gsize start, gsize max_size, GError **error); + +G_END_DECLS + +#endif /* __SML_CHANGE_ITEM_INTERNALS_H__ */ Modified: trunk/tests/CMakeLists.txt ============================================================================== --- trunk/tests/CMakeLists.txt Sat Aug 1 17:23:46 2009 (r1224) +++ trunk/tests/CMakeLists.txt Tue Aug 4 16:35:52 2009 (r1225) @@ -89,6 +89,41 @@ SML_ADD_TESTCASE( location_references ) SML_END_TEST() + SML_START_TEST( "change_item" data_sync_api_change_item check_data_sync_api_change_item.c ${TEST_TARGET_LIBRARIES} ) + SML_ADD_TESTCASE( change_item_new ) + SML_ADD_TESTCASE( change_item_set_local ) + SML_ADD_TESTCASE( change_item_set_local_null ) + SML_ADD_TESTCASE( change_item_set_local_missing_uri ) + SML_ADD_TESTCASE( change_item_get_local ) + SML_ADD_TESTCASE( change_item_set_remote ) + SML_ADD_TESTCASE( change_item_set_remote_null ) + SML_ADD_TESTCASE( change_item_set_remote_missing_uri ) + SML_ADD_TESTCASE( change_item_get_remote ) + SML_ADD_TESTCASE( change_item_set_data ) + SML_ADD_TESTCASE( change_item_set_data_with_limit ) + SML_ADD_TESTCASE( change_item_set_data_with_length ) + SML_ADD_TESTCASE( change_item_set_data_with_overflow ) + SML_ADD_TESTCASE( change_item_set_data_not_null ) + SML_ADD_TESTCASE( change_item_get_data ) + SML_ADD_TESTCASE( change_item_get_data_with_limit ) + SML_ADD_TESTCASE( change_item_get_data_with_length ) + SML_ADD_TESTCASE( change_item_get_data_with_overflow ) + SML_ADD_TESTCASE( change_item_set_planned_size ) + SML_ADD_TESTCASE( change_item_get_planned_size ) + SML_ADD_TESTCASE( change_item_set_content_type ) + SML_ADD_TESTCASE( change_item_set_content_type_not_null ) + SML_ADD_TESTCASE( change_item_get_content_type ) + SML_ADD_TESTCASE( change_item_get_fragment_missing_data ) + SML_ADD_TESTCASE( change_item_get_fragment ) + SML_ADD_TESTCASE( change_item_get_too_large_fragment ) + SML_ADD_TESTCASE( change_item_get_illegal_fragment ) + SML_ADD_TESTCASE( change_item_attach_empty_fragment ) + SML_ADD_TESTCASE( change_item_attach_fragment ) + SML_ADD_TESTCASE( change_item_attach_too_long_fragment ) + SML_ADD_TESTCASE( change_item_attach_unnecessary_fragment ) + SML_ADD_TESTCASE( change_item_references ) + SML_END_TEST() + SML_START_TEST( "map_item" data_sync_api_map_item check_data_sync_api_map_item.c ${TEST_TARGET_LIBRARIES} ) SML_ADD_TESTCASE( map_item_new ) SML_ADD_TESTCASE( map_item_set_local ) Added: trunk/tests/check_data_sync_api_change_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tests/check_data_sync_api_change_item.c Tue Aug 4 16:35:52 2009 (r1225) @@ -0,0 +1,875 @@ +/* + * libsyncml - A syncml protocol implementation + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "tests/support.h" + +#include <libsyncml/data_sync_api/sml_change_item_internals.h> + +START_TEST (change_item_new) +{ + setup_testbed(NULL); + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_local_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_set_local(item, NULL, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_local_missing_uri) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_change_item_set_local(item, location, &error), "The location must have an URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_local(item) == NULL, "The local location is not set until now."); + + sml_fail_unless(sml_change_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_get_local(item) != NULL, "The local location must be set now."); + sml_fail_unless(sml_change_item_get_local(item) == location, "The local location must be 1234."); + + sml_fail_unless(sml_change_item_set_local(item, NULL, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_get_local(item) == NULL, "The local location was deleted."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_remote_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_set_remote(item, NULL, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_remote_missing_uri) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_change_item_set_remote(item, location, &error), "The location must have an URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_remote(item) == NULL, "The remote location is not set until now."); + + sml_fail_unless(sml_change_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_get_remote(item) != NULL, "The remote location must be set now."); + sml_fail_unless(sml_change_item_get_remote(item) == location, "The remote location must be 1234."); + + sml_fail_unless(sml_change_item_set_remote(item, NULL, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_get_remote(item) == NULL, "The remote location was deleted."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_data) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_data_with_limit) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, strlen(data)-3, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_data_with_length) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, strlen(data), &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_data_with_overflow) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, strlen(data)+3, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_data_not_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_set_local(item, NULL, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_data) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_data(item) == NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + const char* result = sml_change_item_get_data(item); + sml_fail_unless(result != NULL, "The data must be present."); + sml_fail_unless(strcmp(result, data) == 0, "The data must be '%s'.", result); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_data_with_limit) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_data(item) == NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, strlen(data)-3, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + const char* result = sml_change_item_get_data(item); + sml_fail_unless(result != NULL, "The data must be present."); + sml_fail_unless(strlen(data)-3 == strlen(result), "The data has the wrong length."); + sml_fail_unless(strncmp(result, data, strlen(data)-3) == 0, "The data must be a part from '%s'.", result); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_data_with_length) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_data(item) == NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, strlen(data), &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + const char* result = sml_change_item_get_data(item); + sml_fail_unless(result != NULL, "The data must be present."); + sml_fail_unless(strcmp(result, data) == 0, "The data must be '%s'.", result); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_data_with_overflow) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_data(item) == NULL, NULL); + + const gchar* data = "I am a vCard."; + sml_fail_unless(sml_change_item_set_data(item, data, strlen(data)+3, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + const char* result = sml_change_item_get_data(item); + sml_fail_unless(result != NULL, "The data must be present."); + sml_fail_unless(strcmp(result, data) == 0, "The data must be '%s'.", result); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_planned_size) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_change_item_set_planned_size(item, 0); + sml_change_item_set_planned_size(item, 1); + sml_change_item_set_planned_size(item, 2); + sml_change_item_set_planned_size(item, 0); + sml_change_item_set_planned_size(item, 1); + sml_change_item_set_planned_size(item, 0); + sml_change_item_set_planned_size(item, 2); + sml_change_item_set_planned_size(item, 2); + sml_change_item_set_planned_size(item, 0); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_planned_size) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_planned_size(item) == 0, NULL); + sml_change_item_set_planned_size(item, 0); + sml_fail_unless(sml_change_item_get_planned_size(item) == 0, NULL); + sml_change_item_set_planned_size(item, 1); + sml_fail_unless(sml_change_item_get_planned_size(item) == 1, NULL); + sml_change_item_set_planned_size(item, 2); + sml_fail_unless(sml_change_item_get_planned_size(item) == 2, NULL); + sml_change_item_set_planned_size(item, 0); + sml_fail_unless(sml_change_item_get_planned_size(item) == 0, NULL); + sml_change_item_set_planned_size(item, 1); + sml_fail_unless(sml_change_item_get_planned_size(item) == 1, NULL); + sml_change_item_set_planned_size(item, 0); + sml_fail_unless(sml_change_item_get_planned_size(item) == 0, NULL); + sml_change_item_set_planned_size(item, 2); + sml_fail_unless(sml_change_item_get_planned_size(item) == 2, NULL); + sml_change_item_set_planned_size(item, 2); + sml_fail_unless(sml_change_item_get_planned_size(item) == 2, NULL); + sml_change_item_set_planned_size(item, 0); + sml_fail_unless(sml_change_item_get_planned_size(item) == 0, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_content_type) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_set_content_type(item, "text/plain", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_set_content_type(item, "text/html", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_set_content_type_not_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_change_item_set_content_type(item, NULL, &error), NULL); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_content_type) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_get_content_type(item) == NULL, "The default content-type is NULL."); + + sml_fail_unless(sml_change_item_set_content_type(item, "text/plain", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + const char* result = sml_change_item_get_content_type(item); + sml_fail_unless(result != NULL, "The content-type is present."); + sml_fail_unless(strcmp(result, "text/plain") == 0, "The content-type must be text/plain."); + + sml_fail_unless(sml_change_item_set_content_type(item, "text/html", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + result = sml_change_item_get_content_type(item); + sml_fail_unless(result != NULL, "The content-type is present."); + sml_fail_unless(strcmp(result, "text/html") == 0, "The content-type must be text/html."); + + sml_fail_unless(!sml_change_item_set_content_type(item, NULL, &error), NULL); + sml_fail_unless(error != NULL, NULL); + g_error_free(error); + error = NULL; + result = sml_change_item_get_content_type(item); + sml_fail_unless(result != NULL, "The content-type is present."); + sml_fail_unless(strcmp(result, "text/html") == 0, "The content-type must be text/html."); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_fragment_missing_data) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + + sml_fail_unless(!sml_change_item_get_fragment(item, 0, 10, &error), "Fragmentation on empty items is not supported."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_fragment) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + + const gchar* data = "1234567890abcdefghijklmnopqrstuvwxyz"; + sml_fail_unless(sml_change_item_set_data(item, data, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* get the first chunk */ + + SmlChangeItem *frag = sml_change_item_get_fragment(item, 0, 10, &error); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_get_local(frag) == NULL, NULL); + sml_fail_unless(sml_change_item_get_remote(frag) == NULL, NULL); + sml_fail_unless(sml_change_item_get_content_type(frag) == NULL, NULL); + sml_fail_unless(sml_change_item_get_missing_data(frag) == TRUE, NULL); + /* only the first element contains the size */ + sml_fail_unless(sml_change_item_get_planned_size(frag) == strlen(data), NULL); + sml_fail_unless(sml_change_item_get_data(frag) != NULL, NULL); + sml_fail_unless(strcmp("1234567890", sml_change_item_get_data(frag)) == 0, NULL); + g_object_unref(frag); + frag = NULL; + + /* set location and content-type */ + + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_set_content_type(item, "text/plain", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* get the next chunk with location and content-type */ + + frag = sml_change_item_get_fragment(item, 10, 10, &error); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_get_local(frag) == location, NULL); + sml_fail_unless(sml_change_item_get_remote(frag) == location, NULL); + sml_fail_unless(sml_change_item_get_content_type(frag) != NULL, NULL); + sml_fail_unless(strcmp(sml_change_item_get_content_type(frag), "text/plain") == 0, NULL); + sml_fail_unless(sml_change_item_get_missing_data(frag) == TRUE, NULL); + sml_fail_unless(sml_change_item_get_planned_size(frag) == 0, NULL); + sml_fail_unless(sml_change_item_get_data(frag) != NULL, NULL); + sml_fail_unless(strcmp("abcdefghij", sml_change_item_get_data(frag)) == 0, NULL); + g_object_unref(frag); + + /* get last chunk */ + + frag = sml_change_item_get_fragment(item, 20, 16, &error); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_get_local(frag) == location, NULL); + sml_fail_unless(sml_change_item_get_remote(frag) == location, NULL); + sml_fail_unless(sml_change_item_get_content_type(frag) != NULL, NULL); + sml_fail_unless(strcmp(sml_change_item_get_content_type(frag), "text/plain") == 0, NULL); + sml_fail_unless(sml_change_item_get_missing_data(frag) == FALSE, NULL); + sml_fail_unless(sml_change_item_get_planned_size(frag) == 0, NULL); + sml_fail_unless(sml_change_item_get_data(frag) != NULL, NULL); + sml_fail_unless(strcmp("klmnopqrstuvwxyz", sml_change_item_get_data(frag)) == 0, NULL); + g_object_unref(frag); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_too_large_fragment) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + + const gchar* data = "1234567890abcdefghijklmnopqrstuvwxyz"; + sml_fail_unless(sml_change_item_set_data(item, data, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* get the first chunk */ + + SmlChangeItem *frag = sml_change_item_get_fragment(item, 0, strlen(data)+1, &error); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_get_local(frag) == NULL, NULL); + sml_fail_unless(sml_change_item_get_remote(frag) == NULL, NULL); + sml_fail_unless(sml_change_item_get_content_type(frag) == NULL, NULL); + sml_fail_unless(sml_change_item_get_missing_data(frag) == FALSE, NULL); + sml_fail_unless(sml_change_item_get_planned_size(frag) == 0, NULL); + sml_fail_unless(sml_change_item_get_data(frag) != NULL, NULL); + sml_fail_unless(strcmp(data, sml_change_item_get_data(frag)) == 0, NULL); + g_object_unref(frag); + frag = NULL; + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_get_illegal_fragment) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + + const gchar* data = "1234567890abcdefghijklmnopqrstuvwxyz"; + sml_fail_unless(sml_change_item_set_data(item, data, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* get the first chunk */ + + sml_fail_unless(!sml_change_item_get_fragment(item, strlen(data), 10, &error), "The fragment start position is too large."); + sml_fail_unless(error != NULL, NULL); + g_error_free(error); + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_attach_empty_fragment) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + SmlChangeItem *frag = sml_change_item_new(); + + sml_fail_unless(!sml_change_item_attach_fragment(item, NULL, &error), "A fragment cannot be empty."); + sml_fail_unless(error != NULL, NULL); + g_error_free(error); + error = NULL; + + sml_fail_unless(!sml_change_item_attach_fragment(item, frag, &error), "A fragment cannot be empty."); + sml_fail_unless(error != NULL, NULL); + g_error_free(error); + error = NULL; + + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_attach_fragment) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + + const gchar* data1 = "1234567890"; + const gchar* data2 = "abcdefghij"; + const gchar* data3 = "klmnopqrstuvwxyz"; + + sml_change_item_set_planned_size(item, strlen(data1) + strlen(data2) + strlen(data3)); + sml_fail_unless(sml_change_item_set_data(item, data1, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(item, TRUE); + + /* add the first chunk */ + + SmlChangeItem *frag = sml_change_item_new(); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_change_item_set_data(frag, data2, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(frag, TRUE); + + sml_fail_unless(sml_change_item_attach_fragment(item, frag, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(strlen(sml_change_item_get_data(item)) == strlen(data1) + strlen(data2), NULL); + sml_fail_unless(sml_change_item_get_missing_data(item) == TRUE, NULL); + sml_fail_unless(sml_change_item_get_local(item) == NULL, NULL); + sml_fail_unless(sml_change_item_get_remote(item) == NULL, NULL); + sml_fail_unless(sml_change_item_get_content_type(item) == NULL, NULL); + g_object_unref(frag); + frag = NULL; + + /* set location and content-type */ + + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_set_content_type(item, "text/plain", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* add the last chunk with location and content-type */ + + frag = sml_change_item_new(); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_change_item_set_data(frag, data3, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(frag, FALSE); + sml_fail_unless(sml_change_item_set_local(frag, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_set_remote(frag, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_change_item_set_content_type(frag, "text/plain", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_change_item_attach_fragment(item, frag, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(strlen(sml_change_item_get_data(item)) == strlen(data1) + strlen(data2) + strlen(data3), NULL); + sml_fail_unless(sml_change_item_get_missing_data(item) == FALSE, NULL); + sml_fail_unless(sml_change_item_get_local(item) == location, NULL); + sml_fail_unless(sml_change_item_get_remote(item) == location, NULL); + sml_fail_unless(strcmp(sml_change_item_get_content_type(item), "text/plain") == 0, NULL); + g_object_unref(frag); + frag = NULL; + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_attach_too_long_fragment) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + + const gchar* data1 = "1234567890"; + const gchar* data3 = "klmnopqrstuvwxyz"; + const gchar* datak = "klmnopqrstuvwxyzABC"; + + sml_change_item_set_planned_size(item, strlen(data1) + strlen(data3)); + sml_fail_unless(sml_change_item_set_data(item, data1, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(item, TRUE); + + /* add the too large chunk */ + + SmlChangeItem *frag = sml_change_item_new(); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_change_item_set_data(frag, datak, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(frag, FALSE); + + sml_fail_unless(!sml_change_item_attach_fragment(item, frag, &error), "The fragment is larger then the planned size."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(frag); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_attach_unnecessary_fragment) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + + const gchar* data1 = "1234567890"; + const gchar* data2 = "abcdefghij"; + const gchar* data3 = "klmnopqrstuvwxyz"; + + sml_change_item_set_planned_size(item, strlen(data1) + strlen(data2)); + sml_fail_unless(sml_change_item_set_data(item, data1, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(item, TRUE); + + /* add the first and last chunk */ + + SmlChangeItem *frag = sml_change_item_new(); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_change_item_set_data(frag, data2, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(frag, FALSE); + + sml_fail_unless(sml_change_item_attach_fragment(item, frag, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(strlen(sml_change_item_get_data(item)) == strlen(data1) + strlen(data2), NULL); + sml_fail_unless(sml_change_item_get_missing_data(item) == FALSE, NULL); + sml_fail_unless(sml_change_item_get_local(item) == NULL, NULL); + sml_fail_unless(sml_change_item_get_remote(item) == NULL, NULL); + sml_fail_unless(sml_change_item_get_content_type(item) == NULL, NULL); + g_object_unref(frag); + frag = NULL; + + /* add the unnecessary chunk */ + + frag = sml_change_item_new(); + sml_fail_unless(frag != NULL, "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_change_item_set_data(frag, data3, 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_change_item_set_missing_data(frag, FALSE); + + sml_fail_unless(!sml_change_item_attach_fragment(item, frag, &error), "The chunk is not necessary."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(frag); + g_object_unref(item); +} +END_TEST + +START_TEST (change_item_references) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlChangeItem *item = sml_change_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_change_item_set_data(item, "1234", 0, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_ref(item); + + sml_fail_unless(sml_change_item_get_data(item) != NULL, "The data was not set."); + + g_object_unref(item); + + sml_fail_unless(sml_change_item_get_data(item) != NULL, "The data is already cleaned up."); + + g_object_unref(item); +} +END_TEST + +@SML_TESTCASE_CODE@ + |
From: <svn...@op...> - 2009-08-02 18:37:50
|
Author: scriptor Date: Sun Aug 2 20:37:34 2009 New Revision: 5709 URL: http://www.opensync.org/changeset/5709 Log: The LDAP plugin of opensync can now be built against libldap60 from mozldap. Packages used on fedora 11 are: mozldap-6.0.5-5.fc11.x86_64 mozldap-devel-6.0.5-5.fc11.x86_64 mozldap-tools-6.0.5-5.fc11.x86_64 So there are now two possibilities for the linking, and two possibilities of LDAP servers to interact with. This means: If the plugin is built with libldap from openldap, it can talk to: - slapd from openldap - The fedora directory server, which is essentially ns-slapd derived from Mozilla. If the plugin is built with libldap60 from Mozilla (mozldap), it can talk to: - slapd from openldap - The fedora directory server (service dirsrv; ns-slapd) Please note: The build process as well as the synchronization functionality are still in alpha state. Especially the authentication towards the LDAP server has some problems and bugs in the current version. The documentation is NOT up to date, yet. The test suite is NOT up to date, either. Added: branches/3rd-party-cmake-modules/modules/FindLibMozLdap.cmake Modified: plugins/ldap-sync/CMakeLists.txt plugins/ldap-sync/config.h.cmake plugins/ldap-sync/src/CMakeLists.txt plugins/ldap-sync/src/ldap_connect.c plugins/ldap-sync/src/ldap_debug.c plugins/ldap-sync/src/ldap_plugin.c plugins/ldap-sync/src/ldap_plugin.h plugins/ldap-sync/src/ldap_sasl.c Added: branches/3rd-party-cmake-modules/modules/FindLibMozLdap.cmake ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ branches/3rd-party-cmake-modules/modules/FindLibMozLdap.cmake Sun Aug 2 20:37:34 2009 (r5709) @@ -0,0 +1,96 @@ +# Try and find libmozldap. +# As soon as libmozldap has been found, the following variables will be defined: +# +# LIBMOZLDAP_FOUND (this is or is not #defined) +# MOZLDAP_INCLUDE_DIR:DIRPATH +# MOZLDAP_LIBRARY:FILEPATH +# +# +# Copyright (c) 2009 Juergen Leising <jle...@us...> +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +MESSAGE(STATUS "checking for libmozldap...") + +# Prepare for using pkg-config +INCLUDE( FindPkgConfig ) + +IF ( LibMozLdap_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "REQUIRED" ) +ELSE ( LibMozLdap_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "" ) +ENDIF ( LibMozLdap_FIND_REQUIRED ) + +FIND_PROGRAM( PKGCONFIG_EXECUTABLE NAMES pkg-config ) + + + +# Search for the header files and the libraries by means of pkg-config +IF ( PKG_CONFIG_FOUND ) + MESSAGE (STATUS " Trying to invoke pkg-config...") + # PKG_SEARCH_MODULE ( LIBMOZLDAP ${_pkgconfig_REQUIRED} mozldap ) + PKG_CHECK_MODULES ( LIBMOZLDAP ${_pkgconfig_REQUIRED} mozldap ) + IF ( LIBMOZLDAP_FOUND ) + MESSAGE (STATUS " pkg-config found mozldap.") + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE (STATUS " pkg-config did NOT find mozldap.") + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( PKG_CONFIG_FOUND ) + + + + +# Manually searching for header and library. +# Only, if it has not been found, yet. Which would also be the case, +# if pkg-config could not have been found. +IF ( NOT MOZLDAP_INCLUDE_DIR ) + MESSAGE (STATUS " Falling back to searching for mozldap/ldap.h without pkg-config" ) + FIND_PATH(MOZLDAP_INCLUDE_DIR NAMES mozldap/ldap.h + PATHS /include /usr/include /usr/local/include /usr/share/include /opt/include + DOC "Try and find the header file mozldap/ldap.h.") +ENDIF ( NOT MOZLDAP_INCLUDE_DIR ) + + +IF ( NOT LIBMOZLDAP_LIBRARIES ) + MESSAGE (STATUS " Falling back to searching for libldap60 and libssldap60 without pkg-config" ) + + FIND_LIBRARY(MOZLDAP_LIBRARY NAMES ldap60 + PATHS /usr/lib /lib /usr/local/lib /usr/share/lib /opt/lib /opt/share/lib /var/lib /usr/lib64 /lib64 /usr/local/lib64 /usr/share/lib64 /opt/lib64 /opt/share/lib64 /var/lib64 + DOC "Try and find libldap60 from Mozilla.") + + FIND_LIBRARY(MOZSSLDAP_LIBRARY NAMES ssldap60 + PATHS /usr/lib /lib /usr/local/lib /usr/share/lib /opt/lib /opt/share/lib /var/lib /usr/lib64 /lib64 /usr/local/lib64 /usr/share/lib64 /opt/lib64 /opt/share/lib64 /var/lib64 + DOC "Try and find libssldap60 from Mozilla.") + + SET ( LIBMOZLDAP_LIBRARIES ${MOZLDAP_LIBRARY} ${MOZSSLDAP_LIBRARY} ) + +ENDIF ( NOT LIBMOZLDAP_LIBRARIES ) + + + + + +# Reviewing the results +IF (MOZLDAP_INCLUDE_DIR AND MOZLDAP_LIBRARY) + SET( LIBMOZLDAP_FOUND 1 ) + get_filename_component(MOZLDAP_LIBRARY_DIRS ${MOZLDAP_LIBRARY} PATH) + MESSAGE(STATUS " Found ${MOZLDAP_LIBRARY}") +ELSE (MOZLDAP_INCLUDE_DIR AND MOZLDAP_LIBRARY) + IF ( LibMozLdap_FIND_REQUIRED ) + MESSAGE( FATAL_ERROR " Could NOT find libldap60 from Mozilla. The ldap plugin needs this library.") + ELSE ( LibMozLdap_FIND_REQUIRED ) + MESSAGE( STATUS " Could NOT find libldap60 from Mozilla." ) + MESSAGE( STATUS " LIBMOZLDAP_INCLUDE_DIR = ${LIBMOZLDAP_INCLUDE_DIR}" ) + MESSAGE( STATUS " LIBMOZLDAP_INCLUDE_DIRS = ${LIBMOZLDAP_INCLUDE_DIRS}" ) + MESSAGE( STATUS " LIBMOZLDAP_LIBRARY = ${LIBMOZLDAP_LIBRARY}" ) + MESSAGE( STATUS " LIBMOZLDAP_LIBRARY_DIRS = ${LIBMOZLDAP_LIBRARY_DIRS}" ) + MESSAGE( STATUS " LIBMOZLDAP_LIBDIR = ${LIBMOZLDAP_LIBDIR}" ) + + + ENDIF ( LibMozLdap_FIND_REQUIRED ) +ENDIF (MOZLDAP_INCLUDE_DIR AND MOZLDAP_LIBRARY) + Modified: plugins/ldap-sync/CMakeLists.txt ============================================================================== --- plugins/ldap-sync/CMakeLists.txt Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/CMakeLists.txt Sun Aug 2 20:37:34 2009 (r5709) @@ -40,11 +40,23 @@ FIND_PACKAGE( GLIB2 REQUIRED ) FIND_PACKAGE( LibXml2 REQUIRED ) FIND_PACKAGE( LibXslt REQUIRED ) -FIND_PACKAGE( LibLdap REQUIRED ) +FIND_PACKAGE( LibLdap ) +FIND_PACKAGE( LibMozLdap ) FIND_PACKAGE( LibGCrypt REQUIRED ) +FIND_PACKAGE( LibSASL2 REQUIRED ) FIND_PACKAGE( LibGSSAPIV2 ) +# By default use openldap, if available. +# Fall back to mozldap only, if necessary (and possible, of course). +IF ( LIBLDAP_FOUND ) + SET ( USE_OPENLDAP 1 ) +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + SET ( USE_MOZLDAP 1 ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + ############### Doxygen ############################ MESSAGE(STATUS "checking for doxygen...") @@ -129,6 +141,13 @@ MESSAGE(STATUS "CWD = $ENV{PWD}" ) MESSAGE(STATUS "LDAP_PLUGIN_OPENSYNC_CONFIGDIR = ${LDAP_PLUGIN_OPENSYNC_CONFIGDIR}") MESSAGE(STATUS "LDAP_PLUGIN_OPENSYNC_SCHEMASDIR = ${LDAP_PLUGIN_OPENSYNC_SCHEMASDIR}") +IF ( USE_OPENLDAP ) + MESSAGE(STATUS "libldap from openldap is to be used.") +ELSE ( USE_OPENLDAP ) + IF ( USE_MOZLDAP ) + MESSAGE(STATUS "libldap60 from Mozilla is to be used.") + ENDIF ( USE_MOZLDAP ) +ENDIF ( USE_OPENLDAP ) ##################### debugging cmake... ################################# Modified: plugins/ldap-sync/config.h.cmake ============================================================================== --- plugins/ldap-sync/config.h.cmake Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/config.h.cmake Sun Aug 2 20:37:34 2009 (r5709) @@ -1,21 +1,107 @@ #ifndef _CONFIG_H_LDAP_PLUGIN #define _CONFIG_H_LDAP_PLUGIN +/* CFLAGS for the build type "Debug" */ +#cmakedefine CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" -#define CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" -#define CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" -#define CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" -#define CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" -#define HAVE_DOT "${HAVE_DOT}" -#define LDAP_INCLUDE_DIR "${LDAP_INCLUDE_DIR}" -#define LDAP_LIBRARY "${LDAP_LIBRARY}" -#define LIBGSSAPIV2_FOUND "${LIBGSSAPIV2_FOUND}" -#define LIBLDAP_FOUND "${LIBLDAP_FOUND}" -#define LIBSASL2_FOUND "${LIBSASL2_FOUND}" -#define LIBXSLT_FOUND "${LIBXSLT_FOUND}" -#define LDAP_PLUGIN_OPENSYNC_CONFIGDIR "${LDAP_PLUGIN_OPENSYNC_CONFIGDIR}" -#define LDAP_PLUGIN_OPENSYNC_SCHEMASDIR "${LDAP_PLUGIN_OPENSYNC_SCHEMASDIR}" -#define VERSION "${VERSION}" +/* LFLAGS for the build type "Debug" */ +#cmakedefine CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}" + +/* Where are the cmake modules? */ +#cmakedefine CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" + +/* LFLAGS for the build type "Debug" */ +#cmakedefine CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}" + +/* Does the program "dot" exist? Useful for doxygen based documentation + of the source code */ +#cmakedefine HAVE_DOT + + + + +/********************************************************/ +/* There are two alternatives for us which LDAP client library + to use: */ + + + +/****** 1. libldap from openldap: http://www.openldap.org/ ******/ + +/* Whether or not libldap from openldap has been found. */ +#cmakedefine LIBLDAP_FOUND + +/* Whether or not libldap from openldap is to be used. */ +#cmakedefine USE_OPENLDAP + +/* Where is the ldap.h from openldap? */ +#cmakedefine LDAP_INCLUDE_DIR "${LDAP_INCLUDE_DIR}" + +/* Where is libldap.so from openldap? */ +#cmakedefine LDAP_LIBRARY "${LDAP_LIBRARY}" + +/* In which directories can libldap.so be found? */ +#cmakedefine LDAP_LIBRARY_DIRS "${LDAP_LIBRARY_DIRS}" + + + +/****** 2. libldap60 from Mozilla: + http://www.mozilla.org/directory/csdk.html *******/ + +/* Whether or not libldap60 from Mozilla has been found. */ +#cmakedefine LIBMOZLDAP_FOUND + +/* Whether or not libldap60 from Mozilla is to be used. */ +#cmakedefine USE_MOZLDAP + +/* Where is "mozldap/ldap.h" from Mozilla? Please note: + You must write "include <mozldap/ldap.h>" to use this, + not just "include <ldap.h>". (deliberately left out the + hash sign/number sign here to avoid confusing the preprocessor) */ +#cmakedefine MOZLDAP_INCLUDE_DIR "${MOZLDAP_INCLUDE_DIR}" + +/* Where is ldap.h from Mozilla, as pkg-config puts it. + And this means, that one would have to "include <ldap.h>" + WITHOUT prefixing it with "mozldap/". + Be careful with writing the header files on systems + where both of these client libraries are installed. +*/ +#cmakedefine LIBMOZLDAP_INCLUDEDIR "${LIBMOZLDAP_INCLUDEDIR}" + +/* Again, as pkg-config puts it: */ +#cmakedefine LIBMOZLDAP_INCLUDE_DIRS "${LIBMOZLDAP_INCLUDE_DIRS}" + +/* Where is libldap60 from Mozilla? */ +#cmakedefine MOZLDAP_LIBRARY "${MOZLDAP_LIBRARY}" + +/* Which libraries do we need to link against? */ +#cmakedefine LIBMOZLDAP_LIBRARIES "${LIBMOZLDAP_LIBRARIES}" + +/* Where is libldap60 from Mozilla? As pkg-config puts it: */ +#cmakedefine LIBMOZLDAP_LIBDIR "${LIBMOZLDAP_LIBDIR}" + +/***********************************************************/ + + + +/* Whether or not the cyrus-sasl library has been found. */ +#cmakedefine LIBSASL2_FOUND + +/* Is the GSSAPIV2 library available? For kerberos 5. Optional. */ +#cmakedefine LIBGSSAPIV2_FOUND + +/* Whether or not libxslt has been found. */ +#cmakedefine LIBXSLT_FOUND + +/* Where are the libopensync configuration files by default? */ +#cmakedefine LDAP_PLUGIN_OPENSYNC_CONFIGDIR "${LDAP_PLUGIN_OPENSYNC_CONFIGDIR}" + +/* Where are the XML schema files (*.xsd) for XML validation purposes? */ +#cmakedefine LDAP_PLUGIN_OPENSYNC_SCHEMASDIR "${LDAP_PLUGIN_OPENSYNC_SCHEMASDIR}" + +/* The version of the ldap-sync plugin which shares the version number + of the whole opensync package */ +#cmakedefine VERSION "${VERSION}" #endif Modified: plugins/ldap-sync/src/CMakeLists.txt ============================================================================== --- plugins/ldap-sync/src/CMakeLists.txt Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/CMakeLists.txt Sun Aug 2 20:37:34 2009 (r5709) @@ -20,10 +20,101 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # - -LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARY_DIRS} ${LDAP_LIBRARY_DIRS} ${SASL2_LIBRARY_DIRS} ${GSSAPIV2_LIBRARY_DIRS}) -INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${OPENSYNC_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS} ${LIBXSLT_INCLUDE_DIRS} ${LDAP_INCLUDE_DIRS} ${SASL2_INCLUDE_DIRS} ${GSSAPIV2_INCLUDE_DIRS}) + + +# Determine _LDAP_INCLUDE_DIRS +IF ( LIBLDAP_FOUND ) + # libldap from openldap + SET ( _LDAP_INCLUDE_DIRS ${LDAP_INCLUDE_DIR} ) + +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + #libldap60 from Mozilla + IF ( MOZLDAP_INCLUDE_DIR ) + SET ( _LDAP_INCLUDE_DIRS ${MOZLDAP_INCLUDE_DIR} ) + + ELSE ( MOZLDAP_INCLUDE_DIR ) + IF ( LIBMOZLDAP_INCLUDEDIR ) + SET ( _LDAP_INCLUDE_DIRS ${LIBMOZLDAP_INCLUDEDIR}) + ENDIF ( LIBMOZLDAP_INCLUDEDIR ) + ENDIF ( MOZLDAP_INCLUDE_DIR ) + + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE( FATAL_ERROR " Neither libldap from openldap nor libldap60 from Mozilla could be found. The ldap-sync plugin requires one of these libraries including the header files, as can be found in \"development packages\" or \"SDK's\"." ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + + + + +# Determine _LDAP_LIBRARY_DIRS +IF ( LIBLDAP_FOUND ) + SET ( _LDAP_LIBRARY_DIRS ${LDAP_LIBRARY_DIRS} ) +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + IF ( LIBMOZLDAP_LIBDIR ) + SET ( _LDAP_LIBRARY_DIRS ${LIBMOZLDAP_LIBDIR} ) + ENDIF ( LIBMOZLDAP_LIBDIR ) + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE( FATAL_ERROR " Neither libldap from openldap nor libldap60 from Mozilla could be found. The ldap-sync plugin requires one of these." ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + + + + +# Determine _LDAP_LIBRARIES +IF ( LIBLDAP_FOUND ) + SET ( _LDAP_LIBRARIES ${LDAP_LIBRARY} ) +ELSE ( LIBLDAP_FOUND ) + IF ( LIBMOZLDAP_FOUND ) + + IF ( LIBMOZLDAP_LIBRARIES ) + SET ( _LDAP_LIBRARIES ${LIBMOZLDAP_LIBRARIES} ) + + ELSE ( LIBMOZLDAP_LIBRARIES ) + IF ( MOZLDAP_LIBRARY ) + SET ( _LDAP_LIBRARIES ${MOZLDAP_LIBRARY} ) + ELSE ( MOZLDAP_LIBRARY ) + MESSAGE( FATAL_ERROR " Neither LIBMOZLDAP_LIBRARIES nor MOZLDAP_LIBRARY has been defined." ) + ENDIF ( MOZLDAP_LIBRARY ) + + ENDIF ( LIBMOZLDAP_LIBRARIES ) + + ELSE ( LIBMOZLDAP_FOUND ) + MESSAGE( FATAL_ERROR " Neither libldap from openldap nor libldap60 from Mozilla could be found. The ldap-sync plugin requires one of these." ) + ENDIF ( LIBMOZLDAP_FOUND ) +ENDIF ( LIBLDAP_FOUND ) + + + + + + + + +# Safety checks +IF ( NOT _LDAP_INCLUDE_DIRS ) + MESSAGE( FATAL_ERROR " _LDAP_INCLUDE_DIRS could not be determined. The ldap-sync plugin requires the header files of an LDAP client library, either from openldap or from Mozilla." ) +ELSE ( NOT _LDAP_INCLUDE_DIRS ) + MESSAGE( STATUS "_LDAP_INCLUDE_DIRS = \"${_LDAP_INCLUDE_DIRS}\"" ) +ENDIF ( NOT _LDAP_INCLUDE_DIRS ) + +IF ( NOT _LDAP_LIBRARY_DIRS ) + MESSAGE( FATAL ERROR " _LDAP_LIBRARY_DIRS could not be determined. The build process of the ldap-sync plugin must know where to find the ldap libraries.") +ELSE ( NOT _LDAP_LIBRARY_DIRS ) + MESSAGE( STATUS "_LDAP_LIBRARY_DIRS = \"${_LDAP_LIBRARY_DIRS}\"" ) +ENDIF ( NOT _LDAP_LIBRARY_DIRS ) + +IF ( NOT _LDAP_LIBRARIES ) + MESSAGE( FATAL ERROR " _LDAP_LIBRARIES could not be determined. The build process of the ldap-sync plugin requires the ldap library.") +ELSE ( NOT _LDAP_LIBRARIES ) + MESSAGE( STATUS "_LDAP_LIBRARIES = \"${_LDAP_LIBRARIES}\"" ) +ENDIF ( NOT _LDAP_LIBRARIES ) + +LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARY_DIRS} ${_LDAP_LIBRARY_DIRS} ${SASL2_LIBRARY_DIRS} ${GSSAPIV2_LIBRARY_DIRS}) +INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} ${OPENSYNC_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS} ${LIBXSLT_INCLUDE_DIRS} ${_LDAP_INCLUDE_DIRS} ${SASL2_INCLUDE_DIRS} ${GSSAPIV2_INCLUDE_DIRS}) INCLUDE( Compiler ) @@ -33,8 +124,8 @@ -TARGET_LINK_LIBRARIES( ldap-sync ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${LDAP_LIBRARY} ${GCRYPT_LIBRARY} ${SASL2_LIBRARY}) -TARGET_LINK_LIBRARIES( ldap-format ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${LDAP_LIBRARY} ${GCRYPT_LIBRARY}) +TARGET_LINK_LIBRARIES( ldap-sync ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${_LDAP_LIBRARIES} ${GCRYPT_LIBRARY} ${SASL2_LIBRARY}) +TARGET_LINK_LIBRARIES( ldap-format ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARY_DIRS} ${LIBXSLT_LIBRARIES} ${_LDAP_LIBRARIES} ${GCRYPT_LIBRARY}) Modified: plugins/ldap-sync/src/ldap_connect.c ============================================================================== --- plugins/ldap-sync/src/ldap_connect.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_connect.c Sun Aug 2 20:37:34 2009 (r5709) @@ -131,11 +131,27 @@ - +#ifdef USE_OPENLDAP if (ldap_is_ldap_url(sinkenv->servername) || ldap_is_ldaps_url(sinkenv->servername)) { +#else +# ifdef USE_MOZLDAP + if (ldap_is_ldap_url(sinkenv->servername)) { +# else +# error __FILE__ ":" __LINE__ ": ERROR: Neither USE_OPENLDAP nor USE_MOZLDAP has been defined. Compiler cannot proceed." +# endif +#endif + sinkenv->url = g_strdup(sinkenv->servername); +#ifdef USE_OPENLDAP ldap_initialize(&(sinkenv->ld), sinkenv->servername); +#else +# ifdef USE_MOZLDAP + sinkenv->ld = ldap_init(sinkenv->servername, sinkenv->serverport); +# else + sinkenv->ld = NULL; +# endif +#endif if (sinkenv->ld == NULL ) { osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "Could not connect to \"%s\"", sinkenv->servername); @@ -156,10 +172,21 @@ } - osync_trace(TRACE_INTERNAL, "%s:%i: INFO: url = \"%s\"\n", __FILE__, __LINE__, sinkenv->url); + +#ifdef USE_OPENLDAP ldap_initialize(&(sinkenv->ld), sinkenv->url); +#else +# ifdef USE_MOZLDAP + sinkenv->ld = ldap_init(sinkenv->servername, sinkenv->serverport); +# else + sinkenv->ld = NULL; +#endif +#endif + + + if (sinkenv->ld == NULL ) { osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "Could not connect to \"%s\"", sinkenv->url); @@ -680,7 +707,7 @@ */ osync_bool ldap_plugin_set_ldap_protocol (OSyncContext *ctx, OSyncPluginInfo *info, sink_environment *sinkenv, OSyncError **error) { - int *ldap_version = NULL; + int *ldap_protocol_version = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, ctx, info, sinkenv, error); @@ -710,9 +737,9 @@ char *ldap_error1 = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, ldap_errno); /* Couldn't set version, store connection's version in sinkenv */ - ldap_get_option(sinkenv->ld, LDAP_OPT_PROTOCOL_VERSION, ldap_version); + ldap_get_option(sinkenv->ld, LDAP_OPT_PROTOCOL_VERSION, ldap_protocol_version); - if (ldap_version == NULL) { + if (ldap_protocol_version == NULL) { if (ldap_error1 == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: 1. Could not set LDAP Version to %i. 2. Could not retrieve ldap_version, either. Returning.\n", __FILE__, __LINE__, sinkenv->ldap_version); } else { @@ -723,13 +750,13 @@ } if (ldap_error1 == NULL) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, using %i\n", __FILE__, __LINE__, sinkenv->ldap_version, *ldap_version); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, using %i\n", __FILE__, __LINE__, sinkenv->ldap_version, *ldap_protocol_version); } else { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, because: \"%s\". Using version %i. \n", __FILE__, __LINE__, sinkenv->ldap_version, ldap_error1, *ldap_version); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Could not set LDAP Version to %i, because: \"%s\". Using version %i. \n", __FILE__, __LINE__, sinkenv->ldap_version, ldap_error1, *ldap_protocol_version); } - sinkenv->ldap_version = *ldap_version; + sinkenv->ldap_version = *ldap_protocol_version; goto error; } @@ -893,7 +920,7 @@ osync_trace(TRACE_INTERNAL, "Simple authentication towards LDAP server selected"); - passwd.bv_val = ber_strdup(bindpwd); + passwd.bv_val = g_strdup(bindpwd); passwd.bv_len = strlen( passwd.bv_val ); @@ -927,10 +954,10 @@ osync_trace(TRACE_INTERNAL, "SASL based authentication towards LDAP server selected"); - passwd.bv_val = ber_strdup(bindpwd); + passwd.bv_val = g_strdup(bindpwd); passwd.bv_len = strlen( passwd.bv_val ); - tmp_authmech = ber_strdup(authmech); - tmp_authcid = ber_strdup(authcid); + tmp_authmech = g_strdup(authmech); + tmp_authcid = g_strdup(authcid); // Load default parameters into a libldap specific struct @@ -951,7 +978,7 @@ char *extra_error = NULL; - ldap_plugin_printf("%s:%i: ldap_errno = %i", __FILE__, __LINE__, ldap_errno); + ldap_plugin_printf("%s:%i: ERROR: ldap_errno = %i", __FILE__, __LINE__, ldap_errno); if ( (ldap_errno == LDAP_AUTH_METHOD_NOT_SUPPORTED) || @@ -1335,7 +1362,15 @@ if (all_entries == NULL) { int result_code = 0; + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in.\n", __FILE__, __LINE__); } else { if (result_code != LDAP_SUCCESS) { @@ -1470,11 +1505,23 @@ switch(kind_of_attributes) { case USER_ATTRIBUTES: +#ifdef LDAP_ALL_USER_ATTRIBUTES + // openldap version userattributes[0] = LDAP_ALL_USER_ATTRIBUTES; +#else + // mozldap version + userattributes[0] = NULL; +#endif break; case OPERATIONAL_ATTRIBUTES: +#ifdef LDAP_ALL_OPERATIONAL_ATTRIBUTES + // openldap version userattributes[0] = LDAP_ALL_OPERATIONAL_ATTRIBUTES; +#else + // mozldap version + userattributes[0] = "+"; +#endif break; case OBJECTCLASSES: @@ -1486,7 +1533,14 @@ break; default: +#ifdef LDAP_ALL_USER_ATTRIBUTES + // openldap version userattributes[0] = LDAP_ALL_USER_ATTRIBUTES; +#else + // xxx jl: TODO ??????????????? + // mozldap version + userattributes[0] = NULL; +#endif }; @@ -1523,8 +1577,9 @@ searchbase, scope, filter, - (char **)&userattributes, ///< The attrs parameter is a null-terminated - ///< array of attribute descriptions to return from matching entries. + (char **)&userattributes, ///< Quoting from ldap_search(3) from openldap: + ///< The attrs parameter is a null-terminated array of attribute + ///< descriptions to return from matching entries. ///< If NULL is specified, the return of all user attributes is ///< requested. The description "*" (LDAP_ALL_USER_ATTRIBUTES) may be ///< used to request all user attributes to be returned. @@ -1561,11 +1616,13 @@ case LDAP_SCOPE_SUBTREE: scope_str = "sub"; break; - + +#ifdef LDAP_SCOPE_CHILDREN + // openldap version; mozldap does not support this case LDAP_SCOPE_CHILDREN: scope_str = "children"; break; - +#endif default: scope_str = "default"; break; @@ -1645,8 +1702,14 @@ if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, dn, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, TRUE, &all_results, error)) { int result_code = 0; - + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif if (result_code == LDAP_NO_SUCH_OBJECT) { #ifdef DEBUG_change_type_deleted @@ -1671,8 +1734,14 @@ if (all_results == NULL) { int result_code = 0; - + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif if (result_code == LDAP_NO_SUCH_OBJECT) { #ifdef DEBUG_change_type_deleted @@ -2038,8 +2107,15 @@ osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } - + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif + if (result_code == LDAP_NO_SUCH_OBJECT) { osync_trace(TRACE_INTERNAL, "%s:%i: Either the searchbase (\"%s\") is really wrong, or the user does not have sufficient access permissions to this particular part of the DIT, or there is indeed not a single entry.", __FILE__, __LINE__, base); @@ -2066,7 +2142,14 @@ int result_code = 0; +#ifdef LDAP_OPT_RESULT_CODE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif + if (result_code == LDAP_SUCCESS) { goto done; @@ -2495,7 +2578,14 @@ osync_trace(TRACE_INTERNAL, "%s:%i: uid = NULL. Returning NULL. May be, that there is really not a single entry stored on the LDAP server. Authentication mechanism = \"%s\", objtype = \"%s\", scope LDAP_SCOPE_ONELEVEL, searchbase = \"%s\", filter=\"%s\".\n", __FILE__, __LINE__, sinkenv->authmech, osync_objtype_sink_get_name(sinkenv->sink), sinkenv->searchbase, filter); +#ifdef LDAP_OPT_RESULT_CODE + // openldap version if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in. \n", __FILE__, __LINE__); goto error; @@ -4485,7 +4575,7 @@ filter = g_strdup_printf("(entryCSN=*)"); } - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUB, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &messages, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUBTREE, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &messages, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -4500,7 +4590,7 @@ filter = g_strdup_printf("(modifyTimestamp=*)"); } - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUB, FEDORADSmodifyTimestamp, sinkenv, FALSE, &messages, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUBTREE, FEDORADSmodifyTimestamp, sinkenv, FALSE, &messages, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -4522,7 +4612,15 @@ if (messages == NULL) { int result_code = 0; + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in.\n", __FILE__, __LINE__); } else { char *error_msg = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, result_code); Modified: plugins/ldap-sync/src/ldap_debug.c ============================================================================== --- plugins/ldap-sync/src/ldap_debug.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_debug.c Sun Aug 2 20:37:34 2009 (r5709) @@ -124,7 +124,14 @@ if (sinkenv->ld) { +#ifdef LDAP_OPT_RESULT_CODE + // openldap version: if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { +#else + // mozldap version: + if (ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code)) { +#endif + ldap_plugin_printf("%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in.", __FILE__, __LINE__); } else { if (result_code != 0) { @@ -478,7 +485,13 @@ strncat(buf, msg2, 4096 - strlen(buf)); if (sinkenv && sinkenv->ld) { +#ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE + // openldap version ldap_get_option(sinkenv->ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, &msg3); +#else + // mozldap version + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_STRING, &msg3); +#endif } if (msg3 && msg3[0]) { Modified: plugins/ldap-sync/src/ldap_plugin.c ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_plugin.c Sun Aug 2 20:37:34 2009 (r5709) @@ -3310,7 +3310,13 @@ int result_code = 0; +#ifdef LDAP_OPT_RESULT_CODE + // openldap version: ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + // mozldap version: + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif // OK. This error is expected. ldap_add_ext_s() is due. @@ -3557,7 +3563,14 @@ if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, *dn_of_modified_entry, "(objectClass=*)", LDAP_SCOPE_ONELEVEL, USER_ATTRIBUTES, sinkenv, FALSE, &dn_list, error)) { int result_code2 = 0; + +#ifdef LDAP_OPT_RESULT_CODE + // openldap version: ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code2); +#else + // mozldap version: + ldap_get_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code2); +#endif if (result_code2 != LDAP_SUCCESS) { char *msg = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, result_code2); @@ -3956,8 +3969,19 @@ int result_code = 0; const char *diagnostic = ""; + +#ifdef LDAP_OPT_RESULT_CODE ldap_set_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code); +#else + ldap_set_option(sinkenv->ld, LDAP_OPT_ERROR_NUMBER, &result_code); +#endif + + +#ifdef LDAP_OPT_DIAGNOSTIC_MESSAGE ldap_set_option(sinkenv->ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, diagnostic); +#else + ldap_set_option(sinkenv->ld, LDAP_OPT_ERROR_STRING, diagnostic); +#endif } Modified: plugins/ldap-sync/src/ldap_plugin.h ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.h Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_plugin.h Sun Aug 2 20:37:34 2009 (r5709) @@ -33,13 +33,33 @@ #ifndef _LDAP_PLUGIN_H #define _LDAP_PLUGIN_H +#include "config.h" #include <errno.h> #include <ctype.h> #include <gcrypt.h> #include <glib.h> + +#ifdef LIBLDAP_FOUND #include <lber.h> #include <ldap.h> +#else +# ifdef LIBMOZLDAP_FOUND +# ifdef MOZLDAP_INCLUDE_DIR +# include <mozldap/ldap.h> +# include <mozldap/ldap_ssl.h> +# else +# ifdef LIBMOZLDAP_INCLUDEDIR +// I want to make sure that it is really the "mozldap/ldap.h" that +// is to be included. And NOT some /usr/include/ldap.h. +# include <../mozldap/ldap.h> +# include <../mozldap/ldap_ssl.h> +# endif +# endif +# endif +#endif + + #include <libxml/parser.h> #include <libxml/tree.h> #include <libxml/xmlmemory.h> @@ -68,7 +88,6 @@ #include <sys/stat.h> #include <unistd.h> -#include "config.h" #if 0 @@ -131,7 +150,7 @@ ///< ldap_format_convert_xmlinternal2ldap() -#undef DEBUG_auth +// undef DEBUG_auth #undef DEBUG_configuration #undef DEBUG_detection #undef DEBUG_ldapdata_from_server Modified: plugins/ldap-sync/src/ldap_sasl.c ============================================================================== --- plugins/ldap-sync/src/ldap_sasl.c Mon Jul 27 22:39:10 2009 (r5708) +++ plugins/ldap-sync/src/ldap_sasl.c Sun Aug 2 20:37:34 2009 (r5709) @@ -151,23 +151,27 @@ lutilSASLdefaults *ldap_plugin_lutil_sasl_defaults(LDAP *ld, char *mech, char *realm, char *authcid, char *passwd, char *authzid) { - lutilSASLdefaults *defaults; + lutilSASLdefaults *defaults = NULL; if (ld == NULL) { ldap_plugin_printf("%s:%i: ERROR: ld = NULL. Returning.", __FILE__, __LINE__); return NULL; } - - defaults = ber_memalloc( sizeof( lutilSASLdefaults ) ); + +#ifdef USE_OPENLDAP + defaults = ber_memalloc(sizeof( lutilSASLdefaults )); +#else + defaults = malloc(sizeof( lutilSASLdefaults )); +#endif if( defaults == NULL ) return NULL; - defaults->mech = mech ? ber_strdup(mech) : NULL; - defaults->realm = realm ? ber_strdup(realm) : NULL; - defaults->authcid = authcid ? ber_strdup(authcid) : NULL; - defaults->passwd = passwd ? ber_strdup(passwd) : NULL; - defaults->authzid = authzid ? ber_strdup(authzid) : NULL; + defaults->mech = mech ? g_strdup(mech) : NULL; + defaults->realm = realm ? g_strdup(realm) : NULL; + defaults->authcid = authcid ? g_strdup(authcid) : NULL; + defaults->passwd = passwd ? g_strdup(passwd) : NULL; + defaults->authzid = authzid ? g_strdup(authzid) : NULL; if( defaults->mech == NULL ) { |
From: <svn...@op...> - 2009-08-01 15:24:04
|
Author: bellmich Date: Sat Aug 1 17:23:46 2009 New Revision: 1224 URL: http://libsyncml.opensync.org/changeset/1224 Log: - renamed SmlDataSyncMapItem into SmlMapItem - integrated SmlMapItem into DS API - fixed synchronous map handling (now asynchron) - fixed tests to support asynchronous map handling Added: trunk/libsyncml/data_sync_api/sml_map_item.c trunk/libsyncml/data_sync_api/sml_map_item.h trunk/libsyncml/data_sync_api/sml_map_item_internals.h Deleted: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h Modified: trunk/libsyncml/CMakeLists.txt trunk/libsyncml/data_sync_api/callbacks.h trunk/libsyncml/data_sync_api/data_sync.c trunk/libsyncml/data_sync_api/data_sync_callbacks.c trunk/libsyncml/data_sync_api/data_sync_callbacks.h trunk/libsyncml/data_sync_api/standard.h trunk/libsyncml/objects/sml_ds_server.c trunk/libsyncml/objects/sml_ds_server.h trunk/libsyncml/objects/sml_ds_server_internals.h trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_command.c trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_elements_internals.h trunk/libsyncml/sml_session.c trunk/tests/CMakeLists.txt trunk/tests/check_data_sync_api_map_item.c trunk/tests/check_ds.c trunk/tests/check_sync.c Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/CMakeLists.txt Sat Aug 1 17:23:46 2009 (r1224) @@ -24,7 +24,7 @@ data_sync_api/data_sync_client.c data_sync_api/data_sync_server.c data_sync_api/sml_location.c - data_sync_api/sml_data_sync_map_item.c + data_sync_api/sml_map_item.c data_sync_api/transport_http_client.c data_sync_api/transport_http_server.c data_sync_api/transport_obex_client.c @@ -79,7 +79,7 @@ INSTALL( FILES data_sync_api/sml_location.h - data_sync_api/sml_data_sync_map_item.h + data_sync_api/sml_map_item.h data_sync_api/defines.h data_sync_api/standard.h data_sync_api/callbacks.h Modified: trunk/libsyncml/data_sync_api/callbacks.h ============================================================================== --- trunk/libsyncml/data_sync_api/callbacks.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/callbacks.h Sat Aug 1 17:23:46 2009 (r1224) @@ -31,6 +31,7 @@ #include <libsyncml/data_sync_api/defines.h> #include <libsyncml/data_sync_api/standard.h> #include <libsyncml/dev_inf_api/sml_dev_inf.h> +#include <libsyncml/data_sync_api/sml_map_item.h> #include <glib.h> @@ -69,8 +70,7 @@ typedef gboolean (* SmlDataSyncMappingCallback) ( SmlDataSyncObject *dsObject, const gchar *source, - const gchar *orig, - const gchar *newuid, + SmlMapItem *item, void *userdata, GError **error); typedef gchar *(* SmlDataSyncGetAnchorCallback) ( Modified: trunk/libsyncml/data_sync_api/data_sync.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/data_sync.c Sat Aug 1 17:23:46 2009 (r1224) @@ -764,8 +764,7 @@ gboolean smlDataSyncAddMapping (SmlDataSyncObject *dsObject, const gchar *source, - const gchar *remoteID, - const gchar *localID, + SmlMapItem *item, GError **error) { smlTrace(TRACE_ENTRY, "%s(%s)", __func__, VA_STRING(source)); @@ -774,8 +773,7 @@ CHECK_ERROR_REF smlAssert(dsObject); smlAssert(source); - smlAssert(remoteID); - smlAssert(localID); + smlAssert(item); /* A map can only be created if a sync from a server was * received. So it makes no sense to cache the mapping. @@ -786,7 +784,7 @@ datastore = smlDataSyncGetDatastoreFromSource(dsObject, source, error); if (!datastore) goto error; - if (!smlDsSessionQueueMap(datastore->session, remoteID, localID, error)) + if (!smlDsSessionQueueMap(datastore->session, item, error)) goto error; smlTrace(TRACE_EXIT, "%s - TRUE", __func__); Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.c Sat Aug 1 17:23:46 2009 (r1224) @@ -632,11 +632,10 @@ void smlDataSyncMappingCallback( SmlDsSession *dsession, - SmlLocation *orig, - SmlLocation *newuid, + SmlMapItem *item, void *userdata) { - smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, VA_STRING(sml_location_get_uri(orig)), VA_STRING(sml_location_get_uri(newuid)), userdata); + smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, item, userdata); GError *error = NULL; SmlDataSyncDatastore *datastore = userdata; @@ -647,9 +646,9 @@ /* perform callback */ if (!datastore->dsObject->mappingCallback( - datastore->dsObject, datastore->sourceUri, - sml_location_get_uri(orig), - sml_location_get_uri(newuid), + datastore->dsObject, + datastore->sourceUri, + item, datastore->dsObject->mappingUserdata, &error)) goto error; Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.h ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.h Sat Aug 1 17:23:46 2009 (r1224) @@ -90,8 +90,7 @@ void smlDataSyncMappingCallback( SmlDsSession *dsession, - SmlLocation *orig, - SmlLocation *newuid, + SmlMapItem *item, void *userdata); /* ********************************* */ Added: trunk/libsyncml/data_sync_api/sml_map_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_map_item.c Sat Aug 1 17:23:46 2009 (r1224) @@ -0,0 +1,300 @@ +/* sml_map_item.c + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "sml_map_item_internals.h" +#include "../sml_error_internals.h" +#include <string.h> + +G_DEFINE_TYPE (SmlMapItem, sml_map_item, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_REMOTE, + PROP_LOCAL +}; + +struct _SmlMapItemPrivate +{ + SmlLocation* remote; + SmlLocation* local; +}; + +static void +sml_map_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + g_value_set_object (value, SML_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + g_value_set_object (value, SML_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_map_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + if (SML_MAP_ITEM (object)->priv->remote) + g_object_unref (SML_MAP_ITEM (object)->priv->remote); + SML_MAP_ITEM (object)->priv->remote = SML_LOCATION (value); + g_object_ref(SML_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + if (SML_MAP_ITEM (object)->priv->local) + g_object_unref (SML_MAP_ITEM (object)->priv->local); + SML_MAP_ITEM (object)->priv->local = SML_LOCATION (value); + g_object_ref(SML_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_map_item_finalize (GObject *object) +{ + SmlMapItem *self = (SmlMapItem *) object; + g_object_unref(self->priv->remote); + g_object_unref(self->priv->local); + /* all pointers must be NULL */ + self->priv->remote = NULL; + self->priv->local = NULL; + G_OBJECT_CLASS (sml_map_item_parent_class)->finalize (object); +} + +static void +sml_map_item_class_init (SmlMapItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlMapItemPrivate)); + + object_class->get_property = sml_map_item_get_property; + object_class->set_property = sml_map_item_set_property; + object_class->finalize = sml_map_item_finalize; + + /** + * SmlMapItem:remote: + * + * The remote property. + */ + g_object_class_install_property (object_class, + PROP_REMOTE, + g_param_spec_object ("remote", + "remote", + "remote", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + /** + * SmlMapItem:local: + * + * The local property. + */ + g_object_class_install_property (object_class, + PROP_LOCAL, + g_param_spec_object ("local", + "local", + "local", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + +} + +static void +sml_map_item_init (SmlMapItem *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_MAP_ITEM, + SmlMapItemPrivate); +} + +/** + * sml_map_item_new: + * + * Creates a new instance of #SmlMapItem. + * + * Return value: the newly created #SmlMapItem instance + */ +SmlMapItem* +sml_map_item_new (void) +{ + return g_object_new (SML_TYPE_MAP_ITEM, NULL); +} + +/** + * sml_map_item_get_remote: + * @self: A #SmlMapItem + * + * Gets the remote property. + * + * Return value: + */ +SmlLocation* +sml_map_item_get_remote (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + return self->priv->remote; +} + +/** + * sml_map_item_get_remote_uri: + * @self: A #SmlMapItem + * + * Gets the remote URI property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_map_item_get_remote_uri (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + if (!self->priv->remote) + return NULL; + return sml_location_get_uri(self->priv->remote); +} + +/** + * sml_map_item_set_remote: + * @self: A #SmlMapItem + * @remote: + * + * Sets the remote property. + */ +gboolean +sml_map_item_set_remote (SmlMapItem *self, + SmlLocation* remote, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + if (self->priv->remote) + g_object_unref (self->priv->remote); + self->priv->remote = remote; + g_object_ref (remote); + return TRUE; +} + +/** + * sml_map_item_get_local: + * @self: A #SmlMapItem + * + * Gets the local property. + * + * Return value: + */ +SmlLocation* +sml_map_item_get_local (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + return self->priv->local; +} + +/** + * sml_map_item_get_local_uri: + * @self: A #SmlMapItem + * + * Gets the local URI property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_map_item_get_local_uri (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + if (!self->priv->local) + return NULL; + return sml_location_get_uri(self->priv->local); +} + +/** + * sml_map_item_set_local: + * @self: A #SmlMapItem + * @local: + * + * Sets the local property. + */ +gboolean +sml_map_item_set_local (SmlMapItem *self, + SmlLocation* local, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + if (self->priv->local) + g_object_unref (self->priv->local); + self->priv->local = local; + g_object_ref (local); + return TRUE; +} + +/** + * sml_map_item_is_compliant: + * @self: A #SmlMapItem + * + * Checks the compliance with the OMA specifications for mappings. + */ +gboolean +sml_map_item_is_compliant (SmlMapItem *self, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlMapItem object."); + + SmlLocation *remote = self->priv->remote; + sml_return_val_error_if_fail (remote, FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + SmlLocation *local = self->priv->local; + sml_return_val_error_if_fail (local, FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + return TRUE; +} Added: trunk/libsyncml/data_sync_api/sml_map_item.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_map_item.h Sat Aug 1 17:23:46 2009 (r1224) @@ -0,0 +1,64 @@ +/* sml_map_item.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_MAP_ITEM_H__ +#define __SML_MAP_ITEM_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_location.h> + +G_BEGIN_DECLS + +#define SML_TYPE_MAP_ITEM (sml_map_item_get_type()) +#define SML_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_MAP_ITEM, SmlMapItem)) +#define SML_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_MAP_ITEM, SmlMapItemClass)) +#define SML_IS_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_MAP_ITEM)) +#define SML_IS_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_MAP_ITEM)) +#define SML_MAP_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_MAP_ITEM, SmlMapItemClass)) + +typedef struct _SmlMapItem SmlMapItem; +typedef struct _SmlMapItemClass SmlMapItemClass; +typedef struct _SmlMapItemPrivate SmlMapItemPrivate; + +struct _SmlMapItem +{ + GObject parent; + + /*< private >*/ + SmlMapItemPrivate *priv; +}; + +struct _SmlMapItemClass +{ + GObjectClass parent_class; + +}; + +GType sml_map_item_get_type (void); +SmlMapItem* sml_map_item_new (void); +G_CONST_RETURN gchar* sml_map_item_get_local_uri (SmlMapItem *self); +gboolean sml_map_item_set_local (SmlMapItem *self, SmlLocation* local, GError **error); +G_CONST_RETURN gchar* sml_map_item_get_remote_uri (SmlMapItem *self); +gboolean sml_map_item_set_remote (SmlMapItem *self, SmlLocation* remote, GError **error); +gboolean sml_map_item_is_compliant (SmlMapItem *self, GError **error); + +G_END_DECLS + +#endif /* __SML_MAP_ITEM_H__ */ Added: trunk/libsyncml/data_sync_api/sml_map_item_internals.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_map_item_internals.h Sat Aug 1 17:23:46 2009 (r1224) @@ -0,0 +1,34 @@ +/* sml_map_item_internals.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_MAP_ITEM_INTERNALS_H__ +#define __SML_MAP_ITEM_INTERNALS_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_map_item.h> + +G_BEGIN_DECLS + +SmlLocation* sml_map_item_get_local (SmlMapItem *self); +SmlLocation* sml_map_item_get_remote (SmlMapItem *self); + +G_END_DECLS + +#endif /* __SML_MAP_ITEM_INTERNALS_H__ */ Modified: trunk/libsyncml/data_sync_api/standard.h ============================================================================== --- trunk/libsyncml/data_sync_api/standard.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/standard.h Sat Aug 1 17:23:46 2009 (r1224) @@ -35,6 +35,7 @@ #include <libsyncml/data_sync_api/defines.h> #include <libsyncml/data_sync_api/sml_location.h> +#include <libsyncml/data_sync_api/sml_map_item.h> #ifdef __cplusplus extern "C" @@ -68,8 +69,7 @@ gboolean smlDataSyncSendChanges (SmlDataSyncObject *dsObject, GError **error); gboolean smlDataSyncAddMapping (SmlDataSyncObject *dsObject, const gchar *source, - const gchar *remoteID, - const gchar *localID, + SmlMapItem *item, GError **error); /** Modified: trunk/libsyncml/objects/sml_ds_server.c ============================================================================== --- trunk/libsyncml/objects/sml_ds_server.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/objects/sml_ds_server.c Sat Aug 1 17:23:46 2009 (r1224) @@ -33,17 +33,17 @@ { smlTrace(TRACE_ENTRY, "%s(%p, %s, %i)", __func__, dsession, VA_STRING(uid), type); - g_mutex_lock(dsession->pendingMapsLock); + g_mutex_lock(dsession->pendingChangesLock); GList *c = NULL; - for (c = dsession->pendingMaps; c; c = c->next) { + for (c = dsession->pendingChanges; c; c = c->next) { SmlWriteContext *ctx = c->data; if (!strcmp(uid, ctx->uid) && ctx->type == type) { - g_mutex_unlock(dsession->pendingMapsLock); + g_mutex_unlock(dsession->pendingChangesLock); smlTrace(TRACE_EXIT, "%s: %p", __func__, ctx); return ctx; } } - g_mutex_unlock(dsession->pendingMapsLock); + g_mutex_unlock(dsession->pendingChangesLock); smlTrace(TRACE_EXIT_ERROR, "%s: Not found", __func__); return NULL; @@ -59,9 +59,6 @@ if (ctx->uid) smlSafeCFree(&(ctx->uid)); - if (ctx->newuid) - smlSafeCFree(&(ctx->newuid)); - smlSafeFree((gpointer *)&ctx); smlTrace(TRACE_EXIT, "%s", __func__); @@ -76,37 +73,13 @@ return; } - smlTrace(TRACE_INTERNAL, "%s: Dispatching: uid %s, Type %i, newuid %s, result %i", __func__, VA_STRING(ctx->uid), ctx->type, VA_STRING(ctx->newuid), smlStatusGetCode(ctx->status)); + smlTrace(TRACE_INTERNAL, "%s: Dispatching: uid %s, Type %i, result %i", __func__, VA_STRING(ctx->uid), ctx->type, smlStatusGetCode(ctx->status)); - if (ctx->type == SML_CHANGE_ADD && - smlStatusGetClass(ctx->status) == SML_ERRORCLASS_SUCCESS && - !dsession->recvMappingCallback && - !ctx->newuid && - dsession->server->servertype == SML_DS_SERVER) - { - smlTrace(TRACE_EXIT, "%s: No mapitem yet", __func__); - return; - } - ctx->callback(dsession, ctx->status, ctx->userdata); - g_mutex_lock(dsession->pendingMapsLock); - dsession->pendingMaps = g_list_remove(dsession->pendingMaps, ctx); - g_mutex_unlock(dsession->pendingMapsLock); - - if (ctx->type == SML_CHANGE_ADD && - smlStatusGetClass(ctx->status) == SML_ERRORCLASS_SUCCESS && - dsession->recvEventCallback && - !dsession->pendingMaps) - { - /* FIXME: I'm sure that this event is buggy. - * FIXME: What is the semantic of this event? - * Now there are no more MapItems ... - * do some fancy callback. Some applications will love it ;) - */ - dsession->recvEventCallback(dsession, SML_DS_EVENT_COMMITEDCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback commited changes callback", __func__); - } + g_mutex_lock(dsession->pendingChangesLock); + dsession->pendingChanges = g_list_remove(dsession->pendingChanges, ctx); + g_mutex_unlock(dsession->pendingChangesLock); _write_context_free(ctx); @@ -138,12 +111,6 @@ dsession->sentSyncCallback = NULL; dsession->sentSyncCallbackUserdata = NULL; - // Now there are no more MapItems ... do some fancy callback. Some applications will love it ;) - if (dsession->recvEventCallback && !dsession->pendingMaps) { - dsession->recvEventCallback(dsession, SML_DS_EVENT_COMMITEDCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback commited changes callback", __func__); - } - smlTrace(TRACE_EXIT, "%s", __func__); } @@ -432,7 +399,7 @@ dsession->location = server->location; g_object_ref(dsession->location); - dsession->pendingMapsLock = g_mutex_new(); + dsession->pendingChangesLock = g_mutex_new(); smlTrace(TRACE_EXIT, "%s: %p", __func__, dsession); return dsession; @@ -481,25 +448,31 @@ dsession->recvChanges = g_list_delete_link(dsession->recvChanges, dsession->recvChanges); } + while (dsession->recvMap) { + SmlCommand *cmd = dsession->recvMap->data; + smlCommandUnref(cmd); + dsession->recvMap = g_list_delete_link(dsession->recvMap, dsession->recvMap); + } + if (dsession->syncCommand) smlCommandUnref(dsession->syncCommand); - if (!g_mutex_trylock(dsession->pendingMapsLock)) { + if (!g_mutex_trylock(dsession->pendingChangesLock)) { smlTrace(TRACE_ERROR, "%s: somebody still uses this object", __func__); - g_mutex_lock(dsession->pendingMapsLock); + g_mutex_lock(dsession->pendingChangesLock); } - while (dsession->pendingMaps) { - SmlWriteContext *ctx = dsession->pendingMaps->data; + while (dsession->pendingChanges) { + SmlWriteContext *ctx = dsession->pendingChanges->data; _write_context_free(ctx); - dsession->pendingMaps = g_list_delete_link(dsession->pendingMaps, dsession->pendingMaps); + dsession->pendingChanges = g_list_delete_link(dsession->pendingChanges, dsession->pendingChanges); } - g_mutex_unlock(dsession->pendingMapsLock); - g_mutex_free(dsession->pendingMapsLock); + g_mutex_unlock(dsession->pendingChangesLock); + g_mutex_free(dsession->pendingChangesLock); while (dsession->mapItems) { SmlMapItem *item = dsession->mapItems->data; - smlMapItemUnref(item); + g_object_unref(item); dsession->mapItems = g_list_delete_link(dsession->mapItems, dsession->mapItems); } @@ -600,11 +573,6 @@ if (!dsession->recvChanges) { /* There are no changes. */ - /* ... do some fancy callback. Some applications will love it ;) */ - if (dsession->recvEventCallback) { - dsession->recvEventCallback(dsession, SML_DS_EVENT_GOTCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback no changes in recvSync callback", __func__); - } /* unlock the final event at the manager * * If this is called from a test case then the datastore @@ -617,7 +585,7 @@ } smlTrace(TRACE_INTERNAL, "%s: final handling done", __func__); } - } else if (dsession->recvChanges && dsession->changesCallback) { + } else if (dsession->recvChanges && dsession->recvChangeCallback) { smlTrace(TRACE_INTERNAL, "%s: Dispatching changes", __func__); while (dsession->recvChanges) { @@ -662,12 +630,12 @@ if (!smlItemStealData(item, &data, &size, &error)) goto error; - if (!dsession->changesCallback(dsession, + if (!dsession->recvChangeCallback(dsession, smlCommandGetChangeType(cmd), smlItemGetTarget(item) ? sml_location_get_uri(smlItemGetTarget(item)) : sml_location_get_uri(smlItemGetSource(item)), data, size, smlItemGetContentType(item), - dsession->changesCallbackUserdata, &error)) + dsession->recvChangeCallbackUserdata, &error)) goto error; } @@ -690,11 +658,6 @@ dsession->recvChanges = g_list_delete_link(dsession->recvChanges, dsession->recvChanges); } - // Now there are no more changes... do some fancy callback. Some applications will love it ;) - if (dsession->recvEventCallback) { - dsession->recvEventCallback(dsession, SML_DS_EVENT_GOTCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback all changes sent in recvChanges callback", __func__); - } /* unlock the final event at the manager * * If this is called from a test case then the datastore @@ -707,9 +670,43 @@ } else smlTrace(TRACE_INTERNAL, "%s - no manager so should be a test", __func__); + } else if (dsession->recvMap && dsession->recvMappingCallback) { + while (dsession->recvMap) { + SmlCommand *cmd = dsession->recvMap->data; + + smlTrace(TRACE_INTERNAL, "%s: answering map command with cmdRef %i and msgRef %i", + __func__, + smlCommandGetID(cmd), + smlCommandGetMessageID(cmd)); + + /* handle the mapping */ + gsize i; + for (i = 0; i < smlCommandGetNumMappings(cmd); i++) { + SmlMapItem *item = smlCommandGetNthMapping(cmd, i); + + dsession->recvMappingCallback( + dsession, + item, + dsession->recvMappingCallbackUserdata); + } + + /* send the reply */ + reply = smlCommandNewReply(cmd, SML_NO_ERROR, &error); + if (!reply) + goto error; + + if (!smlSessionSendReply(dsession->session, reply, &error)) + goto error; + + smlStatusUnref(reply); + + /* cleanup the command */ + smlCommandUnref(cmd); + dsession->recvMap = g_list_delete_link(dsession->recvMap, dsession->recvMap); + } } else { - smlTrace(TRACE_INTERNAL, "%s: recvChanges: %p changesCallback: %p", __func__, dsession->recvChanges, dsession->changesCallback); + smlTrace(TRACE_INTERNAL, "%s: no actions/callbacks to be done", __func__); } smlTrace(TRACE_EXIT, "%s()", __func__); @@ -729,7 +726,8 @@ { if ((dsession->alertCommand && dsession->recvAlertCallback) || \ (dsession->recvSync && dsession->recvSyncCallback) || \ - (dsession->recvChanges && dsession->changesCallback)) + (dsession->recvChanges && dsession->recvChangeCallback) || \ + (dsession->recvMap && dsession->recvMappingCallback)) return TRUE; return FALSE; } @@ -901,6 +899,7 @@ smlTrace(TRACE_EXIT, "%s", __func__); } +/* FIXME: this is synchronous behaviour !? */ void smlDsSessionRecvMap(SmlSession *session, SmlCommand *cmd, void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, cmd, userdata); @@ -909,44 +908,13 @@ g_mutex_lock(dsession->lock); - SmlStatus *reply = smlCommandNewReply(cmd, SML_NO_ERROR, &error); - if (!reply) - goto error; - - if (!smlSessionSendReply(session, reply, &error)) - goto error; - - smlStatusUnref(reply); - - gsize i; - for (i = 0; i < smlCommandGetNumMappings(cmd); i++) { - SmlMapItem *item = smlCommandGetNthMapping(cmd, i); - - if (dsession->recvMappingCallback) { - dsession->recvMappingCallback( - dsession, - smlMapItemGetTarget(item), - smlMapItemGetSource(item), - dsession->recvMappingCallbackUserdata); - } else { - SmlWriteContext *ctx = _write_context_find(dsession, sml_location_get_uri(smlMapItemGetTarget(item)), SML_CHANGE_ADD); - if (ctx) { - ctx->newuid = g_strdup(sml_location_get_uri(smlMapItemGetSource(item))); - _write_context_dispatch(dsession, ctx); - } else { - smlTrace(TRACE_ERROR, "%s: Unknown map ... %s => %s", - __func__, - VA_STRING(sml_location_get_uri(smlMapItemGetTarget(item))), - VA_STRING(sml_location_get_uri(smlMapItemGetSource(item)))); - } - } - } + dsession->recvMap = g_list_append(dsession->recvMap, cmd); + smlCommandRef(cmd); g_mutex_unlock(dsession->lock); smlTrace(TRACE_EXIT, "%s", __func__); return; - error: g_mutex_unlock(dsession->lock); smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); @@ -1048,14 +1016,14 @@ * @param error A pointer to a error struct * @returns TRUE if the call was successful, FALSE otherwise */ -void smlDsSessionGetChanges(SmlDsSession *dsession, SmlDsSessionChangesCb chgCallback, void *userdata) +void smlDsSessionGetChanges(SmlDsSession *dsession, SmlDsSessionChangeCb chgCallback, void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, dsession, chgCallback, userdata); smlAssert(dsession); smlAssert(chgCallback); - dsession->changesCallback = chgCallback; - dsession->changesCallbackUserdata = userdata; + dsession->recvChangeCallback = chgCallback; + dsession->recvChangeCallbackUserdata = userdata; smlDsSessionDispatch(dsession); @@ -1076,21 +1044,6 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -void smlDsSessionGetEvent(SmlDsSession *dsession, SmlDsSessionEventCb eventCallback, void *userdata) -{ - smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, dsession, eventCallback, userdata); - smlAssert(dsession); - smlAssert(eventCallback); - - dsession->recvEventCallback = eventCallback; - dsession->recvEventCallbackUserdata = userdata; - - smlDsSessionDispatch(dsession); - - smlTrace(TRACE_EXIT, "%s", __func__); -} - - /** @brief Start the sync command to send to the other side * * This function will start the sync command with which the changes will be sent to the other side. @@ -1145,7 +1098,7 @@ const gchar *data, gsize size, const gchar *contenttype, - SmlDsSessionWriteCb callback, + SmlDsSessionChangeStatusCb callback, void *userdata, GError **error) { @@ -1176,9 +1129,9 @@ ctx->type = type; ctx->session = dsession; - g_mutex_lock(dsession->pendingMapsLock); - dsession->pendingMaps = g_list_append(dsession->pendingMaps, ctx); - g_mutex_unlock(dsession->pendingMapsLock); + g_mutex_lock(dsession->pendingChangesLock); + dsession->pendingChanges = g_list_append(dsession->pendingChanges, ctx); + g_mutex_unlock(dsession->pendingChangesLock); if (!smlSessionSendCommand(dsession->session, cmd, dsession->syncCommand, _change_reply, ctx, error)) goto error; @@ -1234,19 +1187,15 @@ gboolean smlDsSessionQueueMap (SmlDsSession *dsession, - const gchar *uid, - const gchar *newuid, + SmlMapItem *item, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, VA_STRING(uid), VA_STRING(newuid), error); + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, dsession, item, error); smlAssert(dsession); CHECK_ERROR_REF - SmlMapItem *item = smlMapItemNew(uid, newuid, error); - if (!item) - goto error; - dsession->mapItems = g_list_append(dsession->mapItems, item); + g_object_ref(item); smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; @@ -1287,9 +1236,8 @@ SmlMapItem *item = dsession->mapItems->data; if (!smlCommandAddMapItem(cmd, item, error)) goto error; - smlMapItemUnref(item); - dsession->mapItems = g_list_remove(dsession->mapItems, item); + g_object_unref(item); } if (!smlSessionSendCommand(dsession->session, cmd, NULL, callback, userdata, error)) Modified: trunk/libsyncml/objects/sml_ds_server.h ============================================================================== --- trunk/libsyncml/objects/sml_ds_server.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/objects/sml_ds_server.h Sat Aug 1 17:23:46 2009 (r1224) @@ -31,21 +31,16 @@ #define _SML_DS_SERVER_H_ #include "../sml_notification.h" +#include <libsyncml/data_sync_api/sml_map_item.h> typedef struct SmlDsServer SmlDsServer; typedef struct SmlDsSession SmlDsSession; -typedef enum { - SML_DS_EVENT_GOTCHANGES = 0, - SML_DS_EVENT_COMMITEDCHANGES = 1 -} SmlDsEvent; - typedef void (* SmlDsSessionConnectCb) (SmlDsSession *dsession, void *userdata); typedef gboolean (* SmlDsSessionAlertCb) (SmlDsSession *dsession, SmlAlertType type, const gchar *last, const gchar *next, void *userdata); typedef void (* SmlDsSessionSyncCb) (SmlDsSession *dsession, gsize numchanges, void *userdata); -typedef void (* SmlDsSessionEventCb) (SmlDsSession *dsession, SmlDsEvent event, void *userdata); -typedef gboolean (* SmlDsSessionChangesCb) (SmlDsSession *dsession, SmlChangeType type, const gchar *uid, gchar *data, gsize size, const gchar *contenttype, void *userdata, GError **error); -typedef void (* SmlDsSessionWriteCb) (SmlDsSession *dsession, SmlStatus *status, void *userdata); +typedef gboolean (* SmlDsSessionChangeCb) (SmlDsSession *dsession, SmlChangeType type, const gchar *uid, gchar *data, gsize size, const gchar *contenttype, void *userdata, GError **error); +typedef void (* SmlDsSessionChangeStatusCb) (SmlDsSession *dsession, SmlStatus *status, void *userdata); SmlDsServer* smlDsServerNew (const gchar *type, SmlLocation *location, GError **error); SmlDsServer* smlDsClientNew (const gchar *type, SmlLocation *location, SmlLocation *target, GError **error); @@ -66,13 +61,12 @@ gboolean smlDsSessionCheck (SmlDsSession *dsession); void smlDsSessionGetAlert (SmlDsSession *dsession, SmlDsSessionAlertCb callback, void *userdata); gboolean smlDsSessionSendAlert (SmlDsSession *dsession, SmlAlertType type, const gchar *last, const gchar *next, SmlStatusReplyCb callback, void *userdata, GError **error); -void smlDsSessionGetChanges (SmlDsSession *dsession, SmlDsSessionChangesCb chgCallback, void *userdata); +void smlDsSessionGetChanges (SmlDsSession *dsession, SmlDsSessionChangeCb chgCallback, void *userdata); void smlDsSessionGetSync (SmlDsSession *dsession, SmlDsSessionSyncCb chgCallback, void *userdata); -void smlDsSessionGetEvent (SmlDsSession *dsession, SmlDsSessionEventCb eventCallback, void *userdata); gboolean smlDsSessionSendSync (SmlDsSession *dsession, gsize num_changes, SmlStatusReplyCb callback, void *userdata, GError **error); -gboolean smlDsSessionQueueChange (SmlDsSession *dsession, SmlChangeType type, const gchar *uid, const gchar *data, gsize size, const gchar *contenttype, SmlDsSessionWriteCb callback, void *userdata, GError **error); +gboolean smlDsSessionQueueChange (SmlDsSession *dsession, SmlChangeType type, const gchar *uid, const gchar *data, gsize size, const gchar *contenttype, SmlDsSessionChangeStatusCb callback, void *userdata, GError **error); gboolean smlDsSessionCloseSync (SmlDsSession *dsession, GError **error); -gboolean smlDsSessionQueueMap (SmlDsSession *dsession, const gchar *uid, const gchar *newuid, GError **error); +gboolean smlDsSessionQueueMap (SmlDsSession *dsession, SmlMapItem *item, GError **error); gboolean smlDsSessionCloseMap (SmlDsSession *dsession, SmlStatusReplyCb callback, void *userdata, GError **error); const gchar* smlDsSessionGetLocation (SmlDsSession *dsession); const gchar* smlDsSessionGetContentType (SmlDsSession *dsession); Modified: trunk/libsyncml/objects/sml_ds_server_internals.h ============================================================================== --- trunk/libsyncml/objects/sml_ds_server_internals.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/objects/sml_ds_server_internals.h Sat Aug 1 17:23:46 2009 (r1224) @@ -32,12 +32,11 @@ #include "sml_ds_server.h" -typedef void (* SmlDsSessionMapCb) (SmlDsSession *dsession, SmlLocation *orig, SmlLocation *mapped, void *userdata); +typedef void (* SmlDsSessionMapCb) (SmlDsSession *dsession, SmlMapItem *item, void *userdata); typedef struct SmlWriteContext { - SmlDsSessionWriteCb callback; + SmlDsSessionChangeStatusCb callback; gchar *uid; - gchar *newuid; SmlStatus *status; void *userdata; SmlChangeType type; @@ -65,8 +64,8 @@ /** Callback that will receive the sync command */ SmlDsSessionSyncCb recvSyncCallback; void *recvSyncCallbackUserdata; - SmlDsSessionChangesCb changesCallback; - void *changesCallbackUserdata; + SmlDsSessionChangeCb recvChangeCallback; + void *recvChangeCallbackUserdata; /** List of received sync commands. We need a list here * since sync commands might get split due to size limitations * and the answer to a sync command might arrive after several @@ -81,20 +80,17 @@ SmlStatusReplyCb sentSyncCallback; void *sentSyncCallbackUserdata; - /** Callback that will information about the Ds Session events */ - SmlDsSessionEventCb recvEventCallback; - void *recvEventCallbackUserdata; - /** The temporary storage for the sync command to send */ SmlCommand *syncCommand; - GList *pendingMaps; - GMutex *pendingMapsLock; + GList *pendingChanges; + GMutex *pendingChangesLock; GList *mapItems; /** Callback that signals mappings */ SmlDsSessionMapCb recvMappingCallback; void *recvMappingCallbackUserdata; + GList *recvMap; GMutex *write_lock; GMutex *lock; Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/parser/sml_xml_assm.c Sat Aug 1 17:23:46 2009 (r1224) @@ -25,6 +25,7 @@ #include <libsyncml/sml_session_internals.h> #include "libsyncml/sml_error_internals.h" +#include "libsyncml/data_sync_api/sml_map_item_internals.h" #include "sml_xml_assm_internals.h" #include <string.h> @@ -757,13 +758,13 @@ if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_MAPITEM, error)) goto error; - if (item->source) { - if (!smlLocationAssemble(item->source, assm, SML_ELEMENT_SOURCE, error)) + if (sml_map_item_get_remote(item)) { + if (!smlLocationAssemble(sml_map_item_get_remote(item), assm, SML_ELEMENT_SOURCE, error)) goto error; } - if (item->target) { - if (!smlLocationAssemble(item->target, assm, SML_ELEMENT_TARGET, error)) + if (sml_map_item_get_local(item)) { + if (!smlLocationAssemble(sml_map_item_get_local(item), assm, SML_ELEMENT_TARGET, error)) goto error; } Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/parser/sml_xml_parse.c Sat Aug 1 17:23:46 2009 (r1224) @@ -1464,10 +1464,11 @@ CHECK_ERROR_REF smlAssert(parser); - SmlMapItem *item = smlTryMalloc0(sizeof(SmlMapItem), error); - if (!item) + SmlMapItem *item = sml_map_item_new(); + if (!item) { + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Out of memory."); goto error; - item->refCount = 1; + } while (1) { if (!_smlXmlParserStep(parser)) { @@ -1486,11 +1487,23 @@ } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE)) { - if (!_smlLocationParse(&item->source, parser, error)) + SmlLocation *loc = NULL; + if (!_smlLocationParse(&loc, parser, error)) + goto error_free_item; + if (!sml_map_item_set_remote(item, loc, error)) { + g_object_unref(loc); goto error_free_item; + } + g_object_unref(loc); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET)) { - if (!_smlLocationParse(&item->target, parser, error)) + SmlLocation *loc = NULL; + if (!_smlLocationParse(&loc, parser, error)) + goto error_free_item; + if (!sml_map_item_set_local(item, loc, error)) { + g_object_unref(loc); goto error_free_item; + } + g_object_unref(loc); } else { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); goto error_free_item; @@ -1501,7 +1514,7 @@ return item; error_free_item: - smlMapItemUnref(item); + g_object_unref(item); error: smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_command.c Sat Aug 1 17:23:46 2009 (r1224) @@ -422,7 +422,7 @@ case SML_COMMAND_TYPE_MAP: while (cmd->private.map.items) { SmlMapItem *item = cmd->private.map.items->data; - smlMapItemUnref(item); + g_object_unref(item); cmd->private.map.items = g_list_delete_link(cmd->private.map.items, cmd->private.map.items); } break; @@ -953,7 +953,7 @@ smlAssert(map->type == SML_COMMAND_TYPE_MAP); smlAssert(item); - smlMapItemRef(item); + g_object_ref(item); map->private.map.items = g_list_append(map->private.map.items, item); smlTrace(TRACE_EXIT, "%s", __func__); Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_elements.c Sat Aug 1 17:23:46 2009 (r1224) @@ -851,89 +851,3 @@ return chal->type; } -SmlMapItem* -smlMapItemNew (const gchar *uid, - const gchar *newuid, - GError **error) -{ - smlTrace(TRACE_ENTRY, "%s(%s, %s, %p)", __func__, VA_STRING(uid), VA_STRING(newuid), error); - CHECK_ERROR_REF - smlAssert(uid); - smlAssert(newuid); - - SmlMapItem *item = smlTryMalloc0(sizeof(SmlMapItem), error); - if (!item) - goto error; - item->refCount = 1; - - item->source = sml_location_new_with_options(newuid, NULL, error); - if (!item->source) - goto error; - - item->target = sml_location_new_with_options(uid, NULL, error); - if (!item->target) - goto error; - - smlTrace(TRACE_EXIT, "%s: %p", __func__, item); - return item; - -error: - if (item) { - if (item->source) - g_object_unref(item->source); - smlSafeFree((gpointer *)&item); - } - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); - return NULL; -} - -SmlMapItem* -smlMapItemRef (SmlMapItem *item) -{ - smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); - smlAssert(item); - - g_atomic_int_inc(&(item->refCount)); - - smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, item->refCount); - return item; -} - -void -smlMapItemUnref (SmlMapItem *item) -{ - smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); - smlAssert(item); - - if (g_atomic_int_dec_and_test(&(item->refCount))) { - smlTrace(TRACE_INTERNAL, "%s: Refcount == 0!", __func__); - - if (item->source) - { - g_object_unref(item->source); - item->source = NULL; - } - - if (item->target) - { - g_object_unref(item->target); - item->target = NULL; - } - - smlSafeFree((gpointer *)&item); - } - - smlTrace(TRACE_EXIT, "%s", __func__); -} - -SmlLocation* -smlMapItemGetSource (SmlMapItem *item) -{ - return item->source; -} - -SmlLocation* -smlMapItemGetTarget (SmlMapItem *item) -{ - return item->target; -} Modified: trunk/libsyncml/sml_elements.h ============================================================================== --- trunk/libsyncml/sml_elements.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_elements.h Sat Aug 1 17:23:46 2009 (r1224) @@ -39,7 +39,6 @@ typedef struct SmlItem SmlItem; typedef struct SmlHeader SmlHeader; typedef struct SmlChal SmlChal; -typedef struct SmlMapItem SmlMapItem; SmlCred* smlCredNewFromString (const gchar *type, const gchar *format, const gchar *data, GError **error); SmlCred* smlCredNewAuth (SmlAuthType type, const gchar *username, const gchar *password, GError **error); @@ -101,12 +100,6 @@ const gchar* smlChalGetNonce (SmlChal *chal); /* Base 64 only */ SmlAuthType smlChalGetType (SmlChal *chal); -SmlMapItem* smlMapItemNew (const gchar *uid, const gchar *newuid, GError **error); -SmlMapItem* smlMapItemRef (SmlMapItem *item); -void smlMapItemUnref (SmlMapItem *item); -SmlLocation* smlMapItemGetSource (SmlMapItem *item); -SmlLocation* smlMapItemGetTarget (SmlMapItem *item); - #endif //_SML_ELEMENTS_H_ /*@}*/ Modified: trunk/libsyncml/sml_elements_internals.h ============================================================================== --- trunk/libsyncml/sml_elements_internals.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_elements_internals.h Sat Aug 1 17:23:46 2009 (r1224) @@ -57,12 +57,6 @@ gboolean raw; }; -struct SmlMapItem { - gint refCount; - SmlLocation *source; - SmlLocation *target; -}; - struct SmlHeader { gsize sessionID; SmlProtocolVersion version; Modified: trunk/libsyncml/sml_session.c ============================================================================== --- trunk/libsyncml/sml_session.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_session.c Sat Aug 1 17:23:46 2009 (r1224) @@ -1017,7 +1017,7 @@ } else { - smlTrace(TRACE_INTERNAL, "%s: dispatch status", __func__); + smlTrace(TRACE_INTERNAL, "%s: dispatch status - %d", __func__, smlQueueLengthPrio(session->command_queue)); smlQueueDispatchPrio(session->command_queue); } smlTrace(TRACE_EXIT, "%s - done", __func__); @@ -2188,7 +2188,7 @@ sesscmd->type = SML_SESSION_FLUSH; sesscmd->final = TRUE; sesscmd->end = TRUE; - smlTrace(TRACE_INTERNAL, "%s: sending command %p", sesscmd); + smlTrace(TRACE_INTERNAL, "%s: sending command %p", __func__, sesscmd); smlQueueSend(session->command_queue, sesscmd); } else { Modified: trunk/tests/CMakeLists.txt ============================================================================== --- trunk/tests/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/tests/CMakeLists.txt Sat Aug 1 17:23:46 2009 (r1224) @@ -89,26 +89,26 @@ SML_ADD_TESTCASE( location_references ) SML_END_TEST() - SML_START_TEST( "data_sync_map_item" data_sync_api_map_item check_data_sync_api_map_item.c ${TEST_TARGET_LIBRARIES} ) - SML_ADD_TESTCASE( data_sync_map_item_new ) - SML_ADD_TESTCASE( data_sync_map_item_set_local ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_not_null ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_no_name ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_no_parent ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_missing_uri ) - SML_ADD_TESTCASE( data_sync_map_item_get_local ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_not_null ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_name ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_parent ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_missing_uri ) - SML_ADD_TESTCASE( data_sync_map_item_get_remote ) - SML_ADD_TESTCASE( data_sync_map_item_compliance ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_local ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_remote ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_local ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_remote ) - SML_ADD_TESTCASE( data_sync_map_item_references ) + SML_START_TEST( "map_item" data_sync_api_map_item check_data_sync_api_map_item.c ${TEST_TARGET_LIBRARIES} ) + SML_ADD_TESTCASE( map_item_new ) + SML_ADD_TESTCASE( map_item_set_local ) + SML_ADD_TESTCASE( map_item_set_local_not_null ) + SML_ADD_TESTCASE( map_item_set_local_no_name ) + SML_ADD_TESTCASE( map_item_set_local_no_parent ) + SML_ADD_TESTCASE( map_item_set_local_missing_uri ) + SML_ADD_TESTCASE( map_item_get_local ) + SML_ADD_TESTCASE( map_item_set_remote ) + SML_ADD_TESTCASE( map_item_set_remote_not_null ) + SML_ADD_TESTCASE( map_item_set_remote_no_name ) + SML_ADD_TESTCASE( map_item_set_remote_no_parent ) + SML_ADD_TESTCASE( map_item_set_remote_missing_uri ) + SML_ADD_TESTCASE( map_item_get_remote ) + SML_ADD_TESTCASE( map_item_compliance ) + SML_ADD_TESTCASE( map_item_compliance_missing_local ) + SML_ADD_TESTCASE( map_item_compliance_missing_remote ) + SML_ADD_TESTCASE( map_item_compliance_wrong_local ) + SML_ADD_TESTCASE( map_item_compliance_wrong_remote ) + SML_ADD_TESTCASE( map_item_references ) SML_END_TEST() SML_START_TEST( "XML fix broken Item Data" xml-fix-broken-item-data check_xml_fix_broken_item_data.c ${TEST_TARGET_LIBRARIES} ) Modified: trunk/tests/check_data_sync_api_map_item.c ============================================================================== --- trunk/tests/check_data_sync_api_map_item.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/tests/check_data_sync_api_map_item.c Sat Aug 1 17:23:46 2009 (r1224) @@ -20,18 +20,18 @@ #include "tests/support.h" -#include <libsyncml/data_sync_api/sml_data_sync_map_item.h> +#include <libsyncml/data_sync_api/sml_map_item.h> -START_TEST (data_sync_map_item_new) +START_TEST (map_item_new) { setup_testbed(NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); g_object_unref(item); } END_TEST -START_TEST (data_sync_map_item_set_local) +START_TEST (map_item_set_local) { setup_testbed(NULL); @@ -41,10 +41,10 @@ sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); g_object_unref(location); @@ -52,16 +52,16 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_not_null) +START_TEST (map_item_set_local_not_null) { setup_testbed(NULL); GError *error = NULL; - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, NULL, &error), "The local URI must be enforced."); + sml_fail_unless(!sml_map_item_set_local(item, NULL, &error), "The local URI must be enforced."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -69,7 +69,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_no_name) +START_TEST (map_item_set_local_no_name) { setup_testbed(NULL); @@ -81,10 +81,10 @@ sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a name."); + sml_fail_unless(!sml_map_item_set_local(item, location, &error), "The location must not have a name."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -93,7 +93,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_no_parent) +START_TEST (map_item_set_local_no_parent) { setup_testbed(NULL); @@ -105,10 +105,10 @@ sml_fail_unless(sml_location_set_parent_uri(location, "56", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a parent URI."); + sml_fail_unless(!sml_map_item_set_local(item, location, &error), "The location must not have a parent URI."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -117,7 +117,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_missing_uri) +START_TEST (map_item_set_local_missing_uri) { setup_testbed(NULL); @@ -125,10 +125,10 @@ SmlLocation *location = sml_location_new(); sml_fail_unless(location != NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must have an URI."); + sml_fail_unless(!sml_map_item_set_local(item, location, &error), "The location must have an URI."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -137,7 +137,7 @@ } END_TEST -START_TEST (data_sync_map_item_get_local) +START_TEST (map_item_get_local) { setup_testbed(NULL); @@ -147,23 +147,23 @@ sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) == NULL, "The local URI is not set until now."); + sml_fail_unless(sml_map_item_get_local_uri(item) == NULL, "The local URI is not set until now."); - sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI must be set now."); - sml_fail_unless(strcmp(sml_data_sync_map_item_get_local_uri(item), "1234") == 0, "The local URI must be 1234."); + sml_fail_unless(sml_map_item_get_local_uri(item) != NULL, "The local URI must be set now."); + sml_fail_unless(strcmp(sml_map_item_get_local_uri(item), "1234") == 0, "The local URI must be 1234."); g_object_unref(location); g_object_unref(item); } END_TEST -START_TEST (data_sync_map_item_set_remote) +START_TEST (map_item_set_remote) { setup_testbed(NULL); @@ -173,10 +173,10 @@ sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); g_object_unref(location); @@ -184,16 +184,16 @@ } END_TEST -START_TEST (data_sync_map_item_set_remote_not_null) +START_TEST (map_item_set_remote_not_null) { setup_testbed(NULL); GError *error = NULL; - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_remote(item, NULL, &error), "The remote URI must be enforced."); + sml_fail_unless(!sml_map_item_set_remote(item, NULL, &error), "The remote URI must be enforced."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -201,7 +201,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_remote_no_name) +START_TEST (map_item_set_remote_no_name) { setup_testbed(NULL); @@ -213,10 +213,10 @@ sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The locatio... [truncated message content] |
From: <svn...@op...> - 2009-07-31 11:32:36
|
Author: bellmich Date: Fri Jul 31 13:32:17 2009 New Revision: 1223 URL: http://libsyncml.opensync.org/changeset/1223 Log: added SmlDataSyncMapItem object incl. tests The object is not integrated into the interfaces today. Added: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h trunk/tests/check_data_sync_api_map_item.c Modified: trunk/libsyncml/CMakeLists.txt trunk/tests/CMakeLists.txt trunk/tests/check_data_sync_api_location.c Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Mon Jul 20 13:10:53 2009 (r1222) +++ trunk/libsyncml/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) @@ -24,6 +24,7 @@ data_sync_api/data_sync_client.c data_sync_api/data_sync_server.c data_sync_api/sml_location.c + data_sync_api/sml_data_sync_map_item.c data_sync_api/transport_http_client.c data_sync_api/transport_http_server.c data_sync_api/transport_obex_client.c @@ -78,6 +79,7 @@ INSTALL( FILES data_sync_api/sml_location.h + data_sync_api/sml_data_sync_map_item.h data_sync_api/defines.h data_sync_api/standard.h data_sync_api/callbacks.h Added: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c Fri Jul 31 13:32:17 2009 (r1223) @@ -0,0 +1,270 @@ +/* sml_data_sync_map_item.c + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "sml_data_sync_map_item.h" +#include "../sml_error_internals.h" +#include <string.h> + +G_DEFINE_TYPE (SmlDataSyncMapItem, sml_data_sync_map_item, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_REMOTE, + PROP_LOCAL +}; + +struct _SmlDataSyncMapItemPrivate +{ + SmlLocation* remote; + SmlLocation* local; +}; + +static void +sml_data_sync_map_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + g_value_set_object (value, SML_DATA_SYNC_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + g_value_set_object (value, SML_DATA_SYNC_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_data_sync_map_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + if (SML_DATA_SYNC_MAP_ITEM (object)->priv->remote) + g_object_unref (SML_DATA_SYNC_MAP_ITEM (object)->priv->remote); + SML_DATA_SYNC_MAP_ITEM (object)->priv->remote = SML_LOCATION (value); + g_object_ref(SML_DATA_SYNC_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + if (SML_DATA_SYNC_MAP_ITEM (object)->priv->local) + g_object_unref (SML_DATA_SYNC_MAP_ITEM (object)->priv->local); + SML_DATA_SYNC_MAP_ITEM (object)->priv->local = SML_LOCATION (value); + g_object_ref(SML_DATA_SYNC_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_data_sync_map_item_finalize (GObject *object) +{ + SmlDataSyncMapItem *self = (SmlDataSyncMapItem *) object; + g_object_unref(self->priv->remote); + g_object_unref(self->priv->local); + /* all pointers must be NULL */ + self->priv->remote = NULL; + self->priv->local = NULL; + G_OBJECT_CLASS (sml_data_sync_map_item_parent_class)->finalize (object); +} + +static void +sml_data_sync_map_item_class_init (SmlDataSyncMapItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlDataSyncMapItemPrivate)); + + object_class->get_property = sml_data_sync_map_item_get_property; + object_class->set_property = sml_data_sync_map_item_set_property; + object_class->finalize = sml_data_sync_map_item_finalize; + + /** + * SmlDataSyncMapItem:remote: + * + * The remote property. + */ + g_object_class_install_property (object_class, + PROP_REMOTE, + g_param_spec_object ("remote", + "remote", + "remote", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + /** + * SmlDataSyncMapItem:local: + * + * The local property. + */ + g_object_class_install_property (object_class, + PROP_LOCAL, + g_param_spec_object ("local", + "local", + "local", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + +} + +static void +sml_data_sync_map_item_init (SmlDataSyncMapItem *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_DATA_SYNC_MAP_ITEM, + SmlDataSyncMapItemPrivate); +} + +/** + * sml_data_sync_map_item_new: + * + * Creates a new instance of #SmlDataSyncMapItem. + * + * Return value: the newly created #SmlDataSyncMapItem instance + */ +SmlDataSyncMapItem* +sml_data_sync_map_item_new (void) +{ + return g_object_new (SML_TYPE_DATA_SYNC_MAP_ITEM, NULL); +} + +/** + * sml_data_sync_map_item_get_remote_uri: + * @self: A #SmlDataSyncMapItem + * + * Gets the remote property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_data_sync_map_item_get_remote_uri (SmlDataSyncMapItem *self) +{ + g_return_val_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), NULL); + if (!self->priv->remote) + return NULL; + return sml_location_get_uri(self->priv->remote); +} + +/** + * sml_data_sync_map_item_set_remote: + * @self: A #SmlDataSyncMapItem + * @remote: + * + * Sets the remote property. + */ +gboolean +sml_data_sync_map_item_set_remote (SmlDataSyncMapItem *self, + SmlLocation* remote, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDataSyncMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + if (self->priv->remote) + g_object_unref (self->priv->remote); + self->priv->remote = remote; + g_object_ref (remote); + return TRUE; +} + +/** + * sml_data_sync_map_item_get_local_uri: + * @self: A #SmlDataSyncMapItem + * + * Gets the local property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_data_sync_map_item_get_local_uri (SmlDataSyncMapItem *self) +{ + g_return_val_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), NULL); + if (!self->priv->local) + return NULL; + return sml_location_get_uri(self->priv->local); +} + +/** + * sml_data_sync_map_item_set_local: + * @self: A #SmlDataSyncMapItem + * @local: + * + * Sets the local property. + */ +gboolean +sml_data_sync_map_item_set_local (SmlDataSyncMapItem *self, + SmlLocation* local, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDataSyncMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + if (self->priv->local) + g_object_unref (self->priv->local); + self->priv->local = local; + g_object_ref (local); + return TRUE; +} + +/** + * sml_data_sync_map_item_is_compliant: + * @self: A #SmlDataSyncMapItem + * + * Checks the compliance with the OMA specifications for mappings. + */ +gboolean +sml_data_sync_map_item_is_compliant (SmlDataSyncMapItem *self, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_DATA_SYNC_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlDataSyncMapItem object."); + + SmlLocation *remote = self->priv->remote; + sml_return_val_error_if_fail (remote, FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + SmlLocation *local = self->priv->local; + sml_return_val_error_if_fail (local, FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + return TRUE; +} Added: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h Fri Jul 31 13:32:17 2009 (r1223) @@ -0,0 +1,64 @@ +/* sml_data_sync_map_item.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_DATA_SYNC_MAP_ITEM_H__ +#define __SML_DATA_SYNC_MAP_ITEM_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_location.h> + +G_BEGIN_DECLS + +#define SML_TYPE_DATA_SYNC_MAP_ITEM (sml_data_sync_map_item_get_type()) +#define SML_DATA_SYNC_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_DATA_SYNC_MAP_ITEM, SmlDataSyncMapItem)) +#define SML_DATA_SYNC_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_DATA_SYNC_MAP_ITEM, SmlDataSyncMapItemClass)) +#define SML_IS_DATA_SYNC_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_DATA_SYNC_MAP_ITEM)) +#define SML_IS_DATA_SYNC_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_DATA_SYNC_MAP_ITEM)) +#define SML_DATA_SYNC_MAP_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_DATA_SYNC_MAP_ITEM, SmlDataSyncMapItemClass)) + +typedef struct _SmlDataSyncMapItem SmlDataSyncMapItem; +typedef struct _SmlDataSyncMapItemClass SmlDataSyncMapItemClass; +typedef struct _SmlDataSyncMapItemPrivate SmlDataSyncMapItemPrivate; + +struct _SmlDataSyncMapItem +{ + GObject parent; + + /*< private >*/ + SmlDataSyncMapItemPrivate *priv; +}; + +struct _SmlDataSyncMapItemClass +{ + GObjectClass parent_class; + +}; + +GType sml_data_sync_map_item_get_type (void); +SmlDataSyncMapItem* sml_data_sync_map_item_new (void); +G_CONST_RETURN gchar* sml_data_sync_map_item_get_local_uri (SmlDataSyncMapItem *self); +gboolean sml_data_sync_map_item_set_local (SmlDataSyncMapItem *self, SmlLocation* local, GError **error); +G_CONST_RETURN gchar* sml_data_sync_map_item_get_remote_uri (SmlDataSyncMapItem *self); +gboolean sml_data_sync_map_item_set_remote (SmlDataSyncMapItem *self, SmlLocation* remote, GError **error); +gboolean sml_data_sync_map_item_is_compliant (SmlDataSyncMapItem *self, GError **error); + +G_END_DECLS + +#endif /* __SML_DATA_SYNC_MAP_ITEM_H__ */ Modified: trunk/tests/CMakeLists.txt ============================================================================== --- trunk/tests/CMakeLists.txt Mon Jul 20 13:10:53 2009 (r1222) +++ trunk/tests/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) @@ -86,6 +86,29 @@ SML_ADD_TESTCASE( location_compare_different_full_uri_wrong_parent ) SML_ADD_TESTCASE( location_compare_different_full_uri_wrong_uri ) SML_ADD_TESTCASE( location_compare_equal_full_uri_root ) + SML_ADD_TESTCASE( location_references ) + SML_END_TEST() + + SML_START_TEST( "data_sync_map_item" data_sync_api_map_item check_data_sync_api_map_item.c ${TEST_TARGET_LIBRARIES} ) + SML_ADD_TESTCASE( data_sync_map_item_new ) + SML_ADD_TESTCASE( data_sync_map_item_set_local ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_not_null ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_no_name ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_no_parent ) + SML_ADD_TESTCASE( data_sync_map_item_set_local_missing_uri ) + SML_ADD_TESTCASE( data_sync_map_item_get_local ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_not_null ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_name ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_parent ) + SML_ADD_TESTCASE( data_sync_map_item_set_remote_missing_uri ) + SML_ADD_TESTCASE( data_sync_map_item_get_remote ) + SML_ADD_TESTCASE( data_sync_map_item_compliance ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_local ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_remote ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_local ) + SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_remote ) + SML_ADD_TESTCASE( data_sync_map_item_references ) SML_END_TEST() SML_START_TEST( "XML fix broken Item Data" xml-fix-broken-item-data check_xml_fix_broken_item_data.c ${TEST_TARGET_LIBRARIES} ) Modified: trunk/tests/check_data_sync_api_location.c ============================================================================== --- trunk/tests/check_data_sync_api_location.c Mon Jul 20 13:10:53 2009 (r1222) +++ trunk/tests/check_data_sync_api_location.c Fri Jul 31 13:32:17 2009 (r1223) @@ -1,6 +1,7 @@ /* * libsyncml - A syncml protocol implementation * Copyright (C) 2005 Armin Bauer <arm...@op...> + * Copyright (C) 2009 Michael Bell <mic...@op...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,7 +20,8 @@ */ #include "tests/support.h" -#include <fnmatch.h> + +#include <libsyncml/data_sync_api/sml_location.h> START_TEST (location_new) { @@ -445,5 +447,27 @@ } END_TEST +START_TEST (location_references) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *loc = sml_location_new(); + sml_fail_unless(loc != NULL, NULL); + + sml_fail_unless(sml_location_set_uri(loc, "test", &error), "%s", error?error->message:"No GError set."); + + g_object_ref(loc); + + sml_fail_unless(sml_location_get_uri(loc) != NULL, "The location URI was not set."); + + g_object_unref(loc); + + sml_fail_unless(sml_location_get_uri(loc) != NULL, "The location URI is already cleaned up."); + + g_object_unref(loc); +} +END_TEST + @SML_TESTCASE_CODE@ Added: trunk/tests/check_data_sync_api_map_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/tests/check_data_sync_api_map_item.c Fri Jul 31 13:32:17 2009 (r1223) @@ -0,0 +1,487 @@ +/* + * libsyncml - A syncml protocol implementation + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "tests/support.h" + +#include <libsyncml/data_sync_api/sml_data_sync_map_item.h> + +START_TEST (data_sync_map_item_new) +{ + setup_testbed(NULL); + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_not_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, NULL, &error), "The local URI must be enforced."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_no_name) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a name."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_no_parent) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_parent_uri(location, "56", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a parent URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_local_missing_uri) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must have an URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_get_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) == NULL, "The local URI is not set until now."); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI must be set now."); + sml_fail_unless(strcmp(sml_data_sync_map_item_get_local_uri(item), "1234") == 0, "The local URI must be 1234."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_not_null) +{ + setup_testbed(NULL); + + GError *error = NULL; + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, NULL, &error), "The remote URI must be enforced."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_no_name) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The location must not have a name."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_no_parent) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_location_set_parent_uri(location, "56", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The location must not have a parent URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_set_remote_missing_uri) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The location must have an URI."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_get_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_remote_uri(item) == NULL, "The remote URI is not set until now."); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_get_remote_uri(item) != NULL, "The remote URI must be set now."); + sml_fail_unless(strcmp(sml_data_sync_map_item_get_remote_uri(item), "1234") == 0, "The remote URI must be 1234."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, NULL), "The item is compliant."); + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_missing_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_missing_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_wrong_local) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *local = sml_location_new(); + sml_fail_unless(local != NULL, NULL); + sml_fail_unless(sml_location_set_uri(local, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + SmlLocation *remote = sml_location_new(); + sml_fail_unless(remote != NULL, NULL); + sml_fail_unless(sml_location_set_uri(remote, "5678", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, remote, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_data_sync_map_item_set_local(item, local, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, NULL), "The item is compliant."); + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* add name */ + sml_fail_unless(sml_location_set_name(local, "my 1234", &error), "%s", error?error->message:"No GError set."); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(local); + g_object_unref(remote); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_compliance_wrong_remote) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *local = sml_location_new(); + sml_fail_unless(local != NULL, NULL); + sml_fail_unless(sml_location_set_uri(local, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + SmlLocation *remote = sml_location_new(); + sml_fail_unless(remote != NULL, NULL); + sml_fail_unless(sml_location_set_uri(remote, "5678", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_remote(item, remote, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + sml_fail_unless(sml_data_sync_map_item_set_local(item, local, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, NULL), "The item is compliant."); + sml_fail_unless(sml_data_sync_map_item_is_compliant(item, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + /* add parent */ + sml_fail_unless(sml_location_set_parent_uri(remote, "56", &error), "%s", error?error->message:"No GError set."); + + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, NULL), "The item is not compliant."); + sml_fail_unless(!sml_data_sync_map_item_is_compliant(item, &error), "The item is not compliant."); + sml_fail_unless(error != NULL, NULL); + + g_error_free(error); + g_object_unref(local); + g_object_unref(remote); + g_object_unref(item); +} +END_TEST + +START_TEST (data_sync_map_item_references) +{ + setup_testbed(NULL); + + GError *error = NULL; + SmlLocation *location = sml_location_new(); + sml_fail_unless(location != NULL, NULL); + sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + sml_fail_unless(item != NULL, NULL); + + sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(error == NULL, NULL); + + g_object_ref(item); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI was not set."); + + g_object_unref(item); + + sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI is already cleaned up."); + + g_object_unref(location); + g_object_unref(item); +} +END_TEST + +@SML_TESTCASE_CODE@ + |
From: <svn...@op...> - 2009-07-27 20:39:23
|
Author: scriptor Date: Mon Jul 27 22:39:10 2009 New Revision: 5708 URL: http://www.opensync.org/changeset/5708 Log: I have modified the ldap-sync plugin in a way, so that it can talk to the LDAP server "ns-slapd" from the Fedora Directory Server package. This is only the first step in trying to achieve compatibility with the Fedora Directory Server. The ldap-sync plugin in its current fashion is still to be linked against libldap from openldap. Most notable differences between slapd from openldap and ns-slapd from the Fedora Directory Server: 1. Searching for the available objectclasses works differently: slapd: ldapsearch (...) -LLL -b 'cn=Subschema' -s base '(objectclass=subschema)' objectClasses ns-slapd: ldapsearch (...) -LLL -b "cn=schema" -s base "objectclass=*" objectclasses | egrep -o "NAME[ ]*['][^']+[']" | cut -d\' -f2 2. ns-slapd does not know the scope type "LDAP_SCOPE_CHILDREN". Only "LDAP_SCOPE_SUB" and "LDAP_SCOPE_ONE", and - as it seems - LDAP_SCOPE_BASE. Cf. http://www.redhat.com/docs/manuals/dir-server/ag/8.0/Finding_Directory_Entries-Using_ldapsearch.html#Using_ldapsearch-Commonly_Used_ldapsearch_Options Modified: plugins/ldap-sync/src/ldap_connect.c plugins/ldap-sync/src/ldap_plugin.c plugins/ldap-sync/src/ldap_plugin.h Modified: plugins/ldap-sync/src/ldap_connect.c ============================================================================== --- plugins/ldap-sync/src/ldap_connect.c Mon Jul 27 22:38:57 2009 (r5707) +++ plugins/ldap-sync/src/ldap_connect.c Mon Jul 27 22:39:10 2009 (r5708) @@ -183,7 +183,18 @@ - +/** + * @brief This function checks whether the LDAP server supports + * the LDAP schema that has been configured for usage with + * the object type "contact". + * + * @param ctx The libopensync context. + * @param sinkenv The object type environment. + * @param error The libopensync error pointer. + * + * @returns TRUE on success, FALSE on error. + * + */ osync_bool ldap_plugin_check_contact_format_support(OSyncContext *ctx, sink_environment *sinkenv, OSyncError **error) { @@ -379,7 +390,7 @@ if (!ldap_plugin_get_sinkenv(ctx, sink, userdata, &sinkenv, &error)) { if (!osync_error_is_set(&error)) - osync_error_set(&error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: has failed.", __FILE__, __LINE__); + osync_error_set(&error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: ldap_plugin_get_sinkenv() has failed.", __FILE__, __LINE__); goto error; } @@ -460,7 +471,7 @@ - // Bind to LDAP server + // Bind with LDAP server if (!ldap_plugin_makebind(ctx, sinkenv, &error)) { if (!osync_error_is_set(&error)) { osync_error_set(&error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Could not bind with LDAP server.", __FILE__, __LINE__); @@ -471,6 +482,17 @@ + if (!ldap_plugin_check_for_entryCSN(ctx, sinkenv, &error)) { + if (!osync_error_is_set(&error)) { + osync_error_set(&error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_check_for entryCSN() has failed.", __FILE__, __LINE__); + } + + goto error; + } + + + + if (!strcmp(osync_objtype_sink_get_name(sink), "contact")) { // Check whether the format chosen by configuration is supported // by the LDAP server, as well (currently only for objtype "contact"): @@ -614,7 +636,7 @@ if (!ldap_plugin_get_sinkenv(ctx, sink, userdata, &sinkenv, &error)) { if (!osync_error_is_set(&error)) - osync_error_set(&error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: has failed.", __FILE__, __LINE__); + osync_error_set(&error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: ldap_plugin_get_sinkenv() has failed.", __FILE__, __LINE__); goto error; } @@ -764,9 +786,9 @@ if (ldap_error == NULL) { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: ldap_start_tls_s() has failed. Could not establish a connection to the LDAP server \"%s\", therefore.\n", __FILE__, __LINE__, sinkenv->url); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: ldap_start_tls_s() has failed. Could not establish a connection to the LDAP server \"%s\", therefore.\n", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername); } else { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: ldap_start_tls_s() has failed. Could not establish a connection to the LDAP server \"%s\", therefore: \"%s\"\n", __FILE__, __LINE__, sinkenv->url, ldap_error); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: ERROR: ldap_start_tls_s() has failed. Could not establish a connection to the LDAP server \"%s\", therefore: \"%s\"\n", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, ldap_error); } goto error; @@ -790,7 +812,7 @@ /** - * @brief Binds to the LDAP server. + * @brief Binds with the LDAP server. * * Quoting from LDAP admin guide, section 13.3.1: * @@ -883,16 +905,16 @@ if (passwd.bv_len == 0) { if (ldap_error == NULL) { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind to \"%s\" as \"%s\" with an empty password. Maybe the LDAP server does not allow anonymous binds.", __FILE__, __LINE__, sinkenv->servername, binddn); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind with \"%s\" as \"%s\" with an empty password. Maybe the LDAP server does not allow anonymous binds.", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, binddn); } else { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind to \"%s\" as \"%s\" with an empty password. Maybe the LDAP server does not allow anonymous binds: \"%s\"", __FILE__, __LINE__, sinkenv->servername, binddn, ldap_error); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind with \"%s\" as \"%s\" with an empty password. Maybe the LDAP server does not allow anonymous binds: \"%s\"", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, binddn, ldap_error); } } else { if (ldap_error == NULL) { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind to \"%s\" as \"%s\".", __FILE__, __LINE__, sinkenv->servername, binddn); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind with \"%s\" as \"%s\".", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, binddn); } else { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind to \"%s\" as \"%s\": \"%s\"", __FILE__, __LINE__, sinkenv->servername, binddn, ldap_error); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and bind with \"%s\" as \"%s\": \"%s\"", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, binddn, ldap_error); } } @@ -975,18 +997,18 @@ if (passwd.bv_len == 0) { if (ldap_error == NULL) { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind to \"%s\" as \"%s\" with an empty password, using \"%s\" as authentication mechanism. Maybe the LDAP server does not allow an anonymous bind.", __FILE__, __LINE__, sinkenv->servername, sinkenv->authcid, tmp_authmech); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind with \"%s\" as \"%s\" with an empty password, using \"%s\" as authentication mechanism. Maybe the LDAP server does not allow an anonymous bind.", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, sinkenv->authcid, tmp_authmech); } else { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind to \"%s\" as \"%s\" with an empty password, using \"%s\" as authentication mechanism. Maybe the LDAP server does not allow an anonymous bind: \"%s\"", __FILE__, __LINE__, sinkenv->servername, sinkenv->authcid, tmp_authmech, ldap_error); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind with \"%s\" as \"%s\" with an empty password, using \"%s\" as authentication mechanism. Maybe the LDAP server does not allow an anonymous bind: \"%s\"", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, sinkenv->authcid, tmp_authmech, ldap_error); } } else { if (ldap_error == NULL) { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind to \"%s\" as \"%s\" using \"%s\" as authentication mechanism.", __FILE__, __LINE__, sinkenv->servername, sinkenv->authcid, tmp_authmech); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind with \"%s\" as \"%s\" using \"%s\" as authentication mechanism.", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, sinkenv->authcid, tmp_authmech); } else { if (extra_error && extra_error[0]) { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind to \"%s\" as \"%s\" using \"%s\" as authentication mechanism: \"%s\". %s", __FILE__, __LINE__, sinkenv->servername, sinkenv->authcid, tmp_authmech, ldap_error, extra_error); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind with \"%s\" as \"%s\" using \"%s\" as authentication mechanism: \"%s\". %s", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, sinkenv->authcid, tmp_authmech, ldap_error, extra_error); } else { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind to \"%s\" as \"%s\" using \"%s\" as authentication mechanism: \"%s\"", __FILE__, __LINE__, sinkenv->servername, sinkenv->authcid, tmp_authmech, ldap_error); + osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "%s:%i: Unable to connect and sasl bind with \"%s\" as \"%s\" using \"%s\" as authentication mechanism: \"%s\"", __FILE__, __LINE__, sinkenv->url ? sinkenv->url : sinkenv->servername, sinkenv->authcid, tmp_authmech, ldap_error); } } } @@ -1129,8 +1151,8 @@ *result = FALSE; - // Look for all the LDAP subschemata: - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, "cn=Subschema", "(objectClass=subschema)", LDAP_SCOPE_BASE, OBJECTCLASSES, sinkenv, FALSE, &res, error)) { + // Look for all the LDAP subschemata (as used by slapd from openldap): + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, "cn=Subschema", "(objectClass=subschema)", LDAP_SCOPE_BASE, OBJECTCLASSES, sinkenv, TRUE, &res, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -1140,7 +1162,6 @@ if (res == NULL) { - // TODO: Produce osync error message. osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() must have failed.\n", __FILE__, __LINE__); ldap_plugin_dump_ldap_error_message(sinkenv, "cn=Subschema", "(objectClass=subschema)", "ldap_plugin_call_ldap_search()"); @@ -1151,28 +1172,220 @@ res2 = ldap_first_entry(sinkenv->ld, res); if (!res2) { /* No objectClass entries found */ +/* osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Could not find any objectClass entry while searching for LDAP subschemata.", __FILE__, __LINE__); goto error; - } +*/ + if (res) + ldap_msgfree(res); - ber = ldap_get_values_len(sinkenv->ld, res2, "objectClasses"); + // Look for all the LDAP schemata (as used by ns-slapd from the + // fedora directory server): + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, "cn=schema", "(objectClass=subschema)", LDAP_SCOPE_BASE, OBJECTCLASSES, sinkenv, TRUE, &res, error)) { + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + } - while (ber[i]) { - if (strstr(ber[i]->bv_val, ldap_schema)) { - *result = TRUE; - break; + goto error; + } + + if (res == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() must have failed.\n", __FILE__, __LINE__); + ldap_plugin_dump_ldap_error_message(sinkenv, "cn=schema", "(objectClass=subschema)", "ldap_plugin_call_ldap_search()"); + + goto error; } - i++; - } + res2 = ldap_first_entry(sinkenv->ld, res); + if (!res2) { + /* No objectClass entries found */ + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Could not find any objectClass entry while searching for LDAP schemata.", __FILE__, __LINE__); + goto error; + } else { + ber = ldap_get_values_len(sinkenv->ld, res2, "objectClasses"); + } + } else { + ber = ldap_get_values_len(sinkenv->ld, res2, "objectClasses"); + } + + + if (ber) { + while (ber[i]) { + if (strstr(ber[i]->bv_val, ldap_schema)) { + *result = TRUE; + break; + } + i++; + } + } else { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ber = NULL. This should have been unreachable code.", __FILE__, __LINE__); + goto error; + } + + + if (ber) + ldap_value_free_len(ber); + + if (res) + ldap_msgfree(res); + + + + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; + + +error: if (ber) ldap_value_free_len(ber); if (res) ldap_msgfree(res); + if (!osync_error_is_set(error)) + osync_error_set(error, OSYNC_ERROR_GENERIC, "Unknown reason.\n"); + + osync_context_report_osyncwarning(ctx, *error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; +} + + + + +/* + * @brief This function checks whether the LDAP server supports the + * operational attribute "entryCSN". While slapd from openldap + * does so, ns-slapd from the Fedora Directory Server does not. + * entryCSN and modifyTimestamp in the latter case are used to + * build up a unique hash value for the current state of an + * LDAP entry. @sa ldap_plugin_get_hash_from_ldap_server() + * + * @param ctx The libopensync context. + * @param sinkenv The object type environment. As a result of this function + * sinkenv->has_entryCSN is set to either TRUE or FALSE. + * @param error The libopensync error pointer. + * + * @returns TRUE on success, FALSE on error. + */ + +osync_bool +ldap_plugin_check_for_entryCSN(OSyncContext *ctx, sink_environment *sinkenv, OSyncError **error) +{ + LDAPMessage *res = NULL; + LDAPMessage *all_entries = NULL; + char *filter = NULL; + char *base = NULL; + struct berval **ber = NULL; + + + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, ctx, sinkenv, error); + + + if (ctx == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ctx = NULL. Returning.\n", __FILE__, __LINE__); + goto error; + } + + if (sinkenv == NULL) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: sinkenv = NULL. Returning.\n", __FILE__, __LINE__); + goto error; + } + + + + + + filter = (char *)g_malloc0(4096); + if (filter) { + memset(filter, 0, 4096); + } else { + ldap_plugin_printf("%s:%i: ERROR: g_malloc0 problem. Exiting.", __FILE__, __LINE__); + exit(1); + } + + snprintf(filter, 4095, "(entryCSN=*)"); + + + base = (char *)g_malloc0(4096); + if (base) { + memset(base, 0, 4096); + } else { + ldap_plugin_printf("%s:%i: ERROR: g_malloc0 problem. Exiting.", __FILE__, __LINE__); + exit(1); + } + + snprintf(base, 4095, "%s", sinkenv->searchbase); + +#ifdef DEBUG_configuration + ldap_plugin_printf("\n\n%s:%i: base = \"%s\", filter = \"%s\"", __FILE__, __LINE__, base, filter); +#endif + + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_BASE, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &all_entries, error)) { + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + } + + goto error; + } + + + if (all_entries == NULL) { + int result_code = 0; + + if (ldap_get_option(sinkenv->ld, LDAP_OPT_RESULT_CODE, &result_code) != LDAP_OPT_SUCCESS) { + osync_trace(TRACE_ERROR, "%s:%i: ERROR: ldap_get_option() has failed. result_code could not be filled in.\n", __FILE__, __LINE__); + } else { + if (result_code != LDAP_SUCCESS) { + char *error_msg = ldap_plugin_report_ldap_error(sinkenv, __FILE__, __LINE__, result_code); + if (error_msg) { + ldap_plugin_printf("%s:%i: ERROR: %s", __FILE__, __LINE__, error_msg); + g_free(error_msg); + } + } + } + + osync_trace(TRACE_INTERNAL, "\n\n%s:%i: Setting sinkenv->has_entryCSN to FALSE.", __FILE__, __LINE__); + + sinkenv->has_entryCSN = FALSE; + } else { + int count = ldap_count_entries(sinkenv->ld, all_entries); + +#ifdef DEBUG_configuration + ldap_plugin_printf("%s:%i: There are %i subentries.", __FILE__, __LINE__, count); +#endif + + if (count > 0) { + osync_trace(TRACE_INTERNAL, "\n\n%s:%i: Setting sinkenv->has_entryCSN to TRUE.", __FILE__, __LINE__); + sinkenv->has_entryCSN = TRUE; + } else { + osync_trace(TRACE_INTERNAL, "\n\n%s:%i: Setting sinkenv->has_entryCSN to FALSE.", __FILE__, __LINE__); + sinkenv->has_entryCSN = FALSE; + } + } + + + + + + + + + + + + if (base) + g_free(base); + + if (filter) + g_free(filter); + + if (all_entries) { + ldap_msgfree(all_entries); + all_entries = NULL; + } osync_trace(TRACE_EXIT, "%s", __func__); @@ -1186,6 +1399,17 @@ if (res) ldap_msgfree(res); + if (base) + g_free(base); + + if (filter) + g_free(filter); + + if (all_entries) { + ldap_msgfree(all_entries); + all_entries = NULL; + } + if (!osync_error_is_set(error)) osync_error_set(error, OSYNC_ERROR_GENERIC, "Unknown reason.\n"); @@ -1196,6 +1420,8 @@ + + /** * @brief A wrapper function to the ldap_search_ext_s() library call. * @@ -1255,6 +1481,10 @@ userattributes[0] = "objectClasses"; break; + case FEDORADSmodifyTimestamp: + userattributes[0] = "modifyTimestamp"; + break; + default: userattributes[0] = LDAP_ALL_USER_ATTRIBUTES; }; @@ -1873,7 +2103,15 @@ char *subentry_filter = (char *)"(objectClass=*)"; LDAPMessage *possible_subentries = NULL; - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, subentry_filter, LDAP_SCOPE_CHILDREN, USER_ATTRIBUTES, sinkenv, FALSE, &possible_subentries, error)) { + + /* ns-slapd does not understand LDAP_SCOPE_CHILDREN. + * LDAP_SCOPE_ONELEVEL is NOT correct, because it does not cover + * special elements, like AlarmDisplay, RecurrenceRule, TimezoneComponent, + * TimezoneRule etc. + * So we MUST use LDAP_SCOPE_SUBTREE. This forces us to skip the + * base element (continue in a for-loop). + */ + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, subentry_filter, /* LDAP_SCOPE_CHILDREN */ LDAP_SCOPE_SUBTREE, USER_ATTRIBUTES, sinkenv, FALSE, &possible_subentries, error)) { if (!osync_error_is_set(error)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); } @@ -1897,6 +2135,22 @@ for ( ; subentry_result ; subentry_result = ldap_next_entry(sinkenv->ld, subentry_result)) { // keyattribute for subentries: "ou" char *keyattr = (char *)"ou"; + + +#ifdef DEBUG_ldapdata_from_server + fprintf(stderr, "\n\n\n%s:%i: dn: \"%s\"\n\n\n", __FILE__, __LINE__, ldap_get_dn(sinkenv->ld, subentry_result)); +#endif + + // We skip the base element, because with respect to ns-slapd + // we have used LDAP_SCOPE_SUBTREE rather than LDAP_SCOPE_CHILDREN. + if (!strcmp(entry->dn, ldap_get_dn(sinkenv->ld, subentry_result))) { +#ifdef DEBUG_ldapdata_from_server + fprintf(stderr, "\n\n\n****************\n%s:%i: dn == base!!!\n****************\n\n\n", __FILE__, __LINE__); +#endif + + continue; + } + ldap_entry *subentry = ldap_plugin_create_ldap_entry_from_LDAPMessage(ctx, sinkenv, subentry_result, keyattr, error); if (subentry == NULL) { @@ -2346,8 +2600,9 @@ /** * @brief This function calculates the hash value of one LDAP entry on the - * LDAP server. The hash is based on the entryCSN attribute of each entry - * in the DIT. Helper function for ldap_plugin_get_hash_from_ldap_server(). + * LDAP server. The hash is based on either the entryCSN attribute + * or the modifyTimestamp attribute of each entry in the DIT. + * Helper function for ldap_plugin_get_hash_from_ldap_server(). * * @param ctx The libopensync context. * @param sinkenv Object type specific environment. @@ -2395,7 +2650,14 @@ // ------------------------------------------- for ( ; one_entry; one_entry = ldap_next_entry(sinkenv->ld, one_entry)) { - struct berval **one_csn = ldap_get_values_len(sinkenv->ld, one_entry, "entryCSN"); + struct berval **one_csn = NULL; + + + if (sinkenv->has_entryCSN) { + one_csn = ldap_get_values_len(sinkenv->ld, one_entry, "entryCSN"); + } else { + one_csn = ldap_get_values_len(sinkenv->ld, one_entry, "modifyTimestamp"); + } if (!one_csn) { @@ -2412,7 +2674,11 @@ if (one_csn[0]->bv_val) { #ifdef DEBUG_fastsync - ldap_plugin_printf("%s:%i: entryCSN = \"%s\"", __FILE__, __LINE__, one_csn[0]->bv_val); + if (sinkenv->has_entryCSN) { + ldap_plugin_printf("%s:%i: entryCSN = \"%s\"", __FILE__, __LINE__, one_csn[0]->bv_val); + } else { + ldap_plugin_printf("%s:%i: modifyTimestamp = \"%s\"", __FILE__, __LINE__, one_csn[0]->bv_val); + } #endif if (actual_hash == NULL) { @@ -2460,8 +2726,8 @@ /** * @brief This functions calculates the hash value of an LDAP entry including - * any subentries in the DIT for any uid, based on the entryCSN - * attribute of each entry/subentry. + * any subentries in the DIT for any uid, based on either the entryCSN + * attribute or the modifyTimestamp attribute of each entry/subentry. * * @param ctx The libopensync context. * @param sinkenv Object type specific environment @@ -2506,7 +2772,11 @@ - snprintf(filter, 4095, "(entryCSN=*)"); + if (sinkenv->has_entryCSN) { + snprintf(filter, 4095, "(entryCSN=*)"); + } else { + snprintf(filter, 4095, "(modifyTimestamp=*)"); + } base = (char *)g_malloc0(4096); if (base) { @@ -2524,16 +2794,26 @@ #endif // -------------------------------------------------- - // Get entryCSN for the base entry itself plus all related subentries - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_SUBTREE, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &all_entries, error)) { - if (!osync_error_is_set(error)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + // Get entryCSN or modifyTimesatmp for the base entry itself + // plus all related subentries + if (sinkenv->has_entryCSN) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_SUBTREE, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &all_entries, error)) { + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + } + + goto error; } + } else { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, base, filter, LDAP_SCOPE_SUBTREE, FEDORADSmodifyTimestamp, sinkenv, FALSE, &all_entries, error)) { + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + } - goto error; + goto error; + } } - if (all_entries == NULL) { ldap_plugin_dump_ldap_error_message(sinkenv, base, filter, "ldap_plugin_call_ldap_search()"); osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: all_entries = NULL. No hash available for this uid.\n", __FILE__, __LINE__); @@ -4141,12 +4421,13 @@ /** - * @brief Queries the LDAP server about the entryCSN attribute of - * one particular LDAP entry, and adds it to an already existing - * hash string, thus gradually building the final hash value. + * @brief Queries the LDAP server about either the entryCSN attribute + * or the modifyTimestamp attribute of one particular LDAP entry, + * and adds it to an already existing hash string, thus gradually + * building the final hash value. * * @param ctx The libopensync context. - * @param hash The entryCSN based hash value of an LDAP entry. + * @param hash The entryCSN/modifyTimestamp based hash value of an LDAP entry. * @param sinkenv The object type specific environment. * @param entry The LDAP entry. * @param error The libopensync error pointer. @@ -4196,23 +4477,47 @@ ldap_plugin_printf("%s:%i: \nentry->dn = \"%s\"", __FILE__, __LINE__, entry->dn); #endif - - if (sinkenv->searchfilter) { - filter = g_strdup_printf("(&(entryCSN=*)%s)", sinkenv->searchfilter); + + if (sinkenv->has_entryCSN) { + if (sinkenv->searchfilter) { + filter = g_strdup_printf("(&(entryCSN=*)%s)", sinkenv->searchfilter); + } else { + filter = g_strdup_printf("(entryCSN=*)"); + } + + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUB, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &messages, error)) { + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + } + + goto error; + } + } else { - filter = (char *)"(entryCSN=*)"; - } + if (sinkenv->searchfilter) { + filter = g_strdup_printf("(&(modifyTimestamp=*)%s)", sinkenv->searchfilter); + } else { + filter = g_strdup_printf("(modifyTimestamp=*)"); + } - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, "(entryCSN=*)", LDAP_SCOPE_SUB, OPERATIONAL_ATTRIBUTES, sinkenv, FALSE, &messages, error)) { - if (!osync_error_is_set(error)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, filter, LDAP_SCOPE_SUB, FEDORADSmodifyTimestamp, sinkenv, FALSE, &messages, error)) { + if (!osync_error_is_set(error)) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: ldap_plugin_call_ldap_search() has failed.\n", __FILE__, __LINE__); + } + + goto error; } - goto error; } + + + + if (filter) { + g_free(filter); + filter = NULL; + } - g_free(filter); if (messages == NULL) { int result_code = 0; @@ -4230,13 +4535,26 @@ } else { LDAPMessage *msg = ldap_first_entry(sinkenv->ld, messages); for ( ; msg ; msg = ldap_next_entry(sinkenv->ld, msg)) { - struct berval **id_values = ldap_get_values_len(sinkenv->ld, msg, "entryCSN"); + struct berval **id_values = NULL; char *ldap_attribute = NULL; BerElement *berptr = NULL; + if (sinkenv->has_entryCSN) { + id_values = ldap_get_values_len(sinkenv->ld, msg, "entryCSN"); + } else { + id_values = ldap_get_values_len(sinkenv->ld, msg, "modifyTimestamp"); + } + + + if (!id_values) { - ldap_plugin_printf("%s:%i: WARNING: Entry DN=%s has no attribute 'entryCSN' which is used here as key attribute.", __FILE__, __LINE__, ldap_get_dn(sinkenv->ld, msg)); + if (sinkenv->has_entryCSN) { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Entry dn: %s has no attribute 'entryCSN', although here it is expected as key attribute.", __FILE__, __LINE__, ldap_get_dn(sinkenv->ld, msg)); + } else { + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: WARNING: Entry dn: %s has no attribute 'modifyTimestamp', although here it is expected as key attribute.", __FILE__, __LINE__, ldap_get_dn(sinkenv->ld, msg)); + } + goto error; } else { @@ -4252,7 +4570,16 @@ ldap_attribute = ldap_next_attribute(sinkenv->ld, msg, berptr) ) { - if (!strcmp(ldap_attribute, "entryCSN")) { + const char *identifying_str = NULL; + + + if (sinkenv->has_entryCSN) { + identifying_str = "entryCSN"; + } else { + identifying_str = "modifyTimestamp"; + } + + if (!strcmp(ldap_attribute, identifying_str)) { struct berval **ret = NULL; ret = ldap_get_values_len(sinkenv->ld, msg, ldap_attribute); @@ -4315,7 +4642,10 @@ break; - } // if (!strcmp(ldap_attribute, "entryCSN")) + } // if (!strcmp(ldap_attribute, identifying_str)) + + + if (ldap_attribute) { ldap_memfree(ldap_attribute); Modified: plugins/ldap-sync/src/ldap_plugin.c ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.c Mon Jul 27 22:38:57 2009 (r5707) +++ plugins/ldap-sync/src/ldap_plugin.c Mon Jul 27 22:39:10 2009 (r5708) @@ -583,7 +583,7 @@ * @returns TRUE on successful parsing, FALSE on any error. */ -osync_bool ldap_plugin_parse_config(OSyncPluginInfo *info, sink_environment *sinkenv, const char *objtype, OSyncPluginConfig * config, OSyncError **error) +osync_bool ldap_plugin_parse_config(OSyncPluginInfo *info, sink_environment *sinkenv, const char *objtype, OSyncPluginConfig *config, OSyncError **error) { osync_bool retval = FALSE; OSyncPluginConnection *conn = NULL; @@ -3306,7 +3306,7 @@ // we should call ldap_add_ext_s(), instead. // So we must check for the existence of this LDAP entry in order to // decide which libldap call to make. - if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, "", LDAP_SCOPE_BASE, USER_ATTRIBUTES, sinkenv, FALSE, &res2, error)) { + if (!ldap_plugin_call_ldap_search(ctx, sinkenv->ld, entry->dn, "(objectclass=*)", LDAP_SCOPE_BASE, USER_ATTRIBUTES, sinkenv, FALSE, &res2, error)) { int result_code = 0; Modified: plugins/ldap-sync/src/ldap_plugin.h ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.h Mon Jul 27 22:38:57 2009 (r5707) +++ plugins/ldap-sync/src/ldap_plugin.h Mon Jul 27 22:39:10 2009 (r5708) @@ -181,7 +181,11 @@ #define OPERATIONAL_ATTRIBUTES 2 ///< This refers to ldap_plugin_call_ldap_search() ///< and LDAP_ALL_OPERATIONAL_ATTRIBUTES in ldap.h #define OBJECTCLASSES 3 ///< This refers to ldap_plugin_call_ldap_search() - +#define FEDORADSmodifyTimestamp 4 ///< ns-slapd does not clearly make + ///< an appropriate distinction between + ///< LDAP_ALL_USER_ATTRIBUTES and + ///< LDAP_ALL_OPERATIONAL_ATTRIBUTES. + ///< This is sloppy. @@ -362,6 +366,11 @@ ///< the "mozillaAbPersonAlpha" objectclass. osync_bool inetorg_support; ///< Whether or not the LDAP server supports ///< the "inetOrgPerson" objectclass + osync_bool has_entryCSN; ///< Whether or not the LDAP server offers + ///< the operational attribute "entryCSN". + ///< slapd from openldap does, whereas + ///< ns-slapd from the fedora directory server + ///< does not, as it seems. LDAP *ld; ///< Handle for the connection to the LDAP server. ///< (NULL, if no connection is present) } sink_environment; @@ -419,6 +428,7 @@ char *ldap_plugin_build_actual_hash(OSyncContext *ctx, sink_environment *sinkenv, const char *base, const char *filter, LDAPMessage *all_entries, OSyncError **error); osync_bool ldap_plugin_call_ldap_search(OSyncContext *ctx, const LDAP *ldap_handle, const char *searchbase, const char *filter, const int scope, const int kind_of_attributes, const sink_environment *sinkenv, osync_bool ignore_no_such_object, LDAPMessage **results, OSyncError **error); osync_bool ldap_plugin_check_contact_format_support(OSyncContext *ctx, sink_environment *sinkenv, OSyncError **error); +osync_bool ldap_plugin_check_for_entryCSN(OSyncContext *ctx, sink_environment *sinkenv, OSyncError **error); osync_bool ldap_plugin_check_for_keyattribute(sink_environment *sinkenv, ldap_entry *entry, osync_bool check_key_attribute, OSyncError **error); osync_bool ldap_plugin_check_ldap_schema_support(OSyncContext *ctx, sink_environment *sinkenv, const char *ldap_schema, osync_bool *result, OSyncError **error); osync_bool ldap_plugin_check_modify_on_attr_vals (OSyncContext *ctx, struct berval **oldvals, struct berval **newvals, osync_bool *modification, OSyncError **error); |
From: <svn...@op...> - 2009-07-27 20:39:07
|
Author: scriptor Date: Mon Jul 27 22:38:57 2009 New Revision: 5707 URL: http://www.opensync.org/changeset/5707 Log: Example configuration files to be used with slapd from openldap and ns-slapd from the Fedora Directory Server. Added: plugins/ldap-sync/tests/ldap-sync.conf_ns-slapd_example plugins/ldap-sync/tests/ldap-sync.conf_slapd_example Added: plugins/ldap-sync/tests/ldap-sync.conf_ns-slapd_example ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ plugins/ldap-sync/tests/ldap-sync.conf_ns-slapd_example Mon Jul 27 22:38:57 2009 (r5707) @@ -0,0 +1,191 @@ +<?xml version="1.0"?> +<config version="1.0"> + <AdvancedOptions> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>binddn</Name> + <Type>string</Type> + <Value>cn=ldap_user,ou=People,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>authcid</Name> + <Type>string</Type> + <Value>ldap_user</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>password</Name> + <Type>string</Type> + <Value>secret</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>anonymous</Name> + <Type>string</Type> + <Value>0</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>authmech</Name> + <Type>string</Type> + <Value>SIMPLE</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>encryption</Name> + <Type>string</Type> + <Value>0</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>ldap_read</Name> + <Type>string</Type> + <Value>1</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>ldap_write</Name> + <Type>string</Type> + <Value>1</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_contact</Name> + <Type>string</Type> + <Value>ou=addressbook,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_contact</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_contact</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_event</Name> + <Type>string</Type> + <Value>ou=calendar,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_event</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_event</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_todo</Name> + <Type>string</Type> + <Value>ou=todo,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_todo</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_todo</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_note</Name> + <Type>string</Type> + <Value>o=notes,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_note</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_note</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + </AdvancedOptions> + <Connection> + <ActiveConnection>Network</ActiveConnection> + <Network> + <Address>localhost</Address> + <Port>3890</Port> + <Protocol>ldap</Protocol> + </Network> + </Connection> + <Resources> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-inetorgperson</Name> + </Format> + </Formats> + <ObjType>contact</ObjType> + </Resource> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-event</Name> + </Format> + </Formats> + <ObjType>event</ObjType> + </Resource> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-todo</Name> + </Format> + </Formats> + <ObjType>todo</ObjType> + </Resource> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-note</Name> + </Format> + </Formats> + <ObjType>note</ObjType> + </Resource> + </Resources> +</config> Added: plugins/ldap-sync/tests/ldap-sync.conf_slapd_example ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ plugins/ldap-sync/tests/ldap-sync.conf_slapd_example Mon Jul 27 22:38:57 2009 (r5707) @@ -0,0 +1,191 @@ +<?xml version="1.0"?> +<config version="1.0"> + <AdvancedOptions> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>binddn</Name> + <Type>string</Type> + <Value>cn=ldap_user,ou=people,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>authcid</Name> + <Type>string</Type> + <Value>ldap_user</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>password</Name> + <Type>string</Type> + <Value>secret</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>anonymous</Name> + <Type>string</Type> + <Value>0</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>authmech</Name> + <Type>string</Type> + <Value>GSSAPI</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>encryption</Name> + <Type>string</Type> + <Value>0</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>ldap_read</Name> + <Type>string</Type> + <Value>1</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>ldap_write</Name> + <Type>string</Type> + <Value>1</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_contact</Name> + <Type>string</Type> + <Value>ou=addressbook,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_contact</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_contact</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_event</Name> + <Type>string</Type> + <Value>ou=calendar,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_event</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_event</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_todo</Name> + <Type>string</Type> + <Value>ou=todo,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_todo</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_todo</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchbase_note</Name> + <Type>string</Type> + <Value>o=notes,dc=example,dc=com</Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>searchfilter_note</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + <AdvancedOption> + <MaxOccurs>2147483647</MaxOccurs> + <Max>2147483647</Max> + <Name>storebase_note</Name> + <Type>string</Type> + <Value></Value> + </AdvancedOption> + </AdvancedOptions> + <Connection> + <ActiveConnection>Network</ActiveConnection> + <Network> + <Address>localhost</Address> + <Port>389</Port> + <Protocol>ldap</Protocol> + </Network> + </Connection> + <Resources> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-inetorgperson</Name> + </Format> + </Formats> + <ObjType>contact</ObjType> + </Resource> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-event</Name> + </Format> + </Formats> + <ObjType>event</ObjType> + </Resource> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-todo</Name> + </Format> + </Formats> + <ObjType>todo</ObjType> + </Resource> + <Resource> + <Enabled>1</Enabled> + <Formats> + <Format> + <Name>ldap-note</Name> + </Format> + </Formats> + <ObjType>note</ObjType> + </Resource> + </Resources> +</config> |