summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/Makefile.am2
-rw-r--r--docs/idevicenotificationproxy.133
-rw-r--r--tools/Makefile.am7
-rw-r--r--tools/idevicenotificationproxy.c257
4 files changed, 297 insertions, 2 deletions
diff --git a/docs/Makefile.am b/docs/Makefile.am
index e9fc21c..d788297 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -1,4 +1,4 @@
1man_MANS = idevice_id.1 ideviceinfo.1 idevicesyslog.1 idevicebackup.1 idevicebackup2.1 ideviceimagemounter.1 idevicescreenshot.1 idevicepair.1 ideviceenterrecovery.1 idevicedate.1 ideviceprovision.1 idevicedebugserverproxy.1 idevicediagnostics.1 idevicecrashreport.1 idevicename.1 idevicedebug.1 1man_MANS = idevice_id.1 ideviceinfo.1 idevicesyslog.1 idevicebackup.1 idevicebackup2.1 ideviceimagemounter.1 idevicescreenshot.1 idevicepair.1 ideviceenterrecovery.1 idevicedate.1 ideviceprovision.1 idevicedebugserverproxy.1 idevicediagnostics.1 idevicecrashreport.1 idevicename.1 idevicedebug.1 idevicenotificationproxy.1
2 2
3EXTRA_DIST = $(man_MANS) 3EXTRA_DIST = $(man_MANS)
4 4
diff --git a/docs/idevicenotificationproxy.1 b/docs/idevicenotificationproxy.1
new file mode 100644
index 0000000..d7ecb32
--- /dev/null
+++ b/docs/idevicenotificationproxy.1
@@ -0,0 +1,33 @@
1.TH "idevicenotificationproxy" 1
2.SH NAME
3idevicenotificationproxy \- Post or observe notifications on a device.
4.SH SYNOPSIS
5.B idevicenotificationproxy
6[OPTIONS] COMMAND
7
8.SH DESCRIPTION
9
10Post or observe notifications on an iOS device from the command line.
11
12.SH OPTIONS
13.TP
14.B \-u, \-\-udid UDID
15target specific device by its 40-digit device UDID.
16.TP
17.B \-d, \-\-debug
18enable communication debugging.
19.TP
20.B \-h, \-\-help
21prints usage information.
22
23.SH COMMANDS
24.TP
25.B post ID [ID...]
26post notification IDs to device and exit.
27.TP
28.B observe ID [ID...]
29observe notification IDs in the foreground until CTRL+C or signal is received.
30
31.SH AUTHORS
32
33Martin Szulecki
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 8cda9f5..698e083 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -3,7 +3,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgcrypt_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgcrypt_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgcrypt_LIBS) $(openssl_LIBS) $(libplist_LIBS) 4AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgcrypt_LIBS) $(openssl_LIBS) $(libplist_LIBS)
5 5
6bin_PROGRAMS = idevice_id ideviceinfo idevicename idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy idevicediagnostics idevicedebug 6bin_PROGRAMS = idevice_id ideviceinfo idevicename idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy idevicediagnostics idevicedebug idevicenotificationproxy
7 7
8ideviceinfo_SOURCES = ideviceinfo.c 8ideviceinfo_SOURCES = ideviceinfo.c
9ideviceinfo_CFLAGS = $(AM_CFLAGS) 9ideviceinfo_CFLAGS = $(AM_CFLAGS)
@@ -80,6 +80,11 @@ idevicedebug_CFLAGS = $(AM_CFLAGS)
80idevicedebug_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) 80idevicedebug_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS)
81idevicedebug_LDADD = $(top_builddir)/src/libimobiledevice.la 81idevicedebug_LDADD = $(top_builddir)/src/libimobiledevice.la
82 82
83idevicenotificationproxy_SOURCES = idevicenotificationproxy.c
84idevicenotificationproxy_CFLAGS = $(AM_CFLAGS)
85idevicenotificationproxy_LDFLAGS = $(AM_LDFLAGS)
86idevicenotificationproxy_LDADD = $(top_builddir)/src/libimobiledevice.la
87
83if !WIN32 88if !WIN32
84bin_PROGRAMS += idevicecrashreport 89bin_PROGRAMS += idevicecrashreport
85idevicecrashreport_SOURCES = idevicecrashreport.c 90idevicecrashreport_SOURCES = idevicecrashreport.c
diff --git a/tools/idevicenotificationproxy.c b/tools/idevicenotificationproxy.c
new file mode 100644
index 0000000..15a3ba8
--- /dev/null
+++ b/tools/idevicenotificationproxy.c
@@ -0,0 +1,257 @@
1/*
2 * idevicenotificationproxy.c
3 * Simple client for the notification_proxy service
4 *
5 * Copyright (c) 2009-2015 Martin Szulecki All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
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
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25#include <signal.h>
26#include <stdlib.h>
27
28#ifdef WIN32
29#include <windows.h>
30#define sleep(x) Sleep(x*1000)
31#else
32#include <unistd.h>
33#endif
34
35#include <libimobiledevice/libimobiledevice.h>
36#include <libimobiledevice/lockdown.h>
37#include <libimobiledevice/notification_proxy.h>
38
39enum cmd_mode {
40 CMD_NONE = 0,
41 CMD_OBSERVE,
42 CMD_POST
43};
44
45static int quit_flag = 0;
46
47/**
48 * signal handler function for cleaning up properly
49 */
50static void clean_exit(int sig)
51{
52 fprintf(stderr, "Exiting...\n");
53 quit_flag++;
54}
55
56static void print_usage(int argc, char **argv)
57{
58 char *name = NULL;
59
60 name = strrchr(argv[0], '/');
61 printf("Usage: %s [OPTIONS] COMMAND\n", (name ? name + 1: argv[0]));
62 printf("Post or observe notifications on a device.\n\n");
63 printf(" Where COMMAND is one of:\n");
64 printf(" post ID [...]\t\tpost notification IDs to device and exit\n");
65 printf(" observe ID [...]\tobserve notification IDs in the foreground until CTRL+C or signal is received\n");
66 printf("\n");
67 printf(" The following OPTIONS are accepted:\n");
68 printf(" -d, --debug\t\tenable communication debugging\n");
69 printf(" -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n");
70 printf(" -h, --help\t\tprints usage information\n");
71 printf("\n");
72}
73
74static void notify_cb(const char *notification, void *user_data)
75{
76 printf("> %s\n", notification);
77}
78
79int main(int argc, char *argv[])
80{
81 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
82 lockdownd_service_descriptor_t service = NULL;
83 lockdownd_client_t client = NULL;
84 idevice_t device = NULL;
85 np_client_t gnp = NULL;
86
87 int result = -1;
88 int i;
89 const char* udid = NULL;
90 int cmd = CMD_NONE;
91 char* cmd_arg = NULL;
92
93 int count = 0;
94 char **nspec = NULL;
95 char **nspectmp = NULL;
96
97 signal(SIGINT, clean_exit);
98 signal(SIGTERM, clean_exit);
99#ifndef WIN32
100 signal(SIGQUIT, clean_exit);
101 signal(SIGPIPE, SIG_IGN);
102#endif
103
104 /* parse cmdline args */
105 for (i = 1; i < argc; i++) {
106 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
107 idevice_set_debug_level(1);
108 continue;
109 }
110 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) {
111 i++;
112 if (!argv[i] || (strlen(argv[i]) != 40)) {
113 print_usage(argc, argv);
114 result = 0;
115 goto cleanup;
116 }
117 udid = argv[i];
118 continue;
119 }
120 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
121 print_usage(argc, argv);
122 result = 0;
123 goto cleanup;
124 }
125 else if (!strcmp(argv[i], "post") || !strcmp(argv[i], "observe")) {
126 cmd = CMD_POST;
127 if (!strcmp(argv[i], "observe")) {
128 cmd = CMD_OBSERVE;
129 }
130
131 i++;
132
133 if (!argv[i] || argv[i] == NULL || (!strncmp(argv[i], "-", 1))) {
134 printf("Please supply a valid notification identifier.\n");
135 print_usage(argc, argv);
136 goto cleanup;
137 }
138
139 count = 0;
140 nspec = malloc(sizeof(char*) * (count+1));
141
142 while(1) {
143 if (argv[i] && (strlen(argv[i]) >= 2) && (strncmp(argv[i], "-", 1) != 0)) {
144 nspectmp = realloc(nspec, sizeof(char*) * (count+1));
145 nspectmp[count] = strdup(argv[i]);
146 nspec = nspectmp;
147 count = count+1;
148 i++;
149 } else {
150 i--;
151 break;
152 }
153 }
154
155 nspectmp = realloc(nspec, sizeof(char*) * (count+1));
156 nspectmp[count] = NULL;
157 nspec = nspectmp;
158 continue;
159 }
160 else {
161 print_usage(argc, argv);
162 return 0;
163 }
164 }
165
166 /* verify options */
167 if (cmd == CMD_NONE) {
168 print_usage(argc, argv);
169 goto cleanup;
170 }
171
172 if (IDEVICE_E_SUCCESS != idevice_new(&device, udid)) {
173 if (udid) {
174 printf("No device found with udid %s, is it plugged in?\n", udid);
175 } else {
176 printf("No device found, is it plugged in?\n");
177 }
178 goto cleanup;
179 }
180
181 if (LOCKDOWN_E_SUCCESS != (ret = lockdownd_client_new_with_handshake(device, &client, "idevicenotificationproxy"))) {
182 fprintf(stderr, "ERROR: Could not connect to lockdownd, error code %d\n", ret);
183 goto cleanup;
184 }
185
186 ret = lockdownd_start_service(client, NP_SERVICE_NAME, &service);
187
188 lockdownd_client_free(client);
189
190 if ((ret == LOCKDOWN_E_SUCCESS) && (service->port > 0)) {
191 if (np_client_new(device, service, &gnp) != NP_E_SUCCESS) {
192 printf("Could not connect to notification_proxy!\n");
193 result = -1;
194 } else {
195 np_set_notify_callback(gnp, notify_cb, NULL);
196
197 switch (cmd) {
198 case CMD_POST:
199 i = 0;
200 while(nspec[i] != NULL && i < (count+1)) {
201 printf("< posting \"%s\"\n", nspec[i]);
202 np_post_notification(gnp, nspec[i]);
203 i++;
204 }
205 break;
206 case CMD_OBSERVE:
207 default:
208 i = 0;
209 while(nspec[i] != NULL && i < (count+1)) {
210 printf("! observing \"%s\"\n", nspec[i]);
211 np_observe_notification(gnp, nspec[i]);
212 i++;
213 }
214
215 /* just sleep and wait for notifications */
216 while (!quit_flag) {
217 sleep(1);
218 }
219
220 break;
221 }
222
223 result = EXIT_SUCCESS;
224
225 if (gnp) {
226 np_client_free(gnp);
227 gnp = NULL;
228 }
229 }
230 } else {
231 printf("Could not start notification_proxy service on device.\n");
232 }
233
234 if (service) {
235 lockdownd_service_descriptor_free(service);
236 service = NULL;
237 }
238
239cleanup:
240 if (nspec) {
241 i = 0;
242 while(nspec[i] != NULL && i < (count+1)) {
243 free(nspec[i]);
244 i++;
245 }
246 free(nspec);
247 }
248
249 if (cmd_arg) {
250 free(cmd_arg);
251 }
252
253 if (device)
254 idevice_free(device);
255
256 return result;
257}