diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/notification_proxy.c | 67 |
1 files changed, 34 insertions, 33 deletions
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 | |||
| 113 | 113 | ||
| 114 | LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) | 114 | LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) |
| 115 | { | 115 | { |
| 116 | plist_t dict; | ||
| 117 | |||
| 116 | if (!client) | 118 | if (!client) |
| 117 | return NP_E_INVALID_ARG; | 119 | return NP_E_INVALID_ARG; |
| 118 | 120 | ||
| 119 | property_list_service_client_free(client->parent); | 121 | dict = plist_new_dict(); |
| 120 | client->parent = NULL; | 122 | plist_dict_set_item(dict,"Command", plist_new_string("Shutdown")); |
| 123 | property_list_service_send_xml_plist(client->parent, dict); | ||
| 124 | plist_free(dict); | ||
| 125 | |||
| 121 | if (client->notifier) { | 126 | if (client->notifier) { |
| 122 | debug_info("joining np callback"); | 127 | debug_info("joining np callback"); |
| 123 | thread_join(client->notifier); | 128 | thread_join(client->notifier); |
| 129 | } else { | ||
| 130 | dict = NULL; | ||
| 131 | property_list_service_receive_plist(client->parent, &dict); | ||
| 132 | if (dict) { | ||
| 133 | #ifndef STRIP_DEBUG_CODE | ||
| 134 | char *cmd_value = NULL; | ||
| 135 | plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); | ||
| 136 | if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { | ||
| 137 | plist_get_string_val(cmd_value_node, &cmd_value); | ||
| 138 | } | ||
| 139 | if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { | ||
| 140 | // this is the expected answer | ||
| 141 | } else { | ||
| 142 | debug_info("Did not get ProxyDeath but:"); | ||
| 143 | debug_plist(dict); | ||
| 144 | } | ||
| 145 | if (cmd_value) { | ||
| 146 | free(cmd_value); | ||
| 147 | } | ||
| 148 | #endif | ||
| 149 | plist_free(dict); | ||
| 150 | } | ||
| 124 | } | 151 | } |
| 152 | |||
| 153 | property_list_service_client_free(client->parent); | ||
| 154 | client->parent = NULL; | ||
| 155 | |||
| 125 | mutex_destroy(&client->mutex); | 156 | mutex_destroy(&client->mutex); |
| 126 | free(client); | 157 | free(client); |
| 127 | 158 | ||
| @@ -142,39 +173,9 @@ LIBIMOBILEDEVICE_API np_error_t np_post_notification(np_client_t client, const c | |||
| 142 | np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); | 173 | np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); |
| 143 | plist_free(dict); | 174 | plist_free(dict); |
| 144 | 175 | ||
| 145 | dict = plist_new_dict(); | ||
| 146 | plist_dict_set_item(dict,"Command", plist_new_string("Shutdown")); | ||
| 147 | |||
| 148 | res = np_error(property_list_service_send_xml_plist(client->parent, dict)); | ||
| 149 | plist_free(dict); | ||
| 150 | |||
| 151 | if (res != NP_E_SUCCESS) { | 176 | if (res != NP_E_SUCCESS) { |
| 152 | debug_info("Error sending XML plist to device!"); | 177 | debug_info("Error sending XML plist to device!"); |
| 153 | } | 178 | } |
| 154 | |||
| 155 | // try to read an answer, we just ignore errors here | ||
| 156 | dict = NULL; | ||
| 157 | property_list_service_receive_plist(client->parent, &dict); | ||
| 158 | if (dict) { | ||
| 159 | #ifndef STRIP_DEBUG_CODE | ||
| 160 | char *cmd_value = NULL; | ||
| 161 | plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); | ||
| 162 | if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { | ||
| 163 | plist_get_string_val(cmd_value_node, &cmd_value); | ||
| 164 | } | ||
| 165 | |||
| 166 | if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { | ||
| 167 | // this is the expected answer | ||
| 168 | } else { | ||
| 169 | debug_plist(dict); | ||
| 170 | } | ||
| 171 | if (cmd_value) { | ||
| 172 | free(cmd_value); | ||
| 173 | } | ||
| 174 | #endif | ||
| 175 | plist_free(dict); | ||
| 176 | } | ||
| 177 | |||
| 178 | np_unlock(client); | 179 | np_unlock(client); |
| 179 | return res; | 180 | return res; |
| 180 | } | 181 | } |
| @@ -279,7 +280,7 @@ static int np_get_notification(np_client_t client, char **notification) | |||
| 279 | res = 0; | 280 | res = 0; |
| 280 | } | 281 | } |
| 281 | } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { | 282 | } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { |
| 282 | debug_info("ERROR: NotificationProxy died!"); | 283 | debug_info("NotificationProxy died!"); |
| 283 | res = -1; | 284 | res = -1; |
| 284 | } else if (cmd_value) { | 285 | } else if (cmd_value) { |
| 285 | debug_info("unknown NotificationProxy command '%s' received!", cmd_value); | 286 | debug_info("unknown NotificationProxy command '%s' received!", cmd_value); |
