diff options
-rw-r--r-- | include/libimobiledevice/mobilebackup2.h | 3 | ||||
-rw-r--r-- | src/mobilebackup2.c | 34 | ||||
-rw-r--r-- | tools/idevicebackup2.c | 6 |
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" { #define MOBILEBACKUP2_E_MUX_ERROR -3 #define MOBILEBACKUP2_E_BAD_VERSION -4 #define MOBILEBACKUP2_E_REPLY_NOT_OK -5 +#define MOBILEBACKUP2_E_NO_COMMON_VERSION -6 #define MOBILEBACKUP2_E_UNKNOWN_ERROR -256 /*@}*/ @@ -52,7 +53,7 @@ mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client); mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage); mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes); mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes); -mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client); +mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version); mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options); mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2); 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 /** * Performs the mobilebackup2 protocol version exchange. * - * @param The MobileBackup client to use. + * @param client The MobileBackup client to use. + * @param local_versions An array of supported versions to send to the remote. + * @param count The number of items in local_versions. + * @param remote_version Holds the protocol version of the remote on success. * * @return MOBILEBACKUP2_E_SUCCESS on success, or a MOBILEBACKUP2_E_* error * code otherwise. */ -mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client) +mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version) { + int i; + if (!client || !client->parent) return MOBILEBACKUP2_E_INVALID_ARG; plist_t dict = plist_new_dict(); plist_t array = plist_new_array(); - plist_array_append_item(array, plist_new_real(2.0)); - plist_array_append_item(array, plist_new_real(2.1)); + for (i = 0; i < count; i++) { + plist_array_append_item(array, plist_new_real(local_versions[i])); + } plist_dict_insert_item(dict, "SupportedProtocolVersions", array); 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 if (err != MOBILEBACKUP2_E_SUCCESS) goto leave; + /* check if we received an error */ plist_t node = plist_dict_get_item(dict, "ErrorCode"); if (!node || (plist_get_node_type(node) != PLIST_UINT)) { err = MOBILEBACKUP2_E_PLIST_ERROR; @@ -381,27 +388,24 @@ mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t clie uint64_t val = 0; plist_get_uint_val(node, &val); - if (val != 0) { - err = MOBILEBACKUP2_E_REPLY_NOT_OK; + if (val == 1) { + err = MOBILEBACKUP2_E_NO_COMMON_VERSION; + } else { + err = MOBILEBACKUP2_E_REPLY_NOT_OK; + } goto leave; } + /* retrieve the protocol version of the device */ node = plist_dict_get_item(dict, "ProtocolVersion"); if (!node || (plist_get_node_type(node) != PLIST_REAL)) { err = MOBILEBACKUP2_E_PLIST_ERROR; goto leave; } - double rval = 0.0; - plist_get_real_val(node, &rval); - - debug_info("using protocol version %f\n", rval); - - // TODO version check ?? - // if version does not match - // err = MOBILEBACKUP2_E_BAD_VERSION - + *remote_version = 0.0; + plist_get_real_val(node, remote_version); leave: if (dict) 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[]) mobilebackup2_client_new(phone, port, &mobilebackup2); /* send Hello message */ - err = mobilebackup2_version_exchange(mobilebackup2); + double local_versions[2] = {2.0, 2.1}; + double remote_version = 0.0; + err = mobilebackup2_version_exchange(mobilebackup2, local_versions, 2, &remote_version); if (err != MOBILEBACKUP2_E_SUCCESS) { printf("Could not perform backup protocol version exchange, error code %d\n", err); cmd = CMD_LEAVE; goto checkpoint; } + PRINT_VERBOSE(1, "Negotiated Protocol Version %.1f\n", remote_version); + /* check abort conditions */ if (quit_flag > 0) { PRINT_VERBOSE(1, "Aborting as requested by user...\n"); |