diff options
| author | 2009-07-25 02:20:03 +0200 | |
|---|---|---|
| committer | 2009-07-25 02:20:03 +0200 | |
| commit | d11abfb48218a37d9c66831ebec8b0a736d5385f (patch) | |
| tree | 1bc4ad43106e3ef7076f1021525a395d271c6259 | |
| parent | 40a0abaa1c7f2196d40276b0689b18a04e468acd (diff) | |
| download | libimobiledevice-d11abfb48218a37d9c66831ebec8b0a736d5385f.tar.gz libimobiledevice-d11abfb48218a37d9c66831ebec8b0a736d5385f.tar.bz2 | |
Update NotificationProxy API and introduce new error codes
| -rw-r--r-- | dev/main.c | 14 | ||||
| -rw-r--r-- | include/libiphone/notification_proxy.h | 34 | ||||
| -rw-r--r-- | src/NotificationProxy.c | 99 |
3 files changed, 77 insertions, 70 deletions
| @@ -46,11 +46,11 @@ static void perform_notification(iphone_device_t phone, lockdownd_client_t clien | |||
| 46 | lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); | 46 | lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); |
| 47 | if (nport) { | 47 | if (nport) { |
| 48 | printf("::::::::::::::: np was started ::::::::::::\n"); | 48 | printf("::::::::::::::: np was started ::::::::::::\n"); |
| 49 | np_new_client(phone, nport, &np); | 49 | np_client_new(phone, nport, &np); |
| 50 | if (np) { | 50 | if (np) { |
| 51 | printf("::::::::: PostNotification %s\n", notification); | 51 | printf("::::::::: PostNotification %s\n", notification); |
| 52 | np_post_notification(np, notification); | 52 | np_post_notification(np, notification); |
| 53 | np_free_client(np); | 53 | np_client_free(np); |
| 54 | } | 54 | } |
| 55 | } else { | 55 | } else { |
| 56 | printf("::::::::::::::: np was NOT started ::::::::::::\n"); | 56 | printf("::::::::::::::: np was NOT started ::::::::::::\n"); |
| @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) | |||
| 108 | lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); | 108 | lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); |
| 109 | if (npp) { | 109 | if (npp) { |
| 110 | printf("Notification Proxy started.\n"); | 110 | printf("Notification Proxy started.\n"); |
| 111 | np_new_client(phone, npp, &gnp); | 111 | np_client_new(phone, npp, &gnp); |
| 112 | } else { | 112 | } else { |
| 113 | printf("ERROR: Notification proxy could not be started.\n"); | 113 | printf("ERROR: Notification proxy could not be started.\n"); |
| 114 | } | 114 | } |
| @@ -225,17 +225,19 @@ int main(int argc, char *argv[]) | |||
| 225 | printf("XXX sleeping\n"); | 225 | printf("XXX sleeping\n"); |
| 226 | sleep(5); | 226 | sleep(5); |
| 227 | 227 | ||
| 228 | //perform_notification(phone, control, NP_SYNC_DID_FINISH); | ||
| 229 | |||
| 230 | printf("XXX unlocking file\n"); | 228 | printf("XXX unlocking file\n"); |
| 231 | afc_lock_file(afc, lockfile, AFC_LOCK_UN); | 229 | afc_lock_file(afc, lockfile, AFC_LOCK_UN); |
| 232 | 230 | ||
| 233 | printf("XXX closing file\n"); | 231 | printf("XXX closing file\n"); |
| 234 | afc_close_file(afc, lockfile); | 232 | afc_close_file(afc, lockfile); |
| 233 | |||
| 234 | printf("XXX sleeping\n"); | ||
| 235 | sleep(5); | ||
| 236 | //perform_notification(phone, client, NP_SYNC_DID_FINISH); | ||
| 235 | } | 237 | } |
| 236 | 238 | ||
| 237 | if (gnp) { | 239 | if (gnp) { |
| 238 | np_free_client(gnp); | 240 | np_client_free(gnp); |
| 239 | gnp = NULL; | 241 | gnp = NULL; |
| 240 | } | 242 | } |
| 241 | 243 | ||
diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h index 14d1b39..520ccd1 100644 --- a/include/libiphone/notification_proxy.h +++ b/include/libiphone/notification_proxy.h | |||
| @@ -27,16 +27,21 @@ extern "C" { | |||
| 27 | 27 | ||
| 28 | #include <libiphone/libiphone.h> | 28 | #include <libiphone/libiphone.h> |
| 29 | 29 | ||
| 30 | struct np_client_int; | 30 | /* Error Codes */ |
| 31 | typedef struct np_client_int *np_client_t; | 31 | #define NP_E_SUCCESS 0 |
| 32 | #define NP_E_INVALID_ARG -1 | ||
| 33 | #define NP_E_PLIST_ERROR -2 | ||
| 34 | |||
| 35 | #define NP_E_UNKNOWN_ERROR -256 | ||
| 36 | |||
| 37 | typedef int16_t np_error_t; | ||
| 32 | 38 | ||
| 33 | // NotificationProxy related | 39 | /* Notification IDs for use with post_notification (client --> device) */ |
| 34 | // notifications for use with post_notification (client --> device) | ||
| 35 | #define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" | 40 | #define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" |
| 36 | #define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" | 41 | #define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" |
| 37 | #define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" | 42 | #define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" |
| 38 | 43 | ||
| 39 | // notifications for use with observe_notification (device --> client) | 44 | /* Notification IDs for use with observe_notification (device --> client) */ |
| 40 | #define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" | 45 | #define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" |
| 41 | #define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" | 46 | #define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" |
| 42 | #define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" | 47 | #define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" |
| @@ -48,17 +53,18 @@ typedef struct np_client_int *np_client_t; | |||
| 48 | #define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" | 53 | #define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" |
| 49 | #define NP_ITDBPREP_DID_END "com.apple.itdbprep.notification.didEnd" | 54 | #define NP_ITDBPREP_DID_END "com.apple.itdbprep.notification.didEnd" |
| 50 | 55 | ||
| 51 | iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ); | 56 | struct np_client_int; |
| 52 | iphone_error_t np_free_client ( np_client_t client ); | 57 | typedef struct np_client_int *np_client_t; |
| 53 | |||
| 54 | iphone_error_t np_post_notification ( np_client_t client, const char *notification ); | ||
| 55 | |||
| 56 | iphone_error_t np_observe_notification ( np_client_t client, const char *notification ); | ||
| 57 | iphone_error_t np_observe_notifications ( np_client_t client, const char **notification_spec ); | ||
| 58 | 58 | ||
| 59 | typedef void (*np_notify_cb_t) ( const char *notification ); | 59 | typedef void (*np_notify_cb_t) (const char *notification); |
| 60 | 60 | ||
| 61 | iphone_error_t np_set_notify_callback ( np_client_t client, np_notify_cb_t notify_cb ); | 61 | /* Interface */ |
| 62 | np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *client); | ||
| 63 | np_error_t np_client_free(np_client_t client); | ||
| 64 | np_error_t np_post_notification(np_client_t client, const char *notification); | ||
| 65 | np_error_t np_observe_notification(np_client_t client, const char *notification); | ||
| 66 | np_error_t np_observe_notifications(np_client_t client, const char **notification_spec); | ||
| 67 | np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb); | ||
| 62 | 68 | ||
| 63 | #ifdef __cplusplus | 69 | #ifdef __cplusplus |
| 64 | } | 70 | } |
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index 1bbdc6d..7e52405 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
| 25 | #include <arpa/inet.h> | 25 | #include <arpa/inet.h> |
| 26 | #include <plist/plist.h> | 26 | #include <plist/plist.h> |
| 27 | |||
| 27 | #include "NotificationProxy.h" | 28 | #include "NotificationProxy.h" |
| 28 | #include "iphone.h" | 29 | #include "iphone.h" |
| 29 | #include "utils.h" | 30 | #include "utils.h" |
| @@ -60,24 +61,24 @@ static void np_unlock(np_client_t client) | |||
| 60 | * @param client NP to send data to | 61 | * @param client NP to send data to |
| 61 | * @param dict plist to send | 62 | * @param dict plist to send |
| 62 | * | 63 | * |
| 63 | * @return IPHONE_E_SUCCESS or an error code. | 64 | * @return NP_E_SUCCESS or an error code. |
| 64 | */ | 65 | */ |
| 65 | static iphone_error_t np_plist_send(np_client_t client, plist_t dict) | 66 | static np_error_t np_plist_send(np_client_t client, plist_t dict) |
| 66 | { | 67 | { |
| 67 | char *XML_content = NULL; | 68 | char *XML_content = NULL; |
| 68 | uint32_t length = 0; | 69 | uint32_t length = 0; |
| 69 | uint32_t nlen = 0; | 70 | uint32_t nlen = 0; |
| 70 | int bytes = 0; | 71 | int bytes = 0; |
| 71 | iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; | 72 | np_error_t res = NP_E_UNKNOWN_ERROR; |
| 72 | 73 | ||
| 73 | if (!client || !dict) { | 74 | if (!client || !dict) { |
| 74 | return IPHONE_E_INVALID_ARG; | 75 | return NP_E_INVALID_ARG; |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | plist_to_xml(dict, &XML_content, &length); | 78 | plist_to_xml(dict, &XML_content, &length); |
| 78 | 79 | ||
| 79 | if (!XML_content || length == 0) { | 80 | if (!XML_content || length == 0) { |
| 80 | return IPHONE_E_PLIST_ERROR; | 81 | return NP_E_PLIST_ERROR; |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | nlen = htonl(length); | 84 | nlen = htonl(length); |
| @@ -86,7 +87,7 @@ static iphone_error_t np_plist_send(np_client_t client, plist_t dict) | |||
| 86 | usbmuxd_send(client->sfd, XML_content, length, (uint32_t*)&bytes); | 87 | usbmuxd_send(client->sfd, XML_content, length, (uint32_t*)&bytes); |
| 87 | if (bytes > 0) { | 88 | if (bytes > 0) { |
| 88 | if ((uint32_t)bytes == length) { | 89 | if ((uint32_t)bytes == length) { |
| 89 | res = IPHONE_E_SUCCESS; | 90 | res = NP_E_SUCCESS; |
| 90 | } else { | 91 | } else { |
| 91 | log_debug_msg("%s: ERROR: Could not send all data (%d of %d)!\n", __func__, bytes, length); | 92 | log_debug_msg("%s: ERROR: Could not send all data (%d of %d)!\n", __func__, bytes, length); |
| 92 | } | 93 | } |
| @@ -109,19 +110,19 @@ static iphone_error_t np_plist_send(np_client_t client, plist_t dict) | |||
| 109 | * | 110 | * |
| 110 | * @return A handle to the newly-connected client or NULL upon error. | 111 | * @return A handle to the newly-connected client or NULL upon error. |
| 111 | */ | 112 | */ |
| 112 | iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ) | 113 | np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *client) |
| 113 | { | 114 | { |
| 114 | //makes sure thread environment is available | 115 | /* makes sure thread environment is available */ |
| 115 | if (!g_thread_supported()) | 116 | if (!g_thread_supported()) |
| 116 | g_thread_init(NULL); | 117 | g_thread_init(NULL); |
| 117 | 118 | ||
| 118 | if (!device) | 119 | if (!device) |
| 119 | return IPHONE_E_INVALID_ARG; | 120 | return NP_E_INVALID_ARG; |
| 120 | 121 | ||
| 121 | // Attempt connection | 122 | /* Attempt connection */ |
| 122 | int sfd = usbmuxd_connect(device->handle, dst_port); | 123 | int sfd = usbmuxd_connect(device->handle, dst_port); |
| 123 | if (sfd < 0) { | 124 | if (sfd < 0) { |
| 124 | return IPHONE_E_UNKNOWN_ERROR; //ret; | 125 | return NP_E_UNKNOWN_ERROR; |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); | 128 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); |
| @@ -132,17 +133,17 @@ iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t | |||
| 132 | client_loc->notifier = NULL; | 133 | client_loc->notifier = NULL; |
| 133 | 134 | ||
| 134 | *client = client_loc; | 135 | *client = client_loc; |
| 135 | return IPHONE_E_SUCCESS; | 136 | return NP_E_SUCCESS; |
| 136 | } | 137 | } |
| 137 | 138 | ||
| 138 | /** Disconnects an NP client from the phone. | 139 | /** Disconnects an NP client from the phone. |
| 139 | * | 140 | * |
| 140 | * @param client The client to disconnect. | 141 | * @param client The client to disconnect. |
| 141 | */ | 142 | */ |
| 142 | iphone_error_t np_free_client ( np_client_t client ) | 143 | np_error_t np_client_free(np_client_t client) |
| 143 | { | 144 | { |
| 144 | if (!client) | 145 | if (!client) |
| 145 | return IPHONE_E_INVALID_ARG; | 146 | return NP_E_INVALID_ARG; |
| 146 | 147 | ||
| 147 | usbmuxd_disconnect(client->sfd); | 148 | usbmuxd_disconnect(client->sfd); |
| 148 | client->sfd = -1; | 149 | client->sfd = -1; |
| @@ -155,7 +156,7 @@ iphone_error_t np_free_client ( np_client_t client ) | |||
| 155 | } | 156 | } |
| 156 | free(client); | 157 | free(client); |
| 157 | 158 | ||
| 158 | return IPHONE_E_SUCCESS; | 159 | return NP_E_SUCCESS; |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 161 | /** Sends a notification to the device's Notification Proxy. | 162 | /** Sends a notification to the device's Notification Proxy. |
| @@ -167,10 +168,10 @@ iphone_error_t np_free_client ( np_client_t client ) | |||
| 167 | * @param client The client to send to | 168 | * @param client The client to send to |
| 168 | * @param notification The notification message to send | 169 | * @param notification The notification message to send |
| 169 | */ | 170 | */ |
| 170 | iphone_error_t np_post_notification( np_client_t client, const char *notification ) | 171 | np_error_t np_post_notification(np_client_t client, const char *notification) |
| 171 | { | 172 | { |
| 172 | if (!client || !notification) { | 173 | if (!client || !notification) { |
| 173 | return IPHONE_E_INVALID_ARG; | 174 | return NP_E_INVALID_ARG; |
| 174 | } | 175 | } |
| 175 | np_lock(client); | 176 | np_lock(client); |
| 176 | 177 | ||
| @@ -180,7 +181,7 @@ iphone_error_t np_post_notification( np_client_t client, const char *notificatio | |||
| 180 | plist_add_sub_key_el(dict, "Name"); | 181 | plist_add_sub_key_el(dict, "Name"); |
| 181 | plist_add_sub_string_el(dict, notification); | 182 | plist_add_sub_string_el(dict, notification); |
| 182 | 183 | ||
| 183 | iphone_error_t res = np_plist_send(client, dict); | 184 | np_error_t res = np_plist_send(client, dict); |
| 184 | plist_free(dict); | 185 | plist_free(dict); |
| 185 | 186 | ||
| 186 | dict = plist_new_dict(); | 187 | dict = plist_new_dict(); |
| @@ -190,7 +191,7 @@ iphone_error_t np_post_notification( np_client_t client, const char *notificatio | |||
| 190 | res = np_plist_send(client, dict); | 191 | res = np_plist_send(client, dict); |
| 191 | plist_free(dict); | 192 | plist_free(dict); |
| 192 | 193 | ||
| 193 | if (res != IPHONE_E_SUCCESS) { | 194 | if (res != NP_E_SUCCESS) { |
| 194 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); | 195 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); |
| 195 | } | 196 | } |
| 196 | 197 | ||
| @@ -203,10 +204,10 @@ iphone_error_t np_post_notification( np_client_t client, const char *notificatio | |||
| 203 | * @param client The client to send to | 204 | * @param client The client to send to |
| 204 | * @param notification The notifications that should be observed. | 205 | * @param notification The notifications that should be observed. |
| 205 | */ | 206 | */ |
| 206 | iphone_error_t np_observe_notification( np_client_t client, const char *notification ) | 207 | np_error_t np_observe_notification( np_client_t client, const char *notification ) |
| 207 | { | 208 | { |
| 208 | if (!client || !notification) { | 209 | if (!client || !notification) { |
| 209 | return IPHONE_E_INVALID_ARG; | 210 | return NP_E_INVALID_ARG; |
| 210 | } | 211 | } |
| 211 | np_lock(client); | 212 | np_lock(client); |
| 212 | 213 | ||
| @@ -216,8 +217,8 @@ iphone_error_t np_observe_notification( np_client_t client, const char *notifica | |||
| 216 | plist_add_sub_key_el(dict, "Name"); | 217 | plist_add_sub_key_el(dict, "Name"); |
| 217 | plist_add_sub_string_el(dict, notification); | 218 | plist_add_sub_string_el(dict, notification); |
| 218 | 219 | ||
| 219 | iphone_error_t res = np_plist_send(client, dict); | 220 | np_error_t res = np_plist_send(client, dict); |
| 220 | if (res != IPHONE_E_SUCCESS) { | 221 | if (res != NP_E_SUCCESS) { |
| 221 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); | 222 | log_debug_msg("%s: Error sending XML plist to device!\n", __func__); |
| 222 | } | 223 | } |
| 223 | plist_free(dict); | 224 | plist_free(dict); |
| @@ -245,14 +246,14 @@ iphone_error_t np_observe_notification( np_client_t client, const char *notifica | |||
| 245 | * terminating NULL entry. However this parameter can be NULL; in this case, | 246 | * terminating NULL entry. However this parameter can be NULL; in this case, |
| 246 | * the default set of notifications will be used. | 247 | * the default set of notifications will be used. |
| 247 | */ | 248 | */ |
| 248 | iphone_error_t np_observe_notifications( np_client_t client, const char **notification_spec ) | 249 | np_error_t np_observe_notifications(np_client_t client, const char **notification_spec) |
| 249 | { | 250 | { |
| 250 | int i = 0; | 251 | int i = 0; |
| 251 | iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; | 252 | np_error_t res = NP_E_UNKNOWN_ERROR; |
| 252 | const char **notifications = notification_spec; | 253 | const char **notifications = notification_spec; |
| 253 | 254 | ||
| 254 | if (!client) { | 255 | if (!client) { |
| 255 | return IPHONE_E_INVALID_ARG; | 256 | return NP_E_INVALID_ARG; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| 258 | if (!notifications) { | 259 | if (!notifications) { |
| @@ -261,7 +262,7 @@ iphone_error_t np_observe_notifications( np_client_t client, const char **notifi | |||
| 261 | 262 | ||
| 262 | while (notifications[i]) { | 263 | while (notifications[i]) { |
| 263 | res = np_observe_notification(client, notifications[i]); | 264 | res = np_observe_notification(client, notifications[i]); |
| 264 | if (res != IPHONE_E_SUCCESS) { | 265 | if (res != NP_E_SUCCESS) { |
| 265 | break; | 266 | break; |
| 266 | } | 267 | } |
| 267 | i++; | 268 | i++; |
| @@ -277,24 +278,22 @@ iphone_error_t np_observe_notifications( np_client_t client, const char **notifi | |||
| 277 | * @param notification Pointer to a buffer that will be allocated and filled | 278 | * @param notification Pointer to a buffer that will be allocated and filled |
| 278 | * with the notification that has been received. | 279 | * with the notification that has been received. |
| 279 | * | 280 | * |
| 280 | * @return IPHONE_E_SUCCESS if a notification has been received, | 281 | * @return 0 if a notification has been received or nothing has been received, |
| 281 | * IPHONE_E_TIMEOUT if nothing has been received, | ||
| 282 | * or an error value if an error occured. | 282 | * or an error value if an error occured. |
| 283 | * | 283 | * |
| 284 | * @note You probably want to check out np_set_notify_callback | 284 | * @note You probably want to check out np_set_notify_callback |
| 285 | * @see np_set_notify_callback | 285 | * @see np_set_notify_callback |
| 286 | */ | 286 | */ |
| 287 | static iphone_error_t np_get_notification( np_client_t client, char **notification ) | 287 | static int np_get_notification(np_client_t client, char **notification) |
| 288 | { | 288 | { |
| 289 | uint32_t bytes = 0; | 289 | uint32_t bytes = 0; |
| 290 | iphone_error_t res; | 290 | int res = 0; |
| 291 | uint32_t pktlen = 0; | 291 | uint32_t pktlen = 0; |
| 292 | char *XML_content = NULL; | 292 | char *XML_content = NULL; |
| 293 | plist_t dict = NULL; | 293 | plist_t dict = NULL; |
| 294 | 294 | ||
| 295 | if (!client || client->sfd < 0 || *notification) { | 295 | if (!client || client->sfd < 0 || *notification) |
| 296 | return IPHONE_E_INVALID_ARG; | 296 | return -1; |
| 297 | } | ||
| 298 | 297 | ||
| 299 | np_lock(client); | 298 | np_lock(client); |
| 300 | 299 | ||
| @@ -302,7 +301,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati | |||
| 302 | log_debug_msg("NotificationProxy: initial read=%i\n", bytes); | 301 | log_debug_msg("NotificationProxy: initial read=%i\n", bytes); |
| 303 | if (bytes < 4) { | 302 | if (bytes < 4) { |
| 304 | log_debug_msg("NotificationProxy: no notification received!\n"); | 303 | log_debug_msg("NotificationProxy: no notification received!\n"); |
| 305 | res = IPHONE_E_TIMEOUT; | 304 | res = 0; |
| 306 | } else { | 305 | } else { |
| 307 | if ((char)pktlen == 0) { | 306 | if ((char)pktlen == 0) { |
| 308 | pktlen = ntohl(pktlen); | 307 | pktlen = ntohl(pktlen); |
| @@ -312,7 +311,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati | |||
| 312 | 311 | ||
| 313 | usbmuxd_recv_timeout(client->sfd, XML_content, pktlen, &bytes, 1000); | 312 | usbmuxd_recv_timeout(client->sfd, XML_content, pktlen, &bytes, 1000); |
| 314 | if (bytes <= 0) { | 313 | if (bytes <= 0) { |
| 315 | res = IPHONE_E_UNKNOWN_ERROR; | 314 | res = -1; |
| 316 | } else { | 315 | } else { |
| 317 | log_debug_msg("NotificationProxy: received data:\n"); | 316 | log_debug_msg("NotificationProxy: received data:\n"); |
| 318 | log_debug_buffer(XML_content, pktlen); | 317 | log_debug_buffer(XML_content, pktlen); |
| @@ -320,7 +319,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati | |||
| 320 | plist_from_xml(XML_content, bytes, &dict); | 319 | plist_from_xml(XML_content, bytes, &dict); |
| 321 | if (!dict) { | 320 | if (!dict) { |
| 322 | np_unlock(client); | 321 | np_unlock(client); |
| 323 | return IPHONE_E_PLIST_ERROR; | 322 | return -2; |
| 324 | } | 323 | } |
| 325 | 324 | ||
| 326 | plist_t cmd_key_node = plist_find_node_by_key(dict, "Command"); | 325 | plist_t cmd_key_node = plist_find_node_by_key(dict, "Command"); |
| @@ -345,21 +344,21 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati | |||
| 345 | plist_get_string_val(name_value_node, &name_value); | 344 | plist_get_string_val(name_value_node, &name_value); |
| 346 | } | 345 | } |
| 347 | 346 | ||
| 348 | res = IPHONE_E_PLIST_ERROR; | 347 | res = -2; |
| 349 | if (name_key && name_value && !strcmp(name_key, "Name")) { | 348 | if (name_key && name_value && !strcmp(name_key, "Name")) { |
| 350 | *notification = name_value; | 349 | *notification = name_value; |
| 351 | log_debug_msg("%s: got notification %s\n", __func__, name_value); | 350 | log_debug_msg("%s: got notification %s\n", __func__, name_value); |
| 352 | res = IPHONE_E_SUCCESS; | 351 | res = 0; |
| 353 | } | 352 | } |
| 354 | free(name_key); | 353 | free(name_key); |
| 355 | } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { | 354 | } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { |
| 356 | log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__); | 355 | log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__); |
| 357 | res = IPHONE_E_UNKNOWN_ERROR; | 356 | res = -1; |
| 358 | } else if (cmd_value) { | 357 | } else if (cmd_value) { |
| 359 | log_debug_msg("%d: unknown NotificationProxy command '%s' received!\n", __func__); | 358 | log_debug_msg("%d: unknown NotificationProxy command '%s' received!\n", __func__); |
| 360 | res = IPHONE_E_UNKNOWN_ERROR; | 359 | res = -1; |
| 361 | } else { | 360 | } else { |
| 362 | res = IPHONE_E_PLIST_ERROR; | 361 | res = -2; |
| 363 | } | 362 | } |
| 364 | if (cmd_value) { | 363 | if (cmd_value) { |
| 365 | free(cmd_value); | 364 | free(cmd_value); |
| @@ -370,7 +369,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati | |||
| 370 | XML_content = NULL; | 369 | XML_content = NULL; |
| 371 | } | 370 | } |
| 372 | } else { | 371 | } else { |
| 373 | res = IPHONE_E_UNKNOWN_ERROR; | 372 | res = -1; |
| 374 | } | 373 | } |
| 375 | } | 374 | } |
| 376 | 375 | ||
| @@ -416,15 +415,15 @@ gpointer np_notifier( gpointer arg ) | |||
| 416 | * @param notify_cb pointer to a callback function or NULL to de-register a | 415 | * @param notify_cb pointer to a callback function or NULL to de-register a |
| 417 | * previously set callback function | 416 | * previously set callback function |
| 418 | * | 417 | * |
| 419 | * @return IPHONE_E_SUCCESS when the callback was successfully registered, | 418 | * @return NP_E_SUCCESS when the callback was successfully registered, |
| 420 | * or an error value when an error occured. | 419 | * or an error value when an error occured. |
| 421 | */ | 420 | */ |
| 422 | iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) | 421 | np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) |
| 423 | { | 422 | { |
| 424 | if (!client) { | 423 | if (!client) |
| 425 | return IPHONE_E_INVALID_ARG; | 424 | return NP_E_INVALID_ARG; |
| 426 | } | 425 | |
| 427 | iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; | 426 | np_error_t res = NP_E_UNKNOWN_ERROR; |
| 428 | 427 | ||
| 429 | np_lock(client); | 428 | np_lock(client); |
| 430 | if (client->notifier) { | 429 | if (client->notifier) { |
| @@ -444,7 +443,7 @@ iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify | |||
| 444 | 443 | ||
| 445 | client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); | 444 | client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); |
| 446 | if (client->notifier) { | 445 | if (client->notifier) { |
| 447 | res = IPHONE_E_SUCCESS; | 446 | res = NP_E_SUCCESS; |
| 448 | } | 447 | } |
| 449 | } | 448 | } |
| 450 | } else { | 449 | } else { |
