diff options
| author | 2014-05-21 15:11:49 +0200 | |
|---|---|---|
| committer | 2014-05-21 15:11:49 +0200 | |
| commit | df51f6cfb7f73b159e7c7d704b9e59ef09f94b3e (patch) | |
| tree | dfa5453d77d76f6a8335c3d16608917f9cdfcac3 /tools | |
| parent | 6c47c92882d4009c8a0d1a82a82f352bb6dfaaa0 (diff) | |
| download | libimobiledevice-df51f6cfb7f73b159e7c7d704b9e59ef09f94b3e.tar.gz libimobiledevice-df51f6cfb7f73b159e7c7d704b9e59ef09f94b3e.tar.bz2 | |
ideviceimagemounter: Use plist print helper from common module
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/Makefile.am | 2 | ||||
| -rw-r--r-- | tools/ideviceimagemounter.c | 150 |
2 files changed, 7 insertions, 145 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 959bdc4..68be776 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am | |||
| @@ -42,7 +42,7 @@ idevicebackup2_LDADD = $(top_builddir)/src/libimobiledevice.la | |||
| 42 | 42 | ||
| 43 | ideviceimagemounter_SOURCES = ideviceimagemounter.c | 43 | ideviceimagemounter_SOURCES = ideviceimagemounter.c |
| 44 | ideviceimagemounter_CFLAGS = $(AM_CFLAGS) | 44 | ideviceimagemounter_CFLAGS = $(AM_CFLAGS) |
| 45 | ideviceimagemounter_LDFLAGS = $(AM_LDFLAGS) | 45 | ideviceimagemounter_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) |
| 46 | ideviceimagemounter_LDADD = $(top_builddir)/src/libimobiledevice.la | 46 | ideviceimagemounter_LDADD = $(top_builddir)/src/libimobiledevice.la |
| 47 | 47 | ||
| 48 | idevicescreenshot_SOURCES = idevicescreenshot.c | 48 | idevicescreenshot_SOURCES = idevicescreenshot.c |
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c index 3cd1e55..cd41e6a 100644 --- a/tools/ideviceimagemounter.c +++ b/tools/ideviceimagemounter.c | |||
| @@ -37,8 +37,7 @@ | |||
| 37 | #include <libimobiledevice/notification_proxy.h> | 37 | #include <libimobiledevice/notification_proxy.h> |
| 38 | #include <libimobiledevice/mobile_image_mounter.h> | 38 | #include <libimobiledevice/mobile_image_mounter.h> |
| 39 | #include <asprintf.h> | 39 | #include <asprintf.h> |
| 40 | 40 | #include "common/utils.h" | |
| 41 | static int indent_level = 0; | ||
| 42 | 41 | ||
| 43 | static int list_mode = 0; | 42 | static int list_mode = 0; |
| 44 | static int xml_mode = 0; | 43 | static int xml_mode = 0; |
| @@ -116,143 +115,6 @@ static void parse_opts(int argc, char **argv) | |||
| 116 | } | 115 | } |
| 117 | } | 116 | } |
| 118 | 117 | ||
| 119 | static void plist_node_to_string(plist_t node); | ||
| 120 | |||
| 121 | static void plist_array_to_string(plist_t node) | ||
| 122 | { | ||
| 123 | /* iterate over items */ | ||
| 124 | int i, count; | ||
| 125 | plist_t subnode = NULL; | ||
| 126 | |||
| 127 | count = plist_array_get_size(node); | ||
| 128 | |||
| 129 | for (i = 0; i < count; i++) { | ||
| 130 | subnode = plist_array_get_item(node, i); | ||
| 131 | printf("%*s", indent_level, ""); | ||
| 132 | printf("%d: ", i); | ||
| 133 | plist_node_to_string(subnode); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | static void plist_dict_to_string(plist_t node) | ||
| 138 | { | ||
| 139 | /* iterate over key/value pairs */ | ||
| 140 | plist_dict_iter it = NULL; | ||
| 141 | |||
| 142 | char* key = NULL; | ||
| 143 | plist_t subnode = NULL; | ||
| 144 | plist_dict_new_iter(node, &it); | ||
| 145 | plist_dict_next_item(node, it, &key, &subnode); | ||
| 146 | while (subnode) | ||
| 147 | { | ||
| 148 | printf("%*s", indent_level, ""); | ||
| 149 | printf("%s", key); | ||
| 150 | if (plist_get_node_type(subnode) == PLIST_ARRAY) | ||
| 151 | printf("[%d]: ", plist_array_get_size(subnode)); | ||
| 152 | else | ||
| 153 | printf(": "); | ||
| 154 | free(key); | ||
| 155 | key = NULL; | ||
| 156 | plist_node_to_string(subnode); | ||
| 157 | plist_dict_next_item(node, it, &key, &subnode); | ||
| 158 | } | ||
| 159 | free(it); | ||
| 160 | } | ||
| 161 | |||
| 162 | static void plist_node_to_string(plist_t node) | ||
| 163 | { | ||
| 164 | char *s = NULL; | ||
| 165 | char *data = NULL; | ||
| 166 | double d; | ||
| 167 | uint8_t b; | ||
| 168 | uint64_t u = 0; | ||
| 169 | struct timeval tv = { 0, 0 }; | ||
| 170 | |||
| 171 | plist_type t; | ||
| 172 | |||
| 173 | if (!node) | ||
| 174 | return; | ||
| 175 | |||
| 176 | t = plist_get_node_type(node); | ||
| 177 | |||
| 178 | switch (t) { | ||
| 179 | case PLIST_BOOLEAN: | ||
| 180 | plist_get_bool_val(node, &b); | ||
| 181 | printf("%s\n", (b ? "true" : "false")); | ||
| 182 | break; | ||
| 183 | |||
| 184 | case PLIST_UINT: | ||
| 185 | plist_get_uint_val(node, &u); | ||
| 186 | printf("%"PRIu64"\n", (long long)u); | ||
| 187 | break; | ||
| 188 | |||
| 189 | case PLIST_REAL: | ||
| 190 | plist_get_real_val(node, &d); | ||
| 191 | printf("%f\n", d); | ||
| 192 | break; | ||
| 193 | |||
| 194 | case PLIST_STRING: | ||
| 195 | plist_get_string_val(node, &s); | ||
| 196 | printf("%s\n", s); | ||
| 197 | free(s); | ||
| 198 | break; | ||
| 199 | |||
| 200 | case PLIST_KEY: | ||
| 201 | plist_get_key_val(node, &s); | ||
| 202 | printf("%s: ", s); | ||
| 203 | free(s); | ||
| 204 | break; | ||
| 205 | |||
| 206 | case PLIST_DATA: | ||
| 207 | plist_get_data_val(node, &data, &u); | ||
| 208 | uint64_t i; | ||
| 209 | for (i = 0; i < u; i++) { | ||
| 210 | printf("%02x", (unsigned char)data[i]); | ||
| 211 | } | ||
| 212 | free(data); | ||
| 213 | printf("\n"); | ||
| 214 | break; | ||
| 215 | |||
| 216 | case PLIST_DATE: | ||
| 217 | plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); | ||
| 218 | { | ||
| 219 | time_t ti = (time_t)tv.tv_sec; | ||
| 220 | struct tm *btime = localtime(&ti); | ||
| 221 | if (btime) { | ||
| 222 | s = (char*)malloc(24); | ||
| 223 | memset(s, 0, 24); | ||
| 224 | if (strftime(s, 24, "%Y-%m-%dT%H:%M:%SZ", btime) <= 0) { | ||
| 225 | free (s); | ||
| 226 | s = NULL; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | } | ||
| 230 | if (s) { | ||
| 231 | puts(s); | ||
| 232 | free(s); | ||
| 233 | } | ||
| 234 | puts("\n"); | ||
| 235 | break; | ||
| 236 | |||
| 237 | case PLIST_ARRAY: | ||
| 238 | printf("\n"); | ||
| 239 | indent_level++; | ||
| 240 | plist_array_to_string(node); | ||
| 241 | indent_level--; | ||
| 242 | break; | ||
| 243 | |||
| 244 | case PLIST_DICT: | ||
| 245 | printf("\n"); | ||
| 246 | indent_level++; | ||
| 247 | plist_dict_to_string(node); | ||
| 248 | indent_level--; | ||
| 249 | break; | ||
| 250 | |||
| 251 | default: | ||
| 252 | break; | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | static void print_xml(plist_t node) | 118 | static void print_xml(plist_t node) |
| 257 | { | 119 | { |
| 258 | char *xml = NULL; | 120 | char *xml = NULL; |
| @@ -388,7 +250,7 @@ int main(int argc, char **argv) | |||
| 388 | if (xml_mode) { | 250 | if (xml_mode) { |
| 389 | print_xml(result); | 251 | print_xml(result); |
| 390 | } else { | 252 | } else { |
| 391 | plist_dict_to_string(result); | 253 | plist_print_to_stream(result, stdout); |
| 392 | } | 254 | } |
| 393 | } else { | 255 | } else { |
| 394 | printf("Error: lookup_image returned %d\n", err); | 256 | printf("Error: lookup_image returned %d\n", err); |
| @@ -508,7 +370,7 @@ int main(int argc, char **argv) | |||
| 508 | if (xml_mode) { | 370 | if (xml_mode) { |
| 509 | print_xml(result); | 371 | print_xml(result); |
| 510 | } else { | 372 | } else { |
| 511 | plist_dict_to_string(result); | 373 | plist_print_to_stream(result, stdout); |
| 512 | } | 374 | } |
| 513 | } | 375 | } |
| 514 | free(status); | 376 | free(status); |
| @@ -517,7 +379,7 @@ int main(int argc, char **argv) | |||
| 517 | if (xml_mode) { | 379 | if (xml_mode) { |
| 518 | print_xml(result); | 380 | print_xml(result); |
| 519 | } else { | 381 | } else { |
| 520 | plist_dict_to_string(result); | 382 | plist_print_to_stream(result, stdout); |
| 521 | } | 383 | } |
| 522 | } | 384 | } |
| 523 | } | 385 | } |
| @@ -533,7 +395,7 @@ int main(int argc, char **argv) | |||
| 533 | if (xml_mode) { | 395 | if (xml_mode) { |
| 534 | print_xml(result); | 396 | print_xml(result); |
| 535 | } else { | 397 | } else { |
| 536 | plist_dict_to_string(result); | 398 | plist_print_to_stream(result, stdout); |
| 537 | } | 399 | } |
| 538 | } | 400 | } |
| 539 | 401 | ||
| @@ -541,7 +403,7 @@ int main(int argc, char **argv) | |||
| 541 | if (xml_mode) { | 403 | if (xml_mode) { |
| 542 | print_xml(result); | 404 | print_xml(result); |
| 543 | } else { | 405 | } else { |
| 544 | plist_dict_to_string(result); | 406 | plist_print_to_stream(result, stdout); |
| 545 | } | 407 | } |
| 546 | } | 408 | } |
| 547 | } | 409 | } |
