summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dev/main.c59
-rw-r--r--include/libiphone/libiphone.h4
-rw-r--r--src/AFC.c57
-rw-r--r--src/Makefile.am2
-rw-r--r--src/NotificationProxy.h30
5 files changed, 151 insertions, 1 deletions
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 <libiphone/libiphone.h>
+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 <glib.h>
+
+struct iphone_np_client_int {
+ iphone_umux_client_t connection;
+ GMutex *mutex;
+};
+