From a5e6ad39de10ac2c182665f61d0c751372636efb Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Thu, 5 Feb 2009 20:45:39 -0800 Subject: Only merge afc capability onto HAL usb interface node. Signed-off-by: Matt Colyer --- fdi/31-apple-mobile-device.fdi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fdi/31-apple-mobile-device.fdi b/fdi/31-apple-mobile-device.fdi index 3e9ccc9..d598409 100644 --- a/fdi/31-apple-mobile-device.fdi +++ b/fdi/31-apple-mobile-device.fdi @@ -5,11 +5,12 @@ - afc + + afc + - -- cgit v1.1-32-gdbae From aab730841f6bf9fe93383649c2e1e25cea3818a8 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 5 Feb 2009 21:23:07 -0800 Subject: Large file support Signed-off-by: Matt Colyer --- configure.ac | 27 +++++++++++++++++++++++++++ dev/Makefile.am | 4 ++-- src/Makefile.am | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 286b1d8..7c31e2a 100644 --- a/configure.ac +++ b/configure.ac @@ -59,4 +59,31 @@ if test "$no_debug_code" = true; then AC_DEFINE(STRIP_DEBUG_CODE,1,[Strip debug reporting code]) fi +# check for large file support +AC_SYS_LARGEFILE +LFS_CFLAGS='' +if test "$enable_largefile" != no; then + if test "$ac_cv_sys_file_offset_bits" != 'no'; then + LFS_CFLAGS="$LFS_CFLAGS -D_FILE_OFFSET_BITS=$ac_cv_sys_file_offset_bits" + else + AC_MSG_CHECKING(for native large file support) + AC_RUN_IFELSE([#include + int main (int argc, char **argv) + { + exit(!(sizeof(off_t) == 8)); + }], + [ac_cv_sys_file_offset_bits=64; AC_DEFINE(_FILE_OFFSET_BITS,64) + AC_MSG_RESULT(yes)], + [AC_MSG_RESULT(no)]) + fi + if test "$ac_cv_sys_large_files" != 'no'; then + LFS_CFLAGS="$LFS_CFLAGS -D_LARGE_FILES=1" + fi + AC_FUNC_FSEEKO + if test "$ac_cv_sys_largefile_source" != 'no'; then + LFS_CFLAGS="$LFS_CFLAGS -D_LARGEFILE_SOURCE=1" + fi +fi +AC_SUBST(LFS_CFLAGS) + AC_OUTPUT(Makefile src/Makefile include/Makefile fdi/Makefile dev/Makefile libiphone-1.0.pc) diff --git a/dev/Makefile.am b/dev/Makefile.am index 4833728..5f85ad7 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -1,6 +1,6 @@ INCLUDES = -I$(top_srcdir)/include -AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g +AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g $(LFS_CFLAGS) AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) bin_PROGRAMS = iphoneclient lckd-client afccheck @@ -16,4 +16,4 @@ lckd_client_LDADD = ../src/libiphone.la afccheck_SOURCES = afccheck.c afccheck_CFLAGS = $(AM_CFLAGS) afccheck_LDFLAGS = $(AM_LDFLAGS) -afccheck_LDADD = ../src/libiphone.la \ No newline at end of file +afccheck_LDADD = ../src/libiphone.la diff --git a/src/Makefile.am b/src/Makefile.am index 382be1f..2661ed6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ INCLUDES = -I$(top_srcdir)/include -AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g -Wall +AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g -Wall $(LFS_CFLAGS) AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) bin_PROGRAMS = libiphone-initconf -- cgit v1.1-32-gdbae From 927a6d3d437ca4532f8e9e906089b3a24542ebd3 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 8 Mar 2009 11:57:58 -0700 Subject: Adds the iphone_afc_truncate function and fixes a small log_debug issue. Signed-off-by: Matt Colyer --- include/libiphone/libiphone.h | 1 + src/AFC.c | 49 ++++++++++++++++++++++++++++++++++++++++++- src/AFC.h | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 32d47d3..158fd84 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -118,6 +118,7 @@ iphone_error_t iphone_afc_truncate_file ( iphone_afc_client_t client, iphone_afc 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); #ifdef __cplusplus diff --git a/src/AFC.c b/src/AFC.c index cd24cc6..dc8fe20 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -179,7 +179,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int 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(data + offset); + log_debug_buffer(data + offset, length - offset); iphone_mux_send(client->connection, data + offset, length - offset, &bytes); return bytes; @@ -1017,6 +1017,53 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, iphone_afc_f } } +/** Sets the size of a file on the phone without prior opening it. + * + * @param client The client to use to set the file size. + * @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. + */ +iphone_error_t iphone_afc_truncate(iphone_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; + + if (!client || !path || !client->afc_packet || !client->connection) + return IPHONE_E_INVALID_ARG; + + afc_lock(client); + + // Send command + 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; + bytes = dispatch_AFC_packet(client, send, 8 + strlen(path)); + free(send); + if (bytes <= 0) { + afc_unlock(client); + return IPHONE_E_NOT_ENOUGH_DATA; + } + // Receive response + bytes = receive_AFC_data(client, &response); + if (response) + free(response); + + afc_unlock(client); + + if (bytes < 0) { + return IPHONE_E_NOT_ENOUGH_DATA; + } else { + return IPHONE_E_SUCCESS; + } +} + + uint32 iphone_afc_get_file_handle(iphone_afc_file_t file) { return file->filehandle; diff --git a/src/AFC.h b/src/AFC.h index 463c13e..de4e071 100644 --- a/src/AFC.h +++ b/src/AFC.h @@ -63,6 +63,7 @@ enum { AFC_LIST_DIR = 0x00000003, AFC_MAKE_DIR = 0x00000009, AFC_DELETE = 0x00000008, + AFC_TRUNCATE = 0x00000007, AFC_RENAME = 0x00000018, AFC_SUCCESS_RESPONSE = 0x00000002, AFC_FILE_OPEN = 0x0000000d, -- cgit v1.1-32-gdbae From 774c3ed001a48a52cceb450bca292dd6112d683f Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 8 Mar 2009 12:13:03 -0700 Subject: Adds ability to show notification screen to the user. Signed-off-by: Matt Colyer --- dev/main.c | 59 +++++++++++++++++++++++++++++++++++++++++++ include/libiphone/libiphone.h | 4 +++ src/AFC.c | 57 +++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/NotificationProxy.h | 30 ++++++++++++++++++++++ 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/NotificationProxy.h diff --git a/dev/main.c b/dev/main.c index 2dbfb4a..c68427b 100644 --- a/dev/main.c +++ b/dev/main.c @@ -29,12 +29,51 @@ #include +void perform_syncWillStart(iphone_device_t phone, iphone_lckd_client_t control) +{ + int nport = 0; + iphone_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, 3555, nport, &np); + if (np) { + printf("::::::::: PostNotification com.apple.itunes-mobdev.syncWillStart\n"); + iphone_np_post_notification(np, "com.apple.itunes-mobdev.syncWillStart"); + iphone_np_free_client(np); + } + } else { + printf("::::::::::::::: np was NOT started ::::::::::::\n"); + } +} + +void perform_syncDidStart(iphone_device_t phone, iphone_lckd_client_t control) +{ + int nport = 0; + iphone_np_client_t np; + + iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); + if (nport) { + printf("::::::::::::::: np was started ::::::::::::\n"); + sleep(1); + iphone_np_new_client(phone, 3555, nport, &np); + if (np) { + printf("::::::::: PostNotification com.apple.itunes-mobdev.syncDidStart\n"); + iphone_np_post_notification(np, "com.apple.itunes-mobdev.syncDidStart"); + iphone_np_free_client(np); + } + } else { + printf("::::::::::::::: np was NOT started ::::::::::::\n"); + } +} int main(int argc, char *argv[]) { int bytes = 0, port = 0, i = 0; iphone_lckd_client_t control = NULL; iphone_device_t phone = NULL; + iphone_afc_file_t lockfile = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) { iphone_set_debug(1); @@ -64,6 +103,16 @@ int main(int argc, char *argv[]) iphone_afc_client_t afc = NULL; iphone_afc_new_client(phone, 3432, port, &afc); if (afc) { + perform_syncWillStart(phone, control); + + iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", IPHONE_AFC_FILE_WRITE, &lockfile); + if (lockfile) { + printf("locking file\n"); + iphone_afc_lock_file(afc, lockfile, 2 | 4); + + perform_syncDidStart(phone, control); + } + char **dirs = NULL; iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); if (!dirs) @@ -138,7 +187,17 @@ int main(int argc, char *argv[]) printf("Couldn't read!\n"); free(threeletterword); iphone_afc_close_file(afc, my_file); + } + + if (lockfile) { + printf("XXX sleeping 2 seconds\n"); + sleep(2); + + printf("XXX unlocking file\n"); + iphone_afc_lock_file(afc, lockfile, 8 | 4); + printf("XXX closing file\n"); + iphone_afc_close_file(afc, lockfile); } iphone_afc_free_client(afc); } else { diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 158fd84..7d9c223 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -77,6 +77,9 @@ typedef struct iphone_afc_client_int *iphone_afc_client_t; struct iphone_afc_file_int; typedef struct iphone_afc_file_int *iphone_afc_file_t; +struct iphone_np_client_int; +typedef struct iphone_np_client_int *iphone_np_client_t; + //device related functions void iphone_set_debug(int level); iphone_error_t iphone_get_device ( iphone_device_t *device ); @@ -111,6 +114,7 @@ iphone_error_t iphone_afc_get_dir_list ( iphone_afc_client_t client, const char iphone_error_t iphone_afc_get_file_attr ( iphone_afc_client_t client, const char *filename, struct stat *stbuf ); iphone_error_t iphone_afc_open_file ( iphone_afc_client_t client, const char *filename, iphone_afc_file_mode_t file_mode, iphone_afc_file_t *file ); iphone_error_t iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file); +iphone_error_t iphone_afc_lock_file ( iphone_afc_client_t client, iphone_afc_file_t file, int operation); iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_file_t file, char *data, int length, uint32_t *bytes); iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, const char *data, int length, uint32_t *bytes); iphone_error_t iphone_afc_seek_file ( iphone_afc_client_t client, iphone_afc_file_t file, int seekpos); diff --git a/src/AFC.c b/src/AFC.c index dc8fe20..af07b56 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -917,6 +917,63 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file return IPHONE_E_SUCCESS; } +/** Locks or unlocks a file on the phone. + * + * makes use of flock, 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 file A pointer to an AFCFile struct containing the file handle of the + * file to close. + * @operation the lock or unlock operation to perform. + */ +iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, iphone_afc_file_t file, int operation) +{ + if (!client || !file) + return IPHONE_E_INVALID_ARG; + char *buffer = malloc(16); + uint32 zero = 0; + int bytes = 0; + uint64_t op = operation; + + afc_lock(client); + + log_debug_msg("afc_lock_file: File handle %i\n", file->filehandle); + + // Send command + memcpy(buffer, &file->filehandle, sizeof(uint32)); + memcpy(buffer + sizeof(uint32), &zero, sizeof(zero)); + memcpy(buffer + 8, &op, 8); + + client->afc_packet->operation = AFC_FILE_LOCK; + client->afc_packet->entire_length = client->afc_packet->this_length = 0; + bytes = dispatch_AFC_packet(client, buffer, 15); + free(buffer); + buffer = NULL; + + if (bytes <= 0) { + afc_unlock(client); + log_debug_msg("fuck\n"); + return IPHONE_E_UNKNOWN_ERROR; + } + // Receive the response + bytes = receive_AFC_data(client, &buffer); + log_debug_msg("%s: receiving response (%d bytes)\n", __func__, bytes); + if (buffer) { + log_debug_buffer(buffer, bytes); + free(buffer); + } + afc_unlock(client); + return IPHONE_E_SUCCESS; +} + /** Seeks to a given position of a pre-opened file on the phone. * * @param client The client to use to seek to the position. diff --git a/src/Makefile.am b/src/Makefile.am index 2661ed6..76b15ec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,4 +12,4 @@ libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) $(AM_LDFLAGS) lib_LTLIBRARIES = libiphone.la -libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c utils.c +libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c NotificationProxy.c userpref.c utils.c diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h new file mode 100644 index 0000000..7b47346 --- /dev/null +++ b/src/NotificationProxy.h @@ -0,0 +1,30 @@ +/* + * NotificationProxy.h + * Notification Proxy header file. + * + * 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 + */ +#include "usbmux.h" +#include "iphone.h" + +#include + +struct iphone_np_client_int { + iphone_umux_client_t connection; + GMutex *mutex; +}; + -- cgit v1.1-32-gdbae From d85a44994876b2c1f5b457e8f72c6edb3e32a365 Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Mon, 9 Mar 2009 18:44:30 -0700 Subject: Add forgotten file. --- src/NotificationProxy.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 src/NotificationProxy.c diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c new file mode 100644 index 0000000..b0c10ea --- /dev/null +++ b/src/NotificationProxy.c @@ -0,0 +1,256 @@ +/* + * NotificationProxy.c + * Notification Proxy implementation. + * + * 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 + */ + +#include +#include "NotificationProxy.h" +#include "plist.h" +#include "utils.h" + +/** Locks an NP client, done for thread safety stuff. + * + * @param client The NP + */ +static void np_lock(iphone_np_client_t client) +{ + log_debug_msg("NP: Locked\n"); + g_mutex_lock(client->mutex); +} + +/** Unlocks an NP client, done for thread safety stuff. + * + * @param client The NP + */ +static void np_unlock(iphone_np_client_t client) +{ + log_debug_msg("NP: Unlocked\n"); + g_mutex_unlock(client->mutex); +} + +/** Makes a connection to the NP service on the phone. + * + * @param phone The iPhone to connect on. + * @param s_port The source port. + * @param d_port The destination port. + * + * @return A handle to the newly-connected client or NULL upon error. + */ +iphone_error_t iphone_np_new_client ( iphone_device_t device, int src_port, int dst_port, iphone_np_client_t *client ) +{ + int ret = IPHONE_E_SUCCESS; + + //makes sure thread environment is available + if (!g_thread_supported()) + g_thread_init(NULL); + iphone_np_client_t client_loc = (iphone_np_client_t) malloc(sizeof(struct iphone_np_client_int)); + + if (!device) + return IPHONE_E_INVALID_ARG; + + // Attempt connection + client_loc->connection = NULL; + ret = iphone_mux_new_client(device, src_port, dst_port, &client_loc->connection); + if (IPHONE_E_SUCCESS != ret || !client_loc->connection) { + free(client_loc); + return ret; + } + + client_loc->mutex = g_mutex_new(); + + *client = client_loc; + return IPHONE_E_SUCCESS; +} + +/** Disconnects an NP client from the phone. + * + * @param client The client to disconnect. + */ +iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) +{ + if (!client || !client->connection ) + return IPHONE_E_INVALID_ARG; + + iphone_mux_free_client(client->connection); + free(client); + return IPHONE_E_SUCCESS; +} + +/** Sends a notification to the NP client. + * + * notification messages seen so far: + * com.apple.itunes-mobdev.syncWillStart + * com.apple.itunes-mobdev.syncDidStart + * + * @param client The client to send to + * @param notification The notification Message + */ +iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) +{ + xmlDocPtr plist; + xmlNode *dict, *key; + char *XML_content; + uint32_t length; + int bytes; + iphone_error_t ret; + unsigned char sndbuf[4096]; + int sndlen = 0; + int nlen; + + if (!client || !notification) { + return IPHONE_E_INVALID_ARG; + } + np_lock(client); + + plist = new_plist(); + dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); + key = add_key_str_dict_element(plist, dict, "Command", "PostNotification", 1); + key = add_key_str_dict_element(plist, dict, "Name", notification, 1); + xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); + + nlen = htonl(length); + + memcpy(sndbuf+sndlen, &nlen, 4); + sndlen += 4; + memcpy(sndbuf+sndlen, XML_content, length); + sndlen += length; + + xmlFree(XML_content); + xmlFreeDoc(plist); + + plist = new_plist(); + dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); + key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1); + xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); + + nlen = htonl(length); + + memcpy(sndbuf+sndlen, &nlen, 4); + sndlen+=4; + + memcpy(sndbuf+sndlen, XML_content, length); + sndlen+=length; + + xmlFree(XML_content); + xmlFreeDoc(plist); + plist = NULL; + + log_debug_buffer(sndbuf, sndlen); + + iphone_mux_send(client->connection, sndbuf, sndlen, &bytes); + if (bytes <= 0) { + np_unlock(client); + return bytes; + } + + np_unlock(client); + return bytes; +} + +/** Notifies the iphone to send a notification on certain events. + * + * observation messages seen so far: + * com.apple.itunes-client.syncCancelRequest + * com.apple.itunes-client.syncSuspendRequest + * com.apple.itunes-client.syncResumeRequest + * com.apple.mobile.lockdown.phone_number_changed + * com.apple.mobile.lockdown.device_name_changed + * com.apple.springboard.attemptactivation + * com.apple.mobile.data_sync.domain_changed + * com.apple.mobile.application_installed + * com.apple.mobile.application_uninstalled + * + * @param client The client to send to + */ +iphone_error_t iphone_np_observe_notification( iphone_np_client_t client ) +{ + xmlDocPtr plist; + xmlNode *dict, *key; + char *XML_content; + uint32_t length; + int bytes; + iphone_error_t ret; + unsigned char sndbuf[4096]; + int sndlen = 0; + int nlen; + int i=0; + char *notifications[10] = { + "com.apple.itunes-client.syncCancelRequest", + "com.apple.itunes-client.syncSuspendRequest", + "com.apple.itunes-client.syncResumeRequest", + "com.apple.mobile.lockdown.phone_number_changed", + "com.apple.mobile.lockdown.device_name_changed", + "com.apple.springboard.attemptactivation", + "com.apple.mobile.data_sync.domain_changed", + "com.apple.mobile.application_installed", + "com.apple.mobile.application_uninstalled", + NULL}; + + sndlen = 0; + + if (!client) { + return IPHONE_E_INVALID_ARG; + } + np_lock(client); + + while (notifications[i]) { + plist = new_plist(); + dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); + key = add_key_str_dict_element(plist, dict, "Command", "ObserveNotification", 1); + key = add_key_str_dict_element(plist, dict, "Name", notifications[i++], 1); + xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); + + nlen = htonl(length); + memcpy(sndbuf+sndlen, &nlen, 4); + sndlen += 4; + memcpy(sndbuf+sndlen, XML_content, length); + sndlen += length; + + xmlFree(XML_content); + xmlFreeDoc(plist); + } + + plist = new_plist(); + dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); + key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1); + xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); + + nlen = htonl(length); + + memcpy(sndbuf+sndlen, &nlen, 4); + sndlen+=4; + + memcpy(sndbuf+sndlen, XML_content, length); + sndlen+=length; + + xmlFree(XML_content); + xmlFreeDoc(plist); + plist = NULL; + + log_debug_buffer(sndbuf, sndlen); + + iphone_mux_send(client->connection, sndbuf, sndlen, &bytes); + if (bytes <= 0) { + np_unlock(client); + return bytes; + } + + np_unlock(client); + return bytes; +} -- cgit v1.1-32-gdbae From 201e1ff5bf2054fcb1c0cc3cd7ba1e229dbde3fa Mon Sep 17 00:00:00 2001 From: Zach C Date: Wed, 11 Mar 2009 22:04:38 -0700 Subject: Fixes a compile error and two usbmux bugs Signed-off-by: Matt Colyer --- src/AFC.h | 41 +++++++++++++++++++++++++++-------------- src/usbmux.c | 7 ++++--- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/AFC.h b/src/AFC.h index de4e071..62ec659 100644 --- a/src/AFC.h +++ b/src/AFC.h @@ -58,21 +58,34 @@ struct iphone_afc_file_int { enum { AFC_ERROR = 0x00000001, - AFC_GET_INFO = 0x0000000a, - AFC_GET_DEVINFO = 0x0000000b, - AFC_LIST_DIR = 0x00000003, - AFC_MAKE_DIR = 0x00000009, - AFC_DELETE = 0x00000008, - AFC_TRUNCATE = 0x00000007, - AFC_RENAME = 0x00000018, AFC_SUCCESS_RESPONSE = 0x00000002, - AFC_FILE_OPEN = 0x0000000d, - AFC_FILE_CLOSE = 0x00000014, - AFC_FILE_SEEK = 0x00000011, - AFC_FILE_TRUNCATE = 0x00000015, - AFC_FILE_HANDLE = 0x0000000e, - AFC_READ = 0x0000000f, - AFC_WRITE = 0x00000010 + 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 }; uint32 iphone_afc_get_file_handle(iphone_afc_file_t file); + diff --git a/src/usbmux.c b/src/usbmux.c index c7ac7ef..d8e6b44 100644 --- a/src/usbmux.c +++ b/src/usbmux.c @@ -309,7 +309,8 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t } // Since we were able to fill the data straight from our buffer, we can just return datalen. See 2a above. - return datalen; + *recv_bytes = datalen; + return IPHONE_E_SUCCESS; } else { memcpy(data, client->recv_buffer, client->r_len); free(client->recv_buffer); // don't need to deal with anymore, but... @@ -361,10 +362,10 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t if ((bytes - 28) > datalen) { // Copy what we need into the data, buffer the rest because we can. memcpy(data + offset, buffer + 28, datalen); // data+offset: see #2b, above - complex = client->r_len + (bytes - 28) - datalen; + complex = client->r_len + ((bytes - 28) - datalen); client->recv_buffer = (char *) realloc(client->recv_buffer, (sizeof(char) * complex)); client->r_len = complex; - complex = client->r_len - (bytes - 28) - datalen; + complex = client->r_len - ((bytes - 28) - datalen); memcpy(client->recv_buffer + complex, buffer + 28 + datalen, (bytes - 28) - datalen); free(buffer); client->header->ocnt += bytes - 28; -- cgit v1.1-32-gdbae