summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libimobiledevice/restore.h11
-rw-r--r--src/restore.c52
2 files changed, 30 insertions, 33 deletions
diff --git a/include/libimobiledevice/restore.h b/include/libimobiledevice/restore.h
index 897c07c..950f8fd 100644
--- a/include/libimobiledevice/restore.h
+++ b/include/libimobiledevice/restore.h
@@ -35,13 +35,10 @@ extern "C" {
typedef enum {
RESTORE_E_SUCCESS = 0,
RESTORE_E_INVALID_ARG = -1,
- RESTORE_E_INVALID_CONF = -2,
- RESTORE_E_PLIST_ERROR = -3,
- RESTORE_E_DICT_ERROR = -4,
- RESTORE_E_NOT_ENOUGH_DATA = -5,
- RESTORE_E_MUX_ERROR = -6,
- RESTORE_E_START_RESTORE_FAILED = -7,
- RESTORE_E_DEVICE_ERROR = -8,
+ RESTORE_E_PLIST_ERROR = -2,
+ RESTORE_E_MUX_ERROR = -3,
+ RESTORE_E_NOT_ENOUGH_DATA = -4,
+ RESTORE_E_RECEIVE_TIMEOUT = -5,
RESTORE_E_UNKNOWN_ERROR = -256
} restored_error_t;
diff --git a/src/restore.c b/src/restore.c
index 6571a2f..0a13698 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -89,6 +89,25 @@ static void plist_dict_add_label(plist_t plist, const char *label)
}
}
+static restored_error_t restored_error(property_list_service_error_t err)
+{
+ switch (err) {
+ case PROPERTY_LIST_SERVICE_E_SUCCESS:
+ return RESTORE_E_SUCCESS;
+ case PROPERTY_LIST_SERVICE_E_INVALID_ARG:
+ return RESTORE_E_INVALID_ARG;
+ case PROPERTY_LIST_SERVICE_E_PLIST_ERROR:
+ return RESTORE_E_PLIST_ERROR;
+ case PROPERTY_LIST_SERVICE_E_MUX_ERROR:
+ return RESTORE_E_MUX_ERROR;
+ case PROPERTY_LIST_SERVICE_E_RECEIVE_TIMEOUT:
+ return RESTORE_E_RECEIVE_TIMEOUT;
+ default:
+ break;
+ }
+ return RESTORE_E_UNKNOWN_ERROR;
+}
+
LIBIMOBILEDEVICE_API restored_error_t restored_client_free(restored_client_t client)
{
if (!client)
@@ -99,9 +118,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_client_free(restored_client_t cli
if (client->parent) {
restored_goodbye(client);
- if (property_list_service_client_free(client->parent) == PROPERTY_LIST_SERVICE_E_SUCCESS) {
- ret = RESTORE_E_SUCCESS;
- }
+ ret = restored_error(property_list_service_client_free(client->parent));
}
if (client->udid) {
@@ -134,18 +151,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_receive(restored_client_t client,
if (!client || !plist || (plist && *plist))
return RESTORE_E_INVALID_ARG;
- restored_error_t ret = RESTORE_E_SUCCESS;
- property_list_service_error_t err;
-
- err = property_list_service_receive_plist(client->parent, plist);
- if (err != PROPERTY_LIST_SERVICE_E_SUCCESS) {
- ret = RESTORE_E_UNKNOWN_ERROR;
- }
-
- if (!*plist)
- ret = RESTORE_E_PLIST_ERROR;
-
- return ret;
+ return restored_error(property_list_service_receive_plist(client->parent, plist));
}
LIBIMOBILEDEVICE_API restored_error_t restored_send(restored_client_t client, plist_t plist)
@@ -153,14 +159,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_send(restored_client_t client, pl
if (!client || !plist)
return RESTORE_E_INVALID_ARG;
- restored_error_t ret = RESTORE_E_SUCCESS;
- property_list_service_error_t err;
-
- err = property_list_service_send_xml_plist(client->parent, plist);
- if (err != PROPERTY_LIST_SERVICE_E_SUCCESS) {
- ret = RESTORE_E_UNKNOWN_ERROR;
- }
- return ret;
+ return restored_error(property_list_service_send_xml_plist(client->parent, plist));
}
LIBIMOBILEDEVICE_API restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version)
@@ -305,9 +304,10 @@ LIBIMOBILEDEVICE_API restored_error_t restored_client_new(idevice_t device, rest
};
property_list_service_client_t plistclient = NULL;
- if (property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
+ ret = restored_error(property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient));
+ if (ret != RESTORE_E_SUCCESS) {
debug_info("could not connect to restored (device %s)", device->udid);
- return RESTORE_E_MUX_ERROR;
+ return ret;
}
restored_client_t client_loc = (restored_client_t) malloc(sizeof(struct restored_client_private));
@@ -321,7 +321,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_client_new(idevice_t device, rest
idev_ret = idevice_get_udid(device, &client_loc->udid);
if (IDEVICE_E_SUCCESS != idev_ret) {
debug_info("failed to get device udid.");
- ret = RESTORE_E_DEVICE_ERROR;
+ ret = RESTORE_E_UNKNOWN_ERROR;
}
debug_info("device udid: %s", client_loc->udid);