summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mobilebackup2.c34
1 files changed, 19 insertions, 15 deletions
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);