summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/MobileSync.c36
-rw-r--r--src/NotificationProxy.c14
-rw-r--r--src/lockdown.c75
3 files changed, 53 insertions, 72 deletions
diff --git a/src/MobileSync.c b/src/MobileSync.c
index 9e52f32..77d2710 100644
--- a/src/MobileSync.c
+++ b/src/MobileSync.c
@@ -54,9 +54,21 @@ mobilesync_error_t mobilesync_client_new(iphone_device_t device, int dst_port,
/* first receive version */
ret = mobilesync_recv(client_loc, &array);
- plist_t msg_node = plist_find_node_by_string(array, "DLMessageVersionExchange");
- plist_t ver_1 = plist_get_next_sibling(msg_node);
- plist_t ver_2 = plist_get_next_sibling(ver_1);
+ plist_t msg_node = plist_array_get_item(array, 0);
+
+ char* msg = NULL;
+ plist_type type = plist_get_node_type(msg_node);
+ if (PLIST_STRING == type) {
+ plist_get_string_val(msg_node, &msg);
+ }
+ if (PLIST_STRING != type || strcmp(msg, "DLMessageVersionExchange") || plist_array_get_size(array) < 3) {
+ log_debug_msg("%s: ERROR: MobileSync client expected a version exchange !\n", __func__);
+ }
+ free(msg);
+ msg = NULL;
+
+ plist_t ver_1 = plist_array_get_item(array, 1);
+ plist_t ver_2 = plist_array_get_item(array, 2);
plist_type ver_1_type = plist_get_node_type(ver_1);
plist_type ver_2_type = plist_get_node_type(ver_2);
@@ -85,16 +97,24 @@ mobilesync_error_t mobilesync_client_new(iphone_device_t device, int dst_port,
array = NULL;
ret = mobilesync_recv(client_loc, &array);
- plist_t rep_node = plist_find_node_by_string(array, "DLMessageDeviceReady");
+ plist_t rep_node = plist_array_get_item(array, 0);
- if (rep_node) {
- ret = MOBILESYNC_E_SUCCESS;
- *client = client_loc;
+ type = plist_get_node_type(rep_node);
+ if (PLIST_STRING == type) {
+ plist_get_string_val(rep_node, &msg);
+ }
+ if (PLIST_STRING != type || strcmp(msg, "DLMessageDeviceReady")) {
+ log_debug_msg("%s: ERROR: MobileSync client failed to start session !\n", __func__);
+ ret = MOBILESYNC_E_BAD_VERSION;
}
else
{
- ret = MOBILESYNC_E_BAD_VERSION;
+ ret = MOBILESYNC_E_SUCCESS;
+ *client = client_loc;
}
+ free(msg);
+ msg = NULL;
+
plist_free(array);
array = NULL;
}
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index ee2ad95..884be5f 100644
--- a/src/NotificationProxy.c
+++ b/src/NotificationProxy.c
@@ -318,35 +318,27 @@ static int np_get_notification(np_client_t client, char **notification)
return -2;
}
- plist_t cmd_key_node = plist_find_node_by_key(dict, "Command");
- plist_t cmd_value_node = plist_get_next_sibling(cmd_key_node);
char *cmd_value = NULL;
+ plist_t cmd_value_node = plist_dict_get_item(dict, "Command");
if (plist_get_node_type(cmd_value_node) == PLIST_STRING) {
plist_get_string_val(cmd_value_node, &cmd_value);
}
if (cmd_value && !strcmp(cmd_value, "RelayNotification")) {
- plist_t name_key_node = plist_get_next_sibling(cmd_value_node);
- plist_t name_value_node = plist_get_next_sibling(name_key_node);
-
- char *name_key = NULL;
char *name_value = NULL;
+ plist_t name_value_node = plist_dict_get_item(dict, "Name");
- if (plist_get_node_type(name_key_node) == PLIST_KEY) {
- plist_get_key_val(name_key_node, &name_key);
- }
if (plist_get_node_type(name_value_node) == PLIST_STRING) {
plist_get_string_val(name_value_node, &name_value);
}
res = -2;
- if (name_key && name_value && !strcmp(name_key, "Name")) {
+ if (name_value_node && name_value) {
*notification = name_value;
log_debug_msg("%s: got notification %s\n", __func__, name_value);
res = 0;
}
- free(name_key);
} else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) {
log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__);
res = -1;
diff --git a/src/lockdown.c b/src/lockdown.c
index 6f9c922..80a89dc 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -60,11 +60,7 @@ static int lockdown_check_result(plist_t dict, const char *query_match)
{
int ret = -1;
- plist_t query_key = plist_find_node_by_key(dict, "Request");
- if (!query_key) {
- return ret;
- }
- plist_t query_node = plist_get_next_sibling(query_key);
+ plist_t query_node = plist_dict_get_item(dict, "Request");
if (!query_node) {
return ret;
}
@@ -83,40 +79,30 @@ static int lockdown_check_result(plist_t dict, const char *query_match)
free(query_value);
}
- plist_t result_node = plist_get_next_sibling(query_node);
+ plist_t result_node = plist_dict_get_item(dict, "Result");
if (!result_node) {
return ret;
}
- plist_t value_node = plist_get_next_sibling(result_node);
- if (!value_node) {
- return ret;
- }
-
plist_type result_type = plist_get_node_type(result_node);
- plist_type value_type = plist_get_node_type(value_node);
- if (result_type == PLIST_KEY && value_type == PLIST_STRING) {
+ if (result_type == PLIST_STRING) {
char *result_value = NULL;
- char *value_value = NULL;
- plist_get_key_val(result_node, &result_value);
- plist_get_string_val(value_node, &value_value);
+ plist_get_string_val(result_node, &result_value);
- if (result_value && value_value && !strcmp(result_value, "Result")) {
- if (!strcmp(value_value, "Success")) {
+ if (result_value) {
+ if (!strcmp(result_value, "Success")) {
ret = RESULT_SUCCESS;
- } else if (!strcmp(value_value, "Failure")) {
+ } else if (!strcmp(result_value, "Failure")) {
ret = RESULT_FAILURE;
} else {
- log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, value_value);
+ log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, result_value);
}
}
if (result_value)
free(result_value);
- if (value_value)
- free(value_value);
}
return ret;
}
@@ -437,20 +423,11 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom
return ret;
}
- plist_t value_key_node = plist_find_node_by_key(dict, "Value");
- plist_t value_value_node = plist_get_next_sibling(value_key_node);
-
- plist_type value_key_type = plist_get_node_type(value_key_node);
+ plist_t value_node = plist_dict_get_item(dict, "Value");
- if (value_key_type == PLIST_KEY) {
- char *result_key = NULL;
- plist_get_key_val(value_key_node, &result_key);
-
- if (!strcmp(result_key, "Value")) {
- log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__);
- *value = plist_copy(value_value_node);
- }
- free(result_key);
+ if (value_node) {
+ log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__);
+ *value = plist_copy(value_node);
}
plist_free(dict);
@@ -1024,7 +1001,7 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
return LOCKDOWN_E_PLIST_ERROR;
if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) {
- plist_t error_node = plist_get_dict_el_from_key(dict, "Error");
+ plist_t error_node = plist_dict_get_item(dict, "Error");
if (error_node && PLIST_STRING == plist_get_node_type(error_node)) {
char *error = NULL;
plist_get_string_val(error_node, &error);
@@ -1108,18 +1085,17 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
}
}
/* store session id */
- plist_t session_node = plist_find_node_by_key(dict, "SessionID");
+ plist_t session_node = plist_dict_get_item(dict, "SessionID");
if (session_node) {
- plist_t session_node_val = plist_get_next_sibling(session_node);
- plist_type session_node_val_type = plist_get_node_type(session_node_val);
+ plist_type session_node_type = plist_get_node_type(session_node);
- if (session_node_val_type == PLIST_STRING) {
+ if (session_node_type == PLIST_STRING) {
char *session_id = NULL;
- plist_get_string_val(session_node_val, &session_id);
+ plist_get_string_val(session_node, &session_id);
- if (session_node_val_type == PLIST_STRING && session_id) {
+ if (session_node_type == PLIST_STRING && session_id) {
/* we need to store the session ID for StopSession */
strcpy(client->session_id, session_id);
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id);
@@ -1260,23 +1236,16 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char
ret = LOCKDOWN_E_UNKNOWN_ERROR;
if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) {
- plist_t port_key_node = plist_find_node_by_key(dict, "Port");
- plist_t port_value_node = plist_get_next_sibling(port_key_node);
+ plist_t port_value_node = plist_dict_get_item(dict, "Port");
- if ((plist_get_node_type(port_key_node) == PLIST_KEY)
- && (plist_get_node_type(port_value_node) == PLIST_UINT)) {
- char *port_key = NULL;
+ if (port_value_node && (plist_get_node_type(port_value_node) == PLIST_UINT)) {
uint64_t port_value = 0;
-
- plist_get_key_val(port_key_node, &port_key);
plist_get_uint_val(port_value_node, &port_value);
- if (port_key && !strcmp(port_key, "Port")) {
+
+ if (port_value) {
port_loc = port_value;
ret = LOCKDOWN_E_SUCCESS;
}
- if (port_key)
- free(port_key);
-
if (port && ret == LOCKDOWN_E_SUCCESS)
*port = port_loc;
}