diff options
author | 2020-06-08 03:11:29 +0200 | |
---|---|---|
committer | 2020-07-30 14:45:11 +0200 | |
commit | efa547103b619e62c7e41a305e5429055dcea370 (patch) | |
tree | be05d1ada851c3d70edbbcdfc7a1ead2c07848cc | |
parent | d39172b9b35230060da85cf03548d3e516a736c4 (diff) | |
download | usbmuxd-efa547103b619e62c7e41a305e5429055dcea370.tar.gz usbmuxd-efa547103b619e62c7e41a305e5429055dcea370.tar.bz2 |
client: First go at renaming key internal functions for easier refactoring
-rw-r--r-- | src/client.c | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/client.c b/src/client.c index 2819516..52e569d 100644 --- a/src/client.c +++ b/src/client.c | |||
@@ -293,7 +293,7 @@ void client_get_fds(struct fdlist *list) | |||
293 | pthread_mutex_unlock(&client_list_mutex); | 293 | pthread_mutex_unlock(&client_list_mutex); |
294 | } | 294 | } |
295 | 295 | ||
296 | static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtype msg, void *payload, int payload_length) | 296 | static int output_buffer_add_message(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtype msg, void *payload, int payload_length) |
297 | { | 297 | { |
298 | struct usbmuxd_header hdr; | 298 | struct usbmuxd_header hdr; |
299 | hdr.version = client->proto_version; | 299 | hdr.version = client->proto_version; |
@@ -324,14 +324,14 @@ static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtyp | |||
324 | return hdr.length; | 324 | return hdr.length; |
325 | } | 325 | } |
326 | 326 | ||
327 | static int send_plist_pkt(struct mux_client *client, uint32_t tag, plist_t plist) | 327 | static int send_plist(struct mux_client *client, uint32_t tag, plist_t plist) |
328 | { | 328 | { |
329 | int res = -1; | 329 | int res = -1; |
330 | char *xml = NULL; | 330 | char *xml = NULL; |
331 | uint32_t xmlsize = 0; | 331 | uint32_t xmlsize = 0; |
332 | plist_to_xml(plist, &xml, &xmlsize); | 332 | plist_to_xml(plist, &xml, &xmlsize); |
333 | if (xml) { | 333 | if (xml) { |
334 | res = send_pkt(client, tag, MESSAGE_PLIST, xml, xmlsize); | 334 | res = output_buffer_add_message(client, tag, MESSAGE_PLIST, xml, xmlsize); |
335 | free(xml); | 335 | free(xml); |
336 | } else { | 336 | } else { |
337 | usbmuxd_log(LL_ERROR, "%s: Could not convert plist to xml", __func__); | 337 | usbmuxd_log(LL_ERROR, "%s: Could not convert plist to xml", __func__); |
@@ -347,11 +347,11 @@ static int send_result(struct mux_client *client, uint32_t tag, uint32_t result) | |||
347 | plist_t dict = plist_new_dict(); | 347 | plist_t dict = plist_new_dict(); |
348 | plist_dict_set_item(dict, "MessageType", plist_new_string("Result")); | 348 | plist_dict_set_item(dict, "MessageType", plist_new_string("Result")); |
349 | plist_dict_set_item(dict, "Number", plist_new_uint(result)); | 349 | plist_dict_set_item(dict, "Number", plist_new_uint(result)); |
350 | res = send_plist_pkt(client, tag, dict); | 350 | res = send_plist(client, tag, dict); |
351 | plist_free(dict); | 351 | plist_free(dict); |
352 | } else { | 352 | } else { |
353 | /* binary packet */ | 353 | /* binary packet */ |
354 | res = send_pkt(client, tag, MESSAGE_RESULT, &result, sizeof(uint32_t)); | 354 | res = output_buffer_add_message(client, tag, MESSAGE_RESULT, &result, sizeof(uint32_t)); |
355 | } | 355 | } |
356 | return res; | 356 | return res; |
357 | } | 357 | } |
@@ -417,7 +417,7 @@ static int send_device_list(struct mux_client *client, uint32_t tag) | |||
417 | free(devs); | 417 | free(devs); |
418 | 418 | ||
419 | plist_dict_set_item(dict, "DeviceList", devices); | 419 | plist_dict_set_item(dict, "DeviceList", devices); |
420 | res = send_plist_pkt(client, tag, dict); | 420 | res = send_plist(client, tag, dict); |
421 | plist_free(dict); | 421 | plist_free(dict); |
422 | return res; | 422 | return res; |
423 | } | 423 | } |
@@ -479,7 +479,7 @@ static int send_listener_list(struct mux_client *client, uint32_t tag) | |||
479 | pthread_mutex_unlock(&client_list_mutex); | 479 | pthread_mutex_unlock(&client_list_mutex); |
480 | 480 | ||
481 | plist_dict_set_item(dict, "ListenerList", listeners); | 481 | plist_dict_set_item(dict, "ListenerList", listeners); |
482 | res = send_plist_pkt(client, tag, dict); | 482 | res = send_plist(client, tag, dict); |
483 | plist_free(dict); | 483 | plist_free(dict); |
484 | 484 | ||
485 | return res; | 485 | return res; |
@@ -495,7 +495,7 @@ static int send_system_buid(struct mux_client *client, uint32_t tag) | |||
495 | plist_t dict = plist_new_dict(); | 495 | plist_t dict = plist_new_dict(); |
496 | plist_dict_set_item(dict, "BUID", plist_new_string(buid)); | 496 | plist_dict_set_item(dict, "BUID", plist_new_string(buid)); |
497 | free(buid); | 497 | free(buid); |
498 | res = send_plist_pkt(client, tag, dict); | 498 | res = send_plist(client, tag, dict); |
499 | plist_free(dict); | 499 | plist_free(dict); |
500 | return res; | 500 | return res; |
501 | } | 501 | } |
@@ -516,7 +516,7 @@ static int send_pair_record(struct mux_client *client, uint32_t tag, const char* | |||
516 | plist_t dict = plist_new_dict(); | 516 | plist_t dict = plist_new_dict(); |
517 | plist_dict_set_item(dict, "PairRecordData", plist_new_data(record_data, record_size)); | 517 | plist_dict_set_item(dict, "PairRecordData", plist_new_data(record_data, record_size)); |
518 | free(record_data); | 518 | free(record_data); |
519 | res = send_plist_pkt(client, tag, dict); | 519 | res = send_plist(client, tag, dict); |
520 | plist_free(dict); | 520 | plist_free(dict); |
521 | } else { | 521 | } else { |
522 | res = send_result(client, tag, ENOENT); | 522 | res = send_result(client, tag, ENOENT); |
@@ -524,13 +524,13 @@ static int send_pair_record(struct mux_client *client, uint32_t tag, const char* | |||
524 | return res; | 524 | return res; |
525 | } | 525 | } |
526 | 526 | ||
527 | static int notify_device_add(struct mux_client *client, struct device_info *dev) | 527 | static int send_device_add(struct mux_client *client, struct device_info *dev) |
528 | { | 528 | { |
529 | int res = -1; | 529 | int res = -1; |
530 | if (client->proto_version == 1) { | 530 | if (client->proto_version == 1) { |
531 | /* XML plist packet */ | 531 | /* XML plist packet */ |
532 | plist_t dict = create_device_attached_plist(dev); | 532 | plist_t dict = create_device_attached_plist(dev); |
533 | res = send_plist_pkt(client, 0, dict); | 533 | res = send_plist(client, 0, dict); |
534 | plist_free(dict); | 534 | plist_free(dict); |
535 | } else { | 535 | } else { |
536 | /* binary packet */ | 536 | /* binary packet */ |
@@ -541,12 +541,12 @@ static int notify_device_add(struct mux_client *client, struct device_info *dev) | |||
541 | dmsg.serial_number[255] = 0; | 541 | dmsg.serial_number[255] = 0; |
542 | dmsg.location = dev->location; | 542 | dmsg.location = dev->location; |
543 | dmsg.product_id = dev->pid; | 543 | dmsg.product_id = dev->pid; |
544 | res = send_pkt(client, 0, MESSAGE_DEVICE_ADD, &dmsg, sizeof(dmsg)); | 544 | res = output_buffer_add_message(client, 0, MESSAGE_DEVICE_ADD, &dmsg, sizeof(dmsg)); |
545 | } | 545 | } |
546 | return res; | 546 | return res; |
547 | } | 547 | } |
548 | 548 | ||
549 | static int notify_device_remove(struct mux_client *client, uint32_t device_id) | 549 | static int send_device_remove(struct mux_client *client, uint32_t device_id) |
550 | { | 550 | { |
551 | int res = -1; | 551 | int res = -1; |
552 | if (client->proto_version == 1) { | 552 | if (client->proto_version == 1) { |
@@ -554,16 +554,16 @@ static int notify_device_remove(struct mux_client *client, uint32_t device_id) | |||
554 | plist_t dict = plist_new_dict(); | 554 | plist_t dict = plist_new_dict(); |
555 | plist_dict_set_item(dict, "MessageType", plist_new_string("Detached")); | 555 | plist_dict_set_item(dict, "MessageType", plist_new_string("Detached")); |
556 | plist_dict_set_item(dict, "DeviceID", plist_new_uint(device_id)); | 556 | plist_dict_set_item(dict, "DeviceID", plist_new_uint(device_id)); |
557 | res = send_plist_pkt(client, 0, dict); | 557 | res = send_plist(client, 0, dict); |
558 | plist_free(dict); | 558 | plist_free(dict); |
559 | } else { | 559 | } else { |
560 | /* binary packet */ | 560 | /* binary packet */ |
561 | res = send_pkt(client, 0, MESSAGE_DEVICE_REMOVE, &device_id, sizeof(uint32_t)); | 561 | res = output_buffer_add_message(client, 0, MESSAGE_DEVICE_REMOVE, &device_id, sizeof(uint32_t)); |
562 | } | 562 | } |
563 | return res; | 563 | return res; |
564 | } | 564 | } |
565 | 565 | ||
566 | static int notify_device_paired(struct mux_client *client, uint32_t device_id) | 566 | static int send_device_paired(struct mux_client *client, uint32_t device_id) |
567 | { | 567 | { |
568 | int res = -1; | 568 | int res = -1; |
569 | if (client->proto_version == 1) { | 569 | if (client->proto_version == 1) { |
@@ -571,12 +571,12 @@ static int notify_device_paired(struct mux_client *client, uint32_t device_id) | |||
571 | plist_t dict = plist_new_dict(); | 571 | plist_t dict = plist_new_dict(); |
572 | plist_dict_set_item(dict, "MessageType", plist_new_string("Paired")); | 572 | plist_dict_set_item(dict, "MessageType", plist_new_string("Paired")); |
573 | plist_dict_set_item(dict, "DeviceID", plist_new_uint(device_id)); | 573 | plist_dict_set_item(dict, "DeviceID", plist_new_uint(device_id)); |
574 | res = send_plist_pkt(client, 0, dict); | 574 | res = send_plist(client, 0, dict); |
575 | plist_free(dict); | 575 | plist_free(dict); |
576 | } | 576 | } |
577 | else { | 577 | else { |
578 | /* binary packet */ | 578 | /* binary packet */ |
579 | res = send_pkt(client, 0, MESSAGE_DEVICE_PAIRED, &device_id, sizeof(uint32_t)); | 579 | res = output_buffer_add_message(client, 0, MESSAGE_DEVICE_PAIRED, &device_id, sizeof(uint32_t)); |
580 | } | 580 | } |
581 | return res; | 581 | return res; |
582 | } | 582 | } |
@@ -592,7 +592,7 @@ static int start_listen(struct mux_client *client) | |||
592 | count = device_get_list(0, &devs); | 592 | count = device_get_list(0, &devs); |
593 | dev = devs; | 593 | dev = devs; |
594 | for(i=0; devs && i < count; i++) { | 594 | for(i=0; devs && i < count; i++) { |
595 | if(notify_device_add(client, dev++) < 0) { | 595 | if(send_device_add(client, dev++) < 0) { |
596 | free(devs); | 596 | free(devs); |
597 | return -1; | 597 | return -1; |
598 | } | 598 | } |
@@ -643,7 +643,7 @@ static void update_client_info(struct mux_client *client, plist_t dict) | |||
643 | client->info = info; | 643 | client->info = info; |
644 | } | 644 | } |
645 | 645 | ||
646 | static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) | 646 | static int handle_command(struct mux_client *client, struct usbmuxd_header *hdr) |
647 | { | 647 | { |
648 | int res; | 648 | int res; |
649 | usbmuxd_log(LL_DEBUG, "Client %d command len %d ver %d msg %d tag %d", client->fd, hdr->length, hdr->version, hdr->message, hdr->tag); | 649 | usbmuxd_log(LL_DEBUG, "Client %d command len %d ver %d msg %d tag %d", client->fd, hdr->length, hdr->version, hdr->message, hdr->tag); |
@@ -878,7 +878,7 @@ static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) | |||
878 | return -1; | 878 | return -1; |
879 | } | 879 | } |
880 | 880 | ||
881 | static void process_send(struct mux_client *client) | 881 | static void output_buffer_process(struct mux_client *client) |
882 | { | 882 | { |
883 | int res; | 883 | int res; |
884 | if(!client->ob_size) { | 884 | if(!client->ob_size) { |
@@ -908,7 +908,7 @@ static void process_send(struct mux_client *client) | |||
908 | memmove(client->ob_buf, client->ob_buf + res, client->ob_size); | 908 | memmove(client->ob_buf, client->ob_buf + res, client->ob_size); |
909 | } | 909 | } |
910 | } | 910 | } |
911 | static void process_recv(struct mux_client *client) | 911 | static void input_buffer_process(struct mux_client *client) |
912 | { | 912 | { |
913 | int res; | 913 | int res; |
914 | int did_read = 0; | 914 | int did_read = 0; |
@@ -955,7 +955,7 @@ static void process_recv(struct mux_client *client) | |||
955 | if(client->ib_size < hdr->length) | 955 | if(client->ib_size < hdr->length) |
956 | return; | 956 | return; |
957 | } | 957 | } |
958 | client_command(client, hdr); | 958 | handle_command(client, hdr); |
959 | client->ib_size = 0; | 959 | client->ib_size = 0; |
960 | } | 960 | } |
961 | 961 | ||
@@ -981,9 +981,9 @@ void client_process(int fd, short events) | |||
981 | device_client_process(client->connect_device, client, events); | 981 | device_client_process(client->connect_device, client, events); |
982 | } else { | 982 | } else { |
983 | if(events & POLLIN) { | 983 | if(events & POLLIN) { |
984 | process_recv(client); | 984 | input_buffer_process(client); |
985 | } else if(events & POLLOUT) { //not both in case client died as part of process_recv | 985 | } else if(events & POLLOUT) { //not both in case client died as part of process_recv |
986 | process_send(client); | 986 | output_buffer_process(client); |
987 | } | 987 | } |
988 | } | 988 | } |
989 | 989 | ||
@@ -996,7 +996,7 @@ void client_device_add(struct device_info *dev) | |||
996 | device_set_visible(dev->id); | 996 | device_set_visible(dev->id); |
997 | FOREACH(struct mux_client *client, &client_list) { | 997 | FOREACH(struct mux_client *client, &client_list) { |
998 | if(client->state == CLIENT_LISTEN) | 998 | if(client->state == CLIENT_LISTEN) |
999 | notify_device_add(client, dev); | 999 | send_device_add(client, dev); |
1000 | } ENDFOREACH | 1000 | } ENDFOREACH |
1001 | pthread_mutex_unlock(&client_list_mutex); | 1001 | pthread_mutex_unlock(&client_list_mutex); |
1002 | } | 1002 | } |
@@ -1008,7 +1008,7 @@ void client_device_remove(int device_id) | |||
1008 | usbmuxd_log(LL_DEBUG, "client_device_remove: id %d", device_id); | 1008 | usbmuxd_log(LL_DEBUG, "client_device_remove: id %d", device_id); |
1009 | FOREACH(struct mux_client *client, &client_list) { | 1009 | FOREACH(struct mux_client *client, &client_list) { |
1010 | if(client->state == CLIENT_LISTEN) | 1010 | if(client->state == CLIENT_LISTEN) |
1011 | notify_device_remove(client, id); | 1011 | send_device_remove(client, id); |
1012 | } ENDFOREACH | 1012 | } ENDFOREACH |
1013 | pthread_mutex_unlock(&client_list_mutex); | 1013 | pthread_mutex_unlock(&client_list_mutex); |
1014 | } | 1014 | } |
@@ -1020,7 +1020,7 @@ void client_device_paired(int device_id) | |||
1020 | usbmuxd_log(LL_DEBUG, "client_device_paired: id %d", device_id); | 1020 | usbmuxd_log(LL_DEBUG, "client_device_paired: id %d", device_id); |
1021 | FOREACH(struct mux_client *client, &client_list) { | 1021 | FOREACH(struct mux_client *client, &client_list) { |
1022 | if (client->state == CLIENT_LISTEN) | 1022 | if (client->state == CLIENT_LISTEN) |
1023 | notify_device_paired(client, id); | 1023 | send_device_paired(client, id); |
1024 | } ENDFOREACH | 1024 | } ENDFOREACH |
1025 | pthread_mutex_unlock(&client_list_mutex); | 1025 | pthread_mutex_unlock(&client_list_mutex); |
1026 | } | 1026 | } |