diff options
| -rw-r--r-- | tools/idevicebackup.c | 95 |
1 files changed, 18 insertions, 77 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index 1984833..d7d7d1c 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c | |||
| @@ -234,35 +234,6 @@ static int plist_strcmp(plist_t node, const char *str) | |||
| 234 | return ret; | 234 | return ret; |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | static plist_t device_link_message_factory_process_message_new(plist_t content) | ||
| 238 | { | ||
| 239 | plist_t ret = plist_new_array(); | ||
| 240 | plist_array_append_item(ret, plist_new_string("DLMessageProcessMessage")); | ||
| 241 | plist_array_append_item(ret, content); | ||
| 242 | return ret; | ||
| 243 | } | ||
| 244 | |||
| 245 | static void mobilebackup_cancel_backup_with_error(const char *reason) | ||
| 246 | { | ||
| 247 | plist_t node = plist_new_dict(); | ||
| 248 | plist_dict_insert_item(node, "BackupMessageTypeKey", plist_new_string("BackupMessageError")); | ||
| 249 | plist_dict_insert_item(node, "BackupErrorReasonKey", plist_new_string(reason)); | ||
| 250 | |||
| 251 | plist_t message = device_link_message_factory_process_message_new(node); | ||
| 252 | |||
| 253 | mobilebackup_send(mobilebackup, message); | ||
| 254 | |||
| 255 | plist_free(message); | ||
| 256 | message = NULL; | ||
| 257 | } | ||
| 258 | |||
| 259 | static plist_t mobilebackup_factory_backup_file_received_new() | ||
| 260 | { | ||
| 261 | plist_t node = plist_new_dict(); | ||
| 262 | plist_dict_insert_item(node, "BackupMessageTypeKey", plist_new_string("kBackupMessageBackupFileReceived")); | ||
| 263 | return device_link_message_factory_process_message_new(node); | ||
| 264 | } | ||
| 265 | |||
| 266 | static gchar *mobilebackup_build_path(const char *backup_directory, const char *name, const char *extension) | 237 | static gchar *mobilebackup_build_path(const char *backup_directory, const char *name, const char *extension) |
| 267 | { | 238 | { |
| 268 | gchar *filename = g_strconcat(name, extension, NULL); | 239 | gchar *filename = g_strconcat(name, extension, NULL); |
| @@ -650,54 +621,27 @@ int main(int argc, char *argv[]) | |||
| 650 | /* request backup from device with manifest from last backup */ | 621 | /* request backup from device with manifest from last backup */ |
| 651 | printf("Requesting backup from device...\n"); | 622 | printf("Requesting backup from device...\n"); |
| 652 | 623 | ||
| 653 | node = plist_new_dict(); | 624 | mobilebackup_error_t err = mobilebackup_request_backup(mobilebackup, manifest_plist, "/", "1.6"); |
| 654 | 625 | if (err == MOBILEBACKUP_E_SUCCESS) { | |
| 655 | if (manifest_plist) | 626 | if (is_full_backup) |
| 656 | plist_dict_insert_item(node, "BackupManifestKey", manifest_plist); | 627 | printf("Full backup mode.\n"); |
| 657 | 628 | else | |
| 658 | plist_dict_insert_item(node, "BackupComputerBasePathKey", plist_new_string("/")); | 629 | printf("Incremental backup mode.\n"); |
| 659 | plist_dict_insert_item(node, "BackupMessageTypeKey", plist_new_string("BackupMessageBackupRequest")); | 630 | printf("Please wait. Device is preparing backup data...\n"); |
| 660 | plist_dict_insert_item(node, "BackupProtocolVersion", plist_new_string("1.6")); | ||
| 661 | |||
| 662 | plist_t message = device_link_message_factory_process_message_new(node); | ||
| 663 | mobilebackup_send(mobilebackup, message); | ||
| 664 | plist_free(message); | ||
| 665 | message = NULL; | ||
| 666 | node = NULL; | ||
| 667 | |||
| 668 | /* get response */ | ||
| 669 | int backup_ok = 0; | ||
| 670 | mobilebackup_receive(mobilebackup, &message); | ||
| 671 | |||
| 672 | node = plist_array_get_item(message, 0); | ||
| 673 | if (!plist_strcmp(node, "DLMessageProcessMessage")) { | ||
| 674 | node = plist_array_get_item(message, 1); | ||
| 675 | node = plist_dict_get_item(node, "BackupMessageTypeKey"); | ||
| 676 | if (node && !plist_strcmp(node, "BackupMessageBackupReplyOK")) { | ||
| 677 | printf("Device accepts manifest and will send backup data now...\n"); | ||
| 678 | backup_ok = 1; | ||
| 679 | printf("Acknowledging...\n"); | ||
| 680 | if (is_full_backup) | ||
| 681 | printf("Full backup mode.\n"); | ||
| 682 | else | ||
| 683 | printf("Incremental backup mode.\n"); | ||
| 684 | printf("Please wait. Device prepares backup data...\n"); | ||
| 685 | /* send it back for ACK */ | ||
| 686 | mobilebackup_send(mobilebackup, message); | ||
| 687 | } | ||
| 688 | } else { | 631 | } else { |
| 689 | printf("ERROR: Unhandled message received!\n"); | 632 | if (err == MOBILEBACKUP_E_BAD_VERSION) { |
| 690 | } | 633 | printf("ERROR: Could not start backup process: backup protocol version mismatch!\n"); |
| 691 | plist_free(message); | 634 | } else if (err == MOBILEBACKUP_E_REPLY_NOT_OK) { |
| 692 | message = NULL; | 635 | printf("ERROR: Could not start backup process: device refused to start the backup process.\n"); |
| 693 | 636 | } else { | |
| 694 | if (!backup_ok) { | 637 | printf("ERROR: Could not start backup process: unspecified error occured\n"); |
| 695 | printf("ERROR: Device rejected to start the backup process.\n"); | 638 | } |
| 696 | break; | 639 | break; |
| 697 | } | 640 | } |
| 698 | 641 | ||
| 699 | /* reset backup status */ | 642 | /* reset backup status */ |
| 700 | backup_ok = 0; | 643 | int backup_ok = 0; |
| 644 | plist_t message = NULL; | ||
| 701 | 645 | ||
| 702 | /* receive and save DLSendFile files and metadata, ACK each */ | 646 | /* receive and save DLSendFile files and metadata, ACK each */ |
| 703 | int file_index = 0; | 647 | int file_index = 0; |
| @@ -836,15 +780,12 @@ int main(int argc, char *argv[]) | |||
| 836 | printf("DONE\n"); | 780 | printf("DONE\n"); |
| 837 | 781 | ||
| 838 | /* acknowlegdge that we received the file */ | 782 | /* acknowlegdge that we received the file */ |
| 839 | message = mobilebackup_factory_backup_file_received_new(); | 783 | mobilebackup_send_backup_file_received(mobilebackup); |
| 840 | mobilebackup_send(mobilebackup, message); | ||
| 841 | plist_free(message); | ||
| 842 | message = NULL; | ||
| 843 | } | 784 | } |
| 844 | 785 | ||
| 845 | if (quit_flag > 0) { | 786 | if (quit_flag > 0) { |
| 846 | /* need to cancel the backup here */ | 787 | /* need to cancel the backup here */ |
| 847 | mobilebackup_cancel_backup_with_error("Cancelling DLSendFile"); | 788 | mobilebackup_send_error(mobilebackup, "Cancelling DLSendFile"); |
| 848 | 789 | ||
| 849 | /* remove any atomic Manifest.plist.tmp */ | 790 | /* remove any atomic Manifest.plist.tmp */ |
| 850 | if (manifest_path) | 791 | if (manifest_path) |
