diff options
Diffstat (limited to 'include/libimobiledevice/mobilesync.h')
-rw-r--r-- | include/libimobiledevice/mobilesync.h | 342 |
1 files changed, 299 insertions, 43 deletions
diff --git a/include/libimobiledevice/mobilesync.h b/include/libimobiledevice/mobilesync.h index 7658b7d..c3bc53d 100644 --- a/include/libimobiledevice/mobilesync.h +++ b/include/libimobiledevice/mobilesync.h | |||
@@ -3,6 +3,9 @@ | |||
3 | * @brief Synchronize data classes with a device and computer. | 3 | * @brief Synchronize data classes with a device and computer. |
4 | * \internal | 4 | * \internal |
5 | * | 5 | * |
6 | * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved. | ||
7 | * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved. | ||
8 | * Copyright (c) 2014 Christophe Fergeau All Rights Reserved. | ||
6 | * Copyright (c) 2010 Bryan Forbes All Rights Reserved. | 9 | * Copyright (c) 2010 Bryan Forbes All Rights Reserved. |
7 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | 10 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. |
8 | * | 11 | * |
@@ -29,22 +32,26 @@ extern "C" { | |||
29 | #endif | 32 | #endif |
30 | 33 | ||
31 | #include <libimobiledevice/libimobiledevice.h> | 34 | #include <libimobiledevice/libimobiledevice.h> |
32 | #include <glib.h> | 35 | #include <libimobiledevice/lockdown.h> |
33 | 36 | ||
34 | /** @name Error Codes */ | 37 | /** Service identifier passed to lockdownd_start_service() to start the mobilesync service */ |
35 | /*@{*/ | 38 | #define MOBILESYNC_SERVICE_NAME "com.apple.mobilesync" |
36 | #define MOBILESYNC_E_SUCCESS 0 | 39 | |
37 | #define MOBILESYNC_E_INVALID_ARG -1 | 40 | /** Error Codes */ |
38 | #define MOBILESYNC_E_PLIST_ERROR -2 | 41 | typedef enum { |
39 | #define MOBILESYNC_E_MUX_ERROR -3 | 42 | MOBILESYNC_E_SUCCESS = 0, |
40 | #define MOBILESYNC_E_BAD_VERSION -4 | 43 | MOBILESYNC_E_INVALID_ARG = -1, |
41 | #define MOBILESYNC_E_SYNC_REFUSED -5 | 44 | MOBILESYNC_E_PLIST_ERROR = -2, |
42 | #define MOBILESYNC_E_CANCELLED -6 | 45 | MOBILESYNC_E_MUX_ERROR = -3, |
43 | #define MOBILESYNC_E_WRONG_DIRECTION -7 | 46 | MOBILESYNC_E_SSL_ERROR = -4, |
44 | #define MOBILESYNC_E_NOT_READY -8 | 47 | MOBILESYNC_E_RECEIVE_TIMEOUT = -5, |
45 | 48 | MOBILESYNC_E_BAD_VERSION = -6, | |
46 | #define MOBILESYNC_E_UNKNOWN_ERROR -256 | 49 | MOBILESYNC_E_SYNC_REFUSED = -7, |
47 | /*@}*/ | 50 | MOBILESYNC_E_CANCELLED = -8, |
51 | MOBILESYNC_E_WRONG_DIRECTION = -9, | ||
52 | MOBILESYNC_E_NOT_READY = -10, | ||
53 | MOBILESYNC_E_UNKNOWN_ERROR = -256 | ||
54 | } mobilesync_error_t; | ||
48 | 55 | ||
49 | /** The sync type of the current sync session. */ | 56 | /** The sync type of the current sync session. */ |
50 | typedef enum { | 57 | typedef enum { |
@@ -53,48 +60,297 @@ typedef enum { | |||
53 | MOBILESYNC_SYNC_TYPE_RESET /**< Reset-sync signals that the computer should send all data again. */ | 60 | MOBILESYNC_SYNC_TYPE_RESET /**< Reset-sync signals that the computer should send all data again. */ |
54 | } mobilesync_sync_type_t; | 61 | } mobilesync_sync_type_t; |
55 | 62 | ||
56 | /** Represents an error code. */ | 63 | typedef struct mobilesync_client_private mobilesync_client_private; /**< \private */ |
57 | typedef int16_t mobilesync_error_t; | ||
58 | |||
59 | typedef struct mobilesync_client_private mobilesync_client_private; | ||
60 | typedef mobilesync_client_private *mobilesync_client_t; /**< The client handle */ | 64 | typedef mobilesync_client_private *mobilesync_client_t; /**< The client handle */ |
61 | 65 | ||
66 | /** Anchors used by the device and computer (structure) */ | ||
62 | typedef struct { | 67 | typedef struct { |
63 | char *device_anchor; | 68 | char *device_anchor; /**< device anchor */ |
64 | char *computer_anchor; | 69 | char *computer_anchor; /**< computer anchor */ |
65 | } mobilesync_anchors; | 70 | } mobilesync_anchors; |
66 | typedef mobilesync_anchors *mobilesync_anchors_t; /**< Anchors used by the device and computer. */ | 71 | /** Anchors used by the device and computer */ |
72 | typedef mobilesync_anchors *mobilesync_anchors_t; | ||
67 | 73 | ||
68 | /* Interface */ | 74 | /* Interface */ |
69 | mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client); | ||
70 | mobilesync_error_t mobilesync_client_free(mobilesync_client_t client); | ||
71 | 75 | ||
72 | mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t *plist); | 76 | /** |
73 | mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist); | 77 | * Connects to the mobilesync service on the specified device. |
78 | * | ||
79 | * @param device The device to connect to. | ||
80 | * @param service The service descriptor returned by lockdownd_start_service. | ||
81 | * @param client Pointer that will be set to a newly allocated | ||
82 | * #mobilesync_client_t upon successful return. | ||
83 | * | ||
84 | * @retval MOBILESYNC_E_SUCCESS on success | ||
85 | * @retval MOBILESYNC_E_INVALID_ARG if one or more parameters are invalid | ||
86 | * @retval DEVICE_LINK_SERVICE_E_BAD_VERSION if the mobilesync version on | ||
87 | * the device is newer. | ||
88 | */ | ||
89 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilesync_client_t * client); | ||
90 | |||
91 | /** | ||
92 | * Starts a new mobilesync service on the specified device and connects to it. | ||
93 | * | ||
94 | * @param device The device to connect to. | ||
95 | * @param client Pointer that will point to a newly allocated | ||
96 | * mobilesync_client_t upon successful return. Must be freed using | ||
97 | * mobilesync_client_free() after use. | ||
98 | * @param label The label to use for communication. Usually the program name. | ||
99 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
100 | * | ||
101 | * @return MOBILESYNC_E_SUCCESS on success, or an MOBILESYNC_E_* error | ||
102 | * code otherwise. | ||
103 | */ | ||
104 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_start_service(idevice_t device, mobilesync_client_t* client, const char* label); | ||
105 | |||
106 | /** | ||
107 | * Disconnects a mobilesync client from the device and frees up the | ||
108 | * mobilesync client data. | ||
109 | * | ||
110 | * @param client The mobilesync client to disconnect and free. | ||
111 | * | ||
112 | * @retval MOBILESYNC_E_SUCCESS on success | ||
113 | * @retval MOBILESYNC_E_INVALID_ARG if \a client is NULL. | ||
114 | */ | ||
115 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_free(mobilesync_client_t client); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Polls the device for mobilesync data. | ||
120 | * | ||
121 | * @param client The mobilesync client | ||
122 | * @param plist A pointer to the location where the plist should be stored | ||
123 | * | ||
124 | * @return an error code | ||
125 | */ | ||
126 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t *plist); | ||
127 | |||
128 | /** | ||
129 | * Sends mobilesync data to the device | ||
130 | * | ||
131 | * @note This function is low-level and should only be used if you need to send | ||
132 | * a new type of message. | ||
133 | * | ||
134 | * @param client The mobilesync client | ||
135 | * @param plist The location of the plist to send | ||
136 | * | ||
137 | * @return an error code | ||
138 | */ | ||
139 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist); | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Requests starting synchronization of a data class with the device | ||
144 | * | ||
145 | * @param client The mobilesync client | ||
146 | * @param data_class The data class identifier to sync | ||
147 | * @param anchors The anchors required to exchange with the device. The anchors | ||
148 | * allow the device to tell if the synchronization information on the computer | ||
149 | * and device are consistent to determine what sync type is required. | ||
150 | * @param computer_data_class_version The version of the data class storage on the computer | ||
151 | * @param sync_type A pointer to store the sync type reported by the device_anchor | ||
152 | * @param device_data_class_version The version of the data class storage on the device | ||
153 | * @param error_description A pointer to store an error message if reported by the device | ||
154 | * | ||
155 | * @retval MOBILESYNC_E_SUCCESS on success | ||
156 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
157 | * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form | ||
158 | * @retval MOBILESYNC_E_SYNC_REFUSED if the device refused to sync | ||
159 | * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the | ||
160 | * sync request | ||
161 | */ | ||
162 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version, char** error_description); | ||
163 | |||
164 | /** | ||
165 | * Cancels a running synchronization session with a device at any time. | ||
166 | * | ||
167 | * @param client The mobilesync client | ||
168 | * @param reason The reason to supply to the device for cancelling | ||
169 | * | ||
170 | * @retval MOBILESYNC_E_SUCCESS on success | ||
171 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
172 | */ | ||
173 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason); | ||
174 | |||
175 | /** | ||
176 | * Finish a synchronization session of a data class on the device. | ||
177 | * A session must have previously been started using mobilesync_start(). | ||
178 | * | ||
179 | * @param client The mobilesync client | ||
180 | * | ||
181 | * @retval MOBILESYNC_E_SUCCESS on success | ||
182 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
183 | * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid | ||
184 | * form | ||
185 | */ | ||
186 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_finish(mobilesync_client_t client); | ||
187 | |||
188 | |||
189 | /** | ||
190 | * Requests to receive all records of the currently set data class from the device. | ||
191 | * The actually changes are retrieved using mobilesync_receive_changes() after this | ||
192 | * request has been successful. | ||
193 | * | ||
194 | * @param client The mobilesync client | ||
195 | * | ||
196 | * @retval MOBILESYNC_E_SUCCESS on success | ||
197 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
198 | */ | ||
199 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client); | ||
200 | |||
201 | /** | ||
202 | * Requests to receive only changed records of the currently set data class from the device. | ||
203 | * The actually changes are retrieved using mobilesync_receive_changes() after this | ||
204 | * request has been successful. | ||
205 | * | ||
206 | * @param client The mobilesync client | ||
207 | * | ||
208 | * @retval MOBILESYNC_E_SUCCESS on success | ||
209 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
210 | */ | ||
211 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client); | ||
212 | |||
213 | /** | ||
214 | * Requests the device to delete all records of the current data class | ||
215 | * | ||
216 | * @note The operation must be called after starting synchronization. | ||
217 | * | ||
218 | * @param client The mobilesync client | ||
219 | * | ||
220 | * @retval MOBILESYNC_E_SUCCESS on success | ||
221 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
222 | * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form | ||
223 | */ | ||
224 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client); | ||
74 | 225 | ||
75 | mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version); | ||
76 | mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason); | ||
77 | mobilesync_error_t mobilesync_finish(mobilesync_client_t client); | ||
78 | 226 | ||
79 | mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client); | 227 | /** |
80 | mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client); | 228 | * Receives changed entitites of the currently set data class from the device |
81 | mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client); | 229 | * |
230 | * @param client The mobilesync client | ||
231 | * @param entities A pointer to store the changed entity records as a PLIST_DICT | ||
232 | * @param is_last_record A pointer to store a flag indicating if this submission is the last one | ||
233 | * @param actions A pointer to additional flags the device is sending or NULL to ignore | ||
234 | * | ||
235 | * @retval MOBILESYNC_E_SUCCESS on success | ||
236 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
237 | * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the | ||
238 | * session | ||
239 | */ | ||
240 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions); | ||
241 | |||
242 | /** | ||
243 | * Acknowledges to the device that the changes have been merged on the computer | ||
244 | * | ||
245 | * @param client The mobilesync client | ||
246 | * | ||
247 | * @retval MOBILESYNC_E_SUCCESS on success | ||
248 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
249 | */ | ||
250 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client); | ||
82 | 251 | ||
83 | mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions); | ||
84 | mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client); | ||
85 | 252 | ||
86 | mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client); | 253 | /** |
254 | * Verifies if the device is ready to receive changes from the computer. | ||
255 | * This call changes the synchronization direction so that mobilesync_send_changes() | ||
256 | * can be used to send changes to the device. | ||
257 | * | ||
258 | * @param client The mobilesync client | ||
259 | * | ||
260 | * @retval MOBILESYNC_E_SUCCESS on success | ||
261 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
262 | * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid form | ||
263 | * @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does | ||
264 | * not permit this call | ||
265 | * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the | ||
266 | * session | ||
267 | * @retval MOBILESYNC_E_NOT_READY if the device is not ready to start | ||
268 | * receiving any changes | ||
269 | */ | ||
270 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client); | ||
271 | |||
272 | |||
273 | /** | ||
274 | * Sends changed entities of the currently set data class to the device | ||
275 | * | ||
276 | * @param client The mobilesync client | ||
277 | * @param entities The changed entity records as a PLIST_DICT | ||
278 | * @param is_last_record A flag indicating if this submission is the last one | ||
279 | * @param actions Additional actions for the device created with mobilesync_actions_new() | ||
280 | * or NULL if no actions should be passed | ||
281 | * | ||
282 | * @retval MOBILESYNC_E_SUCCESS on success | ||
283 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid, | ||
284 | * @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does | ||
285 | * not permit this call | ||
286 | */ | ||
287 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions); | ||
87 | 288 | ||
88 | mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions); | 289 | /** |
89 | mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping); | 290 | * Receives any remapped identifiers reported after the device merged submitted changes. |
291 | * | ||
292 | * @param client The mobilesync client | ||
293 | * @param mapping A pointer to an array plist containing a dict of identifier remappings | ||
294 | * | ||
295 | * @retval MOBILESYNC_E_SUCCESS on success | ||
296 | * @retval MOBILESYNC_E_INVALID_ARG if one of the parameters is invalid | ||
297 | * @retval MOBILESYNC_E_PLIST_ERROR if the received plist is not of valid | ||
298 | * form | ||
299 | * @retval MOBILESYNC_E_WRONG_DIRECTION if the current sync direction does | ||
300 | * not permit this call | ||
301 | * @retval MOBILESYNC_E_CANCELLED if the device explicitly cancelled the | ||
302 | * session | ||
303 | */ | ||
304 | LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping); | ||
90 | 305 | ||
91 | /* Helper */ | 306 | /* Helper */ |
92 | mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor); | ||
93 | void mobilesync_anchors_free(mobilesync_anchors_t anchors); | ||
94 | 307 | ||
95 | plist_t mobilesync_actions_new(); | 308 | /** |
96 | void mobilesync_actions_add(plist_t actions, ...) G_GNUC_NULL_TERMINATED; | 309 | * Allocates memory for a new anchors struct initialized with the passed anchors. |
97 | void mobilesync_actions_free(plist_t actions); | 310 | * |
311 | * @param device_anchor An anchor the device reported the last time or NULL | ||
312 | * if none is known yet which for instance is true on first synchronization. | ||
313 | * @param computer_anchor An arbitrary string to use as anchor for the computer. | ||
314 | * | ||
315 | * @return A new #mobilesync_anchors_t struct. Must be freed using mobilesync_anchors_free(). | ||
316 | */ | ||
317 | LIBIMOBILEDEVICE_API mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor); | ||
318 | |||
319 | /** | ||
320 | * Free memory used by anchors. | ||
321 | * | ||
322 | * @param anchors The anchors to free. | ||
323 | */ | ||
324 | LIBIMOBILEDEVICE_API void mobilesync_anchors_free(mobilesync_anchors_t anchors); | ||
325 | |||
326 | |||
327 | /** | ||
328 | * Create a new actions plist to use in mobilesync_send_changes(). | ||
329 | * | ||
330 | * @return A new plist_t of type PLIST_DICT. | ||
331 | */ | ||
332 | LIBIMOBILEDEVICE_API plist_t mobilesync_actions_new(void); | ||
333 | |||
334 | /** | ||
335 | * Add one or more new key:value pairs to the given actions plist. | ||
336 | * | ||
337 | * @param actions The actions to modify. | ||
338 | * @param ... KEY, VALUE, [KEY, VALUE], NULL | ||
339 | * | ||
340 | * @note The known keys so far are "SyncDeviceLinkEntityNamesKey" which expects | ||
341 | * an array of entity names, followed by a count paramter as well as | ||
342 | * "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey" which expects an | ||
343 | * integer to use as a boolean value indicating that the device should | ||
344 | * link submitted changes and report remapped identifiers. | ||
345 | */ | ||
346 | LIBIMOBILEDEVICE_API void mobilesync_actions_add(plist_t actions, ...); | ||
347 | |||
348 | /** | ||
349 | * Free actions plist. | ||
350 | * | ||
351 | * @param actions The actions plist to free. Does nothing if NULL is passed. | ||
352 | */ | ||
353 | LIBIMOBILEDEVICE_API void mobilesync_actions_free(plist_t actions); | ||
98 | 354 | ||
99 | #ifdef __cplusplus | 355 | #ifdef __cplusplus |
100 | } | 356 | } |