summaryrefslogtreecommitdiffstats
path: root/dev/ideviceclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'dev/ideviceclient.c')
-rw-r--r--dev/ideviceclient.c252
1 files changed, 0 insertions, 252 deletions
diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c
deleted file mode 100644
index d952594..0000000
--- a/dev/ideviceclient.c
+++ /dev/null
@@ -1,252 +0,0 @@
1/*
2 * main.c
3 * Test program for testing several services.
4 *
5 * Copyright (c) 2008 Zach C. 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 <stdlib.h>
24#include <string.h>
25#include <errno.h>
26#include <glib.h>
27
28#include <libimobiledevice/libimobiledevice.h>
29#include <libimobiledevice/lockdown.h>
30#include <libimobiledevice/afc.h>
31#include <libimobiledevice/notification_proxy.h>
32
33static void notifier(const char *notification, void *userdata)
34{
35 printf("---------------------------------------------------------\n");
36 printf("------> Notification received: %s\n", notification);
37 printf("---------------------------------------------------------\n");
38}
39
40static void perform_notification(idevice_t phone, lockdownd_client_t client, const char *notification)
41{
42 uint16_t nport = 0;
43 np_client_t np;
44
45 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport);
46 if (nport) {
47 printf("::::::::::::::: np was started ::::::::::::\n");
48 np_client_new(phone, nport, &np);
49 if (np) {
50 printf("::::::::: PostNotification %s\n", notification);
51 np_post_notification(np, notification);
52 np_client_free(np);
53 }
54 } else {
55 printf("::::::::::::::: np was NOT started ::::::::::::\n");
56 }
57}
58
59int main(int argc, char *argv[])
60{
61 unsigned int bytes = 0;
62 uint16_t port = 0, i = 0;
63 uint16_t npp;
64 lockdownd_client_t client = NULL;
65 idevice_t phone = NULL;
66 uint64_t lockfile = 0;
67 np_client_t gnp = NULL;
68
69 if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
70 idevice_set_debug_level(1);
71 } else {
72 idevice_set_debug_level(0);
73 }
74
75 if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) {
76 printf("No device found, is it plugged in?\n");
77 return -1;
78 }
79
80 char *uuid = NULL;
81 if (IDEVICE_E_SUCCESS == idevice_get_uuid(phone, &uuid)) {
82 printf("DeviceUniqueID : %s\n", uuid);
83 }
84 if (uuid)
85 free(uuid);
86
87 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "ideviceclient")) {
88 idevice_free(phone);
89 printf("Exiting.\n");
90 return -1;
91 }
92
93 char *nnn = NULL;
94 if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) {
95 printf("DeviceName : %s\n", nnn);
96 free(nnn);
97 }
98
99 lockdownd_start_service(client, "com.apple.afc", &port);
100
101 if (port) {
102 afc_client_t afc = NULL;
103 afc_client_new(phone, port, &afc);
104 if (afc) {
105 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp);
106 if (npp) {
107 printf("Notification Proxy started.\n");
108 np_client_new(phone, npp, &gnp);
109 } else {
110 printf("ERROR: Notification proxy could not be started.\n");
111 }
112 if (gnp) {
113 const char *nspec[5] = {
114 NP_SYNC_CANCEL_REQUEST,
115 NP_SYNC_SUSPEND_REQUEST,
116 NP_SYNC_RESUME_REQUEST,
117 NP_ITDBPREP_DID_END,
118 NULL
119 };
120 np_observe_notifications(gnp, nspec);
121 np_set_notify_callback(gnp, notifier, NULL);
122 }
123
124 perform_notification(phone, client, NP_SYNC_WILL_START);
125
126 afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile);
127 if (lockfile) {
128 printf("locking file\n");
129 afc_file_lock(afc, lockfile, AFC_LOCK_EX);
130
131 perform_notification(phone, client, NP_SYNC_DID_START);
132 }
133
134 char **dirs = NULL;
135 afc_read_directory(afc, "/eafaedf", &dirs);
136 if (!dirs)
137 afc_read_directory(afc, "/", &dirs);
138 printf("Directory time.\n");
139 for (i = 0; dirs[i]; i++) {
140 printf("/%s\n", dirs[i]);
141 }
142
143 g_strfreev(dirs);
144
145 dirs = NULL;
146 afc_get_device_info(afc, &dirs);
147 if (dirs) {
148 for (i = 0; dirs[i]; i += 2) {
149 printf("%s: %s\n", dirs[i], dirs[i + 1]);
150 }
151 }
152 g_strfreev(dirs);
153
154 uint64_t my_file = 0;
155 char **info = NULL;
156 uint64_t fsize = 0;
157 if (AFC_E_SUCCESS == afc_get_file_info(afc, "/readme.libimobiledevice.fx", &info) && info) {
158 for (i = 0; info[i]; i += 2) {
159 printf("%s: %s\n", info[i], info[i+1]);
160 if (!strcmp(info[i], "st_size")) {
161 fsize = atoll(info[i+1]);
162 }
163 }
164 }
165
166 if (AFC_E_SUCCESS ==
167 afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) {
168 printf("A file size: %llu\n", (long long)fsize);
169 char *file_data = (char *) malloc(sizeof(char) * fsize);
170 afc_file_read(afc, my_file, file_data, fsize, &bytes);
171 if (bytes > 0) {
172 printf("The file's data:\n");
173 fwrite(file_data, 1, bytes, stdout);
174 }
175 printf("\nClosing my file.\n");
176 afc_file_close(afc, my_file);
177 free(file_data);
178 } else
179 printf("couldn't open a file\n");
180
181 afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_WR, &my_file);
182 if (my_file) {
183 char *outdatafile = strdup("this is a bitchin text file\n");
184 afc_file_write(afc, my_file, outdatafile, strlen(outdatafile), &bytes);
185 free(outdatafile);
186 if (bytes > 0)
187 printf("Wrote a surprise. ;)\n");
188 else
189 printf("I wanted to write a surprise, but... :(\n");
190 afc_file_close(afc, my_file);
191 }
192 printf("Deleting a file...\n");
193 bytes = afc_remove_path(afc, "/delme");
194 if (bytes)
195 printf("Success.\n");
196 else
197 printf("Failure. (expected unless you have a /delme file on your phone)\n");
198
199 printf("Renaming a file...\n");
200 bytes = afc_rename_path(afc, "/renme", "/renme2");
201 if (bytes > 0)
202 printf("Success.\n");
203 else
204 printf("Failure. (expected unless you have a /renme file on your phone)\n");
205
206 printf("Seek & read\n");
207 afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file);
208 if (AFC_E_SUCCESS != afc_file_seek(afc, my_file, 5, SEEK_CUR))
209 printf("WARN: SEEK DID NOT WORK\n");
210 char *threeletterword = (char *) malloc(sizeof(char) * 5);
211 afc_file_read(afc, my_file, threeletterword, 3, &bytes);
212 threeletterword[3] = '\0';
213 if (bytes > 0)
214 printf("Result: %s\n", threeletterword);
215 else
216 printf("Couldn't read!\n");
217 free(threeletterword);
218 afc_file_close(afc, my_file);
219 }
220
221 if (gnp && lockfile) {
222 printf("XXX sleeping\n");
223 sleep(5);
224
225 printf("XXX unlocking file\n");
226 afc_file_lock(afc, lockfile, AFC_LOCK_UN);
227
228 printf("XXX closing file\n");
229 afc_file_close(afc, lockfile);
230
231 printf("XXX sleeping\n");
232 sleep(5);
233 //perform_notification(phone, client, NP_SYNC_DID_FINISH);
234 }
235
236 if (gnp) {
237 np_client_free(gnp);
238 gnp = NULL;
239 }
240
241 afc_client_free(afc);
242 } else {
243 printf("Start service failure.\n");
244 }
245
246 printf("All done.\n");
247
248 lockdownd_client_free(client);
249 idevice_free(phone);
250
251 return 0;
252}