diff options
author | Martin Szulecki | 2011-03-16 21:35:56 +0100 |
---|---|---|
committer | Martin Szulecki | 2011-03-16 21:35:56 +0100 |
commit | ae4b7bacc40fe85fa3c2c023ca5a6a5b45b43c53 (patch) | |
tree | 259f8e05d2dd84b44aeb0fef8359efd5a754b20f | |
parent | 1ecd04355c0a135ef2c2244186977c5700390c96 (diff) | |
download | libimobiledevice-ae4b7bacc40fe85fa3c2c023ca5a6a5b45b43c53.tar.gz libimobiledevice-ae4b7bacc40fe85fa3c2c023ca5a6a5b45b43c53.tar.bz2 |
mobilesync: Check for cancel message when attempting to clear all records on device
Furthermore the clearing must happen after starting synchronization and as
we have the data class set already, we can obsolete that argument.
-rw-r--r-- | include/libimobiledevice/mobilesync.h | 2 | ||||
-rw-r--r-- | src/mobilesync.c | 22 |
2 files changed, 16 insertions, 8 deletions
diff --git a/include/libimobiledevice/mobilesync.h b/include/libimobiledevice/mobilesync.h index 2cd6d30..7658b7d 100644 --- a/include/libimobiledevice/mobilesync.h +++ b/include/libimobiledevice/mobilesync.h @@ -78,7 +78,7 @@ mobilesync_error_t mobilesync_finish(mobilesync_client_t client); mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client); mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client); -mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client, const char *data_class); +mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client); mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions); mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client); diff --git a/src/mobilesync.c b/src/mobilesync.c index 475e46c..7f20e16 100644 --- a/src/mobilesync.c +++ b/src/mobilesync.c @@ -516,18 +516,17 @@ mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_ } /** - * Requests the device to delete all records of the supplied data class + * Requests the device to delete all records of the current data class * - * @note The operation must be called outside of the regular synchronization loop. + * @note The operation must be called after starting synchronization. * * @param client The mobilesync client - * @param data_class The data class identifier * * @retval MOBILESYNC_E_SUCCESS on success * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form */ -mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client, const char *data_class) +mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client) { if (!client || !client->data_class) { return MOBILESYNC_E_INVALID_ARG; @@ -540,7 +539,7 @@ mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t cl msg = plist_new_array(); plist_array_append_item(msg, plist_new_string("SDMessageClearAllRecordsOnDevice")); - plist_array_append_item(msg, plist_new_string(data_class)); + plist_array_append_item(msg, plist_new_string(client->data_class)); plist_array_append_item(msg, plist_new_string(EMPTY_PARAMETER_STRING)); err = mobilesync_send(client, msg); @@ -570,8 +569,17 @@ mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t cl goto out; } - if (!strcmp(response_type, "SDMessageDeviceWillClearAllRecords")) { - err = MOBILESYNC_E_SUCCESS; + if (!strcmp(response_type, "SDMessageCancelSession")) { + char *reason = NULL; + err = MOBILESYNC_E_CANCELLED; + plist_get_string_val(plist_array_get_item(msg, 2), &reason); + debug_info("Device cancelled: %s", reason); + free(reason); + goto out; + } + + if (strcmp(response_type, "SDMessageDeviceWillClearAllRecords")) { + err = MOBILESYNC_E_PLIST_ERROR; } out: |