summaryrefslogtreecommitdiffstats
path: root/src/NotificationProxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/NotificationProxy.c')
-rw-r--r--src/NotificationProxy.c91
1 files changed, 49 insertions, 42 deletions
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index c13a547..726852e 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
@@ -131,13 +131,15 @@ iphone_error_t iphone_np_post_notification(iphone_np_client_t client, const char
131 memcpy(sndbuf + sndlen, XML_content, length); 131 memcpy(sndbuf + sndlen, XML_content, length);
132 sndlen += length; 132 sndlen += length;
133 133
134 xmlFree(XML_content); 134 plist_free(dict);
135 xmlFreeDoc(plist); 135 dict = NULL;
136 free(XML_content);
137 XML_content = NULL;
136 138
137 plist = new_plist(); 139 dict = plist_new_dict();
138 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 140 plist_add_sub_key_el(dict, "Command");
139 key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1); 141 plist_add_sub_string_el(dict, "Shutdown");
140 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 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 char
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 char
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",
@@ -211,11 +213,13 @@ iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
211 np_lock(client); 213 np_lock(client);
212 214
213 while (notifications[i]) { 215 while (notifications[i]) {
214 plist = new_plist(); 216
215 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 217 dict = plist_new_dict();
216 key = add_key_str_dict_element(plist, dict, "Command", "ObserveNotification", 1); 218 plist_add_sub_key_el(dict, "Command");
217 key = add_key_str_dict_element(plist, dict, "Name", notifications[i++], 1); 219 plist_add_sub_string_el(dict, "ObserveNotification");
218 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 220 plist_add_sub_key_el(dict, "Name");
221 plist_add_sub_string_el(dict, notifications[i++]);
222 plist_to_xml(dict, &XML_content, &length);
219 223
220 nlen = htonl(length); 224 nlen = htonl(length);
221 memcpy(sndbuf + sndlen, &nlen, 4); 225 memcpy(sndbuf + sndlen, &nlen, 4);
@@ -223,14 +227,16 @@ iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
223 memcpy(sndbuf + sndlen, XML_content, length); 227 memcpy(sndbuf + sndlen, XML_content, length);
224 sndlen += length; 228 sndlen += length;
225 229
226 xmlFree(XML_content); 230 plist_free(dict);
227 xmlFreeDoc(plist); 231 dict = NULL;
232 free(XML_content);
233 XML_content = NULL;
228 } 234 }
229 235
230 plist = new_plist(); 236 dict = plist_new_dict();
231 dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); 237 plist_add_sub_key_el(dict, "Command");
232 key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1); 238 plist_add_sub_string_el(dict, "Shutdown");
233 xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); 239 plist_to_xml(dict, &XML_content, &length);
234 240
235 nlen = htonl(length); 241 nlen = htonl(length);
236 242
@@ -240,9 +246,10 @@ iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
240 memcpy(sndbuf + sndlen, XML_content, length); 246 memcpy(sndbuf + sndlen, XML_content, length);
241 sndlen += length; 247 sndlen += length;
242 248
243 xmlFree(XML_content); 249 plist_free(dict);
244 xmlFreeDoc(plist); 250 dict = NULL;
245 plist = NULL; 251 free(XML_content);
252 XML_content = NULL;
246 253
247 log_debug_buffer(sndbuf, sndlen); 254 log_debug_buffer(sndbuf, sndlen);
248 255