summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2011-04-27 14:58:45 +0200
committerGravatar Martin Szulecki2011-04-27 14:58:45 +0200
commit88a5b03233ad95a0ccb3449a656f637ccde453ce (patch)
tree253db1c1d8c63534be0cbccf21da9858dd131518
parentcaca63af9b0e78eb302ec290b7cbebed7afb2589 (diff)
downloadlibimobiledevice-88a5b03233ad95a0ccb3449a656f637ccde453ce.tar.gz
libimobiledevice-88a5b03233ad95a0ccb3449a656f637ccde453ce.tar.bz2
mobilebackup2: Finish mobilebackup2_version_exchange() and use it in idevicebackup2
-rw-r--r--include/libimobiledevice/mobilebackup2.h3
-rw-r--r--src/mobilebackup2.c34
-rw-r--r--tools/idevicebackup2.c6
3 files changed, 26 insertions, 17 deletions
diff --git a/include/libimobiledevice/mobilebackup2.h b/include/libimobiledevice/mobilebackup2.h
index a58dc00..5d695e9 100644
--- a/include/libimobiledevice/mobilebackup2.h
+++ b/include/libimobiledevice/mobilebackup2.h
@@ -37,6 +37,7 @@ extern "C" {
37#define MOBILEBACKUP2_E_MUX_ERROR -3 37#define MOBILEBACKUP2_E_MUX_ERROR -3
38#define MOBILEBACKUP2_E_BAD_VERSION -4 38#define MOBILEBACKUP2_E_BAD_VERSION -4
39#define MOBILEBACKUP2_E_REPLY_NOT_OK -5 39#define MOBILEBACKUP2_E_REPLY_NOT_OK -5
40#define MOBILEBACKUP2_E_NO_COMMON_VERSION -6
40 41
41#define MOBILEBACKUP2_E_UNKNOWN_ERROR -256 42#define MOBILEBACKUP2_E_UNKNOWN_ERROR -256
42/*@}*/ 43/*@}*/
@@ -52,7 +53,7 @@ mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client);
52mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage); 53mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage);
53mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes); 54mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes);
54mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes); 55mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes);
55mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client); 56mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version);
56mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options); 57mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options);
57mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2); 58mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2);
58 59
diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c
index ae7ac03..a595b01 100644
--- a/src/mobilebackup2.c
+++ b/src/mobilebackup2.c
@@ -346,20 +346,26 @@ mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, c
346/** 346/**
347 * Performs the mobilebackup2 protocol version exchange. 347 * Performs the mobilebackup2 protocol version exchange.
348 * 348 *
349 * @param The MobileBackup client to use. 349 * @param client The MobileBackup client to use.
350 * @param local_versions An array of supported versions to send to the remote.
351 * @param count The number of items in local_versions.
352 * @param remote_version Holds the protocol version of the remote on success.
350 * 353 *
351 * @return MOBILEBACKUP2_E_SUCCESS on success, or a MOBILEBACKUP2_E_* error 354 * @return MOBILEBACKUP2_E_SUCCESS on success, or a MOBILEBACKUP2_E_* error
352 * code otherwise. 355 * code otherwise.
353 */ 356 */
354mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client) 357mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version)
355{ 358{
359 int i;
360
356 if (!client || !client->parent) 361 if (!client || !client->parent)
357 return MOBILEBACKUP2_E_INVALID_ARG; 362 return MOBILEBACKUP2_E_INVALID_ARG;
358 363
359 plist_t dict = plist_new_dict(); 364 plist_t dict = plist_new_dict();
360 plist_t array = plist_new_array(); 365 plist_t array = plist_new_array();
361 plist_array_append_item(array, plist_new_real(2.0)); 366 for (i = 0; i < count; i++) {
362 plist_array_append_item(array, plist_new_real(2.1)); 367 plist_array_append_item(array, plist_new_real(local_versions[i]));
368 }
363 plist_dict_insert_item(dict, "SupportedProtocolVersions", array); 369 plist_dict_insert_item(dict, "SupportedProtocolVersions", array);
364 370
365 mobilebackup2_error_t err = internal_mobilebackup2_send_message(client, "Hello", dict); 371 mobilebackup2_error_t err = internal_mobilebackup2_send_message(client, "Hello", dict);
@@ -373,6 +379,7 @@ mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t clie
373 if (err != MOBILEBACKUP2_E_SUCCESS) 379 if (err != MOBILEBACKUP2_E_SUCCESS)
374 goto leave; 380 goto leave;
375 381
382 /* check if we received an error */
376 plist_t node = plist_dict_get_item(dict, "ErrorCode"); 383 plist_t node = plist_dict_get_item(dict, "ErrorCode");
377 if (!node || (plist_get_node_type(node) != PLIST_UINT)) { 384 if (!node || (plist_get_node_type(node) != PLIST_UINT)) {
378 err = MOBILEBACKUP2_E_PLIST_ERROR; 385 err = MOBILEBACKUP2_E_PLIST_ERROR;
@@ -381,27 +388,24 @@ mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t clie
381 388
382 uint64_t val = 0; 389 uint64_t val = 0;
383 plist_get_uint_val(node, &val); 390 plist_get_uint_val(node, &val);
384
385 if (val != 0) { 391 if (val != 0) {
386 err = MOBILEBACKUP2_E_REPLY_NOT_OK; 392 if (val == 1) {
393 err = MOBILEBACKUP2_E_NO_COMMON_VERSION;
394 } else {
395 err = MOBILEBACKUP2_E_REPLY_NOT_OK;
396 }
387 goto leave; 397 goto leave;
388 } 398 }
389 399
400 /* retrieve the protocol version of the device */
390 node = plist_dict_get_item(dict, "ProtocolVersion"); 401 node = plist_dict_get_item(dict, "ProtocolVersion");
391 if (!node || (plist_get_node_type(node) != PLIST_REAL)) { 402 if (!node || (plist_get_node_type(node) != PLIST_REAL)) {
392 err = MOBILEBACKUP2_E_PLIST_ERROR; 403 err = MOBILEBACKUP2_E_PLIST_ERROR;
393 goto leave; 404 goto leave;
394 } 405 }
395 406
396 double rval = 0.0; 407 *remote_version = 0.0;
397 plist_get_real_val(node, &rval); 408 plist_get_real_val(node, remote_version);
398
399 debug_info("using protocol version %f\n", rval);
400
401 // TODO version check ??
402 // if version does not match
403 // err = MOBILEBACKUP2_E_BAD_VERSION
404
405leave: 409leave:
406 if (dict) 410 if (dict)
407 plist_free(dict); 411 plist_free(dict);
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index b9187e9..113180b 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -1231,13 +1231,17 @@ int main(int argc, char *argv[])
1231 mobilebackup2_client_new(phone, port, &mobilebackup2); 1231 mobilebackup2_client_new(phone, port, &mobilebackup2);
1232 1232
1233 /* send Hello message */ 1233 /* send Hello message */
1234 err = mobilebackup2_version_exchange(mobilebackup2); 1234 double local_versions[2] = {2.0, 2.1};
1235 double remote_version = 0.0;
1236 err = mobilebackup2_version_exchange(mobilebackup2, local_versions, 2, &remote_version);
1235 if (err != MOBILEBACKUP2_E_SUCCESS) { 1237 if (err != MOBILEBACKUP2_E_SUCCESS) {
1236 printf("Could not perform backup protocol version exchange, error code %d\n", err); 1238 printf("Could not perform backup protocol version exchange, error code %d\n", err);
1237 cmd = CMD_LEAVE; 1239 cmd = CMD_LEAVE;
1238 goto checkpoint; 1240 goto checkpoint;
1239 } 1241 }
1240 1242
1243 PRINT_VERBOSE(1, "Negotiated Protocol Version %.1f\n", remote_version);
1244
1241 /* check abort conditions */ 1245 /* check abort conditions */
1242 if (quit_flag > 0) { 1246 if (quit_flag > 0) {
1243 PRINT_VERBOSE(1, "Aborting as requested by user...\n"); 1247 PRINT_VERBOSE(1, "Aborting as requested by user...\n");