diff options
| author | 2009-05-10 08:27:53 -0700 | |
|---|---|---|
| committer | 2009-05-10 08:28:04 -0700 | |
| commit | 1351b686d450112ae55d26d81d9d59c5f542f12e (patch) | |
| tree | 442c7e48eb83f96a22f7c6d889e8fe26151d6cba /dev | |
| parent | e91caeb1c9929f9dc8af747bb3a2e52ec06b03af (diff) | |
| download | libimobiledevice-1351b686d450112ae55d26d81d9d59c5f542f12e.tar.gz libimobiledevice-1351b686d450112ae55d26d81d9d59c5f542f12e.tar.bz2 | |
NotificationProxy support added.0.9.0
[#27 state:resolved]
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/main.c | 95 |
1 files changed, 70 insertions, 25 deletions
| @@ -27,26 +27,14 @@ | |||
| 27 | #include <libiphone/libiphone.h> | 27 | #include <libiphone/libiphone.h> |
| 28 | #include "../src/utils.h" | 28 | #include "../src/utils.h" |
| 29 | 29 | ||
| 30 | void perform_syncWillStart(iphone_device_t phone, iphone_lckd_client_t control) | 30 | void notifier(const char *notification) |
| 31 | { | 31 | { |
| 32 | int nport = 0; | 32 | printf("---------------------------------------------------------\n"); |
| 33 | iphone_np_client_t np; | 33 | printf("------> Notification received: %s\n", notification); |
| 34 | 34 | printf("---------------------------------------------------------\n"); | |
| 35 | iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); | ||
| 36 | if (nport) { | ||
| 37 | printf("::::::::::::::: np was started ::::::::::::\n"); | ||
| 38 | iphone_np_new_client(phone, 3555, nport, &np); | ||
| 39 | if (np) { | ||
| 40 | printf("::::::::: PostNotification com.apple.itunes-mobdev.syncWillStart\n"); | ||
| 41 | iphone_np_post_notification(np, "com.apple.itunes-mobdev.syncWillStart"); | ||
| 42 | iphone_np_free_client(np); | ||
| 43 | } | ||
| 44 | } else { | ||
| 45 | printf("::::::::::::::: np was NOT started ::::::::::::\n"); | ||
| 46 | } | ||
| 47 | } | 35 | } |
| 48 | 36 | ||
| 49 | void perform_syncDidStart(iphone_device_t phone, iphone_lckd_client_t control) | 37 | void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification) |
| 50 | { | 38 | { |
| 51 | int nport = 0; | 39 | int nport = 0; |
| 52 | iphone_np_client_t np; | 40 | iphone_np_client_t np; |
| @@ -54,11 +42,10 @@ void perform_syncDidStart(iphone_device_t phone, iphone_lckd_client_t control) | |||
| 54 | iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); | 42 | iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); |
| 55 | if (nport) { | 43 | if (nport) { |
| 56 | printf("::::::::::::::: np was started ::::::::::::\n"); | 44 | printf("::::::::::::::: np was started ::::::::::::\n"); |
| 57 | sleep(1); | ||
| 58 | iphone_np_new_client(phone, 3555, nport, &np); | 45 | iphone_np_new_client(phone, 3555, nport, &np); |
| 59 | if (np) { | 46 | if (np) { |
| 60 | printf("::::::::: PostNotification com.apple.itunes-mobdev.syncDidStart\n"); | 47 | printf("::::::::: PostNotification %s\n", notification); |
| 61 | iphone_np_post_notification(np, "com.apple.itunes-mobdev.syncDidStart"); | 48 | iphone_np_post_notification(np, notification); |
| 62 | iphone_np_free_client(np); | 49 | iphone_np_free_client(np); |
| 63 | } | 50 | } |
| 64 | } else { | 51 | } else { |
| @@ -69,9 +56,11 @@ void perform_syncDidStart(iphone_device_t phone, iphone_lckd_client_t control) | |||
| 69 | int main(int argc, char *argv[]) | 56 | int main(int argc, char *argv[]) |
| 70 | { | 57 | { |
| 71 | int bytes = 0, port = 0, i = 0; | 58 | int bytes = 0, port = 0, i = 0; |
| 59 | int npp; | ||
| 72 | iphone_lckd_client_t control = NULL; | 60 | iphone_lckd_client_t control = NULL; |
| 73 | iphone_device_t phone = NULL; | 61 | iphone_device_t phone = NULL; |
| 74 | iphone_afc_file_t lockfile = NULL; | 62 | iphone_afc_file_t lockfile = NULL; |
| 63 | iphone_np_client_t gnp = NULL; | ||
| 75 | 64 | ||
| 76 | if (argc > 1 && !strcasecmp(argv[1], "--debug")) { | 65 | if (argc > 1 && !strcasecmp(argv[1], "--debug")) { |
| 77 | iphone_set_debug(1); | 66 | iphone_set_debug(1); |
| @@ -88,6 +77,7 @@ int main(int argc, char *argv[]) | |||
| 88 | 77 | ||
| 89 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | 78 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { |
| 90 | iphone_free_device(phone); | 79 | iphone_free_device(phone); |
| 80 | printf("Exiting.\n"); | ||
| 91 | return -1; | 81 | return -1; |
| 92 | } | 82 | } |
| 93 | 83 | ||
| @@ -97,20 +87,45 @@ int main(int argc, char *argv[]) | |||
| 97 | free(uid); | 87 | free(uid); |
| 98 | } | 88 | } |
| 99 | 89 | ||
| 90 | |||
| 91 | char *nnn = NULL; | ||
| 92 | if (IPHONE_E_SUCCESS == lockdownd_get_device_name(control, &nnn)) { | ||
| 93 | printf("DeviceName : %s\n", nnn); | ||
| 94 | free(nnn); | ||
| 95 | } | ||
| 96 | |||
| 100 | iphone_lckd_start_service(control, "com.apple.afc", &port); | 97 | iphone_lckd_start_service(control, "com.apple.afc", &port); |
| 101 | 98 | ||
| 102 | if (port) { | 99 | if (port) { |
| 103 | iphone_afc_client_t afc = NULL; | 100 | iphone_afc_client_t afc = NULL; |
| 104 | iphone_afc_new_client(phone, 3432, port, &afc); | 101 | iphone_afc_new_client(phone, 3432, port, &afc); |
| 105 | if (afc) { | 102 | if (afc) { |
| 106 | perform_syncWillStart(phone, control); | 103 | iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); |
| 104 | if (npp) { | ||
| 105 | printf("Notification Proxy started.\n"); | ||
| 106 | iphone_np_new_client(phone, 3756, npp, &gnp); | ||
| 107 | } else { | ||
| 108 | printf("ERROR: Notification proxy could not be started.\n"); | ||
| 109 | } | ||
| 110 | if (gnp) { | ||
| 111 | const char *nspec[4] = { | ||
| 112 | NP_SYNC_CANCEL_REQUEST, | ||
| 113 | NP_SYNC_SUSPEND_REQUEST, | ||
| 114 | NP_SYNC_RESUME_REQUEST, | ||
| 115 | NULL | ||
| 116 | }; | ||
| 117 | iphone_np_observe_notifications(gnp, nspec); | ||
| 118 | //iphone_np_set_notify_callback(gnp, notifier); | ||
| 119 | } | ||
| 120 | |||
| 121 | perform_notification(phone, control, NP_SYNC_WILL_START); | ||
| 107 | 122 | ||
| 108 | iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); | 123 | iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); |
| 109 | if (lockfile) { | 124 | if (lockfile) { |
| 110 | printf("locking file\n"); | 125 | printf("locking file\n"); |
| 111 | iphone_afc_lock_file(afc, lockfile, 2 | 4); | 126 | iphone_afc_lock_file(afc, lockfile, 2 | 4); |
| 112 | 127 | ||
| 113 | perform_syncDidStart(phone, control); | 128 | perform_notification(phone, control, NP_SYNC_DID_START); |
| 114 | } | 129 | } |
| 115 | 130 | ||
| 116 | char **dirs = NULL; | 131 | char **dirs = NULL; |
| @@ -123,6 +138,8 @@ int main(int argc, char *argv[]) | |||
| 123 | } | 138 | } |
| 124 | 139 | ||
| 125 | g_strfreev(dirs); | 140 | g_strfreev(dirs); |
| 141 | |||
| 142 | dirs = NULL; | ||
| 126 | iphone_afc_get_devinfo(afc, &dirs); | 143 | iphone_afc_get_devinfo(afc, &dirs); |
| 127 | if (dirs) { | 144 | if (dirs) { |
| 128 | for (i = 0; dirs[i]; i += 2) { | 145 | for (i = 0; dirs[i]; i += 2) { |
| @@ -189,9 +206,31 @@ int main(int argc, char *argv[]) | |||
| 189 | iphone_afc_close_file(afc, my_file); | 206 | iphone_afc_close_file(afc, my_file); |
| 190 | } | 207 | } |
| 191 | 208 | ||
| 192 | if (lockfile) { | 209 | if (gnp && lockfile) { |
| 193 | printf("XXX sleeping 2 seconds\n"); | 210 | char *noti; |
| 194 | sleep(2); | 211 | |
| 212 | noti = NULL; | ||
| 213 | iphone_np_get_notification(gnp, ¬i); | ||
| 214 | if (noti) { | ||
| 215 | printf("------> received notification '%s'\n", noti); | ||
| 216 | free(noti); | ||
| 217 | } | ||
| 218 | |||
| 219 | printf("XXX sleeping\n"); | ||
| 220 | for (i = 0; i < 5; i++) { | ||
| 221 | noti = NULL; | ||
| 222 | printf("--- getting notification\n"); | ||
| 223 | iphone_np_get_notification(gnp, ¬i); | ||
| 224 | if (noti) { | ||
| 225 | printf("------> received notification '%s'\n", noti); | ||
| 226 | free(noti); | ||
| 227 | } else { | ||
| 228 | printf("---- no notification\n"); | ||
| 229 | } | ||
| 230 | sleep(1); | ||
| 231 | } | ||
| 232 | |||
| 233 | //perform_notification(phone, control, NP_SYNC_DID_FINISH); | ||
| 195 | 234 | ||
| 196 | printf("XXX unlocking file\n"); | 235 | printf("XXX unlocking file\n"); |
| 197 | iphone_afc_lock_file(afc, lockfile, 8 | 4); | 236 | iphone_afc_lock_file(afc, lockfile, 8 | 4); |
| @@ -199,6 +238,12 @@ int main(int argc, char *argv[]) | |||
| 199 | printf("XXX closing file\n"); | 238 | printf("XXX closing file\n"); |
| 200 | iphone_afc_close_file(afc, lockfile); | 239 | iphone_afc_close_file(afc, lockfile); |
| 201 | } | 240 | } |
| 241 | |||
| 242 | if (gnp) { | ||
| 243 | iphone_np_free_client(gnp); | ||
| 244 | gnp = NULL; | ||
| 245 | } | ||
| 246 | |||
| 202 | iphone_afc_free_client(afc); | 247 | iphone_afc_free_client(afc); |
| 203 | } else { | 248 | } else { |
| 204 | printf("Start service failure.\n"); | 249 | printf("Start service failure.\n"); |
