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
-rw-r--r--src/userpref.h13
-rw-r--r--src/utils.h10
5 files changed, 66 insertions, 82 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;
}
diff --git a/src/userpref.h b/src/userpref.h
index fcb8b62..3540468 100644
--- a/src/userpref.h
+++ b/src/userpref.h
@@ -23,6 +23,7 @@
#define USERPREF_H
#include <gnutls/gnutls.h>
+#include <glib.h>
#define USERPREF_E_SUCCESS 0
#define USERPREF_E_INVALID_ARG -1
@@ -33,11 +34,11 @@
typedef int16_t userpref_error_t;
-userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt);
-userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert);
-userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert);
-userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key);
-int userpref_has_device_public_key(const char *uuid);
-void userpref_get_host_id(char **host_id);
+G_GNUC_INTERNAL userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt);
+G_GNUC_INTERNAL userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert);
+G_GNUC_INTERNAL userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert);
+G_GNUC_INTERNAL userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key);
+G_GNUC_INTERNAL int userpref_has_device_public_key(const char *uuid);
+G_GNUC_INTERNAL void userpref_get_host_id(char **host_id);
#endif
diff --git a/src/utils.h b/src/utils.h
index 430e812..c99730a 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -22,10 +22,12 @@
#ifndef UTILS_H
#define UTILS_H
-inline void log_debug_msg(const char *format, ...);
-inline void log_dbg_msg(uint16_t id, const char *format, ...);
+#include <glib.h>
-inline void log_debug_buffer(const char *data, const int length);
-inline void dump_debug_buffer(const char *file, const char *data, const int length);
+G_GNUC_INTERNAL inline void log_debug_msg(const char *format, ...);
+G_GNUC_INTERNAL inline void log_dbg_msg(uint16_t id, const char *format, ...);
+
+G_GNUC_INTERNAL inline void log_debug_buffer(const char *data, const int length);
+G_GNUC_INTERNAL inline void dump_debug_buffer(const char *file, const char *data, const int length);
#endif