diff options
| author | 2010-01-22 13:01:22 +0100 | |
|---|---|---|
| committer | 2010-01-22 13:01:22 +0100 | |
| commit | 647f1722c60fd7275e246b79f21aeeec819f35a5 (patch) | |
| tree | 19f54b32ab3a2332320cfacd9b9d0c187f7e1f3e | |
| parent | 19dc6e13984f97a972feaceefa8384df75188f6a (diff) | |
| download | libimobiledevice-647f1722c60fd7275e246b79f21aeeec819f35a5.tar.gz libimobiledevice-647f1722c60fd7275e246b79f21aeeec819f35a5.tar.bz2 | |
Refactor iphoneinfo and make internal functions static
| -rw-r--r-- | tools/iphoneinfo.c | 257 |
1 files changed, 127 insertions, 130 deletions
diff --git a/tools/iphoneinfo.c b/tools/iphoneinfo.c index 5b131c4..4414b14 100644 --- a/tools/iphoneinfo.c +++ b/tools/iphoneinfo.c | |||
| @@ -58,10 +58,133 @@ static const char *domains[] = { | |||
| 58 | 58 | ||
| 59 | static int indent_level = 0; | 59 | static int indent_level = 0; |
| 60 | 60 | ||
| 61 | int is_domain_known(char *domain); | 61 | static int is_domain_known(char *domain) |
| 62 | void print_usage(int argc, char **argv); | 62 | { |
| 63 | void plist_node_to_string(plist_t node); | 63 | int i = 0; |
| 64 | void plist_children_to_string(plist_t node); | 64 | while (domains[i] != NULL) { |
| 65 | if (strstr(domain, domains[i++])) { | ||
| 66 | return 1; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | return 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | static void plist_node_to_string(plist_t node); | ||
| 73 | |||
| 74 | static void plist_children_to_string(plist_t node) | ||
| 75 | { | ||
| 76 | /* iterate over key/value pairs */ | ||
| 77 | plist_dict_iter it = NULL; | ||
| 78 | |||
| 79 | char* key = NULL; | ||
| 80 | plist_t subnode = NULL; | ||
| 81 | plist_dict_new_iter(node, &it); | ||
| 82 | plist_dict_next_item(node, it, &key, &subnode); | ||
| 83 | while (subnode) | ||
| 84 | { | ||
| 85 | printf("%*s", indent_level, ""); | ||
| 86 | printf("%s: ", key); | ||
| 87 | free(key); | ||
| 88 | key = NULL; | ||
| 89 | plist_node_to_string(subnode); | ||
| 90 | plist_dict_next_item(node, it, &key, &subnode); | ||
| 91 | } | ||
| 92 | free(it); | ||
| 93 | } | ||
| 94 | |||
| 95 | static void plist_node_to_string(plist_t node) | ||
| 96 | { | ||
| 97 | char *s = NULL; | ||
| 98 | char *data = NULL; | ||
| 99 | double d; | ||
| 100 | uint8_t b; | ||
| 101 | uint64_t u = 0; | ||
| 102 | GTimeVal tv = { 0, 0 }; | ||
| 103 | |||
| 104 | plist_type t; | ||
| 105 | |||
| 106 | if (!node) | ||
| 107 | return; | ||
| 108 | |||
| 109 | t = plist_get_node_type(node); | ||
| 110 | |||
| 111 | switch (t) { | ||
| 112 | case PLIST_BOOLEAN: | ||
| 113 | plist_get_bool_val(node, &b); | ||
| 114 | printf("%s\n", (b ? "true" : "false")); | ||
| 115 | break; | ||
| 116 | |||
| 117 | case PLIST_UINT: | ||
| 118 | plist_get_uint_val(node, &u); | ||
| 119 | printf("%llu\n", (long long)u); | ||
| 120 | break; | ||
| 121 | |||
| 122 | case PLIST_REAL: | ||
| 123 | plist_get_real_val(node, &d); | ||
| 124 | printf("%f\n", d); | ||
| 125 | break; | ||
| 126 | |||
| 127 | case PLIST_STRING: | ||
| 128 | plist_get_string_val(node, &s); | ||
| 129 | printf("%s\n", s); | ||
| 130 | free(s); | ||
| 131 | break; | ||
| 132 | |||
| 133 | case PLIST_KEY: | ||
| 134 | plist_get_key_val(node, &s); | ||
| 135 | printf("%s: ", s); | ||
| 136 | free(s); | ||
| 137 | break; | ||
| 138 | |||
| 139 | case PLIST_DATA: | ||
| 140 | plist_get_data_val(node, &data, &u); | ||
| 141 | s = g_base64_encode((guchar *)data, u); | ||
| 142 | free(data); | ||
| 143 | printf("%s\n", s); | ||
| 144 | g_free(s); | ||
| 145 | break; | ||
| 146 | |||
| 147 | case PLIST_DATE: | ||
| 148 | plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); | ||
| 149 | s = g_time_val_to_iso8601(&tv); | ||
| 150 | printf("%s\n", s); | ||
| 151 | free(s); | ||
| 152 | break; | ||
| 153 | |||
| 154 | case PLIST_ARRAY: | ||
| 155 | case PLIST_DICT: | ||
| 156 | printf("\n"); | ||
| 157 | indent_level++; | ||
| 158 | plist_children_to_string(node); | ||
| 159 | indent_level--; | ||
| 160 | break; | ||
| 161 | |||
| 162 | default: | ||
| 163 | break; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | |||
| 167 | static void print_usage(int argc, char **argv) | ||
| 168 | { | ||
| 169 | int i = 0; | ||
| 170 | char *name = NULL; | ||
| 171 | |||
| 172 | name = strrchr(argv[0], '/'); | ||
| 173 | printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); | ||
| 174 | printf("Show information about the first connected iPhone/iPod Touch.\n\n"); | ||
| 175 | printf(" -d, --debug\t\tenable communication debugging\n"); | ||
| 176 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); | ||
| 177 | printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); | ||
| 178 | printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); | ||
| 179 | printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); | ||
| 180 | printf(" -h, --help\t\tprints usage information\n"); | ||
| 181 | printf("\n"); | ||
| 182 | printf(" Known domains are:\n\n"); | ||
| 183 | while (domains[i] != NULL) { | ||
| 184 | printf(" %s\n", domains[i++]); | ||
| 185 | } | ||
| 186 | printf("\n"); | ||
| 187 | } | ||
| 65 | 188 | ||
| 66 | int main(int argc, char *argv[]) | 189 | int main(int argc, char *argv[]) |
| 67 | { | 190 | { |
| @@ -183,129 +306,3 @@ int main(int argc, char *argv[]) | |||
| 183 | return 0; | 306 | return 0; |
| 184 | } | 307 | } |
| 185 | 308 | ||
| 186 | int is_domain_known(char *domain) | ||
| 187 | { | ||
| 188 | int i = 0; | ||
| 189 | while (domains[i] != NULL) { | ||
| 190 | if (strstr(domain, domains[i++])) { | ||
| 191 | return 1; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | return 0; | ||
| 195 | } | ||
| 196 | |||
| 197 | void print_usage(int argc, char **argv) | ||
| 198 | { | ||
| 199 | int i = 0; | ||
| 200 | char *name = NULL; | ||
| 201 | |||
| 202 | name = strrchr(argv[0], '/'); | ||
| 203 | printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); | ||
| 204 | printf("Show information about the first connected iPhone/iPod Touch.\n\n"); | ||
| 205 | printf(" -d, --debug\t\tenable communication debugging\n"); | ||
| 206 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); | ||
| 207 | printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); | ||
| 208 | printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); | ||
| 209 | printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); | ||
| 210 | printf(" -h, --help\t\tprints usage information\n"); | ||
| 211 | printf("\n"); | ||
| 212 | printf(" Known domains are:\n\n"); | ||
| 213 | while (domains[i] != NULL) { | ||
| 214 | printf(" %s\n", domains[i++]); | ||
| 215 | } | ||
| 216 | printf("\n"); | ||
| 217 | } | ||
| 218 | |||
| 219 | void plist_node_to_string(plist_t node) | ||
| 220 | { | ||
| 221 | char *s = NULL; | ||
| 222 | char *data = NULL; | ||
| 223 | double d; | ||
| 224 | uint8_t b; | ||
| 225 | uint64_t u = 0; | ||
| 226 | GTimeVal tv = { 0, 0 }; | ||
| 227 | |||
| 228 | plist_type t; | ||
| 229 | |||
| 230 | if (!node) | ||
| 231 | return; | ||
| 232 | |||
| 233 | t = plist_get_node_type(node); | ||
| 234 | |||
| 235 | switch (t) { | ||
| 236 | case PLIST_BOOLEAN: | ||
| 237 | plist_get_bool_val(node, &b); | ||
| 238 | printf("%s\n", (b ? "true" : "false")); | ||
| 239 | break; | ||
| 240 | |||
| 241 | case PLIST_UINT: | ||
| 242 | plist_get_uint_val(node, &u); | ||
| 243 | printf("%llu\n", (long long)u); | ||
| 244 | break; | ||
| 245 | |||
| 246 | case PLIST_REAL: | ||
| 247 | plist_get_real_val(node, &d); | ||
| 248 | printf("%f\n", d); | ||
| 249 | break; | ||
| 250 | |||
| 251 | case PLIST_STRING: | ||
| 252 | plist_get_string_val(node, &s); | ||
| 253 | printf("%s\n", s); | ||
| 254 | free(s); | ||
| 255 | break; | ||
| 256 | |||
| 257 | case PLIST_KEY: | ||
| 258 | plist_get_key_val(node, &s); | ||
| 259 | printf("%s: ", s); | ||
| 260 | free(s); | ||
| 261 | break; | ||
| 262 | |||
| 263 | case PLIST_DATA: | ||
| 264 | plist_get_data_val(node, &data, &u); | ||
| 265 | s = g_base64_encode((guchar *)data, u); | ||
| 266 | free(data); | ||
| 267 | printf("%s\n", s); | ||
| 268 | g_free(s); | ||
| 269 | break; | ||
| 270 | |||
| 271 | case PLIST_DATE: | ||
| 272 | plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); | ||
| 273 | s = g_time_val_to_iso8601(&tv); | ||
| 274 | printf("%s\n", s); | ||
| 275 | free(s); | ||
| 276 | break; | ||
| 277 | |||
| 278 | case PLIST_ARRAY: | ||
| 279 | case PLIST_DICT: | ||
| 280 | printf("\n"); | ||
| 281 | indent_level++; | ||
| 282 | plist_children_to_string(node); | ||
| 283 | indent_level--; | ||
| 284 | break; | ||
| 285 | |||
| 286 | default: | ||
| 287 | break; | ||
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 291 | void plist_children_to_string(plist_t node) | ||
| 292 | { | ||
| 293 | /* iterate over key/value pairs */ | ||
| 294 | plist_dict_iter it = NULL; | ||
| 295 | |||
| 296 | char* key = NULL; | ||
| 297 | plist_t subnode = NULL; | ||
| 298 | plist_dict_new_iter(node, &it); | ||
| 299 | plist_dict_next_item(node, it, &key, &subnode); | ||
| 300 | while (subnode) | ||
| 301 | { | ||
| 302 | printf("%*s", indent_level, ""); | ||
| 303 | printf("%s: ", key); | ||
| 304 | free(key); | ||
| 305 | key = NULL; | ||
| 306 | plist_node_to_string(subnode); | ||
| 307 | plist_dict_next_item(node, it, &key, &subnode); | ||
| 308 | } | ||
| 309 | free(it); | ||
| 310 | } | ||
| 311 | |||
