summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.c47
1 files changed, 19 insertions, 28 deletions
diff --git a/src/client.c b/src/client.c
index d902591..e77e07e 100644
--- a/src/client.c
+++ b/src/client.c
@@ -190,25 +190,32 @@ static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtyp
190 return hdr.length; 190 return hdr.length;
191} 191}
192 192
193static int send_plist_pkt(struct mux_client *client, uint32_t tag, plist_t plist)
194{
195 int res = -1;
196 char *xml = NULL;
197 uint32_t xmlsize = 0;
198 plist_to_xml(plist, &xml, &xmlsize);
199 if (xml) {
200 res = send_pkt(client, tag, MESSAGE_PLIST, xml, xmlsize);
201 free(xml);
202 } else {
203 usbmuxd_log(LL_ERROR, "%s: Could not convert plist to xml", __func__);
204 }
205 return res;
206}
207
193static int send_result(struct mux_client *client, uint32_t tag, uint32_t result) 208static int send_result(struct mux_client *client, uint32_t tag, uint32_t result)
194{ 209{
195 int res = -1; 210 int res = -1;
196#ifdef HAVE_PLIST 211#ifdef HAVE_PLIST
197 if (client->proto_version == 1) { 212 if (client->proto_version == 1) {
198 /* XML plist packet */ 213 /* XML plist packet */
199 char *xml = NULL;
200 uint32_t xmlsize = 0;
201 plist_t dict = plist_new_dict(); 214 plist_t dict = plist_new_dict();
202 plist_dict_insert_item(dict, "MessageType", plist_new_string("Result")); 215 plist_dict_insert_item(dict, "MessageType", plist_new_string("Result"));
203 plist_dict_insert_item(dict, "Number", plist_new_uint(result)); 216 plist_dict_insert_item(dict, "Number", plist_new_uint(result));
204 plist_to_xml(dict, &xml, &xmlsize); 217 res = send_plist_pkt(client, tag, dict);
205 plist_free(dict); 218 free(dict);
206 if (xml) {
207 res = send_pkt(client, tag, MESSAGE_PLIST, xml, xmlsize);
208 free(xml);
209 } else {
210 usbmuxd_log(LL_ERROR, "%s: Could not convert plist to xml", __func__);
211 }
212 } else 219 } else
213#endif 220#endif
214 { 221 {
@@ -247,8 +254,6 @@ static int notify_device_add(struct mux_client *client, struct device_info *dev)
247#ifdef HAVE_PLIST 254#ifdef HAVE_PLIST
248 if (client->proto_version == 1) { 255 if (client->proto_version == 1) {
249 /* XML plist packet */ 256 /* XML plist packet */
250 char *xml = NULL;
251 uint32_t xmlsize = 0;
252 plist_t dict = plist_new_dict(); 257 plist_t dict = plist_new_dict();
253 plist_dict_insert_item(dict, "MessageType", plist_new_string("Attached")); 258 plist_dict_insert_item(dict, "MessageType", plist_new_string("Attached"));
254 plist_dict_insert_item(dict, "DeviceID", plist_new_uint(dev->id)); 259 plist_dict_insert_item(dict, "DeviceID", plist_new_uint(dev->id));
@@ -261,14 +266,8 @@ static int notify_device_add(struct mux_client *client, struct device_info *dev)
261 plist_dict_insert_item(props, "ProductID", plist_new_uint(dev->pid)); 266 plist_dict_insert_item(props, "ProductID", plist_new_uint(dev->pid));
262 plist_dict_insert_item(props, "SerialNumber", plist_new_string(dev->serial)); 267 plist_dict_insert_item(props, "SerialNumber", plist_new_string(dev->serial));
263 plist_dict_insert_item(dict, "Properties", props); 268 plist_dict_insert_item(dict, "Properties", props);
264 plist_to_xml(dict, &xml, &xmlsize); 269 res = send_plist_pkt(client, 0, dict);
265 plist_free(dict); 270 plist_free(dict);
266 if (xml) {
267 res = send_pkt(client, 0, MESSAGE_PLIST, xml, xmlsize);
268 free(xml);
269 } else {
270 usbmuxd_log(LL_ERROR, "%s: Could not convert plist to xml", __func__);
271 }
272 } else 271 } else
273#endif 272#endif
274 { 273 {
@@ -291,19 +290,11 @@ static int notify_device_remove(struct mux_client *client, uint32_t device_id)
291#ifdef HAVE_PLIST 290#ifdef HAVE_PLIST
292 if (client->proto_version == 1) { 291 if (client->proto_version == 1) {
293 /* XML plist packet */ 292 /* XML plist packet */
294 char *xml = NULL;
295 uint32_t xmlsize = 0;
296 plist_t dict = plist_new_dict(); 293 plist_t dict = plist_new_dict();
297 plist_dict_insert_item(dict, "MessageType", plist_new_string("Detached")); 294 plist_dict_insert_item(dict, "MessageType", plist_new_string("Detached"));
298 plist_dict_insert_item(dict, "DeviceID", plist_new_uint(device_id)); 295 plist_dict_insert_item(dict, "DeviceID", plist_new_uint(device_id));
299 plist_to_xml(dict, &xml, &xmlsize); 296 res = send_plist_pkt(client, 0, dict);
300 plist_free(dict); 297 plist_free(dict);
301 if (xml) {
302 res = send_pkt(client, 0, MESSAGE_PLIST, xml, xmlsize);
303 free(xml);
304 } else {
305 usbmuxd_log(LL_ERROR, "%s: Could not convert plist to xml", __func__);
306 }
307 } else 298 } else
308#endif 299#endif
309 { 300 {