summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-04-16 20:52:29 +0200
committerGravatar Matt Colyer2009-04-19 15:22:31 -0700
commit63e5eed5542c8c85144ee0ac20174c0859fab866 (patch)
tree375f7bc7097a0987b0b242e9d8df1197556e8428 /src
parentf104eb4371c2da6bac81f283d9943cdb800a6f95 (diff)
downloadlibimobiledevice-63e5eed5542c8c85144ee0ac20174c0859fab866.tar.gz
libimobiledevice-63e5eed5542c8c85144ee0ac20174c0859fab866.tar.bz2
Make sure start_service returns an error if it fails to start the service
[#34 state:resolved] Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src')
-rw-r--r--src/lockdown.c36
1 files changed, 21 insertions, 15 deletions
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_
*
* @param control The lockdownd client
* @param service The name of the service to start
- *
- * @return The port number the service was started on or 0 on failure.
+ * @param port The port number the service was started on
+
+ * @return an error code
*/
iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char *service, int *port)
{
@@ -1064,6 +1065,8 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
if (!dict)
return IPHONE_E_PLIST_ERROR;
+ ret = IPHONE_E_UNKNOWN_ERROR;
+
plist_t query_node = plist_find_node_by_string(dict, "StartService");
plist_t result_key_node = plist_get_next_sibling(query_node);
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
plist_type port_key_type = plist_get_node_type(port_key_node);
plist_type port_value_type = plist_get_node_type(port_value_node);
- if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING && port_key_type == PLIST_KEY
- && port_value_type == PLIST_UINT) {
-
+ if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) {
char *result_key = NULL;
char *result_value = NULL;
char *port_key = NULL;
@@ -1086,18 +1087,23 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char
plist_get_key_val(result_key_node, &result_key);
plist_get_string_val(result_value_node, &result_value);
- plist_get_key_val(port_key_node, &port_key);
- plist_get_uint_val(port_value_node, &port_value);
- if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success") && !strcmp(port_key, "Port")) {
- port_loc = port_value;
- ret = IPHONE_E_SUCCESS;
- }
+ if (!strcmp(result_key, "Result") && !strcmp(result_value, "Failure")) {
+ ret = IPHONE_E_START_SERVICE_FAILED;
+ } else {
+ if (port_key_type == PLIST_KEY && port_value_type == PLIST_UINT) {
+ plist_get_key_val(port_key_node, &port_key);
+ plist_get_uint_val(port_value_node, &port_value);
- if (port && ret == IPHONE_E_SUCCESS)
- *port = port_loc;
- else
- ret = IPHONE_E_UNKNOWN_ERROR;
+ if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success") && !strcmp(port_key, "Port")) {
+ port_loc = port_value;
+ ret = IPHONE_E_SUCCESS;
+ }
+
+ if (port && ret == IPHONE_E_SUCCESS)
+ *port = port_loc;
+ }
+ }
}
plist_free(dict);