diff options
Diffstat (limited to 'src/mobilebackup.c')
| -rw-r--r-- | src/mobilebackup.c | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/src/mobilebackup.c b/src/mobilebackup.c index 209aee3..03d3920 100644 --- a/src/mobilebackup.c +++ b/src/mobilebackup.c | |||
| @@ -113,8 +113,11 @@ mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) | |||
| 113 | { | 113 | { |
| 114 | if (!client) | 114 | if (!client) |
| 115 | return MOBILEBACKUP_E_INVALID_ARG; | 115 | return MOBILEBACKUP_E_INVALID_ARG; |
| 116 | device_link_service_disconnect(client->parent); | 116 | mobilebackup_error_t err = MOBILEBACKUP_E_SUCCESS; |
| 117 | mobilebackup_error_t err = mobilebackup_error(device_link_service_client_free(client->parent)); | 117 | if (client->parent) { |
| 118 | device_link_service_disconnect(client->parent); | ||
| 119 | err = mobilebackup_error(device_link_service_client_free(client->parent)); | ||
| 120 | } | ||
| 118 | free(client); | 121 | free(client); |
| 119 | return err; | 122 | return err; |
| 120 | } | 123 | } |
| @@ -453,17 +456,59 @@ mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_cli | |||
| 453 | } | 456 | } |
| 454 | 457 | ||
| 455 | /** | 458 | /** |
| 456 | * Tells the device that the restore process is complete. | 459 | * Tells the device that the restore process is complete and waits for the |
| 460 | * device to close the connection. After that, the device should reboot. | ||
| 457 | * | 461 | * |
| 458 | * @param client The connected MobileBackup client to use. | 462 | * @param client The connected MobileBackup client to use. |
| 459 | * | 463 | * |
| 460 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | 464 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if |
| 461 | * client is invalid, or MOBILEBACKUP_E_MUX_ERROR if a communication error | 465 | * client is invalid, MOBILEBACKUP_E_PLIST_ERROR if the received disconnect |
| 462 | * occurs. | 466 | * message plist is invalid, or MOBILEBACKUP_E_MUX_ERROR if a communication |
| 467 | * error occurs. | ||
| 463 | */ | 468 | */ |
| 464 | mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client) | 469 | mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client) |
| 465 | { | 470 | { |
| 466 | return mobilebackup_send_message(client, "BackupMessageRestoreComplete", NULL); | 471 | mobilebackup_error_t err = mobilebackup_send_message(client, "BackupMessageRestoreComplete", NULL); |
| 472 | if (err != MOBILEBACKUP_E_SUCCESS) { | ||
| 473 | return err; | ||
| 474 | } | ||
| 475 | plist_t dlmsg = NULL; | ||
| 476 | err = mobilebackup_receive(client, &dlmsg); | ||
| 477 | if ((err != MOBILEBACKUP_E_SUCCESS) || !dlmsg || (plist_get_node_type(dlmsg) != PLIST_ARRAY) || (plist_array_get_size(dlmsg) != 2)) { | ||
| 478 | if (dlmsg) { | ||
| 479 | debug_info("ERROR: Did not receive DLMessageDisconnect:"); | ||
| 480 | debug_plist(dlmsg); | ||
| 481 | plist_free(dlmsg); | ||
| 482 | } | ||
| 483 | if (err == MOBILEBACKUP_E_SUCCESS) { | ||
| 484 | err = MOBILEBACKUP_E_PLIST_ERROR; | ||
| 485 | } | ||
| 486 | return err; | ||
| 487 | } | ||
| 488 | plist_t node = plist_array_get_item (dlmsg, 0); | ||
| 489 | char *msg = NULL; | ||
| 490 | if (node && (plist_get_node_type(node) == PLIST_STRING)) { | ||
| 491 | plist_get_string_val(node, &msg); | ||
| 492 | } | ||
| 493 | |||
| 494 | if (msg && !strcmp(msg, "DLMessageDisconnect")) { | ||
| 495 | err = MOBILEBACKUP_E_SUCCESS; | ||
| 496 | /* we need to do this here, otherwise mobilebackup_client_free | ||
| 497 | will fail */ | ||
| 498 | device_link_service_client_free(client->parent); | ||
| 499 | client->parent = NULL; | ||
| 500 | } else { | ||
| 501 | debug_info("ERROR: Malformed plist received:"); | ||
| 502 | debug_plist(dlmsg); | ||
| 503 | err = MOBILEBACKUP_E_PLIST_ERROR; | ||
| 504 | } | ||
| 505 | |||
| 506 | plist_free(dlmsg); | ||
| 507 | |||
| 508 | if (msg) | ||
| 509 | free(msg); | ||
| 510 | |||
| 511 | return err; | ||
| 467 | } | 512 | } |
| 468 | 513 | ||
| 469 | /** | 514 | /** |
