summaryrefslogtreecommitdiffstats
path: root/src/NotificationProxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/NotificationProxy.c')
-rw-r--r--src/NotificationProxy.c93
1 files changed, 50 insertions, 43 deletions
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index b0c10ea..eec7857 100644
--- a/src/NotificationProxy.c
+++ b/src/NotificationProxy.c
@@ -20,8 +20,8 @@
20 */ 20 */
21 21
22#include <stdio.h> 22#include <stdio.h>
23#include <plist/plist.h>
23#include "NotificationProxy.h" 24#include "NotificationProxy.h"
24#include "plist.h"
25#include "utils.h" 25#include "utils.h"
26 26
27/** Locks an NP client, done for thread safety stuff. 27/** Locks an NP client, done for thread safety stuff.
@@ -103,26 +103,26 @@ iphone_error_t iphone_np_free_client ( iphone_np_client_t client )
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 xmlDocPtr plist; 106 char *XML_content = NULL;
107 xmlNode *dict, *key; 107 uint32_t length = 0;
108 char *XML_content; 108 int bytes = 0;
109 uint32_t length;
110 int bytes;
111 iphone_error_t ret; 109 iphone_error_t ret;
112 unsigned char sndbuf[4096]; 110 unsigned char sndbuf[4096];
113 int sndlen = 0; 111 int sndlen = 0;
114 int nlen; 112 int nlen = 0;
113 plist_t dict = NULL;
115 114
116 if (!client || !notification) { 115 if (!client || !notification) {
117 return IPHONE_E_INVALID_ARG; 116 return IPHONE_E_INVALID_ARG;
118 } 117 }
119 np_lock(client); 118 np_lock(client);
120 119
121 plist = new_plist(); 120 dict = plist_new_dict();
122 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 121 plist_add_sub_key_el(dict, "Command");
123 key = add_key_str_dict_element(plist, dict, "Command", "PostNotification", 1); 122 plist_add_sub_string_el(dict, "PostNotification");
124 key = add_key_str_dict_element(plist, dict, "Name", notification, 1); 123 plist_add_sub_key_el(dict, "Name");
125 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 124 plist_add_sub_string_el(dict, notification);
125 plist_to_xml(dict, &XML_content, &length);
126 126
127 nlen = htonl(length); 127 nlen = htonl(length);
128 128
@@ -130,14 +130,16 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
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
134 xmlFree(XML_content);
135 xmlFreeDoc(plist);
136 133
137 plist = new_plist(); 134 plist_free(dict);
138 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 135 dict = NULL;
139 key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1); 136 free(XML_content);
140 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 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);
141 143
142 nlen = htonl(length); 144 nlen = htonl(length);
143 145
@@ -147,9 +149,10 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
147 memcpy(sndbuf+sndlen, XML_content, length); 149 memcpy(sndbuf+sndlen, XML_content, length);
148 sndlen+=length; 150 sndlen+=length;
149 151
150 xmlFree(XML_content); 152 plist_free(dict);
151 xmlFreeDoc(plist); 153 dict = NULL;
152 plist = NULL; 154 free(XML_content);
155 XML_content = NULL;
153 156
154 log_debug_buffer(sndbuf, sndlen); 157 log_debug_buffer(sndbuf, sndlen);
155 158
@@ -180,17 +183,16 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha
180 */ 183 */
181iphone_error_t iphone_np_observe_notification( iphone_np_client_t client ) 184iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
182{ 185{
183 xmlDocPtr plist; 186 plist_t dict = NULL;
184 xmlNode *dict, *key; 187 char *XML_content = NULL;
185 char *XML_content; 188 uint32_t length = 0;
186 uint32_t length; 189 int bytes = 0;
187 int bytes;
188 iphone_error_t ret; 190 iphone_error_t ret;
189 unsigned char sndbuf[4096]; 191 unsigned char sndbuf[4096];
190 int sndlen = 0; 192 int sndlen = 0;
191 int nlen; 193 int nlen = 0;
192 int i=0; 194 int i=0;
193 char *notifications[10] = { 195 const char *notifications[10] = {
194 "com.apple.itunes-client.syncCancelRequest", 196 "com.apple.itunes-client.syncCancelRequest",
195 "com.apple.itunes-client.syncSuspendRequest", 197 "com.apple.itunes-client.syncSuspendRequest",
196 "com.apple.itunes-client.syncResumeRequest", 198 "com.apple.itunes-client.syncResumeRequest",
@@ -210,11 +212,13 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
210 np_lock(client); 212 np_lock(client);
211 213
212 while (notifications[i]) { 214 while (notifications[i]) {
213 plist = new_plist(); 215
214 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 216 dict = plist_new_dict();
215 key = add_key_str_dict_element(plist, dict, "Command", "ObserveNotification", 1); 217 plist_add_sub_key_el(dict, "Command");
216 key = add_key_str_dict_element(plist, dict, "Name", notifications[i++], 1); 218 plist_add_sub_string_el(dict, "ObserveNotification");
217 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 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);
218 222
219 nlen = htonl(length); 223 nlen = htonl(length);
220 memcpy(sndbuf+sndlen, &nlen, 4); 224 memcpy(sndbuf+sndlen, &nlen, 4);
@@ -222,14 +226,16 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
222 memcpy(sndbuf+sndlen, XML_content, length); 226 memcpy(sndbuf+sndlen, XML_content, length);
223 sndlen += length; 227 sndlen += length;
224 228
225 xmlFree(XML_content); 229 plist_free(dict);
226 xmlFreeDoc(plist); 230 dict = NULL;
231 free(XML_content);
232 XML_content = NULL;
227 } 233 }
228 234
229 plist = new_plist(); 235 dict = plist_new_dict();
230 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 236 plist_add_sub_key_el(dict, "Command");
231 key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1); 237 plist_add_sub_string_el(dict, "Shutdown");
232 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 238 plist_to_xml(dict, &XML_content, &length);
233 239
234 nlen = htonl(length); 240 nlen = htonl(length);
235 241
@@ -239,9 +245,10 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client )
239 memcpy(sndbuf+sndlen, XML_content, length); 245 memcpy(sndbuf+sndlen, XML_content, length);
240 sndlen+=length; 246 sndlen+=length;
241 247
242 xmlFree(XML_content); 248 plist_free(dict);
243 xmlFreeDoc(plist); 249 dict = NULL;
244 plist = NULL; 250 free(XML_content);
251 XML_content = NULL;
245 252
246 log_debug_buffer(sndbuf, sndlen); 253 log_debug_buffer(sndbuf, sndlen);
247 254