diff options
| -rw-r--r-- | libusbmuxd/libusbmuxd.c | 47 | ||||
| -rw-r--r-- | libusbmuxd/usbmuxd.h | 24 | ||||
| -rw-r--r-- | tools/iproxy.c | 2 |
3 files changed, 62 insertions, 11 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c index 584e930..a00ceb0 100644 --- a/libusbmuxd/libusbmuxd.c +++ b/libusbmuxd/libusbmuxd.c | |||
| @@ -296,7 +296,7 @@ int usbmuxd_unsubscribe() | |||
| 296 | return 0; | 296 | return 0; |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | 299 | int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list) |
| 300 | { | 300 | { |
| 301 | struct usbmuxd_listen_request s_req; | 301 | struct usbmuxd_listen_request s_req; |
| 302 | int sfd; | 302 | int sfd; |
| @@ -340,7 +340,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 340 | return -1; | 340 | return -1; |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | *available_devices = NULL; | 343 | *device_list = NULL; |
| 344 | // receive device list | 344 | // receive device list |
| 345 | while (1) { | 345 | while (1) { |
| 346 | if (recv_buf_timeout(sfd, &hdr, sizeof(hdr), 0, 1000) == sizeof(hdr)) { | 346 | if (recv_buf_timeout(sfd, &hdr, sizeof(hdr), 0, 1000) == sizeof(hdr)) { |
| @@ -362,7 +362,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 362 | fprintf(stderr, | 362 | fprintf(stderr, |
| 363 | "%s: received less data than specified in header!\n", __func__); | 363 | "%s: received less data than specified in header!\n", __func__); |
| 364 | } else { | 364 | } else { |
| 365 | newlist = (usbmuxd_device_info_t *) realloc(*available_devices, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); | 365 | newlist = (usbmuxd_device_info_t *) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); |
| 366 | if (newlist) { | 366 | if (newlist) { |
| 367 | newlist[dev_cnt].handle = | 367 | newlist[dev_cnt].handle = |
| 368 | (int) dev_info.device_id; | 368 | (int) dev_info.device_id; |
| @@ -373,7 +373,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 373 | memcpy(newlist[dev_cnt].uuid, | 373 | memcpy(newlist[dev_cnt].uuid, |
| 374 | dev_info.serial_number, | 374 | dev_info.serial_number, |
| 375 | sizeof(newlist[dev_cnt].uuid)); | 375 | sizeof(newlist[dev_cnt].uuid)); |
| 376 | *available_devices = newlist; | 376 | *device_list = newlist; |
| 377 | dev_cnt++; | 377 | dev_cnt++; |
| 378 | } else { | 378 | } else { |
| 379 | fprintf(stderr, | 379 | fprintf(stderr, |
| @@ -390,13 +390,48 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | // terminating zero record | 392 | // terminating zero record |
| 393 | newlist = (usbmuxd_device_info_t*) realloc(*available_devices, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); | 393 | newlist = (usbmuxd_device_info_t*) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); |
| 394 | memset(newlist + dev_cnt, 0, sizeof(usbmuxd_device_info_t)); | 394 | memset(newlist + dev_cnt, 0, sizeof(usbmuxd_device_info_t)); |
| 395 | *available_devices = newlist; | 395 | *device_list = newlist; |
| 396 | 396 | ||
| 397 | return dev_cnt; | 397 | return dev_cnt; |
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | int usbmuxd_get_device_by_uuid(const char *uuid, usbmuxd_device_info_t *device) | ||
| 401 | { | ||
| 402 | usbmuxd_device_info_t *dev_list = NULL; | ||
| 403 | |||
| 404 | if (!device) { | ||
| 405 | return -EINVAL; | ||
| 406 | } | ||
| 407 | if (usbmuxd_get_device_list(&dev_list) < 0) { | ||
| 408 | return -ENODEV; | ||
| 409 | } | ||
| 410 | |||
| 411 | int i; | ||
| 412 | int result = 0; | ||
| 413 | for (i = 0; dev_list[i].handle > 0; i++) { | ||
| 414 | if (!uuid) { | ||
| 415 | device->handle = dev_list[i].handle; | ||
| 416 | device->product_id = dev_list[i].product_id; | ||
| 417 | strcpy(device->uuid, dev_list[i].uuid); | ||
| 418 | result = 1; | ||
| 419 | break; | ||
| 420 | } | ||
| 421 | if (!strcmp(uuid, dev_list[i].uuid)) { | ||
| 422 | device->handle = dev_list[i].handle; | ||
| 423 | device->product_id = dev_list[i].product_id; | ||
| 424 | strcpy(device->uuid, dev_list[i].uuid); | ||
| 425 | result = 1; | ||
| 426 | break; | ||
| 427 | } | ||
| 428 | } | ||
| 429 | |||
| 430 | free(dev_list); | ||
| 431 | |||
| 432 | return result; | ||
| 433 | } | ||
| 434 | |||
| 400 | int usbmuxd_connect(const int handle, const unsigned short port) | 435 | int usbmuxd_connect(const int handle, const unsigned short port) |
| 401 | { | 436 | { |
| 402 | int sfd; | 437 | int sfd; |
diff --git a/libusbmuxd/usbmuxd.h b/libusbmuxd/usbmuxd.h index a4e7e4a..106f921 100644 --- a/libusbmuxd/usbmuxd.h +++ b/libusbmuxd/usbmuxd.h | |||
| @@ -57,12 +57,28 @@ int usbmuxd_unsubscribe(); | |||
| 57 | /** | 57 | /** |
| 58 | * Contacts usbmuxd and retrieves a list of connected devices. | 58 | * Contacts usbmuxd and retrieves a list of connected devices. |
| 59 | * | 59 | * |
| 60 | * @param available_devices pointer to an array of usbmuxd_device_info_t | 60 | * @param device_list A pointer to an array of usbmuxd_device_info_t |
| 61 | * that will hold records of the connected devices. | 61 | * that will hold records of the connected devices. The last record |
| 62 | * is a null-terminated record with all fields set to 0/NULL. | ||
| 63 | * @note The user has to free the list returned. | ||
| 62 | * | 64 | * |
| 63 | * @return number of available devices, zero on no devices, or negative on error | 65 | * @return number of attached devices, zero on no devices, or negative |
| 66 | * if an error occured. | ||
| 64 | */ | 67 | */ |
| 65 | int usbmuxd_scan(usbmuxd_device_info_t **available_devices); | 68 | int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list); |
| 69 | |||
| 70 | /** | ||
| 71 | * Gets device information for the device specified by uuid. | ||
| 72 | * | ||
| 73 | * @param uuid A device uuid of the device to look for. If uuid is NULL, | ||
| 74 | * This function will return the first device found. | ||
| 75 | * @param device Pointer to a previously allocated (or static) | ||
| 76 | * usbmuxd_device_info_t that will be filled with the device info. | ||
| 77 | * | ||
| 78 | * @return 0 if no matching device is connected, 1 if the device was found, | ||
| 79 | * or a negative value on error. | ||
| 80 | */ | ||
| 81 | int usbmuxd_get_device_by_uuid(const char *uuid, usbmuxd_device_info_t *device); | ||
| 66 | 82 | ||
| 67 | /** | 83 | /** |
| 68 | * Request proxy connect to | 84 | * Request proxy connect to |
diff --git a/tools/iproxy.c b/tools/iproxy.c index f10d701..094ae75 100644 --- a/tools/iproxy.c +++ b/tools/iproxy.c | |||
| @@ -153,7 +153,7 @@ void *acceptor_thread(void *arg) | |||
| 153 | 153 | ||
| 154 | cdata = (struct client_data*)arg; | 154 | cdata = (struct client_data*)arg; |
| 155 | 155 | ||
| 156 | if ((count = usbmuxd_scan(&dev_list)) < 0) { | 156 | if ((count = usbmuxd_get_device_list(&dev_list)) < 0) { |
| 157 | printf("Connecting to usbmuxd failed, terminating.\n"); | 157 | printf("Connecting to usbmuxd failed, terminating.\n"); |
| 158 | free(dev_list); | 158 | free(dev_list); |
| 159 | return NULL; | 159 | return NULL; |
