summaryrefslogtreecommitdiffstats
path: root/dev/housearresttest.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/housearresttest.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/housearresttest.c')
-rw-r--r--dev/housearresttest.c219
1 files changed, 0 insertions, 219 deletions
diff --git a/dev/housearresttest.c b/dev/housearresttest.c
deleted file mode 100644
index 6586787..0000000
--- a/dev/housearresttest.c
+++ /dev/null
@@ -1,219 +0,0 @@
1/*
2 * housearresttest.c
3 * Simple Test program showing the usage of the house_arrest interface.
4 *
5 * Copyright (c) 2010 Nikias Bassen 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#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include <libimobiledevice/libimobiledevice.h>
26#include <libimobiledevice/lockdown.h>
27#include <libimobiledevice/house_arrest.h>
28#include <libimobiledevice/afc.h>
29
30static void print_usage(int argc, char **argv)
31{
32 char *name = NULL;
33
34 name = strrchr(argv[0], '/');
35 printf("Usage: %s [OPTIONS] APPID\n", (name ? name + 1: argv[0]));
36 printf("Test the house_arrest service.\n\n");
37 printf(" -d, --debug\t\tenable communication debugging\n");
38 printf(" -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n");
39 printf(" -t, --test\t\ttest creating, writing, and deleting a file\n");
40 printf(" -h, --help\t\tprints usage information\n");
41 printf("\n");
42}
43
44int main(int argc, char **argv)
45{
46 idevice_t dev = NULL;
47 lockdownd_client_t client = NULL;
48 house_arrest_client_t hac = NULL;
49 house_arrest_error_t res;
50 int i;
51 char *udid = NULL;
52 const char *appid = NULL;
53 int test_file_io = 0;
54
55 /* parse cmdline args */
56 for (i = 1; i < argc; i++) {
57 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
58 idevice_set_debug_level(1);
59 continue;
60 }
61 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) {
62 i++;
63 if (!argv[i] || (strlen(argv[i]) != 40)) {
64 print_usage(argc, argv);
65 return 0;
66 }
67 udid = strdup(argv[i]);
68 continue;
69 }
70 else if (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--test")) {
71 test_file_io = 1;
72 continue;
73 }
74 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
75 print_usage(argc, argv);
76 return 0;
77 }
78 else {
79 appid = argv[i];
80 break;
81 }
82 }
83
84 if (!appid) {
85 print_usage(argc, argv);
86 return 0;
87 }
88
89 if (idevice_new(&dev, udid) != IDEVICE_E_SUCCESS) {
90 printf("no device connected?!\n");
91 goto leave_cleanup;
92 }
93
94 if (lockdownd_client_new_with_handshake(dev, &client, NULL) != LOCKDOWN_E_SUCCESS) {
95 printf("could not connect to lockdownd!\n");
96 goto leave_cleanup;
97 }
98
99 lockdownd_service_descriptor_t service = NULL;
100 if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &service) != LOCKDOWN_E_SUCCESS) {
101 printf("could not start house_arrest service!\n");
102 goto leave_cleanup;
103 }
104
105 if (client) {
106 lockdownd_client_free(client);
107 client = NULL;
108 }
109
110 if (house_arrest_client_new(dev, service, &hac) != HOUSE_ARREST_E_SUCCESS) {
111 printf("could not connect to house_arrest service!\n");
112 goto leave_cleanup;
113 }
114
115 if (service) {
116 lockdownd_service_descriptor_free(service);
117 service = NULL;
118 }
119
120 res = house_arrest_send_command(hac, "VendDocuments", appid);
121 if (res != HOUSE_ARREST_E_SUCCESS) {
122 printf("error %d when trying to get VendDocuments\n", res);
123 goto leave_cleanup;
124 }
125
126 plist_t dict = NULL;
127 if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) {
128 if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) {
129 printf("hmmm....\n");
130 goto leave_cleanup;
131 }
132 }
133
134 plist_t node = plist_dict_get_item(dict, "Error");
135 if (node) {
136 char *str = NULL;
137 plist_get_string_val(node, &str);
138 printf("Error: %s\n", str);
139 if (str) free(str);
140 plist_free(dict);
141 dict = NULL;
142 goto leave_cleanup;
143 }
144 node = plist_dict_get_item(dict, "Status");
145 if (node) {
146 char *str = NULL;
147 plist_get_string_val(node, &str);
148 if (str && (strcmp(str, "Complete") != 0)) {
149 printf("Warning: Status is not 'Complete' but '%s'\n", str);
150 }
151 if (str) free(str);
152 plist_free(dict);
153 dict = NULL;
154 }
155 if (dict) {
156 plist_free(dict);
157 }
158
159 afc_client_t afc = NULL;
160 afc_error_t ae = afc_client_new_from_house_arrest_client(hac, &afc);
161 if (ae != AFC_E_SUCCESS) {
162 printf("afc error %d\n", ae);
163 }
164 if (ae == AFC_E_SUCCESS) {
165 char **list = NULL;
166 afc_read_directory(afc, "/", &list);
167 printf("Directory contents:\n");
168 if (list) {
169 while (list[0]) {
170 if (strcmp(list[0], ".") && strcmp(list[0], "..")) {
171 puts(list[0]);
172 }
173 list++;
174 }
175 }
176
177 if (test_file_io) {
178 uint64_t tf = 0;
179 printf("\n==== Performing file tests ====\n");
180 printf("Opening file 'foobar' for writing: ");
181 if (afc_file_open(afc, "/foobar", AFC_FOPEN_RW, &tf) == AFC_E_SUCCESS) {
182 uint32_t wb = 0;
183 printf("OK\n");
184
185 printf("Writing to file: ");
186 if (afc_file_write(afc, tf, "test\r\n", 6, &wb) != AFC_E_SUCCESS) {
187 printf("ERROR\n");
188 } else {
189 printf("OK\n");
190 }
191 afc_file_close(afc, tf);
192 printf("Deleting file 'foobar': ");
193 if (afc_remove_path(afc, "/foobar") == AFC_E_SUCCESS) {
194 printf("OK\n");
195 } else {
196 printf("ERROR\n");
197 }
198 } else {
199 printf("ERROR\n");
200 }
201 }
202 afc_client_free(afc);
203 } else {
204 printf("failed to connect to afc service, error %d\n", ae);
205 }
206
207leave_cleanup:
208 if (hac) {
209 house_arrest_client_free(hac);
210 }
211 if (client) {
212 lockdownd_client_free(client);
213 }
214 if (dev) {
215 idevice_free(dev);
216 }
217
218 return 0;
219}