summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dev/main.c40
-rw-r--r--include/Makefile.am2
-rw-r--r--include/libiphone/libiphone.h33
-rw-r--r--include/libiphone/notification_proxy.h46
-rw-r--r--src/NotificationProxy.c39
-rw-r--r--src/NotificationProxy.h7
6 files changed, 80 insertions, 87 deletions
diff --git a/dev/main.c b/dev/main.c
index fe340ff..d39baa7 100644
--- a/dev/main.c
+++ b/dev/main.c
@@ -26,6 +26,7 @@
26 26
27#include <libiphone/libiphone.h> 27#include <libiphone/libiphone.h>
28#include <libiphone/afc.h> 28#include <libiphone/afc.h>
29#include <libiphone/notification_proxy.h>
29#include "../src/utils.h" 30#include "../src/utils.h"
30 31
31void notifier(const char *notification) 32void notifier(const char *notification)
@@ -38,16 +39,16 @@ void notifier(const char *notification)
38void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification) 39void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification)
39{ 40{
40 int nport = 0; 41 int nport = 0;
41 iphone_np_client_t np; 42 np_client_t np;
42 43
43 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); 44 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport);
44 if (nport) { 45 if (nport) {
45 printf("::::::::::::::: np was started ::::::::::::\n"); 46 printf("::::::::::::::: np was started ::::::::::::\n");
46 iphone_np_new_client(phone, nport, &np); 47 np_new_client(phone, nport, &np);
47 if (np) { 48 if (np) {
48 printf("::::::::: PostNotification %s\n", notification); 49 printf("::::::::: PostNotification %s\n", notification);
49 iphone_np_post_notification(np, notification); 50 np_post_notification(np, notification);
50 iphone_np_free_client(np); 51 np_free_client(np);
51 } 52 }
52 } else { 53 } else {
53 printf("::::::::::::::: np was NOT started ::::::::::::\n"); 54 printf("::::::::::::::: np was NOT started ::::::::::::\n");
@@ -61,7 +62,7 @@ int main(int argc, char *argv[])
61 iphone_lckd_client_t control = NULL; 62 iphone_lckd_client_t control = NULL;
62 iphone_device_t phone = NULL; 63 iphone_device_t phone = NULL;
63 uint64_t lockfile = 0; 64 uint64_t lockfile = 0;
64 iphone_np_client_t gnp = NULL; 65 np_client_t gnp = NULL;
65 66
66 if (argc > 1 && !strcasecmp(argv[1], "--debug")) { 67 if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
67 iphone_set_debug(1); 68 iphone_set_debug(1);
@@ -104,7 +105,7 @@ int main(int argc, char *argv[])
104 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); 105 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp);
105 if (npp) { 106 if (npp) {
106 printf("Notification Proxy started.\n"); 107 printf("Notification Proxy started.\n");
107 iphone_np_new_client(phone, npp, &gnp); 108 np_new_client(phone, npp, &gnp);
108 } else { 109 } else {
109 printf("ERROR: Notification proxy could not be started.\n"); 110 printf("ERROR: Notification proxy could not be started.\n");
110 } 111 }
@@ -115,8 +116,8 @@ int main(int argc, char *argv[])
115 NP_SYNC_RESUME_REQUEST, 116 NP_SYNC_RESUME_REQUEST,
116 NULL 117 NULL
117 }; 118 };
118 iphone_np_observe_notifications(gnp, nspec); 119 np_observe_notifications(gnp, nspec);
119 iphone_np_set_notify_callback(gnp, notifier); 120 np_set_notify_callback(gnp, notifier);
120 } 121 }
121 122
122 perform_notification(phone, control, NP_SYNC_WILL_START); 123 perform_notification(phone, control, NP_SYNC_WILL_START);
@@ -219,28 +220,7 @@ int main(int argc, char *argv[])
219 if (gnp && lockfile) { 220 if (gnp && lockfile) {
220 char *noti; 221 char *noti;
221 222
222 /*
223 noti = NULL;
224 iphone_np_get_notification(gnp, &noti);
225 if (noti) {
226 printf("------> received notification '%s'\n", noti);
227 free(noti);
228 }*/
229
230 printf("XXX sleeping\n"); 223 printf("XXX sleeping\n");
231 /*for (i = 0; i < 5; i++) {
232 noti = NULL;
233 printf("--- getting notification\n");
234 iphone_np_get_notification(gnp, &noti);
235 if (noti) {
236 printf("------> received notification '%s'\n", noti);
237 free(noti);
238 } else {
239 printf("---- no notification\n");
240 }
241 sleep(1);
242 }
243 */
244 sleep(5); 224 sleep(5);
245 225
246 //perform_notification(phone, control, NP_SYNC_DID_FINISH); 226 //perform_notification(phone, control, NP_SYNC_DID_FINISH);
@@ -253,7 +233,7 @@ int main(int argc, char *argv[])
253 } 233 }
254 234
255 if (gnp) { 235 if (gnp) {
256 iphone_np_free_client(gnp); 236 np_free_client(gnp);
257 gnp = NULL; 237 gnp = NULL;
258 } 238 }
259 239
diff --git a/include/Makefile.am b/include/Makefile.am
index 4c17261..d8ae1e4 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1 +1 @@
nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h libiphone/notification_proxy.h
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h
index 3f5d86c..456f000 100644
--- a/include/libiphone/libiphone.h
+++ b/include/libiphone/libiphone.h
@@ -63,9 +63,6 @@ typedef struct iphone_lckd_client_int *iphone_lckd_client_t;
63struct iphone_msync_client_int; 63struct iphone_msync_client_int;
64typedef struct iphone_msync_client_int *iphone_msync_client_t; 64typedef struct iphone_msync_client_int *iphone_msync_client_t;
65 65
66struct iphone_np_client_int;
67typedef struct iphone_np_client_int *iphone_np_client_t;
68
69//debug related functions 66//debug related functions
70#define DBGMASK_ALL 0xFFFF 67#define DBGMASK_ALL 0xFFFF
71#define DBGMASK_NONE 0x0000 68#define DBGMASK_NONE 0x0000
@@ -102,36 +99,6 @@ iphone_error_t iphone_msync_free_client(iphone_msync_client_t client);
102iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist); 99iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist);
103iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist); 100iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist);
104 101
105// NotificationProxy related
106// notifications for use with post_notification (client --> device)
107#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart"
108#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart"
109#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish"
110
111// notifications for use with observe_notification (device --> client)
112#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest"
113#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest"
114#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest"
115#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed"
116#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed"
117#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation"
118#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed"
119#define NP_APP_INSTALLED "com.apple.mobile.application_installed"
120#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled"
121
122iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client );
123iphone_error_t iphone_np_free_client ( iphone_np_client_t client );
124
125iphone_error_t iphone_np_post_notification ( iphone_np_client_t client, const char *notification );
126
127iphone_error_t iphone_np_observe_notification ( iphone_np_client_t client, const char *notification );
128iphone_error_t iphone_np_observe_notifications ( iphone_np_client_t client, const char **notification_spec );
129iphone_error_t iphone_np_get_notification ( iphone_np_client_t client, char **notification );
130
131typedef void (*iphone_np_notify_cb_t) ( const char *notification );
132
133iphone_error_t iphone_np_set_notify_callback ( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb );
134
135#ifdef __cplusplus 102#ifdef __cplusplus
136} 103}
137#endif 104#endif
diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h
new file mode 100644
index 0000000..9412b4f
--- /dev/null
+++ b/include/libiphone/notification_proxy.h
@@ -0,0 +1,46 @@
1#ifndef NOTIFICATION_PROXY_H
2#define NOTIFICATION_PROXY_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <libiphone/libiphone.h>
9
10struct np_client_int;
11typedef struct np_client_int *np_client_t;
12
13// NotificationProxy related
14// notifications for use with post_notification (client --> device)
15#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart"
16#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart"
17#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish"
18
19// notifications for use with observe_notification (device --> client)
20#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest"
21#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest"
22#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest"
23#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed"
24#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed"
25#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation"
26#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed"
27#define NP_APP_INSTALLED "com.apple.mobile.application_installed"
28#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled"
29
30iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client );
31iphone_error_t np_free_client ( np_client_t client );
32
33iphone_error_t np_post_notification ( np_client_t client, const char *notification );
34
35iphone_error_t np_observe_notification ( np_client_t client, const char *notification );
36iphone_error_t np_observe_notifications ( np_client_t client, const char **notification_spec );
37
38typedef void (*np_notify_cb_t) ( const char *notification );
39
40iphone_error_t np_set_notify_callback ( np_client_t client, np_notify_cb_t notify_cb );
41
42#ifdef __cplusplus
43}
44#endif
45
46#endif
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index 6fc048c..374420c 100644
--- a/src/NotificationProxy.c
+++ b/src/NotificationProxy.c
@@ -25,18 +25,19 @@
25#include <arpa/inet.h> 25#include <arpa/inet.h>
26#include <plist/plist.h> 26#include <plist/plist.h>
27#include "NotificationProxy.h" 27#include "NotificationProxy.h"
28#include "iphone.h"
28#include "utils.h" 29#include "utils.h"
29 30
30struct np_thread { 31struct np_thread {
31 iphone_np_client_t client; 32 np_client_t client;
32 iphone_np_notify_cb_t cbfunc; 33 np_notify_cb_t cbfunc;
33}; 34};
34 35
35/** Locks an NP client, done for thread safety stuff. 36/** Locks an NP client, done for thread safety stuff.
36 * 37 *
37 * @param client The NP 38 * @param client The NP
38 */ 39 */
39static void np_lock(iphone_np_client_t client) 40static void np_lock(np_client_t client)
40{ 41{
41 log_debug_msg("NP: Locked\n"); 42 log_debug_msg("NP: Locked\n");
42 g_mutex_lock(client->mutex); 43 g_mutex_lock(client->mutex);
@@ -46,7 +47,7 @@ static void np_lock(iphone_np_client_t client)
46 * 47 *
47 * @param client The NP 48 * @param client The NP
48 */ 49 */
49static void np_unlock(iphone_np_client_t client) 50static void np_unlock(np_client_t client)
50{ 51{
51 log_debug_msg("NP: Unlocked\n"); 52 log_debug_msg("NP: Unlocked\n");
52 g_mutex_unlock(client->mutex); 53 g_mutex_unlock(client->mutex);
@@ -61,7 +62,7 @@ static void np_unlock(iphone_np_client_t client)
61 * 62 *
62 * @return IPHONE_E_SUCCESS or an error code. 63 * @return IPHONE_E_SUCCESS or an error code.
63 */ 64 */
64static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) 65static iphone_error_t np_plist_send(np_client_t client, plist_t dict)
65{ 66{
66 char *XML_content = NULL; 67 char *XML_content = NULL;
67 uint32_t length = 0; 68 uint32_t length = 0;
@@ -108,7 +109,7 @@ static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict)
108 * 109 *
109 * @return A handle to the newly-connected client or NULL upon error. 110 * @return A handle to the newly-connected client or NULL upon error.
110 */ 111 */
111iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client ) 112iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client )
112{ 113{
113 //makes sure thread environment is available 114 //makes sure thread environment is available
114 if (!g_thread_supported()) 115 if (!g_thread_supported())
@@ -123,7 +124,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho
123 return IPHONE_E_UNKNOWN_ERROR; //ret; 124 return IPHONE_E_UNKNOWN_ERROR; //ret;
124 } 125 }
125 126
126 iphone_np_client_t client_loc = (iphone_np_client_t) malloc(sizeof(struct iphone_np_client_int)); 127 np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int));
127 client_loc->sfd = sfd; 128 client_loc->sfd = sfd;
128 129
129 client_loc->mutex = g_mutex_new(); 130 client_loc->mutex = g_mutex_new();
@@ -138,7 +139,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho
138 * 139 *
139 * @param client The client to disconnect. 140 * @param client The client to disconnect.
140 */ 141 */
141iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) 142iphone_error_t np_free_client ( np_client_t client )
142{ 143{
143 if (!client) 144 if (!client)
144 return IPHONE_E_INVALID_ARG; 145 return IPHONE_E_INVALID_ARG;
@@ -166,7 +167,7 @@ iphone_error_t iphone_np_free_client ( iphone_np_client_t client )
166 * @param client The client to send to 167 * @param client The client to send to
167 * @param notification The notification message to send 168 * @param notification The notification message to send
168 */ 169 */
169iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) 170iphone_error_t np_post_notification( np_client_t client, const char *notification )
170{ 171{
171 if (!client || !notification) { 172 if (!client || !notification) {
172 return IPHONE_E_INVALID_ARG; 173 return IPHONE_E_INVALID_ARG;
@@ -202,7 +203,7 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
202 * @param client The client to send to 203 * @param client The client to send to
203 * @param notification The notifications that should be observed. 204 * @param notification The notifications that should be observed.
204 */ 205 */
205iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const char *notification ) 206iphone_error_t np_observe_notification( np_client_t client, const char *notification )
206{ 207{
207 if (!client || !notification) { 208 if (!client || !notification) {
208 return IPHONE_E_INVALID_ARG; 209 return IPHONE_E_INVALID_ARG;
@@ -245,7 +246,7 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const
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 */
248iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const char **notification_spec ) 249iphone_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 iphone_error_t res = IPHONE_E_UNKNOWN_ERROR;
@@ -260,7 +261,7 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const
260 } 261 }
261 262
262 while (notifications[i]) { 263 while (notifications[i]) {
263 res = iphone_np_observe_notification(client, notifications[i]); 264 res = np_observe_notification(client, notifications[i]);
264 if (res != IPHONE_E_SUCCESS) { 265 if (res != IPHONE_E_SUCCESS) {
265 break; 266 break;
266 } 267 }
@@ -281,10 +282,10 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const
281 * IPHONE_E_TIMEOUT if nothing has been received, 282 * IPHONE_E_TIMEOUT if nothing has been received,
282 * or an error value if an error occured. 283 * or an error value if an error occured.
283 * 284 *
284 * @note You probably want to check out iphone_np_set_notify_callback 285 * @note You probably want to check out np_set_notify_callback
285 * @see iphone_np_set_notify_callback 286 * @see np_set_notify_callback
286 */ 287 */
287iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **notification ) 288static iphone_error_t np_get_notification( np_client_t client, char **notification )
288{ 289{
289 uint32_t bytes = 0; 290 uint32_t bytes = 0;
290 iphone_error_t res; 291 iphone_error_t res;
@@ -382,7 +383,7 @@ iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **not
382/** 383/**
383 * Internally used thread function. 384 * Internally used thread function.
384 */ 385 */
385gpointer iphone_np_notifier( gpointer arg ) 386gpointer np_notifier( gpointer arg )
386{ 387{
387 char *notification = NULL; 388 char *notification = NULL;
388 struct np_thread *npt = (struct np_thread*)arg; 389 struct np_thread *npt = (struct np_thread*)arg;
@@ -391,7 +392,7 @@ gpointer iphone_np_notifier( gpointer arg )
391 392
392 log_debug_msg("%s: starting callback.\n", __func__); 393 log_debug_msg("%s: starting callback.\n", __func__);
393 while (npt->client->sfd >= 0) { 394 while (npt->client->sfd >= 0) {
394 iphone_np_get_notification(npt->client, &notification); 395 np_get_notification(npt->client, &notification);
395 if (notification) { 396 if (notification) {
396 npt->cbfunc(notification); 397 npt->cbfunc(notification);
397 free(notification); 398 free(notification);
@@ -419,7 +420,7 @@ gpointer iphone_np_notifier( gpointer arg )
419 * @return IPHONE_E_SUCCESS when the callback was successfully registered, 420 * @return IPHONE_E_SUCCESS when the callback was successfully registered,
420 * or an error value when an error occured. 421 * or an error value when an error occured.
421 */ 422 */
422iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb ) 423iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb )
423{ 424{
424 if (!client) { 425 if (!client) {
425 return IPHONE_E_INVALID_ARG; 426 return IPHONE_E_INVALID_ARG;
@@ -442,7 +443,7 @@ iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_
442 npt->client = client; 443 npt->client = client;
443 npt->cbfunc = notify_cb; 444 npt->cbfunc = notify_cb;
444 445
445 client->notifier = g_thread_create(iphone_np_notifier, npt, TRUE, NULL); 446 client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL);
446 if (client->notifier) { 447 if (client->notifier) {
447 res = IPHONE_E_SUCCESS; 448 res = IPHONE_E_SUCCESS;
448 } 449 }
diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h
index afae98a..a10cde4 100644
--- a/src/NotificationProxy.h
+++ b/src/NotificationProxy.h
@@ -18,12 +18,11 @@
18 * License along with this library; if not, write to the Free Software 18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21#include "libiphone/libiphone.h" 21#include "libiphone/notification_proxy.h"
22#include "iphone.h"
23 22
24#include <glib.h> 23#include <glib.h>
25 24
26struct iphone_np_client_int { 25struct np_client_int {
27 int sfd; 26 int sfd;
28 GMutex *mutex; 27 GMutex *mutex;
29 GThread *notifier; 28 GThread *notifier;
@@ -42,4 +41,4 @@ static const char *np_default_notifications[10] = {
42 NULL 41 NULL
43}; 42};
44 43
45gpointer iphone_np_notifier( gpointer arg ); 44gpointer np_notifier( gpointer arg );