diff options
Diffstat (limited to 'common/userpref.c')
-rw-r--r-- | common/userpref.c | 33 |
1 files changed, 19 insertions, 14 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 | /** |