diff options
Diffstat (limited to 'src/NotificationProxy.c')
| -rw-r--r-- | src/NotificationProxy.c | 98 |
1 files changed, 41 insertions, 57 deletions
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index e2c1faa..e994c16 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c | |||
| @@ -27,8 +27,8 @@ | |||
| 27 | #include <plist/plist.h> | 27 | #include <plist/plist.h> |
| 28 | 28 | ||
| 29 | #include "NotificationProxy.h" | 29 | #include "NotificationProxy.h" |
| 30 | #include "iphone.h" | 30 | #include "property_list_service.h" |
| 31 | #include "utils.h" | 31 | #include "debug.h" |
| 32 | 32 | ||
| 33 | struct np_thread { | 33 | struct np_thread { |
| 34 | np_client_t client; | 34 | np_client_t client; |
| @@ -41,7 +41,7 @@ struct np_thread { | |||
| 41 | */ | 41 | */ |
| 42 | static void np_lock(np_client_t client) | 42 | static void np_lock(np_client_t client) |
| 43 | { | 43 | { |
| 44 | log_debug_msg("NP: Locked\n"); | 44 | debug_info("NP: Locked"); |
| 45 | g_mutex_lock(client->mutex); | 45 | g_mutex_lock(client->mutex); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| @@ -51,29 +51,30 @@ static void np_lock(np_client_t client) | |||
| 51 | */ | 51 | */ |
| 52 | static void np_unlock(np_client_t client) | 52 | static void np_unlock(np_client_t client) |
| 53 | { | 53 | { |
| 54 | log_debug_msg("NP: Unlocked\n"); | 54 | debug_info("NP: Unlocked"); |
| 55 | g_mutex_unlock(client->mutex); | 55 | g_mutex_unlock(client->mutex); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * Convert an iphone_error_t value to an np_error_t value. | 59 | * Convert a property_list_service_error_t value to an np_error_t value. |
| 60 | * Used internally to get correct error codes when using plist helper | 60 | * Used internally to get correct error codes. |
| 61 | * functions. | ||
| 62 | * | 61 | * |
| 63 | * @param err An iphone_error_t error code | 62 | * @param err A property_list_service_error_t error code |
| 64 | * | 63 | * |
| 65 | * @return A matching np_error_t error code, | 64 | * @return A matching np_error_t error code, |
| 66 | * NP_E_UNKNOWN_ERROR otherwise. | 65 | * NP_E_UNKNOWN_ERROR otherwise. |
| 67 | */ | 66 | */ |
| 68 | static np_error_t iphone_to_np_error(iphone_error_t err) | 67 | static np_error_t np_error(property_list_service_error_t err) |
| 69 | { | 68 | { |
| 70 | switch (err) { | 69 | switch (err) { |
| 71 | case IPHONE_E_SUCCESS: | 70 | case PROPERTY_LIST_SERVICE_E_SUCCESS: |
| 72 | return NP_E_SUCCESS; | 71 | return NP_E_SUCCESS; |
| 73 | case IPHONE_E_INVALID_ARG: | 72 | case PROPERTY_LIST_SERVICE_E_INVALID_ARG: |
| 74 | return NP_E_INVALID_ARG; | 73 | return NP_E_INVALID_ARG; |
| 75 | case IPHONE_E_PLIST_ERROR: | 74 | case PROPERTY_LIST_SERVICE_E_PLIST_ERROR: |
| 76 | return NP_E_PLIST_ERROR; | 75 | return NP_E_PLIST_ERROR; |
| 76 | case PROPERTY_LIST_SERVICE_E_MUX_ERROR: | ||
| 77 | return NP_E_CONN_FAILED; | ||
| 77 | default: | 78 | default: |
| 78 | break; | 79 | break; |
| 79 | } | 80 | } |
| @@ -83,7 +84,7 @@ static np_error_t iphone_to_np_error(iphone_error_t err) | |||
| 83 | /** Makes a connection to the NP service on the phone. | 84 | /** Makes a connection to the NP service on the phone. |
| 84 | * | 85 | * |
| 85 | * @param device The device to connect to. | 86 | * @param device The device to connect to. |
| 86 | * @param dst_port Destination port (usually given by lockdownd_start_service). | 87 | * @param port Destination port (usually given by lockdownd_start_service). |
| 87 | * @param client Pointer that will be set to a newly allocated np_client_t | 88 | * @param client Pointer that will be set to a newly allocated np_client_t |
| 88 | * upon successful return. | 89 | * upon successful return. |
| 89 | * | 90 | * |
| @@ -91,7 +92,7 @@ static np_error_t iphone_to_np_error(iphone_error_t err) | |||
| 91 | * or NP_E_CONN_FAILED when the connection to the device could not be | 92 | * or NP_E_CONN_FAILED when the connection to the device could not be |
| 92 | * established. | 93 | * established. |
| 93 | */ | 94 | */ |
| 94 | np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *client) | 95 | np_error_t np_client_new(iphone_device_t device, uint16_t port, np_client_t *client) |
| 95 | { | 96 | { |
| 96 | /* makes sure thread environment is available */ | 97 | /* makes sure thread environment is available */ |
| 97 | if (!g_thread_supported()) | 98 | if (!g_thread_supported()) |
| @@ -100,14 +101,13 @@ np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *clie | |||
| 100 | if (!device) | 101 | if (!device) |
| 101 | return NP_E_INVALID_ARG; | 102 | return NP_E_INVALID_ARG; |
| 102 | 103 | ||
| 103 | /* Attempt connection */ | 104 | property_list_service_client_t plistclient = NULL; |
| 104 | iphone_connection_t connection = NULL; | 105 | if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { |
| 105 | if (iphone_device_connect(device, dst_port, &connection) != IPHONE_E_SUCCESS) { | ||
| 106 | return NP_E_CONN_FAILED; | 106 | return NP_E_CONN_FAILED; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); | 109 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); |
| 110 | client_loc->connection = connection; | 110 | client_loc->parent = plistclient; |
| 111 | 111 | ||
| 112 | client_loc->mutex = g_mutex_new(); | 112 | client_loc->mutex = g_mutex_new(); |
| 113 | 113 | ||
| @@ -128,10 +128,10 @@ np_error_t np_client_free(np_client_t client) | |||
| 128 | if (!client) | 128 | if (!client) |
| 129 | return NP_E_INVALID_ARG; | 129 | return NP_E_INVALID_ARG; |
| 130 | 130 | ||
| 131 | iphone_device_disconnect(client->connection); | 131 | property_list_service_client_free(client->parent); |
| 132 | client->connection = NULL; | 132 | client->parent = NULL; |
| 133 | if (client->notifier) { | 133 | if (client->notifier) { |
| 134 | log_debug_msg("joining np callback\n"); | 134 | debug_info("joining np callback"); |
| 135 | g_thread_join(client->notifier); | 135 | g_thread_join(client->notifier); |
| 136 | } | 136 | } |
| 137 | if (client->mutex) { | 137 | if (client->mutex) { |
| @@ -144,10 +144,6 @@ np_error_t np_client_free(np_client_t client) | |||
| 144 | 144 | ||
| 145 | /** Sends a notification to the device's Notification Proxy. | 145 | /** Sends a notification to the device's Notification Proxy. |
| 146 | * | 146 | * |
| 147 | * notification messages seen so far: | ||
| 148 | * com.apple.itunes-mobdev.syncWillStart | ||
| 149 | * com.apple.itunes-mobdev.syncDidStart | ||
| 150 | * | ||
| 151 | * @param client The client to send to | 147 | * @param client The client to send to |
| 152 | * @param notification The notification message to send | 148 | * @param notification The notification message to send |
| 153 | * | 149 | * |
| @@ -164,17 +160,17 @@ np_error_t np_post_notification(np_client_t client, const char *notification) | |||
| 164 | plist_dict_insert_item(dict,"Command", plist_new_string("PostNotification")); | 160 | plist_dict_insert_item(dict,"Command", plist_new_string("PostNotification")); |
| 165 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); | 161 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); |
| 166 | 162 | ||
| 167 | np_error_t res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict)); | 163 | np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); |
| 168 | plist_free(dict); | 164 | plist_free(dict); |
| 169 | 165 | ||
| 170 | dict = plist_new_dict(); | 166 | dict = plist_new_dict(); |
| 171 | plist_dict_insert_item(dict,"Command", plist_new_string("Shutdown")); | 167 | plist_dict_insert_item(dict,"Command", plist_new_string("Shutdown")); |
| 172 | 168 | ||
| 173 | res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict)); | 169 | res = np_error(property_list_service_send_xml_plist(client->parent, dict)); |
| 174 | plist_free(dict); | 170 | plist_free(dict); |
| 175 | 171 | ||
| 176 | if (res != NP_E_SUCCESS) { | 172 | if (res != NP_E_SUCCESS) { |
| 177 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); | 173 | debug_info("Error sending XML plist to device!"); |
| 178 | } | 174 | } |
| 179 | 175 | ||
| 180 | np_unlock(client); | 176 | np_unlock(client); |
| @@ -200,9 +196,9 @@ np_error_t np_observe_notification( np_client_t client, const char *notification | |||
| 200 | plist_dict_insert_item(dict,"Command", plist_new_string("ObserveNotification")); | 196 | plist_dict_insert_item(dict,"Command", plist_new_string("ObserveNotification")); |
| 201 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); | 197 | plist_dict_insert_item(dict,"Name", plist_new_string(notification)); |
| 202 | 198 | ||
| 203 | np_error_t res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict)); | 199 | np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict)); |
| 204 | if (res != NP_E_SUCCESS) { | 200 | if (res != NP_E_SUCCESS) { |
| 205 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); | 201 | debug_info("Error sending XML plist to device!"); |
| 206 | } | 202 | } |
| 207 | plist_free(dict); | 203 | plist_free(dict); |
| 208 | 204 | ||
| @@ -212,22 +208,10 @@ np_error_t np_observe_notification( np_client_t client, const char *notification | |||
| 212 | 208 | ||
| 213 | /** Notifies the iphone to send a notification on specified events. | 209 | /** Notifies the iphone to send a notification on specified events. |
| 214 | * | 210 | * |
| 215 | * observation messages seen so far: | ||
| 216 | * com.apple.itunes-client.syncCancelRequest | ||
| 217 | * com.apple.itunes-client.syncSuspendRequest | ||
| 218 | * com.apple.itunes-client.syncResumeRequest | ||
| 219 | * com.apple.mobile.lockdown.phone_number_changed | ||
| 220 | * com.apple.mobile.lockdown.device_name_changed | ||
| 221 | * com.apple.springboard.attemptactivation | ||
| 222 | * com.apple.mobile.data_sync.domain_changed | ||
| 223 | * com.apple.mobile.application_installed | ||
| 224 | * com.apple.mobile.application_uninstalled | ||
| 225 | * | ||
| 226 | * @param client The client to send to | 211 | * @param client The client to send to |
| 227 | * @param notification_spec Specification of the notifications that should be | 212 | * @param notification_spec Specification of the notifications that should be |
| 228 | * observed. This is expected to be an array of const char* that MUST have a | 213 | * observed. This is expected to be an array of const char* that MUST have a |
| 229 | * terminating NULL entry. However this parameter can be NULL; in this case, | 214 | * terminating NULL entry. |
| 230 | * the default set of notifications will be used. | ||
| 231 | * | 215 | * |
| 232 | * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when client is null, | 216 | * @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when client is null, |
| 233 | * or an error returned by np_observe_notification. | 217 | * or an error returned by np_observe_notification. |
| @@ -243,7 +227,7 @@ np_error_t np_observe_notifications(np_client_t client, const char **notificatio | |||
| 243 | } | 227 | } |
| 244 | 228 | ||
| 245 | if (!notifications) { | 229 | if (!notifications) { |
| 246 | notifications = np_default_notifications; | 230 | return NP_E_INVALID_ARG; |
| 247 | } | 231 | } |
| 248 | 232 | ||
| 249 | while (notifications[i]) { | 233 | while (notifications[i]) { |
| @@ -275,14 +259,14 @@ static int np_get_notification(np_client_t client, char **notification) | |||
| 275 | int res = 0; | 259 | int res = 0; |
| 276 | plist_t dict = NULL; | 260 | plist_t dict = NULL; |
| 277 | 261 | ||
| 278 | if (!client || !client->connection || *notification) | 262 | if (!client || !client->parent || *notification) |
| 279 | return -1; | 263 | return -1; |
| 280 | 264 | ||
| 281 | np_lock(client); | 265 | np_lock(client); |
| 282 | 266 | ||
| 283 | iphone_device_receive_plist_with_timeout(client->connection, &dict, 500); | 267 | property_list_service_receive_plist_with_timeout(client->parent, &dict, 500); |
| 284 | if (!dict) { | 268 | if (!dict) { |
| 285 | log_debug_msg("NotificationProxy: no notification received!\n"); | 269 | debug_info("NotificationProxy: no notification received!"); |
| 286 | res = 0; | 270 | res = 0; |
| 287 | } else { | 271 | } else { |
| 288 | char *cmd_value = NULL; | 272 | char *cmd_value = NULL; |
| @@ -303,14 +287,14 @@ static int np_get_notification(np_client_t client, char **notification) | |||
| 303 | res = -2; | 287 | res = -2; |
| 304 | if (name_value_node && name_value) { | 288 | if (name_value_node && name_value) { |
| 305 | *notification = name_value; | 289 | *notification = name_value; |
| 306 | log_debug_msg("%s: got notification %s\n", __func__, name_value); | 290 | debug_info("got notification %s\n", __func__, name_value); |
| 307 | res = 0; | 291 | res = 0; |
| 308 | } | 292 | } |
| 309 | } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { | 293 | } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { |
| 310 | log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__); | 294 | debug_info("ERROR: NotificationProxy died!"); |
| 311 | res = -1; | 295 | res = -1; |
| 312 | } else if (cmd_value) { | 296 | } else if (cmd_value) { |
| 313 | log_debug_msg("%d: unknown NotificationProxy command '%s' received!\n", __func__); | 297 | debug_info("unknown NotificationProxy command '%s' received!", cmd_value); |
| 314 | res = -1; | 298 | res = -1; |
| 315 | } else { | 299 | } else { |
| 316 | res = -2; | 300 | res = -2; |
| @@ -337,8 +321,8 @@ gpointer np_notifier( gpointer arg ) | |||
| 337 | 321 | ||
| 338 | if (!npt) return NULL; | 322 | if (!npt) return NULL; |
| 339 | 323 | ||
| 340 | log_debug_msg("%s: starting callback.\n", __func__); | 324 | debug_info("starting callback."); |
| 341 | while (npt->client->connection) { | 325 | while (npt->client->parent) { |
| 342 | np_get_notification(npt->client, ¬ification); | 326 | np_get_notification(npt->client, ¬ification); |
| 343 | if (notification) { | 327 | if (notification) { |
| 344 | npt->cbfunc(notification); | 328 | npt->cbfunc(notification); |
| @@ -380,12 +364,12 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb | |||
| 380 | 364 | ||
| 381 | np_lock(client); | 365 | np_lock(client); |
| 382 | if (client->notifier) { | 366 | if (client->notifier) { |
| 383 | log_debug_msg("%s: callback already set, removing\n"); | 367 | debug_info("callback already set, removing\n"); |
| 384 | iphone_connection_t conn = client->connection; | 368 | property_list_service_client_t parent = client->parent; |
| 385 | client->connection = NULL; | 369 | client->parent = NULL; |
| 386 | g_thread_join(client->notifier); | 370 | g_thread_join(client->notifier); |
| 387 | client->notifier = NULL; | 371 | client->notifier = NULL; |
| 388 | client->connection = conn; | 372 | client->parent = parent; |
| 389 | } | 373 | } |
| 390 | 374 | ||
| 391 | if (notify_cb) { | 375 | if (notify_cb) { |
| @@ -400,7 +384,7 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb | |||
| 400 | } | 384 | } |
| 401 | } | 385 | } |
| 402 | } else { | 386 | } else { |
| 403 | log_debug_msg("%s: no callback set\n", __func__); | 387 | debug_info("no callback set"); |
| 404 | } | 388 | } |
| 405 | np_unlock(client); | 389 | np_unlock(client); |
| 406 | 390 | ||
