From: <svn...@op...> - 2010-02-23 14:19:51
|
Author: bellmich Date: Tue Feb 23 15:19:41 2010 New Revision: 1360 URL: http://libsyncml.opensync.org/changeset/1360 Log: added support for handling of status code 419 Modified: trunk/libsyncml/sml_error.c trunk/libsyncml/sml_error.h trunk/tools/syncml-ds-tool.c Modified: trunk/libsyncml/sml_error.c ============================================================================== --- trunk/libsyncml/sml_error.c Mon Feb 22 16:09:54 2010 (r1359) +++ trunk/libsyncml/sml_error.c Tue Feb 23 15:19:41 2010 (r1360) @@ -130,6 +130,12 @@ case SML_ERROR_ALREADY_EXISTS: return "Already exists. The requested Put or Add command failed " \ "because the target already exists."; + case SML_ERROR_CONFLICT_SERVER_WINS: + return "Conflict resolved with server data. The response indicates that the " \ + "client request created a conflict; which was resolved by the server " \ + "command winning. The normal information in the Status " \ + "SHOULD be sufficient for the client to \"undo\" the resolution, if it " \ + "is desired."; case SML_ERROR_SIZE_MISMATCH: return "Size mismatch. The chunked object was received, but the size of " \ "the received object did not match the size declared within the first " \ Modified: trunk/libsyncml/sml_error.h ============================================================================== --- trunk/libsyncml/sml_error.h Mon Feb 22 16:09:54 2010 (r1359) +++ trunk/libsyncml/sml_error.h Tue Feb 23 15:19:41 2010 (r1360) @@ -95,6 +95,7 @@ SML_ERROR_AUTH_REQUIRED = 407, // Authentication required, Missing Credentials SML_ERROR_RETRY_LATER = 417, // Retry later SML_ERROR_ALREADY_EXISTS = 418, // Put or Add failed because item already exists + SML_ERROR_CONFLICT_SERVER_WINS = 419, // Put or Add creates a conflict. Server data wins. SML_ERROR_SIZE_MISMATCH = 424, // Size mismatch /* Standard errors */ Modified: trunk/tools/syncml-ds-tool.c ============================================================================== --- trunk/tools/syncml-ds-tool.c Mon Feb 22 16:09:54 2010 (r1359) +++ trunk/tools/syncml-ds-tool.c Tue Feb 23 15:19:41 2010 (r1360) @@ -1308,11 +1308,19 @@ /* 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) + /* sometimes an item is not mappeni + * (e.g. client:ADD => server:DELETE because of error 419) + */ + const char *map = NULL; + if (g_key_file_has_group(datastore->index, "reverse_map")) + map = g_key_file_get_string(datastore->index, "reverse_map", safeUID, error); + if (!map && *error) goto error; - smlSafeCFree(&safeUID); - safeUID = g_strdup(map); + if (map) + { + smlSafeCFree(&safeUID); + safeUID = g_strdup(map); + } printf("\tMap item to %s.\n", safeUID); } @@ -1648,8 +1656,14 @@ { smlTrace(TRACE_ENTRY, "%s(%p, %p, %d, %p, %p)", __func__, session, item, code, userdata, error); - /* If there is an error then the whole operation must be aborted. */ - if (sml_error_get_class(code) != SML_ERRORCLASS_SUCCESS) + /* If there is an error then the whole operation must be aborted. + * 418 => The item is already present. So no problem. + * 419 => There was a conflict but the server data wins. + * Usually this means that the item should be removed. + */ + if (sml_error_get_class(code) != SML_ERRORCLASS_SUCCESS && + code != SML_ERROR_ALREADY_EXISTS && + code != SML_ERROR_CONFLICT_SERVER_WINS) { g_set_error(error, TOOL_ERROR, code, smlErrorTypeGetMessage(code)); goto error; @@ -1672,17 +1686,38 @@ if (!digest && *error) goto error; - if (sml_data_sync_change_item_get_action(item) != SML_CHANGE_DELETE) + if (sml_data_sync_change_item_get_action(item) != SML_CHANGE_DELETE && + ! (code == SML_ERROR_CONFLICT_SERVER_WINS && + sml_data_sync_change_item_get_action(item) == SML_CHANGE_ADD + ) + ) + { + /* No delete and no 419 of an add. */ g_key_file_set_string(datastore->index, "committed_index", key, digest); + } + /* NOTICE: glib changed the return type of g_key_file_remove_key */ g_key_file_remove_key(datastore->index, "change_index", key, error); if (*error) goto error; +// /* 419 => conflict and server wins +// * => item must be locally removed. +// */ +// if (code == SML_ERROR_CONFLICT_SERVER_WINS && +// sml_data_sync_change_item_get_action(item) == SML_CHANGE_ADD) +// { +// char *safeUID = getSafeFilename(key); +// char *absoluteUID = g_strdup_printf("%s/%s", datastore->directory, safeUID); +// g_unlink(absoluteUID); +// smlSafeCFree(&absoluteUID); +// smlSafeCFree(&safeUID); +// } + smlTrace(TRACE_EXIT, "%s - TRUE", __func__); return TRUE; error: - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); + smlTrace(TRACE_EXIT_ERROR, "%s - %d => %s", __func__, (*error)->code, (*error)->message); return FALSE; } |