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