diff options
| author | 2018-09-15 03:46:34 +0200 | |
|---|---|---|
| committer | 2018-09-15 03:46:34 +0200 | |
| commit | d33402036d563667a76910dbfec50a37b622d3a5 (patch) | |
| tree | 7d58e8d2ee2d5d7bc8027bb9c8b9f465f7d87e53 /src/client.c | |
| parent | ee85938c21043ef5f7cd4dfbc7677f385814d4d8 (diff) | |
| download | usbmuxd-d33402036d563667a76910dbfec50a37b622d3a5.tar.gz usbmuxd-d33402036d563667a76910dbfec50a37b622d3a5.tar.bz2 | |
client: Send 'Paired' message when a device's pairing record has been stored successfully
This requires the SavePairRecord message sent from the client to contain a
usbmux device id so the device can be matched accordingly.
For the record: This is the original behavior.
Diffstat (limited to 'src/client.c')
| -rw-r--r-- | src/client.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c index a24233c..c566d8c 100644 --- a/src/client.c +++ b/src/client.c | |||
| @@ -524,6 +524,24 @@ static int notify_device_remove(struct mux_client *client, uint32_t device_id) | |||
| 524 | return res; | 524 | return res; |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | static int notify_device_paired(struct mux_client *client, uint32_t device_id) | ||
| 528 | { | ||
| 529 | int res = -1; | ||
| 530 | if (client->proto_version == 1) { | ||
| 531 | /* XML plist packet */ | ||
| 532 | plist_t dict = plist_new_dict(); | ||
| 533 | plist_dict_set_item(dict, "MessageType", plist_new_string("Paired")); | ||
| 534 | plist_dict_set_item(dict, "DeviceID", plist_new_uint(device_id)); | ||
| 535 | res = send_plist_pkt(client, 0, dict); | ||
| 536 | plist_free(dict); | ||
| 537 | } | ||
| 538 | else { | ||
| 539 | /* binary packet */ | ||
| 540 | res = send_pkt(client, 0, MESSAGE_DEVICE_PAIRED, &device_id, sizeof(uint32_t)); | ||
| 541 | } | ||
| 542 | return res; | ||
| 543 | } | ||
| 544 | |||
| 527 | static int start_listen(struct mux_client *client) | 545 | static int start_listen(struct mux_client *client) |
| 528 | { | 546 | { |
| 529 | struct device_info *devs = NULL; | 547 | struct device_info *devs = NULL; |
| @@ -738,6 +756,34 @@ static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) | |||
| 738 | res = config_set_device_record(record_id, record_data, record_size); | 756 | res = config_set_device_record(record_id, record_data, record_size); |
| 739 | if (res < 0) { | 757 | if (res < 0) { |
| 740 | rval = -res; | 758 | rval = -res; |
| 759 | } else { | ||
| 760 | plist_t p_dev_id = plist_dict_get_item(dict, "DeviceID"); | ||
| 761 | uint32_t dev_id = 0; | ||
| 762 | if (p_dev_id && plist_get_node_type(p_dev_id) == PLIST_UINT) { | ||
| 763 | uint64_t u_dev_id = 0; | ||
| 764 | plist_get_uint_val(p_dev_id, &u_dev_id); | ||
| 765 | dev_id = (uint32_t)u_dev_id; | ||
| 766 | } | ||
| 767 | if (dev_id > 0) { | ||
| 768 | struct device_info *devs = NULL; | ||
| 769 | struct device_info *dev; | ||
| 770 | int i; | ||
| 771 | int count = device_get_list(1, &devs); | ||
| 772 | int found = 0; | ||
| 773 | dev = devs; | ||
| 774 | for (i = 0; devs && i < count; i++, dev++) { | ||
| 775 | if ((uint32_t)dev->id == dev_id && (strcmp(dev->serial, record_id) == 0)) { | ||
| 776 | found++; | ||
| 777 | break; | ||
| 778 | } | ||
| 779 | } | ||
| 780 | if (!found) { | ||
| 781 | usbmuxd_log(LL_ERROR, "ERROR: SavePairRecord: DeviceID %d (%s) is not connected\n", dev_id, record_id); | ||
| 782 | } else { | ||
| 783 | client_device_paired(dev_id); | ||
| 784 | } | ||
| 785 | free(devs); | ||
| 786 | } | ||
| 741 | } | 787 | } |
| 742 | free(record_id); | 788 | free(record_id); |
| 743 | } else { | 789 | } else { |
| @@ -937,6 +983,18 @@ void client_device_remove(int device_id) | |||
| 937 | pthread_mutex_unlock(&client_list_mutex); | 983 | pthread_mutex_unlock(&client_list_mutex); |
| 938 | } | 984 | } |
| 939 | 985 | ||
| 986 | void client_device_paired(int device_id) | ||
| 987 | { | ||
| 988 | pthread_mutex_lock(&client_list_mutex); | ||
| 989 | uint32_t id = device_id; | ||
| 990 | usbmuxd_log(LL_DEBUG, "client_device_paired: id %d", device_id); | ||
| 991 | FOREACH(struct mux_client *client, &client_list) { | ||
| 992 | if (client->state == CLIENT_LISTEN) | ||
| 993 | notify_device_paired(client, id); | ||
| 994 | } ENDFOREACH | ||
| 995 | pthread_mutex_unlock(&client_list_mutex); | ||
| 996 | } | ||
| 997 | |||
| 940 | void client_init(void) | 998 | void client_init(void) |
| 941 | { | 999 | { |
| 942 | usbmuxd_log(LL_DEBUG, "client_init"); | 1000 | usbmuxd_log(LL_DEBUG, "client_init"); |
