summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-03-08 12:13:03 -0700
committerGravatar Matt Colyer2009-03-08 12:13:03 -0700
commit774c3ed001a48a52cceb450bca292dd6112d683f (patch)
tree98d3d01ecb8bb492d61eaab2dccb90a409bb76ba
parent927a6d3d437ca4532f8e9e906089b3a24542ebd3 (diff)
downloadlibimobiledevice-774c3ed001a48a52cceb450bca292dd6112d683f.tar.gz
libimobiledevice-774c3ed001a48a52cceb450bca292dd6112d683f.tar.bz2
Adds ability to show notification screen to the user.
Signed-off-by: Matt Colyer <matt@colyer.name>
-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 @@
29 29
30#include <libiphone/libiphone.h> 30#include <libiphone/libiphone.h>
31 31
32void perform_syncWillStart(iphone_device_t phone, iphone_lckd_client_t control)
33{
34 int nport = 0;
35 iphone_np_client_t np;
36
37 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport);
38 if (nport) {
39 printf("::::::::::::::: np was started ::::::::::::\n");
40 iphone_np_new_client(phone, 3555, nport, &np);
41 if (np) {
42 printf("::::::::: PostNotification com.apple.itunes-mobdev.syncWillStart\n");
43 iphone_np_post_notification(np, "com.apple.itunes-mobdev.syncWillStart");
44 iphone_np_free_client(np);
45 }
46 } else {
47 printf("::::::::::::::: np was NOT started ::::::::::::\n");
48 }
49}
50
51void perform_syncDidStart(iphone_device_t phone, iphone_lckd_client_t control)
52{
53 int nport = 0;
54 iphone_np_client_t np;
55
56 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport);
57 if (nport) {
58 printf("::::::::::::::: np was started ::::::::::::\n");
59 sleep(1);
60 iphone_np_new_client(phone, 3555, nport, &np);
61 if (np) {
62 printf("::::::::: PostNotification com.apple.itunes-mobdev.syncDidStart\n");
63 iphone_np_post_notification(np, "com.apple.itunes-mobdev.syncDidStart");
64 iphone_np_free_client(np);
65 }
66 } else {
67 printf("::::::::::::::: np was NOT started ::::::::::::\n");
68 }
69}
32 70
33int main(int argc, char *argv[]) 71int main(int argc, char *argv[])
34{ 72{
35 int bytes = 0, port = 0, i = 0; 73 int bytes = 0, port = 0, i = 0;
36 iphone_lckd_client_t control = NULL; 74 iphone_lckd_client_t control = NULL;
37 iphone_device_t phone = NULL; 75 iphone_device_t phone = NULL;
76 iphone_afc_file_t lockfile = NULL;
38 77
39 if (argc > 1 && !strcasecmp(argv[1], "--debug")) { 78 if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
40 iphone_set_debug(1); 79 iphone_set_debug(1);
@@ -64,6 +103,16 @@ int main(int argc, char *argv[])
64 iphone_afc_client_t afc = NULL; 103 iphone_afc_client_t afc = NULL;
65 iphone_afc_new_client(phone, 3432, port, &afc); 104 iphone_afc_new_client(phone, 3432, port, &afc);
66 if (afc) { 105 if (afc) {
106 perform_syncWillStart(phone, control);
107
108 iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", IPHONE_AFC_FILE_WRITE, &lockfile);
109 if (lockfile) {
110 printf("locking file\n");
111 iphone_afc_lock_file(afc, lockfile, 2 | 4);
112
113 perform_syncDidStart(phone, control);
114 }
115
67 char **dirs = NULL; 116 char **dirs = NULL;
68 iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); 117 iphone_afc_get_dir_list(afc, "/eafaedf", &dirs);
69 if (!dirs) 118 if (!dirs)
@@ -138,7 +187,17 @@ int main(int argc, char *argv[])
138 printf("Couldn't read!\n"); 187 printf("Couldn't read!\n");
139 free(threeletterword); 188 free(threeletterword);
140 iphone_afc_close_file(afc, my_file); 189 iphone_afc_close_file(afc, my_file);
190 }
191
192 if (lockfile) {
193 printf("XXX sleeping 2 seconds\n");
194 sleep(2);
195
196 printf("XXX unlocking file\n");
197 iphone_afc_lock_file(afc, lockfile, 8 | 4);
141 198
199 printf("XXX closing file\n");
200 iphone_afc_close_file(afc, lockfile);
142 } 201 }
143 iphone_afc_free_client(afc); 202 iphone_afc_free_client(afc);
144 } else { 203 } 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;
77struct iphone_afc_file_int; 77struct iphone_afc_file_int;
78typedef struct iphone_afc_file_int *iphone_afc_file_t; 78typedef struct iphone_afc_file_int *iphone_afc_file_t;
79 79
80struct iphone_np_client_int;
81typedef struct iphone_np_client_int *iphone_np_client_t;
82
80//device related functions 83//device related functions
81void iphone_set_debug(int level); 84void iphone_set_debug(int level);
82iphone_error_t iphone_get_device ( iphone_device_t *device ); 85iphone_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
111iphone_error_t iphone_afc_get_file_attr ( iphone_afc_client_t client, const char *filename, struct stat *stbuf ); 114iphone_error_t iphone_afc_get_file_attr ( iphone_afc_client_t client, const char *filename, struct stat *stbuf );
112iphone_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 ); 115iphone_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 );
113iphone_error_t iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file); 116iphone_error_t iphone_afc_close_file ( iphone_afc_client_t client, iphone_afc_file_t file);
117iphone_error_t iphone_afc_lock_file ( iphone_afc_client_t client, iphone_afc_file_t file, int operation);
114iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_file_t file, char *data, int length, uint32_t *bytes); 118iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_file_t file, char *data, int length, uint32_t *bytes);
115iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, const char *data, int length, uint32_t *bytes); 119iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_file_t file, const char *data, int length, uint32_t *bytes);
116iphone_error_t iphone_afc_seek_file ( iphone_afc_client_t client, iphone_afc_file_t file, int seekpos); 120iphone_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
917 return IPHONE_E_SUCCESS; 917 return IPHONE_E_SUCCESS;
918} 918}
919 919
920/** Locks or unlocks a file on the phone.
921 *
922 * makes use of flock, see
923 * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html
924 *
925 * operation (same as in sys/file.h on linux):
926 *
927 * LOCK_SH 1 // shared lock
928 * LOCK_EX 2 // exclusive lock
929 * LOCK_NB 4 // don't block when locking
930 * LOCK_UN 8 // unlock
931 *
932 * @param client The client to close the file with.
933 * @param file A pointer to an AFCFile struct containing the file handle of the
934 * file to close.
935 * @operation the lock or unlock operation to perform.
936 */
937iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, iphone_afc_file_t file, int operation)
938{
939 if (!client || !file)
940 return IPHONE_E_INVALID_ARG;
941 char *buffer = malloc(16);
942 uint32 zero = 0;
943 int bytes = 0;
944 uint64_t op = operation;
945
946 afc_lock(client);
947
948 log_debug_msg("afc_lock_file: File handle %i\n", file->filehandle);
949
950 // Send command
951 memcpy(buffer, &file->filehandle, sizeof(uint32));
952 memcpy(buffer + sizeof(uint32), &zero, sizeof(zero));
953 memcpy(buffer + 8, &op, 8);
954
955 client->afc_packet->operation = AFC_FILE_LOCK;
956 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
957 bytes = dispatch_AFC_packet(client, buffer, 15);
958 free(buffer);
959 buffer = NULL;
960
961 if (bytes <= 0) {
962 afc_unlock(client);
963 log_debug_msg("fuck\n");
964 return IPHONE_E_UNKNOWN_ERROR;
965 }
966 // Receive the response
967 bytes = receive_AFC_data(client, &buffer);
968 log_debug_msg("%s: receiving response (%d bytes)\n", __func__, bytes);
969 if (buffer) {
970 log_debug_buffer(buffer, bytes);
971 free(buffer);
972 }
973 afc_unlock(client);
974 return IPHONE_E_SUCCESS;
975}
976
920/** Seeks to a given position of a pre-opened file on the phone. 977/** Seeks to a given position of a pre-opened file on the phone.
921 * 978 *
922 * @param client The client to use to seek to the position. 979 * @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)
12 12
13 13
14lib_LTLIBRARIES = libiphone.la 14lib_LTLIBRARIES = libiphone.la
15libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c utils.c 15libiphone_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 @@
1/*
2 * NotificationProxy.h
3 * Notification Proxy header file.
4 *
5 * Copyright (c) 2009 Nikias Bassen, All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21#include "usbmux.h"
22#include "iphone.h"
23
24#include <glib.h>
25
26struct iphone_np_client_int {
27 iphone_umux_client_t connection;
28 GMutex *mutex;
29};
30