summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-11-07 23:29:00 +0100
committerGravatar Nikias Bassen2019-11-07 23:29:00 +0100
commit953c13961071a9836430a814159aae33502e2e0c (patch)
tree7b5b03a73007948909d64c8edc56f1079a26b2c9
parent5390060ec90bed0f565698a389cebc57c09c3ac8 (diff)
downloadlibimobiledevice-953c13961071a9836430a814159aae33502e2e0c.tar.gz
libimobiledevice-953c13961071a9836430a814159aae33502e2e0c.tar.bz2
Add new idevice_get_device_list_extended() allowing to list all devices, including network
Instead of just returning a list of UDIDs (like idevice_get_device_list) this function will return idevice_info_t* records which also contains the type of the connection and the connection data.
-rw-r--r--include/libimobiledevice/libimobiledevice.h32
-rw-r--r--src/idevice.c56
2 files changed, 84 insertions, 4 deletions
diff --git a/include/libimobiledevice/libimobiledevice.h b/include/libimobiledevice/libimobiledevice.h
index c1d5460..8bf022a 100644
--- a/include/libimobiledevice/libimobiledevice.h
+++ b/include/libimobiledevice/libimobiledevice.h
@@ -124,25 +124,49 @@ idevice_error_t idevice_event_unsubscribe(void);
124/* discovery (synchronous) */ 124/* discovery (synchronous) */
125 125
126/** 126/**
127 * Get a list of currently available devices. 127 * Get a list of UDIDs of currently available devices (USBMUX devices only).
128 * 128 *
129 * @param devices List of udids of devices that are currently available. 129 * @param devices List of UDIDs of devices that are currently available.
130 * This list is terminated by a NULL pointer. 130 * This list is terminated by a NULL pointer.
131 * @param count Number of devices found. 131 * @param count Number of devices found.
132 * 132 *
133 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred. 133 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
134 *
135 * @note This function only returns the UDIDs of USBMUX devices. To also include
136 * network devices in the list, use idevice_get_device_list_extended().
137 * @see idevice_get_device_list_extended
134 */ 138 */
135idevice_error_t idevice_get_device_list(char ***devices, int *count); 139idevice_error_t idevice_get_device_list(char ***devices, int *count);
136 140
137/** 141/**
138 * Free a list of device udids. 142 * Free a list of device UDIDs.
139 * 143 *
140 * @param devices List of udids to free. 144 * @param devices List of UDIDs to free.
141 * 145 *
142 * @return Always returnes IDEVICE_E_SUCCESS. 146 * @return Always returnes IDEVICE_E_SUCCESS.
143 */ 147 */
144idevice_error_t idevice_device_list_free(char **devices); 148idevice_error_t idevice_device_list_free(char **devices);
145 149
150/**
151 * Get a list of currently available devices
152 *
153 * @param devices List of idevice_info_t records with device information.
154 * This list is terminated by a NULL pointer.
155 * @param count Number of devices included in the list.
156 *
157 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
158 */
159idevice_error_t idevice_get_device_list_extended(idevice_info_t **devices, int *count);
160
161/**
162 * Free an extended device list retrieved through idevice_get_device_list_extended().
163 *
164 * @param devices Device list to free.
165 *
166 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
167 */
168idevice_error_t idevice_device_list_extended_free(idevice_info_t *devices);
169
146/* device structure creation and destruction */ 170/* device structure creation and destruction */
147 171
148/** 172/**
diff --git a/src/idevice.c b/src/idevice.c
index d23c5b5..31a8d3a 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -227,6 +227,62 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_event_unsubscribe(void)
227 return IDEVICE_E_SUCCESS; 227 return IDEVICE_E_SUCCESS;
228} 228}
229 229
230LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list_extended(idevice_info_t **devices, int *count)
231{
232 usbmuxd_device_info_t *dev_list;
233
234 *devices = NULL;
235 *count = 0;
236
237 if (usbmuxd_get_device_list(&dev_list) < 0) {
238 debug_info("ERROR: usbmuxd is not running!", __func__);
239 return IDEVICE_E_NO_DEVICE;
240 }
241
242 idevice_info_t *newlist = NULL;
243 int i, newcount = 0;
244
245 for (i = 0; dev_list[i].handle > 0; i++) {
246 newlist = realloc(*devices, sizeof(idevice_info_t) * (newcount+1));
247 newlist[newcount] = malloc(sizeof(struct idevice_info));
248 newlist[newcount]->udid = strdup(dev_list[i].udid);
249 if (dev_list[i].conn_type == CONNECTION_TYPE_USB) {
250 newlist[newcount]->conn_type = CONNECTION_USBMUXD;
251 newlist[newcount]->conn_data = NULL;
252 } else if (dev_list[i].conn_type == CONNECTION_TYPE_NETWORK) {
253 newlist[newcount]->conn_type = CONNECTION_NETWORK;
254 size_t addrlen = dev_list[i].conn_data[0];
255 newlist[newcount]->conn_data = malloc(addrlen);
256 memcpy(newlist[newcount]->conn_data, dev_list[i].conn_data, addrlen);
257 }
258 newcount++;
259 *devices = newlist;
260 }
261 usbmuxd_device_list_free(&dev_list);
262
263 *count = newcount;
264 newlist = realloc(*devices, sizeof(idevice_info_t) * (newcount+1));
265 newlist[newcount] = NULL;
266 *devices = newlist;
267
268 return IDEVICE_E_SUCCESS;
269}
270
271LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_extended_free(idevice_info_t *devices)
272{
273 if (devices) {
274 int i = 0;
275 while (devices[i]) {
276 free(devices[i]->udid);
277 free(devices[i]->conn_data);
278 free(devices[i]);
279 i++;
280 }
281 free(devices);
282 }
283 return IDEVICE_E_SUCCESS;
284}
285
230LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list(char ***devices, int *count) 286LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list(char ***devices, int *count)
231{ 287{
232 usbmuxd_device_info_t *dev_list; 288 usbmuxd_device_info_t *dev_list;