summaryrefslogtreecommitdiffstats
path: root/src/device_link_service.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-09-27 12:52:03 +0200
committerGravatar Nikias Bassen2019-09-27 12:52:03 +0200
commit8f96c52de2f9f35f361d29095190fc673db7d1c1 (patch)
tree991b5f37ed8c504b2f77a8d0afc22182afbd340c /src/device_link_service.c
parentacf0a76be3c81a8ce69817af2b16a546a08f7ecb (diff)
downloadlibimobiledevice-8f96c52de2f9f35f361d29095190fc673db7d1c1.tar.gz
libimobiledevice-8f96c52de2f9f35f361d29095190fc673db7d1c1.tar.bz2
Make sure to handle timeout errors in device link service and all depending services
Diffstat (limited to 'src/device_link_service.c')
-rw-r--r--src/device_link_service.c91
1 files changed, 49 insertions, 42 deletions
diff --git a/src/device_link_service.c b/src/device_link_service.c
index 007223e..856d301 100644
--- a/src/device_link_service.c
+++ b/src/device_link_service.c
@@ -2,7 +2,7 @@
2 * device_link_service.c 2 * device_link_service.c
3 * DeviceLink service implementation. 3 * DeviceLink service implementation.
4 * 4 *
5 * Copyright (c) 2010 Nikias Bassen, All Rights Reserved. 5 * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
@@ -24,6 +24,27 @@
24#include "property_list_service.h" 24#include "property_list_service.h"
25#include "common/debug.h" 25#include "common/debug.h"
26 26
27static device_link_service_error_t device_link_error(property_list_service_error_t err)
28{
29 switch (err) {
30 case PROPERTY_LIST_SERVICE_E_SUCCESS:
31 return DEVICE_LINK_SERVICE_E_SUCCESS;
32 case PROPERTY_LIST_SERVICE_E_INVALID_ARG:
33 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
34 case PROPERTY_LIST_SERVICE_E_PLIST_ERROR:
35 return DEVICE_LINK_SERVICE_E_PLIST_ERROR;
36 case PROPERTY_LIST_SERVICE_E_MUX_ERROR:
37 return DEVICE_LINK_SERVICE_E_MUX_ERROR;
38 case PROPERTY_LIST_SERVICE_E_SSL_ERROR:
39 return DEVICE_LINK_SERVICE_E_SSL_ERROR;
40 case PROPERTY_LIST_SERVICE_E_RECEIVE_TIMEOUT:
41 return DEVICE_LINK_SERVICE_E_RECEIVE_TIMEOUT;
42 default:
43 break;
44 }
45 return DEVICE_LINK_SERVICE_E_UNKNOWN_ERROR;
46}
47
27/** 48/**
28 * Internally used function to extract the message string from a DL* message 49 * Internally used function to extract the message string from a DL* message
29 * plist. 50 * plist.
@@ -89,18 +110,15 @@ device_link_service_error_t device_link_service_client_new(idevice_t device, loc
89 } 110 }
90 111
91 property_list_service_client_t plistclient = NULL; 112 property_list_service_client_t plistclient = NULL;
92 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 113 device_link_service_error_t err = device_link_error(property_list_service_client_new(device, service, &plistclient));
93 return DEVICE_LINK_SERVICE_E_MUX_ERROR; 114 if (err != DEVICE_LINK_SERVICE_E_SUCCESS) {
115 return err;
94 } 116 }
95 117
96 /* create client object */ 118 /* create client object */
97 device_link_service_client_t client_loc = (device_link_service_client_t) malloc(sizeof(struct device_link_service_client_private)); 119 device_link_service_client_t client_loc = (device_link_service_client_t) malloc(sizeof(struct device_link_service_client_private));
98 client_loc->parent = plistclient; 120 client_loc->parent = plistclient;
99 121
100 /* enable SSL if requested */
101 if (service->ssl_enabled)
102 property_list_service_enable_ssl(client_loc->parent);
103
104 /* all done, return success */ 122 /* all done, return success */
105 *client = client_loc; 123 *client = client_loc;
106 return DEVICE_LINK_SERVICE_E_SUCCESS; 124 return DEVICE_LINK_SERVICE_E_SUCCESS;
@@ -121,11 +139,10 @@ device_link_service_error_t device_link_service_client_free(device_link_service_
121 if (!client) 139 if (!client)
122 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 140 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
123 141
124 if (property_list_service_client_free(client->parent) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 142 device_link_service_error_t err = device_link_error(property_list_service_client_free(client->parent));
125 return DEVICE_LINK_SERVICE_E_UNKNOWN_ERROR;
126 }
127 free(client); 143 free(client);
128 return DEVICE_LINK_SERVICE_E_SUCCESS; 144
145 return err;
129} 146}
130 147
131/** 148/**
@@ -157,9 +174,9 @@ device_link_service_error_t device_link_service_version_exchange(device_link_ser
157 char *msg = NULL; 174 char *msg = NULL;
158 175
159 /* receive DLMessageVersionExchange from device */ 176 /* receive DLMessageVersionExchange from device */
160 if (property_list_service_receive_plist(client->parent, &array) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 177 err = device_link_error(property_list_service_receive_plist(client->parent, &array));
178 if (err != DEVICE_LINK_SERVICE_E_SUCCESS) {
161 debug_info("Did not receive initial message from device!"); 179 debug_info("Did not receive initial message from device!");
162 err = DEVICE_LINK_SERVICE_E_MUX_ERROR;
163 goto leave; 180 goto leave;
164 } 181 }
165 device_link_service_get_message(array, &msg); 182 device_link_service_get_message(array, &msg);
@@ -203,18 +220,18 @@ device_link_service_error_t device_link_service_version_exchange(device_link_ser
203 plist_array_append_item(array, plist_new_string("DLMessageVersionExchange")); 220 plist_array_append_item(array, plist_new_string("DLMessageVersionExchange"));
204 plist_array_append_item(array, plist_new_string("DLVersionsOk")); 221 plist_array_append_item(array, plist_new_string("DLVersionsOk"));
205 plist_array_append_item(array, plist_new_uint(version_major)); 222 plist_array_append_item(array, plist_new_uint(version_major));
206 if (property_list_service_send_binary_plist(client->parent, array) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 223 err = device_link_error(property_list_service_send_binary_plist(client->parent, array));
224 if (err != DEVICE_LINK_SERVICE_E_SUCCESS) {
207 debug_info("Error when sending DLVersionsOk"); 225 debug_info("Error when sending DLVersionsOk");
208 err = DEVICE_LINK_SERVICE_E_MUX_ERROR;
209 goto leave; 226 goto leave;
210 } 227 }
211 plist_free(array); 228 plist_free(array);
212 229
213 /* receive DeviceReady message */ 230 /* receive DeviceReady message */
214 array = NULL; 231 array = NULL;
215 if (property_list_service_receive_plist(client->parent, &array) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 232 err = device_link_error(property_list_service_receive_plist(client->parent, &array));
233 if (err != DEVICE_LINK_SERVICE_E_SUCCESS) {
216 debug_info("Error when receiving DLMessageDeviceReady!"); 234 debug_info("Error when receiving DLMessageDeviceReady!");
217 err = DEVICE_LINK_SERVICE_E_MUX_ERROR;
218 goto leave; 235 goto leave;
219 } 236 }
220 device_link_service_get_message(array, &msg); 237 device_link_service_get_message(array, &msg);
@@ -258,11 +275,9 @@ device_link_service_error_t device_link_service_disconnect(device_link_service_c
258 else 275 else
259 plist_array_append_item(array, plist_new_string("___EmptyParameterString___")); 276 plist_array_append_item(array, plist_new_string("___EmptyParameterString___"));
260 277
261 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_SUCCESS; 278 device_link_service_error_t err = device_link_error(property_list_service_send_binary_plist(client->parent, array));
262 if (property_list_service_send_binary_plist(client->parent, array) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
263 err = DEVICE_LINK_SERVICE_E_MUX_ERROR;
264 }
265 plist_free(array); 279 plist_free(array);
280
266 return err; 281 return err;
267} 282}
268 283
@@ -286,11 +301,9 @@ device_link_service_error_t device_link_service_send_ping(device_link_service_cl
286 plist_array_append_item(array, plist_new_string("DLMessagePing")); 301 plist_array_append_item(array, plist_new_string("DLMessagePing"));
287 plist_array_append_item(array, plist_new_string(message)); 302 plist_array_append_item(array, plist_new_string(message));
288 303
289 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_SUCCESS; 304 device_link_service_error_t err = device_link_error(property_list_service_send_binary_plist(client->parent, array));
290 if (property_list_service_send_binary_plist(client->parent, array) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
291 err = DEVICE_LINK_SERVICE_E_MUX_ERROR;
292 }
293 plist_free(array); 305 plist_free(array);
306
294 return err; 307 return err;
295} 308}
296 309
@@ -317,11 +330,9 @@ device_link_service_error_t device_link_service_send_process_message(device_link
317 plist_array_append_item(array, plist_new_string("DLMessageProcessMessage")); 330 plist_array_append_item(array, plist_new_string("DLMessageProcessMessage"));
318 plist_array_append_item(array, plist_copy(message)); 331 plist_array_append_item(array, plist_copy(message));
319 332
320 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_SUCCESS; 333 device_link_service_error_t err = device_link_error(property_list_service_send_binary_plist(client->parent, array));
321 if (property_list_service_send_binary_plist(client->parent, array) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
322 err = DEVICE_LINK_SERVICE_E_MUX_ERROR;
323 }
324 plist_free(array); 334 plist_free(array);
335
325 return err; 336 return err;
326} 337}
327 338
@@ -348,8 +359,9 @@ device_link_service_error_t device_link_service_receive_message(device_link_serv
348 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 359 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
349 360
350 *msg_plist = NULL; 361 *msg_plist = NULL;
351 if (property_list_service_receive_plist(client->parent, msg_plist) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 362 device_link_service_error_t err = device_link_error(property_list_service_receive_plist(client->parent, msg_plist));
352 return DEVICE_LINK_SERVICE_E_MUX_ERROR; 363 if (err != DEVICE_LINK_SERVICE_E_SUCCESS) {
364 return err;
353 } 365 }
354 366
355 if (!device_link_service_get_message(*msg_plist, dlmessage)) { 367 if (!device_link_service_get_message(*msg_plist, dlmessage)) {
@@ -378,11 +390,12 @@ device_link_service_error_t device_link_service_receive_process_message(device_l
378 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 390 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
379 391
380 plist_t pmsg = NULL; 392 plist_t pmsg = NULL;
381 if (property_list_service_receive_plist(client->parent, &pmsg) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 393 device_link_service_error_t err = device_link_error(property_list_service_receive_plist(client->parent, &pmsg));
382 return DEVICE_LINK_SERVICE_E_MUX_ERROR; 394 if (err != DEVICE_LINK_SERVICE_E_SUCCESS) {
395 return err;
383 } 396 }
384 397
385 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_UNKNOWN_ERROR; 398 err = DEVICE_LINK_SERVICE_E_UNKNOWN_ERROR;
386 399
387 char *msg = NULL; 400 char *msg = NULL;
388 device_link_service_get_message(pmsg, &msg); 401 device_link_service_get_message(pmsg, &msg);
@@ -432,10 +445,7 @@ device_link_service_error_t device_link_service_send(device_link_service_client_
432 if (!client || !plist) { 445 if (!client || !plist) {
433 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 446 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
434 } 447 }
435 if (property_list_service_send_binary_plist(client->parent, plist) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 448 return device_link_error(property_list_service_send_binary_plist(client->parent, plist));
436 return DEVICE_LINK_SERVICE_E_MUX_ERROR;
437 }
438 return DEVICE_LINK_SERVICE_E_SUCCESS;
439} 449}
440 450
441/* Generic device link service receive function. 451/* Generic device link service receive function.
@@ -455,9 +465,6 @@ device_link_service_error_t device_link_service_receive(device_link_service_clie
455 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 465 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
456 } 466 }
457 467
458 if (property_list_service_receive_plist(client->parent, plist) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 468 return device_link_error(property_list_service_receive_plist(client->parent, plist));
459 return DEVICE_LINK_SERVICE_E_MUX_ERROR;
460 }
461 return DEVICE_LINK_SERVICE_E_SUCCESS;
462} 469}
463 470