diff options
author | 2021-07-29 02:45:10 +0200 | |
---|---|---|
committer | 2021-07-29 02:45:10 +0200 | |
commit | 4405a0fff74faaed363bc3ea4c4997293ac9d4a3 (patch) | |
tree | b1d00d7ed7eef7f4e2ea88b0391e0306fa2b65d0 | |
parent | 2380f7c6db47aef91263e125a6c8ca6aba170b28 (diff) | |
download | libimobiledevice-4405a0fff74faaed363bc3ea4c4997293ac9d4a3.tar.gz libimobiledevice-4405a0fff74faaed363bc3ea4c4997293ac9d4a3.tar.bz2 |
common: Return proper error codes from userpref_read_pair_record
-rw-r--r-- | common/userpref.c | 33 | ||||
-rw-r--r-- | common/userpref.h | 9 |
2 files changed, 24 insertions, 18 deletions
diff --git a/common/userpref.c b/common/userpref.c index 0c6050f..bf7e1bd 100644 --- a/common/userpref.c +++ b/common/userpref.c | |||
@@ -309,8 +309,10 @@ userpref_error_t userpref_save_pair_record(const char *udid, uint32_t device_id, | |||
309 | * @param udid The device UDID as given by the device | 309 | * @param udid The device UDID as given by the device |
310 | * @param pair_record The pair record to read | 310 | * @param pair_record The pair record to read |
311 | * | 311 | * |
312 | * @return 1 on success and 0 if no device record is given or if it has already | 312 | * @return USERPREF_E_SUCCESS on success, |
313 | * been saved previously. | 313 | * USERPREF_E_NOENT if no pairing record was found, |
314 | * USERPREF_E_READ_ERROR if retrieving the pairing record from usbmuxd failed, | ||
315 | * or USERPREF_E_INVALID_CONF otherwise. | ||
314 | */ | 316 | */ |
315 | userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_record) | 317 | userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_record) |
316 | { | 318 | { |
@@ -318,24 +320,27 @@ userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_recor | |||
318 | uint32_t record_size = 0; | 320 | uint32_t record_size = 0; |
319 | 321 | ||
320 | int res = usbmuxd_read_pair_record(udid, &record_data, &record_size); | 322 | int res = usbmuxd_read_pair_record(udid, &record_data, &record_size); |
321 | |||
322 | if (res < 0) { | 323 | if (res < 0) { |
323 | if (record_data) | 324 | free(record_data); |
324 | free(record_data); | 325 | switch (-res) { |
325 | 326 | case ENOENT: | |
326 | return USERPREF_E_INVALID_CONF; | 327 | return USERPREF_E_NOENT; |
328 | case ETIMEDOUT: | ||
329 | return USERPREF_E_READ_ERROR; | ||
330 | default: | ||
331 | return USERPREF_E_INVALID_CONF; | ||
332 | } | ||
327 | } | 333 | } |
328 | 334 | ||
329 | *pair_record = NULL; | 335 | *pair_record = NULL; |
330 | if (memcmp(record_data, "bplist00", 8) == 0) { | 336 | plist_from_memory(record_data, record_size, pair_record); |
331 | plist_from_bin(record_data, record_size, pair_record); | ||
332 | } else { | ||
333 | plist_from_xml(record_data, record_size, pair_record); | ||
334 | } | ||
335 | |||
336 | free(record_data); | 337 | free(record_data); |
337 | 338 | ||
338 | return res == 0 ? USERPREF_E_SUCCESS: USERPREF_E_UNKNOWN_ERROR; | 339 | if (!*pair_record) { |
340 | debug_info("Failed to parse pairing record"); | ||
341 | return USERPREF_E_INVALID_CONF; | ||
342 | } | ||
343 | return USERPREF_E_SUCCESS; | ||
339 | } | 344 | } |
340 | 345 | ||
341 | /** | 346 | /** |
diff --git a/common/userpref.h b/common/userpref.h index 072721a..75bb8b7 100644 --- a/common/userpref.h +++ b/common/userpref.h | |||
@@ -54,10 +54,11 @@ typedef gnutls_datum_t key_data_t; | |||
54 | typedef enum { | 54 | typedef enum { |
55 | USERPREF_E_SUCCESS = 0, | 55 | USERPREF_E_SUCCESS = 0, |
56 | USERPREF_E_INVALID_ARG = -1, | 56 | USERPREF_E_INVALID_ARG = -1, |
57 | USERPREF_E_INVALID_CONF = -2, | 57 | USERPREF_E_NOENT = -2, |
58 | USERPREF_E_SSL_ERROR = -3, | 58 | USERPREF_E_INVALID_CONF = -3, |
59 | USERPREF_E_READ_ERROR = -4, | 59 | USERPREF_E_SSL_ERROR = -4, |
60 | USERPREF_E_WRITE_ERROR = -5, | 60 | USERPREF_E_READ_ERROR = -5, |
61 | USERPREF_E_WRITE_ERROR = -6, | ||
61 | USERPREF_E_UNKNOWN_ERROR = -256 | 62 | USERPREF_E_UNKNOWN_ERROR = -256 |
62 | } userpref_error_t; | 63 | } userpref_error_t; |
63 | 64 | ||