summaryrefslogtreecommitdiffstats
path: root/tools/ideviceinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ideviceinfo.c')
-rw-r--r--tools/ideviceinfo.c84
1 files changed, 46 insertions, 38 deletions
diff --git a/tools/ideviceinfo.c b/tools/ideviceinfo.c
index bd3819e..fd45763 100644
--- a/tools/ideviceinfo.c
+++ b/tools/ideviceinfo.c
@@ -24,6 +24,8 @@
#include <config.h>
#endif
+#define TOOL_NAME "ideviceinfo"
+
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -35,7 +37,7 @@
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
-#include "common/utils.h"
+#include <plist/plist.h>
#define FORMAT_KEY_VALUE 1
#define FORMAT_XML 2
@@ -72,10 +74,12 @@ static const char *domains[] = {
"com.apple.iTunes",
"com.apple.mobile.iTunes.store",
"com.apple.mobile.iTunes",
+ "com.apple.fmip",
+ "com.apple.Accessibility",
NULL
};
-static int is_domain_known(char *domain)
+static int is_domain_known(const char *domain)
{
int i = 0;
while (domains[i] != NULL) {
@@ -89,28 +93,32 @@ static int is_domain_known(char *domain)
static void print_usage(int argc, char **argv, int is_error)
{
int i = 0;
- char *name = NULL;
- name = strrchr(argv[0], '/');
+ char *name = strrchr(argv[0], '/');
fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
fprintf(is_error ? stderr : stdout,
- "Show information about a connected device.\n\n" \
- " -s, --simple use a simple connection to avoid auto-pairing with the device\n" \
- " -u, --udid UDID target specific device by UDID\n" \
- " -n, --network connect to network device even if available via USB\n" \
- " -q, --domain NAME set domain of query to NAME. Default: None\n" \
- " -k, --key NAME only query key specified by NAME. Default: All keys.\n" \
- " -x, --xml output information as xml plist instead of key/value pairs\n" \
- " -h, --help prints usage information\n" \
- " -d, --debug enable communication debugging\n" \
- "\n"
+ "\n"
+ "Show information about a connected device.\n"
+ "\n"
+ "OPTIONS:\n"
+ " -u, --udid UDID target specific device by UDID\n"
+ " -n, --network connect to network device\n"
+ " -s, --simple use simple connection to avoid auto-pairing with device\n"
+ " -q, --domain NAME set domain of query to NAME. Default: None\n" \
+ " -k, --key NAME only query key specified by NAME. Default: All keys.\n" \
+ " -x, --xml output information in XML property list format\n" \
+ " -h, --help prints usage information\n" \
+ " -d, --debug enable communication debugging\n" \
+ " -v, --version prints version information\n" \
+ "\n"
);
- fprintf(is_error ? stderr : stdout, " Known domains are:\n\n");
+ fprintf(is_error ? stderr : stdout, "Known domains are:\n\n");
while (domains[i] != NULL) {
fprintf(is_error ? stderr : stdout, " %s\n", domains[i++]);
}
fprintf(is_error ? stderr : stdout,
- "\n" \
- "Homepage: <" PACKAGE_URL ">\n"
+ "\n" \
+ "Homepage: <" PACKAGE_URL ">\n"
+ "Bug Reports: <" PACKAGE_BUGREPORT ">\n"
);
}
@@ -122,13 +130,13 @@ int main(int argc, char *argv[])
idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
int simple = 0;
int format = FORMAT_KEY_VALUE;
- char* udid = NULL;
- char *domain = NULL;
- char *key = NULL;
+ const char* udid = NULL;
+ int use_network = 0;
+ const char *domain = NULL;
+ const char *key = NULL;
char *xml_doc = NULL;
uint32_t xml_length;
plist_t node = NULL;
- enum idevice_options lookup_opts = IDEVICE_LOOKUP_USBMUX | IDEVICE_LOOKUP_NETWORK;
int c = 0;
const struct option longopts[] = {
@@ -138,7 +146,9 @@ int main(int argc, char *argv[])
{ "network", no_argument, NULL, 'n' },
{ "domain", required_argument, NULL, 'q' },
{ "key", required_argument, NULL, 'k' },
+ { "simple", no_argument, NULL, 's' },
{ "xml", no_argument, NULL, 'x' },
+ { "version", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0}
};
@@ -146,7 +156,7 @@ int main(int argc, char *argv[])
signal(SIGPIPE, SIG_IGN);
#endif
- while ((c = getopt_long(argc, argv, "dhu:nq:k:x", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "dhu:nq:k:sxv", longopts, NULL)) != -1) {
switch (c) {
case 'd':
idevice_set_debug_level(1);
@@ -157,11 +167,10 @@ int main(int argc, char *argv[])
print_usage(argc, argv, 1);
return 2;
}
- free(udid);
- udid = strdup(optarg);
+ udid = optarg;
break;
case 'n':
- lookup_opts |= IDEVICE_LOOKUP_PREFER_NETWORK;
+ use_network = 1;
break;
case 'q':
if (!*optarg) {
@@ -169,8 +178,7 @@ int main(int argc, char *argv[])
print_usage(argc, argv, 1);
return 2;
}
- free(domain);
- domain = strdup(optarg);
+ domain = optarg;
break;
case 'k':
if (!*optarg) {
@@ -178,8 +186,7 @@ int main(int argc, char *argv[])
print_usage(argc, argv, 1);
return 2;
}
- free(key);
- key = strdup(optarg);
+ key = optarg;
break;
case 'x':
format = FORMAT_XML;
@@ -190,6 +197,9 @@ int main(int argc, char *argv[])
case 'h':
print_usage(argc, argv, 0);
return 0;
+ case 'v':
+ printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION);
+ return 0;
default:
print_usage(argc, argv, 1);
return 2;
@@ -199,19 +209,19 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
- ret = idevice_new_with_options(&device, udid, lookup_opts);
+ ret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX);
if (ret != IDEVICE_E_SUCCESS) {
if (udid) {
- printf("ERROR: Device %s not found!\n", udid);
+ fprintf(stderr, "ERROR: Device %s not found!\n", udid);
} else {
- printf("ERROR: No device found!\n");
+ fprintf(stderr, "ERROR: No device found!\n");
}
return -1;
}
if (LOCKDOWN_E_SUCCESS != (ldret = simple ?
- lockdownd_client_new(device, &client, "ideviceinfo"):
- lockdownd_client_new_with_handshake(device, &client, "ideviceinfo"))) {
+ lockdownd_client_new(device, &client, TOOL_NAME):
+ lockdownd_client_new_with_handshake(device, &client, TOOL_NAME))) {
fprintf(stderr, "ERROR: Could not connect to lockdownd: %s (%d)\n", lockdownd_strerror(ldret), ldret);
idevice_free(device);
return -1;
@@ -231,11 +241,11 @@ int main(int argc, char *argv[])
free(xml_doc);
break;
case FORMAT_KEY_VALUE:
- plist_print_to_stream(node, stdout);
+ plist_write_to_stream(node, stdout, PLIST_FORMAT_LIMD, 0);
break;
default:
if (key != NULL)
- plist_print_to_stream(node, stdout);
+ plist_write_to_stream(node, stdout, PLIST_FORMAT_LIMD, 0);
break;
}
plist_free(node);
@@ -243,8 +253,6 @@ int main(int argc, char *argv[])
}
}
- if (domain != NULL)
- free(domain);
lockdownd_client_free(client);
idevice_free(device);