summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/mobilebackup2.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/mobilebackup2.h')
-rw-r--r--include/libimobiledevice/mobilebackup2.h214
1 files changed, 214 insertions, 0 deletions
diff --git a/include/libimobiledevice/mobilebackup2.h b/include/libimobiledevice/mobilebackup2.h
new file mode 100644
index 0000000..2e9222d
--- /dev/null
+++ b/include/libimobiledevice/mobilebackup2.h
@@ -0,0 +1,214 @@
1/**
2 * @file libimobiledevice/mobilebackup2.h
3 * @brief Backup and restore of all device data (mobilebackup2, iOS4+ only)
4 * \internal
5 *
6 * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved.
7 * Copyright (c) 2011-2014 Martin Szulecki, All Rights Reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef IMOBILEBACKUP2_H
25#define IMOBILEBACKUP2_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include <libimobiledevice/libimobiledevice.h>
32#include <libimobiledevice/lockdown.h>
33
34/** Service identifier passed to lockdownd_start_service() to start the mobilebackup2 service */
35#define MOBILEBACKUP2_SERVICE_NAME "com.apple.mobilebackup2"
36
37/** Error Codes */
38typedef enum {
39 MOBILEBACKUP2_E_SUCCESS = 0,
40 MOBILEBACKUP2_E_INVALID_ARG = -1,
41 MOBILEBACKUP2_E_PLIST_ERROR = -2,
42 MOBILEBACKUP2_E_MUX_ERROR = -3,
43 MOBILEBACKUP2_E_SSL_ERROR = -4,
44 MOBILEBACKUP2_E_RECEIVE_TIMEOUT = -5,
45 MOBILEBACKUP2_E_BAD_VERSION = -6,
46 MOBILEBACKUP2_E_REPLY_NOT_OK = -7,
47 MOBILEBACKUP2_E_NO_COMMON_VERSION = -8,
48 MOBILEBACKUP2_E_UNKNOWN_ERROR = -256
49} mobilebackup2_error_t;
50
51typedef struct mobilebackup2_client_private mobilebackup2_client_private; /**< \private */
52typedef mobilebackup2_client_private *mobilebackup2_client_t; /**< The client handle. */
53
54
55/**
56 * Connects to the mobilebackup2 service on the specified device.
57 *
58 * @param device The device to connect to.
59 * @param service The service descriptor returned by lockdownd_start_service.
60 * @param client Pointer that will be set to a newly allocated
61 * mobilebackup2_client_t upon successful return.
62 *
63 * @return MOBILEBACKUP2_E_SUCCESS on success, MOBILEBACKUP2_E_INVALID ARG
64 * if one or more parameter is invalid, or MOBILEBACKUP2_E_BAD_VERSION
65 * if the mobilebackup2 version on the device is newer.
66 */
67LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup2_client_t * client);
68
69/**
70 * Starts a new mobilebackup2 service on the specified device and connects to it.
71 *
72 * @param device The device to connect to.
73 * @param client Pointer that will point to a newly allocated
74 * mobilebackup2_client_t upon successful return. Must be freed using
75 * mobilebackup2_client_free() after use.
76 * @param label The label to use for communication. Usually the program name.
77 * Pass NULL to disable sending the label in requests to lockdownd.
78 *
79 * @return MOBILEBACKUP2_E_SUCCESS on success, or an MOBILEBACKUP2_E_* error
80 * code otherwise.
81 */
82LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_start_service(idevice_t device, mobilebackup2_client_t* client, const char* label);
83
84/**
85 * Disconnects a mobilebackup2 client from the device and frees up the
86 * mobilebackup2 client data.
87 *
88 * @param client The mobilebackup2 client to disconnect and free.
89 *
90 * @return MOBILEBACKUP2_E_SUCCESS on success, or MOBILEBACKUP2_E_INVALID_ARG
91 * if client is NULL.
92 */
93LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client);
94
95
96/**
97 * Sends a backup message plist.
98 *
99 * @param client The connected MobileBackup client to use.
100 * @param message The message to send. This will be inserted into the request
101 * plist as value for MessageName. If this parameter is NULL,
102 * the plist passed in the options parameter will be sent directly.
103 * @param options Additional options as PLIST_DICT to add to the request.
104 * The MessageName key with the value passed in the message parameter
105 * will be inserted into this plist before sending it. This parameter
106 * can be NULL if message is not NULL.
107 */
108LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options);
109
110/**
111 * Receives a DL* message plist from the device.
112 * This function is a wrapper around device_link_service_receive_message.
113 *
114 * @param client The connected MobileBackup client to use.
115 * @param msg_plist Pointer to a plist that will be set to the contents of the
116 * message plist upon successful return.
117 * @param dlmessage A pointer that will be set to a newly allocated char*
118 * containing the DL* string from the given plist. It is up to the caller
119 * to free the allocated memory. If this parameter is NULL
120 * it will be ignored.
121 *
122 * @return MOBILEBACKUP2_E_SUCCESS if a DL* message was received,
123 * MOBILEBACKUP2_E_INVALID_ARG if client or message is invalid,
124 * MOBILEBACKUP2_E_PLIST_ERROR if the received plist is invalid
125 * or is not a DL* message plist, or MOBILEBACKUP2_E_MUX_ERROR if
126 * receiving from the device failed.
127 */
128LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage);
129
130/**
131 * Send binary data to the device.
132 *
133 * @note This function returns MOBILEBACKUP2_E_SUCCESS even if less than the
134 * requested length has been sent. The fourth parameter is required and
135 * must be checked to ensure if the whole data has been sent.
136 *
137 * @param client The MobileBackup client to send to.
138 * @param data Pointer to the data to send
139 * @param length Number of bytes to send
140 * @param bytes Number of bytes actually sent
141 *
142 * @return MOBILEBACKUP2_E_SUCCESS if any data was successfully sent,
143 * MOBILEBACKUP2_E_INVALID_ARG if one of the parameters is invalid,
144 * or MOBILEBACKUP2_E_MUX_ERROR if sending of the data failed.
145 */
146LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes);
147
148/**
149 * Receive binary from the device.
150 *
151 * @note This function returns MOBILEBACKUP2_E_SUCCESS even if no data
152 * has been received (unless a communication error occurred).
153 * The fourth parameter is required and must be checked to know how
154 * many bytes were actually received.
155 *
156 * @param client The MobileBackup client to receive from.
157 * @param data Pointer to a buffer that will be filled with the received data.
158 * @param length Number of bytes to receive. The data buffer needs to be large
159 * enough to store this amount of data.
160 * @param bytes Number of bytes actually received.
161 *
162 * @return MOBILEBACKUP2_E_SUCCESS if any or no data was received,
163 * MOBILEBACKUP2_E_INVALID_ARG if one of the parameters is invalid,
164 * or MOBILEBACKUP2_E_MUX_ERROR if receiving the data failed.
165 */
166LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes);
167
168/**
169 * Performs the mobilebackup2 protocol version exchange.
170 *
171 * @param client The MobileBackup client to use.
172 * @param local_versions An array of supported versions to send to the remote.
173 * @param count The number of items in local_versions.
174 * @param remote_version Holds the protocol version of the remote on success.
175 *
176 * @return MOBILEBACKUP2_E_SUCCESS on success, or a MOBILEBACKUP2_E_* error
177 * code otherwise.
178 */
179LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version);
180
181/**
182 * Send a request to the connected mobilebackup2 service.
183 *
184 * @param client
185 * @param request The request to send to the backup service.
186 * Currently, this is one of "Backup", "Restore", "Info", or "List".
187 * @param target_identifier UDID of the target device.
188 * @param source_identifier UDID of backup data?
189 * @param options Additional options in a plist of type PLIST_DICT.
190 *
191 * @return MOBILEBACKUP2_E_SUCCESS if the request was successfully sent,
192 * or a MOBILEBACKUP2_E_* error value otherwise.
193 */
194LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options);
195
196/**
197 * Sends a DLMessageStatusResponse to the device.
198 *
199 * @param client The MobileBackup client to use.
200 * @param status_code The status code to send.
201 * @param status1 A status message to send. Can be NULL if not required.
202 * @param status2 An additional status plist to attach to the response.
203 * Can be NULL if not required.
204 *
205 * @return MOBILEBACKUP2_E_SUCCESS on success, MOBILEBACKUP2_E_INVALID_ARG
206 * if client is invalid, or another MOBILEBACKUP2_E_* otherwise.
207 */
208LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2);
209
210#ifdef __cplusplus
211}
212#endif
213
214#endif