summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libiphone/lockdown.h1
-rw-r--r--src/debug.c16
-rw-r--r--src/debug.h9
-rw-r--r--src/lockdown.c13
-rw-r--r--tools/iphoneinfo.c312
5 files changed, 209 insertions, 142 deletions
diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h
index 7fa5384..e80851b 100644
--- a/include/libiphone/lockdown.h
+++ b/include/libiphone/lockdown.h
@@ -48,6 +48,7 @@ extern "C" {
48#define LOCKDOWN_E_PASSWORD_PROTECTED -14 48#define LOCKDOWN_E_PASSWORD_PROTECTED -14
49#define LOCKDOWN_E_NO_RUNNING_SESSION -15 49#define LOCKDOWN_E_NO_RUNNING_SESSION -15
50#define LOCKDOWN_E_INVALID_HOST_ID -16 50#define LOCKDOWN_E_INVALID_HOST_ID -16
51#define LOCKDOWN_E_INVALID_SERVICE -17
51 52
52#define LOCKDOWN_E_UNKNOWN_ERROR -256 53#define LOCKDOWN_E_UNKNOWN_ERROR -256
53 54
diff --git a/src/debug.c b/src/debug.c
index 2cdeebf..b194b0d 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -3,6 +3,7 @@
3 * contains utilitary functions for debugging 3 * contains utilitary functions for debugging
4 * 4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved. 5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 * Copyright (c) 2010 Martin S. All Rights Reserved.
6 * 7 *
7 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
@@ -56,10 +57,12 @@ static void debug_print_line(const char *func, const char *file, int line, const
56 (void)asprintf(&header, "%s %s:%d %s()", str_time, file, line, func); 57 (void)asprintf(&header, "%s %s:%d %s()", str_time, file, line, func);
57 free (str_time); 58 free (str_time);
58 59
59 /* always in light green */ 60 /* trim ending newlines */
61
62 /* print header */
60 printf ("%s: ", header); 63 printf ("%s: ", header);
61 64
62 /* different colors according to the severity */ 65 /* print actual debug content */
63 printf ("%s\n", buffer); 66 printf ("%s\n", buffer);
64 67
65 /* flush this output, as we need to debug */ 68 /* flush this output, as we need to debug */
@@ -135,7 +138,7 @@ inline void debug_buffer_to_file(const char *file, const char *data, const int l
135#endif 138#endif
136} 139}
137 140
138inline void debug_plist(plist_t plist) 141inline void debug_plist_real(const char *func, const char *file, int line, plist_t plist)
139{ 142{
140#ifndef STRIP_DEBUG_CODE 143#ifndef STRIP_DEBUG_CODE
141 if (!plist) 144 if (!plist)
@@ -144,7 +147,12 @@ inline void debug_plist(plist_t plist)
144 char *buffer = NULL; 147 char *buffer = NULL;
145 uint32_t length = 0; 148 uint32_t length = 0;
146 plist_to_xml(plist, &buffer, &length); 149 plist_to_xml(plist, &buffer, &length);
147 debug_info("plist size: %i\nbuffer :\n%s", length, buffer); 150
151 /* get rid of ending newline as one is already added in the debug line */
152 if (buffer[length-1] == '\n')
153 buffer[length-1] = '\0';
154
155 debug_info_real(func, file, line, "printing %i bytes plist:\n%s", length, buffer);
148 free(buffer); 156 free(buffer);
149#endif 157#endif
150} 158}
diff --git a/src/debug.h b/src/debug.h
index 0a29be3..2fd0960 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -3,6 +3,7 @@
3 * contains utilitary functions for debugging 3 * contains utilitary functions for debugging
4 * 4 *
5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved. 5 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
6 * Copyright (c) 2010 Martin S. All Rights Reserved.
6 * 7 *
7 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
@@ -27,10 +28,13 @@
27 28
28#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(STRIP_DEBUG_CODE) 29#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(STRIP_DEBUG_CODE)
29#define debug_info(...) debug_info_real (__func__, __FILE__, __LINE__, __VA_ARGS__) 30#define debug_info(...) debug_info_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
31#define debug_plist(a) debug_plist_real (__func__, __FILE__, __LINE__, a)
30#elif defined(__GNUC__) && __GNUC__ >= 3 && !defined(STRIP_DEBUG_CODE) 32#elif defined(__GNUC__) && __GNUC__ >= 3 && !defined(STRIP_DEBUG_CODE)
31#define debug_info(...) debug_info_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__) 33#define debug_info(...) debug_info_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
34#define debug_plist(a) debug_plist_real (__FUNCTION__, __FILE__, __LINE__, a)
32#else 35#else
33#define debug_info(...) 36#define debug_info(...)
37#define debug_plist(a)
34#endif 38#endif
35 39
36G_GNUC_INTERNAL inline void debug_info_real(const char *func, 40G_GNUC_INTERNAL inline void debug_info_real(const char *func,
@@ -40,6 +44,9 @@ G_GNUC_INTERNAL inline void debug_info_real(const char *func,
40 44
41G_GNUC_INTERNAL inline void debug_buffer(const char *data, const int length); 45G_GNUC_INTERNAL inline void debug_buffer(const char *data, const int length);
42G_GNUC_INTERNAL inline void debug_buffer_to_file(const char *file, const char *data, const int length); 46G_GNUC_INTERNAL inline void debug_buffer_to_file(const char *file, const char *data, const int length);
43G_GNUC_INTERNAL inline void debug_plist(plist_t plist); 47G_GNUC_INTERNAL inline void debug_plist_real(const char *func,
48 const char *file,
49 int line,
50 plist_t plist);
44 51
45#endif 52#endif
diff --git a/src/lockdown.c b/src/lockdown.c
index 1befb72..8f15b3f 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -1262,9 +1262,18 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char
1262 if (port && ret == LOCKDOWN_E_SUCCESS) 1262 if (port && ret == LOCKDOWN_E_SUCCESS)
1263 *port = port_loc; 1263 *port = port_loc;
1264 } 1264 }
1265 } 1265 } else {
1266 else
1267 ret = LOCKDOWN_E_START_SERVICE_FAILED; 1266 ret = LOCKDOWN_E_START_SERVICE_FAILED;
1267 plist_t error_node = plist_dict_get_item(dict, "Error");
1268 if (error_node && PLIST_STRING == plist_get_node_type(error_node)) {
1269 char *error = NULL;
1270 plist_get_string_val(error_node, &error);
1271 if (!strcmp(error, "InvalidService")) {
1272 ret = LOCKDOWN_E_INVALID_SERVICE;
1273 }
1274 free(error);
1275 }
1276 }
1268 1277
1269 plist_free(dict); 1278 plist_free(dict);
1270 dict = NULL; 1279 dict = NULL;
diff --git a/tools/iphoneinfo.c b/tools/iphoneinfo.c
index 7c41033..5ee92f5 100644
--- a/tools/iphoneinfo.c
+++ b/tools/iphoneinfo.c
@@ -23,6 +23,7 @@
23#include <string.h> 23#include <string.h>
24#include <errno.h> 24#include <errno.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <glib.h>
26 27
27#include <libiphone/libiphone.h> 28#include <libiphone/libiphone.h>
28#include <libiphone/lockdown.h> 29#include <libiphone/lockdown.h>
@@ -55,10 +56,161 @@ static const char *domains[] = {
55 NULL 56 NULL
56}; 57};
57 58
58int is_domain_known(char *domain); 59static int indent_level = 0;
59void print_usage(int argc, char **argv); 60
60void plist_node_to_string(plist_t node); 61static int is_domain_known(char *domain)
61void plist_children_to_string(plist_t node); 62{
63 int i = 0;
64 while (domains[i] != NULL) {
65 if (strstr(domain, domains[i++])) {
66 return 1;
67 }
68 }
69 return 0;
70}
71
72static void plist_node_to_string(plist_t node);
73
74static void plist_array_to_string(plist_t node)
75{
76 /* iterate over items */
77 int i, count;
78 plist_t subnode = NULL;
79
80 count = plist_array_get_size(node);
81
82 for (i = 0; i < count; i++) {
83 subnode = plist_array_get_item(node, i);
84 printf("%*s", indent_level, "");
85 printf("%d: ", i);
86 plist_node_to_string(subnode);
87 }
88}
89
90static void plist_dict_to_string(plist_t node)
91{
92 /* iterate over key/value pairs */
93 plist_dict_iter it = NULL;
94
95 char* key = NULL;
96 plist_t subnode = NULL;
97 plist_dict_new_iter(node, &it);
98 plist_dict_next_item(node, it, &key, &subnode);
99 while (subnode)
100 {
101 printf("%*s", indent_level, "");
102 printf("%s", key);
103 if (plist_get_node_type(subnode) == PLIST_ARRAY)
104 printf("[%d]: ", plist_array_get_size(subnode));
105 else
106 printf(": ");
107 free(key);
108 key = NULL;
109 plist_node_to_string(subnode);
110 plist_dict_next_item(node, it, &key, &subnode);
111 }
112 free(it);
113}
114
115static void plist_node_to_string(plist_t node)
116{
117 char *s = NULL;
118 char *data = NULL;
119 double d;
120 uint8_t b;
121 uint64_t u = 0;
122 GTimeVal tv = { 0, 0 };
123
124 plist_type t;
125
126 if (!node)
127 return;
128
129 t = plist_get_node_type(node);
130
131 switch (t) {
132 case PLIST_BOOLEAN:
133 plist_get_bool_val(node, &b);
134 printf("%s\n", (b ? "true" : "false"));
135 break;
136
137 case PLIST_UINT:
138 plist_get_uint_val(node, &u);
139 printf("%llu\n", (long long)u);
140 break;
141
142 case PLIST_REAL:
143 plist_get_real_val(node, &d);
144 printf("%f\n", d);
145 break;
146
147 case PLIST_STRING:
148 plist_get_string_val(node, &s);
149 printf("%s\n", s);
150 free(s);
151 break;
152
153 case PLIST_KEY:
154 plist_get_key_val(node, &s);
155 printf("%s: ", s);
156 free(s);
157 break;
158
159 case PLIST_DATA:
160 plist_get_data_val(node, &data, &u);
161 s = g_base64_encode((guchar *)data, u);
162 free(data);
163 printf("%s\n", s);
164 g_free(s);
165 break;
166
167 case PLIST_DATE:
168 plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec);
169 s = g_time_val_to_iso8601(&tv);
170 printf("%s\n", s);
171 free(s);
172 break;
173
174 case PLIST_ARRAY:
175 printf("\n");
176 indent_level++;
177 plist_array_to_string(node);
178 indent_level--;
179 break;
180
181 case PLIST_DICT:
182 printf("\n");
183 indent_level++;
184 plist_dict_to_string(node);
185 indent_level--;
186 break;
187
188 default:
189 break;
190 }
191}
192
193static void print_usage(int argc, char **argv)
194{
195 int i = 0;
196 char *name = NULL;
197
198 name = strrchr(argv[0], '/');
199 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
200 printf("Show information about the first connected iPhone/iPod Touch.\n\n");
201 printf(" -d, --debug\t\tenable communication debugging\n");
202 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
203 printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n");
204 printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n");
205 printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n");
206 printf(" -h, --help\t\tprints usage information\n");
207 printf("\n");
208 printf(" Known domains are:\n\n");
209 while (domains[i] != NULL) {
210 printf(" %s\n", domains[i++]);
211 }
212 printf("\n");
213}
62 214
63int main(int argc, char *argv[]) 215int main(int argc, char *argv[])
64{ 216{
@@ -73,6 +225,7 @@ int main(int argc, char *argv[])
73 char *xml_doc = NULL; 225 char *xml_doc = NULL;
74 uint32_t xml_length; 226 uint32_t xml_length;
75 plist_t node = NULL; 227 plist_t node = NULL;
228 plist_type node_type;
76 uuid[0] = 0; 229 uuid[0] = 0;
77 230
78 /* parse cmdline args */ 231 /* parse cmdline args */
@@ -147,29 +300,30 @@ int main(int argc, char *argv[])
147 } 300 }
148 301
149 /* run query and output information */ 302 /* run query and output information */
150 if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) 303 if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) {
151 { 304 if (node) {
152 if (plist_get_node_type(node) == PLIST_DICT) { 305 switch (format) {
153 if (plist_dict_get_size(node)) 306 case FORMAT_XML:
154 { 307 plist_to_xml(node, &xml_doc, &xml_length);
155 switch (format) { 308 printf("%s", xml_doc);
156 case FORMAT_XML: 309 free(xml_doc);
157 plist_to_xml(node, &xml_doc, &xml_length); 310 break;
158 printf("%s", xml_doc); 311 case FORMAT_KEY_VALUE:
159 free(xml_doc); 312 node_type = plist_get_node_type(node);
160 break; 313 if (node_type == PLIST_DICT) {
161 case FORMAT_KEY_VALUE: 314 plist_dict_to_string(node);
162 default: 315 } else if (node_type == PLIST_ARRAY) {
163 plist_children_to_string(node); 316 plist_array_to_string(node);
164 break; 317 break;
165 } 318 }
319 default:
320 if (key != NULL)
321 plist_node_to_string(node);
322 break;
166 } 323 }
167 }
168 else if(node && (key != NULL))
169 plist_node_to_string(node);
170 if (node)
171 plist_free(node); 324 plist_free(node);
172 node = NULL; 325 node = NULL;
326 }
173 } 327 }
174 328
175 if (domain != NULL) 329 if (domain != NULL)
@@ -180,115 +334,3 @@ int main(int argc, char *argv[])
180 return 0; 334 return 0;
181} 335}
182 336
183int is_domain_known(char *domain)
184{
185 int i = 0;
186 while (domains[i] != NULL) {
187 if (strstr(domain, domains[i++])) {
188 return 1;
189 }
190 }
191 return 0;
192}
193
194void print_usage(int argc, char **argv)
195{
196 int i = 0;
197 char *name = NULL;
198
199 name = strrchr(argv[0], '/');
200 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
201 printf("Show information about the first connected iPhone/iPod Touch.\n\n");
202 printf(" -d, --debug\t\tenable communication debugging\n");
203 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
204 printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n");
205 printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n");
206 printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n");
207 printf(" -h, --help\t\tprints usage information\n");
208 printf("\n");
209 printf(" Known domains are:\n\n");
210 while (domains[i] != NULL) {
211 printf(" %s\n", domains[i++]);
212 }
213 printf("\n");
214}
215
216void plist_node_to_string(plist_t node)
217{
218 char *s = NULL;
219 double d;
220 uint8_t b;
221
222 uint64_t u = 0;
223
224 plist_type t;
225
226 if (!node)
227 return;
228
229 t = plist_get_node_type(node);
230
231 switch (t) {
232 case PLIST_BOOLEAN:
233 plist_get_bool_val(node, &b);
234 printf("%s\n", (b ? "true" : "false"));
235 break;
236
237 case PLIST_UINT:
238 plist_get_uint_val(node, &u);
239 printf("%llu\n", (long long)u);
240 break;
241
242 case PLIST_REAL:
243 plist_get_real_val(node, &d);
244 printf("%f\n", d);
245 break;
246
247 case PLIST_STRING:
248 plist_get_string_val(node, &s);
249 printf("%s\n", s);
250 free(s);
251 break;
252
253 case PLIST_KEY:
254 plist_get_key_val(node, &s);
255 printf("%s: ", s);
256 free(s);
257 break;
258
259 case PLIST_DATA:
260 printf("\n");
261 break;
262 case PLIST_DATE:
263 printf("\n");
264 break;
265 case PLIST_ARRAY:
266 case PLIST_DICT:
267 printf("\n");
268 plist_children_to_string(node);
269 break;
270 default:
271 break;
272 }
273}
274
275void plist_children_to_string(plist_t node)
276{
277 /* iterate over key/value pairs */
278 plist_dict_iter it = NULL;
279
280 char* key = NULL;
281 plist_t subnode = NULL;
282 plist_dict_new_iter(node, &it);
283 plist_dict_next_item(node, it, &key, &subnode);
284 while (subnode)
285 {
286 printf("%s: ", key);
287 free(key);
288 key = NULL;
289 plist_node_to_string(subnode);
290 plist_dict_next_item(node, it, &key, &subnode);
291 }
292 free(it);
293}
294