From e449f1b3699f356b4e3238ca287e371656c4136c Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Mon, 11 May 2009 17:28:31 +0200 Subject: Add explicit check and flags for libgcrypt needed for some distributions --- configure.ac | 1 + src/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 68929ff..210105a 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,7 @@ PKG_CHECK_MODULES(libgthread2, gthread-2.0 >= 2.14.1) PKG_CHECK_MODULES(libgnutls, gnutls >= 1.6.3 ) PKG_CHECK_MODULES(libtasn1, libtasn1 >= 1.1) PKG_CHECK_MODULES(libplist, libplist >= 0.12) +AC_CHECK_LIB(gcrypt, gcry_control, [AC_SUBST(libgcrypt_LIBS,[-lgcrypt])], ["libgcrypt is required to build libiphone"]) # Checks for header files. AC_HEADER_STDC diff --git a/src/Makefile.am b/src/Makefile.am index 2ae1943..0cae16b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ INCLUDES = -I$(top_srcdir)/include AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) -AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) +AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libgcrypt_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) lib_LTLIBRARIES = libiphone.la libiphone_la_SOURCES = usbmux.c usbmux.h \ -- cgit v1.1-32-gdbae From f5ab55ba0b16bce9fd359a5391fec8486839c27d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Mon, 11 May 2009 18:06:06 +0200 Subject: Fix distcheck target for swig binding generation --- swig/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swig/Makefile.am b/swig/Makefile.am index 726014b..d65b984 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = -I$(top_srcdir)/include $(libplist_CFLAGS) -I$(includedir) +INCLUDES = -I$(top_srcdir)/include $(libplist_CFLAGS) -I$(oldincludedir) BUILT_SOURCES = iphone_wrap.c SWIG_SOURCES = iphone.i -- cgit v1.1-32-gdbae From 4ae6a292dfcbf7b67d54934c8782667e748b388d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sun, 24 May 2009 14:45:41 +0200 Subject: Remove libusb and add libusbmuxd to pkg-config file requires --- libiphone-1.0.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libiphone-1.0.pc.in b/libiphone-1.0.pc.in index 562cf56..323a73d 100644 --- a/libiphone-1.0.pc.in +++ b/libiphone-1.0.pc.in @@ -6,7 +6,7 @@ includedir=@includedir@ Name: libiphone Description: A library to communicate with the Lockdown server on the iPhone Version: @VERSION@ -Requires: libplist >= 0.12 libusb >= 0.1.12 glib-2.0 >= 2.14.1 gthread-2.0 >= 2.14.1 gnutls >= 1.6.3 libtasn1 >= 1.1 +Requires: libplist >= 0.12 libusbmuxd >= 0.1.0 glib-2.0 >= 2.14.1 gthread-2.0 >= 2.14.1 gnutls >= 1.6.3 libtasn1 >= 1.1 Libs: -L${libdir} -liphone Cflags: -I${includedir} -- cgit v1.1-32-gdbae From 38a37213ba6d5a2746cd7d5085d4d1587e7f8408 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 8 Jun 2009 02:42:22 +0200 Subject: lockdown: fix receive of large TLS-encapsulated plists Signed-off-by: Martin Szulecki --- src/lockdown.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lockdown.c b/src/lockdown.c index ae408be..a950ceb 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -211,23 +211,27 @@ iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist) } } datalen = ntohl(datalen); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: datalen = %d\n", __func__, datalen); receive = (char *) malloc(sizeof(char) * datalen); + /* fill buffer and request more packets if needed */ if (!client->in_SSL) { - /* fill buffer and request more packets if needed */ while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes); received_bytes += bytes; } } else { - ssize_t res = gnutls_record_recv(*client->ssl_session, receive, datalen); - if (res < 0) { - log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res)); - ret = IPHONE_E_SSL_ERROR; - } else { - received_bytes = res; - ret = IPHONE_E_SUCCESS; + ssize_t res = 0; + while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { + res = gnutls_record_recv(*client->ssl_session, receive + received_bytes, datalen - received_bytes); + if (res < 0) { + log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res)); + ret = IPHONE_E_SSL_ERROR; + } else { + received_bytes += res; + ret = IPHONE_E_SUCCESS; + } } } -- cgit v1.1-32-gdbae From bdeaf4eb9c6b3d40bc4be3a13e9c0f8c9ed5f429 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 19 Jun 2009 13:15:39 +0200 Subject: Add product ids to support iPhone 3GS --- fdi/31-apple-mobile-device.fdi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fdi/31-apple-mobile-device.fdi b/fdi/31-apple-mobile-device.fdi index d598409..5d4427b 100644 --- a/fdi/31-apple-mobile-device.fdi +++ b/fdi/31-apple-mobile-device.fdi @@ -4,7 +4,7 @@ - + afc -- cgit v1.1-32-gdbae From 0727ae7c72bf149bf5898c667933a27d44e94f7d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sun, 21 Jun 2009 23:02:22 +0200 Subject: Lkdn times out after few seconds idle so close it early and fix a crash on quit --- dev/syslog_relay.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 3407f2f..e552e9c 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -60,6 +61,7 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { iphone_set_debug_mask(DBGMASK_ALL); + iphone_set_debug(1); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { @@ -105,6 +107,8 @@ int main(int argc, char *argv[]) /* start syslog_relay service and retrieve port */ ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); if ((ret == IPHONE_E_SUCCESS) && port) { + iphone_lckd_free_client(control); + /* connect to socket relay messages */ int sfd = usbmuxd_connect(iphone_get_device_handle(phone), port); @@ -143,7 +147,6 @@ int main(int argc, char *argv[]) printf("ERROR: Could not start service com.apple.syslog_relay.\n"); } - iphone_lckd_free_client(control); iphone_free_device(phone); return 0; -- cgit v1.1-32-gdbae From 773f5c797622bedbc2aed0ee8d8680e45a2807d2 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sun, 21 Jun 2009 23:05:23 +0200 Subject: Silence warning and also dump iTunes format support information --- dev/iphoneinfo.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index c28eb9e..cee8dff 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -43,6 +44,7 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { iphone_set_debug_mask(DBGMASK_ALL); + iphone_set_debug(1); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { @@ -98,6 +100,7 @@ int main(int argc, char *argv[]) print_lckd_request_info(control, "com.apple.mobile.sync_data_class", "GetValue", NULL); print_lckd_request_info(control, "com.apple.iTunes", "GetValue", NULL); print_lckd_request_info(control, "com.apple.mobile.iTunes.store", "GetValue", NULL); + print_lckd_request_info(control, "com.apple.mobile.iTunes", "GetValue", NULL); iphone_lckd_free_client(control); iphone_free_device(phone); -- cgit v1.1-32-gdbae From 4697b70a0110d15c2a79804e1e2e2fcf7a3b3ec5 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sun, 21 Jun 2009 23:06:30 +0200 Subject: Silence compiler warning for dispatch_AFC_packet() --- src/AFC.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AFC.c b/src/AFC.c index 71093df..abaeb3f 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -213,7 +213,7 @@ int iphone_afc_get_errno(iphone_afc_client_t client) * reason is that if you set them to different values, it indicates * you want to send the data as two packets. */ -static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int length) +static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, uint64_t length) { int bytes = 0, offset = 0; char *buffer; -- cgit v1.1-32-gdbae From ba381c9fb036f63c6db42da7cc606847a934cd44 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Mon, 22 Jun 2009 00:36:35 +0200 Subject: Update python bindings to use allow targeting device by uuid --- swig/iphone.i | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/swig/iphone.i b/swig/iphone.i index 7a003d4..0a337ad 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -16,7 +16,7 @@ } Lockdownd; typedef struct { - Lockdownd* lckd; + iPhone* dev; iphone_msync_client_t client; } MobileSync; @@ -29,6 +29,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd); %} /* Parse the header file to generate wrappers */ %include "stdint.i" +%include "cstring.i" %include "plist/swig/plist.i" #define DBGMASK_ALL 0xFFFF @@ -47,7 +48,7 @@ typedef struct { } Lockdownd; typedef struct { - Lockdownd* lckd; + iPhone* dev; iphone_msync_client_t client; } MobileSync; @@ -78,7 +79,6 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) { void my_delete_Lockdownd(Lockdownd* lckd) { if (lckd) { - my_delete_iPhone(lckd->dev); iphone_lckd_free_client ( lckd->client ); free(lckd); } @@ -90,7 +90,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { int port = 0; if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { client = (MobileSync*) malloc(sizeof(MobileSync)); - client->lckd = lckd; + client->dev = lckd->dev; client->client = NULL; iphone_msync_new_client ( lckd->dev->dev, port, &(client->client)); } @@ -115,15 +115,28 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { iphone_set_debug_mask(mask); } + void set_debug_level(int level) { + iphone_set_debug(level); + } + + int init_device_by_uuid(char* uuid) { + if (IPHONE_E_SUCCESS == iphone_get_device_by_uuid ( &($self->dev), uuid)) + return 1; + return 0; + } + int init_device() { if (IPHONE_E_SUCCESS == iphone_get_device ( &($self->dev))) return 1; return 0; } - char* serial_number(){ - return iphone_get_uuid($self->dev); - } + %newobject get_uuid; + char* get_uuid(){ + char* uuid = NULL; + uuid = (char *)iphone_get_uuid($self->dev); + return uuid; + } Lockdownd* get_lockdown_client() { return my_new_Lockdownd($self); @@ -162,7 +175,6 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { } ~MobileSync() { - my_delete_Lockdownd($self->lckd); iphone_msync_free_client ( $self->client ); free($self); } -- cgit v1.1-32-gdbae From 0463978f0c43d37e053d916b14c16121505266bb Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 27 Jun 2009 18:09:30 +0200 Subject: Make iphoneinfo useful by adding XML output and queries by domain and/or key --- dev/iphoneinfo.c | 126 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 105 insertions(+), 21 deletions(-) diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index cee8dff..641b47d 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -26,8 +26,26 @@ #include +#define FORMAT_KEY_VALUE 1 +#define FORMAT_XML 2 + +static const char *domains[] = { + "com.apple.disk_usage", + "com.apple.mobile.battery", +/* FIXME: For some reason lockdownd segfaults on this, works sometimes though + "com.apple.mobile.debug",. */ + "com.apple.xcode.developerdomain", + "com.apple.international", + "com.apple.mobile.sync_data_class", + "com.apple.iTunes", + "com.apple.mobile.iTunes.store", + "com.apple.mobile.iTunes", + NULL +}; + +int is_domain_known(char *domain); void print_usage(int argc, char **argv); -void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, const char *request, const char *key); +void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format); void plist_node_to_string(plist_t *node); void plist_children_to_string(plist_t *node); @@ -37,7 +55,10 @@ int main(int argc, char *argv[]) iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; + int format = FORMAT_KEY_VALUE; char uuid[41]; + char *domain = NULL; + char *key = NULL; uuid[0] = 0; /* parse cmdline args */ @@ -56,6 +77,31 @@ int main(int argc, char *argv[]) strcpy(uuid, argv[i]); continue; } + else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--domain")) { + i++; + if (!argv[i] || (strlen(argv[i]) < 4)) { + print_usage(argc, argv); + return 0; + } + if (!is_domain_known(argv[i])) { + fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]); + } + domain = strdup(argv[i]); + continue; + } + else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--key")) { + i++; + if (!argv[i] || (strlen(argv[i]) <= 1)) { + print_usage(argc, argv); + return 0; + } + key = strdup(argv[i]); + continue; + } + else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) { + format = FORMAT_XML; + continue; + } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { print_usage(argc, argv); return 0; @@ -87,35 +133,45 @@ int main(int argc, char *argv[]) return -1; } - /* dump all information we can retrieve */ - printf("# general\n"); - print_lckd_request_info(control, NULL, "GetValue", NULL); - print_lckd_request_info(control, "com.apple.disk_usage", "GetValue", NULL); - print_lckd_request_info(control, "com.apple.mobile.battery", "GetValue", NULL); - /* FIXME: For some reason lockdownd segfaults on this, works sometimes though - print_lckd_request_info(control, "com.apple.mobile.debug", "GetValue", NULL); - */ - print_lckd_request_info(control, "com.apple.xcode.developerdomain", "GetValue", NULL); - print_lckd_request_info(control, "com.apple.international", "GetValue", NULL); - print_lckd_request_info(control, "com.apple.mobile.sync_data_class", "GetValue", NULL); - print_lckd_request_info(control, "com.apple.iTunes", "GetValue", NULL); - print_lckd_request_info(control, "com.apple.mobile.iTunes.store", "GetValue", NULL); - print_lckd_request_info(control, "com.apple.mobile.iTunes", "GetValue", NULL); + /* run query and output information */ + print_lckd_request_result(control, domain, "GetValue", key, format); + if (domain != NULL) + free(domain); iphone_lckd_free_client(control); iphone_free_device(phone); return 0; } +int is_domain_known(char *domain) +{ + int i = 0; + while (domains[i] != NULL) { + if (strstr(domain, domains[i++])) { + return 1; + } + } + return 0; +} + void print_usage(int argc, char **argv) { + int i = 0; printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); printf("Show information about the first connected iPhone/iPod Touch.\n\n"); printf(" -d, --debug\t\tenable communication debugging\n"); printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); + printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n"); + printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n"); + printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n"); printf(" -h, --help\t\tprints usage information\n"); printf("\n"); + printf(" Known domains are:\n\n"); + while (domains[i] != NULL) { + printf(" %s\n", domains[i++]); + } + printf("\n"); } void plist_node_to_string(plist_t *node) @@ -189,14 +245,16 @@ void plist_children_to_string(plist_t *node) } } -void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, const char *request, const char *key) { +void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format) { + char *xml_doc = NULL; + char *s = NULL; + uint32_t xml_length = 0; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_t node = plist_new_dict(); if (domain) { plist_add_sub_key_el(node, "Domain"); plist_add_sub_string_el(node, domain); - printf("# %s\n", domain); } if (key) { plist_add_sub_key_el(node, "Key"); @@ -211,15 +269,41 @@ void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, c node = NULL; ret = iphone_lckd_recv(control, &node); if (ret == IPHONE_E_SUCCESS) { - /* seek to first dict node */ + /* seek to value node */ for ( node = plist_get_first_child(node); - node && (plist_get_node_type(node) != PLIST_DICT); + node != NULL; node = plist_get_next_sibling(node) ) { + if(plist_get_node_type(node) == PLIST_KEY) + { + plist_get_key_val(node, &s); + + if (strcmp("Value", s)) + continue; + + node = plist_get_next_sibling(node); + + if (plist_get_node_type(node) == PLIST_DICT) { + if (plist_get_first_child(node)) + { + switch (format) { + case FORMAT_XML: + plist_to_xml(node, &xml_doc, &xml_length); + printf(xml_doc); + free(xml_doc); + break; + case FORMAT_KEY_VALUE: + default: + plist_children_to_string(node); + break; + } + } + } + else if(node && (key != NULL)) + plist_node_to_string(node); + } } - if(plist_get_first_child(node)) - plist_children_to_string(node); } } if (node) -- cgit v1.1-32-gdbae From 922339633b08d0815eaf236c94edb774e190ff7f Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Wed, 1 Jul 2009 18:17:16 +0200 Subject: Fix segfault when displaying usage for installed iphoneinfo and iphonesyslog --- dev/iphoneinfo.c | 5 ++++- dev/syslog_relay.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 641b47d..18ee055 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -158,7 +158,10 @@ int is_domain_known(char *domain) void print_usage(int argc, char **argv) { int i = 0; - printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); + char *name = NULL; + + name = strrchr(argv[0], '/'); + printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); printf("Show information about the first connected iPhone/iPod Touch.\n\n"); printf(" -d, --debug\t\tenable communication debugging\n"); printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index e552e9c..6698653 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -154,7 +154,10 @@ int main(int argc, char *argv[]) void print_usage(int argc, char **argv) { - printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); + char *name = NULL; + + name = strrchr(argv[0], '/'); + printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); printf("Relay syslog of a connected iPhone/iPod Touch.\n\n"); printf(" -d, --debug\t\tenable communication debugging\n"); printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); -- cgit v1.1-32-gdbae From abb74bcae219c25cffb7e30db6a34c69dcd92f0a Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 6 Jul 2009 19:38:00 +0200 Subject: API cleanup for AFC Signed-off-by: Martin Szulecki --- dev/afccheck.c | 21 ++++++++-------- dev/main.c | 47 ++++++++++++++++++----------------- include/Makefile.am | 2 +- include/libiphone/afc.h | 54 ++++++++++++++++++++++++++++++++++++++++ include/libiphone/libiphone.h | 40 ------------------------------ src/AFC.c | 57 +++++++++++++++++++++++-------------------- src/AFC.h | 5 +--- 7 files changed, 121 insertions(+), 105 deletions(-) create mode 100644 include/libiphone/afc.h diff --git a/dev/afccheck.c b/dev/afccheck.c index 965981b..b107437 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -25,13 +25,14 @@ #include #include +#include #define BUFFER_SIZE 20000 #define NB_THREADS 10 typedef struct { - iphone_afc_client_t afc; + afc_client_t afc; int id; } param; @@ -53,18 +54,18 @@ void check_afc(gpointer data) uint64_t file = 0; char path[50]; sprintf(path, "/Buf%i", ((param *) data)->id); - iphone_afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RW, &file); - iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); - iphone_afc_close_file(((param *) data)->afc, file); + afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RW, &file); + afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); + afc_close_file(((param *) data)->afc, file); file = 0; if (bytes != buffersize) printf("Write operation failed\n"); //now read it bytes = 0; - iphone_afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); - iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); - iphone_afc_close_file(((param *) data)->afc, file); + afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); + afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); + afc_close_file(((param *) data)->afc, file); if (bytes != buffersize) printf("Read operation failed\n"); @@ -77,7 +78,7 @@ void check_afc(gpointer data) } //cleanup - iphone_afc_delete_file(((param *) data)->afc, path); + afc_delete_file(((param *) data)->afc, path); g_thread_exit(0); } @@ -87,7 +88,7 @@ int main(int argc, char *argv[]) iphone_device_t phone = NULL; GError *err; int port = 0; - iphone_afc_client_t afc = NULL; + afc_client_t afc = NULL; if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); @@ -106,7 +107,7 @@ int main(int argc, char *argv[]) return 1; } - iphone_afc_new_client(phone, port, &afc); + afc_new_client(phone, port, &afc); //makes sure thread environment is available if (!g_thread_supported()) diff --git a/dev/main.c b/dev/main.c index c8c9dfa..fe340ff 100644 --- a/dev/main.c +++ b/dev/main.c @@ -25,6 +25,7 @@ #include #include +#include #include "../src/utils.h" void notifier(const char *notification) @@ -97,8 +98,8 @@ int main(int argc, char *argv[]) iphone_lckd_start_service(control, "com.apple.afc", &port); if (port) { - iphone_afc_client_t afc = NULL; - iphone_afc_new_client(phone, port, &afc); + afc_client_t afc = NULL; + afc_new_client(phone, port, &afc); if (afc) { iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); if (npp) { @@ -120,18 +121,18 @@ int main(int argc, char *argv[]) perform_notification(phone, control, NP_SYNC_WILL_START); - iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); + afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); - iphone_afc_lock_file(afc, lockfile, 2 | 4); + afc_lock_file(afc, lockfile, 2 | 4); perform_notification(phone, control, NP_SYNC_DID_START); } char **dirs = NULL; - iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); + afc_get_dir_list(afc, "/eafaedf", &dirs); if (!dirs) - iphone_afc_get_dir_list(afc, "/", &dirs); + afc_get_dir_list(afc, "/", &dirs); printf("Directory time.\n"); for (i = 0; dirs[i]; i++) { printf("/%s\n", dirs[i]); @@ -140,7 +141,7 @@ int main(int argc, char *argv[]) g_strfreev(dirs); dirs = NULL; - iphone_afc_get_devinfo(afc, &dirs); + afc_get_devinfo(afc, &dirs); if (dirs) { for (i = 0; dirs[i]; i += 2) { printf("%s: %s\n", dirs[i], dirs[i + 1]); @@ -151,7 +152,7 @@ int main(int argc, char *argv[]) uint64_t my_file = 0; char **info = NULL; uint64_t fsize = 0; - if (IPHONE_E_SUCCESS == iphone_afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { + if (IPHONE_E_SUCCESS == afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { for (i = 0; info[i]; i += 2) { printf("%s: %s\n", info[i], info[i+1]); if (!strcmp(info[i], "st_size")) { @@ -161,58 +162,58 @@ int main(int argc, char *argv[]) } if (IPHONE_E_SUCCESS == - iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { + afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { printf("A file size: %i\n", fsize); char *file_data = (char *) malloc(sizeof(char) * fsize); - iphone_afc_read_file(afc, my_file, file_data, fsize, &bytes); + afc_read_file(afc, my_file, file_data, fsize, &bytes); if (bytes >= 0) { printf("The file's data:\n"); fwrite(file_data, 1, bytes, stdout); } printf("\nClosing my file.\n"); - iphone_afc_close_file(afc, my_file); + afc_close_file(afc, my_file); free(file_data); } else printf("couldn't open a file\n"); - iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); + afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); if (my_file) { char *outdatafile = strdup("this is a bitchin text file\n"); - iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); + afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); free(outdatafile); if (bytes > 0) printf("Wrote a surprise. ;)\n"); else printf("I wanted to write a surprise, but... :(\n"); - iphone_afc_close_file(afc, my_file); + afc_close_file(afc, my_file); } printf("Deleting a file...\n"); - bytes = iphone_afc_delete_file(afc, "/delme"); + bytes = afc_delete_file(afc, "/delme"); if (bytes) printf("Success.\n"); else printf("Failure. (expected unless you have a /delme file on your phone)\n"); printf("Renaming a file...\n"); - bytes = iphone_afc_rename_file(afc, "/renme", "/renme2"); + bytes = afc_rename_file(afc, "/renme", "/renme2"); if (bytes > 0) printf("Success.\n"); else printf("Failure. (expected unless you have a /renme file on your phone)\n"); printf("Seek & read\n"); - iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); - if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5, SEEK_CUR)) + afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); + if (IPHONE_E_SUCCESS != afc_seek_file(afc, my_file, 5, SEEK_CUR)) printf("WARN: SEEK DID NOT WORK\n"); char *threeletterword = (char *) malloc(sizeof(char) * 5); - iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes); + afc_read_file(afc, my_file, threeletterword, 3, &bytes); threeletterword[3] = '\0'; if (bytes > 0) printf("Result: %s\n", threeletterword); else printf("Couldn't read!\n"); free(threeletterword); - iphone_afc_close_file(afc, my_file); + afc_close_file(afc, my_file); } if (gnp && lockfile) { @@ -245,10 +246,10 @@ int main(int argc, char *argv[]) //perform_notification(phone, control, NP_SYNC_DID_FINISH); printf("XXX unlocking file\n"); - iphone_afc_lock_file(afc, lockfile, 8 | 4); + afc_lock_file(afc, lockfile, 8 | 4); printf("XXX closing file\n"); - iphone_afc_close_file(afc, lockfile); + afc_close_file(afc, lockfile); } if (gnp) { @@ -256,7 +257,7 @@ int main(int argc, char *argv[]) gnp = NULL; } - iphone_afc_free_client(afc); + afc_free_client(afc); } else { printf("Start service failure.\n"); } diff --git a/include/Makefile.am b/include/Makefile.am index a5f8766..4c17261 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -nobase_include_HEADERS = libiphone/libiphone.h +nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h new file mode 100644 index 0000000..2a0bbad --- /dev/null +++ b/include/libiphone/afc.h @@ -0,0 +1,54 @@ +#ifndef AFC_H +#define AFC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef enum { + AFC_FOPEN_RDONLY = 0x00000001, // r O_RDONLY + AFC_FOPEN_RW = 0x00000002, // r+ O_RDWR | O_CREAT + AFC_FOPEN_WRONLY = 0x00000003, // w O_WRONLY | O_CREAT | O_TRUNC + AFC_FOPEN_WR = 0x00000004, // w+ O_RDWR | O_CREAT | O_TRUNC + AFC_FOPEN_APPEND = 0x00000005, // a O_WRONLY | O_APPEND | O_CREAT + AFC_FOPEN_RDAPPEND = 0x00000006 // a+ O_RDWR | O_APPEND | O_CREAT +} afc_file_mode_t; + +typedef enum { + AFC_HARDLINK = 1, + AFC_SYMLINK = 2 +} afc_link_type_t; + +struct afc_client_int; +typedef struct afc_client_int *afc_client_t; + +//afc related functions +iphone_error_t afc_new_client ( iphone_device_t device, int dst_port, afc_client_t *client ); +iphone_error_t afc_free_client ( afc_client_t client ); +int afc_get_afcerror ( afc_client_t client ); +int afc_get_errno ( afc_client_t client ); + +iphone_error_t afc_get_devinfo ( afc_client_t client, char ***infos ); +iphone_error_t afc_get_dir_list ( afc_client_t client, const char *dir, char ***list); + +iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist ); +iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle ); +iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle); +iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, int operation); +iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); +iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); +iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence); +iphone_error_t afc_truncate_file ( afc_client_t client, uint64_t handle, uint64_t newsize); +iphone_error_t afc_delete_file ( afc_client_t client, const char *path); +iphone_error_t afc_rename_file ( afc_client_t client, const char *from, const char *to); +iphone_error_t afc_mkdir ( afc_client_t client, const char *dir); +iphone_error_t afc_truncate ( afc_client_t client, const char *path, off_t newsize); +iphone_error_t afc_make_link ( afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 463efa7..3f5d86c 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -54,29 +54,12 @@ extern "C" { typedef int16_t iphone_error_t; -typedef enum { - AFC_FOPEN_RDONLY = 0x00000001, // r O_RDONLY - AFC_FOPEN_RW = 0x00000002, // r+ O_RDWR | O_CREAT - AFC_FOPEN_WRONLY = 0x00000003, // w O_WRONLY | O_CREAT | O_TRUNC - AFC_FOPEN_WR = 0x00000004, // w+ O_RDWR | O_CREAT | O_TRUNC - AFC_FOPEN_APPEND = 0x00000005, // a O_WRONLY | O_APPEND | O_CREAT - AFC_FOPEN_RDAPPEND = 0x00000006 // a+ O_RDWR | O_APPEND | O_CREAT -} iphone_afc_file_mode_t; - -typedef enum { - IPHONE_AFC_HARDLINK = 1, - IPHONE_AFC_SYMLINK = 2 -} iphone_afc_link_type_t; - struct iphone_device_int; typedef struct iphone_device_int *iphone_device_t; struct iphone_lckd_client_int; typedef struct iphone_lckd_client_int *iphone_lckd_client_t; -struct iphone_afc_client_int; -typedef struct iphone_afc_client_int *iphone_afc_client_t; - struct iphone_msync_client_int; typedef struct iphone_msync_client_int *iphone_msync_client_t; @@ -111,29 +94,6 @@ iphone_error_t iphone_lckd_recv ( iphone_lckd_client_t client, plist_t* plist); iphone_error_t iphone_lckd_send ( iphone_lckd_client_t client, plist_t plist); -//afc related functions -iphone_error_t iphone_afc_new_client ( iphone_device_t device, int dst_port, iphone_afc_client_t *client ); -iphone_error_t iphone_afc_free_client ( iphone_afc_client_t client ); -int iphone_afc_get_afcerror ( iphone_afc_client_t client ); -int iphone_afc_get_errno ( iphone_afc_client_t client ); - -iphone_error_t iphone_afc_get_devinfo ( iphone_afc_client_t client, char ***infos ); -iphone_error_t iphone_afc_get_dir_list ( iphone_afc_client_t client, const char *dir, char ***list); - -iphone_error_t iphone_afc_get_file_info ( iphone_afc_client_t client, const char *filename, char ***infolist ); -iphone_error_t iphone_afc_open_file ( iphone_afc_client_t client, const char *filename, iphone_afc_file_mode_t file_mode, uint64_t *handle ); -iphone_error_t iphone_afc_close_file ( iphone_afc_client_t client, uint64_t handle); -iphone_error_t iphone_afc_lock_file ( iphone_afc_client_t client, uint64_t handle, int operation); -iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); -iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); -iphone_error_t iphone_afc_seek_file ( iphone_afc_client_t client, uint64_t handle, int64_t offset, int whence); -iphone_error_t iphone_afc_truncate_file ( iphone_afc_client_t client, uint64_t handle, uint64_t newsize); -iphone_error_t iphone_afc_delete_file ( iphone_afc_client_t client, const char *path); -iphone_error_t iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to); -iphone_error_t iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir); -iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize); -iphone_error_t iphone_afc_make_link ( iphone_afc_client_t client, iphone_afc_link_type_t linktype, const char *target, const char *linkname); - iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, iphone_msync_client_t * client); diff --git a/src/AFC.c b/src/AFC.c index 960d640..e666c45 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -24,8 +24,11 @@ #include #include #include "AFC.h" +#include "iphone.h" #include "utils.h" +#include + // This is the maximum size an AFC data packet can be const int MAXIMUM_PACKET_SIZE = (2 << 15); @@ -34,7 +37,7 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15); * * @param client The AFC client connection to lock */ -static void afc_lock(iphone_afc_client_t client) +static void afc_lock(afc_client_t client) { log_debug_msg("Locked\n"); /*while (client->lock) { @@ -48,7 +51,7 @@ static void afc_lock(iphone_afc_client_t client) * * @param client The AFC */ -static void afc_unlock(iphone_afc_client_t client) +static void afc_unlock(afc_client_t client) { // just to be pretty log_debug_msg("Unlocked\n"); //client->lock = 0; @@ -63,7 +66,7 @@ static void afc_unlock(iphone_afc_client_t client) * * @return A handle to the newly-connected client or NULL upon error. */ -iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphone_afc_client_t * client) +iphone_error_t afc_new_client(iphone_device_t device, int dst_port, afc_client_t * client) { //makes sure thread environment is available if (!g_thread_supported()) @@ -78,7 +81,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphon return IPHONE_E_UNKNOWN_ERROR; // ret; } - iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int)); + afc_client_t client_loc = (afc_client_t) malloc(sizeof(struct afc_client_int)); client_loc->sfd = sfd; // Allocate a packet @@ -105,7 +108,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphon * * @param client The client to disconnect. */ -iphone_error_t iphone_afc_free_client(iphone_afc_client_t client) +iphone_error_t afc_free_client(afc_client_t client) { if (!client || client->sfd < 0 || !client->afc_packet) return IPHONE_E_INVALID_ARG; @@ -127,7 +130,7 @@ iphone_error_t iphone_afc_free_client(iphone_afc_client_t client) * * @return AFC error code or -1 on error. */ -int iphone_afc_get_afcerror(iphone_afc_client_t client) +int afc_get_afcerror(afc_client_t client) { int res = -1; if (client) { @@ -140,13 +143,13 @@ int iphone_afc_get_afcerror(iphone_afc_client_t client) /** * Tries to convert the AFC error value into a meaningful errno value. - * Internally used by iphone_afc_get_errno. + * Internally used by afc_get_errno. * * @param afcerror AFC error value to convert * * @return errno value or -1 if the errno could not be determined. * - * @see iphone_afc_get_errno + * @see afc_get_errno */ static int afcerror_to_errno(int afcerror) { @@ -189,7 +192,7 @@ static int afcerror_to_errno(int afcerror) * * @return errno value or -1 on error. */ -int iphone_afc_get_errno(iphone_afc_client_t client) +int afc_get_errno(afc_client_t client) { int res = -1; if (client) { @@ -213,7 +216,7 @@ int iphone_afc_get_errno(iphone_afc_client_t client) * reason is that if you set them to different values, it indicates * you want to send the data as two packets. */ -static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, uint64_t length) +static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t length) { int bytes = 0, offset = 0; char *buffer; @@ -294,7 +297,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, uin * received raised a non-trivial error condition (i.e. non-zero with * AFC_ERROR operation) */ -static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) +static int receive_AFC_data(afc_client_t client, char **dump_here) { AFCPacket header; int bytes = 0; @@ -468,7 +471,7 @@ static char **make_strings_list(char *tokens, int true_length) * @return A char ** list of files in that directory, terminated by an empty * string for now or NULL if there was an error. */ -iphone_error_t iphone_afc_get_dir_list(iphone_afc_client_t client, const char *dir, char ***list) +iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***list) { int bytes = 0; char *data = NULL, **list_loc = NULL; @@ -514,7 +517,7 @@ iphone_error_t iphone_afc_get_dir_list(iphone_afc_client_t client, const char *d * @return A char ** list of parameters as given by AFC or NULL if there was an * error. */ -iphone_error_t iphone_afc_get_devinfo(iphone_afc_client_t client, char ***infos) +iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos) { int bytes = 0; char *data = NULL, **list = NULL; @@ -556,7 +559,7 @@ iphone_error_t iphone_afc_get_devinfo(iphone_afc_client_t client, char ***infos) * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *path) +iphone_error_t afc_delete_file(afc_client_t client, const char *path) { char *response = NULL; int bytes; @@ -596,7 +599,7 @@ iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *pa * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *from, const char *to) +iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char *to) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t))); @@ -640,7 +643,7 @@ iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *fr * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_mkdir(iphone_afc_client_t client, const char *dir) +iphone_error_t afc_mkdir(afc_client_t client, const char *dir) { int bytes = 0; char *response = NULL; @@ -682,7 +685,7 @@ iphone_error_t iphone_afc_mkdir(iphone_afc_client_t client, const char *dir) * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error value * when something went wrong. */ -iphone_error_t iphone_afc_get_file_info(iphone_afc_client_t client, const char *path, char ***infolist) +iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) { char *received = NULL; int length; @@ -726,8 +729,8 @@ iphone_error_t iphone_afc_get_file_info(iphone_afc_client_t client, const char * * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error on failure. */ iphone_error_t -iphone_afc_open_file(iphone_afc_client_t client, const char *filename, - iphone_afc_file_mode_t file_mode, uint64_t *handle) +afc_open_file(afc_client_t client, const char *filename, + afc_file_mode_t file_mode, uint64_t *handle) { uint32_t ag = 0; int bytes = 0, length = 0; @@ -786,7 +789,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename, * @return The number of bytes read if successful. If there was an error -1. */ iphone_error_t -iphone_afc_read_file(iphone_afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) +afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) { char *input = NULL; int current_count = 0, bytes_loc = 0; @@ -857,7 +860,7 @@ iphone_afc_read_file(iphone_afc_client_t client, uint64_t handle, char *data, in * none were written... */ iphone_error_t -iphone_afc_write_file(iphone_afc_client_t client, uint64_t handle, +afc_write_file(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t * bytes) { char *acknowledgement = NULL; @@ -946,7 +949,7 @@ iphone_afc_write_file(iphone_afc_client_t client, uint64_t handle, * @param client The client to close the file with. * @param handle File handle of a previously opened file. */ -iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, uint64_t handle) +iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) { if (!client || (handle == 0)) return IPHONE_E_INVALID_ARG; @@ -997,7 +1000,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, uint64_t handle * @param handle File handle of a previously opened file. * @operation the lock or unlock operation to perform. */ -iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, uint64_t handle, int operation) +iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation) { if (!client || (handle == 0)) return IPHONE_E_INVALID_ARG; @@ -1046,7 +1049,7 @@ iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, uint64_t handle, * * @return IPHONE_E_SUCCESS on success, IPHONE_E_NOT_ENOUGH_DATA on failure. */ -iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, uint64_t handle, int64_t offset, int whence) +iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offset, int whence) { char *buffer = (char *) malloc(sizeof(char) * 24); uint32_t zero = 0; @@ -1093,7 +1096,7 @@ iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, uint64_t handle, * @note This function is more akin to ftruncate than truncate, and truncate * calls would have to open the file before calling this, sadly. */ -iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, uint64_t handle, uint64_t newsize) +iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t newsize) { char *buffer = (char *) malloc(sizeof(char) * 16); int bytes = 0; @@ -1135,7 +1138,7 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, uint64_t han * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize) +iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); @@ -1181,7 +1184,7 @@ iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_make_link(iphone_afc_client_t client, iphone_afc_link_type_t linktype, const char *target, const char *linkname) +iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); diff --git a/src/AFC.h b/src/AFC.h index a9c33c3..5d337e5 100644 --- a/src/AFC.h +++ b/src/AFC.h @@ -19,9 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libiphone/libiphone.h" -#include "iphone.h" - #include #include #include @@ -46,7 +43,7 @@ typedef struct __AFCToken { char *token; } AFCToken; -struct iphone_afc_client_int { +struct afc_client_int { int sfd; AFCPacket *afc_packet; int file_handle; -- cgit v1.1-32-gdbae From a1e2fec59eb7d0d2a3adbd4691b3ea2ee1302921 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 6 Jul 2009 19:46:35 +0200 Subject: API cleanup for NotificationProxy Signed-off-by: Martin Szulecki --- dev/main.c | 40 ++++++++--------------------- include/Makefile.am | 2 +- include/libiphone/libiphone.h | 33 ------------------------ include/libiphone/notification_proxy.h | 46 ++++++++++++++++++++++++++++++++++ src/NotificationProxy.c | 39 ++++++++++++++-------------- src/NotificationProxy.h | 7 +++--- 6 files changed, 80 insertions(+), 87 deletions(-) create mode 100644 include/libiphone/notification_proxy.h diff --git a/dev/main.c b/dev/main.c index fe340ff..d39baa7 100644 --- a/dev/main.c +++ b/dev/main.c @@ -26,6 +26,7 @@ #include #include +#include #include "../src/utils.h" void notifier(const char *notification) @@ -38,16 +39,16 @@ void notifier(const char *notification) void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification) { int nport = 0; - iphone_np_client_t np; + np_client_t np; iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); if (nport) { printf("::::::::::::::: np was started ::::::::::::\n"); - iphone_np_new_client(phone, nport, &np); + np_new_client(phone, nport, &np); if (np) { printf("::::::::: PostNotification %s\n", notification); - iphone_np_post_notification(np, notification); - iphone_np_free_client(np); + np_post_notification(np, notification); + np_free_client(np); } } else { printf("::::::::::::::: np was NOT started ::::::::::::\n"); @@ -61,7 +62,7 @@ int main(int argc, char *argv[]) iphone_lckd_client_t control = NULL; iphone_device_t phone = NULL; uint64_t lockfile = 0; - iphone_np_client_t gnp = NULL; + np_client_t gnp = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) { iphone_set_debug(1); @@ -104,7 +105,7 @@ int main(int argc, char *argv[]) iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); if (npp) { printf("Notification Proxy started.\n"); - iphone_np_new_client(phone, npp, &gnp); + np_new_client(phone, npp, &gnp); } else { printf("ERROR: Notification proxy could not be started.\n"); } @@ -115,8 +116,8 @@ int main(int argc, char *argv[]) NP_SYNC_RESUME_REQUEST, NULL }; - iphone_np_observe_notifications(gnp, nspec); - iphone_np_set_notify_callback(gnp, notifier); + np_observe_notifications(gnp, nspec); + np_set_notify_callback(gnp, notifier); } perform_notification(phone, control, NP_SYNC_WILL_START); @@ -219,28 +220,7 @@ int main(int argc, char *argv[]) if (gnp && lockfile) { char *noti; - /* - noti = NULL; - iphone_np_get_notification(gnp, ¬i); - if (noti) { - printf("------> received notification '%s'\n", noti); - free(noti); - }*/ - printf("XXX sleeping\n"); - /*for (i = 0; i < 5; i++) { - noti = NULL; - printf("--- getting notification\n"); - iphone_np_get_notification(gnp, ¬i); - if (noti) { - printf("------> received notification '%s'\n", noti); - free(noti); - } else { - printf("---- no notification\n"); - } - sleep(1); - } - */ sleep(5); //perform_notification(phone, control, NP_SYNC_DID_FINISH); @@ -253,7 +233,7 @@ int main(int argc, char *argv[]) } if (gnp) { - iphone_np_free_client(gnp); + np_free_client(gnp); gnp = NULL; } diff --git a/include/Makefile.am b/include/Makefile.am index 4c17261..d8ae1e4 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h +nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h libiphone/notification_proxy.h diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 3f5d86c..456f000 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -63,9 +63,6 @@ typedef struct iphone_lckd_client_int *iphone_lckd_client_t; struct iphone_msync_client_int; typedef struct iphone_msync_client_int *iphone_msync_client_t; -struct iphone_np_client_int; -typedef struct iphone_np_client_int *iphone_np_client_t; - //debug related functions #define DBGMASK_ALL 0xFFFF #define DBGMASK_NONE 0x0000 @@ -102,36 +99,6 @@ iphone_error_t iphone_msync_free_client(iphone_msync_client_t client); iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist); iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist); -// NotificationProxy related -// notifications for use with post_notification (client --> device) -#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" -#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" -#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" - -// notifications for use with observe_notification (device --> client) -#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" -#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" -#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" -#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed" -#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed" -#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation" -#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed" -#define NP_APP_INSTALLED "com.apple.mobile.application_installed" -#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" - -iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client ); -iphone_error_t iphone_np_free_client ( iphone_np_client_t client ); - -iphone_error_t iphone_np_post_notification ( iphone_np_client_t client, const char *notification ); - -iphone_error_t iphone_np_observe_notification ( iphone_np_client_t client, const char *notification ); -iphone_error_t iphone_np_observe_notifications ( iphone_np_client_t client, const char **notification_spec ); -iphone_error_t iphone_np_get_notification ( iphone_np_client_t client, char **notification ); - -typedef void (*iphone_np_notify_cb_t) ( const char *notification ); - -iphone_error_t iphone_np_set_notify_callback ( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb ); - #ifdef __cplusplus } #endif diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h new file mode 100644 index 0000000..9412b4f --- /dev/null +++ b/include/libiphone/notification_proxy.h @@ -0,0 +1,46 @@ +#ifndef NOTIFICATION_PROXY_H +#define NOTIFICATION_PROXY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct np_client_int; +typedef struct np_client_int *np_client_t; + +// NotificationProxy related +// notifications for use with post_notification (client --> device) +#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" +#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" +#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" + +// notifications for use with observe_notification (device --> client) +#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" +#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" +#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" +#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed" +#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed" +#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation" +#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed" +#define NP_APP_INSTALLED "com.apple.mobile.application_installed" +#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" + +iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ); +iphone_error_t np_free_client ( np_client_t client ); + +iphone_error_t np_post_notification ( np_client_t client, const char *notification ); + +iphone_error_t np_observe_notification ( np_client_t client, const char *notification ); +iphone_error_t np_observe_notifications ( np_client_t client, const char **notification_spec ); + +typedef void (*np_notify_cb_t) ( const char *notification ); + +iphone_error_t np_set_notify_callback ( np_client_t client, np_notify_cb_t notify_cb ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index 6fc048c..374420c 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c @@ -25,18 +25,19 @@ #include #include #include "NotificationProxy.h" +#include "iphone.h" #include "utils.h" struct np_thread { - iphone_np_client_t client; - iphone_np_notify_cb_t cbfunc; + np_client_t client; + np_notify_cb_t cbfunc; }; /** Locks an NP client, done for thread safety stuff. * * @param client The NP */ -static void np_lock(iphone_np_client_t client) +static void np_lock(np_client_t client) { log_debug_msg("NP: Locked\n"); g_mutex_lock(client->mutex); @@ -46,7 +47,7 @@ static void np_lock(iphone_np_client_t client) * * @param client The NP */ -static void np_unlock(iphone_np_client_t client) +static void np_unlock(np_client_t client) { log_debug_msg("NP: Unlocked\n"); g_mutex_unlock(client->mutex); @@ -61,7 +62,7 @@ static void np_unlock(iphone_np_client_t client) * * @return IPHONE_E_SUCCESS or an error code. */ -static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) +static iphone_error_t np_plist_send(np_client_t client, plist_t dict) { char *XML_content = NULL; uint32_t length = 0; @@ -108,7 +109,7 @@ static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) * * @return A handle to the newly-connected client or NULL upon error. */ -iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client ) +iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ) { //makes sure thread environment is available if (!g_thread_supported()) @@ -123,7 +124,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho return IPHONE_E_UNKNOWN_ERROR; //ret; } - iphone_np_client_t client_loc = (iphone_np_client_t) malloc(sizeof(struct iphone_np_client_int)); + np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); client_loc->sfd = sfd; client_loc->mutex = g_mutex_new(); @@ -138,7 +139,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho * * @param client The client to disconnect. */ -iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) +iphone_error_t np_free_client ( np_client_t client ) { if (!client) return IPHONE_E_INVALID_ARG; @@ -166,7 +167,7 @@ iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) * @param client The client to send to * @param notification The notification message to send */ -iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) +iphone_error_t np_post_notification( np_client_t client, const char *notification ) { if (!client || !notification) { return IPHONE_E_INVALID_ARG; @@ -202,7 +203,7 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha * @param client The client to send to * @param notification The notifications that should be observed. */ -iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const char *notification ) +iphone_error_t np_observe_notification( np_client_t client, const char *notification ) { if (!client || !notification) { return IPHONE_E_INVALID_ARG; @@ -245,7 +246,7 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const * terminating NULL entry. However this parameter can be NULL; in this case, * the default set of notifications will be used. */ -iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const char **notification_spec ) +iphone_error_t np_observe_notifications( np_client_t client, const char **notification_spec ) { int i = 0; iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; @@ -260,7 +261,7 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const } while (notifications[i]) { - res = iphone_np_observe_notification(client, notifications[i]); + res = np_observe_notification(client, notifications[i]); if (res != IPHONE_E_SUCCESS) { break; } @@ -281,10 +282,10 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const * IPHONE_E_TIMEOUT if nothing has been received, * or an error value if an error occured. * - * @note You probably want to check out iphone_np_set_notify_callback - * @see iphone_np_set_notify_callback + * @note You probably want to check out np_set_notify_callback + * @see np_set_notify_callback */ -iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **notification ) +static iphone_error_t np_get_notification( np_client_t client, char **notification ) { uint32_t bytes = 0; iphone_error_t res; @@ -382,7 +383,7 @@ iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **not /** * Internally used thread function. */ -gpointer iphone_np_notifier( gpointer arg ) +gpointer np_notifier( gpointer arg ) { char *notification = NULL; struct np_thread *npt = (struct np_thread*)arg; @@ -391,7 +392,7 @@ gpointer iphone_np_notifier( gpointer arg ) log_debug_msg("%s: starting callback.\n", __func__); while (npt->client->sfd >= 0) { - iphone_np_get_notification(npt->client, ¬ification); + np_get_notification(npt->client, ¬ification); if (notification) { npt->cbfunc(notification); free(notification); @@ -419,7 +420,7 @@ gpointer iphone_np_notifier( gpointer arg ) * @return IPHONE_E_SUCCESS when the callback was successfully registered, * or an error value when an error occured. */ -iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb ) +iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) { if (!client) { return IPHONE_E_INVALID_ARG; @@ -442,7 +443,7 @@ iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_ npt->client = client; npt->cbfunc = notify_cb; - client->notifier = g_thread_create(iphone_np_notifier, npt, TRUE, NULL); + client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); if (client->notifier) { res = IPHONE_E_SUCCESS; } diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h index afae98a..a10cde4 100644 --- a/src/NotificationProxy.h +++ b/src/NotificationProxy.h @@ -18,12 +18,11 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libiphone/libiphone.h" -#include "iphone.h" +#include "libiphone/notification_proxy.h" #include -struct iphone_np_client_int { +struct np_client_int { int sfd; GMutex *mutex; GThread *notifier; @@ -42,4 +41,4 @@ static const char *np_default_notifications[10] = { NULL }; -gpointer iphone_np_notifier( gpointer arg ); +gpointer np_notifier( gpointer arg ); -- cgit v1.1-32-gdbae From 62a6f558ac7ca7a9b83c2ed810929732c02bbc9d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 7 Jul 2009 21:02:00 +0200 Subject: Cleanup lockdown request API and fix docs, tools, bindings and exports --- dev/afccheck.c | 15 +- dev/iphone_id.c | 9 +- dev/iphoneinfo.c | 17 +- dev/lckdclient.c | 29 +- dev/main.c | 35 +- dev/msyncclient.c | 12 +- dev/syslog_relay.c | 9 +- include/Makefile.am | 2 +- include/libiphone/libiphone.h | 27 +- include/libiphone/lockdown.h | 51 +++ src/lockdown.c | 778 ++++++++++++++++++++---------------------- src/lockdown.h | 24 +- swig/iphone.i | 17 +- 13 files changed, 501 insertions(+), 524 deletions(-) create mode 100644 include/libiphone/lockdown.h diff --git a/dev/afccheck.c b/dev/afccheck.c index b107437..9174e32 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -25,6 +25,7 @@ #include #include +#include #include #define BUFFER_SIZE 20000 @@ -40,10 +41,10 @@ typedef struct { void check_afc(gpointer data) { //prepare a buffer - int buffersize = BUFFER_SIZE * sizeof(int); + unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int); int *buf = (int *) malloc(buffersize); int *buf2 = (int *) malloc(buffersize); - int bytes = 0; + unsigned int bytes = 0; //fill buffer int i = 0; for (i = 0; i < BUFFER_SIZE; i++) { @@ -84,7 +85,7 @@ void check_afc(gpointer data) int main(int argc, char *argv[]) { - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; GError *err; int port = 0; @@ -95,13 +96,13 @@ int main(int argc, char *argv[]) return 1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return 1; } - if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) { - iphone_lckd_free_client(control); + if (IPHONE_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { + lockdownd_free_client(client); iphone_free_device(phone); fprintf(stderr, "Something went wrong when starting AFC."); return 1; @@ -128,7 +129,7 @@ int main(int argc, char *argv[]) } - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/iphone_id.c b/dev/iphone_id.c index c191608..15081f0 100644 --- a/dev/iphone_id.c +++ b/dev/iphone_id.c @@ -3,6 +3,7 @@ #include #include #include +#include #include static void usage() @@ -18,7 +19,7 @@ static void usage() int main(int argc, char **argv) { iphone_device_t phone = NULL; - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; usbmuxd_scan_result *dev_list; char *devname = NULL; int ret = 0; @@ -67,18 +68,18 @@ int main(int argc, char **argv) return -2; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); fprintf(stderr, "ERROR: Connecting to device failed!\n"); return -2; } - if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(control, &devname)) || !devname) { + if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) { fprintf(stderr, "ERROR: Could not get device name!\n"); ret = -2; } - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); if (ret == 0) { diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 18ee055..7c823e6 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -25,6 +25,7 @@ #include #include +#include #define FORMAT_KEY_VALUE 1 #define FORMAT_XML 2 @@ -45,13 +46,13 @@ static const char *domains[] = { int is_domain_known(char *domain); void print_usage(int argc, char **argv); -void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format); +void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format); void plist_node_to_string(plist_t *node); void plist_children_to_string(plist_t *node); int main(int argc, char *argv[]) { - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; @@ -128,17 +129,17 @@ int main(int argc, char *argv[]) } } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } /* run query and output information */ - print_lckd_request_result(control, domain, "GetValue", key, format); + print_lckd_request_result(client, domain, "GetValue", key, format); if (domain != NULL) free(domain); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; @@ -248,7 +249,7 @@ void plist_children_to_string(plist_t *node) } } -void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format) { +void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format) { char *xml_doc = NULL; char *s = NULL; uint32_t xml_length = 0; @@ -266,11 +267,11 @@ void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, plist_add_sub_key_el(node, "Request"); plist_add_sub_string_el(node, request); - ret = iphone_lckd_send(control, node); + ret = lockdownd_send(client, node); if (ret == IPHONE_E_SUCCESS) { plist_free(node); node = NULL; - ret = iphone_lckd_recv(control, &node); + ret = lockdownd_recv(client, &node); if (ret == IPHONE_E_SUCCESS) { /* seek to value node */ for ( diff --git a/dev/lckdclient.c b/dev/lckdclient.c index c96f052..e197002 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -27,12 +27,11 @@ #include #include - +#include int main(int argc, char *argv[]) { - int bytes = 0, port = 0, i = 0; - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; iphone_set_debug(1); @@ -42,13 +41,13 @@ int main(int argc, char *argv[]) return -1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } char *uid = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { + if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid)) { printf("DeviceUniqueID : %s\n", uid); free(uid); } @@ -74,17 +73,25 @@ int main(int argc, char *argv[]) if (!strcmp(*args, "quit")) loop = FALSE; - if (!strcmp(*args, "get") && len == 3) { - char *value = NULL; - if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args + 1), *(args + 2), &value)) - printf("Success : value = %s\n", value); + if (!strcmp(*args, "get") && len >= 2) { + plist_t *value = NULL; + if (IPHONE_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value)) + { + char *xml = NULL; + uint32_t length; + plist_to_xml(value, &xml, &length); + printf("Success : value = %s\n", xml); + + free(xml); + free(value); + } else printf("Error\n"); } if (!strcmp(*args, "start") && len == 2) { int port = 0; - iphone_lckd_start_service(control, *(args + 1), &port); + lockdownd_start_service(client, *(args + 1), &port); printf("%i\n", port); } } @@ -94,7 +101,7 @@ int main(int argc, char *argv[]) cmd = NULL; } clear_history(); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/main.c b/dev/main.c index d39baa7..cf7dbaa 100644 --- a/dev/main.c +++ b/dev/main.c @@ -23,25 +23,27 @@ #include #include #include +#include #include +#include #include #include #include "../src/utils.h" -void notifier(const char *notification) +static void notifier(const char *notification) { printf("---------------------------------------------------------\n"); printf("------> Notification received: %s\n", notification); printf("---------------------------------------------------------\n"); } -void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification) +static void perform_notification(iphone_device_t phone, lockdownd_client_t client, const char *notification) { int nport = 0; np_client_t np; - iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); + lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); if (nport) { printf("::::::::::::::: np was started ::::::::::::\n"); np_new_client(phone, nport, &np); @@ -57,9 +59,10 @@ void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, c int main(int argc, char *argv[]) { - int bytes = 0, port = 0, i = 0; + unsigned int bytes = 0; + int port = 0, i = 0; int npp; - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; uint64_t lockfile = 0; np_client_t gnp = NULL; @@ -77,32 +80,32 @@ int main(int argc, char *argv[]) return -1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); printf("Exiting.\n"); return -1; } char *uid = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { + if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid)) { printf("DeviceUniqueID : %s\n", uid); free(uid); } char *nnn = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_name(control, &nnn)) { + if (IPHONE_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { printf("DeviceName : %s\n", nnn); free(nnn); } - iphone_lckd_start_service(control, "com.apple.afc", &port); + lockdownd_start_service(client, "com.apple.afc", &port); if (port) { afc_client_t afc = NULL; afc_new_client(phone, port, &afc); if (afc) { - iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); + lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); if (npp) { printf("Notification Proxy started.\n"); np_new_client(phone, npp, &gnp); @@ -120,14 +123,14 @@ int main(int argc, char *argv[]) np_set_notify_callback(gnp, notifier); } - perform_notification(phone, control, NP_SYNC_WILL_START); + perform_notification(phone, client, NP_SYNC_WILL_START); afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); afc_lock_file(afc, lockfile, 2 | 4); - perform_notification(phone, control, NP_SYNC_DID_START); + perform_notification(phone, client, NP_SYNC_DID_START); } char **dirs = NULL; @@ -164,10 +167,10 @@ int main(int argc, char *argv[]) if (IPHONE_E_SUCCESS == afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { - printf("A file size: %i\n", fsize); + printf("A file size: %llu\n", fsize); char *file_data = (char *) malloc(sizeof(char) * fsize); afc_read_file(afc, my_file, file_data, fsize, &bytes); - if (bytes >= 0) { + if (bytes > 0) { printf("The file's data:\n"); fwrite(file_data, 1, bytes, stdout); } @@ -218,8 +221,6 @@ int main(int argc, char *argv[]) } if (gnp && lockfile) { - char *noti; - printf("XXX sleeping\n"); sleep(5); @@ -244,7 +245,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/msyncclient.c b/dev/msyncclient.c index e3bb0c2..e06a5fe 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -25,12 +25,12 @@ #include #include - +#include int main(int argc, char *argv[]) { - int bytes = 0, port = 0, i = 0; - iphone_lckd_client_t control = NULL; + int port = 0; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) @@ -42,12 +42,12 @@ int main(int argc, char *argv[]) return -1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } - iphone_lckd_start_service(control, "com.apple.mobilesync", &port); + lockdownd_start_service(client, "com.apple.mobilesync", &port); if (port) { iphone_msync_client_t msync = NULL; @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 6698653..a93e85b 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -27,6 +27,7 @@ #include #include +#include #include static int quit_flag = 0; @@ -44,7 +45,7 @@ static void clean_exit(int sig) int main(int argc, char *argv[]) { - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; @@ -99,15 +100,15 @@ int main(int argc, char *argv[]) } } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } /* start syslog_relay service and retrieve port */ - ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); + ret = lockdownd_start_service(client, "com.apple.syslog_relay", &port); if ((ret == IPHONE_E_SUCCESS) && port) { - iphone_lckd_free_client(control); + lockdownd_free_client(client); /* connect to socket relay messages */ diff --git a/include/Makefile.am b/include/Makefile.am index d8ae1e4..98792de 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h libiphone/notification_proxy.h +nobase_include_HEADERS = libiphone/libiphone.h libiphone/lockdown.h libiphone/afc.h libiphone/notification_proxy.h diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 456f000..9e983bb 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -57,9 +57,6 @@ typedef int16_t iphone_error_t; struct iphone_device_int; typedef struct iphone_device_int *iphone_device_t; -struct iphone_lckd_client_int; -typedef struct iphone_lckd_client_int *iphone_lckd_client_t; - struct iphone_msync_client_int; typedef struct iphone_msync_client_int *iphone_msync_client_t; @@ -74,29 +71,15 @@ void iphone_set_debug_mask(uint16_t mask); void iphone_set_debug(int level); //device related functions -iphone_error_t iphone_get_device ( iphone_device_t *device ); -iphone_error_t iphone_get_device_by_uuid ( iphone_device_t *device, const char *uuid ); -iphone_error_t iphone_free_device ( iphone_device_t device ); - -uint32_t iphone_get_device_handle ( iphone_device_t device ); - -//lockdownd related functions -iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); -iphone_error_t lockdownd_get_device_name ( iphone_lckd_client_t client, char **device_name ); -iphone_error_t iphone_lckd_new_client ( iphone_device_t device, iphone_lckd_client_t *client ); -iphone_error_t iphone_lckd_free_client( iphone_lckd_client_t client ); - -iphone_error_t iphone_lckd_start_service ( iphone_lckd_client_t client, const char *service, int *port ); -iphone_error_t iphone_lckd_recv ( iphone_lckd_client_t client, plist_t* plist); -iphone_error_t iphone_lckd_send ( iphone_lckd_client_t client, plist_t plist); - - +iphone_error_t iphone_get_device(iphone_device_t *device); +iphone_error_t iphone_get_device_by_uuid(iphone_device_t *device, const char *uuid); +iphone_error_t iphone_free_device(iphone_device_t device); +uint32_t iphone_get_device_handle(iphone_device_t device); iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, iphone_msync_client_t * client); iphone_error_t iphone_msync_free_client(iphone_msync_client_t client); - -iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist); +iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t *plist); iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist); #ifdef __cplusplus diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h new file mode 100644 index 0000000..805c90b --- /dev/null +++ b/include/libiphone/lockdown.h @@ -0,0 +1,51 @@ +/* + * lockdownd.h + * + * Copyright (c) 2009 Martin S. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef LOCKDOWN_H +#define LOCKDOWN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct lockdownd_client_int; +typedef struct lockdownd_client_int *lockdownd_client_t; + +//lockdownd related functions +iphone_error_t lockdownd_new_client (iphone_device_t device, lockdownd_client_t *client); +iphone_error_t lockdownd_free_client(lockdownd_client_t client); +iphone_error_t lockdownd_query_type(lockdownd_client_t client); +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node); +iphone_error_t lockdownd_start_service (lockdownd_client_t client, const char *service, int *port); +iphone_error_t lockdownd_stop_session(lockdownd_client_t client); +iphone_error_t lockdownd_send (lockdownd_client_t client, plist_t plist); +iphone_error_t lockdownd_recv (lockdownd_client_t client, plist_t *plist); +iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id); +iphone_error_t lockdownd_get_device_uid (lockdownd_client_t control, char **uid); +iphone_error_t lockdownd_get_device_name (lockdownd_client_t client, char **device_name); +iphone_error_t lockdownd_goodbye(lockdownd_client_t client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lockdown.c b/src/lockdown.c index a950ceb..7e1f1a8 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -33,6 +33,8 @@ #include +#define RESULT_SUCCESS 0 +#define RESULT_FAILURE 1 const ASN1_ARRAY_TYPE pkcs1_asn1_tab[] = { {"PKCS1", 536872976, 0}, @@ -43,28 +45,80 @@ const ASN1_ARRAY_TYPE pkcs1_asn1_tab[] = { {0, 0, 0} }; -/** Creates a lockdownd client for the give iPhone. +/** + * Internally used function for checking the result from lockdown's answer + * plist to a previously sent request. * - * @param phone The iPhone to create a lockdownd client for + * @param dict The plist to evaluate. + * @param query_match Name of the request to match. * - * @return The lockdownd client. + * @return RESULT_SUCCESS when the result is 'Success', + * RESULT_FAILURE when the result is 'Failure', + * or a negative value if an error occured during evaluation. */ -iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone) +static int lockdown_check_result(plist_t dict, const char *query_match) { - if (!phone) - return NULL; + int ret = -1; - int sfd = usbmuxd_connect(phone->handle, 0xf27e); - if (sfd < 0) { - log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, phone->handle); - return NULL; + plist_t query_key = plist_find_node_by_key(dict, "Request"); + if (!query_key) { + return ret; + } + plist_t query_node = plist_get_next_sibling(query_key); + if (!query_node) { + return ret; + } + if (plist_get_node_type(query_node) != PLIST_STRING) { + return ret; + } else { + char *query_value = NULL; + plist_get_string_val(query_node, &query_value); + if (!query_value) { + return ret; + } + if (strcmp(query_value, query_match) != 0) { + free(query_value); + return ret; + } + free(query_value); + } + + plist_t result_node = plist_get_next_sibling(query_node); + if (!result_node) { + return ret; } - iphone_lckd_client_t control = (iphone_lckd_client_t) malloc(sizeof(struct iphone_lckd_client_int)); - control->sfd = sfd; - control->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); - control->in_SSL = 0; - return control; + plist_t value_node = plist_get_next_sibling(result_node); + if (!value_node) { + return ret; + } + + plist_type result_type = plist_get_node_type(result_node); + plist_type value_type = plist_get_node_type(value_node); + + if (result_type == PLIST_KEY && value_type == PLIST_STRING) { + + char *result_value = NULL; + char *value_value = NULL; + + plist_get_key_val(result_node, &result_value); + plist_get_string_val(value_node, &value_value); + + if (result_value && value_value && !strcmp(result_value, "Result")) { + if (!strcmp(value_value, "Success")) { + ret = RESULT_SUCCESS; + } else if (!strcmp(value_value, "Failure")) { + ret = RESULT_FAILURE; + } else { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, value_value); + } + } + if (result_value) + free(result_value); + if (value_value) + free(value_value); + } + return ret; } /** @@ -73,10 +127,10 @@ iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone) * * @param control The lockdown client */ -static void iphone_lckd_stop_session(iphone_lckd_client_t control) +iphone_error_t lockdownd_stop_session(lockdownd_client_t client) { - if (!control) - return; //IPHONE_E_INVALID_ARG; + if (!client) + return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; @@ -84,48 +138,31 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "StopSession"); plist_add_sub_key_el(dict, "SessionID"); - plist_add_sub_string_el(dict, control->session_id); + plist_add_sub_string_el(dict, client->session_id); log_dbg_msg(DBGMASK_LOCKDOWND, "iphone_lckd_stop_session() called\n"); - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (!dict) { log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): IPHONE_E_PLIST_ERROR\n"); - return; // IPHONE_E_PLIST_ERROR; + return IPHONE_E_PLIST_ERROR; } - plist_t query_node = plist_find_node_by_string(dict, "StopSession"); - plist_t result_node = plist_get_next_sibling(query_node); - plist_t value_node = plist_get_next_sibling(result_node); - - plist_type result_type = plist_get_node_type(result_node); - plist_type value_type = plist_get_node_type(value_node); - - if (result_type == PLIST_KEY && value_type == PLIST_STRING) { - - char *result_value = NULL; - char *value_value = NULL; - - plist_get_key_val(result_node, &result_value); - plist_get_string_val(value_node, &value_value); - - if (!strcmp(result_value, "Result") && !strcmp(value_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_value); - free(value_value); + ret = IPHONE_E_UNKNOWN_ERROR; + if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): success\n"); + ret = IPHONE_E_SUCCESS; } plist_free(dict); dict = NULL; - return; // ret; + return ret; } /** @@ -135,16 +172,17 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) * * @param client The lockdown client */ -static void iphone_lckd_stop_SSL_session(iphone_lckd_client_t client) +static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) { if (!client) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_SSL_session(): invalid argument!\n"); - return; + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_ssl_session(): invalid argument!\n"); + return IPHONE_E_INVALID_ARG; } + iphone_error_t ret = IPHONE_E_SUCCESS; if (client->in_SSL) { log_dbg_msg(DBGMASK_LOCKDOWND, "Stopping SSL Session\n"); - iphone_lckd_stop_session(client); + ret = lockdownd_stop_session(client); log_dbg_msg(DBGMASK_LOCKDOWND, "Sending SSL close notify\n"); gnutls_bye(*client->ssl_session, GNUTLS_SHUT_RDWR); } @@ -154,27 +192,26 @@ static void iphone_lckd_stop_SSL_session(iphone_lckd_client_t client) } client->in_SSL = 0; - return; + return ret; } /** Closes the lockdownd client and does the necessary housekeeping. * - * @param control The lockdown client + * @param client The lockdown client */ -iphone_error_t iphone_lckd_free_client(iphone_lckd_client_t client) +iphone_error_t lockdownd_free_client(lockdownd_client_t client) { if (!client) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - iphone_lckd_stop_SSL_session(client); + lockdownd_stop_ssl_session(client); if (client->sfd > 0) { - lockdownd_close(client); + lockdownd_goodbye(client); // IMO, read of final "sessionUpcall connection closed" packet // should come here instead of in iphone_free_device - ret = usbmuxd_disconnect(client->sfd); } @@ -185,12 +222,11 @@ iphone_error_t iphone_lckd_free_client(iphone_lckd_client_t client) /** Polls the iPhone for lockdownd data. * * @param control The lockdownd client - * @param dump_data The pointer to the location of the buffer in which to store - * the received data + * @param plist The plist to store the received data * - * @return The number of bytes received + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist) +iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) { if (!client || !plist || (plist && *plist)) return IPHONE_E_INVALID_ARG; @@ -265,7 +301,7 @@ iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist) * * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_send(iphone_lckd_client_t client, plist_t plist) +iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) { if (!client || !plist) return IPHONE_E_INVALID_ARG; @@ -278,7 +314,6 @@ iphone_error_t iphone_lckd_send(iphone_lckd_client_t client, plist_t plist) plist_to_xml(plist, &XMLContent, &length); log_dbg_msg(DBGMASK_LOCKDOWND, "Send msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); - real_query = (char *) malloc(sizeof(char) * (length + 4)); length = htonl(length); memcpy(real_query, &length, sizeof(length)); @@ -310,15 +345,13 @@ iphone_error_t iphone_lckd_send(iphone_lckd_client_t client, plist_t plist) /** Initiates the handshake for the lockdown session. Part of the lockdownd handshake. * - * @note You most likely want lockdownd_init unless you are doing something special. - * - * @param control The lockdownd client + * @param client The lockdownd client * - * @return 1 on success and 0 on failure. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_hello(iphone_lckd_client_t control) +iphone_error_t lockdownd_query_type(lockdownd_client_t client) { - if (!control) + if (!client) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; @@ -327,72 +360,60 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "QueryType"); - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_hello() called\n"); - ret = iphone_lckd_send(control, dict); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type() called\n"); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (IPHONE_E_SUCCESS != ret) return ret; - plist_t query_node = plist_find_node_by_string(dict, "QueryType"); - plist_t result_node = plist_get_next_sibling(query_node); - plist_t value_node = plist_get_next_sibling(result_node); - - plist_type result_type = plist_get_node_type(result_node); - plist_type value_type = plist_get_node_type(value_node); - - if (result_type == PLIST_KEY && value_type == PLIST_STRING) { - - char *result_value = NULL; - char *value_value = NULL; - - plist_get_key_val(result_node, &result_value); - plist_get_string_val(value_node, &value_value); - - if (!strcmp(result_value, "Result") && !strcmp(value_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_hello(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_value); - free(value_value); + ret = IPHONE_E_UNKNOWN_ERROR; + if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type(): success\n"); + ret = IPHONE_E_SUCCESS; } - plist_free(dict); dict = NULL; return ret; } -/** Generic function to handle simple (key, value) requests. +/** Retrieves a preferences plist using an optional domain and/or key name. * - * @param control an initialized lockdownd client. - * @param key the key to request - * @param value a pointer to the requested value + * @param client an initialized lockdownd client. + * @param domain the domain to query on or NULL for global domain + * @param key the key name to request or NULL to query for all keys + * @param value_node a plist node representing the result value node * - * @return IPHONE_E_SUCCESS on success. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const char *req_key, const char *req_string, - gnutls_datum_t * value) +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node) { - if (!control || !req_key || !value || value->data) + if (!client) return IPHONE_E_INVALID_ARG; plist_t dict = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - /* Setup DevicePublicKey request plist */ + /* setup request plist */ dict = plist_new_dict(); - plist_add_sub_key_el(dict, req_key); - plist_add_sub_string_el(dict, req_string); + if (domain) { + plist_add_sub_key_el(dict, "Domain"); + plist_add_sub_string_el(dict, domain); + } + if (key) { + plist_add_sub_key_el(dict, "Key"); + plist_add_sub_string_el(dict, key); + } plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "GetValue"); - /* send to iPhone */ - ret = iphone_lckd_send(control, dict); + /* send to device */ + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; @@ -400,71 +421,38 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const c if (ret != IPHONE_E_SUCCESS) return ret; - /* Now get iPhone's answer */ - ret = iphone_lckd_recv(control, &dict); - + /* Now get device's answer */ + ret = lockdownd_recv(client, &dict); if (ret != IPHONE_E_SUCCESS) return ret; - plist_t query_node = plist_find_node_by_string(dict, "GetValue"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - - char *result_key = NULL; - char *result_value = NULL; - ret = IPHONE_E_DICT_ERROR; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_generic_get_value(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_key); - free(result_value); + if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): success\n"); + ret = IPHONE_E_SUCCESS; } if (ret != IPHONE_E_SUCCESS) { + plist_free(dict); return ret; } - plist_t value_key_node = plist_find_node_by_key(dict, "Value");//plist_get_next_sibling(result_value_node); + plist_t value_key_node = plist_find_node_by_key(dict, "Value"); plist_t value_value_node = plist_get_next_sibling(value_key_node); plist_type value_key_type = plist_get_node_type(value_key_node); if (value_key_type == PLIST_KEY) { - char *result_key = NULL; plist_get_key_val(value_key_node, &result_key); if (!strcmp(result_key, "Value")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_generic_get_value(): success\n"); - - plist_type value_value_type = plist_get_node_type(value_value_node); - if (PLIST_STRING == value_value_type) { - char *value_value = NULL; - plist_get_string_val(value_value_node, &value_value); - - value->data = (unsigned char*)value_value; - value->size = strlen(value_value); - ret = IPHONE_E_SUCCESS; - } - - if (PLIST_DATA == value_value_type) { - char *value_value = NULL; - uint64_t size = 0; - plist_get_data_val(value_value_node, &value_value, &size); - - value->data = (unsigned char*)value_value; - value->size = size; - ret = IPHONE_E_SUCCESS; - } + char *buf = NULL; + uint32_t length; + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); + + /* FIXME: libplist does not offer cloning of nodes, use serialization */ + plist_to_bin(value_value_node, &buf, &length); + plist_from_bin(buf, length, value_node); + free(buf); } free(result_key); } @@ -473,69 +461,109 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const c return ret; } -/** Askes for the device's unique id. Part of the lockdownd handshake. - * - * @note You most likely want lockdownd_init unless you are doing something special. +/** Asks for the device's unique id. Part of the lockdownd handshake. * - * @return 1 on success and 0 on failure. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid) +iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid) { - gnutls_datum_t temp = { NULL, 0 }; - iphone_error_t ret = lockdownd_generic_get_value(control, "Key", "UniqueDeviceID", &temp); - *uid = (char*)temp.data; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + plist_t value = NULL; + value = plist_new_dict(); + + ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value); + if (ret != IPHONE_E_SUCCESS) { + return ret; + } + plist_get_string_val(value, uid); + + plist_free(value); + value = NULL; return ret; } /** Askes for the device's public key. Part of the lockdownd handshake. * - * @note You most likely want lockdownd_init unless you are doing something special. - * - * @return IPHONE_E_SUCCESS on succes or an error value < 0 on failure. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key) +iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) { - return lockdownd_generic_get_value(control, "Key", "DevicePublicKey", public_key); + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + plist_t value = NULL; + char *value_value = NULL; + uint64_t size = 0; + value = plist_new_dict(); + + ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value); + if (ret != IPHONE_E_SUCCESS) { + return ret; + } + plist_get_data_val(value, &value_value, &size); + public_key->data = (unsigned char*)value_value; + public_key->size = size; + + plist_free(value); + value = NULL; + + return ret; } /** Askes for the device's name. * - * @return IPHONE_E_SUCCESS on succes or an error value < 0 on failure. + * @param client The pointer to the location of the new lockdownd_client + * + * + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_name(iphone_lckd_client_t control, char **device_name) +iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) { - gnutls_datum_t temp = { NULL, 0 }; - iphone_error_t res = lockdownd_generic_get_value(control, "Key", "DeviceName", &temp); - log_debug_msg("%s: %s\n", __func__, temp.data); - *device_name = (char*)temp.data; - return res; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + plist_t value = NULL; + value = plist_new_dict(); + + ret = lockdownd_get_value(client, NULL, "DeviceName", &value); + if (ret != IPHONE_E_SUCCESS) { + return ret; + } + plist_get_string_val(value, device_name); + log_debug_msg("%s: %s\n", __func__, device_name); + + plist_free(value); + value = NULL; + + return ret; } -/** Completes the entire lockdownd handshake. +/** Creates a lockdownd client for the give iPhone * - * @param phone The iPhone - * @param lockdownd_client The pointer to the location of the lockdownd_client + * @param phone The iPhone to create a lockdownd client for + * @param client The pointer to the location of the new lockdownd_client * - * @return 1 on success and 0 on failure + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client_t * client) +iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *client) { if (!device || !client || (client && *client)) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_SUCCESS; char *host_id = NULL; - iphone_lckd_client_t client_loc = new_lockdownd_client(device); - if (!client_loc) { - log_debug_msg("FATAL: lockdownd client could not be created!\n"); + int sfd = usbmuxd_connect(device->handle, 0xf27e); + if (sfd < 0) { + log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, device->handle); return IPHONE_E_UNKNOWN_ERROR; } - if (IPHONE_E_SUCCESS != lockdownd_hello(client_loc)) { - log_debug_msg("Hello failed in the lockdownd client.\n"); + + lockdownd_client_t client_loc = (lockdownd_client_t) malloc(sizeof(struct lockdownd_client_int)); + client_loc->sfd = sfd; + client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); + client_loc->in_SSL = 0; + + if (IPHONE_E_SUCCESS != lockdownd_query_type(client_loc)) { + log_debug_msg("QueryType failed in the lockdownd client.\n"); ret = IPHONE_E_NOT_ENOUGH_DATA; } - char *uid = NULL; ret = lockdownd_get_device_uid(client_loc, &uid); if (IPHONE_E_SUCCESS != ret) { @@ -549,7 +577,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client } if (IPHONE_E_SUCCESS == ret && !is_device_known(uid)) - ret = lockdownd_pair_device(client_loc, uid, host_id); + ret = lockdownd_pair(client_loc, uid, host_id); if (uid) { free(uid); @@ -557,7 +585,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client } if (IPHONE_E_SUCCESS == ret) { - ret = lockdownd_start_SSL_session(client_loc, host_id); + ret = lockdownd_start_ssl_session(client_loc, host_id); if (IPHONE_E_SUCCESS != ret) { ret = IPHONE_E_SSL_ERROR; log_debug_msg("SSL Session opening failed.\n"); @@ -578,11 +606,9 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client /** Generates the appropriate keys and pairs the device. It's part of the * lockdownd handshake. * - * @note You most likely want lockdownd_init unless you are doing something special. - * - * @return 1 on success and 0 on failure + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id) +iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id) { iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_t dict = NULL; @@ -593,7 +619,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch gnutls_datum_t root_cert = { NULL, 0 }; gnutls_datum_t public_key = { NULL, 0 }; - ret = lockdownd_get_device_public_key(control, &public_key); + ret = lockdownd_get_device_public_key(client, &public_key); if (ret != IPHONE_E_SUCCESS) { log_debug_msg("Device refused to send public key.\n"); return ret; @@ -623,7 +649,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch plist_add_sub_string_el(dict, "Pair"); /* send to iPhone */ - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; @@ -631,43 +657,24 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch return ret; /* Now get iPhone's answer */ - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (ret != IPHONE_E_SUCCESS) return ret; - plist_t query_node = plist_find_node_by_string(dict, "Pair"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - - char *result_key = NULL; - char *result_value = NULL; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { - ret = IPHONE_E_SUCCESS; - } - - free(result_key); - free(result_value); + if (lockdown_check_result(dict, "Pair") == RESULT_SUCCESS) { + ret = IPHONE_E_SUCCESS; } plist_free(dict); dict = NULL; /* store public key in config if pairing succeeded */ if (ret == IPHONE_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair_device: pair success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair success\n"); store_device_public_key(uid, public_key); ret = IPHONE_E_SUCCESS; } else { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair_device: pair failure\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair failure\n"); ret = IPHONE_E_PAIRING_FAILED; } free(public_key.data); @@ -678,12 +685,14 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch * Performs the Goodbye Request to tell the device the communication * session is now closed. * - * @param control The lockdown client + * @param client The lockdown client + * + * @return an error code (IPHONE_E_SUCCESS on success) */ -void lockdownd_close(iphone_lckd_client_t control) +iphone_error_t lockdownd_goodbye(lockdownd_client_t client) { - if (!control) - return; //IPHONE_E_INVALID_ARG; + if (!client) + return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; @@ -691,49 +700,32 @@ void lockdownd_close(iphone_lckd_client_t control) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "Goodbye"); - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_close() called\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye() called\n"); - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (!dict) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_close(): IPHONE_E_PLIST_ERROR\n"); - return; // IPHONE_E_PLIST_ERROR; + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): IPHONE_E_PLIST_ERROR\n"); + return IPHONE_E_PLIST_ERROR; } - plist_t query_node = plist_find_node_by_string(dict, "Goodbye"); - plist_t result_node = plist_get_next_sibling(query_node); - plist_t value_node = plist_get_next_sibling(result_node); - - plist_type result_type = plist_get_node_type(result_node); - plist_type value_type = plist_get_node_type(value_node); - - if (result_type == PLIST_KEY && value_type == PLIST_STRING) { - char *result_value = NULL; - char *value_value = NULL; - - plist_get_key_val(result_node, &result_value); - plist_get_string_val(value_node, &value_value); - - if (!strcmp(result_value, "Result") && !strcmp(value_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_close(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_value); - free(value_value); + if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): success\n"); + ret = IPHONE_E_SUCCESS; } plist_free(dict); dict = NULL; - return; // ret; + return ret; } /** Generates the device certificate from the public key as well as the host * and root certificates. * - * @return IPHONE_E_SUCCESS on success. + * @return an error code (IPHONE_E_SUCCESS on success) */ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert) @@ -798,7 +790,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t gnutls_x509_privkey_init(&root_privkey); gnutls_x509_privkey_init(&host_privkey); - ret = get_keys_and_certs( root_privkey, root_cert, host_privkey, host_cert); + ret = get_keys_and_certs(root_privkey, root_cert, host_privkey, host_cert); if (IPHONE_E_SUCCESS == ret) { @@ -853,18 +845,18 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t /** Starts SSL communication with lockdownd after the iPhone has been paired. * - * @param control The lockdownd client + * @param client The lockdownd client * @param HostID The HostID used with this phone * - * @return 1 on success and 0 on failure + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) +iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID) { plist_t dict = NULL; uint32_t return_me = 0; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - control->session_id[0] = '\0'; + client->session_id[0] = '\0'; /* Setup DevicePublicKey request plist */ dict = plist_new_dict(); @@ -873,137 +865,101 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "StartSession"); - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; if (ret != IPHONE_E_SUCCESS) return ret; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (!dict) return IPHONE_E_PLIST_ERROR; - plist_t request_node = plist_get_dict_el_from_key(dict, "Request"); - plist_t result_node = plist_get_dict_el_from_key(dict, "Result"); - - if (request_node && PLIST_STRING == plist_get_node_type(request_node) && - result_node && PLIST_STRING == plist_get_node_type(result_node)){ - - char *request = NULL; - char *result = NULL; - - plist_get_string_val(request_node, &request); - plist_get_string_val(result_node, &result); - - if (!strcmp(request, "StartSession")) { - if (!strcmp(result, "Failure")) { - - plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); - if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { - - char *error = NULL; - plist_get_string_val(error_node, &error); - - if (!strcmp(error, "InvalidHostID")) { - //hostid is not know. Pair and try again - char *uid = NULL; - char* host_id = get_host_id(); - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid) ) { - if (IPHONE_E_SUCCESS == lockdownd_pair_device(control, uid, host_id) ) { - - //start session again - plist_free(dict); - dict = plist_new_dict(); - plist_add_sub_key_el(dict, "HostID"); - plist_add_sub_string_el(dict, HostID); - plist_add_sub_key_el(dict, "Request"); - plist_add_sub_string_el(dict, "StartSession"); - - ret = iphone_lckd_send(control, dict); - plist_free(dict); - dict = NULL; - - ret = iphone_lckd_recv(control, &dict); - } - } - free(uid); - free(host_id); + if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { + plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); + if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { + char *error = NULL; + plist_get_string_val(error_node, &error); + + if (!strcmp(error, "InvalidHostID")) { + //hostid is unknown. Pair and try again + char *uid = NULL; + char* host_id = get_host_id(); + if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid) ) { + if (IPHONE_E_SUCCESS == lockdownd_pair(client, uid, host_id) ) { + //start session again + plist_free(dict); + dict = plist_new_dict(); + plist_add_sub_key_el(dict, "HostID"); + plist_add_sub_string_el(dict, HostID); + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "StartSession"); + + ret = lockdownd_send(client, dict); + plist_free(dict); + dict = NULL; + + ret = lockdownd_recv(client, &dict); } - free(error); } + free(uid); + free(host_id); } + free(error); } - free(request); - free(result); } - plist_t query_node = plist_find_node_by_string(dict, "StartSession"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - char *result_key = NULL; - char *result_value = NULL; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - ret = IPHONE_E_SSL_ERROR; - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { - // Set up GnuTLS... - //gnutls_anon_client_credentials_t anoncred; - gnutls_certificate_credentials_t xcred; - - log_dbg_msg(DBGMASK_LOCKDOWND, "We started the session OK, now trying GnuTLS\n"); - errno = 0; - gnutls_global_init(); - //gnutls_anon_allocate_client_credentials(&anoncred); - gnutls_certificate_allocate_credentials(&xcred); - gnutls_certificate_set_x509_trust_file(xcred, "hostcert.pem", GNUTLS_X509_FMT_PEM); - gnutls_init(control->ssl_session, GNUTLS_CLIENT); - { - int protocol_priority[16] = { GNUTLS_SSL3, 0 }; - int kx_priority[16] = { GNUTLS_KX_ANON_DH, GNUTLS_KX_RSA, 0 }; - int cipher_priority[16] = { GNUTLS_CIPHER_AES_128_CBC, GNUTLS_CIPHER_AES_256_CBC, 0 }; - int mac_priority[16] = { GNUTLS_MAC_SHA1, GNUTLS_MAC_MD5, 0 }; - int comp_priority[16] = { GNUTLS_COMP_NULL, 0 }; - - gnutls_cipher_set_priority(*control->ssl_session, cipher_priority); - gnutls_compression_set_priority(*control->ssl_session, comp_priority); - gnutls_kx_set_priority(*control->ssl_session, kx_priority); - gnutls_protocol_set_priority(*control->ssl_session, protocol_priority); - gnutls_mac_set_priority(*control->ssl_session, mac_priority); + ret = IPHONE_E_SSL_ERROR; + if (lockdown_check_result(dict, "StartSession") == RESULT_SUCCESS) { + // Set up GnuTLS... + //gnutls_anon_client_credentials_t anoncred; + gnutls_certificate_credentials_t xcred; - } - gnutls_credentials_set(*control->ssl_session, GNUTLS_CRD_CERTIFICATE, xcred); // this part is killing me. - - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 1...\n"); - gnutls_transport_set_ptr(*control->ssl_session, (gnutls_transport_ptr_t) control); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 2...\n"); - gnutls_transport_set_push_function(*control->ssl_session, (gnutls_push_func) & lockdownd_secuwrite); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 3...\n"); - gnutls_transport_set_pull_function(*control->ssl_session, (gnutls_pull_func) & lockdownd_securead); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 4 -- now handshaking...\n"); - - if (errno) - log_dbg_msg(DBGMASK_LOCKDOWND, "WARN: errno says %s before handshake!\n", strerror(errno)); - return_me = gnutls_handshake(*control->ssl_session); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS handshake done...\n"); - - if (return_me != GNUTLS_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS reported something wrong.\n"); - gnutls_perror(return_me); - log_dbg_msg(DBGMASK_LOCKDOWND, "oh.. errno says %s\n", strerror(errno)); - return IPHONE_E_SSL_ERROR; - } else { - control->in_SSL = 1; - ret = IPHONE_E_SUCCESS; - } + log_dbg_msg(DBGMASK_LOCKDOWND, "We started the session OK, now trying GnuTLS\n"); + errno = 0; + gnutls_global_init(); + //gnutls_anon_allocate_client_credentials(&anoncred); + gnutls_certificate_allocate_credentials(&xcred); + gnutls_certificate_set_x509_trust_file(xcred, "hostcert.pem", GNUTLS_X509_FMT_PEM); + gnutls_init(client->ssl_session, GNUTLS_CLIENT); + { + int protocol_priority[16] = { GNUTLS_SSL3, 0 }; + int kx_priority[16] = { GNUTLS_KX_ANON_DH, GNUTLS_KX_RSA, 0 }; + int cipher_priority[16] = { GNUTLS_CIPHER_AES_128_CBC, GNUTLS_CIPHER_AES_256_CBC, 0 }; + int mac_priority[16] = { GNUTLS_MAC_SHA1, GNUTLS_MAC_MD5, 0 }; + int comp_priority[16] = { GNUTLS_COMP_NULL, 0 }; + + gnutls_cipher_set_priority(*client->ssl_session, cipher_priority); + gnutls_compression_set_priority(*client->ssl_session, comp_priority); + gnutls_kx_set_priority(*client->ssl_session, kx_priority); + gnutls_protocol_set_priority(*client->ssl_session, protocol_priority); + gnutls_mac_set_priority(*client->ssl_session, mac_priority); + } + gnutls_credentials_set(*client->ssl_session, GNUTLS_CRD_CERTIFICATE, xcred); // this part is killing me. + + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 1...\n"); + gnutls_transport_set_ptr(*client->ssl_session, (gnutls_transport_ptr_t) client); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 2...\n"); + gnutls_transport_set_push_function(*client->ssl_session, (gnutls_push_func) & lockdownd_secuwrite); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 3...\n"); + gnutls_transport_set_pull_function(*client->ssl_session, (gnutls_pull_func) & lockdownd_securead); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 4 -- now handshaking...\n"); + + if (errno) + log_dbg_msg(DBGMASK_LOCKDOWND, "WARN: errno says %s before handshake!\n", strerror(errno)); + return_me = gnutls_handshake(*client->ssl_session); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS handshake done...\n"); + + if (return_me != GNUTLS_E_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS reported something wrong.\n"); + gnutls_perror(return_me); + log_dbg_msg(DBGMASK_LOCKDOWND, "oh.. errno says %s\n", strerror(errno)); + return IPHONE_E_SSL_ERROR; + } else { + client->in_SSL = 1; + ret = IPHONE_E_SUCCESS; } } //store session id @@ -1020,10 +976,11 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c if (session_node_val_type == PLIST_STRING && session_id) { // we need to store the session ID for StopSession - strcpy(control->session_id, session_id); - log_dbg_msg(DBGMASK_LOCKDOWND, "SessionID: %s\n", control->session_id); + strcpy(client->session_id, session_id); + log_dbg_msg(DBGMASK_LOCKDOWND, "SessionID: %s\n", client->session_id); } - free(session_id); + if (session_id) + free(session_id); } } else log_dbg_msg(DBGMASK_LOCKDOWND, "Failed to get SessionID!\n"); @@ -1048,11 +1005,11 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length) { uint32_t bytes = 0; - iphone_lckd_client_t control; - control = (iphone_lckd_client_t) transport; + lockdownd_client_t client; + client = (lockdownd_client_t) transport; log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_secuwrite() called\n"); log_dbg_msg(DBGMASK_LOCKDOWND, "pre-send\nlength = %zi\n", length); - usbmuxd_send(control->sfd, buffer, length, &bytes); + usbmuxd_send(client->sfd, buffer, length, &bytes); log_dbg_msg(DBGMASK_LOCKDOWND, "post-send\nsent %i bytes\n", bytes); dump_debug_buffer("sslpacketwrite.out", buffer, length); @@ -1073,8 +1030,8 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ size_t tbytes = 0; int this_len = length; iphone_error_t res; - iphone_lckd_client_t control; - control = (iphone_lckd_client_t) transport; + lockdownd_client_t client; + client = (lockdownd_client_t) transport; char *recv_buffer; log_debug_msg("lockdownd_securead() called\nlength = %zi\n", length); @@ -1085,8 +1042,8 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ // repeat until we have the full data or an error occurs. do { - if ((res = usbmuxd_recv(control->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != IPHONE_E_SUCCESS) { - log_debug_msg("%s: ERROR: iphone_mux_recv returned %d\n", __func__, res); + if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != IPHONE_E_SUCCESS) { + log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res); return res; } log_debug_msg("post-read\nwe got %i bytes\n", bytes); @@ -1105,6 +1062,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ this_len = length - tbytes; log_debug_msg("re-read\ntrying to read missing %i bytes\n", this_len); } while (tbytes < length); + if (recv_buffer) { free(recv_buffer); } @@ -1114,13 +1072,13 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ /** Command to start the desired service * - * @param control The lockdownd client + * @param client The lockdownd client * @param service The name of the service to start * @param port The port number the service was started on - * @return an error code + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char *service, int *port) +iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port) { if (!client || !service || !port) return IPHONE_E_INVALID_ARG; @@ -1128,7 +1086,7 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char char *host_id = get_host_id(); if (!host_id) return IPHONE_E_INVALID_CONF; - if (!client->in_SSL && !lockdownd_start_SSL_session(client, host_id)) + if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id)) return IPHONE_E_SSL_ERROR; plist_t dict = NULL; @@ -1145,14 +1103,14 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char plist_add_sub_string_el(dict, service); /* send to iPhone */ - ret = iphone_lckd_send(client, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; if (IPHONE_E_SUCCESS != ret) return ret; - ret = iphone_lckd_recv(client, &dict); + ret = lockdownd_recv(client, &dict); if (IPHONE_E_SUCCESS != ret) return ret; @@ -1161,47 +1119,33 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char return IPHONE_E_PLIST_ERROR; ret = IPHONE_E_UNKNOWN_ERROR; - - plist_t query_node = plist_find_node_by_string(dict, "StartService"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_t port_key_node = plist_find_node_by_key(dict, "Port"); - plist_t port_value_node = plist_get_next_sibling(port_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - plist_type port_key_type = plist_get_node_type(port_key_node); - plist_type port_value_type = plist_get_node_type(port_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - char *result_key = NULL; - char *result_value = NULL; - char *port_key = NULL; - uint64_t port_value = 0; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Failure")) { - ret = IPHONE_E_START_SERVICE_FAILED; - } else { - if (port_key_type == PLIST_KEY && port_value_type == PLIST_UINT) { - plist_get_key_val(port_key_node, &port_key); - plist_get_uint_val(port_value_node, &port_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success") && !strcmp(port_key, "Port")) { - port_loc = port_value; - ret = IPHONE_E_SUCCESS; - } - - if (port && ret == IPHONE_E_SUCCESS) - *port = port_loc; + if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { + plist_t port_key_node = plist_find_node_by_key(dict, "Port"); + plist_t port_value_node = plist_get_next_sibling(port_key_node); + + if ((plist_get_node_type(port_key_node) == PLIST_KEY) + && (plist_get_node_type(port_value_node) == PLIST_UINT)) { + char *port_key = NULL; + uint64_t port_value = 0; + + plist_get_key_val(port_key_node, &port_key); + plist_get_uint_val(port_value_node, &port_value); + if (port_key && !strcmp(port_key, "Port")) { + port_loc = port_value; + ret = IPHONE_E_SUCCESS; } + if (port_key) + free(port_key); + + if (port && ret == IPHONE_E_SUCCESS) + *port = port_loc; } } + else + ret = IPHONE_E_START_SERVICE_FAILED; plist_free(dict); dict = NULL; return ret; } + diff --git a/src/lockdown.h b/src/lockdown.h index 1f9d84c..185d27a 100644 --- a/src/lockdown.h +++ b/src/lockdown.h @@ -1,5 +1,5 @@ /* - * lockdown.h + * lockdownd.h * Defines lockdown stuff, like the client struct. * * Copyright (c) 2008 Zach C. All Rights Reserved. @@ -24,36 +24,22 @@ #include #include -#include +#include "libiphone/lockdown.h" - - - -struct iphone_lckd_client_int { +struct lockdownd_client_int { int sfd; gnutls_session_t *ssl_session; int in_SSL; char session_id[40]; }; -iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); -iphone_error_t lockdownd_hello(iphone_lckd_client_t control); - -iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const char *req_key, const char *req_string, - gnutls_datum_t * value); - -iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key); - +iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert, gnutls_datum_t * host_cert, gnutls_datum_t * root_cert); -iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id); -void lockdownd_close(iphone_lckd_client_t control); // SSL functions - -iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID); +iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID); ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length); ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length); - #endif diff --git a/swig/iphone.i b/swig/iphone.i index 0a337ad..25687f5 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -4,15 +4,16 @@ %{ /* Includes the header in the wrapper code */ #include + #include #include -#include "../src/utils.h" + #include "../src/utils.h" typedef struct { iphone_device_t dev; } iPhone; typedef struct { iPhone* dev; - iphone_lckd_client_t client; + lockdownd_client_t client; } Lockdownd; typedef struct { @@ -44,7 +45,7 @@ typedef struct { typedef struct { iPhone* dev; - iphone_lckd_client_t client; + lockdownd_client_t client; } Lockdownd; typedef struct { @@ -68,7 +69,7 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) { Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); client->dev = phone; client->client = NULL; - if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &(client->client))) { + if (IPHONE_E_SUCCESS == lockdownd_new_client ( phone->dev , &(client->client))) { return client; } else { @@ -79,7 +80,7 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) { void my_delete_Lockdownd(Lockdownd* lckd) { if (lckd) { - iphone_lckd_free_client ( lckd->client ); + lockdownd_free_client ( lckd->client ); free(lckd); } } @@ -88,7 +89,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { if (!lckd || !lckd->dev) return NULL; MobileSync* client = NULL; int port = 0; - if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { + if (IPHONE_E_SUCCESS == lockdownd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { client = (MobileSync*) malloc(sizeof(MobileSync)); client->dev = lckd->dev; client->client = NULL; @@ -154,13 +155,13 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { } void send(PListNode* node) { - iphone_lckd_send($self->client, node->node); + lockdownd_send($self->client, node->node); } PListNode* receive() { PListNode* node = (PListNode*)malloc(sizeof(PListNode)); node->node = NULL; - iphone_lckd_recv($self->client, &(node->node)); + lockdownd_recv($self->client, &(node->node)); return node; } -- cgit v1.1-32-gdbae From 5d047fd1e514e098308430fb59ba335b8ae3d385 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 10 Jul 2009 19:01:09 +0200 Subject: Use new plist_copy instead of serialization workaround in lockdownd_et_value() --- dev/lckdclient.c | 7 ++++--- src/lockdown.c | 12 +----------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/dev/lckdclient.c b/dev/lckdclient.c index e197002..e7ad962 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -74,19 +74,20 @@ int main(int argc, char *argv[]) loop = FALSE; if (!strcmp(*args, "get") && len >= 2) { - plist_t *value = NULL; + plist_t value = NULL; if (IPHONE_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value)) { char *xml = NULL; uint32_t length; plist_to_xml(value, &xml, &length); printf("Success : value = %s\n", xml); - free(xml); - free(value); } else printf("Error\n"); + + if (value) + plist_free(value); } if (!strcmp(*args, "start") && len == 2) { diff --git a/src/lockdown.c b/src/lockdown.c index 7e1f1a8..24283cb 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -445,14 +445,8 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain plist_get_key_val(value_key_node, &result_key); if (!strcmp(result_key, "Value")) { - char *buf = NULL; - uint32_t length; log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); - - /* FIXME: libplist does not offer cloning of nodes, use serialization */ - plist_to_bin(value_value_node, &buf, &length); - plist_from_bin(buf, length, value_node); - free(buf); + *value_node = plist_copy(value_value_node); } free(result_key); } @@ -469,7 +463,6 @@ iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid) { iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_t value = NULL; - value = plist_new_dict(); ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value); if (ret != IPHONE_E_SUCCESS) { @@ -492,7 +485,6 @@ iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls plist_t value = NULL; char *value_value = NULL; uint64_t size = 0; - value = plist_new_dict(); ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value); if (ret != IPHONE_E_SUCCESS) { @@ -519,14 +511,12 @@ iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **devic { iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_t value = NULL; - value = plist_new_dict(); ret = lockdownd_get_value(client, NULL, "DeviceName", &value); if (ret != IPHONE_E_SUCCESS) { return ret; } plist_get_string_val(value, device_name); - log_debug_msg("%s: %s\n", __func__, device_name); plist_free(value); value = NULL; -- cgit v1.1-32-gdbae From a68a82800f116706354adb97da1ef0cfd3e38a52 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 14 Jul 2009 14:21:53 +0200 Subject: Cleanup mobilesync API and bindings. Move get_all_contacts() into msyncclient. --- dev/msync.py | 2 +- dev/msyncclient.c | 109 ++++++++++++++++++++++++++++++++++-- include/Makefile.am | 6 +- include/libiphone/libiphone.h | 9 --- src/MobileSync.c | 125 +++++------------------------------------- src/MobileSync.h | 8 +-- swig/iphone.i | 15 ++--- 7 files changed, 134 insertions(+), 140 deletions(-) diff --git a/dev/msync.py b/dev/msync.py index 17e3121..fe7f1fd 100755 --- a/dev/msync.py +++ b/dev/msync.py @@ -12,7 +12,7 @@ def GetMobileSyncClient() : if not lckd : print "Failed to start lockdown service.\n" return None - msync = lckd.get_mobile_sync_client() + msync = lckd.get_mobilesync_client() if not msync : print "Failed to start mobilesync service.\n" return None diff --git a/dev/msyncclient.c b/dev/msyncclient.c index e06a5fe..5eb105d 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -26,6 +26,107 @@ #include #include +#include + +static iphone_error_t mobilesync_get_all_contacts(mobilesync_client_t client) +{ + if (!client) + return IPHONE_E_INVALID_ARG; + + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + plist_t array = NULL; + + array = plist_new_array(); + plist_add_sub_string_el(array, "SDMessageSyncDataClassWithDevice"); + plist_add_sub_string_el(array, "com.apple.Contacts"); + plist_add_sub_string_el(array, "---"); + plist_add_sub_string_el(array, "2009-01-09 18:03:58 +0100"); + plist_add_sub_uint_el(array, 106); + plist_add_sub_string_el(array, "___EmptyParameterString___"); + + ret = mobilesync_send(client, array); + plist_free(array); + array = NULL; + + ret = mobilesync_recv(client, &array); + + plist_t rep_node = plist_find_node_by_string(array, "SDSyncTypeSlow"); + + if (!rep_node) + return ret; + + plist_free(array); + array = NULL; + + array = plist_new_array(); + plist_add_sub_string_el(array, "SDMessageGetAllRecordsFromDevice"); + plist_add_sub_string_el(array, "com.apple.Contacts"); + + + ret = mobilesync_send(client, array); + plist_free(array); + array = NULL; + + ret = mobilesync_recv(client, &array); + + plist_t contact_node; + plist_t switch_node; + + contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); + switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); + + while (NULL == switch_node) { + + plist_free(array); + array = NULL; + + array = plist_new_array(); + plist_add_sub_string_el(array, "SDMessageAcknowledgeChangesFromDevice"); + plist_add_sub_string_el(array, "com.apple.Contacts"); + + ret = mobilesync_send(client, array); + plist_free(array); + array = NULL; + + ret = mobilesync_recv(client, &array); + + contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); + switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); + } + + array = plist_new_array(); + plist_add_sub_string_el(array, "DLMessagePing"); + plist_add_sub_string_el(array, "Preparing to get changes for device"); + + ret = mobilesync_send(client, array); + plist_free(array); + array = NULL; + + array = plist_new_array(); + plist_add_sub_string_el(array, "SDMessageProcessChanges"); + plist_add_sub_string_el(array, "com.apple.Contacts"); + plist_add_sub_node(array, plist_new_dict()); + plist_add_sub_bool_el(array, 0); + plist_t dict = plist_new_dict(); + plist_add_sub_node(array, dict); + plist_add_sub_key_el(dict, "SyncDeviceLinkEntityNamesKey"); + plist_t array2 = plist_new_array(); + plist_add_sub_string_el(array2, "com.apple.contacts.Contact"); + plist_add_sub_string_el(array2, "com.apple.contacts.Group"); + plist_add_sub_key_el(dict, "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey"); + plist_add_sub_bool_el(dict, 0); + + ret = mobilesync_send(client, array); + plist_free(array); + array = NULL; + + ret = mobilesync_recv(client, &array); + plist_free(array); + array = NULL; + + + return ret; +} int main(int argc, char *argv[]) { @@ -50,11 +151,11 @@ int main(int argc, char *argv[]) lockdownd_start_service(client, "com.apple.mobilesync", &port); if (port) { - iphone_msync_client_t msync = NULL; - iphone_msync_new_client(phone, port, &msync); + mobilesync_client_t msync = NULL; + mobilesync_new_client(phone, port, &msync); if (msync) { - iphone_msync_get_all_contacts(msync); - iphone_msync_free_client(msync); + mobilesync_get_all_contacts(msync); + mobilesync_free_client(msync); } } else { printf("Start service failure.\n"); diff --git a/include/Makefile.am b/include/Makefile.am index 98792de..df7b823 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1,5 @@ -nobase_include_HEADERS = libiphone/libiphone.h libiphone/lockdown.h libiphone/afc.h libiphone/notification_proxy.h +nobase_include_HEADERS = libiphone/libiphone.h \ + libiphone/lockdown.h \ + libiphone/afc.h \ + libiphone/notification_proxy.h \ + libiphone/mobilesync.h diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 9e983bb..fa26d14 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -57,9 +57,6 @@ typedef int16_t iphone_error_t; struct iphone_device_int; typedef struct iphone_device_int *iphone_device_t; -struct iphone_msync_client_int; -typedef struct iphone_msync_client_int *iphone_msync_client_t; - //debug related functions #define DBGMASK_ALL 0xFFFF #define DBGMASK_NONE 0x0000 @@ -76,12 +73,6 @@ iphone_error_t iphone_get_device_by_uuid(iphone_device_t *device, const char *uu iphone_error_t iphone_free_device(iphone_device_t device); uint32_t iphone_get_device_handle(iphone_device_t device); -iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, - iphone_msync_client_t * client); -iphone_error_t iphone_msync_free_client(iphone_msync_client_t client); -iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t *plist); -iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist); - #ifdef __cplusplus } #endif diff --git a/src/MobileSync.c b/src/MobileSync.c index 7d6e947..b9a1cb0 100644 --- a/src/MobileSync.c +++ b/src/MobileSync.c @@ -29,8 +29,8 @@ #define MSYNC_VERSION_INT1 100 #define MSYNC_VERSION_INT2 100 -iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, - iphone_msync_client_t * client) +iphone_error_t mobilesync_new_client(iphone_device_t device, int dst_port, + mobilesync_client_t * client) { if (!device || dst_port == 0 || !client || *client) return IPHONE_E_INVALID_ARG; @@ -43,14 +43,14 @@ iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, return ret; } - iphone_msync_client_t client_loc = (iphone_msync_client_t) malloc(sizeof(struct iphone_msync_client_int)); + mobilesync_client_t client_loc = (mobilesync_client_t) malloc(sizeof(struct mobilesync_client_int)); client_loc->sfd = sfd; //perform handshake plist_t array = NULL; //first receive version - ret = iphone_msync_recv(client_loc, &array); + ret = mobilesync_recv(client_loc, &array); plist_t msg_node = plist_find_node_by_string(array, "DLMessageVersionExchange"); plist_t ver_1 = plist_get_next_sibling(msg_node); @@ -77,12 +77,12 @@ iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, plist_add_sub_string_el(array, "DLMessageVersionExchange"); plist_add_sub_string_el(array, "DLVersionsOk"); - ret = iphone_msync_send(client_loc, array); + ret = mobilesync_send(client_loc, array); plist_free(array); array = NULL; - ret = iphone_msync_recv(client_loc, &array); + ret = mobilesync_recv(client_loc, &array); plist_t rep_node = plist_find_node_by_string(array, "DLMessageDeviceReady"); if (rep_node) { @@ -96,12 +96,12 @@ iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, } if (IPHONE_E_SUCCESS != ret) - iphone_msync_free_client(client_loc); + mobilesync_free_client(client_loc); return ret; } -static void iphone_msync_stop_session(iphone_msync_client_t client) +static void mobilesync_disconnect(mobilesync_client_t client) { if (!client) return; @@ -110,17 +110,17 @@ static void iphone_msync_stop_session(iphone_msync_client_t client) plist_add_sub_string_el(array, "DLMessageDisconnect"); plist_add_sub_string_el(array, "All done, thanks for the memories"); - iphone_msync_send(client, array); + mobilesync_send(client, array); plist_free(array); array = NULL; } -iphone_error_t iphone_msync_free_client(iphone_msync_client_t client) +iphone_error_t mobilesync_free_client(mobilesync_client_t client) { if (!client) return IPHONE_E_INVALID_ARG; - iphone_msync_stop_session(client); + mobilesync_disconnect(client); return usbmuxd_disconnect(client->sfd); } @@ -131,7 +131,7 @@ iphone_error_t iphone_msync_free_client(iphone_msync_client_t client) * * @return an error code */ -iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist) +iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist) { if (!client || !plist || (plist && *plist)) return IPHONE_E_INVALID_ARG; @@ -177,7 +177,7 @@ iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist) * * @return an error code */ -iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist) +iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist) { if (!client || !plist) return IPHONE_E_INVALID_ARG; @@ -207,102 +207,3 @@ iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist) return ret; } -iphone_error_t iphone_msync_get_all_contacts(iphone_msync_client_t client) -{ - if (!client) - return IPHONE_E_INVALID_ARG; - - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - plist_t array = NULL; - - array = plist_new_array(); - plist_add_sub_string_el(array, "SDMessageSyncDataClassWithDevice"); - plist_add_sub_string_el(array, "com.apple.Contacts"); - plist_add_sub_string_el(array, "---"); - plist_add_sub_string_el(array, "2009-01-09 18:03:58 +0100"); - plist_add_sub_uint_el(array, 106); - plist_add_sub_string_el(array, "___EmptyParameterString___"); - - ret = iphone_msync_send(client, array); - plist_free(array); - array = NULL; - - ret = iphone_msync_recv(client, &array); - - plist_t rep_node = plist_find_node_by_string(array, "SDSyncTypeSlow"); - - if (!rep_node) - return ret; - - plist_free(array); - array = NULL; - - array = plist_new_array(); - plist_add_sub_string_el(array, "SDMessageGetAllRecordsFromDevice"); - plist_add_sub_string_el(array, "com.apple.Contacts"); - - - ret = iphone_msync_send(client, array); - plist_free(array); - array = NULL; - - ret = iphone_msync_recv(client, &array); - - plist_t contact_node; - plist_t switch_node; - - contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); - switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); - - while (NULL == switch_node) { - - plist_free(array); - array = NULL; - - array = plist_new_array(); - plist_add_sub_string_el(array, "SDMessageAcknowledgeChangesFromDevice"); - plist_add_sub_string_el(array, "com.apple.Contacts"); - - ret = iphone_msync_send(client, array); - plist_free(array); - array = NULL; - - ret = iphone_msync_recv(client, &array); - - contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); - switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); - } - - array = plist_new_array(); - plist_add_sub_string_el(array, "DLMessagePing"); - plist_add_sub_string_el(array, "Preparing to get changes for device"); - - ret = iphone_msync_send(client, array); - plist_free(array); - array = NULL; - - array = plist_new_array(); - plist_add_sub_string_el(array, "SDMessageProcessChanges"); - plist_add_sub_string_el(array, "com.apple.Contacts"); - plist_add_sub_node(array, plist_new_dict()); - plist_add_sub_bool_el(array, 0); - plist_t dict = plist_new_dict(); - plist_add_sub_node(array, dict); - plist_add_sub_key_el(dict, "SyncDeviceLinkEntityNamesKey"); - plist_t array2 = plist_new_array(); - plist_add_sub_string_el(array2, "com.apple.contacts.Contact"); - plist_add_sub_string_el(array2, "com.apple.contacts.Group"); - plist_add_sub_key_el(dict, "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey"); - plist_add_sub_bool_el(dict, 0); - - ret = iphone_msync_send(client, array); - plist_free(array); - array = NULL; - - ret = iphone_msync_recv(client, &array); - plist_free(array); - array = NULL; - - - return ret; -} diff --git a/src/MobileSync.h b/src/MobileSync.h index 495e702..5279ce0 100644 --- a/src/MobileSync.h +++ b/src/MobileSync.h @@ -23,16 +23,12 @@ #include "iphone.h" #include "utils.h" +#include "libiphone/mobilesync.h" #include - - -struct iphone_msync_client_int { +struct mobilesync_client_int { int sfd; }; - -iphone_error_t iphone_msync_get_all_contacts(iphone_msync_client_t client); - #endif diff --git a/swig/iphone.i b/swig/iphone.i index 25687f5..53fa8da 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -5,6 +5,7 @@ /* Includes the header in the wrapper code */ #include #include + #include #include #include "../src/utils.h" typedef struct { @@ -18,7 +19,7 @@ typedef struct { iPhone* dev; - iphone_msync_client_t client; + mobilesync_client_t client; } MobileSync; //now declare funtions to handle creation and deletion of objects @@ -50,7 +51,7 @@ typedef struct { typedef struct { iPhone* dev; - iphone_msync_client_t client; + mobilesync_client_t client; } MobileSync; %inline %{ @@ -93,7 +94,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { client = (MobileSync*) malloc(sizeof(MobileSync)); client->dev = lckd->dev; client->client = NULL; - iphone_msync_new_client ( lckd->dev->dev, port, &(client->client)); + mobilesync_new_client ( lckd->dev->dev, port, &(client->client)); } return client; } @@ -165,7 +166,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { return node; } - MobileSync* get_mobile_sync_client() { + MobileSync* get_mobilesync_client() { return my_new_MobileSync($self); } }; @@ -176,18 +177,18 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { } ~MobileSync() { - iphone_msync_free_client ( $self->client ); + mobilesync_free_client ( $self->client ); free($self); } void send(PListNode* node) { - iphone_msync_send($self->client, node->node); + mobilesync_send($self->client, node->node); } PListNode* receive() { PListNode* node = (PListNode*)malloc(sizeof(PListNode)); node->node = NULL; - iphone_msync_recv($self->client, &(node->node)); + mobilesync_recv($self->client, &(node->node)); return node; } }; -- cgit v1.1-32-gdbae From 654e58d4526f48d44361dcc81d6d0a1b79663b1d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Wed, 15 Jul 2009 16:16:40 +0200 Subject: Implement lockdown set_value, remove_value and enter_recovery request API --- include/libiphone/lockdown.h | 5 +- src/lockdown.c | 163 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 163 insertions(+), 5 deletions(-) diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h index 805c90b..20ccf77 100644 --- a/include/libiphone/lockdown.h +++ b/include/libiphone/lockdown.h @@ -34,7 +34,9 @@ typedef struct lockdownd_client_int *lockdownd_client_t; iphone_error_t lockdownd_new_client (iphone_device_t device, lockdownd_client_t *client); iphone_error_t lockdownd_free_client(lockdownd_client_t client); iphone_error_t lockdownd_query_type(lockdownd_client_t client); -iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node); +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); +iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); +iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); iphone_error_t lockdownd_start_service (lockdownd_client_t client, const char *service, int *port); iphone_error_t lockdownd_stop_session(lockdownd_client_t client); iphone_error_t lockdownd_send (lockdownd_client_t client, plist_t plist); @@ -42,6 +44,7 @@ iphone_error_t lockdownd_recv (lockdownd_client_t client, plist_t *plist); iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id); iphone_error_t lockdownd_get_device_uid (lockdownd_client_t control, char **uid); iphone_error_t lockdownd_get_device_name (lockdownd_client_t client, char **device_name); +iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client); iphone_error_t lockdownd_goodbye(lockdownd_client_t client); #ifdef __cplusplus diff --git a/src/lockdown.c b/src/lockdown.c index 24283cb..1a434aa 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -387,11 +387,11 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client) * @param client an initialized lockdownd client. * @param domain the domain to query on or NULL for global domain * @param key the key name to request or NULL to query for all keys - * @param value_node a plist node representing the result value node + * @param value a plist node representing the result value node * * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node) +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) { if (!client) return IPHONE_E_INVALID_ARG; @@ -427,7 +427,7 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain return ret; if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); ret = IPHONE_E_SUCCESS; } if (ret != IPHONE_E_SUCCESS) { @@ -446,7 +446,7 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain if (!strcmp(result_key, "Value")) { log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); - *value_node = plist_copy(value_value_node); + *value = plist_copy(value_value_node); } free(result_key); } @@ -455,6 +455,126 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain return ret; } +/** Sets a preferences value using a plist and optional domain and/or key name. + * + * @param client an initialized lockdownd client. + * @param domain the domain to query on or NULL for global domain + * @param key the key name to set the value or NULL to set a value dict plist + * @param value a plist node of any node type representing the value to set + * + * @return an error code (IPHONE_E_SUCCESS on success) + */ +iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) +{ + if (!client || !value) + return IPHONE_E_INVALID_ARG; + + plist_t dict = NULL; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + /* setup request plist */ + dict = plist_new_dict(); + if (domain) { + plist_add_sub_key_el(dict, "Domain"); + plist_add_sub_string_el(dict, domain); + } + if (key) { + plist_add_sub_key_el(dict, "Key"); + plist_add_sub_string_el(dict, key); + } + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "SetValue"); + + plist_add_sub_key_el(dict, "Value"); + plist_add_sub_node(dict, value); + + /* send to device */ + ret = lockdownd_send(client, dict); + + plist_free(dict); + dict = NULL; + + if (ret != IPHONE_E_SUCCESS) + return ret; + + /* Now get device's answer */ + ret = lockdownd_recv(client, &dict); + if (ret != IPHONE_E_SUCCESS) + return ret; + + if (lockdown_check_result(dict, "SetValue") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); + ret = IPHONE_E_SUCCESS; + } + + if (ret != IPHONE_E_SUCCESS) { + plist_free(dict); + return ret; + } + + plist_free(dict); + return ret; +} + +/** Removes a preference node on the device by domain and/or key name + * + * @note: Use with caution as this could remove vital information on the device + * + * @param client an initialized lockdownd client. + * @param domain the domain to query on or NULL for global domain + * @param key the key name to remove or NULL remove all keys for the current domain + * + * @return an error code (IPHONE_E_SUCCESS on success) + */ +iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) +{ + if (!client) + return IPHONE_E_INVALID_ARG; + + plist_t dict = NULL; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + /* setup request plist */ + dict = plist_new_dict(); + if (domain) { + plist_add_sub_key_el(dict, "Domain"); + plist_add_sub_string_el(dict, domain); + } + if (key) { + plist_add_sub_key_el(dict, "Key"); + plist_add_sub_string_el(dict, key); + } + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "RemoveValue"); + + /* send to device */ + ret = lockdownd_send(client, dict); + + plist_free(dict); + dict = NULL; + + if (ret != IPHONE_E_SUCCESS) + return ret; + + /* Now get device's answer */ + ret = lockdownd_recv(client, &dict); + if (ret != IPHONE_E_SUCCESS) + return ret; + + if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); + ret = IPHONE_E_SUCCESS; + } + + if (ret != IPHONE_E_SUCCESS) { + plist_free(dict); + return ret; + } + + plist_free(dict); + return ret; +} + /** Asks for the device's unique id. Part of the lockdownd handshake. * * @return an error code (IPHONE_E_SUCCESS on success) @@ -671,6 +791,41 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i return ret; } +/** + * Tells the device to immediately enter recovery mode. + * + * @param client The lockdown client + * + * @return an error code (IPHONE_E_SUCCESS on success) + */ +iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) +{ + if (!client) + return IPHONE_E_INVALID_ARG; + + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + plist_t dict = plist_new_dict(); + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "EnterRecovery"); + + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Telling device to enter recovery mode\n", __func__); + + ret = lockdownd_send(client, dict); + plist_free(dict); + dict = NULL; + + ret = lockdownd_recv(client, &dict); + + if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); + ret = IPHONE_E_SUCCESS; + } + plist_free(dict); + dict = NULL; + return ret; +} + /** * Performs the Goodbye Request to tell the device the communication * session is now closed. -- cgit v1.1-32-gdbae From 8606fb9575c9eb6ffcbc9afec50c7f24e9ddf8d6 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 18 Jul 2009 20:20:34 +0200 Subject: Simplify iphoneinfo by using new lockdownd_get_value replacing custom code --- dev/iphoneinfo.c | 95 ++++++++++++++++---------------------------------------- 1 file changed, 27 insertions(+), 68 deletions(-) diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 7c823e6..33ab3ac 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -46,7 +46,6 @@ static const char *domains[] = { int is_domain_known(char *domain); void print_usage(int argc, char **argv); -void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format); void plist_node_to_string(plist_t *node); void plist_children_to_string(plist_t *node); @@ -60,6 +59,9 @@ int main(int argc, char *argv[]) char uuid[41]; char *domain = NULL; char *key = NULL; + char *xml_doc = NULL; + uint32_t xml_length; + plist_t node = NULL; uuid[0] = 0; /* parse cmdline args */ @@ -135,7 +137,30 @@ int main(int argc, char *argv[]) } /* run query and output information */ - print_lckd_request_result(client, domain, "GetValue", key, format); + if(lockdownd_get_value(client, domain, key, &node) == IPHONE_E_SUCCESS) + { + if (plist_get_node_type(node) == PLIST_DICT) { + if (plist_get_first_child(node)) + { + switch (format) { + case FORMAT_XML: + plist_to_xml(node, &xml_doc, &xml_length); + printf(xml_doc); + free(xml_doc); + break; + case FORMAT_KEY_VALUE: + default: + plist_children_to_string(node); + break; + } + } + } + else if(node && (key != NULL)) + plist_node_to_string(node); + if (node) + plist_free(node); + node = NULL; + } if (domain != NULL) free(domain); @@ -249,69 +274,3 @@ void plist_children_to_string(plist_t *node) } } -void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format) { - char *xml_doc = NULL; - char *s = NULL; - uint32_t xml_length = 0; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - - plist_t node = plist_new_dict(); - if (domain) { - plist_add_sub_key_el(node, "Domain"); - plist_add_sub_string_el(node, domain); - } - if (key) { - plist_add_sub_key_el(node, "Key"); - plist_add_sub_string_el(node, key); - } - plist_add_sub_key_el(node, "Request"); - plist_add_sub_string_el(node, request); - - ret = lockdownd_send(client, node); - if (ret == IPHONE_E_SUCCESS) { - plist_free(node); - node = NULL; - ret = lockdownd_recv(client, &node); - if (ret == IPHONE_E_SUCCESS) { - /* seek to value node */ - for ( - node = plist_get_first_child(node); - node != NULL; - node = plist_get_next_sibling(node) - ) { - if(plist_get_node_type(node) == PLIST_KEY) - { - plist_get_key_val(node, &s); - - if (strcmp("Value", s)) - continue; - - node = plist_get_next_sibling(node); - - if (plist_get_node_type(node) == PLIST_DICT) { - if (plist_get_first_child(node)) - { - switch (format) { - case FORMAT_XML: - plist_to_xml(node, &xml_doc, &xml_length); - printf(xml_doc); - free(xml_doc); - break; - case FORMAT_KEY_VALUE: - default: - plist_children_to_string(node); - break; - } - } - } - else if(node && (key != NULL)) - plist_node_to_string(node); - } - } - } - } - if (node) - plist_free(node); - node = NULL; -} - -- cgit v1.1-32-gdbae From 67a0fe9b8eb5c85348f282fee540e4fee6eedde9 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sun, 19 Jul 2009 15:29:08 +0200 Subject: Add missing mobilesync public header --- include/libiphone/mobilesync.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/libiphone/mobilesync.h diff --git a/include/libiphone/mobilesync.h b/include/libiphone/mobilesync.h new file mode 100644 index 0000000..128be45 --- /dev/null +++ b/include/libiphone/mobilesync.h @@ -0,0 +1,43 @@ +/* + * mobilesync.h + * + * Copyright (c) 2009 Martin S. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef IMOBILESYNC_H +#define IMOBILESYNC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct mobilesync_client_int; +typedef struct mobilesync_client_int *mobilesync_client_t; + +iphone_error_t mobilesync_new_client(iphone_device_t device, int dst_port, + mobilesync_client_t * client); +iphone_error_t mobilesync_free_client(mobilesync_client_t client); +iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t *plist); +iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist); + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.1-32-gdbae From 37f8ad0f3e64c23cd32c8c58636510f7964f1891 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 19 Jul 2009 20:07:21 +0200 Subject: New type afc_lock_op_t with allowed lock operations for afc_lock_file. Only non-blocking locks are supported via AFC. Signed-off-by: Martin Szulecki --- dev/main.c | 4 ++-- include/libiphone/afc.h | 8 +++++++- src/AFC.c | 22 ++++++++++------------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/dev/main.c b/dev/main.c index cf7dbaa..33ebc2d 100644 --- a/dev/main.c +++ b/dev/main.c @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); - afc_lock_file(afc, lockfile, 2 | 4); + afc_lock_file(afc, lockfile, AFC_LOCK_EX); perform_notification(phone, client, NP_SYNC_DID_START); } @@ -227,7 +227,7 @@ int main(int argc, char *argv[]) //perform_notification(phone, control, NP_SYNC_DID_FINISH); printf("XXX unlocking file\n"); - afc_lock_file(afc, lockfile, 8 | 4); + afc_lock_file(afc, lockfile, AFC_LOCK_UN); printf("XXX closing file\n"); afc_close_file(afc, lockfile); diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 2a0bbad..b64510b 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -21,6 +21,12 @@ typedef enum { AFC_SYMLINK = 2 } afc_link_type_t; +typedef enum { + AFC_LOCK_SH = 1 | 4, // shared lock + AFC_LOCK_EX = 2 | 4, // exclusive lock + AFC_LOCK_UN = 8 | 4 // unlock +} afc_lock_op_t; + struct afc_client_int; typedef struct afc_client_int *afc_client_t; @@ -36,7 +42,7 @@ iphone_error_t afc_get_dir_list ( afc_client_t client, const char *dir, char *** iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist ); iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle ); iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle); -iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, int operation); +iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, afc_lock_op_t operation); iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence); diff --git a/src/AFC.c b/src/AFC.c index e666c45..cd120fc 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -174,6 +174,9 @@ static int afcerror_to_errno(int afcerror) case 10: // occurs if you try to open a file without permission res = EPERM; break; + case 19: // occurs if you try to lock an already locked file + res = EWOULDBLOCK; + break; default: // we'll assume it's an errno value, but report it log_debug_msg("WARNING: unknown AFC error %d, perhaps it's '%s'?\n", afcerror, strerror(afcerror)); res = afcerror; @@ -986,21 +989,16 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) /** Locks or unlocks a file on the phone. * - * makes use of flock, see + * makes use of flock on the device, see * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html * - * operation (same as in sys/file.h on linux): - * - * LOCK_SH 1 // shared lock - * LOCK_EX 2 // exclusive lock - * LOCK_NB 4 // don't block when locking - * LOCK_UN 8 // unlock - * - * @param client The client to close the file with. + * @param client The client to lock the file with. * @param handle File handle of a previously opened file. - * @operation the lock or unlock operation to perform. + * @param operation the lock or unlock operation to perform, this is one of + * AFC_LOCK_SH (shared lock), AFC_LOCK_EX (exclusive lock), + * or AFC_LOCK_UN (unlock). */ -iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation) +iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t operation) { if (!client || (handle == 0)) return IPHONE_E_INVALID_ARG; @@ -1024,7 +1022,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation if (bytes <= 0) { afc_unlock(client); - log_debug_msg("fuck\n"); + log_debug_msg("Could not send lock command\n"); return IPHONE_E_UNKNOWN_ERROR; } // Receive the response -- cgit v1.1-32-gdbae From 0e80ca70829eb7c3cab32019ca4dfaef577b6e69 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 21 Jul 2009 00:53:05 +0200 Subject: Add new lockdown request domains to iphoneinfo --- dev/iphoneinfo.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 33ab3ac..67e7552 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -37,7 +37,12 @@ static const char *domains[] = { "com.apple.mobile.debug",. */ "com.apple.xcode.developerdomain", "com.apple.international", + "com.apple.mobile.mobile_application_usage", + "com.apple.mobile.backup", + "com.apple.mobile.user_preferences", "com.apple.mobile.sync_data_class", + "com.apple.mobile.software_behavior", + "com.apple.mobile.iTunes.SQLMusicLibraryPostProcessCommands", "com.apple.iTunes", "com.apple.mobile.iTunes.store", "com.apple.mobile.iTunes", -- cgit v1.1-32-gdbae From 2e0e269663ac279f3e7a8430ac8c6ec1d4fc2266 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 14:50:58 +0200 Subject: Update README structure, URLS and make requirements more general --- README | 60 +++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/README b/README index d0fc3a9..3c7011f 100644 --- a/README +++ b/README @@ -1,18 +1,23 @@ -INSTALLATION -================================================================================ - -For: - Apple iPhone/iPod Touch 1.0/1.1/1.1.1/1.2/1.3/2.0+ - + iPod USB cable - -You must have: - libgnutls-dev - libgcrypt-dev - libusb-dev - libfuse-dev (and the associated kernel modules) - libglib2.0-dev - libplist-dev - usbmuxd (http://pims.selfip.net/git/usbmuxd) +About +===== + +A library to communicate with services running on Apple iPhone/iPod Touch +devices. + +Requirements +============ + +Development Packages of: + libgnutls + libgcrypt + libusb + libfuse (and the associated kernel modules) + glib2.0 + libplist + libusbmuxd (within usbmuxd package, see below) + +Software: + usbmuxd (git clone http://pims.selfip.net/git/usbmuxd) make autoheader automake @@ -20,30 +25,35 @@ You must have: libtool gcc +Installation +============ + To compile run: ./autogen.sh ./configure make - sudo make install # (if you want to install it into your system directories) + sudo make install On Ubuntu/Debian, you can do: sudo apt-get install build-essential automake autoconf libtool\ libgnutls-dev libusb-dev libfuse-dev libglib2.0-dev libxml2-dev \ libreadline5-dev -== Who/what/where? == +Who/What/Where? +=============== -wiki: - http://matt.colyer.name/projects/iphone-linux/index.php?title=Main_Page +Wiki: + http://matt.colyer.name/projects/iphone-linux/ -code: +Code: git clone git://github.com/MattColyer/libiphone.git -tickets: - http://libiphone.lighthouseapp.com/projects/27916-libiphone/tickets?q=all +Tickets: + http://libiphone.lighthouseapp.com/ -mailing list: +Mailing List: http://lists.mattcolyer.com/listinfo.cgi/iphone-linux-dev-mattcolyer.com -updated: - 2009-04-23 +README Updated on: + 2009-07-24 + -- cgit v1.1-32-gdbae From 4c81f3c622d80a9291f3c13de2075afd753a0e1c Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 14:56:24 +0200 Subject: Add missing copyright to afc and notification_proxy headers --- include/libiphone/afc.h | 20 ++++++++++++++++++++ include/libiphone/notification_proxy.h | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index b64510b..af801b1 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -1,3 +1,23 @@ +/* + * afc.h + * + * Copyright (c) 2009 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #ifndef AFC_H #define AFC_H diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h index 9412b4f..8efb483 100644 --- a/include/libiphone/notification_proxy.h +++ b/include/libiphone/notification_proxy.h @@ -1,3 +1,23 @@ +/* + * notification_proxy.h + * + * Copyright (c) 2009 Nikias Bassen All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #ifndef NOTIFICATION_PROXY_H #define NOTIFICATION_PROXY_H -- cgit v1.1-32-gdbae From cd1aa1c8107c1609746c12a6cd6777bd053167df Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 16:21:37 +0200 Subject: Add --debug option to afccheck --- dev/afccheck.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dev/afccheck.c b/dev/afccheck.c index 9174e32..0525417 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -91,6 +91,14 @@ int main(int argc, char *argv[]) int port = 0; afc_client_t afc = NULL; + if (argc > 1 && !strcasecmp(argv[1], "--debug")) { + iphone_set_debug_level(1); + iphone_set_debug_mask(DBGMASK_ALL); + } else { + iphone_set_debug_level(0); + iphone_set_debug_mask(DBGMASK_NONE); + } + if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); return 1; -- cgit v1.1-32-gdbae From f995c63e1bc56dd2d098a06f130d55334979f38f Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 16:35:28 +0200 Subject: Add new NP_ITDBPREP_DID_END notification signaling music db refresh --- dev/main.c | 3 ++- include/libiphone/notification_proxy.h | 1 + src/NotificationProxy.h | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/main.c b/dev/main.c index 33ebc2d..b4e5c34 100644 --- a/dev/main.c +++ b/dev/main.c @@ -113,10 +113,11 @@ int main(int argc, char *argv[]) printf("ERROR: Notification proxy could not be started.\n"); } if (gnp) { - const char *nspec[4] = { + const char *nspec[5] = { NP_SYNC_CANCEL_REQUEST, NP_SYNC_SUSPEND_REQUEST, NP_SYNC_RESUME_REQUEST, + NP_ITDBPREP_DID_END, NULL }; np_observe_notifications(gnp, nspec); diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h index 8efb483..14d1b39 100644 --- a/include/libiphone/notification_proxy.h +++ b/include/libiphone/notification_proxy.h @@ -46,6 +46,7 @@ typedef struct np_client_int *np_client_t; #define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed" #define NP_APP_INSTALLED "com.apple.mobile.application_installed" #define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" +#define NP_ITDBPREP_DID_END "com.apple.itdbprep.notification.didEnd" iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ); iphone_error_t np_free_client ( np_client_t client ); diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h index a10cde4..02f4251 100644 --- a/src/NotificationProxy.h +++ b/src/NotificationProxy.h @@ -28,7 +28,7 @@ struct np_client_int { GThread *notifier; }; -static const char *np_default_notifications[10] = { +static const char *np_default_notifications[11] = { NP_SYNC_SUSPEND_REQUEST, NP_SYNC_RESUME_REQUEST, NP_PHONE_NUMBER_CHANGED, @@ -38,6 +38,7 @@ static const char *np_default_notifications[10] = { NP_DS_DOMAIN_CHANGED, NP_APP_INSTALLED, NP_APP_UNINSTALLED, + NP_ITDBPREP_DID_END, NULL }; -- cgit v1.1-32-gdbae From 601e70e8ee757b769bdc10b16e108e846a1a0b93 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 17:46:30 +0200 Subject: Rename iphone_set_debug() to iphone_set_debug_level() and code using it --- dev/iphone_id.c | 2 +- dev/iphoneinfo.c | 2 +- dev/lckdclient.c | 2 +- dev/main.c | 4 ++-- dev/syslog_relay.c | 2 +- include/libiphone/libiphone.h | 4 ++-- src/utils.c | 2 +- swig/iphone.i | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dev/iphone_id.c b/dev/iphone_id.c index 15081f0..dde15bc 100644 --- a/dev/iphone_id.c +++ b/dev/iphone_id.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) return 0; } - iphone_set_debug(0); + iphone_set_debug_level(0); iphone_get_device_by_uuid(&phone, argv[0]); if (!phone) { diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 67e7552..02b62d5 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { iphone_set_debug_mask(DBGMASK_ALL); - iphone_set_debug(1); + iphone_set_debug_level(1); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { diff --git a/dev/lckdclient.c b/dev/lckdclient.c index e7ad962..820d05f 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) lockdownd_client_t client = NULL; iphone_device_t phone = NULL; - iphone_set_debug(1); + iphone_set_debug_level(1); if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); diff --git a/dev/main.c b/dev/main.c index b4e5c34..9c8b155 100644 --- a/dev/main.c +++ b/dev/main.c @@ -68,10 +68,10 @@ int main(int argc, char *argv[]) np_client_t gnp = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) { - iphone_set_debug(1); + iphone_set_debug_level(1); iphone_set_debug_mask(DBGMASK_ALL); } else { - iphone_set_debug(0); + iphone_set_debug_level(0); iphone_set_debug_mask(DBGMASK_NONE); } diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index a93e85b..09be6b8 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { iphone_set_debug_mask(DBGMASK_ALL); - iphone_set_debug(1); + iphone_set_debug_level(1); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index fa26d14..fef59e0 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -57,7 +57,7 @@ typedef int16_t iphone_error_t; struct iphone_device_int; typedef struct iphone_device_int *iphone_device_t; -//debug related functions +/* Debugging */ #define DBGMASK_ALL 0xFFFF #define DBGMASK_NONE 0x0000 #define DBGMASK_USBMUX (1 << 1) @@ -65,7 +65,7 @@ typedef struct iphone_device_int *iphone_device_t; #define DBGMASK_MOBILESYNC (1 << 3) void iphone_set_debug_mask(uint16_t mask); -void iphone_set_debug(int level); +void iphone_set_debug_level(int level); //device related functions iphone_error_t iphone_get_device(iphone_device_t *device); diff --git a/src/utils.c b/src/utils.c index 5b0872d..121bc55 100644 --- a/src/utils.c +++ b/src/utils.c @@ -31,7 +31,7 @@ uint16_t dbg_mask = 0; * * @param level Set to 0 for no debugging or 1 for debugging. */ -void iphone_set_debug(int level) +void iphone_set_debug_level(int level) { toto_debug = level; } diff --git a/swig/iphone.i b/swig/iphone.i index 53fa8da..a089cc2 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -118,7 +118,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { } void set_debug_level(int level) { - iphone_set_debug(level); + iphone_set_debug_level(level); } int init_device_by_uuid(char* uuid) { -- cgit v1.1-32-gdbae From fa3465884eee33178d81ace5f538182704311557 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 17:54:06 +0200 Subject: Add missing macro preventing cyclic includes in notification proxy header --- src/NotificationProxy.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h index 02f4251..bc5be43 100644 --- a/src/NotificationProxy.h +++ b/src/NotificationProxy.h @@ -18,10 +18,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libiphone/notification_proxy.h" +#ifndef INOTIFICATION_PROXY_H +#define INOTIFICATION_PROXY_H #include +#include "libiphone/notification_proxy.h" + struct np_client_int { int sfd; GMutex *mutex; @@ -42,4 +45,6 @@ static const char *np_default_notifications[11] = { NULL }; -gpointer np_notifier( gpointer arg ); +gpointer np_notifier(gpointer arg); + +#endif -- cgit v1.1-32-gdbae From 15e2c165ac63e225e3fbfc531da5c1f19fede569 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 17:59:39 +0200 Subject: Remove DBGMASK_USBMUX as it is obsolete since the libusbmuxd code merge --- include/libiphone/libiphone.h | 5 ++--- swig/iphone.i | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index fef59e0..b8c1c59 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -60,9 +60,8 @@ typedef struct iphone_device_int *iphone_device_t; /* Debugging */ #define DBGMASK_ALL 0xFFFF #define DBGMASK_NONE 0x0000 -#define DBGMASK_USBMUX (1 << 1) -#define DBGMASK_LOCKDOWND (1 << 2) -#define DBGMASK_MOBILESYNC (1 << 3) +#define DBGMASK_LOCKDOWND (1 << 1) +#define DBGMASK_MOBILESYNC (1 << 2) void iphone_set_debug_mask(uint16_t mask); void iphone_set_debug_level(int level); diff --git a/swig/iphone.i b/swig/iphone.i index a089cc2..59be4ef 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -36,9 +36,8 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd); #define DBGMASK_ALL 0xFFFF #define DBGMASK_NONE 0x0000 -#define DBGMASK_USBMUX (1 << 1) -#define DBGMASK_LOCKDOWND (1 << 2) -#define DBGMASK_MOBILESYNC (1 << 3) +#define DBGMASK_LOCKDOWND (1 << 1) +#define DBGMASK_MOBILESYNC (1 << 2) typedef struct { iphone_device_t dev; -- cgit v1.1-32-gdbae From 83529098fbf4b39b2643a7c0bf39828247d11f9a Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 22:21:53 +0200 Subject: Improve debug output messages by using __func__ everywhere and adjust wording --- src/AFC.c | 67 ++++++++++++++++------------------ src/MobileSync.c | 4 +-- src/NotificationProxy.c | 1 - src/lockdown.c | 95 +++++++++++++++++++++++-------------------------- src/userpref.c | 5 ++- src/utils.c | 3 +- 6 files changed, 79 insertions(+), 96 deletions(-) diff --git a/src/AFC.c b/src/AFC.c index cd120fc..8cc88f1 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -39,11 +39,7 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15); */ static void afc_lock(afc_client_t client) { - log_debug_msg("Locked\n"); - /*while (client->lock) { - usleep(500); // they say it's obsolete, but whatever - } - client->lock = 1; */ + log_debug_msg("%s: Locked\n", __func__); g_mutex_lock(client->mutex); } @@ -52,9 +48,8 @@ static void afc_lock(afc_client_t client) * @param client The AFC */ static void afc_unlock(afc_client_t client) -{ // just to be pretty - log_debug_msg("Unlocked\n"); - //client->lock = 0; +{ + log_debug_msg("%s: Unlocked\n", __func__); g_mutex_unlock(client->mutex); } @@ -245,12 +240,12 @@ static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t l memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket)); offset = client->afc_packet->this_length - sizeof(AFCPacket); - log_debug_msg("dispatch_AFC_packet: Offset: %i\n", offset); + log_debug_msg("%s: Offset: %i\n", __func__, offset); if ((length) < (client->afc_packet->entire_length - client->afc_packet->this_length)) { - log_debug_msg("dispatch_AFC_packet: Length did not resemble what it was supposed"); + log_debug_msg("%s: Length did not resemble what it was supposed", __func__); log_debug_msg("to based on the packet.\n"); - log_debug_msg("length minus offset: %i\n", length - offset); - log_debug_msg("rest of packet: %i\n", client->afc_packet->entire_length - client->afc_packet->this_length); + log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset); + log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length); free(buffer); return -1; } @@ -261,19 +256,19 @@ static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t l return bytes; } - log_debug_msg("dispatch_AFC_packet: sent the first now go with the second\n"); - log_debug_msg("Length: %i\n", length - offset); - log_debug_msg("Buffer: \n"); + log_debug_msg("%s: sent the first now go with the second\n", __func__); + log_debug_msg("%s: Length: %i\n", __func__, length - offset); + log_debug_msg("%s: Buffer: \n", __func__); log_debug_buffer(data + offset, length - offset); usbmuxd_send(client->sfd, data + offset, length - offset, (uint32_t*)&bytes); return bytes; } else { - log_debug_msg("dispatch_AFC_packet doin things the old way\n"); + log_debug_msg("%s: doin things the old way\n", __func__); buffer = (char *) malloc(sizeof(char) * client->afc_packet->this_length); - log_debug_msg("dispatch_AFC_packet packet length = %i\n", client->afc_packet->this_length); + log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length); memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket)); - log_debug_msg("dispatch_AFC_packet packet data follows\n"); + log_debug_msg("%s: packet data follows\n", __func__); if (length > 0) { memcpy(buffer + sizeof(AFCPacket), data, length); } @@ -354,7 +349,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) } } - log_debug_msg("%s: received AFC packet, full len=%lld, this len=%lld, operation=%lld\n", __func__, header.entire_length, header.this_length, header.operation); + log_debug_msg("%s: received AFC packet, full len=%lld, this len=%lld, operation=0x%llx\n", __func__, header.entire_length, header.this_length, header.operation); entire_len = (uint32_t)header.entire_length - sizeof(AFCPacket); this_len = (uint32_t)header.this_length - sizeof(AFCPacket); @@ -758,7 +753,7 @@ afc_open_file(afc_client_t client, const char *filename, free(data); if (bytes <= 0) { - log_debug_msg("afc_open_file: Didn't receive a response to the command\n"); + log_debug_msg("%s: Didn't receive a response to the command\n", __func__); afc_unlock(client); return IPHONE_E_NOT_ENOUGH_DATA; } @@ -800,14 +795,14 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint if (!client || !client->afc_packet || client->sfd < 0 || handle == 0) return IPHONE_E_INVALID_ARG; - log_debug_msg("afc_read_file called for length %i\n", length); + log_debug_msg("%s: called for length %i\n", __func__, length); afc_lock(client); // Looping here to get around the maximum amount of data that // recieve_AFC_data can handle while (current_count < length) { - log_debug_msg("afc_read_file: current count is %i but length is %i\n", current_count, length); + log_debug_msg("%s: current count is %i but length is %i\n", __func__, current_count, length); // Send the read command AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); @@ -824,7 +819,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint } // Receive the data bytes_loc = receive_AFC_data(client, &input); - log_debug_msg("afc_read_file: bytes returned: %i\n", bytes_loc); + log_debug_msg("%s: bytes returned: %i\n", __func__, bytes_loc); if (bytes_loc < 0) { afc_unlock(client); return IPHONE_E_AFC_ERROR; @@ -837,7 +832,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint // success } else { if (input) { - log_debug_msg("afc_read_file: %d\n", bytes_loc); + log_debug_msg("%s: %d\n", __func__, bytes_loc); memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc); free(input); input = NULL; @@ -845,7 +840,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint } } } - log_debug_msg("afc_read_file: returning current_count as %i\n", current_count); + log_debug_msg("%s: returning current_count as %i\n", __func__, current_count); afc_unlock(client); *bytes = current_count; @@ -878,7 +873,7 @@ afc_write_file(afc_client_t client, uint64_t handle, afc_lock(client); - log_debug_msg("afc_write_file: Write length: %i\n", length); + log_debug_msg("%s: Write length: %i\n", __func__, length); // Divide the file into segments. for (i = 0; i < segments; i++) { @@ -939,7 +934,7 @@ afc_write_file(afc_client_t client, uint64_t handle, bytes_loc = receive_AFC_data(client, &acknowledgement); afc_unlock(client); if (bytes_loc < 0) { - log_debug_msg("afc_write_file: uh oh?\n"); + log_debug_msg("%s: uh oh?\n", __func__); } else { free(acknowledgement); } @@ -961,7 +956,7 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) afc_lock(client); - log_debug_msg("afc_close_file: File handle %i\n", handle); + log_debug_msg("%s: File handle %i\n", __func__, handle); // Send command memcpy(buffer, &handle, sizeof(uint64_t)); @@ -971,18 +966,16 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) free(buffer); buffer = NULL; - // FIXME: Is this necesary? - // client->afc_packet->entire_length = client->afc_packet->this_length - // = 0; - if (bytes <= 0) { afc_unlock(client); return IPHONE_E_UNKNOWN_ERROR; } + // Receive the response bytes = receive_AFC_data(client, &buffer); if (buffer) free(buffer); + afc_unlock(client); return IPHONE_E_SUCCESS; } @@ -1008,7 +1001,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t afc_lock(client); - log_debug_msg("afc_lock_file: File handle %i\n", handle); + log_debug_msg("%s: file handle %i\n", __func__, handle); // Send command memcpy(buffer, &handle, sizeof(uint64_t)); @@ -1022,7 +1015,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t if (bytes <= 0) { afc_unlock(client); - log_debug_msg("Could not send lock command\n"); + log_debug_msg("%s: could not send lock command\n", __func__); return IPHONE_E_UNKNOWN_ERROR; } // Receive the response @@ -1194,9 +1187,9 @@ iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, cons afc_lock(client); - log_debug_msg("link type: %lld\n", type); - log_debug_msg("target: %s, length:%d\n", target, strlen(target)); - log_debug_msg("linkname: %s, length:%d\n", linkname, strlen(linkname)); + log_debug_msg("%s: link type: %lld\n", __func__, type); + log_debug_msg("%s: target: %s, length:%d\n", __func__, target, strlen(target)); + log_debug_msg("%s: linkname: %s, length:%d\n", __func__, linkname, strlen(linkname)); // Send command memcpy(send, &type, 8); diff --git a/src/MobileSync.c b/src/MobileSync.c index b9a1cb0..f544400 100644 --- a/src/MobileSync.c +++ b/src/MobileSync.c @@ -161,7 +161,7 @@ iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist) char *XMLContent = NULL; uint32_t length = 0; plist_to_xml(*plist, &XMLContent, &length); - log_dbg_msg(DBGMASK_MOBILESYNC, "Recv msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); + log_dbg_msg(DBGMASK_MOBILESYNC, "%s: plist size: %i\nbuffer :\n%s\n", __func__, length, XMLContent); free(XMLContent); return ret; @@ -185,7 +185,7 @@ iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist) char *XMLContent = NULL; uint32_t length = 0; plist_to_xml(plist, &XMLContent, &length); - log_dbg_msg(DBGMASK_MOBILESYNC, "Send msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); + log_dbg_msg(DBGMASK_MOBILESYNC, "%s: plist size: %i\nbuffer :\n%s\n", __func__, length, XMLContent); free(XMLContent); char *content = NULL; diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index 374420c..1bbdc6d 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c @@ -226,7 +226,6 @@ iphone_error_t np_observe_notification( np_client_t client, const char *notifica return res; } - /** Notifies the iphone to send a notification on specified events. * * observation messages seen so far: diff --git a/src/lockdown.c b/src/lockdown.c index 1a434aa..bfb44d0 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -140,7 +140,7 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client) plist_add_sub_key_el(dict, "SessionID"); plist_add_sub_string_el(dict, client->session_id); - log_dbg_msg(DBGMASK_LOCKDOWND, "iphone_lckd_stop_session() called\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); ret = lockdownd_send(client, dict); @@ -150,13 +150,13 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client) ret = lockdownd_recv(client, &dict); if (!dict) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): IPHONE_E_PLIST_ERROR\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__); return IPHONE_E_PLIST_ERROR; } ret = IPHONE_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); ret = IPHONE_E_SUCCESS; } plist_free(dict); @@ -175,15 +175,15 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client) static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) { if (!client) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_ssl_session(): invalid argument!\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: invalid argument!\n", __func__); return IPHONE_E_INVALID_ARG; } iphone_error_t ret = IPHONE_E_SUCCESS; if (client->in_SSL) { - log_dbg_msg(DBGMASK_LOCKDOWND, "Stopping SSL Session\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: stopping SSL session\n", __func__); ret = lockdownd_stop_session(client); - log_dbg_msg(DBGMASK_LOCKDOWND, "Sending SSL close notify\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending SSL close notify\n", __func__); gnutls_bye(*client->ssl_session, GNUTLS_SHUT_RDWR); } if (client->ssl_session) { @@ -281,7 +281,7 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) return IPHONE_E_NOT_ENOUGH_DATA; } - log_dbg_msg(DBGMASK_LOCKDOWND, "Recv msg :\nsize : %i\nbuffer :\n%s\n", received_bytes, receive); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: received msg size: %i, buffer follows:\n%s", __func__, received_bytes, receive); plist_from_xml(receive, received_bytes, plist); free(receive); @@ -312,14 +312,14 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_to_xml(plist, &XMLContent, &length); - log_dbg_msg(DBGMASK_LOCKDOWND, "Send msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending msg size %i, buffer follows:\n%s", __func__, length, XMLContent); real_query = (char *) malloc(sizeof(char) * (length + 4)); length = htonl(length); memcpy(real_query, &length, sizeof(length)); memcpy(real_query + 4, XMLContent, ntohl(length)); free(XMLContent); - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): made the query, sending it along\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: made the query, sending it along\n", __func__); if (!client->in_SSL) ret = usbmuxd_send(client->sfd, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes); @@ -334,9 +334,9 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) } } if (ret == IPHONE_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): sent it!\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sent it!\n", __func__); } else { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): sending failed!\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending failed!\n", __func__); } free(real_query); @@ -360,7 +360,7 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "QueryType"); - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type() called\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); ret = lockdownd_send(client, dict); plist_free(dict); @@ -373,7 +373,7 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client) ret = IPHONE_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type(): success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); ret = IPHONE_E_SUCCESS; } plist_free(dict); @@ -445,7 +445,7 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain plist_get_key_val(value_key_node, &result_key); if (!strcmp(result_key, "Value")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__); *value = plist_copy(value_value_node); } free(result_key); @@ -669,17 +669,16 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); client_loc->in_SSL = 0; - if (IPHONE_E_SUCCESS != lockdownd_query_type(client_loc)) { - log_debug_msg("QueryType failed in the lockdownd client.\n"); + log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__); ret = IPHONE_E_NOT_ENOUGH_DATA; } char *uid = NULL; ret = lockdownd_get_device_uid(client_loc, &uid); if (IPHONE_E_SUCCESS != ret) { - log_debug_msg("Device refused to send uid.\n"); + log_debug_msg("%s: failed to get device uuid.\n", __func__); } - log_debug_msg("Device uid: %s\n", uid); + log_debug_msg("%s: device uuid: %s\n", __func__, uid); host_id = get_host_id(); if (IPHONE_E_SUCCESS == ret && !host_id) { @@ -698,7 +697,7 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * ret = lockdownd_start_ssl_session(client_loc, host_id); if (IPHONE_E_SUCCESS != ret) { ret = IPHONE_E_SSL_ERROR; - log_debug_msg("SSL Session opening failed.\n"); + log_debug_msg("%s: SSL Session opening failed.\n", __func__); } if (host_id) { @@ -731,10 +730,10 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i ret = lockdownd_get_device_public_key(client, &public_key); if (ret != IPHONE_E_SUCCESS) { - log_debug_msg("Device refused to send public key.\n"); + log_debug_msg("%s: device refused to send public key.\n", __func__); return ret; } - log_debug_msg("device public key :\n %s.\n", public_key.data); + log_debug_msg("%s: device public key follows:\n%s\n", __func__, public_key.data); ret = lockdownd_gen_pair_cert(public_key, &device_cert, &host_cert, &root_cert); if (ret != IPHONE_E_SUCCESS) { @@ -780,11 +779,11 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i /* store public key in config if pairing succeeded */ if (ret == IPHONE_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); store_device_public_key(uid, public_key); ret = IPHONE_E_SUCCESS; } else { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair failure\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); ret = IPHONE_E_PAIRING_FAILED; } free(public_key.data); @@ -809,7 +808,7 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "EnterRecovery"); - log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Telling device to enter recovery mode\n", __func__); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: telling device to enter recovery mode\n", __func__); ret = lockdownd_send(client, dict); plist_free(dict); @@ -845,21 +844,20 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "Goodbye"); - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye() called\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; ret = lockdownd_recv(client, &dict); - if (!dict) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): IPHONE_E_PLIST_ERROR\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: did not get goodbye response back\n", __func__); return IPHONE_E_PLIST_ERROR; } if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); ret = IPHONE_E_SUCCESS; } plist_free(dict); @@ -1062,7 +1060,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char //gnutls_anon_client_credentials_t anoncred; gnutls_certificate_credentials_t xcred; - log_dbg_msg(DBGMASK_LOCKDOWND, "We started the session OK, now trying GnuTLS\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: started the session OK, now trying GnuTLS\n", __func__); errno = 0; gnutls_global_init(); //gnutls_anon_allocate_client_credentials(&anoncred); @@ -1084,23 +1082,22 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char } gnutls_credentials_set(*client->ssl_session, GNUTLS_CRD_CERTIFICATE, xcred); // this part is killing me. - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 1...\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 1...\n", __func__); gnutls_transport_set_ptr(*client->ssl_session, (gnutls_transport_ptr_t) client); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 2...\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 2...\n", __func__); gnutls_transport_set_push_function(*client->ssl_session, (gnutls_push_func) & lockdownd_secuwrite); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 3...\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 3...\n", __func__); gnutls_transport_set_pull_function(*client->ssl_session, (gnutls_pull_func) & lockdownd_securead); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 4 -- now handshaking...\n"); - + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 4 -- now handshaking...\n", __func__); if (errno) - log_dbg_msg(DBGMASK_LOCKDOWND, "WARN: errno says %s before handshake!\n", strerror(errno)); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: WARN: errno says %s before handshake!\n", __func__, strerror(errno)); return_me = gnutls_handshake(*client->ssl_session); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS handshake done...\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS handshake done...\n", __func__); if (return_me != GNUTLS_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS reported something wrong.\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS reported something wrong.\n", __func__); gnutls_perror(return_me); - log_dbg_msg(DBGMASK_LOCKDOWND, "oh.. errno says %s\n", strerror(errno)); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: oh.. errno says %s\n", __func__, strerror(errno)); return IPHONE_E_SSL_ERROR; } else { client->in_SSL = 1; @@ -1122,20 +1119,20 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char if (session_node_val_type == PLIST_STRING && session_id) { // we need to store the session ID for StopSession strcpy(client->session_id, session_id); - log_dbg_msg(DBGMASK_LOCKDOWND, "SessionID: %s\n", client->session_id); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id); } if (session_id) free(session_id); } } else - log_dbg_msg(DBGMASK_LOCKDOWND, "Failed to get SessionID!\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Failed to get SessionID!\n", __func__); plist_free(dict); dict = NULL; if (ret == IPHONE_E_SUCCESS) return ret; - log_dbg_msg(DBGMASK_LOCKDOWND, "Apparently failed negotiating with lockdownd.\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Apparently failed negotiating with lockdownd.\n", __func__); return IPHONE_E_SSL_ERROR; } @@ -1152,12 +1149,10 @@ ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size uint32_t bytes = 0; lockdownd_client_t client; client = (lockdownd_client_t) transport; - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_secuwrite() called\n"); - log_dbg_msg(DBGMASK_LOCKDOWND, "pre-send\nlength = %zi\n", length); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pre-send length = %zi\n", __func__, length); usbmuxd_send(client->sfd, buffer, length, &bytes); - log_dbg_msg(DBGMASK_LOCKDOWND, "post-send\nsent %i bytes\n", bytes); - - dump_debug_buffer("sslpacketwrite.out", buffer, length); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: post-send sent %i bytes\n", __func__, bytes); return bytes; } @@ -1179,9 +1174,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ client = (lockdownd_client_t) transport; char *recv_buffer; - log_debug_msg("lockdownd_securead() called\nlength = %zi\n", length); - - log_debug_msg("pre-read\nclient wants %zi bytes\n", length); + log_debug_msg("%s: pre-read client wants %zi bytes\n", __func__, length); recv_buffer = (char *) malloc(sizeof(char) * this_len); @@ -1191,7 +1184,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res); return res; } - log_debug_msg("post-read\nwe got %i bytes\n", bytes); + log_debug_msg("%s: post-read we got %i bytes\n", __func__, bytes); // increase read count tbytes += bytes; @@ -1205,7 +1198,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ } this_len = length - tbytes; - log_debug_msg("re-read\ntrying to read missing %i bytes\n", this_len); + log_debug_msg("%s: re-read trying to read missing %i bytes\n", __func__, this_len); } while (tbytes < length); if (recv_buffer) { diff --git a/src/userpref.c b/src/userpref.c index 0e83133..f7ddaeb 100644 --- a/src/userpref.c +++ b/src/userpref.c @@ -102,7 +102,7 @@ static int write_host_id(char *host_id) key_file = g_key_file_new(); /* Store in config file */ - log_debug_msg("init_config_file(): setting hostID to %s\n", host_id); + log_debug_msg("%s: setting hostID to %s\n", __func__, host_id); g_key_file_set_value(key_file, "Global", "HostID", host_id); /* Write config file on disk */ @@ -152,7 +152,7 @@ char *get_host_id(void) write_host_id(host_id); } - log_debug_msg("get_host_id(): Using %s as HostID\n", host_id); + log_debug_msg("%s: Using %s as HostID\n", __func__, host_id); return host_id; } @@ -275,7 +275,6 @@ static iphone_error_t gen_keys_and_cert(void) gnutls_x509_crt_set_expiration_time(root_cert, time(NULL) + (60 * 60 * 24 * 365 * 10)); gnutls_x509_crt_sign(root_cert, root_cert, root_privkey); - gnutls_x509_crt_set_key(host_cert, host_privkey); gnutls_x509_crt_set_serial(host_cert, "\x00", 1); gnutls_x509_crt_set_version(host_cert, 3); diff --git a/src/utils.c b/src/utils.c index 121bc55..6535a07 100644 --- a/src/utils.c +++ b/src/utils.c @@ -116,13 +116,12 @@ inline void log_debug_buffer(const char *data, const int length) inline void dump_debug_buffer(const char *file, const char *data, const int length) { #ifndef STRIP_DEBUG_CODE - /* run the real fprintf */ if (toto_debug) { FILE *my_ssl_packet = fopen(file, "w+"); fwrite(data, 1, length, my_ssl_packet); fflush(my_ssl_packet); - fprintf(stderr, "Wrote SSL packet to drive, too.\n"); + fprintf(stderr, "%s: Wrote SSL packet to drive, too.\n", __func__); fclose(my_ssl_packet); } #endif -- cgit v1.1-32-gdbae From 19a28b0ed18c8ca2f855e7d129ddcdb8c939a707 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 24 Jul 2009 23:51:53 +0200 Subject: Use iphone_device_get_uuid() not lockdown, for less overhead where possible --- dev/lckdclient.c | 13 +++++++------ dev/main.c | 14 +++++++------- include/libiphone/libiphone.h | 1 + src/iphone.c | 12 ++++++------ src/lockdown.c | 21 ++++++++++----------- swig/iphone.i | 2 +- 6 files changed, 32 insertions(+), 31 deletions(-) diff --git a/dev/lckdclient.c b/dev/lckdclient.c index 820d05f..9518a6e 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -41,17 +41,18 @@ int main(int argc, char *argv[]) return -1; } + char *uuid = NULL; + if (IPHONE_E_SUCCESS == iphone_device_get_uuid(phone, &uuid)) { + printf("DeviceUniqueID : %s\n", uuid); + } + if (uuid) + free(uuid); + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } - char *uid = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid)) { - printf("DeviceUniqueID : %s\n", uid); - free(uid); - } - using_history(); int loop = TRUE; while (loop) { diff --git a/dev/main.c b/dev/main.c index 9c8b155..46c5557 100644 --- a/dev/main.c +++ b/dev/main.c @@ -80,19 +80,19 @@ int main(int argc, char *argv[]) return -1; } + char *uuid = NULL; + if (IPHONE_E_SUCCESS == iphone_device_get_uuid(phone, &uuid)) { + printf("DeviceUniqueID : %s\n", uuid); + } + if (uuid) + free(uuid); + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); printf("Exiting.\n"); return -1; } - char *uid = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid)) { - printf("DeviceUniqueID : %s\n", uid); - free(uid); - } - - char *nnn = NULL; if (IPHONE_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { printf("DeviceName : %s\n", nnn); diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index b8c1c59..9764a7e 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -71,6 +71,7 @@ iphone_error_t iphone_get_device(iphone_device_t *device); iphone_error_t iphone_get_device_by_uuid(iphone_device_t *device, const char *uuid); iphone_error_t iphone_free_device(iphone_device_t device); uint32_t iphone_get_device_handle(iphone_device_t device); +iphone_error_t iphone_device_get_uuid(iphone_device_t device, char **uuid); #ifdef __cplusplus } diff --git a/src/iphone.c b/src/iphone.c index 0e179e7..93d7b5d 100644 --- a/src/iphone.c +++ b/src/iphone.c @@ -104,13 +104,13 @@ uint32_t iphone_get_device_handle(iphone_device_t device) } } -char* iphone_get_uuid(iphone_device_t device) +iphone_error_t iphone_device_get_uuid(iphone_device_t device, char **uuid) { - if (device) { - return device->serial_number; - } else { - return NULL; - } + if (!device) + return IPHONE_E_INVALID_ARG; + + *uuid = strdup(device->serial_number); + return IPHONE_E_SUCCESS; } /** Cleans up an iPhone structure, then frees the structure itself. diff --git a/src/lockdown.c b/src/lockdown.c index bfb44d0..3d2b04c 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -673,24 +673,24 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * ret = IPHONE_E_NOT_ENOUGH_DATA; } - char *uid = NULL; - ret = lockdownd_get_device_uid(client_loc, &uid); + char *uuid = NULL; + ret = iphone_device_get_uuid(device, &uuid); if (IPHONE_E_SUCCESS != ret) { log_debug_msg("%s: failed to get device uuid.\n", __func__); } - log_debug_msg("%s: device uuid: %s\n", __func__, uid); + log_debug_msg("%s: device uuid: %s\n", __func__, uuid); host_id = get_host_id(); if (IPHONE_E_SUCCESS == ret && !host_id) { ret = IPHONE_E_INVALID_CONF; } - if (IPHONE_E_SUCCESS == ret && !is_device_known(uid)) - ret = lockdownd_pair(client_loc, uid, host_id); + if (IPHONE_E_SUCCESS == ret && !is_device_known(uuid)) + ret = lockdownd_pair(client_loc, uuid, host_id); - if (uid) { - free(uid); - uid = NULL; + if (uuid) { + free(uuid); + uuid = NULL; } if (IPHONE_E_SUCCESS == ret) { @@ -779,9 +779,8 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i /* store public key in config if pairing succeeded */ if (ret == IPHONE_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); - store_device_public_key(uid, public_key); - ret = IPHONE_E_SUCCESS; + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); + store_device_public_key(uuid, public_key); } else { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); ret = IPHONE_E_PAIRING_FAILED; diff --git a/swig/iphone.i b/swig/iphone.i index 59be4ef..64a8727 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -135,7 +135,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { %newobject get_uuid; char* get_uuid(){ char* uuid = NULL; - uuid = (char *)iphone_get_uuid($self->dev); + uuid = (char *)iphone_device_get_uuid($self->dev); return uuid; } -- cgit v1.1-32-gdbae From c3d9e80985ef52eebb25bb07512cabc52786c130 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 00:19:47 +0200 Subject: Define remaining unknown AFC operations; SUCCESS is actually a DATA operation --- src/AFC.c | 43 ++++++++++++++++++++++--------------------- src/AFC.h | 57 +++++++++++++++++++++++++++++---------------------------- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/AFC.c b/src/AFC.c index 8cc88f1..1151f23 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -341,7 +341,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) && header.entire_length == sizeof(AFCPacket)) { log_debug_msg("%s: Empty AFCPacket received!\n", __func__); *dump_here = NULL; - if (header.operation == AFC_SUCCESS_RESPONSE) { + if (header.operation == AFC_OP_DATA) { return 0; } else { client->afcerror = EIO; @@ -396,13 +396,13 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) } // check for errors - if (header.operation == AFC_SUCCESS_RESPONSE) { + if (header.operation == AFC_OP_DATA) { // we got a positive response! log_debug_msg("%s: got a success response\n", __func__); - } else if (header.operation == AFC_FILE_HANDLE) { + } else if (header.operation == AFC_OP_FILE_OPEN_RES) { // we got a file handle response log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); - } else if (header.operation == AFC_ERROR) { + } else if (header.operation == AFC_OP_STATUS) { // error message received if (param1 == 0) { // ERROR_SUCCESS, this is not an error! @@ -418,7 +418,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) return -1; } } else { - // unknown operation code received! + /* unknown operation code received */ free(*dump_here); *dump_here = NULL; @@ -481,7 +481,7 @@ iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***li afc_lock(client); // Send the command - client->afc_packet->operation = AFC_LIST_DIR; + client->afc_packet->operation = AFC_OP_READ_DIR; client->afc_packet->entire_length = 0; client->afc_packet->this_length = 0; bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1); @@ -526,7 +526,7 @@ iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos) afc_lock(client); // Send the command - client->afc_packet->operation = AFC_GET_DEVINFO; + client->afc_packet->operation = AFC_OP_GET_DEVINFO; client->afc_packet->entire_length = client->afc_packet->this_length = 0; bytes = dispatch_AFC_packet(client, NULL, 0); if (bytes < 0) { @@ -545,6 +545,7 @@ iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos) free(data); afc_unlock(client); + *infos = list; return IPHONE_E_SUCCESS; } @@ -569,7 +570,7 @@ iphone_error_t afc_delete_file(afc_client_t client, const char *path) // Send command client->afc_packet->this_length = client->afc_packet->entire_length = 0; - client->afc_packet->operation = AFC_DELETE; + client->afc_packet->operation = AFC_OP_REMOVE_PATH; bytes = dispatch_AFC_packet(client, path, strlen(path)+1); if (bytes <= 0) { afc_unlock(client); @@ -612,7 +613,7 @@ iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char memcpy(send, from, strlen(from) + 1); memcpy(send + strlen(from) + 1, to, strlen(to) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; - client->afc_packet->operation = AFC_RENAME; + client->afc_packet->operation = AFC_OP_RENAME_PATH; bytes = dispatch_AFC_packet(client, send, strlen(to)+1 + strlen(from)+1); free(send); if (bytes <= 0) { @@ -652,7 +653,7 @@ iphone_error_t afc_mkdir(afc_client_t client, const char *dir) afc_lock(client); // Send command - client->afc_packet->operation = AFC_MAKE_DIR; + client->afc_packet->operation = AFC_OP_MAKE_DIR; client->afc_packet->this_length = client->afc_packet->entire_length = 0; bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1); if (bytes <= 0) { @@ -695,7 +696,7 @@ iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char *** afc_lock(client); // Send command - client->afc_packet->operation = AFC_GET_INFO; + client->afc_packet->operation = AFC_OP_GET_FILE_INFO; client->afc_packet->entire_length = client->afc_packet->this_length = 0; dispatch_AFC_packet(client, path, strlen(path)+1); @@ -747,7 +748,7 @@ afc_open_file(afc_client_t client, const char *filename, memcpy(data + 4, &ag, 4); memcpy(data + 8, filename, strlen(filename)); data[8 + strlen(filename)] = '\0'; - client->afc_packet->operation = AFC_FILE_OPEN; + client->afc_packet->operation = AFC_OP_FILE_OPEN; client->afc_packet->entire_length = client->afc_packet->this_length = 0; bytes = dispatch_AFC_packet(client, data, 8 + strlen(filename) + 1); free(data); @@ -808,7 +809,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); packet->filehandle = handle; packet->size = ((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE; - client->afc_packet->operation = AFC_READ; + client->afc_packet->operation = AFC_OP_READ; client->afc_packet->entire_length = client->afc_packet->this_length = 0; bytes_loc = dispatch_AFC_packet(client, (char *) packet, sizeof(AFCFilePacket)); free(packet); @@ -880,7 +881,7 @@ afc_write_file(afc_client_t client, uint64_t handle, // Send the segment client->afc_packet->this_length = sizeof(AFCPacket) + 8; client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; - client->afc_packet->operation = AFC_WRITE; + client->afc_packet->operation = AFC_OP_WRITE; out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); memcpy(out_buffer, (char *)&handle, sizeof(uint64_t)); memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); @@ -914,7 +915,7 @@ afc_write_file(afc_client_t client, uint64_t handle, client->afc_packet->this_length = sizeof(AFCPacket) + 8; client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count); - client->afc_packet->operation = AFC_WRITE; + client->afc_packet->operation = AFC_OP_WRITE; out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); memcpy(out_buffer, (char *) &handle, sizeof(uint64_t)); memcpy(out_buffer + 8, data + current_count, (length - current_count)); @@ -960,7 +961,7 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) // Send command memcpy(buffer, &handle, sizeof(uint64_t)); - client->afc_packet->operation = AFC_FILE_CLOSE; + client->afc_packet->operation = AFC_OP_FILE_CLOSE; client->afc_packet->entire_length = client->afc_packet->this_length = 0; bytes = dispatch_AFC_packet(client, buffer, 8); free(buffer); @@ -1007,7 +1008,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t memcpy(buffer, &handle, sizeof(uint64_t)); memcpy(buffer + 8, &op, 8); - client->afc_packet->operation = AFC_FILE_LOCK; + client->afc_packet->operation = AFC_OP_FILE_LOCK; client->afc_packet->entire_length = client->afc_packet->this_length = 0; bytes = dispatch_AFC_packet(client, buffer, 16); free(buffer); @@ -1053,7 +1054,7 @@ iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offse memcpy(buffer + 8, &whence, sizeof(int32_t)); // fromwhere memcpy(buffer + 12, &zero, sizeof(uint32_t)); // pad memcpy(buffer + 16, &offset, sizeof(uint64_t)); // offset - client->afc_packet->operation = AFC_FILE_SEEK; + client->afc_packet->operation = AFC_OP_FILE_SEEK; client->afc_packet->this_length = client->afc_packet->entire_length = 0; bytes = dispatch_AFC_packet(client, buffer, 24); free(buffer); @@ -1097,7 +1098,7 @@ iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t // Send command memcpy(buffer, &handle, sizeof(uint64_t)); // handle memcpy(buffer + 8, &newsize, sizeof(uint64_t)); // newsize - client->afc_packet->operation = AFC_FILE_TRUNCATE; + client->afc_packet->operation = AFC_OP_FILE_SET_SIZE; client->afc_packet->this_length = client->afc_packet->entire_length = 0; bytes = dispatch_AFC_packet(client, buffer, 16); free(buffer); @@ -1145,7 +1146,7 @@ iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize memcpy(send, &size_requested, 8); memcpy(send + 8, path, strlen(path) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; - client->afc_packet->operation = AFC_TRUNCATE; + client->afc_packet->operation = AFC_OP_TRUNCATE; bytes = dispatch_AFC_packet(client, send, 8 + strlen(path) + 1); free(send); if (bytes <= 0) { @@ -1196,7 +1197,7 @@ iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, cons memcpy(send + 8, target, strlen(target) + 1); memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; - client->afc_packet->operation = AFC_MAKE_LINK; + client->afc_packet->operation = AFC_OP_MAKE_LINK; bytes = dispatch_AFC_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1); free(send); if (bytes <= 0) { diff --git a/src/AFC.h b/src/AFC.h index 5d337e5..a0ce0ef 100644 --- a/src/AFC.h +++ b/src/AFC.h @@ -52,35 +52,36 @@ struct afc_client_int { GMutex *mutex; }; +/* AFC Operations */ enum { - AFC_ERROR = 0x00000001, - AFC_SUCCESS_RESPONSE = 0x00000002, - AFC_LIST_DIR = 0x00000003, // ReadDir - // 0x00000004 // ReadFile - // 0x00000005 // WriteFile - // 0x00000006 // WritePart - AFC_TRUNCATE = 0x00000007, // Truncate - AFC_DELETE = 0x00000008, // RemovePath - AFC_MAKE_DIR = 0x00000009, // MakeDir - AFC_GET_INFO = 0x0000000a, // GetFileInfo - AFC_GET_DEVINFO = 0x0000000b, // GetDeviceInfo - // 0x0000000c // same as 5, but writes to temp file, then renames it. - AFC_FILE_OPEN = 0x0000000d, // FileRefOpen - AFC_FILE_HANDLE = 0x0000000e, // _unknownPacket - AFC_READ = 0x0000000f, // FileRefRead - AFC_WRITE = 0x00000010, // FileRefWrite - AFC_FILE_SEEK = 0x00000011, // FileRefSeek - AFC_FILE_TELL = 0x00000012, // FileRefTell - // 0x00000013 // _unknownPacket - AFC_FILE_CLOSE = 0x00000014, // FileRefClose - AFC_FILE_TRUNCATE = 0x00000015, // FileRefSetFileSize (ftruncate) - // 0x00000016 // SetFatalError - // 0x00000017 // SetConnectionOptions - AFC_RENAME = 0x00000018, // RenamePath - // 0x00000019 // SetFSBlockSize (0x800000) - // 0x0000001A // SetBlockSize (0x800000) - AFC_FILE_LOCK = 0x0000001B, // FileRefLock - AFC_MAKE_LINK = 0x0000001C // MakeLink + AFC_OP_STATUS = 0x00000001, // Status + AFC_OP_DATA = 0x00000002, // Data + AFC_OP_READ_DIR = 0x00000003, // ReadDir + AFC_OP_READ_FILE = 0x00000004, // ReadFile + AFC_OP_WRITE_FILE = 0x00000005, // WriteFile + AFC_OP_WRITE_PART = 0x00000006, // WritePart + AFC_OP_TRUNCATE = 0x00000007, // TruncateFile + AFC_OP_REMOVE_PATH = 0x00000008, // RemovePath + AFC_OP_MAKE_DIR = 0x00000009, // MakeDir + AFC_OP_GET_FILE_INFO = 0x0000000a, // GetFileInfo + AFC_OP_GET_DEVINFO = 0x0000000b, // GetDeviceInfo + AFC_OP_WRITE_FILE_ATOM = 0x0000000c, // WriteFileAtomic (tmp file+rename) + AFC_OP_FILE_OPEN = 0x0000000d, // FileRefOpen + AFC_OP_FILE_OPEN_RES = 0x0000000e, // FileRefOpenResult + AFC_OP_READ = 0x0000000f, // FileRefRead + AFC_OP_WRITE = 0x00000010, // FileRefWrite + AFC_OP_FILE_SEEK = 0x00000011, // FileRefSeek + AFC_OP_FILE_TELL = 0x00000012, // FileRefTell + AFC_OP_FILE_TELL_RES = 0x00000013, // FileRefTellResult + AFC_OP_FILE_CLOSE = 0x00000014, // FileRefClose + AFC_OP_FILE_SET_SIZE = 0x00000015, // FileRefSetFileSize (ftruncate) + AFC_OP_GET_CON_INFO = 0x00000016, // GetConnectionInfo + AFC_OP_SET_CON_OPTIONS = 0x00000017, // SetConnectionOptions + AFC_OP_RENAME_PATH = 0x00000018, // RenamePath + AFC_OP_SET_FS_BS = 0x00000019, // SetFSBlockSize (0x800000) + AFC_OP_SET_SOCKET_BS = 0x0000001A, // SetSocketBlockSize (0x800000) + AFC_OP_FILE_LOCK = 0x0000001B, // FileRefLock + AFC_OP_MAKE_LINK = 0x0000001C // MakeLink }; static int afcerror_to_errno(int afcerror); -- cgit v1.1-32-gdbae From e2372b2f7f8f9017c9f90a7ed4d01997fb9ba464 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 01:02:11 +0200 Subject: Fix Python bindings build due to signature change of iphone_device_get_uuid() --- swig/iphone.i | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/swig/iphone.i b/swig/iphone.i index 64a8727..3c208ef 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -59,7 +59,7 @@ typedef struct { void my_delete_iPhone(iPhone* dev) { if (dev) { - iphone_free_device ( dev->dev ); + iphone_device_free(dev->dev); free(dev); } } @@ -69,7 +69,7 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) { Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); client->dev = phone; client->client = NULL; - if (IPHONE_E_SUCCESS == lockdownd_new_client ( phone->dev , &(client->client))) { + if (LOCKDOWN_E_SUCCESS == lockdownd_client_new(phone->dev , &(client->client))) { return client; } else { @@ -80,7 +80,7 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) { void my_delete_Lockdownd(Lockdownd* lckd) { if (lckd) { - lockdownd_free_client ( lckd->client ); + lockdownd_client_free(lckd->client); free(lckd); } } @@ -89,11 +89,11 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { if (!lckd || !lckd->dev) return NULL; MobileSync* client = NULL; int port = 0; - if (IPHONE_E_SUCCESS == lockdownd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { + if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(lckd->client, "com.apple.mobilesync", &port)) { client = (MobileSync*) malloc(sizeof(MobileSync)); client->dev = lckd->dev; client->client = NULL; - mobilesync_new_client ( lckd->dev->dev, port, &(client->client)); + mobilesync_client_new(lckd->dev->dev, port, &(client->client)); } return client; } @@ -121,13 +121,13 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { } int init_device_by_uuid(char* uuid) { - if (IPHONE_E_SUCCESS == iphone_get_device_by_uuid ( &($self->dev), uuid)) + if (IPHONE_E_SUCCESS == iphone_get_device_by_uuid(&($self->dev), uuid)) return 1; return 0; } int init_device() { - if (IPHONE_E_SUCCESS == iphone_get_device ( &($self->dev))) + if (IPHONE_E_SUCCESS == iphone_get_device(&($self->dev))) return 1; return 0; } @@ -135,7 +135,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { %newobject get_uuid; char* get_uuid(){ char* uuid = NULL; - uuid = (char *)iphone_device_get_uuid($self->dev); + iphone_device_get_uuid($self->dev, &uuid); return uuid; } @@ -176,7 +176,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { } ~MobileSync() { - mobilesync_free_client ( $self->client ); + mobilesync_client_free($self->client); free($self); } -- cgit v1.1-32-gdbae From 028646335acca403cc8a601d77c2272e077445e0 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 01:08:41 +0200 Subject: Fix includes of utils --- src/utils.c | 3 +++ src/utils.h | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils.c b/src/utils.c index 6535a07..3c08351 100644 --- a/src/utils.c +++ b/src/utils.c @@ -20,7 +20,10 @@ */ #include #include +#include + #include "utils.h" +#include "libiphone/libiphone.h" int toto_debug = 0; uint16_t dbg_mask = 0; diff --git a/src/utils.h b/src/utils.h index 1750b8e..430e812 100644 --- a/src/utils.h +++ b/src/utils.h @@ -22,13 +22,10 @@ #ifndef UTILS_H #define UTILS_H -#include "libiphone/libiphone.h" - - - inline void log_debug_msg(const char *format, ...); inline void log_dbg_msg(uint16_t id, const char *format, ...); inline void log_debug_buffer(const char *data, const int length); inline void dump_debug_buffer(const char *file, const char *data, const int length); + #endif -- cgit v1.1-32-gdbae From 66695e6b7db9457d5ecfe6f4f6624dc195e5274d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 01:39:35 +0200 Subject: Improve API of userpref system --- src/lockdown.c | 58 ++++++++++++++------- src/userpref.c | 161 +++++++++++++++++++++++++++++---------------------------- src/userpref.h | 22 ++++---- 3 files changed, 131 insertions(+), 110 deletions(-) diff --git a/src/lockdown.c b/src/lockdown.c index 3d2b04c..757a94a 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -19,10 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "utils.h" -#include "iphone.h" -#include "lockdown.h" -#include "userpref.h" #include #include #include @@ -30,9 +26,13 @@ #include #include #include - #include +#include "lockdown.h" +#include "iphone.h" +#include "utils.h" +#include "userpref.h" + #define RESULT_SUCCESS 0 #define RESULT_FAILURE 1 @@ -680,12 +680,12 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * } log_debug_msg("%s: device uuid: %s\n", __func__, uuid); - host_id = get_host_id(); + userpref_get_host_id(&host_id); if (IPHONE_E_SUCCESS == ret && !host_id) { ret = IPHONE_E_INVALID_CONF; } - if (IPHONE_E_SUCCESS == ret && !is_device_known(uuid)) + if (IPHONE_E_SUCCESS == ret && !userpref_has_device_public_key(uuid)) ret = lockdownd_pair(client_loc, uuid, host_id); if (uuid) { @@ -780,7 +780,7 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i /* store public key in config if pairing succeeded */ if (ret == IPHONE_E_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); - store_device_public_key(uuid, public_key); + userpref_set_device_public_key(uuid, public_key); } else { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); ret = IPHONE_E_PAIRING_FAILED; @@ -875,6 +875,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t if (!public_key.data || !odevice_cert || !ohost_cert || !oroot_cert) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + userpref_error_t uret = USERPREF_E_UNKNOWN_ERROR; gnutls_datum_t modulus = { NULL, 0 }; gnutls_datum_t exponent = { NULL, 0 }; @@ -932,10 +933,9 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t gnutls_x509_privkey_init(&root_privkey); gnutls_x509_privkey_init(&host_privkey); - ret = get_keys_and_certs(root_privkey, root_cert, host_privkey, host_cert); - - if (IPHONE_E_SUCCESS == ret) { + uret = userpref_get_keys_and_certs(root_privkey, root_cert, host_privkey, host_cert); + if (USERPREF_E_SUCCESS == uret) { /* generate device certificate */ gnutls_x509_crt_set_key(dev_cert, fake_privkey); gnutls_x509_crt_set_serial(dev_cert, "\x00", 1); @@ -955,7 +955,9 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t gnutls_datum_t pem_root_cert = { NULL, 0 }; gnutls_datum_t pem_host_cert = { NULL, 0 }; - if ( IPHONE_E_SUCCESS == get_certs_as_pem(&pem_root_cert, &pem_host_cert) ) { + uret = userpref_get_certs_as_pem(&pem_root_cert, &pem_host_cert); + + if (USERPREF_E_SUCCESS == uret) { /* copy buffer for output */ odevice_cert->data = malloc(dev_pem.size); memcpy(odevice_cert->data, dev_pem.data, dev_pem.size); @@ -974,6 +976,19 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t } } } + + switch(uret) { + case USERPREF_E_INVALID_ARG: + ret = IPHONE_E_INVALID_ARG; + break; + case USERPREF_E_INVALID_CONF: + ret = IPHONE_E_INVALID_CONF; + break; + case USERPREF_E_SSL_ERROR: + ret = IPHONE_E_SSL_ERROR; + default: + break; + } } } @@ -1026,12 +1041,14 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char plist_get_string_val(error_node, &error); if (!strcmp(error, "InvalidHostID")) { - //hostid is unknown. Pair and try again - char *uid = NULL; - char* host_id = get_host_id(); - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid) ) { - if (IPHONE_E_SUCCESS == lockdownd_pair(client, uid, host_id) ) { - //start session again + /* hostid is unknown. Pair and try again */ + char *uuid = NULL; + char *host_id = NULL; + userpref_get_host_id(&host_id); + + if (IPHONE_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) { + if (IPHONE_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) { + /* start session again */ plist_free(dict); dict = plist_new_dict(); plist_add_sub_key_el(dict, "HostID"); @@ -1046,7 +1063,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char ret = lockdownd_recv(client, &dict); } } - free(uid); + free(uuid); free(host_id); } free(error); @@ -1220,7 +1237,8 @@ iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *se if (!client || !service || !port) return IPHONE_E_INVALID_ARG; - char *host_id = get_host_id(); + char *host_id = NULL; + userpref_get_host_id(&host_id); if (!host_id) return IPHONE_E_INVALID_CONF; if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id)) diff --git a/src/userpref.c b/src/userpref.c index f7ddaeb..4b6dd98 100644 --- a/src/userpref.c +++ b/src/userpref.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -42,7 +43,7 @@ /** Creates a freedesktop compatible configuration directory for libiphone. */ -static void create_config_dir(void) +static void userpref_create_config_dir(void) { gchar *config_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, NULL); @@ -62,9 +63,10 @@ static int get_rand(int min, int max) * * @return A null terminated string containing a valid HostID. */ -static char *lockdownd_generate_hostid() +static char *userpref_generate_host_id() { - char *hostid = (char *) malloc(sizeof(char) * 37); // HostID's are just UUID's, and UUID's are 36 characters long + /* HostID's are just UUID's, and UUID's are 36 characters long */ + char *hostid = (char *) malloc(sizeof(char) * 37); const char *chars = "ABCDEF0123456789"; srand(time(NULL)); int i = 0; @@ -77,7 +79,8 @@ static char *lockdownd_generate_hostid() hostid[i] = chars[get_rand(0, 16)]; } } - hostid[36] = '\0'; // make it a real string + /* make it a real string */ + hostid[36] = '\0'; return hostid; } @@ -85,7 +88,7 @@ static char *lockdownd_generate_hostid() * * @param host_id A null terminated string containing a valid HostID. */ -static int write_host_id(char *host_id) +static int userpref_set_host_id(char *host_id) { GKeyFile *key_file; gsize length; @@ -96,7 +99,7 @@ static int write_host_id(char *host_id) return 0; /* Make sure config directory exists */ - create_config_dir(); + userpref_create_config_dir(); /* Now parse file to get the HostID */ key_file = g_key_file_new(); @@ -125,9 +128,8 @@ static int write_host_id(char *host_id) * * @return The string containing the HostID or NULL */ -char *get_host_id(void) +void userpref_get_host_id(char **host_id) { - char *host_id = NULL; gchar *config_file; GKeyFile *key_file; gchar *loc_host_id; @@ -140,20 +142,19 @@ char *get_host_id(void) if (g_key_file_load_from_file(key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, NULL)) { loc_host_id = g_key_file_get_value(key_file, "Global", "HostID", NULL); if (loc_host_id) - host_id = strdup((char *) loc_host_id); + *host_id = strdup((char *) loc_host_id); g_free(loc_host_id); } g_key_file_free(key_file); g_free(config_file); if (!host_id) { - //no config, generate host_id - host_id = lockdownd_generate_hostid(); - write_host_id(host_id); + /* no config, generate host_id */ + *host_id = userpref_generate_host_id(); + userpref_set_host_id(*host_id); } - log_debug_msg("%s: Using %s as HostID\n", __func__, host_id); - return host_id; + log_debug_msg("%s: Using %s as HostID\n", __func__, *host_id); } /** Determines whether this iPhone has been connected to this system before. @@ -163,13 +164,13 @@ char *get_host_id(void) * @return 1 if the iPhone has been connected previously to this configuration * or 0 otherwise. */ -int is_device_known(char *uid) +int userpref_has_device_public_key(char *uuid) { int ret = 0; gchar *config_file; /* first get config file */ - gchar *device_file = g_strconcat(uid, ".pem", NULL); + gchar *device_file = g_strconcat(uuid, ".pem", NULL); config_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); if (g_file_test(config_file, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) ret = 1; @@ -186,17 +187,19 @@ int is_device_known(char *uid) * @return 1 on success and 0 if no public key is given or if it has already * been marked as connected previously. */ -int store_device_public_key(char *uid, gnutls_datum_t public_key) +userpref_error_t userpref_set_device_public_key(char *uuid, gnutls_datum_t public_key) { - - if (NULL == public_key.data || is_device_known(uid)) - return 0; + if (NULL == public_key.data) + return USERPREF_E_INVALID_ARG; + + if (userpref_has_device_public_key(uuid)) + return USERPREF_E_SUCCESS; /* ensure config directory exists */ - create_config_dir(); + userpref_create_config_dir(); /* build file path */ - gchar *device_file = g_strconcat(uid, ".pem", NULL); + gchar *device_file = g_strconcat(uuid, ".pem", NULL); gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, device_file, NULL); /* store file */ @@ -205,7 +208,8 @@ int store_device_public_key(char *uid, gnutls_datum_t public_key) fclose(pFile); g_free(pem); g_free(device_file); - return 1; + + return USERPREF_E_SUCCESS; } /** Private function which reads the given file into a gnutls structure. @@ -215,7 +219,7 @@ int store_device_public_key(char *uid, gnutls_datum_t public_key) * * @return 1 if the file contents where read successfully and 0 otherwise. */ -static int read_file_in_confdir(const char *file, gnutls_datum_t * data) +static int userpref_get_file_contents(const char *file, gnutls_datum_t * data) { gboolean success; gsize size; @@ -237,17 +241,17 @@ static int read_file_in_confdir(const char *file, gnutls_datum_t * data) return success; } - /** Private function which generate private keys and certificates. * - * @return IPHONE_E_SUCCESS if keys were successfully generated. + * @return 1 if keys were successfully generated, 0 otherwise */ -static iphone_error_t gen_keys_and_cert(void) +static userpref_error_t userpref_gen_keys_and_cert(void) { - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + userpref_error_t ret = USERPREF_E_SSL_ERROR; + gnutls_x509_privkey_t root_privkey; - gnutls_x509_privkey_t host_privkey; gnutls_x509_crt_t root_cert; + gnutls_x509_privkey_t host_privkey; gnutls_x509_crt_t host_cert; gnutls_global_deinit(); @@ -311,14 +315,14 @@ static iphone_error_t gen_keys_and_cert(void) if (NULL != root_cert_pem.data && 0 != root_cert_pem.size && NULL != host_cert_pem.data && 0 != host_cert_pem.size) - ret = IPHONE_E_SUCCESS; + ret = USERPREF_E_SUCCESS; /* store values in config file */ - init_config_file( &root_key_pem, &host_key_pem, &root_cert_pem, &host_cert_pem); + userpref_set_keys_and_certs( &root_key_pem, &root_cert_pem, &host_key_pem, &host_cert_pem); gnutls_free(root_key_pem.data); - gnutls_free(host_key_pem.data); gnutls_free(root_cert_pem.data); + gnutls_free(host_key_pem.data); gnutls_free(host_cert_pem.data); //restore gnutls env @@ -333,18 +337,18 @@ static iphone_error_t gen_keys_and_cert(void) * @param key_name The filename of the private key to import. * @param key the gnutls key structure. * - * @return IPHONE_E_SUCCESS if the key was successfully imported. + * @return 1 if the key was successfully imported. */ -static iphone_error_t import_key(const char* key_name, gnutls_x509_privkey_t key) +static userpref_error_t userpref_import_key(const char* key_name, gnutls_x509_privkey_t key) { - iphone_error_t ret = IPHONE_E_INVALID_CONF; + userpref_error_t ret = USERPREF_E_INVALID_CONF; gnutls_datum_t pem_key = { NULL, 0 }; - if ( read_file_in_confdir(key_name, &pem_key) ) { + if (userpref_get_file_contents(key_name, &pem_key)) { if (GNUTLS_E_SUCCESS == gnutls_x509_privkey_import(key, &pem_key, GNUTLS_X509_FMT_PEM)) - ret = IPHONE_E_SUCCESS; + ret = USERPREF_E_SUCCESS; else - ret = IPHONE_E_SSL_ERROR; + ret = USERPREF_E_SSL_ERROR; } gnutls_free(pem_key.data); return ret; @@ -357,16 +361,16 @@ static iphone_error_t import_key(const char* key_name, gnutls_x509_privkey_t key * * @return IPHONE_E_SUCCESS if the certificate was successfully imported. */ -static iphone_error_t import_crt(const char* crt_name, gnutls_x509_crt_t cert) +static userpref_error_t userpref_import_crt(const char* crt_name, gnutls_x509_crt_t cert) { - iphone_error_t ret = IPHONE_E_INVALID_CONF; + userpref_error_t ret = USERPREF_E_INVALID_CONF; gnutls_datum_t pem_cert = { NULL, 0 }; - if ( read_file_in_confdir(crt_name, &pem_cert) ) { + if (userpref_get_file_contents(crt_name, &pem_cert)) { if (GNUTLS_E_SUCCESS == gnutls_x509_crt_import(cert, &pem_cert, GNUTLS_X509_FMT_PEM)) - ret = IPHONE_E_SUCCESS; + ret = USERPREF_E_SUCCESS; else - ret = IPHONE_E_SSL_ERROR; + ret = USERPREF_E_SSL_ERROR; } gnutls_free(pem_cert.data); return ret; @@ -382,41 +386,41 @@ static iphone_error_t import_crt(const char* crt_name, gnutls_x509_crt_t cert) * @param host_privkey The host private key. * @param host_crt The host certificate. * - * @return IPHONE_E_SUCCESS if the keys and certificates were successfully retrieved. + * @return 1 if the keys and certificates were successfully retrieved, 0 otherwise */ -iphone_error_t get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt) +userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt) { - iphone_error_t ret = IPHONE_E_SUCCESS; + userpref_error_t ret = USERPREF_E_SUCCESS; - if (ret == IPHONE_E_SUCCESS) - ret = import_key(LIBIPHONE_ROOT_PRIVKEY, root_privkey); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_key(LIBIPHONE_ROOT_PRIVKEY, root_privkey); - if (ret == IPHONE_E_SUCCESS) - ret = import_key(LIBIPHONE_HOST_PRIVKEY, host_privkey); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_key(LIBIPHONE_HOST_PRIVKEY, host_privkey); - if (ret == IPHONE_E_SUCCESS) - ret = import_crt(LIBIPHONE_ROOT_CERTIF, root_crt); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_crt(LIBIPHONE_ROOT_CERTIF, root_crt); - if (ret == IPHONE_E_SUCCESS) - ret = import_crt(LIBIPHONE_HOST_CERTIF, host_crt); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_crt(LIBIPHONE_HOST_CERTIF, host_crt); - if (IPHONE_E_SUCCESS != ret) { + if (USERPREF_E_SUCCESS != ret) { //we had problem reading or importing root cert //try with a new ones. - ret = gen_keys_and_cert(); + ret = userpref_gen_keys_and_cert(); - if (ret == IPHONE_E_SUCCESS) - ret = import_key(LIBIPHONE_ROOT_PRIVKEY, root_privkey); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_key(LIBIPHONE_ROOT_PRIVKEY, root_privkey); - if (ret == IPHONE_E_SUCCESS) - ret = import_key(LIBIPHONE_HOST_PRIVKEY, host_privkey); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_key(LIBIPHONE_HOST_PRIVKEY, host_privkey); - if (ret == IPHONE_E_SUCCESS) - ret = import_crt(LIBIPHONE_ROOT_CERTIF, root_crt); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_crt(LIBIPHONE_ROOT_CERTIF, root_crt); - if (ret == IPHONE_E_SUCCESS) - ret = import_crt(LIBIPHONE_HOST_CERTIF, host_crt); + if (ret == USERPREF_E_SUCCESS) + ret = userpref_import_crt(LIBIPHONE_HOST_CERTIF, host_crt); } return ret; @@ -427,46 +431,43 @@ iphone_error_t get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x50 * @param pem_root_cert The root certificate. * @param pem_host_cert The host certificate. * - * @return IPHONE_E_SUCCESS if the certificates were successfully retrieved. + * @return 1 if the certificates were successfully retrieved, 0 otherwise */ -iphone_error_t get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert) +userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert) { - iphone_error_t ret = IPHONE_E_INVALID_CONF; - - if ( !pem_root_cert || !pem_host_cert) - return IPHONE_E_INVALID_ARG; + if (!pem_root_cert || !pem_host_cert) + return USERPREF_E_INVALID_ARG; - if ( read_file_in_confdir(LIBIPHONE_ROOT_CERTIF, pem_root_cert) && read_file_in_confdir(LIBIPHONE_HOST_CERTIF, pem_host_cert)) - ret = IPHONE_E_SUCCESS; + if (userpref_get_file_contents(LIBIPHONE_ROOT_CERTIF, pem_root_cert) && userpref_get_file_contents(LIBIPHONE_HOST_CERTIF, pem_host_cert)) + return USERPREF_E_SUCCESS; else { g_free(pem_root_cert->data); g_free(pem_host_cert->data); } - return ret; + return USERPREF_E_INVALID_CONF; } + /** Create and save a configuration file containing the given data. * * @note: All fields must specified and be non-null * - * @param host_id The UUID of the host * @param root_key The root key - * @param host_key The host key * @param root_cert The root certificate + * @param host_key The host key * @param host_cert The host certificate * * @return 1 on success and 0 otherwise. */ -int init_config_file( gnutls_datum_t * root_key, gnutls_datum_t * host_key, gnutls_datum_t * root_cert, - gnutls_datum_t * host_cert) +userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert) { FILE *pFile; gchar *pem; if (!root_key || !host_key || !root_cert || !host_cert) - return 0; + return USERPREF_E_INVALID_ARG; /* Make sure config directory exists */ - create_config_dir(); + userpref_create_config_dir(); /* Now write keys and certificates to disk */ pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIPHONE_CONF_DIR, LIBIPHONE_ROOT_PRIVKEY, NULL); @@ -493,5 +494,5 @@ int init_config_file( gnutls_datum_t * root_key, gnutls_datum_t * host_key, gnut fclose(pFile); g_free(pem); - return 1; + return USERPREF_E_SUCCESS; } diff --git a/src/userpref.h b/src/userpref.h index deced04..414c093 100644 --- a/src/userpref.h +++ b/src/userpref.h @@ -23,19 +23,21 @@ #define USERPREF_H #include -#include "libiphone/libiphone.h" +#define USERPREF_E_SUCCESS 0 +#define USERPREF_E_INVALID_ARG -1 +#define USERPREF_E_INVALID_CONF -2 +#define USERPREF_E_SSL_ERROR -3 -iphone_error_t get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt); +#define USERPREF_E_UNKNOWN_ERROR -256 -iphone_error_t get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert); +typedef int16_t userpref_error_t; -char *get_host_id(void); +userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt); +userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert); +userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert); +userpref_error_t userpref_set_device_public_key(char *uuid, gnutls_datum_t public_key); +int userpref_has_device_public_key(char *uuid); +void userpref_get_host_id(char **host_id); -int is_device_known(char *uid); - -int store_device_public_key(char *uid, gnutls_datum_t public_key); - -int init_config_file( gnutls_datum_t * root_key, gnutls_datum_t * host_key, gnutls_datum_t * root_cert, - gnutls_datum_t * host_cert); #endif -- cgit v1.1-32-gdbae From 40a0abaa1c7f2196d40276b0689b18a04e468acd Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 02:08:12 +0200 Subject: Update MobileSync API and introduce mobilesync error codes --- dev/msyncclient.c | 12 +++++----- include/libiphone/mobilesync.h | 20 ++++++++++++----- src/MobileSync.c | 51 +++++++++++++++++++++++------------------- src/MobileSync.h | 4 ---- 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/dev/msyncclient.c b/dev/msyncclient.c index 5eb105d..7651002 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -28,12 +28,12 @@ #include #include -static iphone_error_t mobilesync_get_all_contacts(mobilesync_client_t client) +static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client) { if (!client) - return IPHONE_E_INVALID_ARG; + return MOBILESYNC_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + mobilesync_error_t ret = MOBILESYNC_E_UNKNOWN_ERROR; plist_t array = NULL; array = plist_new_array(); @@ -124,7 +124,6 @@ static iphone_error_t mobilesync_get_all_contacts(mobilesync_client_t client) plist_free(array); array = NULL; - return ret; } @@ -137,7 +136,6 @@ int main(int argc, char *argv[]) if (argc > 1 && !strcasecmp(argv[1], "--debug")) iphone_set_debug_mask(DBGMASK_MOBILESYNC); - if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); return -1; @@ -152,10 +150,10 @@ int main(int argc, char *argv[]) if (port) { mobilesync_client_t msync = NULL; - mobilesync_new_client(phone, port, &msync); + mobilesync_client_new(phone, port, &msync); if (msync) { mobilesync_get_all_contacts(msync); - mobilesync_free_client(msync); + mobilesync_client_free(msync); } } else { printf("Start service failure.\n"); diff --git a/include/libiphone/mobilesync.h b/include/libiphone/mobilesync.h index 128be45..f8fa711 100644 --- a/include/libiphone/mobilesync.h +++ b/include/libiphone/mobilesync.h @@ -27,14 +27,24 @@ extern "C" { #include +/* Error Codes */ +#define MOBILESYNC_E_SUCCESS 0 +#define MOBILESYNC_E_INVALID_ARG -1 +#define MOBILESYNC_E_PLIST_ERROR -2 +#define MOBILESYNC_E_MUX_ERROR -3 +#define MOBILESYNC_E_BAD_VERSION -4 + +#define MOBILESYNC_E_UNKNOWN_ERROR -256 + +typedef int16_t mobilesync_error_t; + struct mobilesync_client_int; typedef struct mobilesync_client_int *mobilesync_client_t; -iphone_error_t mobilesync_new_client(iphone_device_t device, int dst_port, - mobilesync_client_t * client); -iphone_error_t mobilesync_free_client(mobilesync_client_t client); -iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t *plist); -iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist); +mobilesync_error_t mobilesync_client_new(iphone_device_t device, int dst_port, mobilesync_client_t * client); +mobilesync_error_t mobilesync_client_free(mobilesync_client_t client); +mobilesync_error_t mobilesync_recv(mobilesync_client_t client, plist_t *plist); +mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist); #ifdef __cplusplus } diff --git a/src/MobileSync.c b/src/MobileSync.c index f544400..4463251 100644 --- a/src/MobileSync.c +++ b/src/MobileSync.c @@ -19,25 +19,27 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "MobileSync.h" #include #include #include #include +#include "MobileSync.h" +#include "iphone.h" +#include "utils.h" #define MSYNC_VERSION_INT1 100 #define MSYNC_VERSION_INT2 100 -iphone_error_t mobilesync_new_client(iphone_device_t device, int dst_port, +mobilesync_error_t mobilesync_client_new(iphone_device_t device, int dst_port, mobilesync_client_t * client) { if (!device || dst_port == 0 || !client || *client) - return IPHONE_E_INVALID_ARG; + return MOBILESYNC_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + mobilesync_error_t ret = MOBILESYNC_E_UNKNOWN_ERROR; - // Attempt connection + /* Attempt connection */ int sfd = usbmuxd_connect(device->handle, dst_port); if (sfd < 0) { return ret; @@ -46,10 +48,10 @@ iphone_error_t mobilesync_new_client(iphone_device_t device, int dst_port, mobilesync_client_t client_loc = (mobilesync_client_t) malloc(sizeof(struct mobilesync_client_int)); client_loc->sfd = sfd; - //perform handshake + /* perform handshake */ plist_t array = NULL; - //first receive version + /* first receive version */ ret = mobilesync_recv(client_loc, &array); plist_t msg_node = plist_find_node_by_string(array, "DLMessageVersionExchange"); @@ -86,17 +88,20 @@ iphone_error_t mobilesync_new_client(iphone_device_t device, int dst_port, plist_t rep_node = plist_find_node_by_string(array, "DLMessageDeviceReady"); if (rep_node) { - ret = IPHONE_E_SUCCESS; + ret = MOBILESYNC_E_SUCCESS; *client = client_loc; } + else + { + ret = MOBILESYNC_E_BAD_VERSION; + } plist_free(array); array = NULL; - } } - if (IPHONE_E_SUCCESS != ret) - mobilesync_free_client(client_loc); + if (MOBILESYNC_E_SUCCESS != ret) + mobilesync_client_free(client_loc); return ret; } @@ -115,13 +120,13 @@ static void mobilesync_disconnect(mobilesync_client_t client) array = NULL; } -iphone_error_t mobilesync_free_client(mobilesync_client_t client) +mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) { if (!client) return IPHONE_E_INVALID_ARG; mobilesync_disconnect(client); - return usbmuxd_disconnect(client->sfd); + return (usbmuxd_disconnect(client->sfd) == 0 ? MOBILESYNC_E_SUCCESS: MOBILESYNC_E_MUX_ERROR); } /** Polls the iPhone for MobileSync data. @@ -131,11 +136,11 @@ iphone_error_t mobilesync_free_client(mobilesync_client_t client) * * @return an error code */ -iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist) +mobilesync_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist) { if (!client || !plist || (plist && *plist)) - return IPHONE_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + return MOBILESYNC_E_INVALID_ARG; + mobilesync_error_t ret = MOBILESYNC_E_UNKNOWN_ERROR; char *receive = NULL; uint32_t datalen = 0, bytes = 0, received_bytes = 0; @@ -145,14 +150,14 @@ iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist) receive = (char *) malloc(sizeof(char) * datalen); /* fill buffer and request more packets if needed */ - while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { + while ((received_bytes < datalen) && (ret == MOBILESYNC_E_SUCCESS)) { ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes); received_bytes += bytes; } - if (ret != IPHONE_E_SUCCESS) { + if (ret != MOBILESYNC_E_SUCCESS) { free(receive); - return ret; + return MOBILESYNC_E_MUX_ERROR; } plist_from_bin(receive, received_bytes, plist); @@ -177,10 +182,10 @@ iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist) * * @return an error code */ -iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist) +mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist) { if (!client || !plist) - return IPHONE_E_INVALID_ARG; + return MOBILESYNC_E_INVALID_ARG; char *XMLContent = NULL; uint32_t length = 0; @@ -195,7 +200,7 @@ iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist) char *real_query; int bytes; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + mobilesync_error_t ret = MOBILESYNC_E_UNKNOWN_ERROR; real_query = (char *) malloc(sizeof(char) * (length + 4)); length = htonl(length); @@ -204,6 +209,6 @@ iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist) ret = usbmuxd_send(client->sfd, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes); free(real_query); - return ret; + return (ret == 0 ? MOBILESYNC_E_SUCCESS: MOBILESYNC_E_MUX_ERROR); } diff --git a/src/MobileSync.h b/src/MobileSync.h index 5279ce0..6347399 100644 --- a/src/MobileSync.h +++ b/src/MobileSync.h @@ -21,12 +21,8 @@ #ifndef MOBILESYNC_H #define MOBILESYNC_H -#include "iphone.h" -#include "utils.h" #include "libiphone/mobilesync.h" -#include - struct mobilesync_client_int { int sfd; }; -- cgit v1.1-32-gdbae From d11abfb48218a37d9c66831ebec8b0a736d5385f Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 02:20:03 +0200 Subject: Update NotificationProxy API and introduce new error codes --- dev/main.c | 14 ++--- include/libiphone/notification_proxy.h | 34 +++++++----- src/NotificationProxy.c | 99 +++++++++++++++++----------------- 3 files changed, 77 insertions(+), 70 deletions(-) diff --git a/dev/main.c b/dev/main.c index 46c5557..33c60f9 100644 --- a/dev/main.c +++ b/dev/main.c @@ -46,11 +46,11 @@ static void perform_notification(iphone_device_t phone, lockdownd_client_t clien lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); if (nport) { printf("::::::::::::::: np was started ::::::::::::\n"); - np_new_client(phone, nport, &np); + np_client_new(phone, nport, &np); if (np) { printf("::::::::: PostNotification %s\n", notification); np_post_notification(np, notification); - np_free_client(np); + np_client_free(np); } } else { printf("::::::::::::::: np was NOT started ::::::::::::\n"); @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); if (npp) { printf("Notification Proxy started.\n"); - np_new_client(phone, npp, &gnp); + np_client_new(phone, npp, &gnp); } else { printf("ERROR: Notification proxy could not be started.\n"); } @@ -225,17 +225,19 @@ int main(int argc, char *argv[]) printf("XXX sleeping\n"); sleep(5); - //perform_notification(phone, control, NP_SYNC_DID_FINISH); - printf("XXX unlocking file\n"); afc_lock_file(afc, lockfile, AFC_LOCK_UN); printf("XXX closing file\n"); afc_close_file(afc, lockfile); + + printf("XXX sleeping\n"); + sleep(5); + //perform_notification(phone, client, NP_SYNC_DID_FINISH); } if (gnp) { - np_free_client(gnp); + np_client_free(gnp); gnp = NULL; } diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h index 14d1b39..520ccd1 100644 --- a/include/libiphone/notification_proxy.h +++ b/include/libiphone/notification_proxy.h @@ -27,16 +27,21 @@ extern "C" { #include -struct np_client_int; -typedef struct np_client_int *np_client_t; +/* Error Codes */ +#define NP_E_SUCCESS 0 +#define NP_E_INVALID_ARG -1 +#define NP_E_PLIST_ERROR -2 + +#define NP_E_UNKNOWN_ERROR -256 + +typedef int16_t np_error_t; -// NotificationProxy related -// notifications for use with post_notification (client --> device) +/* Notification IDs for use with post_notification (client --> device) */ #define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" #define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" #define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" -// notifications for use with observe_notification (device --> client) +/* Notification IDs for use with observe_notification (device --> client) */ #define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" #define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" #define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" @@ -48,17 +53,18 @@ typedef struct np_client_int *np_client_t; #define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" #define NP_ITDBPREP_DID_END "com.apple.itdbprep.notification.didEnd" -iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ); -iphone_error_t np_free_client ( np_client_t client ); - -iphone_error_t np_post_notification ( np_client_t client, const char *notification ); - -iphone_error_t np_observe_notification ( np_client_t client, const char *notification ); -iphone_error_t np_observe_notifications ( np_client_t client, const char **notification_spec ); +struct np_client_int; +typedef struct np_client_int *np_client_t; -typedef void (*np_notify_cb_t) ( const char *notification ); +typedef void (*np_notify_cb_t) (const char *notification); -iphone_error_t np_set_notify_callback ( np_client_t client, np_notify_cb_t notify_cb ); +/* Interface */ +np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *client); +np_error_t np_client_free(np_client_t client); +np_error_t np_post_notification(np_client_t client, const char *notification); +np_error_t np_observe_notification(np_client_t client, const char *notification); +np_error_t np_observe_notifications(np_client_t client, const char **notification_spec); +np_error_t np_set_notify_callback(np_client_t client, np_notify_cb_t notify_cb); #ifdef __cplusplus } diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index 1bbdc6d..7e52405 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c @@ -24,6 +24,7 @@ #include #include #include + #include "NotificationProxy.h" #include "iphone.h" #include "utils.h" @@ -60,24 +61,24 @@ static void np_unlock(np_client_t client) * @param client NP to send data to * @param dict plist to send * - * @return IPHONE_E_SUCCESS or an error code. + * @return NP_E_SUCCESS or an error code. */ -static iphone_error_t np_plist_send(np_client_t client, plist_t dict) +static np_error_t np_plist_send(np_client_t client, plist_t dict) { char *XML_content = NULL; uint32_t length = 0; uint32_t nlen = 0; int bytes = 0; - iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; + np_error_t res = NP_E_UNKNOWN_ERROR; if (!client || !dict) { - return IPHONE_E_INVALID_ARG; + return NP_E_INVALID_ARG; } plist_to_xml(dict, &XML_content, &length); if (!XML_content || length == 0) { - return IPHONE_E_PLIST_ERROR; + return NP_E_PLIST_ERROR; } nlen = htonl(length); @@ -86,7 +87,7 @@ static iphone_error_t np_plist_send(np_client_t client, plist_t dict) usbmuxd_send(client->sfd, XML_content, length, (uint32_t*)&bytes); if (bytes > 0) { if ((uint32_t)bytes == length) { - res = IPHONE_E_SUCCESS; + res = NP_E_SUCCESS; } else { log_debug_msg("%s: ERROR: Could not send all data (%d of %d)!\n", __func__, bytes, length); } @@ -109,19 +110,19 @@ static iphone_error_t np_plist_send(np_client_t client, plist_t dict) * * @return A handle to the newly-connected client or NULL upon error. */ -iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ) +np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *client) { - //makes sure thread environment is available + /* makes sure thread environment is available */ if (!g_thread_supported()) g_thread_init(NULL); if (!device) - return IPHONE_E_INVALID_ARG; + return NP_E_INVALID_ARG; - // Attempt connection + /* Attempt connection */ int sfd = usbmuxd_connect(device->handle, dst_port); if (sfd < 0) { - return IPHONE_E_UNKNOWN_ERROR; //ret; + return NP_E_UNKNOWN_ERROR; } np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); @@ -132,17 +133,17 @@ iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t client_loc->notifier = NULL; *client = client_loc; - return IPHONE_E_SUCCESS; + return NP_E_SUCCESS; } /** Disconnects an NP client from the phone. * * @param client The client to disconnect. */ -iphone_error_t np_free_client ( np_client_t client ) +np_error_t np_client_free(np_client_t client) { if (!client) - return IPHONE_E_INVALID_ARG; + return NP_E_INVALID_ARG; usbmuxd_disconnect(client->sfd); client->sfd = -1; @@ -155,7 +156,7 @@ iphone_error_t np_free_client ( np_client_t client ) } free(client); - return IPHONE_E_SUCCESS; + return NP_E_SUCCESS; } /** Sends a notification to the device's Notification Proxy. @@ -167,10 +168,10 @@ iphone_error_t np_free_client ( np_client_t client ) * @param client The client to send to * @param notification The notification message to send */ -iphone_error_t np_post_notification( np_client_t client, const char *notification ) +np_error_t np_post_notification(np_client_t client, const char *notification) { if (!client || !notification) { - return IPHONE_E_INVALID_ARG; + return NP_E_INVALID_ARG; } np_lock(client); @@ -180,7 +181,7 @@ iphone_error_t np_post_notification( np_client_t client, const char *notificatio plist_add_sub_key_el(dict, "Name"); plist_add_sub_string_el(dict, notification); - iphone_error_t res = np_plist_send(client, dict); + np_error_t res = np_plist_send(client, dict); plist_free(dict); dict = plist_new_dict(); @@ -190,7 +191,7 @@ iphone_error_t np_post_notification( np_client_t client, const char *notificatio res = np_plist_send(client, dict); plist_free(dict); - if (res != IPHONE_E_SUCCESS) { + if (res != NP_E_SUCCESS) { log_debug_msg("%s: Error sending XML plist to device!\n", __func__); } @@ -203,10 +204,10 @@ iphone_error_t np_post_notification( np_client_t client, const char *notificatio * @param client The client to send to * @param notification The notifications that should be observed. */ -iphone_error_t np_observe_notification( np_client_t client, const char *notification ) +np_error_t np_observe_notification( np_client_t client, const char *notification ) { if (!client || !notification) { - return IPHONE_E_INVALID_ARG; + return NP_E_INVALID_ARG; } np_lock(client); @@ -216,8 +217,8 @@ iphone_error_t np_observe_notification( np_client_t client, const char *notifica plist_add_sub_key_el(dict, "Name"); plist_add_sub_string_el(dict, notification); - iphone_error_t res = np_plist_send(client, dict); - if (res != IPHONE_E_SUCCESS) { + np_error_t res = np_plist_send(client, dict); + if (res != NP_E_SUCCESS) { log_debug_msg("%s: Error sending XML plist to device!\n", __func__); } plist_free(dict); @@ -245,14 +246,14 @@ iphone_error_t np_observe_notification( np_client_t client, const char *notifica * terminating NULL entry. However this parameter can be NULL; in this case, * the default set of notifications will be used. */ -iphone_error_t np_observe_notifications( np_client_t client, const char **notification_spec ) +np_error_t np_observe_notifications(np_client_t client, const char **notification_spec) { int i = 0; - iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; + np_error_t res = NP_E_UNKNOWN_ERROR; const char **notifications = notification_spec; if (!client) { - return IPHONE_E_INVALID_ARG; + return NP_E_INVALID_ARG; } if (!notifications) { @@ -261,7 +262,7 @@ iphone_error_t np_observe_notifications( np_client_t client, const char **notifi while (notifications[i]) { res = np_observe_notification(client, notifications[i]); - if (res != IPHONE_E_SUCCESS) { + if (res != NP_E_SUCCESS) { break; } i++; @@ -277,24 +278,22 @@ iphone_error_t np_observe_notifications( np_client_t client, const char **notifi * @param notification Pointer to a buffer that will be allocated and filled * with the notification that has been received. * - * @return IPHONE_E_SUCCESS if a notification has been received, - * IPHONE_E_TIMEOUT if nothing has been received, + * @return 0 if a notification has been received or nothing has been received, * or an error value if an error occured. * * @note You probably want to check out np_set_notify_callback * @see np_set_notify_callback */ -static iphone_error_t np_get_notification( np_client_t client, char **notification ) +static int np_get_notification(np_client_t client, char **notification) { uint32_t bytes = 0; - iphone_error_t res; + int res = 0; uint32_t pktlen = 0; char *XML_content = NULL; plist_t dict = NULL; - if (!client || client->sfd < 0 || *notification) { - return IPHONE_E_INVALID_ARG; - } + if (!client || client->sfd < 0 || *notification) + return -1; np_lock(client); @@ -302,7 +301,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati log_debug_msg("NotificationProxy: initial read=%i\n", bytes); if (bytes < 4) { log_debug_msg("NotificationProxy: no notification received!\n"); - res = IPHONE_E_TIMEOUT; + res = 0; } else { if ((char)pktlen == 0) { pktlen = ntohl(pktlen); @@ -312,7 +311,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati usbmuxd_recv_timeout(client->sfd, XML_content, pktlen, &bytes, 1000); if (bytes <= 0) { - res = IPHONE_E_UNKNOWN_ERROR; + res = -1; } else { log_debug_msg("NotificationProxy: received data:\n"); log_debug_buffer(XML_content, pktlen); @@ -320,7 +319,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati plist_from_xml(XML_content, bytes, &dict); if (!dict) { np_unlock(client); - return IPHONE_E_PLIST_ERROR; + return -2; } plist_t cmd_key_node = plist_find_node_by_key(dict, "Command"); @@ -345,21 +344,21 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati plist_get_string_val(name_value_node, &name_value); } - res = IPHONE_E_PLIST_ERROR; + res = -2; if (name_key && name_value && !strcmp(name_key, "Name")) { *notification = name_value; log_debug_msg("%s: got notification %s\n", __func__, name_value); - res = IPHONE_E_SUCCESS; + res = 0; } free(name_key); } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__); - res = IPHONE_E_UNKNOWN_ERROR; + res = -1; } else if (cmd_value) { log_debug_msg("%d: unknown NotificationProxy command '%s' received!\n", __func__); - res = IPHONE_E_UNKNOWN_ERROR; + res = -1; } else { - res = IPHONE_E_PLIST_ERROR; + res = -2; } if (cmd_value) { free(cmd_value); @@ -370,7 +369,7 @@ static iphone_error_t np_get_notification( np_client_t client, char **notificati XML_content = NULL; } } else { - res = IPHONE_E_UNKNOWN_ERROR; + res = -1; } } @@ -416,15 +415,15 @@ gpointer np_notifier( gpointer arg ) * @param notify_cb pointer to a callback function or NULL to de-register a * previously set callback function * - * @return IPHONE_E_SUCCESS when the callback was successfully registered, + * @return NP_E_SUCCESS when the callback was successfully registered, * or an error value when an error occured. */ -iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) +np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) { - if (!client) { - return IPHONE_E_INVALID_ARG; - } - iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; + if (!client) + return NP_E_INVALID_ARG; + + np_error_t res = NP_E_UNKNOWN_ERROR; np_lock(client); if (client->notifier) { @@ -444,7 +443,7 @@ iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); if (client->notifier) { - res = IPHONE_E_SUCCESS; + res = NP_E_SUCCESS; } } } else { -- cgit v1.1-32-gdbae From f5e9d76ebd74999512ab73f44fabba86879b1c1f Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 02:40:25 +0200 Subject: Update lockdown API and introduce new error codes --- dev/afccheck.c | 9 +- dev/iphone_id.c | 6 +- dev/iphoneinfo.c | 6 +- dev/lckdclient.c | 15 ++- dev/main.c | 6 +- dev/msyncclient.c | 4 +- dev/syslog_relay.c | 6 +- include/libiphone/libiphone.h | 10 +- include/libiphone/lockdown.h | 51 ++++--- src/lockdown.c | 305 +++++++++++++++++++++--------------------- src/lockdown.h | 10 +- 11 files changed, 226 insertions(+), 202 deletions(-) diff --git a/dev/afccheck.c b/dev/afccheck.c index 0525417..370742b 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -104,13 +104,13 @@ int main(int argc, char *argv[]) return 1; } - if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_free_device(phone); return 1; } - if (IPHONE_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { - lockdownd_free_client(client); + if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { + lockdownd_client_free(client); iphone_free_device(phone); fprintf(stderr, "Something went wrong when starting AFC."); return 1; @@ -136,8 +136,7 @@ int main(int argc, char *argv[]) g_thread_join(threads[i]); } - - lockdownd_free_client(client); + lockdownd_client_free(client); iphone_free_device(phone); return 0; diff --git a/dev/iphone_id.c b/dev/iphone_id.c index dde15bc..1b8f8a1 100644 --- a/dev/iphone_id.c +++ b/dev/iphone_id.c @@ -68,18 +68,18 @@ int main(int argc, char **argv) return -2; } - if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_free_device(phone); fprintf(stderr, "ERROR: Connecting to device failed!\n"); return -2; } - if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) { + if ((LOCKDOWN_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) { fprintf(stderr, "ERROR: Could not get device name!\n"); ret = -2; } - lockdownd_free_client(client); + lockdownd_client_free(client); iphone_free_device(phone); if (ret == 0) { diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 02b62d5..52d7c8a 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -136,13 +136,13 @@ int main(int argc, char *argv[]) } } - if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_free_device(phone); return -1; } /* run query and output information */ - if(lockdownd_get_value(client, domain, key, &node) == IPHONE_E_SUCCESS) + if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) { if (plist_get_node_type(node) == PLIST_DICT) { if (plist_get_first_child(node)) @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) if (domain != NULL) free(domain); - lockdownd_free_client(client); + lockdownd_client_free(client); iphone_free_device(phone); return 0; diff --git a/dev/lckdclient.c b/dev/lckdclient.c index 9518a6e..4dcb0b4 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) if (uuid) free(uuid); - if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_free_device(phone); return -1; } @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) if (!strcmp(*args, "get") && len >= 2) { plist_t value = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value)) + if (LOCKDOWN_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value)) { char *xml = NULL; uint32_t length; @@ -93,8 +93,13 @@ int main(int argc, char *argv[]) if (!strcmp(*args, "start") && len == 2) { int port = 0; - lockdownd_start_service(client, *(args + 1), &port); - printf("%i\n", port); + if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &port)) { + printf("started service %s on port %i\n", *(args + 1), port); + } + else + { + printf("failed to start service %s on device.\n", *(args + 1)); + } } } g_strfreev(args); @@ -103,7 +108,7 @@ int main(int argc, char *argv[]) cmd = NULL; } clear_history(); - lockdownd_free_client(client); + lockdownd_client_free(client); iphone_free_device(phone); return 0; diff --git a/dev/main.c b/dev/main.c index 33c60f9..69b0b80 100644 --- a/dev/main.c +++ b/dev/main.c @@ -87,14 +87,14 @@ int main(int argc, char *argv[]) if (uuid) free(uuid); - if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_free_device(phone); printf("Exiting.\n"); return -1; } char *nnn = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { + if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { printf("DeviceName : %s\n", nnn); free(nnn); } @@ -248,7 +248,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); - lockdownd_free_client(client); + lockdownd_client_free(client); iphone_free_device(phone); return 0; diff --git a/dev/msyncclient.c b/dev/msyncclient.c index 7651002..6ab7c79 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) return -1; } - if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_free_device(phone); return -1; } @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); - lockdownd_free_client(client); + lockdownd_client_free(client); iphone_free_device(phone); return 0; diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 09be6b8..0c41c94 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -100,15 +100,15 @@ int main(int argc, char *argv[]) } } - if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { + if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_free_device(phone); return -1; } /* start syslog_relay service and retrieve port */ ret = lockdownd_start_service(client, "com.apple.syslog_relay", &port); - if ((ret == IPHONE_E_SUCCESS) && port) { - lockdownd_free_client(client); + if ((ret == LOCKDOWN_E_SUCCESS) && port) { + lockdownd_client_free(client); /* connect to socket relay messages */ diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 9764a7e..895e809 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -32,7 +32,7 @@ extern "C" { #include #include -//general errors +/* Error Codes */ #define IPHONE_E_SUCCESS 0 #define IPHONE_E_INVALID_ARG -1 #define IPHONE_E_UNKNOWN_ERROR -2 @@ -41,14 +41,6 @@ extern "C" { #define IPHONE_E_NOT_ENOUGH_DATA -5 #define IPHONE_E_BAD_HEADER -6 -//lockdownd specific error -#define IPHONE_E_INVALID_CONF -7 -#define IPHONE_E_PAIRING_FAILED -8 -#define IPHONE_E_SSL_ERROR -9 -#define IPHONE_E_PLIST_ERROR -10 -#define IPHONE_E_DICT_ERROR -11 -#define IPHONE_E_START_SERVICE_FAILED -12 - //afc specific error #define IPHONE_E_AFC_ERROR -13 diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h index 20ccf77..55c0cb7 100644 --- a/include/libiphone/lockdown.h +++ b/include/libiphone/lockdown.h @@ -27,25 +27,44 @@ extern "C" { #include +/* Error Codes */ +#define LOCKDOWN_E_SUCCESS 0 +#define LOCKDOWN_E_INVALID_ARG -1 +#define LOCKDOWN_E_INVALID_CONF -2 +#define LOCKDOWN_E_PLIST_ERROR -3 +#define LOCKDOWN_E_PAIRING_FAILED -4 +#define LOCKDOWN_E_SSL_ERROR -5 +#define LOCKDOWN_E_DICT_ERROR -6 +#define LOCKDOWN_E_START_SERVICE_FAILED -7 +#define LOCKDOWN_E_NOT_ENOUGH_DATA -8 +#define LOCKDOWN_E_SET_VALUE_PROHIBITED -9 +#define LOCKDOWN_E_GET_VALUE_PROHIBITED -10 +#define LOCKDOWN_E_REMOVE_VALUE_PROHIBITED -11 +#define LOCKDOWN_E_MUX_ERROR -12 + +#define LOCKDOWN_E_UNKNOWN_ERROR -256 + +typedef int16_t lockdownd_error_t; + struct lockdownd_client_int; typedef struct lockdownd_client_int *lockdownd_client_t; -//lockdownd related functions -iphone_error_t lockdownd_new_client (iphone_device_t device, lockdownd_client_t *client); -iphone_error_t lockdownd_free_client(lockdownd_client_t client); -iphone_error_t lockdownd_query_type(lockdownd_client_t client); -iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); -iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); -iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); -iphone_error_t lockdownd_start_service (lockdownd_client_t client, const char *service, int *port); -iphone_error_t lockdownd_stop_session(lockdownd_client_t client); -iphone_error_t lockdownd_send (lockdownd_client_t client, plist_t plist); -iphone_error_t lockdownd_recv (lockdownd_client_t client, plist_t *plist); -iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id); -iphone_error_t lockdownd_get_device_uid (lockdownd_client_t control, char **uid); -iphone_error_t lockdownd_get_device_name (lockdownd_client_t client, char **device_name); -iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client); -iphone_error_t lockdownd_goodbye(lockdownd_client_t client); +/* Interface */ +lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client); +lockdownd_error_t lockdownd_client_free(lockdownd_client_t client); +lockdownd_error_t lockdownd_query_type(lockdownd_client_t client); +lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); +lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); +lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); +lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port); +lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client); +lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); +lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist); +lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *uuid, char *host_id); +lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t control, char **uuid); +lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); +lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); +lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client); #ifdef __cplusplus } diff --git a/src/lockdown.c b/src/lockdown.c index 757a94a..29e5046 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -126,13 +126,15 @@ static int lockdown_check_result(plist_t dict, const char *query_match) * the StopSession Request to the device. * * @param control The lockdown client + * + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_stop_session(lockdownd_client_t client) +lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client) { if (!client) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_add_sub_key_el(dict, "Request"); @@ -151,13 +153,13 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client) if (!dict) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__); - return IPHONE_E_PLIST_ERROR; + return LOCKDOWN_E_PLIST_ERROR; } - ret = IPHONE_E_UNKNOWN_ERROR; + ret = LOCKDOWN_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; @@ -171,14 +173,16 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client) * performing a close notify, which is done by "gnutls_bye". * * @param client The lockdown client + * + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) +static lockdownd_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) { if (!client) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: invalid argument!\n", __func__); - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; } - iphone_error_t ret = IPHONE_E_SUCCESS; + lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; if (client->in_SSL) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: stopping SSL session\n", __func__); @@ -198,12 +202,14 @@ static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) /** Closes the lockdownd client and does the necessary housekeeping. * * @param client The lockdown client + * + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_free_client(lockdownd_client_t client) +lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) { if (!client) - return IPHONE_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + return LOCKDOWN_E_INVALID_ARG; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; lockdownd_stop_ssl_session(client); @@ -224,13 +230,13 @@ iphone_error_t lockdownd_free_client(lockdownd_client_t client) * @param control The lockdownd client * @param plist The plist to store the received data * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) +lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) { if (!client || !plist || (plist && *plist)) - return IPHONE_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + return LOCKDOWN_E_INVALID_ARG; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; char *receive = NULL; uint32_t datalen = 0, bytes = 0, received_bytes = 0; @@ -240,10 +246,10 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) ssize_t res = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen)); if (res < 0) { log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res)); - return IPHONE_E_SSL_ERROR; + return LOCKDOWN_E_SSL_ERROR; } else { bytes = res; - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } } datalen = ntohl(datalen); @@ -253,32 +259,32 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) /* fill buffer and request more packets if needed */ if (!client->in_SSL) { - while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { + while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) { ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes); received_bytes += bytes; } } else { ssize_t res = 0; - while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { + while ((received_bytes < datalen) && (ret == LOCKDOWN_E_SUCCESS)) { res = gnutls_record_recv(*client->ssl_session, receive + received_bytes, datalen - received_bytes); if (res < 0) { log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_recv: Error occured: %s\n", gnutls_strerror(res)); - ret = IPHONE_E_SSL_ERROR; + ret = LOCKDOWN_E_SSL_ERROR; } else { received_bytes += res; - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } } } - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { free(receive); return ret; } if ((ssize_t)received_bytes <= 0) { free(receive); - return IPHONE_E_NOT_ENOUGH_DATA; + return LOCKDOWN_E_NOT_ENOUGH_DATA; } log_dbg_msg(DBGMASK_LOCKDOWND, "%s: received msg size: %i, buffer follows:\n%s", __func__, received_bytes, receive); @@ -286,7 +292,7 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) free(receive); if (!*plist) - ret = IPHONE_E_PLIST_ERROR; + ret = LOCKDOWN_E_PLIST_ERROR; return ret; } @@ -299,17 +305,17 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) * @param client The lockdownd client * @param plist The plist to send * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) +lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) { if (!client || !plist) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; char *real_query; int bytes; char *XMLContent = NULL; uint32_t length = 0; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_to_xml(plist, &XMLContent, &length); log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending msg size %i, buffer follows:\n%s", __func__, length, XMLContent); @@ -327,13 +333,13 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) ssize_t res = gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length)); if (res < 0) { log_dbg_msg(DBGMASK_LOCKDOWND, "gnutls_record_send: Error occured: %s\n", gnutls_strerror(res)); - ret = IPHONE_E_SSL_ERROR; + ret = LOCKDOWN_E_SSL_ERROR; } else { bytes = res; - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } } - if (ret == IPHONE_E_SUCCESS) { + if (ret == LOCKDOWN_E_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sent it!\n", __func__); } else { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending failed!\n", __func__); @@ -347,14 +353,14 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) * * @param client The lockdownd client * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_query_type(lockdownd_client_t client) +lockdownd_error_t lockdownd_query_type(lockdownd_client_t client) { if (!client) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_add_sub_key_el(dict, "Request"); @@ -368,13 +374,13 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client) ret = lockdownd_recv(client, &dict); - if (IPHONE_E_SUCCESS != ret) + if (LOCKDOWN_E_SUCCESS != ret) return ret; - ret = IPHONE_E_UNKNOWN_ERROR; + ret = LOCKDOWN_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; @@ -389,15 +395,15 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client) * @param key the key name to request or NULL to query for all keys * @param value a plist node representing the result value node * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) +lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) { if (!client) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; plist_t dict = NULL; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; /* setup request plist */ dict = plist_new_dict(); @@ -418,19 +424,19 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain plist_free(dict); dict = NULL; - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; /* Now get device's answer */ ret = lockdownd_recv(client, &dict); - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { plist_free(dict); return ret; } @@ -462,15 +468,15 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain * @param key the key name to set the value or NULL to set a value dict plist * @param value a plist node of any node type representing the value to set * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) +lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) { if (!client || !value) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; plist_t dict = NULL; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; /* setup request plist */ dict = plist_new_dict(); @@ -494,20 +500,20 @@ iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain plist_free(dict); dict = NULL; - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; /* Now get device's answer */ ret = lockdownd_recv(client, &dict); - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; if (lockdown_check_result(dict, "SetValue") == RESULT_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { plist_free(dict); return ret; } @@ -524,15 +530,15 @@ iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain * @param domain the domain to query on or NULL for global domain * @param key the key name to remove or NULL remove all keys for the current domain * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) +lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) { if (!client) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; plist_t dict = NULL; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; /* setup request plist */ dict = plist_new_dict(); @@ -553,20 +559,20 @@ iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *dom plist_free(dict); dict = NULL; - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; /* Now get device's answer */ ret = lockdownd_recv(client, &dict); - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { plist_free(dict); return ret; } @@ -577,18 +583,18 @@ iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *dom /** Asks for the device's unique id. Part of the lockdownd handshake. * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid) +lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uuid) { - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t value = NULL; ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value); - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { return ret; } - plist_get_string_val(value, uid); + plist_get_string_val(value, uuid); plist_free(value); value = NULL; @@ -597,17 +603,17 @@ iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid) /** Askes for the device's public key. Part of the lockdownd handshake. * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) +lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) { - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t value = NULL; char *value_value = NULL; uint64_t size = 0; ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value); - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { return ret; } plist_get_data_val(value, &value_value, &size); @@ -625,15 +631,15 @@ iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls * @param client The pointer to the location of the new lockdownd_client * * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) +lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) { - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t value = NULL; ret = lockdownd_get_value(client, NULL, "DeviceName", &value); - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { return ret; } plist_get_string_val(value, device_name); @@ -649,19 +655,19 @@ iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **devic * @param phone The iPhone to create a lockdownd client for * @param client The pointer to the location of the new lockdownd_client * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *client) +lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client) { if (!device || !client || (client && *client)) - return IPHONE_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_SUCCESS; + return LOCKDOWN_E_INVALID_ARG; + lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; char *host_id = NULL; int sfd = usbmuxd_connect(device->handle, 0xf27e); if (sfd < 0) { log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, device->handle); - return IPHONE_E_UNKNOWN_ERROR; + return LOCKDOWN_E_MUX_ERROR; } lockdownd_client_t client_loc = (lockdownd_client_t) malloc(sizeof(struct lockdownd_client_int)); @@ -669,23 +675,24 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); client_loc->in_SSL = 0; + if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) { log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__); - ret = IPHONE_E_NOT_ENOUGH_DATA; + ret = LOCKDOWN_E_NOT_ENOUGH_DATA; } char *uuid = NULL; ret = iphone_device_get_uuid(device, &uuid); - if (IPHONE_E_SUCCESS != ret) { + if (LOCKDOWN_E_SUCCESS != ret) { log_debug_msg("%s: failed to get device uuid.\n", __func__); } log_debug_msg("%s: device uuid: %s\n", __func__, uuid); userpref_get_host_id(&host_id); - if (IPHONE_E_SUCCESS == ret && !host_id) { - ret = IPHONE_E_INVALID_CONF; + if (LOCKDOWN_E_SUCCESS == ret && !host_id) { + ret = LOCKDOWN_E_INVALID_CONF; } - if (IPHONE_E_SUCCESS == ret && !userpref_has_device_public_key(uuid)) + if (LOCKDOWN_E_SUCCESS == ret && !userpref_has_device_public_key(uuid)) ret = lockdownd_pair(client_loc, uuid, host_id); if (uuid) { @@ -693,10 +700,10 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * uuid = NULL; } - if (IPHONE_E_SUCCESS == ret) { + if (LOCKDOWN_E_SUCCESS == ret) { ret = lockdownd_start_ssl_session(client_loc, host_id); - if (IPHONE_E_SUCCESS != ret) { - ret = IPHONE_E_SSL_ERROR; + if (LOCKDOWN_E_SUCCESS != ret) { + ret = LOCKDOWN_E_SSL_ERROR; log_debug_msg("%s: SSL Session opening failed.\n", __func__); } @@ -705,7 +712,7 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * host_id = NULL; } - if (IPHONE_E_SUCCESS == ret) + if (LOCKDOWN_E_SUCCESS == ret) *client = client_loc; } @@ -715,11 +722,11 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t * /** Generates the appropriate keys and pairs the device. It's part of the * lockdownd handshake. * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id) +lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *uuid, char *host_id) { - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = NULL; plist_t dict_record = NULL; @@ -729,14 +736,14 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i gnutls_datum_t public_key = { NULL, 0 }; ret = lockdownd_get_device_public_key(client, &public_key); - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { log_debug_msg("%s: device refused to send public key.\n", __func__); return ret; } log_debug_msg("%s: device public key follows:\n%s\n", __func__, public_key.data); ret = lockdownd_gen_pair_cert(public_key, &device_cert, &host_cert, &root_cert); - if (ret != IPHONE_E_SUCCESS) { + if (ret != LOCKDOWN_E_SUCCESS) { free(public_key.data); return ret; } @@ -762,28 +769,28 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i plist_free(dict); dict = NULL; - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; /* Now get iPhone's answer */ ret = lockdownd_recv(client, &dict); - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; if (lockdown_check_result(dict, "Pair") == RESULT_SUCCESS) { - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; /* store public key in config if pairing succeeded */ - if (ret == IPHONE_E_SUCCESS) { + if (ret == LOCKDOWN_E_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__); userpref_set_device_public_key(uuid, public_key); } else { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__); - ret = IPHONE_E_PAIRING_FAILED; + ret = LOCKDOWN_E_PAIRING_FAILED; } free(public_key.data); return ret; @@ -794,14 +801,14 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i * * @param client The lockdown client * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) +lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) { if (!client) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_add_sub_key_el(dict, "Request"); @@ -817,7 +824,7 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; @@ -830,14 +837,14 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) * * @param client The lockdown client * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_goodbye(lockdownd_client_t client) +lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) { if (!client) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_add_sub_key_el(dict, "Request"); @@ -852,12 +859,12 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client) ret = lockdownd_recv(client, &dict); if (!dict) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: did not get goodbye response back\n", __func__); - return IPHONE_E_PLIST_ERROR; + return LOCKDOWN_E_PLIST_ERROR; } if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } plist_free(dict); dict = NULL; @@ -867,14 +874,14 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client) /** Generates the device certificate from the public key as well as the host * and root certificates. * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, +lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert) { if (!public_key.data || !odevice_cert || !ohost_cert || !oroot_cert) - return IPHONE_E_INVALID_ARG; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + return LOCKDOWN_E_INVALID_ARG; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; userpref_error_t uret = USERPREF_E_UNKNOWN_ERROR; gnutls_datum_t modulus = { NULL, 0 }; @@ -903,7 +910,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t ret1 = asn1_read_value(asn1_pub_key, "modulus", modulus.data, (int*)&modulus.size); ret2 = asn1_read_value(asn1_pub_key, "publicExponent", exponent.data, (int*)&exponent.size); if (ASN1_SUCCESS == ret1 && ASN1_SUCCESS == ret2) - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } if (asn1_pub_key) asn1_delete_structure(&asn1_pub_key); @@ -913,7 +920,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t } /* now generate certifcates */ - if (IPHONE_E_SUCCESS == ret && 0 != modulus.size && 0 != exponent.size) { + if (LOCKDOWN_E_SUCCESS == ret && 0 != modulus.size && 0 != exponent.size) { gnutls_global_init(); gnutls_datum_t essentially_null = { (unsigned char*)strdup("abababababababab"), strlen("abababababababab") }; @@ -945,7 +952,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t gnutls_x509_crt_set_expiration_time(dev_cert, time(NULL) + (60 * 60 * 24 * 365 * 10)); gnutls_x509_crt_sign(dev_cert, root_cert, root_privkey); - if (IPHONE_E_SUCCESS == ret) { + if (LOCKDOWN_E_SUCCESS == ret) { /* if everything went well, export in PEM format */ gnutls_datum_t dev_pem = { NULL, 0 }; gnutls_x509_crt_export(dev_cert, GNUTLS_X509_FMT_PEM, NULL, &dev_pem.size); @@ -979,13 +986,13 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t switch(uret) { case USERPREF_E_INVALID_ARG: - ret = IPHONE_E_INVALID_ARG; + ret = LOCKDOWN_E_INVALID_ARG; break; case USERPREF_E_INVALID_CONF: - ret = IPHONE_E_INVALID_CONF; + ret = LOCKDOWN_E_INVALID_CONF; break; case USERPREF_E_SSL_ERROR: - ret = IPHONE_E_SSL_ERROR; + ret = LOCKDOWN_E_SSL_ERROR; default: break; } @@ -1005,14 +1012,14 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * @param client The lockdownd client * @param HostID The HostID used with this phone * - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID) +lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID) { plist_t dict = NULL; uint32_t return_me = 0; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; client->session_id[0] = '\0'; /* Setup DevicePublicKey request plist */ @@ -1026,13 +1033,13 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char plist_free(dict); dict = NULL; - if (ret != IPHONE_E_SUCCESS) + if (ret != LOCKDOWN_E_SUCCESS) return ret; ret = lockdownd_recv(client, &dict); if (!dict) - return IPHONE_E_PLIST_ERROR; + return LOCKDOWN_E_PLIST_ERROR; if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); @@ -1046,8 +1053,8 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char char *host_id = NULL; userpref_get_host_id(&host_id); - if (IPHONE_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) { - if (IPHONE_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) { + if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_uuid(client, &uuid) ) { + if (LOCKDOWN_E_SUCCESS == lockdownd_pair(client, uuid, host_id) ) { /* start session again */ plist_free(dict); dict = plist_new_dict(); @@ -1070,7 +1077,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char } } - ret = IPHONE_E_SSL_ERROR; + ret = LOCKDOWN_E_SSL_ERROR; if (lockdown_check_result(dict, "StartSession") == RESULT_SUCCESS) { // Set up GnuTLS... //gnutls_anon_client_credentials_t anoncred; @@ -1114,13 +1121,13 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS reported something wrong.\n", __func__); gnutls_perror(return_me); log_dbg_msg(DBGMASK_LOCKDOWND, "%s: oh.. errno says %s\n", __func__, strerror(errno)); - return IPHONE_E_SSL_ERROR; + return LOCKDOWN_E_SSL_ERROR; } else { client->in_SSL = 1; - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } } - //store session id + /* store session id */ plist_t session_node = plist_find_node_by_key(dict, "SessionID"); if (session_node) { @@ -1133,7 +1140,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char plist_get_string_val(session_node_val, &session_id); if (session_node_val_type == PLIST_STRING && session_id) { - // we need to store the session ID for StopSession + /* we need to store the session ID for StopSession */ strcpy(client->session_id, session_id); log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id); } @@ -1145,11 +1152,11 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char plist_free(dict); dict = NULL; - if (ret == IPHONE_E_SUCCESS) + if (ret == LOCKDOWN_E_SUCCESS) return ret; log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Apparently failed negotiating with lockdownd.\n", __func__); - return IPHONE_E_SSL_ERROR; + return LOCKDOWN_E_SSL_ERROR; } /** gnutls callback for writing data to the iPhone. @@ -1196,7 +1203,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ // repeat until we have the full data or an error occurs. do { - if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != IPHONE_E_SUCCESS) { + if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != LOCKDOWN_E_SUCCESS) { log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res); return res; } @@ -1230,23 +1237,23 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ * @param service The name of the service to start * @param port The port number the service was started on - * @return an error code (IPHONE_E_SUCCESS on success) + * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port) +lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port) { if (!client || !service || !port) - return IPHONE_E_INVALID_ARG; + return LOCKDOWN_E_INVALID_ARG; char *host_id = NULL; userpref_get_host_id(&host_id); if (!host_id) - return IPHONE_E_INVALID_CONF; + return LOCKDOWN_E_INVALID_CONF; if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id)) - return IPHONE_E_SSL_ERROR; + return LOCKDOWN_E_SSL_ERROR; plist_t dict = NULL; uint32_t port_loc = 0; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; free(host_id); host_id = NULL; @@ -1262,18 +1269,18 @@ iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *se plist_free(dict); dict = NULL; - if (IPHONE_E_SUCCESS != ret) + if (LOCKDOWN_E_SUCCESS != ret) return ret; ret = lockdownd_recv(client, &dict); - if (IPHONE_E_SUCCESS != ret) + if (LOCKDOWN_E_SUCCESS != ret) return ret; if (!dict) - return IPHONE_E_PLIST_ERROR; + return LOCKDOWN_E_PLIST_ERROR; - ret = IPHONE_E_UNKNOWN_ERROR; + ret = LOCKDOWN_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { plist_t port_key_node = plist_find_node_by_key(dict, "Port"); plist_t port_value_node = plist_get_next_sibling(port_key_node); @@ -1287,17 +1294,17 @@ iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *se plist_get_uint_val(port_value_node, &port_value); if (port_key && !strcmp(port_key, "Port")) { port_loc = port_value; - ret = IPHONE_E_SUCCESS; + ret = LOCKDOWN_E_SUCCESS; } if (port_key) free(port_key); - if (port && ret == IPHONE_E_SUCCESS) + if (port && ret == LOCKDOWN_E_SUCCESS) *port = port_loc; } } else - ret = IPHONE_E_START_SERVICE_FAILED; + ret = LOCKDOWN_E_START_SERVICE_FAILED; plist_free(dict); dict = NULL; diff --git a/src/lockdown.h b/src/lockdown.h index 185d27a..1e193f6 100644 --- a/src/lockdown.h +++ b/src/lockdown.h @@ -24,6 +24,7 @@ #include #include + #include "libiphone/lockdown.h" struct lockdownd_client_int { @@ -33,13 +34,14 @@ struct lockdownd_client_int { char session_id[40]; }; -iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); -iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert, +lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); +lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert, gnutls_datum_t * host_cert, gnutls_datum_t * root_cert); -// SSL functions -iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID); +/* SSL functions */ +lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID); ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length); ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length); + #endif -- cgit v1.1-32-gdbae From 5cb9ecc85240102402082c442d561d7350732027 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 02:54:40 +0200 Subject: Follow glib style and rename iphone_free_device to iphone_device_free --- dev/afccheck.c | 6 +++--- dev/iphone_id.c | 4 ++-- dev/iphoneinfo.c | 4 ++-- dev/lckdclient.c | 4 ++-- dev/main.c | 4 ++-- dev/msyncclient.c | 4 ++-- dev/syslog_relay.c | 4 ++-- include/libiphone/libiphone.h | 4 ++-- src/iphone.c | 6 +++--- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/dev/afccheck.c b/dev/afccheck.c index 370742b..067dd5b 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -105,13 +105,13 @@ int main(int argc, char *argv[]) } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { - iphone_free_device(phone); + iphone_device_free(phone); return 1; } if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { lockdownd_client_free(client); - iphone_free_device(phone); + iphone_device_free(phone); fprintf(stderr, "Something went wrong when starting AFC."); return 1; } @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) } lockdownd_client_free(client); - iphone_free_device(phone); + iphone_device_free(phone); return 0; } diff --git a/dev/iphone_id.c b/dev/iphone_id.c index 1b8f8a1..f68fc8b 100644 --- a/dev/iphone_id.c +++ b/dev/iphone_id.c @@ -69,7 +69,7 @@ int main(int argc, char **argv) } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { - iphone_free_device(phone); + iphone_device_free(phone); fprintf(stderr, "ERROR: Connecting to device failed!\n"); return -2; } @@ -80,7 +80,7 @@ int main(int argc, char **argv) } lockdownd_client_free(client); - iphone_free_device(phone); + iphone_device_free(phone); if (ret == 0) { printf("%s\n", devname); diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 52d7c8a..790804c 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -137,7 +137,7 @@ int main(int argc, char *argv[]) } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { - iphone_free_device(phone); + iphone_device_free(phone); return -1; } @@ -170,7 +170,7 @@ int main(int argc, char *argv[]) if (domain != NULL) free(domain); lockdownd_client_free(client); - iphone_free_device(phone); + iphone_device_free(phone); return 0; } diff --git a/dev/lckdclient.c b/dev/lckdclient.c index 4dcb0b4..b880253 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) free(uuid); if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { - iphone_free_device(phone); + iphone_device_free(phone); return -1; } @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) } clear_history(); lockdownd_client_free(client); - iphone_free_device(phone); + iphone_device_free(phone); return 0; } diff --git a/dev/main.c b/dev/main.c index 69b0b80..5551ed9 100644 --- a/dev/main.c +++ b/dev/main.c @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) free(uuid); if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { - iphone_free_device(phone); + iphone_device_free(phone); printf("Exiting.\n"); return -1; } @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); lockdownd_client_free(client); - iphone_free_device(phone); + iphone_device_free(phone); return 0; } diff --git a/dev/msyncclient.c b/dev/msyncclient.c index 6ab7c79..5fffe7a 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -142,7 +142,7 @@ int main(int argc, char *argv[]) } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { - iphone_free_device(phone); + iphone_device_free(phone); return -1; } @@ -162,7 +162,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); lockdownd_client_free(client); - iphone_free_device(phone); + iphone_device_free(phone); return 0; } diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 0c41c94..58a2544 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -101,7 +101,7 @@ int main(int argc, char *argv[]) } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { - iphone_free_device(phone); + iphone_device_free(phone); return -1; } @@ -148,7 +148,7 @@ int main(int argc, char *argv[]) printf("ERROR: Could not start service com.apple.syslog_relay.\n"); } - iphone_free_device(phone); + iphone_device_free(phone); return 0; } diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 895e809..7974526 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -58,10 +58,10 @@ typedef struct iphone_device_int *iphone_device_t; void iphone_set_debug_mask(uint16_t mask); void iphone_set_debug_level(int level); -//device related functions +/* Interface */ iphone_error_t iphone_get_device(iphone_device_t *device); iphone_error_t iphone_get_device_by_uuid(iphone_device_t *device, const char *uuid); -iphone_error_t iphone_free_device(iphone_device_t device); +iphone_error_t iphone_device_free(iphone_device_t device); uint32_t iphone_get_device_handle(iphone_device_t device); iphone_error_t iphone_device_get_uuid(iphone_device_t device, char **uuid); diff --git a/src/iphone.c b/src/iphone.c index 93d7b5d..bdabc35 100644 --- a/src/iphone.c +++ b/src/iphone.c @@ -52,11 +52,11 @@ iphone_error_t iphone_get_device_by_uuid(iphone_device_t * device, const char *u } if (dev_list && dev_list[0].handle > 0) { if (!uuid) { - // select first device found if no UUID specified + /* select first device found if no UUID specified */ handle = dev_list[0].handle; strcpy(serial_number, dev_list[0].serial_number); } else { - // otherwise walk through the list + /* otherwise walk through the list */ for (i = 0; dev_list[i].handle > 0; i++) { log_debug_msg("%s: device handle=%d, uuid=%s\n", __func__, dev_list[i].handle, dev_list[i].serial_number); if (strcasecmp(uuid, dev_list[i].serial_number) == 0) { @@ -119,7 +119,7 @@ iphone_error_t iphone_device_get_uuid(iphone_device_t device, char **uuid) * * @param phone A pointer to an iPhone structure. */ -iphone_error_t iphone_free_device(iphone_device_t device) +iphone_error_t iphone_device_free(iphone_device_t device) { if (!device) return IPHONE_E_INVALID_ARG; -- cgit v1.1-32-gdbae From 1cfc2748d38eb97100cabced3b282108898099c2 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 03:07:01 +0200 Subject: Rename iphone_get_device_handle to iphone_device_get_handle and update tools --- dev/syslog_relay.c | 5 +++-- include/libiphone/libiphone.h | 2 +- src/iphone.c | 19 +++++++++---------- src/iphone.h | 2 ++ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 58a2544..a096101 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -52,6 +52,7 @@ int main(int argc, char *argv[]) char uuid[41]; int port = 0; uuid[0] = 0; + uint32_t handle = 0; signal(SIGINT, clean_exit); signal(SIGQUIT, clean_exit); @@ -111,8 +112,8 @@ int main(int argc, char *argv[]) lockdownd_client_free(client); /* connect to socket relay messages */ - - int sfd = usbmuxd_connect(iphone_get_device_handle(phone), port); + iphone_device_get_handle(phone, &handle); + int sfd = usbmuxd_connect(handle, port); if (sfd < 0) { printf("ERROR: Could not open usbmux connection.\n"); } else { diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 7974526..61820e0 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -62,7 +62,7 @@ void iphone_set_debug_level(int level); iphone_error_t iphone_get_device(iphone_device_t *device); iphone_error_t iphone_get_device_by_uuid(iphone_device_t *device, const char *uuid); iphone_error_t iphone_device_free(iphone_device_t device); -uint32_t iphone_get_device_handle(iphone_device_t device); +iphone_error_t iphone_device_get_handle(iphone_device_t device, uint32_t *handle); iphone_error_t iphone_device_get_uuid(iphone_device_t device, char **uuid); #ifdef __cplusplus diff --git a/src/iphone.c b/src/iphone.c index bdabc35..e694373 100644 --- a/src/iphone.c +++ b/src/iphone.c @@ -19,13 +19,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "iphone.h" -#include "utils.h" #include #include #include -#include -#include + +#include "iphone.h" +#include "utils.h" /** * Retrieves a list of connected devices from usbmuxd and matches their @@ -95,13 +94,13 @@ iphone_error_t iphone_get_device(iphone_device_t * device) return iphone_get_device_by_uuid(device, NULL); } -uint32_t iphone_get_device_handle(iphone_device_t device) +iphone_error_t iphone_device_get_handle(iphone_device_t device, uint32_t *handle) { - if (device) { - return device->handle; - } else { - return 0; - } + if (!device) + return IPHONE_E_INVALID_ARG; + + *handle = device->handle; + return IPHONE_E_SUCCESS; } iphone_error_t iphone_device_get_uuid(iphone_device_t device, char **uuid) diff --git a/src/iphone.h b/src/iphone.h index 2ed0fba..6e14280 100644 --- a/src/iphone.h +++ b/src/iphone.h @@ -24,6 +24,8 @@ #include +#include "libiphone/libiphone.h" + struct iphone_device_int { char *buffer; uint32_t handle; -- cgit v1.1-32-gdbae From 50be30047dbb0d38fd8d61763c13ec75d2b52543 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 03:26:39 +0200 Subject: Update AFC API and use error codes from the STATUS operation response --- dev/afccheck.c | 16 +-- dev/main.c | 46 +++---- include/libiphone/afc.h | 72 +++++++--- include/libiphone/libiphone.h | 8 +- src/AFC.c | 306 +++++++++++++++++++++--------------------- src/AFC.h | 2 + 6 files changed, 238 insertions(+), 212 deletions(-) diff --git a/dev/afccheck.c b/dev/afccheck.c index 067dd5b..d06a147 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -55,18 +55,18 @@ void check_afc(gpointer data) uint64_t file = 0; char path[50]; sprintf(path, "/Buf%i", ((param *) data)->id); - afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RW, &file); - afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); - afc_close_file(((param *) data)->afc, file); + afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RW, &file); + afc_file_write(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); + afc_file_close(((param *) data)->afc, file); file = 0; if (bytes != buffersize) printf("Write operation failed\n"); //now read it bytes = 0; - afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); - afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); - afc_close_file(((param *) data)->afc, file); + afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); + afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); + afc_file_close(((param *) data)->afc, file); if (bytes != buffersize) printf("Read operation failed\n"); @@ -79,7 +79,7 @@ void check_afc(gpointer data) } //cleanup - afc_delete_file(((param *) data)->afc, path); + afc_remove_path(((param *) data)->afc, path); g_thread_exit(0); } @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) return 1; } - afc_new_client(phone, port, &afc); + afc_client_new(phone, port, &afc); //makes sure thread environment is available if (!g_thread_supported()) diff --git a/dev/main.c b/dev/main.c index 5551ed9..3e5860e 100644 --- a/dev/main.c +++ b/dev/main.c @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) if (port) { afc_client_t afc = NULL; - afc_new_client(phone, port, &afc); + afc_client_new(phone, port, &afc); if (afc) { lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); if (npp) { @@ -126,18 +126,18 @@ int main(int argc, char *argv[]) perform_notification(phone, client, NP_SYNC_WILL_START); - afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); + afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); - afc_lock_file(afc, lockfile, AFC_LOCK_EX); + afc_file_lock(afc, lockfile, AFC_LOCK_EX); perform_notification(phone, client, NP_SYNC_DID_START); } char **dirs = NULL; - afc_get_dir_list(afc, "/eafaedf", &dirs); + afc_read_directory(afc, "/eafaedf", &dirs); if (!dirs) - afc_get_dir_list(afc, "/", &dirs); + afc_read_directory(afc, "/", &dirs); printf("Directory time.\n"); for (i = 0; dirs[i]; i++) { printf("/%s\n", dirs[i]); @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) g_strfreev(dirs); dirs = NULL; - afc_get_devinfo(afc, &dirs); + afc_get_device_info(afc, &dirs); if (dirs) { for (i = 0; dirs[i]; i += 2) { printf("%s: %s\n", dirs[i], dirs[i + 1]); @@ -157,7 +157,7 @@ int main(int argc, char *argv[]) uint64_t my_file = 0; char **info = NULL; uint64_t fsize = 0; - if (IPHONE_E_SUCCESS == afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { + if (AFC_E_SUCCESS == afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { for (i = 0; info[i]; i += 2) { printf("%s: %s\n", info[i], info[i+1]); if (!strcmp(info[i], "st_size")) { @@ -166,59 +166,59 @@ int main(int argc, char *argv[]) } } - if (IPHONE_E_SUCCESS == - afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { + if (AFC_E_SUCCESS == + afc_file_open(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { printf("A file size: %llu\n", fsize); char *file_data = (char *) malloc(sizeof(char) * fsize); - afc_read_file(afc, my_file, file_data, fsize, &bytes); + afc_file_read(afc, my_file, file_data, fsize, &bytes); if (bytes > 0) { printf("The file's data:\n"); fwrite(file_data, 1, bytes, stdout); } printf("\nClosing my file.\n"); - afc_close_file(afc, my_file); + afc_file_close(afc, my_file); free(file_data); } else printf("couldn't open a file\n"); - afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); + afc_file_open(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); if (my_file) { char *outdatafile = strdup("this is a bitchin text file\n"); - afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); + afc_file_write(afc, my_file, outdatafile, strlen(outdatafile), &bytes); free(outdatafile); if (bytes > 0) printf("Wrote a surprise. ;)\n"); else printf("I wanted to write a surprise, but... :(\n"); - afc_close_file(afc, my_file); + afc_file_close(afc, my_file); } printf("Deleting a file...\n"); - bytes = afc_delete_file(afc, "/delme"); + bytes = afc_remove_path(afc, "/delme"); if (bytes) printf("Success.\n"); else printf("Failure. (expected unless you have a /delme file on your phone)\n"); printf("Renaming a file...\n"); - bytes = afc_rename_file(afc, "/renme", "/renme2"); + bytes = afc_rename_path(afc, "/renme", "/renme2"); if (bytes > 0) printf("Success.\n"); else printf("Failure. (expected unless you have a /renme file on your phone)\n"); printf("Seek & read\n"); - afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); - if (IPHONE_E_SUCCESS != afc_seek_file(afc, my_file, 5, SEEK_CUR)) + afc_file_open(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); + if (AFC_E_SUCCESS != afc_file_seek(afc, my_file, 5, SEEK_CUR)) printf("WARN: SEEK DID NOT WORK\n"); char *threeletterword = (char *) malloc(sizeof(char) * 5); - afc_read_file(afc, my_file, threeletterword, 3, &bytes); + afc_file_read(afc, my_file, threeletterword, 3, &bytes); threeletterword[3] = '\0'; if (bytes > 0) printf("Result: %s\n", threeletterword); else printf("Couldn't read!\n"); free(threeletterword); - afc_close_file(afc, my_file); + afc_file_close(afc, my_file); } if (gnp && lockfile) { @@ -226,10 +226,10 @@ int main(int argc, char *argv[]) sleep(5); printf("XXX unlocking file\n"); - afc_lock_file(afc, lockfile, AFC_LOCK_UN); + afc_file_lock(afc, lockfile, AFC_LOCK_UN); printf("XXX closing file\n"); - afc_close_file(afc, lockfile); + afc_file_close(afc, lockfile); printf("XXX sleeping\n"); sleep(5); @@ -241,7 +241,7 @@ int main(int argc, char *argv[]) gnp = NULL; } - afc_free_client(afc); + afc_client_free(afc); } else { printf("Start service failure.\n"); } diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index af801b1..4b024a1 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -27,6 +27,39 @@ extern "C" { #include +/* Error Codes */ +#define AFC_E_SUCCESS 0 +#define AFC_E_UNKNOWN_ERROR 1 +#define AFC_E_OP_HEADER_INVALID 2 +#define AFC_E_NO_RESOURCES 3 +#define AFC_E_READ_ERROR 4 +#define AFC_E_WRITE_ERROR 5 +#define AFC_E_UNKNOWN_PACKET_TYPE 6 +#define AFC_E_INVALID_ARGUMENT 7 +#define AFC_E_OBJECT_NOT_FOUND 8 +#define AFC_E_OBJECT_IS_DIR 9 +#define AFC_E_PERM_DENIED 10 +#define AFC_E_SERVICE_NOT_CONNECTED 11 +#define AFC_E_OP_TIMEOUT 12 +#define AFC_E_TOO_MUCH_DATA 13 +#define AFC_E_END_OF_DATA 14 +#define AFC_E_OP_NOT_SUPPORTED 15 +#define AFC_E_OBJECT_EXISTS 16 +#define AFC_E_OBJECT_BUSY 17 +#define AFC_E_NO_SPACE_LEFT 18 +#define AFC_E_OP_WOULD_BLOCK 19 +#define AFC_E_IO_ERROR 20 +#define AFC_E_OP_INTERRUPTED 21 +#define AFC_E_OP_IN_PROGRESS 22 +#define AFC_E_INTERNAL_ERROR 23 + +#define AFC_E_MUX_ERROR 30 +#define AFC_E_NO_MEM 31 +#define AFC_E_NOT_ENOUGH_DATA 32 + +typedef int16_t afc_error_t; + +/* Flags */ typedef enum { AFC_FOPEN_RDONLY = 0x00000001, // r O_RDONLY AFC_FOPEN_RW = 0x00000002, // r+ O_RDWR | O_CREAT @@ -50,28 +83,27 @@ typedef enum { struct afc_client_int; typedef struct afc_client_int *afc_client_t; -//afc related functions -iphone_error_t afc_new_client ( iphone_device_t device, int dst_port, afc_client_t *client ); -iphone_error_t afc_free_client ( afc_client_t client ); +/* Interface */ +afc_error_t afc_client_new(iphone_device_t device, int dst_port, afc_client_t *client); +afc_error_t afc_client_free(afc_client_t client); int afc_get_afcerror ( afc_client_t client ); int afc_get_errno ( afc_client_t client ); - -iphone_error_t afc_get_devinfo ( afc_client_t client, char ***infos ); -iphone_error_t afc_get_dir_list ( afc_client_t client, const char *dir, char ***list); - -iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist ); -iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle ); -iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle); -iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, afc_lock_op_t operation); -iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); -iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); -iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence); -iphone_error_t afc_truncate_file ( afc_client_t client, uint64_t handle, uint64_t newsize); -iphone_error_t afc_delete_file ( afc_client_t client, const char *path); -iphone_error_t afc_rename_file ( afc_client_t client, const char *from, const char *to); -iphone_error_t afc_mkdir ( afc_client_t client, const char *dir); -iphone_error_t afc_truncate ( afc_client_t client, const char *path, off_t newsize); -iphone_error_t afc_make_link ( afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); +afc_error_t afc_get_device_info(afc_client_t client, char ***infos); +afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list); +afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char ***infolist); +afc_error_t afc_get_connection_info(afc_client_t client, char ***infolist); +afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle); +afc_error_t afc_file_close(afc_client_t client, uint64_t handle); +afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation); +afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); +afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); +afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence); +afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize); +afc_error_t afc_remove_path(afc_client_t client, const char *path); +afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to); +afc_error_t afc_make_directory(afc_client_t client, const char *dir); +afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize); +afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); #ifdef __cplusplus } diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 61820e0..014c8bf 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -37,12 +37,8 @@ extern "C" { #define IPHONE_E_INVALID_ARG -1 #define IPHONE_E_UNKNOWN_ERROR -2 #define IPHONE_E_NO_DEVICE -3 -#define IPHONE_E_TIMEOUT -4 -#define IPHONE_E_NOT_ENOUGH_DATA -5 -#define IPHONE_E_BAD_HEADER -6 - -//afc specific error -#define IPHONE_E_AFC_ERROR -13 +#define IPHONE_E_NOT_ENOUGH_DATA -4 +#define IPHONE_E_BAD_HEADER -5 typedef int16_t iphone_error_t; diff --git a/src/AFC.c b/src/AFC.c index 1151f23..95ce0a1 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -23,13 +23,11 @@ #include #include #include + #include "AFC.h" #include "iphone.h" #include "utils.h" -#include - - // This is the maximum size an AFC data packet can be const int MAXIMUM_PACKET_SIZE = (2 << 15); @@ -61,30 +59,30 @@ static void afc_unlock(afc_client_t client) * * @return A handle to the newly-connected client or NULL upon error. */ -iphone_error_t afc_new_client(iphone_device_t device, int dst_port, afc_client_t * client) +afc_error_t afc_client_new(iphone_device_t device, int dst_port, afc_client_t * client) { - //makes sure thread environment is available + /* makes sure thread environment is available */ if (!g_thread_supported()) g_thread_init(NULL); if (!device) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; - // Attempt connection + /* attempt connection */ int sfd = usbmuxd_connect(device->handle, dst_port); if (sfd < 0) { - return IPHONE_E_UNKNOWN_ERROR; // ret; + return AFC_E_MUX_ERROR; } afc_client_t client_loc = (afc_client_t) malloc(sizeof(struct afc_client_int)); client_loc->sfd = sfd; - // Allocate a packet + /* allocate a packet */ client_loc->afc_packet = (AFCPacket *) malloc(sizeof(AFCPacket)); if (!client_loc->afc_packet) { usbmuxd_disconnect(client_loc->sfd); free(client_loc); - return IPHONE_E_UNKNOWN_ERROR; + return AFC_E_NO_MEM; } client_loc->afc_packet->packet_num = 0; @@ -96,17 +94,17 @@ iphone_error_t afc_new_client(iphone_device_t device, int dst_port, afc_client_t client_loc->mutex = g_mutex_new(); *client = client_loc; - return IPHONE_E_SUCCESS; + return AFC_E_SUCCESS; } /** Disconnects an AFC client from the phone. * * @param client The client to disconnect. */ -iphone_error_t afc_free_client(afc_client_t client) +afc_error_t afc_client_free(afc_client_t client) { if (!client || client->sfd < 0 || !client->afc_packet) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; usbmuxd_disconnect(client->sfd); free(client->afc_packet); @@ -214,13 +212,14 @@ int afc_get_errno(afc_client_t client) * reason is that if you set them to different values, it indicates * you want to send the data as two packets. */ -static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t length) +static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t length) { int bytes = 0, offset = 0; char *buffer; if (!client || client->sfd < 0 || !client->afc_packet) return 0; + if (!data || !length) length = 0; @@ -319,20 +318,20 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) return -1; } - // check if it's a valid AFC header + /* check if it's a valid AFC header */ if (strncmp(header.magic, AFC_MAGIC, AFC_MAGIC_LEN)) { log_debug_msg("%s: Invalid AFC packet received (magic != " AFC_MAGIC ")!\n", __func__); } - // check if it has the correct packet number + /* check if it has the correct packet number */ if (header.packet_num != client->afc_packet->packet_num) { - // otherwise print a warning but do not abort + /* otherwise print a warning but do not abort */ log_debug_msg("%s: ERROR: Unexpected packet number (%lld != %lld) aborting.\n", __func__, header.packet_num, client->afc_packet->packet_num); *dump_here = NULL; return -1; } - // then, read the attached packet + /* then, read the attached packet */ if (header.this_length < sizeof(AFCPacket)) { log_debug_msg("%s: Invalid AFCPacket header received!\n", __func__); *dump_here = NULL; @@ -354,7 +353,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) entire_len = (uint32_t)header.entire_length - sizeof(AFCPacket); this_len = (uint32_t)header.this_length - sizeof(AFCPacket); - // this is here as a check (perhaps a different upper limit is good?) + /* this is here as a check (perhaps a different upper limit is good?) */ if (entire_len > (uint32_t)MAXIMUM_PACKET_SIZE) { fprintf(stderr, "%s: entire_len is larger than MAXIMUM_PACKET_SIZE, (%d > %d)!\n", __func__, entire_len, MAXIMUM_PACKET_SIZE); } @@ -469,14 +468,14 @@ static char **make_strings_list(char *tokens, int true_length) * @return A char ** list of files in that directory, terminated by an empty * string for now or NULL if there was an error. */ -iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***list) +afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list) { int bytes = 0; char *data = NULL, **list_loc = NULL; - iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !dir || !list || (list && *list)) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -484,10 +483,10 @@ iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***li client->afc_packet->operation = AFC_OP_READ_DIR; client->afc_packet->entire_length = 0; client->afc_packet->this_length = 0; - bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1); + bytes = afc_dispatch_packet(client, dir, strlen(dir)+1); if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive the data bytes = receive_AFC_data(client, &data); @@ -515,23 +514,24 @@ iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***li * @return A char ** list of parameters as given by AFC or NULL if there was an * error. */ -iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos) +afc_error_t afc_get_device_info(afc_client_t client, char ***infos) { int bytes = 0; char *data = NULL, **list = NULL; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !infos) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); // Send the command client->afc_packet->operation = AFC_OP_GET_DEVINFO; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = dispatch_AFC_packet(client, NULL, 0); + bytes = afc_dispatch_packet(client, NULL, 0); if (bytes < 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive the data bytes = receive_AFC_data(client, &data); @@ -547,34 +547,36 @@ iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos) afc_unlock(client); *infos = list; - return IPHONE_E_SUCCESS; + + return ret; } -/** Deletes a file. +/** Deletes a file or directory. * - * @param client The client to have delete the file. - * @param path The file to delete. (must be a fully-qualified path) + * @param client The client to use. + * @param path The path to delete. (must be a fully-qualified path) * - * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG - * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. + * @return AFC_E_SUCCESS if everythong went well, AFC_E_INVALID_ARGUMENT + * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t afc_delete_file(afc_client_t client, const char *path) +afc_error_t afc_remove_path(afc_client_t client, const char *path) { char *response = NULL; int bytes; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !path || !client->afc_packet || client->sfd < 0) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); // Send command client->afc_packet->this_length = client->afc_packet->entire_length = 0; client->afc_packet->operation = AFC_OP_REMOVE_PATH; - bytes = dispatch_AFC_packet(client, path, strlen(path)+1); + bytes = afc_dispatch_packet(client, path, strlen(path)+1); if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive response bytes = receive_AFC_data(client, &response); @@ -583,29 +585,27 @@ iphone_error_t afc_delete_file(afc_client_t client, const char *path) afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_AFC_ERROR; - } - return IPHONE_E_SUCCESS; + return ret; } -/** Renames a file on the phone. +/** Renames a file or directory on the phone. * - * @param client The client to have rename the file. - * @param from The file to rename. (must be a fully-qualified path) - * @param to The new name of the file. (must also be a fully-qualified path) + * @param client The client to have rename. + * @param from The name to rename from. (must be a fully-qualified path) + * @param to The new name. (must also be a fully-qualified path) * - * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG - * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. + * @return AFC_E_SUCCESS if everythong went well, AFC_E_INVALID_ARGUMENT + * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char *to) +afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t))); int bytes = 0; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !from || !to || !client->afc_packet || client->sfd < 0) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -614,11 +614,11 @@ iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char memcpy(send + strlen(from) + 1, to, strlen(to) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; client->afc_packet->operation = AFC_OP_RENAME_PATH; - bytes = dispatch_AFC_packet(client, send, strlen(to)+1 + strlen(from)+1); + bytes = afc_dispatch_packet(client, send, strlen(to)+1 + strlen(from)+1); free(send); if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive response bytes = receive_AFC_data(client, &response); @@ -627,10 +627,7 @@ iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_AFC_ERROR; - } - return IPHONE_E_SUCCESS; + return ret; } /** Creates a directory on the phone. @@ -639,26 +636,27 @@ iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char * @param dir The directory's path. (must be a fully-qualified path, I assume * all other mkdir restrictions apply as well) * - * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG - * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. + * @return AFC_E_SUCCESS if everythong went well, AFC_E_INVALID_ARGUMENT + * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t afc_mkdir(afc_client_t client, const char *dir) +afc_error_t afc_make_directory(afc_client_t client, const char *dir) { int bytes = 0; char *response = NULL; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); // Send command client->afc_packet->operation = AFC_OP_MAKE_DIR; client->afc_packet->this_length = client->afc_packet->entire_length = 0; - bytes = dispatch_AFC_packet(client, dir, strlen(dir)+1); + bytes = afc_dispatch_packet(client, dir, strlen(dir)+1); if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive response bytes = receive_AFC_data(client, &response); @@ -667,10 +665,7 @@ iphone_error_t afc_mkdir(afc_client_t client, const char *dir) afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_AFC_ERROR; - } - return IPHONE_E_SUCCESS; + return ret; } /** Gets information about a specific file. @@ -681,38 +676,37 @@ iphone_error_t afc_mkdir(afc_client_t client, const char *dir) * list of strings with the file information. * Set to NULL before calling this function. * - * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error value + * @return AFC_E_SUCCESS on success or an AFC_E_* error value * when something went wrong. */ -iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) +afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) { char *received = NULL; - int length; + int bytes; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; - if (!client || !path || !infolist) { - return IPHONE_E_INVALID_ARG; - } + if (!client || !path || !infolist) + return AFC_E_INVALID_ARGUMENT; afc_lock(client); // Send command client->afc_packet->operation = AFC_OP_GET_FILE_INFO; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - dispatch_AFC_packet(client, path, strlen(path)+1); + afc_dispatch_packet(client, path, strlen(path)+1); // Receive data length = receive_AFC_data(client, &received); if (received) { - *infolist = make_strings_list(received, length); + *infolist = make_strings_list(received, bytes); free(received); - } else { - afc_unlock(client); - return IPHONE_E_AFC_ERROR; } + log_debug_msg("%s: Didn't get any further data\n", __func__); + afc_unlock(client); - return IPHONE_E_SUCCESS; + return ret; } /** Opens a file on the phone. @@ -725,21 +719,22 @@ iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char *** * destroying anything previously there. * @param handle Pointer to a uint64_t that will hold the handle of the file * - * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error on failure. + * @return AFC_E_SUCCESS on success or an AFC_E_* error on failure. */ iphone_error_t -afc_open_file(afc_client_t client, const char *filename, +afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle) { uint32_t ag = 0; - int bytes = 0, length = 0; + int bytes = 0; char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); + afc_error_t ret = AFC_E_UNKNOWN_ERROR; // set handle to 0 so in case an error occurs, the handle is invalid *handle = 0; if (!client || client->sfd < 0|| !client->afc_packet) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -750,13 +745,13 @@ afc_open_file(afc_client_t client, const char *filename, data[8 + strlen(filename)] = '\0'; client->afc_packet->operation = AFC_OP_FILE_OPEN; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = dispatch_AFC_packet(client, data, 8 + strlen(filename) + 1); + bytes = afc_dispatch_packet(client, data, 8 + strlen(filename) + 1); free(data); if (bytes <= 0) { log_debug_msg("%s: Didn't receive a response to the command\n", __func__); afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive the data length = receive_AFC_data(client, &data); @@ -766,16 +761,12 @@ afc_open_file(afc_client_t client, const char *filename, // Get the file handle memcpy(handle, data, sizeof(uint64_t)); free(data); - return IPHONE_E_SUCCESS; - } else { - log_debug_msg("afc_open_file: Didn't get any further data\n"); - afc_unlock(client); - return IPHONE_E_AFC_ERROR; + return ret; } afc_unlock(client); - return IPHONE_E_UNKNOWN_ERROR; + return ret; } /** Attempts to the read the given number of bytes from the given file. @@ -788,20 +779,21 @@ afc_open_file(afc_client_t client, const char *filename, * @return The number of bytes read if successful. If there was an error -1. */ iphone_error_t -afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) +afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) { char *input = NULL; int current_count = 0, bytes_loc = 0; const int MAXIMUM_READ_SIZE = 1 << 16; + afc_error_t ret = AFC_E_SUCCESS; if (!client || !client->afc_packet || client->sfd < 0 || handle == 0) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; log_debug_msg("%s: called for length %i\n", __func__, length); afc_lock(client); // Looping here to get around the maximum amount of data that - // recieve_AFC_data can handle + // afc_receive_data can handle while (current_count < length) { log_debug_msg("%s: current count is %i but length is %i\n", __func__, current_count, length); @@ -811,26 +803,26 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint packet->size = ((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE; client->afc_packet->operation = AFC_OP_READ; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes_loc = dispatch_AFC_packet(client, (char *) packet, sizeof(AFCFilePacket)); + bytes_loc = afc_dispatch_packet(client, (char *) packet, sizeof(AFCFilePacket)); free(packet); if (bytes_loc <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive the data bytes_loc = receive_AFC_data(client, &input); log_debug_msg("%s: bytes returned: %i\n", __func__, bytes_loc); if (bytes_loc < 0) { afc_unlock(client); - return IPHONE_E_AFC_ERROR; + return ret; } else if (bytes_loc == 0) { if (input) free(input); afc_unlock(client); *bytes = current_count; - return IPHONE_E_SUCCESS; // FIXME check that's actually a - // success + /* FIXME: check that's actually a success */ + return ret; } else { if (input) { log_debug_msg("%s: %d\n", __func__, bytes_loc); @@ -845,7 +837,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint afc_unlock(client); *bytes = current_count; - return IPHONE_E_SUCCESS; + return ret; } /** Writes a given number of bytes to a file. @@ -859,7 +851,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint * none were written... */ iphone_error_t -afc_write_file(afc_client_t client, uint64_t handle, +afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t * bytes) { char *acknowledgement = NULL; @@ -868,9 +860,10 @@ afc_write_file(afc_client_t client, uint64_t handle, uint32_t segments = (length / MAXIMUM_WRITE_SIZE); int bytes_loc = 0; char *out_buffer = NULL; + afc_error_t ret = AFC_E_SUCCESS; if (!client || !client->afc_packet || client->sfd < 0 || !bytes || (handle == 0)) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -885,10 +878,10 @@ afc_write_file(afc_client_t client, uint64_t handle, out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); memcpy(out_buffer, (char *)&handle, sizeof(uint64_t)); memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); - bytes_loc = dispatch_AFC_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); + bytes_loc = afc_dispatch_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); if (bytes_loc < 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } free(out_buffer); out_buffer = NULL; @@ -897,7 +890,7 @@ afc_write_file(afc_client_t client, uint64_t handle, bytes_loc = receive_AFC_data(client, &acknowledgement); if (bytes_loc < 0) { afc_unlock(client); - return IPHONE_E_AFC_ERROR; + return ret; } else { free(acknowledgement); } @@ -910,7 +903,7 @@ afc_write_file(afc_client_t client, uint64_t handle, if (current_count == (uint32_t)length) { afc_unlock(client); *bytes = current_count; - return IPHONE_E_SUCCESS; + return ret; } client->afc_packet->this_length = sizeof(AFCPacket) + 8; @@ -919,7 +912,7 @@ afc_write_file(afc_client_t client, uint64_t handle, out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); memcpy(out_buffer, (char *) &handle, sizeof(uint64_t)); memcpy(out_buffer + 8, data + current_count, (length - current_count)); - bytes_loc = dispatch_AFC_packet(client, out_buffer, (length - current_count) + 8); + bytes_loc = afc_dispatch_packet(client, out_buffer, (length - current_count) + 8); free(out_buffer); out_buffer = NULL; @@ -928,7 +921,7 @@ afc_write_file(afc_client_t client, uint64_t handle, if (bytes_loc <= 0) { afc_unlock(client); *bytes = current_count; - return IPHONE_E_SUCCESS; + return AFC_E_SUCCESS; } zero = bytes_loc; @@ -940,7 +933,7 @@ afc_write_file(afc_client_t client, uint64_t handle, free(acknowledgement); } *bytes = current_count; - return IPHONE_E_SUCCESS; + return ret; } /** Closes a file on the phone. @@ -948,12 +941,14 @@ afc_write_file(afc_client_t client, uint64_t handle, * @param client The client to close the file with. * @param handle File handle of a previously opened file. */ -iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) +afc_error_t afc_file_close(afc_client_t client, uint64_t handle) { - if (!client || (handle == 0)) - return IPHONE_E_INVALID_ARG; char *buffer = malloc(sizeof(char) * 8); int bytes = 0; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; + + if (!client || (handle == 0)) + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -963,13 +958,13 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) memcpy(buffer, &handle, sizeof(uint64_t)); client->afc_packet->operation = AFC_OP_FILE_CLOSE; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = dispatch_AFC_packet(client, buffer, 8); + bytes = afc_dispatch_packet(client, buffer, 8); free(buffer); buffer = NULL; if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_UNKNOWN_ERROR; + return AFC_E_UNKNOWN_ERROR; } // Receive the response @@ -978,7 +973,8 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) free(buffer); afc_unlock(client); - return IPHONE_E_SUCCESS; + + return ret; } /** Locks or unlocks a file on the phone. @@ -992,13 +988,15 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) * AFC_LOCK_SH (shared lock), AFC_LOCK_EX (exclusive lock), * or AFC_LOCK_UN (unlock). */ -iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t operation) +afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation) { - if (!client || (handle == 0)) - return IPHONE_E_INVALID_ARG; char *buffer = malloc(16); int bytes = 0; uint64_t op = operation; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; + + if (!client || (handle == 0)) + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -1010,14 +1008,14 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t client->afc_packet->operation = AFC_OP_FILE_LOCK; client->afc_packet->entire_length = client->afc_packet->this_length = 0; - bytes = dispatch_AFC_packet(client, buffer, 16); + bytes = afc_dispatch_packet(client, buffer, 16); free(buffer); buffer = NULL; if (bytes <= 0) { afc_unlock(client); log_debug_msg("%s: could not send lock command\n", __func__); - return IPHONE_E_UNKNOWN_ERROR; + return AFC_E_UNKNOWN_ERROR; } // Receive the response bytes = receive_AFC_data(client, &buffer); @@ -1026,10 +1024,8 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t free(buffer); } afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_AFC_ERROR; - } - return IPHONE_E_SUCCESS; + + return ret; } /** Seeks to a given position of a pre-opened file on the phone. @@ -1039,13 +1035,17 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t * @param offset Seek offset. * @param whence Seeking direction, one of SEEK_SET, SEEK_CUR, or SEEK_END. * - * @return IPHONE_E_SUCCESS on success, IPHONE_E_NOT_ENOUGH_DATA on failure. + * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure. */ -iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offset, int whence) +afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) { char *buffer = (char *) malloc(sizeof(char) * 24); uint32_t zero = 0; int bytes = 0; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; + + if (!client || (handle == 0)) + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -1056,13 +1056,13 @@ iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offse memcpy(buffer + 16, &offset, sizeof(uint64_t)); // offset client->afc_packet->operation = AFC_OP_FILE_SEEK; client->afc_packet->this_length = client->afc_packet->entire_length = 0; - bytes = dispatch_AFC_packet(client, buffer, 24); + bytes = afc_dispatch_packet(client, buffer, 24); free(buffer); buffer = NULL; if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive response bytes = receive_AFC_data(client, &buffer); @@ -1088,10 +1088,14 @@ iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offse * @note This function is more akin to ftruncate than truncate, and truncate * calls would have to open the file before calling this, sadly. */ -iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t newsize) +afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) { char *buffer = (char *) malloc(sizeof(char) * 16); int bytes = 0; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; + + if (!client || (handle == 0)) + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -1100,13 +1104,13 @@ iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t memcpy(buffer + 8, &newsize, sizeof(uint64_t)); // newsize client->afc_packet->operation = AFC_OP_FILE_SET_SIZE; client->afc_packet->this_length = client->afc_packet->entire_length = 0; - bytes = dispatch_AFC_packet(client, buffer, 16); + bytes = afc_dispatch_packet(client, buffer, 16); free(buffer); buffer = NULL; if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive response bytes = receive_AFC_data(client, &buffer); @@ -1115,10 +1119,7 @@ iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_AFC_ERROR; - } - return IPHONE_E_SUCCESS; + return ret; } /** Sets the size of a file on the phone without prior opening it. @@ -1127,18 +1128,19 @@ iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t * @param path The path of the file to be truncated. * @param newsize The size to set the file to. * - * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG - * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. + * @return AFC_E_SUCCESS if everything went well, AFC_E_INVALID_ARGUMENT + * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) +afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); int bytes = 0; uint64_t size_requested = newsize; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !path || !client->afc_packet || client->sfd < 0) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -1147,11 +1149,11 @@ iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize memcpy(send + 8, path, strlen(path) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; client->afc_packet->operation = AFC_OP_TRUNCATE; - bytes = dispatch_AFC_packet(client, send, 8 + strlen(path) + 1); + bytes = afc_dispatch_packet(client, send, 8 + strlen(path) + 1); free(send); if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive response bytes = receive_AFC_data(client, &response); @@ -1160,10 +1162,7 @@ iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_AFC_ERROR; - } - return IPHONE_E_SUCCESS; + return ret; } /** Creates a hard link or symbolic link on the device. @@ -1173,18 +1172,19 @@ iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize * @param target The file to be linked. * @param linkname The name of link. * - * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG - * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. + * @return AFC_E_SUCCESS if everything went well, AFC_E_INVALID_ARGUMENT + * if arguments are NULL or invalid, AFC_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname) +afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); int bytes = 0; uint64_t type = linktype; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; if (!client || !target || !linkname || !client->afc_packet || client->sfd < 0) - return IPHONE_E_INVALID_ARG; + return AFC_E_INVALID_ARGUMENT; afc_lock(client); @@ -1198,11 +1198,11 @@ iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, cons memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); client->afc_packet->entire_length = client->afc_packet->this_length = 0; client->afc_packet->operation = AFC_OP_MAKE_LINK; - bytes = dispatch_AFC_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1); + bytes = afc_dispatch_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1); free(send); if (bytes <= 0) { afc_unlock(client); - return IPHONE_E_NOT_ENOUGH_DATA; + return AFC_E_NOT_ENOUGH_DATA; } // Receive response bytes = receive_AFC_data(client, &response); @@ -1211,9 +1211,5 @@ iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, cons afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_NOT_ENOUGH_DATA; - } else { - return IPHONE_E_SUCCESS; - } + return ret; } diff --git a/src/AFC.h b/src/AFC.h index a0ce0ef..909e8c3 100644 --- a/src/AFC.h +++ b/src/AFC.h @@ -26,6 +26,8 @@ #include #include +#include "libiphone/afc.h" + #define AFC_MAGIC "CFA6LPAA" #define AFC_MAGIC_LEN (8) -- cgit v1.1-32-gdbae From 8415e1f13dfc8c31fe4d1ff695af26189297795b Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 03:46:13 +0200 Subject: Remove AFC to errno conversion and make afc_receive_data() return AFC errors --- include/libiphone/afc.h | 2 - src/AFC.c | 242 ++++++++++++++++-------------------------------- src/AFC.h | 2 - 3 files changed, 81 insertions(+), 165 deletions(-) diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 4b024a1..18bf32d 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -86,8 +86,6 @@ typedef struct afc_client_int *afc_client_t; /* Interface */ afc_error_t afc_client_new(iphone_device_t device, int dst_port, afc_client_t *client); afc_error_t afc_client_free(afc_client_t client); -int afc_get_afcerror ( afc_client_t client ); -int afc_get_errno ( afc_client_t client ); afc_error_t afc_get_device_info(afc_client_t client, char ***infos); afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list); afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char ***infolist); diff --git a/src/AFC.c b/src/AFC.c index 95ce0a1..87ce78e 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -21,7 +21,6 @@ #include #include -#include #include #include "AFC.h" @@ -112,91 +111,7 @@ afc_error_t afc_client_free(afc_client_t client) g_mutex_free(client->mutex); } free(client); - return IPHONE_E_SUCCESS; -} - -/** - * Returns the AFC error code that has been sent by the device if - * an error occured (set inside receive_AFC_data) - * - * @param client AFC client for that the error value is to be retrieved. - * - * @return AFC error code or -1 on error. - */ -int afc_get_afcerror(afc_client_t client) -{ - int res = -1; - if (client) { - afc_lock(client); - res = client->afcerror; - afc_unlock(client); - } - return res; -} - -/** - * Tries to convert the AFC error value into a meaningful errno value. - * Internally used by afc_get_errno. - * - * @param afcerror AFC error value to convert - * - * @return errno value or -1 if the errno could not be determined. - * - * @see afc_get_errno - */ -static int afcerror_to_errno(int afcerror) -{ - int res = -1; - switch (afcerror) { - case 0: // ERROR_SUCCESS, this means no error. - res = 0; - break; - case 4: // occurs if you try to open a file as directory - res = ENOTDIR; - break; - case 7: // occurs e.g. if you try to close a file handle that - // does not belong to an open file - res = EINVAL; - break; - case 8: // occurs if you try to open a non-existent file - res = ENOENT; - break; - case 9: // occurs if you try to open a directory as file - res = EISDIR; - break; - case 10: // occurs if you try to open a file without permission - res = EPERM; - break; - case 19: // occurs if you try to lock an already locked file - res = EWOULDBLOCK; - break; - default: // we'll assume it's an errno value, but report it - log_debug_msg("WARNING: unknown AFC error %d, perhaps it's '%s'?\n", afcerror, strerror(afcerror)); - res = afcerror; - break; - } - - log_debug_msg("Mapped AFC error %d to errno %d: %s\n", afcerror, res, strerror(res)); - - return res; -} - -/** - * Returns the client's AFC error code converted to an errno value. - * - * @param client AFC client for that the errno value is to be retrieved. - * - * @return errno value or -1 on error. - */ -int afc_get_errno(afc_client_t client) -{ - int res = -1; - if (client) { - afc_lock(client); - res = afcerror_to_errno(client->afcerror); - afc_unlock(client); - } - return res; + return AFC_E_SUCCESS; } /** Dispatches an AFC packet over a client. @@ -294,28 +209,26 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l * received raised a non-trivial error condition (i.e. non-zero with * AFC_ERROR operation) */ -static int receive_AFC_data(afc_client_t client, char **dump_here) +static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *bytes) { AFCPacket header; - int bytes = 0; uint32_t entire_len = 0; uint32_t this_len = 0; uint32_t current_count = 0; uint64_t param1 = -1; - // reset internal afc error value - client->afcerror = 0; + *bytes = 0; - // first, read the AFC header - usbmuxd_recv(client->sfd, (char*)&header, sizeof(AFCPacket), (uint32_t*)&bytes); - if (bytes <= 0) { + /* first, read the AFC header */ + usbmuxd_recv(client->sfd, (char*)&header, sizeof(AFCPacket), (uint32_t*)bytes); + if (*bytes <= 0) { log_debug_msg("%s: Just didn't get enough.\n", __func__); *dump_here = NULL; - return -1; - } else if ((uint32_t)bytes < sizeof(AFCPacket)) { + return AFC_E_MUX_ERROR; + } else if ((uint32_t)*bytes < sizeof(AFCPacket)) { log_debug_msg("%s: Did not even get the AFCPacket header\n", __func__); *dump_here = NULL; - return -1; + return AFC_E_MUX_ERROR; } /* check if it's a valid AFC header */ @@ -328,23 +241,23 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) /* otherwise print a warning but do not abort */ log_debug_msg("%s: ERROR: Unexpected packet number (%lld != %lld) aborting.\n", __func__, header.packet_num, client->afc_packet->packet_num); *dump_here = NULL; - return -1; + return AFC_E_OP_HEADER_INVALID; } /* then, read the attached packet */ if (header.this_length < sizeof(AFCPacket)) { log_debug_msg("%s: Invalid AFCPacket header received!\n", __func__); *dump_here = NULL; - return -1; + return AFC_E_OP_HEADER_INVALID; } else if ((header.this_length == header.entire_length) && header.entire_length == sizeof(AFCPacket)) { log_debug_msg("%s: Empty AFCPacket received!\n", __func__); *dump_here = NULL; + *bytes = 0; if (header.operation == AFC_OP_DATA) { - return 0; + return AFC_E_SUCCESS; } else { - client->afcerror = EIO; - return -1; + return AFC_E_IO_ERROR; } } @@ -360,17 +273,17 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) *dump_here = (char*)malloc(entire_len); if (this_len > 0) { - usbmuxd_recv(client->sfd, *dump_here, this_len, (uint32_t*)&bytes); - if (bytes <= 0) { + usbmuxd_recv(client->sfd, *dump_here, this_len, (uint32_t*)bytes); + if (*bytes <= 0) { free(*dump_here); *dump_here = NULL; log_debug_msg("%s: Did not get packet contents!\n", __func__); - return -1; - } else if ((uint32_t)bytes < this_len) { + return AFC_E_NOT_ENOUGH_DATA; + } else if ((uint32_t)*bytes < this_len) { free(*dump_here); *dump_here = NULL; log_debug_msg("%s: Could not receive this_len=%d bytes\n", __func__, this_len); - return -1; + return AFC_E_NOT_ENOUGH_DATA; } } @@ -378,12 +291,12 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) if (entire_len > this_len) { while (current_count < entire_len) { - usbmuxd_recv(client->sfd, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)&bytes); - if (bytes <= 0) { - log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, bytes); + usbmuxd_recv(client->sfd, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)bytes); + if (*bytes <= 0) { + log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes); break; } - current_count += bytes; + current_count += *bytes; } if (current_count < entire_len) { log_debug_msg("%s: WARNING: could not receive full packet (read %s, size %d)\n", __func__, current_count, entire_len); @@ -394,39 +307,42 @@ static int receive_AFC_data(afc_client_t client, char **dump_here) param1 = *(uint64_t*)(*dump_here); } - // check for errors - if (header.operation == AFC_OP_DATA) { - // we got a positive response! - log_debug_msg("%s: got a success response\n", __func__); - } else if (header.operation == AFC_OP_FILE_OPEN_RES) { - // we got a file handle response - log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); - } else if (header.operation == AFC_OP_STATUS) { - // error message received - if (param1 == 0) { - // ERROR_SUCCESS, this is not an error! - log_debug_msg("%s: ERROR_SUCCESS\n", __func__); - } else { - // but this is an error! - log_debug_msg("%s: ERROR %lld\n", __func__, param1); + log_debug_msg("%s: packet data size = %i\n", __func__, current_count); + log_debug_msg("%s: packet data follows\n", __func__); + log_debug_buffer(*dump_here, current_count); + + /* check operation types */ + if (header.operation == AFC_OP_STATUS) { + /* status response */ + log_debug_msg("%s: got a status response, code=%lld\n", __func__, param1); + + if (param1 != AFC_E_SUCCESS) { + /* error status */ + /* free buffer */ free(*dump_here); *dump_here = NULL; - // store error value - client->afcerror = (int)param1; - afcerror_to_errno(client->afcerror); - return -1; + return (afc_error_t)param1; } + } else if (header.operation == AFC_OP_DATA) { + /* data response */ + log_debug_msg("%s: got a data response\n", __func__); + } else if (header.operation == AFC_OP_FILE_OPEN_RES) { + /* file handle response */ + log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); } else { /* unknown operation code received */ free(*dump_here); *dump_here = NULL; + *bytes = 0; log_debug_msg("%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); - return -1; + return AFC_E_OP_NOT_SUPPORTED; } - return current_count; + + *bytes = current_count; + return AFC_E_SUCCESS; } static int count_nullspaces(char *string, int number) @@ -489,15 +405,13 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis return AFC_E_NOT_ENOUGH_DATA; } // Receive the data - bytes = receive_AFC_data(client, &data); - if (bytes < 0) { + ret = afc_receive_data(client, &data, &bytes); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); - return IPHONE_E_AFC_ERROR; + return ret; } // Parse the data list_loc = make_strings_list(data, bytes); - if (list_loc) - ret = IPHONE_E_SUCCESS; if (data) free(data); @@ -534,10 +448,10 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) return AFC_E_NOT_ENOUGH_DATA; } // Receive the data - bytes = receive_AFC_data(client, &data); - if (bytes < 0) { + ret = afc_receive_data(client, &data, &bytes); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); - return IPHONE_E_AFC_ERROR; + return ret; } // Parse the data list = make_strings_list(data, bytes); @@ -579,7 +493,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path) return AFC_E_NOT_ENOUGH_DATA; } // Receive response - bytes = receive_AFC_data(client, &response); + ret = afc_receive_data(client, &response, &bytes); if (response) free(response); @@ -621,7 +535,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t return AFC_E_NOT_ENOUGH_DATA; } // Receive response - bytes = receive_AFC_data(client, &response); + ret = afc_receive_data(client, &response, &bytes); if (response) free(response); @@ -659,7 +573,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) return AFC_E_NOT_ENOUGH_DATA; } // Receive response - bytes = receive_AFC_data(client, &response); + ret = afc_receive_data(client, &response, &bytes); if (response) free(response); @@ -696,14 +610,12 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf afc_dispatch_packet(client, path, strlen(path)+1); // Receive data - length = receive_AFC_data(client, &received); + ret = afc_receive_data(client, &received, &bytes); if (received) { *infolist = make_strings_list(received, bytes); free(received); } - log_debug_msg("%s: Didn't get any further data\n", __func__); - afc_unlock(client); return ret; @@ -754,8 +666,8 @@ afc_file_open(afc_client_t client, const char *filename, return AFC_E_NOT_ENOUGH_DATA; } // Receive the data - length = receive_AFC_data(client, &data); - if (length > 0 && data) { + ret = afc_receive_data(client, &data, &bytes); + if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) { afc_unlock(client); // Get the file handle @@ -764,6 +676,8 @@ afc_file_open(afc_client_t client, const char *filename, return ret; } + log_debug_msg("%s: Didn't get any further data\n", __func__); + afc_unlock(client); return ret; @@ -811,9 +725,10 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint return AFC_E_NOT_ENOUGH_DATA; } // Receive the data - bytes_loc = receive_AFC_data(client, &input); - log_debug_msg("%s: bytes returned: %i\n", __func__, bytes_loc); - if (bytes_loc < 0) { + ret = afc_receive_data(client, &input, &bytes_loc); + log_debug_msg("%s: afc_receive_data returned error: %d\n", __func__, ret); + log_debug_msg("%s: bytes returned: %i\n", __func__, bytes_loc); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return ret; } else if (bytes_loc == 0) { @@ -887,8 +802,8 @@ afc_file_write(afc_client_t client, uint64_t handle, out_buffer = NULL; current_count += bytes_loc; - bytes_loc = receive_AFC_data(client, &acknowledgement); - if (bytes_loc < 0) { + ret = afc_receive_data(client, &acknowledgement, &bytes_loc); + if (ret != AFC_E_SUCCESS) { afc_unlock(client); return ret; } else { @@ -925,9 +840,9 @@ afc_file_write(afc_client_t client, uint64_t handle, } zero = bytes_loc; - bytes_loc = receive_AFC_data(client, &acknowledgement); + ret = afc_receive_data(client, &acknowledgement, &bytes_loc); afc_unlock(client); - if (bytes_loc < 0) { + if (ret != AFC_E_SUCCESS) { log_debug_msg("%s: uh oh?\n", __func__); } else { free(acknowledgement); @@ -968,7 +883,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) } // Receive the response - bytes = receive_AFC_data(client, &buffer); + ret = afc_receive_data(client, &buffer, &bytes); if (buffer) free(buffer); @@ -1018,7 +933,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op return AFC_E_UNKNOWN_ERROR; } // Receive the response - bytes = receive_AFC_data(client, &buffer); + ret = afc_receive_data(client, &buffer, &bytes); if (buffer) { log_debug_buffer(buffer, bytes); free(buffer); @@ -1065,7 +980,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, return AFC_E_NOT_ENOUGH_DATA; } // Receive response - bytes = receive_AFC_data(client, &buffer); + ret = afc_receive_data(client, &buffer, &bytes); if (buffer) free(buffer); @@ -1074,7 +989,12 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, if (bytes < 0) { return IPHONE_E_AFC_ERROR; } - return IPHONE_E_SUCCESS; + if (buffer) + free(buffer); + + afc_unlock(client); + + return ret; } /** Sets the size of a file on the phone. @@ -1113,7 +1033,7 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new return AFC_E_NOT_ENOUGH_DATA; } // Receive response - bytes = receive_AFC_data(client, &buffer); + ret = afc_receive_data(client, &buffer, &bytes); if (buffer) free(buffer); @@ -1156,7 +1076,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) return AFC_E_NOT_ENOUGH_DATA; } // Receive response - bytes = receive_AFC_data(client, &response); + ret = afc_receive_data(client, &response, &bytes); if (response) free(response); @@ -1205,7 +1125,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c return AFC_E_NOT_ENOUGH_DATA; } // Receive response - bytes = receive_AFC_data(client, &response); + ret = afc_receive_data(client, &response, &bytes); if (response) free(response); diff --git a/src/AFC.h b/src/AFC.h index 909e8c3..7ed6bd8 100644 --- a/src/AFC.h +++ b/src/AFC.h @@ -50,7 +50,6 @@ struct afc_client_int { AFCPacket *afc_packet; int file_handle; int lock; - int afcerror; GMutex *mutex; }; @@ -86,4 +85,3 @@ enum { AFC_OP_MAKE_LINK = 0x0000001C // MakeLink }; -static int afcerror_to_errno(int afcerror); -- cgit v1.1-32-gdbae From 0e255cfe381caedf0375e6834021333d971f8050 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 03:46:54 +0200 Subject: Implement afc_file_tell() and adjust afc_receive_data() to handle it --- dev/afccheck.c | 9 +++++++-- include/libiphone/afc.h | 1 + src/AFC.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/dev/afccheck.c b/dev/afccheck.c index d06a147..a9b666e 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -45,6 +45,8 @@ void check_afc(gpointer data) int *buf = (int *) malloc(buffersize); int *buf2 = (int *) malloc(buffersize); unsigned int bytes = 0; + uint64_t position = 0; + //fill buffer int i = 0; for (i = 0; i < BUFFER_SIZE; i++) { @@ -65,9 +67,12 @@ void check_afc(gpointer data) //now read it bytes = 0; afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); - afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); + afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes); + afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes); + if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position)) + printf("Tell operation failed\n"); afc_file_close(((param *) data)->afc, file); - if (bytes != buffersize) + if (position != buffersize) printf("Read operation failed\n"); //compare buffers diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 18bf32d..08122a1 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -96,6 +96,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence); +afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position); afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize); afc_error_t afc_remove_path(afc_client_t client, const char *path); afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to); diff --git a/src/AFC.c b/src/AFC.c index 87ce78e..6a6d3f2 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -329,6 +329,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int * } else if (header.operation == AFC_OP_FILE_OPEN_RES) { /* file handle response */ log_debug_msg("%s: got a file handle response, handle=%lld\n", __func__, param1); + } else if (header.operation == AFC_OP_FILE_TELL_RES) { + /* tell response */ + log_debug_msg("%s: got a tell response, position=%lld\n", __func__, param1); } else { /* unknown operation code received */ free(*dump_here); @@ -986,8 +989,46 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, afc_unlock(client); - if (bytes < 0) { - return IPHONE_E_AFC_ERROR; + return ret; +} + +/** Returns current position in a pre-opened file on the phone. + * + * @param client The client to use. + * @param handle File handle of a previously opened file. + * @param position Position in bytes of indicator + * + * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure. + */ +afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) +{ + char *buffer = (char *) malloc(sizeof(char) * 8); + int bytes = 0; + afc_error_t ret = AFC_E_UNKNOWN_ERROR; + + if (!client || (handle == 0)) + return AFC_E_INVALID_ARGUMENT; + + afc_lock(client); + + // Send the command + memcpy(buffer, &handle, sizeof(uint64_t)); // handle + client->afc_packet->operation = AFC_OP_FILE_TELL; + client->afc_packet->this_length = client->afc_packet->entire_length = 0; + bytes = afc_dispatch_packet(client, buffer, 8); + free(buffer); + buffer = NULL; + + if (bytes <= 0) { + afc_unlock(client); + return AFC_E_NOT_ENOUGH_DATA; + } + + // Receive the data + ret = afc_receive_data(client, &buffer, &bytes); + if (bytes > 0 && buffer) { + /* Get the position */ + memcpy(position, buffer, sizeof(uint64_t)); } if (buffer) free(buffer); -- cgit v1.1-32-gdbae From da94f0ebc7232e8e9d0e629fe559b7bc93d9a1c6 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 18:12:49 +0200 Subject: Update doxygen config and allow generation of documentation --- doxygen.cfg | 269 ++++++++++++++++++++++++--------- include/libiphone/afc.h | 6 +- include/libiphone/libiphone.h | 7 +- include/libiphone/lockdown.h | 7 +- include/libiphone/mobilesync.h | 8 +- include/libiphone/notification_proxy.h | 6 +- 6 files changed, 218 insertions(+), 85 deletions(-) diff --git a/doxygen.cfg b/doxygen.cfg index 990802c..0942031 100644 --- a/doxygen.cfg +++ b/doxygen.cfg @@ -1,4 +1,4 @@ -# Doxyfile 1.5.3 +# Doxyfile 1.5.6 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project @@ -14,11 +14,11 @@ # Project related configuration options #--------------------------------------------------------------------------- -# This tag specifies the encoding used for all characters in the config file that -# follow. The default is UTF-8 which is also the encoding used for all text before -# the first occurrence of this tag. Doxygen uses libiconv (or the iconv built into -# libc) for the transcoding. See http://www.gnu.org/software/libiconv for the list of -# possible encodings. +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. DOXYFILE_ENCODING = UTF-8 @@ -31,7 +31,7 @@ PROJECT_NAME = libiphone # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 0.1.0 +PROJECT_NUMBER = 0.9.1 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. @@ -54,10 +54,11 @@ CREATE_SUBDIRS = NO # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hungarian, -# Italian, Japanese, Japanese-en (Japanese with English messages), Korean, -# Korean-en, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian, -# Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian. +# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, +# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, +# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, +# and Ukrainian. OUTPUT_LANGUAGE = English @@ -113,7 +114,7 @@ FULL_PATH_NAMES = YES # If left blank the directory from which doxygen is run is used as the # path to strip. -STRIP_FROM_PATH = +STRIP_FROM_PATH = include # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells @@ -195,14 +196,26 @@ ALIASES = OPTIMIZE_OUTPUT_FOR_C = YES # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for Java. -# For instance, namespaces will be presented as packages, qualified scopes -# will look different, etc. +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to -# include (a tag file for) the STL sources as input, then you should +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should # set this tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. # func(std::string) {}). This also make the inheritance and collaboration @@ -215,6 +228,21 @@ BUILTIN_STL_SUPPORT = NO CPP_CLI_SUPPORT = NO +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate getter +# and setter methods for a property. Setting this option to YES (the default) +# will make doxygen to replace the get and set methods by a property in the +# documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default @@ -228,7 +256,17 @@ DISTRIBUTE_GROUP_DOC = NO # NO to prevent subgrouping. Alternatively, this can be done per class using # the \nosubgrouping command. -SUBGROUPING = YES +SUBGROUPING = NO + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = YES #--------------------------------------------------------------------------- # Build related configuration options @@ -239,7 +277,7 @@ SUBGROUPING = YES # Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES -EXTRACT_ALL = YES +EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. @@ -255,7 +293,7 @@ EXTRACT_STATIC = NO # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. -EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_CLASSES = NO # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in @@ -264,10 +302,11 @@ EXTRACT_LOCAL_CLASSES = YES EXTRACT_LOCAL_METHODS = NO -# If this flag is set to YES, the members of anonymous namespaces will be extracted -# and appear in the documentation as a namespace called 'anonymous_namespace{file}', -# where file will be replaced with the base name of the file that contains the anonymous -# namespace. By default anonymous namespace are hidden. +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. EXTRACT_ANON_NSPACES = NO @@ -313,7 +352,7 @@ INTERNAL_DOCS = NO # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. -CASE_SENSE_NAMES = YES +CASE_SENSE_NAMES = NO # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the @@ -325,7 +364,7 @@ HIDE_SCOPE_NAMES = NO # will put a list of the files that are included by a file in the documentation # of that file. -SHOW_INCLUDE_FILES = YES +SHOW_INCLUDE_FILES = NO # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. @@ -346,6 +385,12 @@ SORT_MEMBER_DOCS = YES SORT_BRIEF_DOCS = NO +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be # sorted by fully-qualified names, including namespaces. If set to # NO (the default), the class list will be sorted only by class name, @@ -407,9 +452,21 @@ SHOW_USED_FILES = YES SHOW_DIRECTORIES = NO +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + # The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from the -# version control system). Doxygen will invoke the program by executing (via +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via # popen()) the command , where is the value of # the FILE_VERSION_FILTER tag, and is the name of an input file # provided by doxygen. Whatever the program writes to standard output @@ -477,12 +534,13 @@ WARN_LOGFILE = # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = src +INPUT = src include/libiphone -# This tag can be used to specify the character encoding of the source files that -# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default -# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding. -# See http://www.gnu.org/software/libiconv for the list of possible encodings. +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. INPUT_ENCODING = UTF-8 @@ -491,7 +549,7 @@ INPUT_ENCODING = UTF-8 # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 FILE_PATTERNS = @@ -505,7 +563,7 @@ RECURSIVE = NO # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. -EXCLUDE = src/main.c src/ifuse.c +EXCLUDE = dev # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix filesystem feature) are excluded @@ -522,9 +580,10 @@ EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names -# (namespaces, classes, functions, etc.) that should be excluded from the output. -# The symbol name can be a fully qualified name, a word, or if the wildcard * is used, -# a substring. Examples: ANamespace, AClass, AClass::ANamespace, ANamespace::*Test +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test EXCLUDE_SYMBOLS = @@ -586,11 +645,9 @@ FILTER_SOURCE_FILES = NO # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. # Note: To get rid of all source code in the generated output, make sure also -# VERBATIM_HEADERS is set to NO. If you have enabled CALL_GRAPH or CALLER_GRAPH -# then you must also enable this option. If you don't then doxygen will produce -# a warning and turn it on anyway +# VERBATIM_HEADERS is set to NO. -SOURCE_BROWSER = YES +SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. @@ -603,13 +660,13 @@ INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES -# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# If the REFERENCED_BY_RELATION tag is set to YES # then for each documented function all documented # functions referencing it will be listed. REFERENCED_BY_RELATION = YES -# If the REFERENCES_RELATION tag is set to YES (the default) +# If the REFERENCES_RELATION tag is set to YES # then for each documented function all documented entities # called/used by that function will be listed. @@ -634,7 +691,7 @@ USE_HTAGS = NO # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. -VERBATIM_HEADERS = YES +VERBATIM_HEADERS = NO #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index @@ -709,11 +766,36 @@ HTML_ALIGN_MEMBERS = YES # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. For this to work a browser that supports @@ -742,6 +824,12 @@ HHC_LOCATION = GENERATE_CHI = NO +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag # controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. @@ -764,14 +852,22 @@ DISABLE_INDEX = NO ENUM_VALUES_PER_LINE = 4 -# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be -# generated containing a tree-like index structure (just like the one that +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to FRAME, a side panel will be generated +# containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports # JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, # Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are -# probably better off using the HTML help feature. +# probably better off using the HTML help feature. Other possible values +# for this tag are: HIERARCHIES, which will generate the Groups, Directories, +# and Class Hiererachy pages using a tree view instead of an ordered list; +# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which +# disables this behavior completely. For backwards compatibility with previous +# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE +# respectively. -GENERATE_TREEVIEW = YES +GENERATE_TREEVIEW = NONE # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree @@ -779,6 +875,14 @@ GENERATE_TREEVIEW = YES TREEVIEW_WIDTH = 250 +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- @@ -1031,7 +1135,7 @@ EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. -SEARCH_INCLUDES = YES +SEARCH_INCLUDES = NO # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by @@ -1128,10 +1232,11 @@ PERL_PATH = /usr/bin/perl CLASS_DIAGRAMS = YES # You can define message sequence charts within doxygen comments using the \msc -# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to -# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to -# specify the directory where the mscgen tool resides. If left empty the tool is assumed to -# be found in the default search path. +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. MSCGEN_PATH = @@ -1148,6 +1253,24 @@ HIDE_UNDOC_RELATIONS = YES HAVE_DOT = NO +# By default doxygen will write a font called FreeSans.ttf to the output +# directory and reference it in all dot files that doxygen generates. This +# font does not include all possible unicode characters however, so when you need +# these (or just want a differently looking font) you can specify the font name +# using DOT_FONTNAME. You need need to make sure dot is able to find the font, +# which can be done by putting it in a standard location or by setting the +# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory +# containing the font. + +DOT_FONTNAME = FreeSans + +# By default doxygen will tell dot to use the output directory to look for the +# FreeSans.ttf font (which doxygen will put there itself). If you specify a +# different font using DOT_FONTNAME you can set the path where dot +# can find it using this tag. + +DOT_FONTPATH = + # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the @@ -1192,19 +1315,19 @@ INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES -# If the CALL_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will -# generate a call dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable call graphs for selected -# functions only using the \callgraph command. +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. CALL_GRAPH = NO -# If the CALLER_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will -# generate a caller dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable caller graphs for selected -# functions only using the \callergraph command. +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. CALLER_GRAPH = NO @@ -1237,12 +1360,12 @@ DOT_PATH = DOTFILE_DIRS = -# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of # nodes that will be shown in the graph. If the number of nodes in a graph # becomes larger than this value, doxygen will truncate the graph, which is -# visualized by representing a node as a red box. Note that doxygen if the number -# of direct children of the root node in a graph is already larger than -# MAX_DOT_GRAPH_NOTES then the graph will not be shown at all. Also note +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. DOT_GRAPH_MAX_NODES = 50 @@ -1258,10 +1381,10 @@ DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, which results in a white background. -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to -# read). +# background. This is enabled by default, which results in a transparent +# background. Warning: Depending on the platform used, enabling this option +# may lead to badly anti-aliased labels on the edges of a graph (i.e. they +# become hard to read). DOT_TRANSPARENT = NO diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h index 08122a1..71730cc 100644 --- a/include/libiphone/afc.h +++ b/include/libiphone/afc.h @@ -1,5 +1,7 @@ -/* - * afc.h +/** + * @file libiphone/afc.h + * @brief AFC Implementation + * \internal * * Copyright (c) 2009 Nikias Bassen All Rights Reserved. * diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 014c8bf..1451f15 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -1,6 +1,7 @@ -/* - * libiphone.h - * Main include of libiphone +/** + * @file libiphone/libiphone.h + * @brief Common code and device handling + * \internal * * Copyright (c) 2008 Jonathan Beck All Rights Reserved. * diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h index 55c0cb7..daa5800 100644 --- a/include/libiphone/lockdown.h +++ b/include/libiphone/lockdown.h @@ -1,6 +1,9 @@ -/* - * lockdownd.h +/** + * @file libiphone/lockdown.h + * @brief Communcation with the lockdown device daemon + * \internal * + * Copyright (c) 2008 Zach C. All Rights Reserved. * Copyright (c) 2009 Martin S. All Rights Reserved. * * This library is free software; you can redistribute it and/or diff --git a/include/libiphone/mobilesync.h b/include/libiphone/mobilesync.h index f8fa711..662036c 100644 --- a/include/libiphone/mobilesync.h +++ b/include/libiphone/mobilesync.h @@ -1,7 +1,9 @@ -/* - * mobilesync.h +/** + * @file libiphone/mobilesync.h + * @brief MobileSync Implementation + * \internal * - * Copyright (c) 2009 Martin S. All Rights Reserved. + * Copyright (c) 2009 Jonathan Beck All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h index 520ccd1..66b7a80 100644 --- a/include/libiphone/notification_proxy.h +++ b/include/libiphone/notification_proxy.h @@ -1,5 +1,7 @@ -/* - * notification_proxy.h +/** + * @file libiphone/notification_proxy.h + * @brief Implementation to talk to the notification proxy on a device + * \internal * * Copyright (c) 2009 Nikias Bassen All Rights Reserved. * -- cgit v1.1-32-gdbae From 19c9750d670435ce430f0fc85a55faf127bdfbf9 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Sat, 25 Jul 2009 18:23:54 +0200 Subject: Conform to protocol and add session id argument to lockdownd_stop_session() --- include/libiphone/lockdown.h | 2 +- src/lockdown.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h index daa5800..af58190 100644 --- a/include/libiphone/lockdown.h +++ b/include/libiphone/lockdown.h @@ -60,7 +60,7 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port); -lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client); +lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id); lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); lockdownd_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist); lockdownd_error_t lockdownd_pair(lockdownd_client_t client, char *uuid, char *host_id); diff --git a/src/lockdown.c b/src/lockdown.c index 29e5046..bc430c9 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -129,7 +129,7 @@ static int lockdown_check_result(plist_t dict, const char *query_match) * * @return an error code (LOCKDOWN_E_SUCCESS on success) */ -lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client) +lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id) { if (!client) return LOCKDOWN_E_INVALID_ARG; @@ -140,7 +140,7 @@ lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "StopSession"); plist_add_sub_key_el(dict, "SessionID"); - plist_add_sub_string_el(dict, client->session_id); + plist_add_sub_string_el(dict, session_id); log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); @@ -186,7 +186,7 @@ static lockdownd_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) if (client->in_SSL) { log_dbg_msg(DBGMASK_LOCKDOWND, "%s: stopping SSL session\n", __func__); - ret = lockdownd_stop_session(client); + ret = lockdownd_stop_session(client, client->session_id); log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending SSL close notify\n", __func__); gnutls_bye(*client->ssl_session, GNUTLS_SHUT_RDWR); } -- cgit v1.1-32-gdbae