summaryrefslogtreecommitdiffstats
path: root/src/NotificationProxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/NotificationProxy.c')
-rw-r--r--src/NotificationProxy.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index eec7857..726852e 100644
--- a/src/NotificationProxy.c
+++ b/src/NotificationProxy.c
@@ -52,7 +52,7 @@ static void np_unlock(iphone_np_client_t client)
52 * 52 *
53 * @return A handle to the newly-connected client or NULL upon error. 53 * @return A handle to the newly-connected client or NULL upon error.
54 */ 54 */
55iphone_error_t iphone_np_new_client ( iphone_device_t device, int src_port, int dst_port, iphone_np_client_t *client ) 55iphone_error_t iphone_np_new_client(iphone_device_t device, int src_port, int dst_port, iphone_np_client_t * client)
56{ 56{
57 int ret = IPHONE_E_SUCCESS; 57 int ret = IPHONE_E_SUCCESS;
58 58
@@ -75,16 +75,16 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int src_port, int
75 client_loc->mutex = g_mutex_new(); 75 client_loc->mutex = g_mutex_new();
76 76
77 *client = client_loc; 77 *client = client_loc;
78 return IPHONE_E_SUCCESS; 78 return IPHONE_E_SUCCESS;
79} 79}
80 80
81/** Disconnects an NP client from the phone. 81/** Disconnects an NP client from the phone.
82 * 82 *
83 * @param client The client to disconnect. 83 * @param client The client to disconnect.
84 */ 84 */
85iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) 85iphone_error_t iphone_np_free_client(iphone_np_client_t client)
86{ 86{
87 if (!client || !client->connection ) 87 if (!client || !client->connection)
88 return IPHONE_E_INVALID_ARG; 88 return IPHONE_E_INVALID_ARG;
89 89
90 iphone_mux_free_client(client->connection); 90 iphone_mux_free_client(client->connection);
@@ -101,7 +101,7 @@ iphone_error_t iphone_np_free_client ( iphone_np_client_t client )
101 * @param client The client to send to 101 * @param client The client to send to
102 * @param notification The notification Message 102 * @param notification The notification Message
103 */ 103 */
104iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) 104iphone_error_t iphone_np_post_notification(iphone_np_client_t client, const char *notification)
105{ 105{
106 char *XML_content = NULL; 106 char *XML_content = NULL;
107 uint32_t length = 0; 107 uint32_t length = 0;
@@ -126,9 +126,9 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
126 126
127 nlen = htonl(length); 127 nlen = htonl(length);
128 128
129 memcpy(sndbuf+sndlen, &nlen, 4); 129 memcpy(sndbuf + sndlen, &nlen, 4);
130 sndlen += 4; 130 sndlen += 4;
131 memcpy(sndbuf+sndlen, XML_content, length); 131 memcpy(sndbuf + sndlen, XML_content, length);
132 sndlen += length; 132 sndlen += length;
133 133
134 plist_free(dict); 134 plist_free(dict);
@@ -143,11 +143,11 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
143 143
144 nlen = htonl(length); 144 nlen = htonl(length);
145 145
146 memcpy(sndbuf+sndlen, &nlen, 4); 146 memcpy(sndbuf + sndlen, &nlen, 4);
147 sndlen+=4; 147 sndlen += 4;
148 148
149 memcpy(sndbuf+sndlen, XML_content, length); 149 memcpy(sndbuf + sndlen, XML_content, length);
150 sndlen+=length; 150 sndlen += length;
151 151
152 plist_free(dict); 152 plist_free(dict);
153 dict = NULL; 153 dict = NULL;
@@ -157,7 +157,7 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
157 log_debug_buffer(sndbuf, sndlen); 157 log_debug_buffer(sndbuf, sndlen);
158 158
159 iphone_mux_send(client->connection, sndbuf, sndlen, &bytes); 159 iphone_mux_send(client->connection, sndbuf, sndlen, &bytes);
160 if (bytes <= 0) { 160 if (bytes <= 0) {
161 np_unlock(client); 161 np_unlock(client);
162 return bytes; 162 return bytes;
163 } 163 }
@@ -181,7 +181,7 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
181 * 181 *
182 * @param client The client to send to 182 * @param client The client to send to
183 */ 183 */
184iphone_error_t iphone_np_observe_notification( iphone_np_client_t client ) 184iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
185{ 185{
186 plist_t dict = NULL; 186 plist_t dict = NULL;
187 char *XML_content = NULL; 187 char *XML_content = NULL;
@@ -191,18 +191,19 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
191 unsigned char sndbuf[4096]; 191 unsigned char sndbuf[4096];
192 int sndlen = 0; 192 int sndlen = 0;
193 int nlen = 0; 193 int nlen = 0;
194 int i=0; 194 int i = 0;
195 const char *notifications[10] = { 195 const char *notifications[10] = {
196 "com.apple.itunes-client.syncCancelRequest", 196 "com.apple.itunes-client.syncCancelRequest",
197 "com.apple.itunes-client.syncSuspendRequest", 197 "com.apple.itunes-client.syncSuspendRequest",
198 "com.apple.itunes-client.syncResumeRequest", 198 "com.apple.itunes-client.syncResumeRequest",
199 "com.apple.mobile.lockdown.phone_number_changed", 199 "com.apple.mobile.lockdown.phone_number_changed",
200 "com.apple.mobile.lockdown.device_name_changed", 200 "com.apple.mobile.lockdown.device_name_changed",
201 "com.apple.springboard.attemptactivation", 201 "com.apple.springboard.attemptactivation",
202 "com.apple.mobile.data_sync.domain_changed", 202 "com.apple.mobile.data_sync.domain_changed",
203 "com.apple.mobile.application_installed", 203 "com.apple.mobile.application_installed",
204 "com.apple.mobile.application_uninstalled", 204 "com.apple.mobile.application_uninstalled",
205 NULL}; 205 NULL
206 };
206 207
207 sndlen = 0; 208 sndlen = 0;
208 209
@@ -221,11 +222,11 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
221 plist_to_xml(dict, &XML_content, &length); 222 plist_to_xml(dict, &XML_content, &length);
222 223
223 nlen = htonl(length); 224 nlen = htonl(length);
224 memcpy(sndbuf+sndlen, &nlen, 4); 225 memcpy(sndbuf + sndlen, &nlen, 4);
225 sndlen += 4; 226 sndlen += 4;
226 memcpy(sndbuf+sndlen, XML_content, length); 227 memcpy(sndbuf + sndlen, XML_content, length);
227 sndlen += length; 228 sndlen += length;
228 229
229 plist_free(dict); 230 plist_free(dict);
230 dict = NULL; 231 dict = NULL;
231 free(XML_content); 232 free(XML_content);
@@ -239,11 +240,11 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
239 240
240 nlen = htonl(length); 241 nlen = htonl(length);
241 242
242 memcpy(sndbuf+sndlen, &nlen, 4); 243 memcpy(sndbuf + sndlen, &nlen, 4);
243 sndlen+=4; 244 sndlen += 4;
244 245
245 memcpy(sndbuf+sndlen, XML_content, length); 246 memcpy(sndbuf + sndlen, XML_content, length);
246 sndlen+=length; 247 sndlen += length;
247 248
248 plist_free(dict); 249 plist_free(dict);
249 dict = NULL; 250 dict = NULL;
@@ -253,7 +254,7 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
253 log_debug_buffer(sndbuf, sndlen); 254 log_debug_buffer(sndbuf, sndlen);
254 255
255 iphone_mux_send(client->connection, sndbuf, sndlen, &bytes); 256 iphone_mux_send(client->connection, sndbuf, sndlen, &bytes);
256 if (bytes <= 0) { 257 if (bytes <= 0) {
257 np_unlock(client); 258 np_unlock(client);
258 return bytes; 259 return bytes;
259 } 260 }