From: <svn...@op...> - 2009-10-16 14:42:53
|
Author: bellmich Date: Fri Oct 16 16:42:38 2009 New Revision: 1337 URL: http://libsyncml.opensync.org/changeset/1337 Log: added mapping support for sent and received replace commands Modified: trunk/tools/syncml-ds-tool.c Modified: trunk/tools/syncml-ds-tool.c ============================================================================== --- trunk/tools/syncml-ds-tool.c Fri Oct 16 16:17:08 2009 (r1336) +++ trunk/tools/syncml-ds-tool.c Fri Oct 16 16:42:38 2009 (r1337) @@ -407,7 +407,7 @@ static gboolean smlDsToolRecvChangeStatusCallback (SmlDataSyncDataStoreSession *self, SmlDataSyncChangeItem *item, SmlErrorType code, void *userdata, GError **error); static gboolean smlDsToolRecvMappingCallback (SmlDataSyncDataStoreSession *self, SmlMapItem *item, void *userdata, GError **error); static gchar* smlDsToolGetAnchorCallback (SmlDataSyncDataStoreSession *self, gboolean remote, void *userdata, GError **error); -static gboolean smlDsToolSetAnchorCallback (SmlDataSyncDataStoreSession *self, gboolean remote, const gchar* anchor, void *userdata, GError **error); +static gboolean smlDsToolSetAnchorCallback (SmlDataSyncDataStoreSession *self, gboolean remote, const gchar *anchor, void *userdata, GError **error); SmlTransportType getTransportType(int argc, char *argv[]) { @@ -1077,7 +1077,15 @@ sml_data_sync_change_item_set_action(item, changeType); SmlLocation *uid = sml_location_new(); - sml_location_set_uri(uid, filename); + if (changeType == SML_CHANGE_REPLACE) + { + const gchar *map = g_key_file_get_string(datastore->index, "map", filename, error); + if (!map) + goto error; + sml_location_set_uri(uid, map); + } else { + sml_location_set_uri(uid, filename); + } if (!sml_data_sync_change_item_set_location(item, uid, error)) goto error; if (!sml_data_sync_change_item_set_data(item, data, length, error)) @@ -1247,6 +1255,18 @@ const char *orgUID = sml_location_get_uri(uid); char *safeUID = getSafeFilename(orgUID); printf("Writing item %s to directory %s.\n", safeUID, datastore->directory); + + /* map the item if necessary */ + if (sml_data_sync_change_item_get_action(item) != SML_CHANGE_ADD) + { + const char *map = g_key_file_get_string(datastore->index, "reverse_map", safeUID, error); + if (!map) + goto error; + smlSafeCFree(&safeUID); + safeUID = g_strdup(map); + printf("\tMap item to %s.\n", safeUID); + } + absolute_uid = g_strdup_printf("%s/%s", datastore->directory, safeUID); /* sanity check for uid */ if (!strncmp(safeUID, STATUS_FILENAME, strlen(STATUS_FILENAME))) @@ -1621,6 +1641,8 @@ SmlLocation *loc = sml_data_sync_change_item_get_location(item); const char *key = sml_location_get_uri(loc); + if (sml_data_sync_change_item_get_action(item) != SML_CHANGE_ADD) + key = g_key_file_get_string(datastore->index, "reverse_map", key, error); const char *digest = g_key_file_get_string(datastore->index, "change_index", key, error); if (!digest && *error) goto error; |