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 @@
*/
#include <stdio.h>
+#include <plist/plist.h>
#include "NotificationProxy.h"
-#include "plist.h"
#include "utils.h"
/** 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)
*/
iphone_error_t iphone_np_post_notification(iphone_np_client_t client, const char *notification)
{
- xmlDocPtr plist;
- xmlNode *dict, *key;
- char *XML_content;
- uint32_t length;
- int bytes;
+ char *XML_content = NULL;
+ uint32_t length = 0;
+ int bytes = 0;
iphone_error_t ret;
unsigned char sndbuf[4096];
int sndlen = 0;
- int nlen;
+ int nlen = 0;
+ plist_t dict = NULL;
if (!client || !notification) {
return IPHONE_E_INVALID_ARG;
}
np_lock(client);
- plist = new_plist();
- dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
- key = add_key_str_dict_element(plist, dict, "Command", "PostNotification", 1);
- key = add_key_str_dict_element(plist, dict, "Name", notification, 1);
- xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length);
+ dict = plist_new_dict();
+ plist_add_sub_key_el(dict, "Command");
+ plist_add_sub_string_el(dict, "PostNotification");
+ plist_add_sub_key_el(dict, "Name");
+ plist_add_sub_string_el(dict, notification);
+ plist_to_xml(dict, &XML_content, &length);
nlen = htonl(length);
@@ -131,13 +131,15 @@ iphone_error_t iphone_np_post_notification(iphone_np_client_t client, const char
memcpy(sndbuf + sndlen, XML_content, length);
sndlen += length;
- xmlFree(XML_content);
- xmlFreeDoc(plist);
+ plist_free(dict);
+ dict = NULL;
+ free(XML_content);
+ XML_content = NULL;
- plist = new_plist();
- dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
- key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1);
- xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length);
+ dict = plist_new_dict();
+ plist_add_sub_key_el(dict, "Command");
+ plist_add_sub_string_el(dict, "Shutdown");
+ plist_to_xml(dict, &XML_content, &length);
nlen = htonl(length);
@@ -147,9 +149,10 @@ iphone_error_t iphone_np_post_notification(iphone_np_client_t client, const char
memcpy(sndbuf + sndlen, XML_content, length);
sndlen += length;
- xmlFree(XML_content);
- xmlFreeDoc(plist);
- plist = NULL;
+ plist_free(dict);
+ dict = NULL;
+ free(XML_content);
+ XML_content = NULL;
log_debug_buffer(sndbuf, sndlen);
@@ -180,17 +183,16 @@ iphone_error_t iphone_np_post_notification(iphone_np_client_t client, const char
*/
iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
{
- xmlDocPtr plist;
- xmlNode *dict, *key;
- char *XML_content;
- uint32_t length;
- int bytes;
+ plist_t dict = NULL;
+ char *XML_content = NULL;
+ uint32_t length = 0;
+ int bytes = 0;
iphone_error_t ret;
unsigned char sndbuf[4096];
int sndlen = 0;
- int nlen;
+ int nlen = 0;
int i = 0;
- char *notifications[10] = {
+ const char *notifications[10] = {
"com.apple.itunes-client.syncCancelRequest",
"com.apple.itunes-client.syncSuspendRequest",
"com.apple.itunes-client.syncResumeRequest",
@@ -211,11 +213,13 @@ iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
np_lock(client);
while (notifications[i]) {
- plist = new_plist();
- dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
- key = add_key_str_dict_element(plist, dict, "Command", "ObserveNotification", 1);
- key = add_key_str_dict_element(plist, dict, "Name", notifications[i++], 1);
- xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length);
+
+ dict = plist_new_dict();
+ plist_add_sub_key_el(dict, "Command");
+ plist_add_sub_string_el(dict, "ObserveNotification");
+ plist_add_sub_key_el(dict, "Name");
+ plist_add_sub_string_el(dict, notifications[i++]);
+ plist_to_xml(dict, &XML_content, &length);
nlen = htonl(length);
memcpy(sndbuf + sndlen, &nlen, 4);
@@ -223,14 +227,16 @@ iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
memcpy(sndbuf + sndlen, XML_content, length);
sndlen += length;
- xmlFree(XML_content);
- xmlFreeDoc(plist);
+ plist_free(dict);
+ dict = NULL;
+ free(XML_content);
+ XML_content = NULL;
}
- plist = new_plist();
- dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
- key = add_key_str_dict_element(plist, dict, "Command", "Shutdown", 1);
- xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length);
+ dict = plist_new_dict();
+ plist_add_sub_key_el(dict, "Command");
+ plist_add_sub_string_el(dict, "Shutdown");
+ plist_to_xml(dict, &XML_content, &length);
nlen = htonl(length);
@@ -240,9 +246,10 @@ iphone_error_t iphone_np_observe_notification(iphone_np_client_t client)
memcpy(sndbuf + sndlen, XML_content, length);
sndlen += length;
- xmlFree(XML_content);
- xmlFreeDoc(plist);
- plist = NULL;
+ plist_free(dict);
+ dict = NULL;
+ free(XML_content);
+ XML_content = NULL;
log_debug_buffer(sndbuf, sndlen);