From 53eb963f8e6d607cca6b50381c10820a5e8357f4 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 11 Nov 2014 09:51:31 +0100 Subject: notification_proxy: Send Shutdown command in np_client_free() instead of np_post_notification() --- src/notification_proxy.c | 67 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'src/notification_proxy.c') diff --git a/src/notification_proxy.c b/src/notification_proxy.c index ecfb052..dba42db 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c @@ -113,15 +113,46 @@ LIBIMOBILEDEVICE_API np_error_t np_client_start_service(idevice_t device, np_cli LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) { + plist_t dict; + if (!client) return NP_E_INVALID_ARG; - property_list_service_client_free(client->parent); - client->parent = NULL; + dict = plist_new_dict(); + plist_dict_set_item(dict,"Command", plist_new_string("Shutdown")); + property_list_service_send_xml_plist(client->parent, dict); + plist_free(dict); + if (client->notifier) { debug_info("joining np callback"); thread_join(client->notifier); + } else { + dict = NULL; + property_list_service_receive_plist(client->parent, &dict); + if (dict) { +#ifndef STRIP_DEBUG_CODE + char *cmd_value = NULL; + plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); + if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { + plist_get_string_val(cmd_value_node, &cmd_value); + } + if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { + // this is the expected answer + } else { + debug_info("Did not get ProxyDeath but:"); + debug_plist(dict); + } + if (cmd_value) { + free(cmd_value); + } +#endif + plist_free(dict); + } } + + property_list_service_client_free(client->parent); + client->parent = NULL; + mutex_destroy(&client->mutex); free(client); @@ -142,39 +173,9 @@ LIBIMOBILEDEVICE_API np_error_t np_post_notification(np_client_t client, const c np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); plist_free(dict); - dict = plist_new_dict(); - plist_dict_set_item(dict,"Command", plist_new_string("Shutdown")); - - res = np_error(property_list_service_send_xml_plist(client->parent, dict)); - plist_free(dict); - if (res != NP_E_SUCCESS) { debug_info("Error sending XML plist to device!"); } - - // try to read an answer, we just ignore errors here - dict = NULL; - property_list_service_receive_plist(client->parent, &dict); - if (dict) { -#ifndef STRIP_DEBUG_CODE - char *cmd_value = NULL; - plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); - if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { - plist_get_string_val(cmd_value_node, &cmd_value); - } - - if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { - // this is the expected answer - } else { - debug_plist(dict); - } - if (cmd_value) { - free(cmd_value); - } -#endif - plist_free(dict); - } - np_unlock(client); return res; } @@ -279,7 +280,7 @@ static int np_get_notification(np_client_t client, char **notification) res = 0; } } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { - debug_info("ERROR: NotificationProxy died!"); + debug_info("NotificationProxy died!"); res = -1; } else if (cmd_value) { debug_info("unknown NotificationProxy command '%s' received!", cmd_value); -- cgit v1.1-32-gdbae