summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-12-13 04:36:35 +0100
committerGravatar Nikias Bassen2013-12-13 04:36:35 +0100
commit1d9358ee9f59e655bbfe6ebf1119bace2ad0eb73 (patch)
tree20ef25b425c5801e70dd6a7e3e63971fafec245c
parentc168c3c7746e51fef4ec748a3982553833bb0c4e (diff)
downloadusbmuxd-1d9358ee9f59e655bbfe6ebf1119bace2ad0eb73.tar.gz
usbmuxd-1d9358ee9f59e655bbfe6ebf1119bace2ad0eb73.tar.bz2
client: implemented ReadBUID, ReadPairRecord, SavePairRecord, and DeletePairRecord commonds
-rw-r--r--src/client.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c
index b81c11c..fdbea25 100644
--- a/src/client.c
+++ b/src/client.c
@@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
39#include "usb.h" 39#include "usb.h"
40#include "client.h" 40#include "client.h"
41#include "device.h" 41#include "device.h"
42#include "conf.h"
42 43
43#define CMD_BUF_SIZE 1024 44#define CMD_BUF_SIZE 1024
44#define REPLY_BUF_SIZE 1024 45#define REPLY_BUF_SIZE 1024
@@ -285,6 +286,44 @@ static int send_device_list(struct mux_client *client, uint32_t tag)
285 return res; 286 return res;
286} 287}
287 288
289static int send_system_buid(struct mux_client *client, uint32_t tag)
290{
291 int res = -1;
292 char* buid = NULL;
293
294 config_get_system_buid(&buid);
295
296 plist_t dict = plist_new_dict();
297 plist_dict_insert_item(dict, "BUID", plist_new_string(buid));
298 res = send_plist_pkt(client, tag, dict);
299 plist_free(dict);
300 return res;
301}
302
303static int send_pair_record(struct mux_client *client, uint32_t tag, const char* record_id)
304{
305 int res = -1;
306 char* record_data = NULL;
307 uint64_t record_size = 0;
308
309 if (!record_id) {
310 return send_result(client, tag, EINVAL);
311 }
312
313 config_get_device_record(record_id, &record_data, &record_size);
314
315 if (record_data) {
316 plist_t dict = plist_new_dict();
317 plist_dict_insert_item(dict, "PairRecordData", plist_new_data(record_data, record_size));
318 free(record_data);
319 res = send_plist_pkt(client, tag, dict);
320 plist_free(dict);
321 } else {
322 res = send_result(client, tag, ENOENT);
323 }
324 return res;
325}
326
288static int notify_device_add(struct mux_client *client, struct device_info *dev) 327static int notify_device_add(struct mux_client *client, struct device_info *dev)
289{ 328{
290 int res = -1; 329 int res = -1;
@@ -355,6 +394,18 @@ static int start_listen(struct mux_client *client)
355 return count; 394 return count;
356} 395}
357 396
397static char* plist_dict_get_string_val(plist_t dict, const char* key)
398{
399 if (!dict || plist_get_node_type(dict) != PLIST_DICT)
400 return NULL;
401 plist_t item = plist_dict_get_item(dict, key);
402 if (!item || plist_get_node_type(item) != PLIST_STRING)
403 return NULL;
404 char *str = NULL;
405 plist_get_string_val(item, &str);
406 return str;
407}
408
358static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) 409static int client_command(struct mux_client *client, struct usbmuxd_header *hdr)
359{ 410{
360 int res; 411 int res;
@@ -450,6 +501,62 @@ static int client_command(struct mux_client *client, struct usbmuxd_header *hdr)
450 if (send_device_list(client, hdr->tag) < 0) 501 if (send_device_list(client, hdr->tag) < 0)
451 return -1; 502 return -1;
452 return 0; 503 return 0;
504 } else if (!strcmp(message, "ReadBUID")) {
505 if (send_system_buid(client, hdr->tag) < 0)
506 return -1;
507 return 0;
508 } else if (!strcmp(message, "ReadPairRecord")) {
509 free(message);
510 char* record_id = plist_dict_get_string_val(dict, "PairRecordID");
511 plist_free(dict);
512
513 res = send_pair_record(client, hdr->tag, record_id);
514 if (record_id)
515 free(record_id);
516 if (res < 0)
517 return -1;
518 return 0;
519 } else if (!strcmp(message, "SavePairRecord")) {
520 uint32_t rval = RESULT_OK;
521 free(message);
522 char* record_id = plist_dict_get_string_val(dict, "PairRecordID");
523 char* record_data = NULL;
524 uint64_t record_size = 0;
525 plist_t rdata = plist_dict_get_item(dict, "PairRecordData");
526 if (rdata && plist_get_node_type(rdata) == PLIST_DATA) {
527 plist_get_data_val(rdata, &record_data, &record_size);
528 }
529 plist_free(dict);
530
531 if (record_id && record_data) {
532 res = config_set_device_record(record_id, record_data, record_size);
533 if (res < 0) {
534 rval = -res;
535 }
536 free(record_id);
537 } else {
538 rval = EINVAL;
539 }
540 if (send_result(client, hdr->tag, rval) < 0)
541 return -1;
542 return 0;
543 } else if (!strcmp(message, "DeletePairRecord")) {
544 uint32_t rval = RESULT_OK;
545 free(message);
546 char* record_id = plist_dict_get_string_val(dict, "PairRecordID");
547 plist_free(dict);
548 if (record_id) {
549 res = config_remove_device_record(record_id);
550 if (res < 0) {
551 rval = -res;
552 }
553 free(record_id);
554 } else {
555 rval = EINVAL;
556 }
557 if (send_result(client, hdr->tag, rval) < 0)
558 return -1;
559 return 0;
453 } else { 560 } else {
454 usbmuxd_log(LL_ERROR, "Unexpected command '%s' received!", message); 561 usbmuxd_log(LL_ERROR, "Unexpected command '%s' received!", message);
455 free(message); 562 free(message);