diff options
| author | 2009-03-16 21:40:33 +0100 | |
|---|---|---|
| committer | 2009-03-16 21:40:33 +0100 | |
| commit | 19992c668afeb53a28e08a1f61572b5379f87590 (patch) | |
| tree | 4f1784b81afe88a6240889961b5fc3d2b0d6a82e /src | |
| parent | 0d05f8de79ee91e9be80c6296eff9ce216582ba4 (diff) | |
| parent | 201e1ff5bf2054fcb1c0cc3cd7ba1e229dbde3fa (diff) | |
| download | libimobiledevice-19992c668afeb53a28e08a1f61572b5379f87590.tar.gz libimobiledevice-19992c668afeb53a28e08a1f61572b5379f87590.tar.bz2 | |
Merge branch 'master' into contact_sync
Conflicts:
configure.ac
dev/Makefile.am
include/libiphone/libiphone.h
src/AFC.c
src/AFC.h
src/Makefile.am
Diffstat (limited to 'src')
| -rw-r--r-- | src/AFC.c | 106 | ||||
| -rw-r--r-- | src/AFC.h | 40 | ||||
| -rw-r--r-- | src/Makefile.am | 4 | ||||
| -rw-r--r-- | src/NotificationProxy.c | 263 | ||||
| -rw-r--r-- | src/NotificationProxy.h | 31 | ||||
| -rw-r--r-- | src/usbmux.c | 7 |
6 files changed, 432 insertions, 19 deletions
| @@ -178,7 +178,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int | |||
| 178 | log_debug_msg("dispatch_AFC_packet: sent the first now go with the second\n"); | 178 | log_debug_msg("dispatch_AFC_packet: sent the first now go with the second\n"); |
| 179 | log_debug_msg("Length: %i\n", length - offset); | 179 | log_debug_msg("Length: %i\n", length - offset); |
| 180 | log_debug_msg("Buffer: \n"); | 180 | log_debug_msg("Buffer: \n"); |
| 181 | log_debug_msg(data + offset); | 181 | log_debug_buffer(data + offset, length - offset); |
| 182 | 182 | ||
| 183 | iphone_mux_send(client->connection, data + offset, length - offset, &bytes); | 183 | iphone_mux_send(client->connection, data + offset, length - offset, &bytes); |
| 184 | return bytes; | 184 | return bytes; |
| @@ -916,6 +916,63 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file | |||
| 916 | return IPHONE_E_SUCCESS; | 916 | return IPHONE_E_SUCCESS; |
| 917 | } | 917 | } |
| 918 | 918 | ||
| 919 | /** Locks or unlocks a file on the phone. | ||
| 920 | * | ||
| 921 | * makes use of flock, see | ||
| 922 | * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html | ||
| 923 | * | ||
| 924 | * operation (same as in sys/file.h on linux): | ||
| 925 | * | ||
| 926 | * LOCK_SH 1 // shared lock | ||
| 927 | * LOCK_EX 2 // exclusive lock | ||
| 928 | * LOCK_NB 4 // don't block when locking | ||
| 929 | * LOCK_UN 8 // unlock | ||
| 930 | * | ||
| 931 | * @param client The client to close the file with. | ||
| 932 | * @param file A pointer to an AFCFile struct containing the file handle of the | ||
| 933 | * file to close. | ||
| 934 | * @operation the lock or unlock operation to perform. | ||
| 935 | */ | ||
| 936 | iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, iphone_afc_file_t file, int operation) | ||
| 937 | { | ||
| 938 | if (!client || !file) | ||
| 939 | return IPHONE_E_INVALID_ARG; | ||
| 940 | char *buffer = malloc(16); | ||
| 941 | uint32_t zero = 0; | ||
| 942 | int bytes = 0; | ||
| 943 | uint64_t op = operation; | ||
| 944 | |||
| 945 | afc_lock(client); | ||
| 946 | |||
| 947 | log_debug_msg("afc_lock_file: File handle %i\n", file->filehandle); | ||
| 948 | |||
| 949 | // Send command | ||
| 950 | memcpy(buffer, &file->filehandle, sizeof(uint32_t)); | ||
| 951 | memcpy(buffer + sizeof(uint32_t), &zero, sizeof(zero)); | ||
| 952 | memcpy(buffer + 8, &op, 8); | ||
| 953 | |||
| 954 | client->afc_packet->operation = AFC_FILE_LOCK; | ||
| 955 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | ||
| 956 | bytes = dispatch_AFC_packet(client, buffer, 15); | ||
| 957 | free(buffer); | ||
| 958 | buffer = NULL; | ||
| 959 | |||
| 960 | if (bytes <= 0) { | ||
| 961 | afc_unlock(client); | ||
| 962 | log_debug_msg("fuck\n"); | ||
| 963 | return IPHONE_E_UNKNOWN_ERROR; | ||
| 964 | } | ||
| 965 | // Receive the response | ||
| 966 | bytes = receive_AFC_data(client, &buffer); | ||
| 967 | log_debug_msg("%s: receiving response (%d bytes)\n", __func__, bytes); | ||
| 968 | if (buffer) { | ||
| 969 | log_debug_buffer(buffer, bytes); | ||
| 970 | free(buffer); | ||
| 971 | } | ||
| 972 | afc_unlock(client); | ||
| 973 | return IPHONE_E_SUCCESS; | ||
| 974 | } | ||
| 975 | |||
| 919 | /** Seeks to a given position of a pre-opened file on the phone. | 976 | /** Seeks to a given position of a pre-opened file on the phone. |
| 920 | * | 977 | * |
| 921 | * @param client The client to use to seek to the position. | 978 | * @param client The client to use to seek to the position. |
| @@ -1016,6 +1073,53 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, iphone_afc_f | |||
| 1016 | } | 1073 | } |
| 1017 | } | 1074 | } |
| 1018 | 1075 | ||
| 1076 | /** Sets the size of a file on the phone without prior opening it. | ||
| 1077 | * | ||
| 1078 | * @param client The client to use to set the file size. | ||
| 1079 | * @param path The path of the file to be truncated. | ||
| 1080 | * @param newsize The size to set the file to. | ||
| 1081 | * | ||
| 1082 | * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG | ||
| 1083 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. | ||
| 1084 | */ | ||
| 1085 | iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize) | ||
| 1086 | { | ||
| 1087 | char *response = NULL; | ||
| 1088 | char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); | ||
| 1089 | int bytes = 0; | ||
| 1090 | uint64_t size_requested = newsize; | ||
| 1091 | |||
| 1092 | if (!client || !path || !client->afc_packet || !client->connection) | ||
| 1093 | return IPHONE_E_INVALID_ARG; | ||
| 1094 | |||
| 1095 | afc_lock(client); | ||
| 1096 | |||
| 1097 | // Send command | ||
| 1098 | memcpy(send, &size_requested, 8); | ||
| 1099 | memcpy(send + 8, path, strlen(path) + 1); | ||
| 1100 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | ||
| 1101 | client->afc_packet->operation = AFC_TRUNCATE; | ||
| 1102 | bytes = dispatch_AFC_packet(client, send, 8 + strlen(path)); | ||
| 1103 | free(send); | ||
| 1104 | if (bytes <= 0) { | ||
| 1105 | afc_unlock(client); | ||
| 1106 | return IPHONE_E_NOT_ENOUGH_DATA; | ||
| 1107 | } | ||
| 1108 | // Receive response | ||
| 1109 | bytes = receive_AFC_data(client, &response); | ||
| 1110 | if (response) | ||
| 1111 | free(response); | ||
| 1112 | |||
| 1113 | afc_unlock(client); | ||
| 1114 | |||
| 1115 | if (bytes < 0) { | ||
| 1116 | return IPHONE_E_NOT_ENOUGH_DATA; | ||
| 1117 | } else { | ||
| 1118 | return IPHONE_E_SUCCESS; | ||
| 1119 | } | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | |||
| 1019 | uint32_t iphone_afc_get_file_handle(iphone_afc_file_t file) | 1123 | uint32_t iphone_afc_get_file_handle(iphone_afc_file_t file) |
| 1020 | { | 1124 | { |
| 1021 | return file->filehandle; | 1125 | return file->filehandle; |
| @@ -58,20 +58,34 @@ struct iphone_afc_file_int { | |||
| 58 | 58 | ||
| 59 | enum { | 59 | enum { |
| 60 | AFC_ERROR = 0x00000001, | 60 | AFC_ERROR = 0x00000001, |
| 61 | AFC_GET_INFO = 0x0000000a, | ||
| 62 | AFC_GET_DEVINFO = 0x0000000b, | ||
| 63 | AFC_LIST_DIR = 0x00000003, | ||
| 64 | AFC_MAKE_DIR = 0x00000009, | ||
| 65 | AFC_DELETE = 0x00000008, | ||
| 66 | AFC_RENAME = 0x00000018, | ||
| 67 | AFC_SUCCESS_RESPONSE = 0x00000002, | 61 | AFC_SUCCESS_RESPONSE = 0x00000002, |
| 68 | AFC_FILE_OPEN = 0x0000000d, | 62 | AFC_LIST_DIR = 0x00000003, // ReadDir |
| 69 | AFC_FILE_CLOSE = 0x00000014, | 63 | // 0x00000004 // ReadFile |
| 70 | AFC_FILE_SEEK = 0x00000011, | 64 | // 0x00000005 // WriteFile |
| 71 | AFC_FILE_TRUNCATE = 0x00000015, | 65 | // 0x00000006 // WritePart |
| 72 | AFC_FILE_HANDLE = 0x0000000e, | 66 | AFC_TRUNCATE = 0x00000007, // Truncate |
| 73 | AFC_READ = 0x0000000f, | 67 | AFC_DELETE = 0x00000008, // RemovePath |
| 74 | AFC_WRITE = 0x00000010 | 68 | AFC_MAKE_DIR = 0x00000009, // MakeDir |
| 69 | AFC_GET_INFO = 0x0000000a, // GetFileInfo | ||
| 70 | AFC_GET_DEVINFO = 0x0000000b, // GetDeviceInfo | ||
| 71 | // 0x0000000c // same as 5, but writes to temp file, then renames it. | ||
| 72 | AFC_FILE_OPEN = 0x0000000d, // FileRefOpen | ||
| 73 | AFC_FILE_HANDLE = 0x0000000e, // _unknownPacket | ||
| 74 | AFC_READ = 0x0000000f, // FileRefRead | ||
| 75 | AFC_WRITE = 0x00000010, // FileRefWrite | ||
| 76 | AFC_FILE_SEEK = 0x00000011, // FileRefSeek | ||
| 77 | AFC_FILE_TELL = 0x00000012, // FileRefTell | ||
| 78 | // 0x00000013 // _unknownPacket | ||
| 79 | AFC_FILE_CLOSE = 0x00000014, // FileRefClose | ||
| 80 | AFC_FILE_TRUNCATE = 0x00000015, // FileRefSetFileSize (ftruncate) | ||
| 81 | // 0x00000016 // SetFatalError | ||
| 82 | // 0x00000017 // SetConnectionOptions | ||
| 83 | AFC_RENAME = 0x00000018, // RenamePath | ||
| 84 | // 0x00000019 // SetFSBlockSize (0x800000) | ||
| 85 | // 0x0000001A // SetBlockSize (0x800000) | ||
| 86 | AFC_FILE_LOCK = 0x0000001B, // FileRefLock | ||
| 87 | AFC_MAKE_LINK = 0x0000001C // MakeLink | ||
| 75 | }; | 88 | }; |
| 76 | 89 | ||
| 90 | |||
| 77 | uint32_t iphone_afc_get_file_handle(iphone_afc_file_t file); | 91 | uint32_t iphone_afc_get_file_handle(iphone_afc_file_t file); |
diff --git a/src/Makefile.am b/src/Makefile.am index 039632f..71667ae 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | INCLUDES = -I$(top_srcdir)/include | 1 | INCLUDES = -I$(top_srcdir)/include |
| 2 | 2 | ||
| 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(libplist_CFLAGS) -g | 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) |
| 4 | AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) | 4 | AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) |
| 5 | 5 | ||
| 6 | bin_PROGRAMS = libiphone-initconf | 6 | bin_PROGRAMS = libiphone-initconf |
| @@ -12,4 +12,4 @@ libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) $(AM_LDFLAGS) | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | lib_LTLIBRARIES = libiphone.la | 14 | lib_LTLIBRARIES = libiphone.la |
| 15 | libiphone_la_SOURCES = usbmux.c iphone.c lockdown.c AFC.c userpref.c utils.c MobileSync.c | 15 | libiphone_la_SOURCES = usbmux.c iphone.c lockdown.c AFC.c NotificationProxy.c userpref.c utils.c MobileSync.c |
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c new file mode 100644 index 0000000..eec7857 --- /dev/null +++ b/src/NotificationProxy.c | |||
| @@ -0,0 +1,263 @@ | |||
| 1 | /* | ||
| 2 | * NotificationProxy.c | ||
| 3 | * Notification Proxy implementation. | ||
| 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 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <plist/plist.h> | ||
| 24 | #include "NotificationProxy.h" | ||
| 25 | #include "utils.h" | ||
| 26 | |||
| 27 | /** Locks an NP client, done for thread safety stuff. | ||
| 28 | * | ||
| 29 | * @param client The NP | ||
| 30 | */ | ||
| 31 | static void np_lock(iphone_np_client_t client) | ||
| 32 | { | ||
| 33 | log_debug_msg("NP: Locked\n"); | ||
| 34 | g_mutex_lock(client->mutex); | ||
| 35 | } | ||
| 36 | |||
| 37 | /** Unlocks an NP client, done for thread safety stuff. | ||
| 38 | * | ||
| 39 | * @param client The NP | ||
| 40 | */ | ||
| 41 | static void np_unlock(iphone_np_client_t client) | ||
| 42 | { | ||
| 43 | log_debug_msg("NP: Unlocked\n"); | ||
| 44 | g_mutex_unlock(client->mutex); | ||
| 45 | } | ||
| 46 | |||
| 47 | /** Makes a connection to the NP service on the phone. | ||
| 48 | * | ||
| 49 | * @param phone The iPhone to connect on. | ||
| 50 | * @param s_port The source port. | ||
| 51 | * @param d_port The destination port. | ||
| 52 | * | ||
| 53 | * @return A handle to the newly-connected client or NULL upon error. | ||
| 54 | */ | ||
| 55 | iphone_error_t iphone_np_new_client ( iphone_device_t device, int src_port, int dst_port, iphone_np_client_t *client ) | ||
| 56 | { | ||
| 57 | int ret = IPHONE_E_SUCCESS; | ||
| 58 | |||
| 59 | //makes sure thread environment is available | ||
| 60 | if (!g_thread_supported()) | ||
| 61 | g_thread_init(NULL); | ||
| 62 | iphone_np_client_t client_loc = (iphone_np_client_t) malloc(sizeof(struct iphone_np_client_int)); | ||
| 63 | |||
| 64 | if (!device) | ||
| 65 | return IPHONE_E_INVALID_ARG; | ||
| 66 | |||
| 67 | // Attempt connection | ||
| 68 | client_loc->connection = NULL; | ||
| 69 | ret = iphone_mux_new_client(device, src_port, dst_port, &client_loc->connection); | ||
| 70 | if (IPHONE_E_SUCCESS != ret || !client_loc->connection) { | ||
| 71 | free(client_loc); | ||
| 72 | return ret; | ||
| 73 | } | ||
| 74 | |||
| 75 | client_loc->mutex = g_mutex_new(); | ||
| 76 | |||
| 77 | *client = client_loc; | ||
| 78 | return IPHONE_E_SUCCESS; | ||
| 79 | } | ||
| 80 | |||
| 81 | /** Disconnects an NP client from the phone. | ||
| 82 | * | ||
| 83 | * @param client The client to disconnect. | ||
| 84 | */ | ||
| 85 | iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) | ||
| 86 | { | ||
| 87 | if (!client || !client->connection ) | ||
| 88 | return IPHONE_E_INVALID_ARG; | ||
| 89 | |||
| 90 | iphone_mux_free_client(client->connection); | ||
| 91 | free(client); | ||
| 92 | return IPHONE_E_SUCCESS; | ||
| 93 | } | ||
| 94 | |||
| 95 | /** Sends a notification to the NP client. | ||
| 96 | * | ||
| 97 | * notification messages seen so far: | ||
| 98 | * com.apple.itunes-mobdev.syncWillStart | ||
| 99 | * com.apple.itunes-mobdev.syncDidStart | ||
| 100 | * | ||
| 101 | * @param client The client to send to | ||
| 102 | * @param notification The notification Message | ||
| 103 | */ | ||
| 104 | iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) | ||
| 105 | { | ||
| 106 | char *XML_content = NULL; | ||
| 107 | uint32_t length = 0; | ||
| 108 | int bytes = 0; | ||
| 109 | iphone_error_t ret; | ||
| 110 | unsigned char sndbuf[4096]; | ||
| 111 | int sndlen = 0; | ||
| 112 | int nlen = 0; | ||
| 113 | plist_t dict = NULL; | ||
| 114 | |||
| 115 | if (!client || !notification) { | ||
| 116 | return IPHONE_E_INVALID_ARG; | ||
| 117 | } | ||
| 118 | np_lock(client); | ||
| 119 | |||
| 120 | dict = plist_new_dict(); | ||
| 121 | plist_add_sub_key_el(dict, "Command"); | ||
| 122 | plist_add_sub_string_el(dict, "PostNotification"); | ||
| 123 | plist_add_sub_key_el(dict, "Name"); | ||
| 124 | plist_add_sub_string_el(dict, notification); | ||
| 125 | plist_to_xml(dict, &XML_content, &length); | ||
| 126 | |||
| 127 | nlen = htonl(length); | ||
| 128 | |||
| 129 | memcpy(sndbuf+sndlen, &nlen, 4); | ||
| 130 | sndlen += 4; | ||
| 131 | memcpy(sndbuf+sndlen, XML_content, length); | ||
| 132 | sndlen += length; | ||
| 133 | |||
| 134 | plist_free(dict); | ||
| 135 | dict = NULL; | ||
| 136 | free(XML_content); | ||
| 137 | XML_content = NULL; | ||
| 138 | |||
| 139 | dict = plist_new_dict(); | ||
| 140 | plist_add_sub_key_el(dict, "Command"); | ||
| 141 | plist_add_sub_string_el(dict, "Shutdown"); | ||
| 142 | plist_to_xml(dict, &XML_content, &length); | ||
| 143 | |||
| 144 | nlen = htonl(length); | ||
| 145 | |||
| 146 | memcpy(sndbuf+sndlen, &nlen, 4); | ||
| 147 | sndlen+=4; | ||
| 148 | |||
| 149 | memcpy(sndbuf+sndlen, XML_content, length); | ||
| 150 | sndlen+=length; | ||
| 151 | |||
| 152 | plist_free(dict); | ||
| 153 | dict = NULL; | ||
| 154 | free(XML_content); | ||
| 155 | XML_content = NULL; | ||
| 156 | |||
| 157 | log_debug_buffer(sndbuf, sndlen); | ||
| 158 | |||
| 159 | iphone_mux_send(client->connection, sndbuf, sndlen, &bytes); | ||
| 160 | if (bytes <= 0) { | ||
| 161 | np_unlock(client); | ||
| 162 | return bytes; | ||
| 163 | } | ||
| 164 | |||
| 165 | np_unlock(client); | ||
| 166 | return bytes; | ||
| 167 | } | ||
| 168 | |||
| 169 | /** Notifies the iphone to send a notification on certain events. | ||
| 170 | * | ||
| 171 | * observation messages seen so far: | ||
| 172 | * com.apple.itunes-client.syncCancelRequest | ||
| 173 | * com.apple.itunes-client.syncSuspendRequest | ||
| 174 | * com.apple.itunes-client.syncResumeRequest | ||
| 175 | * com.apple.mobile.lockdown.phone_number_changed | ||
| 176 | * com.apple.mobile.lockdown.device_name_changed | ||
| 177 | * com.apple.springboard.attemptactivation | ||
| 178 | * com.apple.mobile.data_sync.domain_changed | ||
| 179 | * com.apple.mobile.application_installed | ||
| 180 | * com.apple.mobile.application_uninstalled | ||
| 181 | * | ||
| 182 | * @param client The client to send to | ||
| 183 | */ | ||
| 184 | iphone_error_t iphone_np_observe_notification( iphone_np_client_t client ) | ||
| 185 | { | ||
| 186 | plist_t dict = NULL; | ||
| 187 | char *XML_content = NULL; | ||
| 188 | uint32_t length = 0; | ||
| 189 | int bytes = 0; | ||
| 190 | iphone_error_t ret; | ||
| 191 | unsigned char sndbuf[4096]; | ||
| 192 | int sndlen = 0; | ||
| 193 | int nlen = 0; | ||
| 194 | int i=0; | ||
| 195 | const char *notifications[10] = { | ||
| 196 | "com.apple.itunes-client.syncCancelRequest", | ||
| 197 | "com.apple.itunes-client.syncSuspendRequest", | ||
| 198 | "com.apple.itunes-client.syncResumeRequest", | ||
| 199 | "com.apple.mobile.lockdown.phone_number_changed", | ||
| 200 | "com.apple.mobile.lockdown.device_name_changed", | ||
| 201 | "com.apple.springboard.attemptactivation", | ||
| 202 | "com.apple.mobile.data_sync.domain_changed", | ||
| 203 | "com.apple.mobile.application_installed", | ||
| 204 | "com.apple.mobile.application_uninstalled", | ||
| 205 | NULL}; | ||
| 206 | |||
| 207 | sndlen = 0; | ||
| 208 | |||
| 209 | if (!client) { | ||
| 210 | return IPHONE_E_INVALID_ARG; | ||
| 211 | } | ||
| 212 | np_lock(client); | ||
| 213 | |||
| 214 | while (notifications[i]) { | ||
| 215 | |||
| 216 | dict = plist_new_dict(); | ||
| 217 | plist_add_sub_key_el(dict, "Command"); | ||
| 218 | plist_add_sub_string_el(dict, "ObserveNotification"); | ||
| 219 | plist_add_sub_key_el(dict, "Name"); | ||
| 220 | plist_add_sub_string_el(dict, notifications[i++]); | ||
| 221 | plist_to_xml(dict, &XML_content, &length); | ||
| 222 | |||
| 223 | nlen = htonl(length); | ||
| 224 | memcpy(sndbuf+sndlen, &nlen, 4); | ||
| 225 | sndlen += 4; | ||
| 226 | memcpy(sndbuf+sndlen, XML_content, length); | ||
| 227 | sndlen += length; | ||
| 228 | |||
| 229 | plist_free(dict); | ||
| 230 | dict = NULL; | ||
| 231 | free(XML_content); | ||
| 232 | XML_content = NULL; | ||
| 233 | } | ||
| 234 | |||
| 235 | dict = plist_new_dict(); | ||
| 236 | plist_add_sub_key_el(dict, "Command"); | ||
| 237 | plist_add_sub_string_el(dict, "Shutdown"); | ||
| 238 | plist_to_xml(dict, &XML_content, &length); | ||
| 239 | |||
| 240 | nlen = htonl(length); | ||
| 241 | |||
| 242 | memcpy(sndbuf+sndlen, &nlen, 4); | ||
| 243 | sndlen+=4; | ||
| 244 | |||
| 245 | memcpy(sndbuf+sndlen, XML_content, length); | ||
| 246 | sndlen+=length; | ||
| 247 | |||
| 248 | plist_free(dict); | ||
| 249 | dict = NULL; | ||
| 250 | free(XML_content); | ||
| 251 | XML_content = NULL; | ||
| 252 | |||
| 253 | log_debug_buffer(sndbuf, sndlen); | ||
| 254 | |||
| 255 | iphone_mux_send(client->connection, sndbuf, sndlen, &bytes); | ||
| 256 | if (bytes <= 0) { | ||
| 257 | np_unlock(client); | ||
| 258 | return bytes; | ||
| 259 | } | ||
| 260 | |||
| 261 | np_unlock(client); | ||
| 262 | return bytes; | ||
| 263 | } | ||
diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h new file mode 100644 index 0000000..57ad751 --- /dev/null +++ b/src/NotificationProxy.h | |||
| @@ -0,0 +1,31 @@ | |||
| 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 "libiphone/libiphone.h" | ||
| 22 | #include "usbmux.h" | ||
| 23 | #include "iphone.h" | ||
| 24 | |||
| 25 | #include <glib.h> | ||
| 26 | |||
| 27 | struct iphone_np_client_int { | ||
| 28 | iphone_umux_client_t connection; | ||
| 29 | GMutex *mutex; | ||
| 30 | }; | ||
| 31 | |||
diff --git a/src/usbmux.c b/src/usbmux.c index 5eaa1d1..22ce588 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 | |||
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | // Since we were able to fill the data straight from our buffer, we can just return datalen. See 2a above. | 311 | // Since we were able to fill the data straight from our buffer, we can just return datalen. See 2a above. |
| 312 | return datalen; | 312 | *recv_bytes = datalen; |
| 313 | return IPHONE_E_SUCCESS; | ||
| 313 | } else { | 314 | } else { |
| 314 | memcpy(data, client->recv_buffer, client->r_len); | 315 | memcpy(data, client->recv_buffer, client->r_len); |
| 315 | free(client->recv_buffer); // don't need to deal with anymore, but... | 316 | free(client->recv_buffer); // don't need to deal with anymore, but... |
| @@ -362,10 +363,10 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t | |||
| 362 | if ((bytes - 28) > datalen) { | 363 | if ((bytes - 28) > datalen) { |
| 363 | // Copy what we need into the data, buffer the rest because we can. | 364 | // Copy what we need into the data, buffer the rest because we can. |
| 364 | memcpy(data + offset, buffer + 28, datalen); // data+offset: see #2b, above | 365 | memcpy(data + offset, buffer + 28, datalen); // data+offset: see #2b, above |
| 365 | complex = client->r_len + (bytes - 28) - datalen; | 366 | complex = client->r_len + ((bytes - 28) - datalen); |
| 366 | client->recv_buffer = (char *) realloc(client->recv_buffer, (sizeof(char) * complex)); | 367 | client->recv_buffer = (char *) realloc(client->recv_buffer, (sizeof(char) * complex)); |
| 367 | client->r_len = complex; | 368 | client->r_len = complex; |
| 368 | complex = client->r_len - (bytes - 28) - datalen; | 369 | complex = client->r_len - ((bytes - 28) - datalen); |
| 369 | memcpy(client->recv_buffer + complex, buffer + 28 + datalen, (bytes - 28) - datalen); | 370 | memcpy(client->recv_buffer + complex, buffer + 28 + datalen, (bytes - 28) - datalen); |
| 370 | free(buffer); | 371 | free(buffer); |
| 371 | client->header->ocnt += bytes - 28; | 372 | client->header->ocnt += bytes - 28; |
