summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libiphone/libiphone.h27
-rw-r--r--src/lockdown.c36
2 files changed, 35 insertions, 28 deletions
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h
index 0d5257a..4bc2fea 100644
--- a/include/libiphone/libiphone.h
+++ b/include/libiphone/libiphone.h
@@ -32,23 +32,24 @@ extern "C" {
32#include <plist/plist.h> 32#include <plist/plist.h>
33 33
34//general errors 34//general errors
35#define IPHONE_E_SUCCESS 0 35#define IPHONE_E_SUCCESS 0
36#define IPHONE_E_INVALID_ARG -1 36#define IPHONE_E_INVALID_ARG -1
37#define IPHONE_E_UNKNOWN_ERROR -2 37#define IPHONE_E_UNKNOWN_ERROR -2
38#define IPHONE_E_NO_DEVICE -3 38#define IPHONE_E_NO_DEVICE -3
39#define IPHONE_E_TIMEOUT -4 39#define IPHONE_E_TIMEOUT -4
40#define IPHONE_E_NOT_ENOUGH_DATA -5 40#define IPHONE_E_NOT_ENOUGH_DATA -5
41#define IPHONE_E_BAD_HEADER -6 41#define IPHONE_E_BAD_HEADER -6
42 42
43//lockdownd specific error 43//lockdownd specific error
44#define IPHONE_E_INVALID_CONF -7 44#define IPHONE_E_INVALID_CONF -7
45#define IPHONE_E_PAIRING_FAILED -8 45#define IPHONE_E_PAIRING_FAILED -8
46#define IPHONE_E_SSL_ERROR -9 46#define IPHONE_E_SSL_ERROR -9
47#define IPHONE_E_PLIST_ERROR -10 47#define IPHONE_E_PLIST_ERROR -10
48#define IPHONE_E_DICT_ERROR -11 48#define IPHONE_E_DICT_ERROR -11
49#define IPHONE_E_START_SERVICE_FAILED -12
49 50
50//afc specific error 51//afc specific error
51#define IPHONE_E_NO_SUCH_FILE -12 52#define IPHONE_E_NO_SUCH_FILE -13
52 53
53typedef int16_t iphone_error_t; 54typedef int16_t iphone_error_t;
54 55
diff --git a/src/lockdown.c b/src/lockdown.c
index e720b29..e3636d1 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -1021,8 +1021,9 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1021 * 1021 *
1022 * @param control The lockdownd client 1022 * @param control The lockdownd client
1023 * @param service The name of the service to start 1023 * @param service The name of the service to start
1024 * 1024 * @param port The port number the service was started on
1025 * @return The port number the service was started on or 0 on failure. 1025
1026 * @return an error code
1026 */ 1027 */
1027iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char *service, int *port) 1028iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char *service, int *port)
1028{ 1029{
@@ -1064,6 +1065,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
1064 if (!dict) 1065 if (!dict)
1065 return IPHONE_E_PLIST_ERROR; 1066 return IPHONE_E_PLIST_ERROR;
1066 1067
1068 ret = IPHONE_E_UNKNOWN_ERROR;
1069
1067 plist_t query_node = plist_find_node_by_string(dict, "StartService"); 1070 plist_t query_node = plist_find_node_by_string(dict, "StartService");
1068 plist_t result_key_node = plist_get_next_sibling(query_node); 1071 plist_t result_key_node = plist_get_next_sibling(query_node);
1069 plist_t result_value_node = plist_get_next_sibling(result_key_node); 1072 plist_t result_value_node = plist_get_next_sibling(result_key_node);
@@ -1076,9 +1079,7 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
1076 plist_type port_key_type = plist_get_node_type(port_key_node); 1079 plist_type port_key_type = plist_get_node_type(port_key_node);
1077 plist_type port_value_type = plist_get_node_type(port_value_node); 1080 plist_type port_value_type = plist_get_node_type(port_value_node);
1078 1081
1079 if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING && port_key_type == PLIST_KEY 1082 if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) {
1080 && port_value_type == PLIST_UINT) {
1081
1082 char *result_key = NULL; 1083 char *result_key = NULL;
1083 char *result_value = NULL; 1084 char *result_value = NULL;
1084 char *port_key = NULL; 1085 char *port_key = NULL;
@@ -1086,18 +1087,23 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
1086 1087
1087 plist_get_key_val(result_key_node, &result_key); 1088 plist_get_key_val(result_key_node, &result_key);
1088 plist_get_string_val(result_value_node, &result_value); 1089 plist_get_string_val(result_value_node, &result_value);
1089 plist_get_key_val(port_key_node, &port_key);
1090 plist_get_uint_val(port_value_node, &port_value);
1091 1090
1092 if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success") && !strcmp(port_key, "Port")) { 1091 if (!strcmp(result_key, "Result") && !strcmp(result_value, "Failure")) {
1093 port_loc = port_value; 1092 ret = IPHONE_E_START_SERVICE_FAILED;
1094 ret = IPHONE_E_SUCCESS; 1093 } else {
1095 } 1094 if (port_key_type == PLIST_KEY && port_value_type == PLIST_UINT) {
1095 plist_get_key_val(port_key_node, &port_key);
1096 plist_get_uint_val(port_value_node, &port_value);
1096 1097
1097 if (port && ret == IPHONE_E_SUCCESS) 1098 if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success") && !strcmp(port_key, "Port")) {
1098 *port = port_loc; 1099 port_loc = port_value;
1099 else 1100 ret = IPHONE_E_SUCCESS;
1100 ret = IPHONE_E_UNKNOWN_ERROR; 1101 }
1102
1103 if (port && ret == IPHONE_E_SUCCESS)
1104 *port = port_loc;
1105 }
1106 }
1101 } 1107 }
1102 1108
1103 plist_free(dict); 1109 plist_free(dict);