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