diff options
author | Jonathan Beck | 2009-04-22 19:34:36 +0200 |
---|---|---|
committer | Matt Colyer | 2009-04-23 19:11:49 -0700 |
commit | bda6ddc5b9eeb2e56e0c1a6a94cdf20ced4dab78 (patch) | |
tree | d4342380dfac571cf319a55b959f2de35f0ba6f4 | |
parent | d0f4609f8af91abc09810971d023b21e871ec6e7 (diff) | |
download | libimobiledevice-bda6ddc5b9eeb2e56e0c1a6a94cdf20ced4dab78.tar.gz libimobiledevice-bda6ddc5b9eeb2e56e0c1a6a94cdf20ced4dab78.tar.bz2 |
Detect unknown HostId in StartSession an trigger Pair again if needed.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/lockdown.c | 55 |
2 files changed, 55 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index a26be74..a7b627e 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ PKG_CHECK_MODULES(libglib2, glib-2.0 >= 2.14.1) PKG_CHECK_MODULES(libgthread2, gthread-2.0 >= 2.14.1) PKG_CHECK_MODULES(libgnutls, gnutls >= 1.6.3 ) PKG_CHECK_MODULES(libtasn1, libtasn1 >= 1.1) -PKG_CHECK_MODULES(libplist, libplist >= 0.10) +PKG_CHECK_MODULES(libplist, libplist >= 0.11) # Checks for header files. AC_HEADER_STDC diff --git a/src/lockdown.c b/src/lockdown.c index 64c325e..c017cdf 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -506,7 +506,6 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client host_id = get_host_id(); if (IPHONE_E_SUCCESS == ret && !host_id) { - log_debug_msg("No HostID found, run libiphone-initconf.\n"); ret = IPHONE_E_INVALID_CONF; } @@ -847,6 +846,60 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c if (!dict) return IPHONE_E_PLIST_ERROR; + plist_t request_node = plist_get_dict_el_from_key(dict, "Request"); + plist_t result_node = plist_get_dict_el_from_key(dict, "Result"); + + if (request_node && PLIST_STRING == plist_get_node_type(request_node) && + result_node && PLIST_STRING == plist_get_node_type(result_node)){ + + char *request = NULL; + char *result = NULL; + + plist_get_string_val(request_node, &request); + plist_get_string_val(result_node, &result); + + if (!strcmp(request, "StartSession")) { + if (!strcmp(result, "Failure")) { + + plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); + if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { + + char *error = NULL; + plist_get_string_val(error_node, &error); + + if (!strcmp(error, "InvalidHostID")) { + //hostid is not know. Pair and try again + char *uid = NULL; + char* host_id = get_host_id(); + if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid) ) { + if (IPHONE_E_SUCCESS == lockdownd_pair_device(control, uid, host_id) ) { + + //start session again + plist_free(dict); + dict = plist_new_dict(); + plist_add_sub_key_el(dict, "HostID"); + plist_add_sub_string_el(dict, HostID); + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "StartSession"); + + ret = iphone_lckd_send(control, dict); + plist_free(dict); + dict = NULL; + + ret = iphone_lckd_recv(control, &dict); + } + } + free(uid); + free(host_id); + } + free(error); + } + } + } + free(request); + free(result); + } + plist_t query_node = plist_find_node_by_string(dict, "StartSession"); plist_t result_key_node = plist_get_next_sibling(query_node); plist_t result_value_node = plist_get_next_sibling(result_key_node); |