diff options
Diffstat (limited to 'src/mobilesync.c')
| -rw-r--r-- | src/mobilesync.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/mobilesync.c b/src/mobilesync.c index c444c8e..475e46c 100644 --- a/src/mobilesync.c +++ b/src/mobilesync.c | |||
| @@ -516,6 +516,78 @@ mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_ | |||
| 516 | } | 516 | } |
| 517 | 517 | ||
| 518 | /** | 518 | /** |
| 519 | * Requests the device to delete all records of the supplied data class | ||
| 520 | * | ||
| 521 | * @note The operation must be called outside of the regular synchronization loop. | ||
| 522 | * | ||
| 523 | * @param client The mobilesync client | ||
| 524 | * @param data_class The data class identifier | ||
| 525 | * | ||
| 526 | * @retval MOBILESYNC_E_SUCCESS on success | ||
| 527 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
| 528 | * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form | ||
| 529 | */ | ||
| 530 | mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client, const char *data_class) | ||
| 531 | { | ||
| 532 | if (!client || !client->data_class) { | ||
| 533 | return MOBILESYNC_E_INVALID_ARG; | ||
| 534 | } | ||
| 535 | |||
| 536 | mobilesync_error_t err = MOBILESYNC_E_UNKNOWN_ERROR; | ||
| 537 | plist_t msg = NULL; | ||
| 538 | plist_t response_type_node = NULL; | ||
| 539 | char *response_type = NULL; | ||
| 540 | |||
| 541 | msg = plist_new_array(); | ||
| 542 | plist_array_append_item(msg, plist_new_string("SDMessageClearAllRecordsOnDevice")); | ||
| 543 | plist_array_append_item(msg, plist_new_string(data_class)); | ||
| 544 | plist_array_append_item(msg, plist_new_string(EMPTY_PARAMETER_STRING)); | ||
| 545 | |||
| 546 | err = mobilesync_send(client, msg); | ||
| 547 | |||
| 548 | if (err != MOBILESYNC_E_SUCCESS) { | ||
| 549 | goto out; | ||
| 550 | } | ||
| 551 | |||
| 552 | plist_free(msg); | ||
| 553 | msg = NULL; | ||
| 554 | |||
| 555 | err = mobilesync_receive(client, &msg); | ||
| 556 | |||
| 557 | if (err != MOBILESYNC_E_SUCCESS) { | ||
| 558 | goto out; | ||
| 559 | } | ||
| 560 | |||
| 561 | response_type_node = plist_array_get_item(msg, 0); | ||
| 562 | if (!response_type_node) { | ||
| 563 | err = MOBILESYNC_E_PLIST_ERROR; | ||
| 564 | goto out; | ||
| 565 | } | ||
| 566 | |||
| 567 | plist_get_string_val(response_type_node, &response_type); | ||
| 568 | if (!response_type) { | ||
| 569 | err = MOBILESYNC_E_PLIST_ERROR; | ||
| 570 | goto out; | ||
| 571 | } | ||
| 572 | |||
| 573 | if (!strcmp(response_type, "SDMessageDeviceWillClearAllRecords")) { | ||
| 574 | err = MOBILESYNC_E_SUCCESS; | ||
| 575 | } | ||
| 576 | |||
| 577 | out: | ||
| 578 | if (response_type) { | ||
| 579 | free(response_type); | ||
| 580 | response_type = NULL; | ||
| 581 | } | ||
| 582 | if (msg) { | ||
| 583 | plist_free(msg); | ||
| 584 | msg = NULL; | ||
| 585 | } | ||
| 586 | |||
| 587 | return err; | ||
| 588 | } | ||
| 589 | |||
| 590 | /** | ||
| 519 | * Acknowledges to the device that the changes have been merged on the computer | 591 | * Acknowledges to the device that the changes have been merged on the computer |
| 520 | * | 592 | * |
| 521 | * @param client The mobilesync client | 593 | * @param client The mobilesync client |
