diff options
Diffstat (limited to 'include/libimobiledevice/mobilebackup.h')
| -rw-r--r-- | include/libimobiledevice/mobilebackup.h | 226 |
1 files changed, 200 insertions, 26 deletions
diff --git a/include/libimobiledevice/mobilebackup.h b/include/libimobiledevice/mobilebackup.h index 8f31cc4..2ecb60c 100644 --- a/include/libimobiledevice/mobilebackup.h +++ b/include/libimobiledevice/mobilebackup.h | |||
| @@ -3,7 +3,8 @@ | |||
| 3 | * @brief Backup and restore of all device data. | 3 | * @brief Backup and restore of all device data. |
| 4 | * \internal | 4 | * \internal |
| 5 | * | 5 | * |
| 6 | * Copyright (c) 2009 Martin Szulecki All Rights Reserved. | 6 | * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved. |
| 7 | * Copyright (c) 2009-2014 Martin Szulecki, All Rights Reserved. | ||
| 7 | * | 8 | * |
| 8 | * This library is free software; you can redistribute it and/or | 9 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public | 10 | * modify it under the terms of the GNU Lesser General Public |
| @@ -28,42 +29,215 @@ extern "C" { | |||
| 28 | #endif | 29 | #endif |
| 29 | 30 | ||
| 30 | #include <libimobiledevice/libimobiledevice.h> | 31 | #include <libimobiledevice/libimobiledevice.h> |
| 32 | #include <libimobiledevice/lockdown.h> | ||
| 31 | 33 | ||
| 32 | /** @name Error Codes */ | 34 | /** Service identifier passed to lockdownd_start_service() to start the mobilebackup service */ |
| 33 | /*@{*/ | 35 | #define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" |
| 34 | #define MOBILEBACKUP_E_SUCCESS 0 | ||
| 35 | #define MOBILEBACKUP_E_INVALID_ARG -1 | ||
| 36 | #define MOBILEBACKUP_E_PLIST_ERROR -2 | ||
| 37 | #define MOBILEBACKUP_E_MUX_ERROR -3 | ||
| 38 | #define MOBILEBACKUP_E_BAD_VERSION -4 | ||
| 39 | #define MOBILEBACKUP_E_REPLY_NOT_OK -5 | ||
| 40 | 36 | ||
| 41 | #define MOBILEBACKUP_E_UNKNOWN_ERROR -256 | 37 | /** Error Codes */ |
| 42 | /*@}*/ | 38 | typedef enum { |
| 43 | 39 | MOBILEBACKUP_E_SUCCESS = 0, | |
| 44 | /** Represents an error code. */ | 40 | MOBILEBACKUP_E_INVALID_ARG = -1, |
| 45 | typedef int16_t mobilebackup_error_t; | 41 | MOBILEBACKUP_E_PLIST_ERROR = -2, |
| 42 | MOBILEBACKUP_E_MUX_ERROR = -3, | ||
| 43 | MOBILEBACKUP_E_SSL_ERROR = -4, | ||
| 44 | MOBILEBACKUP_E_RECEIVE_TIMEOUT = -5, | ||
| 45 | MOBILEBACKUP_E_BAD_VERSION = -6, | ||
| 46 | MOBILEBACKUP_E_REPLY_NOT_OK = -7, | ||
| 47 | MOBILEBACKUP_E_UNKNOWN_ERROR = -256 | ||
| 48 | } mobilebackup_error_t; | ||
| 46 | 49 | ||
| 47 | typedef struct mobilebackup_client_private mobilebackup_client_private; | 50 | typedef struct mobilebackup_client_private mobilebackup_client_private; /**< \private */ |
| 48 | typedef mobilebackup_client_private *mobilebackup_client_t; /**< The client handle. */ | 51 | typedef mobilebackup_client_private *mobilebackup_client_t; /**< The client handle. */ |
| 49 | 52 | ||
| 53 | /** Available flags passed to #mobilebackup_request_restore */ | ||
| 50 | typedef enum { | 54 | typedef enum { |
| 51 | MB_RESTORE_NOTIFY_SPRINGBOARD = 1 << 0, | 55 | MB_RESTORE_NOTIFY_SPRINGBOARD = 1 << 0, |
| 52 | MB_RESTORE_PRESERVE_SETTINGS = 1 << 1, | 56 | MB_RESTORE_PRESERVE_SETTINGS = 1 << 1, |
| 53 | MB_RESTORE_PRESERVE_CAMERA_ROLL = 1 << 2 | 57 | MB_RESTORE_PRESERVE_CAMERA_ROLL = 1 << 2 |
| 54 | } mobilebackup_flags_t; | 58 | } mobilebackup_flags_t; |
| 55 | 59 | ||
| 56 | mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client); | 60 | /** |
| 57 | mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client); | 61 | * Connects to the mobilebackup service on the specified device. |
| 58 | mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t *plist); | 62 | * |
| 59 | mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist); | 63 | * @param device The device to connect to. |
| 60 | mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist_t backup_manifest, const char *base_path, const char *proto_version); | 64 | * @param service The service descriptor returned by lockdownd_start_service. |
| 61 | mobilebackup_error_t mobilebackup_send_backup_file_received(mobilebackup_client_t client); | 65 | * @param client Pointer that will be set to a newly allocated |
| 62 | mobilebackup_error_t mobilebackup_request_restore(mobilebackup_client_t client, plist_t backup_manifest, mobilebackup_flags_t flags, const char *proto_version); | 66 | * mobilebackup_client_t upon successful return. |
| 63 | mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_client_t client, plist_t *result); | 67 | * |
| 64 | mobilebackup_error_t mobilebackup_receive_restore_application_received(mobilebackup_client_t client, plist_t *result); | 68 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID ARG if one |
| 65 | mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client); | 69 | * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if |
| 66 | mobilebackup_error_t mobilebackup_send_error(mobilebackup_client_t client, const char *reason); | 70 | * the mobilebackup version on the device is newer. |
| 71 | */ | ||
| 72 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client); | ||
| 73 | |||
| 74 | /** | ||
| 75 | * Starts a new mobilebackup service on the specified device and connects to it. | ||
| 76 | * | ||
| 77 | * @param device The device to connect to. | ||
| 78 | * @param client Pointer that will point to a newly allocated | ||
| 79 | * mobilebackup_client_t upon successful return. Must be freed using | ||
| 80 | * mobilebackup_client_free() after use. | ||
| 81 | * @param label The label to use for communication. Usually the program name. | ||
| 82 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
| 83 | * | ||
| 84 | * @return MOBILEBACKUP_E_SUCCESS on success, or an MOBILEBACKUP_E_* error | ||
| 85 | * code otherwise. | ||
| 86 | */ | ||
| 87 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_start_service(idevice_t device, mobilebackup_client_t* client, const char* label); | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Disconnects a mobilebackup client from the device and frees up the | ||
| 91 | * mobilebackup client data. | ||
| 92 | * | ||
| 93 | * @param client The mobilebackup client to disconnect and free. | ||
| 94 | * | ||
| 95 | * @return MOBILEBACKUP_E_SUCCESS on success, or MOBILEBACKUP_E_INVALID_ARG | ||
| 96 | * if client is NULL. | ||
| 97 | */ | ||
| 98 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client); | ||
| 99 | |||
| 100 | |||
| 101 | /** | ||
| 102 | * Polls the device for mobilebackup data. | ||
| 103 | * | ||
| 104 | * @param client The mobilebackup client | ||
| 105 | * @param plist A pointer to the location where the plist should be stored | ||
| 106 | * | ||
| 107 | * @return an error code | ||
| 108 | */ | ||
| 109 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t *plist); | ||
| 110 | |||
| 111 | /** | ||
| 112 | * Sends mobilebackup data to the device | ||
| 113 | * | ||
| 114 | * @note This function is low-level and should only be used if you need to send | ||
| 115 | * a new type of message. | ||
| 116 | * | ||
| 117 | * @param client The mobilebackup client | ||
| 118 | * @param plist The location of the plist to send | ||
| 119 | * | ||
| 120 | * @return an error code | ||
| 121 | */ | ||
| 122 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist); | ||
| 123 | |||
| 124 | /** | ||
| 125 | * Request a backup from the connected device. | ||
| 126 | * | ||
| 127 | * @param client The connected MobileBackup client to use. | ||
| 128 | * @param backup_manifest The backup manifest, a plist_t of type PLIST_DICT | ||
| 129 | * containing the backup state of the last backup. For a first-time backup | ||
| 130 | * set this parameter to NULL. | ||
| 131 | * @param base_path The base path on the device to use for the backup | ||
| 132 | * operation, usually "/". | ||
| 133 | * @param proto_version A string denoting the version of the backup protocol | ||
| 134 | * to use. Latest known version is "1.6" | ||
| 135 | * | ||
| 136 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | ||
| 137 | * one of the parameters is invalid, MOBILEBACKUP_E_PLIST_ERROR if | ||
| 138 | * backup_manifest is not of type PLIST_DICT, MOBILEBACKUP_E_MUX_ERROR | ||
| 139 | * if a communication error occurs, MOBILEBACKUP_E_REPLY_NOT_OK | ||
| 140 | */ | ||
| 141 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist_t backup_manifest, const char *base_path, const char *proto_version); | ||
| 142 | |||
| 143 | /** | ||
| 144 | * Sends a confirmation to the device that a backup file has been received. | ||
| 145 | * | ||
| 146 | * @param client The connected MobileBackup client to use. | ||
| 147 | * | ||
| 148 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | ||
| 149 | * client is invalid, or MOBILEBACKUP_E_MUX_ERROR if a communication error | ||
| 150 | * occurs. | ||
| 151 | */ | ||
| 152 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send_backup_file_received(mobilebackup_client_t client); | ||
| 153 | |||
| 154 | /** | ||
| 155 | * Request that a backup should be restored to the connected device. | ||
| 156 | * | ||
| 157 | * @param client The connected MobileBackup client to use. | ||
| 158 | * @param backup_manifest The backup manifest, a plist_t of type PLIST_DICT | ||
| 159 | * containing the backup state to be restored. | ||
| 160 | * @param flags Flags to send with the request. Currently this is a combination | ||
| 161 | * of the following mobilebackup_flags_t: | ||
| 162 | * MB_RESTORE_NOTIFY_SPRINGBOARD - let SpringBoard show a 'Restore' screen | ||
| 163 | * MB_RESTORE_PRESERVE_SETTINGS - do not overwrite any settings | ||
| 164 | * MB_RESTORE_PRESERVE_CAMERA_ROLL - preserve the photos of the camera roll | ||
| 165 | * @param proto_version A string denoting the version of the backup protocol | ||
| 166 | * to use. Latest known version is "1.6". Ideally this value should be | ||
| 167 | * extracted from the given manifest plist. | ||
| 168 | * | ||
| 169 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | ||
| 170 | * one of the parameters is invalid, MOBILEBACKUP_E_PLIST_ERROR if | ||
| 171 | * backup_manifest is not of type PLIST_DICT, MOBILEBACKUP_E_MUX_ERROR | ||
| 172 | * if a communication error occurs, or MOBILEBACKUP_E_REPLY_NOT_OK | ||
| 173 | * if the device did not accept the request. | ||
| 174 | */ | ||
| 175 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_request_restore(mobilebackup_client_t client, plist_t backup_manifest, mobilebackup_flags_t flags, const char *proto_version); | ||
| 176 | |||
| 177 | /** | ||
| 178 | * Receive a confirmation from the device that it successfully received | ||
| 179 | * a restore file. | ||
| 180 | * | ||
| 181 | * @param client The connected MobileBackup client to use. | ||
| 182 | * @param result Pointer to a plist_t that will be set to the received plist | ||
| 183 | * for further processing. The caller has to free it using plist_free(). | ||
| 184 | * Note that it will be set to NULL if the operation itself fails due to | ||
| 185 | * a communication or plist error. | ||
| 186 | * If this parameter is NULL, it will be ignored. | ||
| 187 | * | ||
| 188 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | ||
| 189 | * client is invalid, MOBILEBACKUP_E_REPLY_NOT_OK if the expected | ||
| 190 | * 'BackupMessageRestoreFileReceived' message could not be received, | ||
| 191 | * MOBILEBACKUP_E_PLIST_ERROR if the received message is not a valid backup | ||
| 192 | * message plist, or MOBILEBACKUP_E_MUX_ERROR if a communication error | ||
| 193 | * occurs. | ||
| 194 | */ | ||
| 195 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_client_t client, plist_t *result); | ||
| 196 | |||
| 197 | /** | ||
| 198 | * Receive a confirmation from the device that it successfully received | ||
| 199 | * application data file. | ||
| 200 | * | ||
| 201 | * @param client The connected MobileBackup client to use. | ||
| 202 | * @param result Pointer to a plist_t that will be set to the received plist | ||
| 203 | * for further processing. The caller has to free it using plist_free(). | ||
| 204 | * Note that it will be set to NULL if the operation itself fails due to | ||
| 205 | * a communication or plist error. | ||
| 206 | * If this parameter is NULL, it will be ignored. | ||
| 207 | * | ||
| 208 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | ||
| 209 | * client is invalid, MOBILEBACKUP_E_REPLY_NOT_OK if the expected | ||
| 210 | * 'BackupMessageRestoreApplicationReceived' message could not be received, | ||
| 211 | * MOBILEBACKUP_E_PLIST_ERROR if the received message is not a valid backup | ||
| 212 | * message plist, or MOBILEBACKUP_E_MUX_ERROR if a communication error | ||
| 213 | * occurs. | ||
| 214 | */ | ||
| 215 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_receive_restore_application_received(mobilebackup_client_t client, plist_t *result); | ||
| 216 | |||
| 217 | /** | ||
| 218 | * Tells the device that the restore process is complete and waits for the | ||
| 219 | * device to close the connection. After that, the device should reboot. | ||
| 220 | * | ||
| 221 | * @param client The connected MobileBackup client to use. | ||
| 222 | * | ||
| 223 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | ||
| 224 | * client is invalid, MOBILEBACKUP_E_PLIST_ERROR if the received disconnect | ||
| 225 | * message plist is invalid, or MOBILEBACKUP_E_MUX_ERROR if a communication | ||
| 226 | * error occurs. | ||
| 227 | */ | ||
| 228 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client); | ||
| 229 | |||
| 230 | /** | ||
| 231 | * Sends a backup error message to the device. | ||
| 232 | * | ||
| 233 | * @param client The connected MobileBackup client to use. | ||
| 234 | * @param reason A string describing the reason for the error message. | ||
| 235 | * | ||
| 236 | * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if | ||
| 237 | * one of the parameters is invalid, or MOBILEBACKUP_E_MUX_ERROR if a | ||
| 238 | * communication error occurs. | ||
| 239 | */ | ||
| 240 | LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send_error(mobilebackup_client_t client, const char *reason); | ||
| 67 | 241 | ||
| 68 | #ifdef __cplusplus | 242 | #ifdef __cplusplus |
| 69 | } | 243 | } |
