summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-07-29 02:45:10 +0200
committerGravatar Nikias Bassen2021-07-29 02:45:10 +0200
commit4405a0fff74faaed363bc3ea4c4997293ac9d4a3 (patch)
treeb1d00d7ed7eef7f4e2ea88b0391e0306fa2b65d0
parent2380f7c6db47aef91263e125a6c8ca6aba170b28 (diff)
downloadlibimobiledevice-4405a0fff74faaed363bc3ea4c4997293ac9d4a3.tar.gz
libimobiledevice-4405a0fff74faaed363bc3ea4c4997293ac9d4a3.tar.bz2
common: Return proper error codes from userpref_read_pair_record
-rw-r--r--common/userpref.c33
-rw-r--r--common/userpref.h9
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,
* @param udid The device UDID as given by the device
* @param pair_record The pair record to read
*
- * @return 1 on success and 0 if no device record is given or if it has already
- * been saved previously.
+ * @return USERPREF_E_SUCCESS on success,
+ * USERPREF_E_NOENT if no pairing record was found,
+ * USERPREF_E_READ_ERROR if retrieving the pairing record from usbmuxd failed,
+ * or USERPREF_E_INVALID_CONF otherwise.
*/
userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_record)
{
@@ -318,24 +320,27 @@ userpref_error_t userpref_read_pair_record(const char *udid, plist_t *pair_recor
uint32_t record_size = 0;
int res = usbmuxd_read_pair_record(udid, &record_data, &record_size);
-
if (res < 0) {
- if (record_data)
- free(record_data);
-
- return USERPREF_E_INVALID_CONF;
+ free(record_data);
+ switch (-res) {
+ case ENOENT:
+ return USERPREF_E_NOENT;
+ case ETIMEDOUT:
+ return USERPREF_E_READ_ERROR;
+ default:
+ return USERPREF_E_INVALID_CONF;
+ }
}
*pair_record = NULL;
- if (memcmp(record_data, "bplist00", 8) == 0) {
- plist_from_bin(record_data, record_size, pair_record);
- } else {
- plist_from_xml(record_data, record_size, pair_record);
- }
-
+ plist_from_memory(record_data, record_size, pair_record);
free(record_data);
- return res == 0 ? USERPREF_E_SUCCESS: USERPREF_E_UNKNOWN_ERROR;
+ if (!*pair_record) {
+ debug_info("Failed to parse pairing record");
+ return USERPREF_E_INVALID_CONF;
+ }
+ return USERPREF_E_SUCCESS;
}
/**
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;
typedef enum {
USERPREF_E_SUCCESS = 0,
USERPREF_E_INVALID_ARG = -1,
- USERPREF_E_INVALID_CONF = -2,
- USERPREF_E_SSL_ERROR = -3,
- USERPREF_E_READ_ERROR = -4,
- USERPREF_E_WRITE_ERROR = -5,
+ USERPREF_E_NOENT = -2,
+ USERPREF_E_INVALID_CONF = -3,
+ USERPREF_E_SSL_ERROR = -4,
+ USERPREF_E_READ_ERROR = -5,
+ USERPREF_E_WRITE_ERROR = -6,
USERPREF_E_UNKNOWN_ERROR = -256
} userpref_error_t;