summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/afc.c34
-rw-r--r--src/idevice.c76
-rw-r--r--src/lockdown.c20
-rw-r--r--src/misagent.c3
-rw-r--r--src/mobileactivation.c15
-rw-r--r--src/mobilebackup2.c9
-rw-r--r--src/preboard.c3
-rw-r--r--src/restore.c18
-rw-r--r--src/syslog_relay.c9
9 files changed, 93 insertions, 94 deletions
diff --git a/src/afc.c b/src/afc.c
index 17273e2..d8c3db0 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -229,7 +229,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t
if (recv_len == 0) {
debug_info("Just didn't get enough.");
return AFC_E_MUX_ERROR;
- } else if (recv_len < sizeof(AFCPacket)) {
+ }
+
+ if (recv_len < sizeof(AFCPacket)) {
debug_info("Did not even get the AFCPacket header");
return AFC_E_MUX_ERROR;
}
@@ -250,14 +252,14 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t
if (header.this_length < sizeof(AFCPacket)) {
debug_info("Invalid AFCPacket header received!");
return AFC_E_OP_HEADER_INVALID;
- } else if ((header.this_length == header.entire_length)
- && header.entire_length == sizeof(AFCPacket)) {
+ }
+ if ((header.this_length == header.entire_length)
+ && header.entire_length == sizeof(AFCPacket)) {
debug_info("Empty AFCPacket received!");
if (header.operation == AFC_OP_DATA) {
return AFC_E_SUCCESS;
- } else {
- return AFC_E_IO_ERROR;
}
+ return AFC_E_IO_ERROR;
}
debug_info("received AFC packet, full len=%lld, this len=%lld, operation=0x%llx", header.entire_length, header.this_length, header.operation);
@@ -273,7 +275,8 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t
free(buf);
debug_info("Did not get packet contents!");
return AFC_E_NOT_ENOUGH_DATA;
- } else if (recv_len < this_len) {
+ }
+ if (recv_len < this_len) {
free(buf);
debug_info("Could not receive this_len=%d bytes", this_len);
return AFC_E_NOT_ENOUGH_DATA;
@@ -749,22 +752,23 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_read(afc_client_t client, uint64_t han
if (ret != AFC_E_SUCCESS) {
afc_unlock(client);
return ret;
- } else if (bytes_loc == 0) {
+ }
+ if (bytes_loc == 0) {
if (input)
free(input);
afc_unlock(client);
*bytes_read = current_count;
/* FIXME: check that's actually a success */
return ret;
- } else {
- if (input) {
- debug_info("%d", bytes_loc);
- memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc);
- free(input);
- input = NULL;
- current_count += (bytes_loc > length) ? length : bytes_loc;
- }
}
+ if (input) {
+ debug_info("%d", bytes_loc);
+ memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc);
+ free(input);
+ input = NULL;
+ current_count += (bytes_loc > length) ? length : bytes_loc;
+ }
+
afc_unlock(client);
*bytes_read = current_count;
return ret;
diff --git a/src/idevice.c b/src/idevice.c
index f64570b..adf47f4 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -473,7 +473,8 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t
new_connection->status = IDEVICE_E_SUCCESS;
*connection = new_connection;
return IDEVICE_E_SUCCESS;
- } else if (device->conn_type == CONNECTION_NETWORK) {
+ }
+ if (device->conn_type == CONNECTION_NETWORK) {
struct sockaddr_storage saddr_storage;
struct sockaddr* saddr = (struct sockaddr*)&saddr_storage;
@@ -529,10 +530,9 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t
*connection = new_connection;
return IDEVICE_E_SUCCESS;
- } else {
- debug_info("Unknown connection type %d", device->conn_type);
}
+ debug_info("Unknown connection type %d", device->conn_type);
return IDEVICE_E_UNKNOWN_ERROR;
}
@@ -583,7 +583,8 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection,
return IDEVICE_E_UNKNOWN_ERROR;
}
return IDEVICE_E_SUCCESS;
- } else if (connection->type == CONNECTION_NETWORK) {
+ }
+ if (connection->type == CONNECTION_NETWORK) {
int s = socket_send((int)(long)connection->data, (void*)data, len);
if (s < 0) {
*sent_bytes = 0;
@@ -591,9 +592,9 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection,
}
*sent_bytes = s;
return IDEVICE_E_SUCCESS;
- } else {
- debug_info("Unknown connection type %d", connection->type);
}
+
+ debug_info("Unknown connection type %d", connection->type);
return IDEVICE_E_UNKNOWN_ERROR;
}
@@ -638,27 +639,26 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_send(idevice_connection_
}
*sent_bytes = sent;
return IDEVICE_E_SUCCESS;
- } else {
- uint32_t sent = 0;
- while (sent < len) {
- uint32_t bytes = 0;
- int s = internal_connection_send(connection, data+sent, len-sent, &bytes);
- if (s < 0) {
- break;
- }
- sent += bytes;
- }
- debug_info("len %d, sent %d", len, sent);
- if (sent < len) {
- *sent_bytes = sent;
- if (sent == 0) {
- return IDEVICE_E_UNKNOWN_ERROR;
- }
- return IDEVICE_E_NOT_ENOUGH_DATA;
+ }
+ uint32_t sent = 0;
+ while (sent < len) {
+ uint32_t bytes = 0;
+ int s = internal_connection_send(connection, data+sent, len-sent, &bytes);
+ if (s < 0) {
+ break;
}
+ sent += bytes;
+ }
+ debug_info("internal_connection_send %d, sent %d", len, sent);
+ if (sent < len) {
*sent_bytes = sent;
- return IDEVICE_E_SUCCESS;
+ if (sent == 0) {
+ return IDEVICE_E_UNKNOWN_ERROR;
+ }
+ return IDEVICE_E_NOT_ENOUGH_DATA;
}
+ *sent_bytes = sent;
+ return IDEVICE_E_SUCCESS;
}
static inline idevice_error_t socket_recv_to_idevice_error(int conn_error, uint32_t len, uint32_t received)
@@ -698,7 +698,8 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t
debug_info("ERROR: usbmuxd_recv_timeout returned %d (%s)", conn_error, strerror(-conn_error));
}
return error;
- } else if (connection->type == CONNECTION_NETWORK) {
+ }
+ if (connection->type == CONNECTION_NETWORK) {
int res = socket_receive_timeout((int)(long)connection->data, data, len, 0, timeout);
idevice_error_t error = socket_recv_to_idevice_error(res, 0, 0);
if (error == IDEVICE_E_SUCCESS) {
@@ -707,9 +708,9 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t
debug_info("ERROR: socket_receive_timeout returned %d (%s)", res, strerror(-res));
}
return error;
- } else {
- debug_info("Unknown connection type %d", connection->type);
}
+
+ debug_info("Unknown connection type %d", connection->type);
return IDEVICE_E_UNKNOWN_ERROR;
}
@@ -793,7 +794,8 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti
return IDEVICE_E_UNKNOWN_ERROR;
}
return IDEVICE_E_SUCCESS;
- } else if (connection->type == CONNECTION_NETWORK) {
+ }
+ if (connection->type == CONNECTION_NETWORK) {
int res = socket_receive((int)(long)connection->data, data, len);
if (res < 0) {
debug_info("ERROR: socket_receive returned %d (%s)", res, strerror(-res));
@@ -801,9 +803,9 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti
}
*recv_bytes = (uint32_t)res;
return IDEVICE_E_SUCCESS;
- } else {
- debug_info("Unknown connection type %d", connection->type);
}
+
+ debug_info("Unknown connection type %d", connection->type);
return IDEVICE_E_UNKNOWN_ERROR;
}
@@ -846,17 +848,17 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_get_fd(idevice_connectio
return IDEVICE_E_INVALID_ARG;
}
- idevice_error_t result = IDEVICE_E_UNKNOWN_ERROR;
if (connection->type == CONNECTION_USBMUXD) {
*fd = (int)(long)connection->data;
- result = IDEVICE_E_SUCCESS;
- } else if (connection->type == CONNECTION_NETWORK) {
+ return IDEVICE_E_SUCCESS;
+ }
+ if (connection->type == CONNECTION_NETWORK) {
*fd = (int)(long)connection->data;
- result = IDEVICE_E_SUCCESS;
- } else {
- debug_info("Unknown connection type %d", connection->type);
+ return IDEVICE_E_SUCCESS;
}
- return result;
+
+ debug_info("Unknown connection type %d", connection->type);
+ return IDEVICE_E_UNKNOWN_ERROR;
}
LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle)
diff --git a/src/lockdown.c b/src/lockdown.c
index 25e8c87..d0922dd 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -163,22 +163,22 @@ lockdownd_error_t lockdown_check_result(plist_t dict, const char *query_match)
if (plist_get_node_type(query_node) != PLIST_STRING) {
return ret;
- } else {
- char *query_value = NULL;
+ }
- plist_get_string_val(query_node, &query_value);
- if (!query_value) {
- return ret;
- }
+ char *query_value = NULL;
- if (query_match && (strcmp(query_value, query_match) != 0)) {
- free(query_value);
- return ret;
- }
+ plist_get_string_val(query_node, &query_value);
+ if (!query_value) {
+ return ret;
+ }
+ if (query_match && (strcmp(query_value, query_match) != 0)) {
free(query_value);
+ return ret;
}
+ free(query_value);
+
plist_t result_node = plist_dict_get_item(dict, "Result");
if (!result_node) {
/* iOS 5: the 'Result' key is not present anymore.
diff --git a/src/misagent.c b/src/misagent.c
index d790a05..af925f9 100644
--- a/src/misagent.c
+++ b/src/misagent.c
@@ -85,9 +85,8 @@ static misagent_error_t misagent_check_result(plist_t response, int* status_code
*status_code = (int)(val & 0xFFFFFFFF);
if (*status_code == 0) {
return MISAGENT_E_SUCCESS;
- } else {
- return MISAGENT_E_REQUEST_FAILED;
}
+ return MISAGENT_E_REQUEST_FAILED;
}
LIBIMOBILEDEVICE_API misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client)
diff --git a/src/mobileactivation.c b/src/mobileactivation.c
index 2de4333..79c7003 100644
--- a/src/mobileactivation.c
+++ b/src/mobileactivation.c
@@ -109,8 +109,6 @@ static plist_t plist_data_from_plist(plist_t plist)
static mobileactivation_error_t mobileactivation_check_result(plist_t dict, const char *command)
{
- mobileactivation_error_t ret = MOBILEACTIVATION_E_UNKNOWN_ERROR;
-
if (!dict || plist_get_node_type(dict) != PLIST_DICT) {
return MOBILEACTIVATION_E_PLIST_ERROR;
}
@@ -118,14 +116,13 @@ static mobileactivation_error_t mobileactivation_check_result(plist_t dict, cons
plist_t err_node = plist_dict_get_item(dict, "Error");
if (!err_node) {
return MOBILEACTIVATION_E_SUCCESS;
- } else {
- char *errmsg = NULL;
- plist_get_string_val(err_node, &errmsg);
- debug_info("ERROR: %s: %s", command, errmsg);
- ret = MOBILEACTIVATION_E_REQUEST_FAILED;
- free(errmsg);
}
- return ret;
+
+ char *errmsg = NULL;
+ plist_get_string_val(err_node, &errmsg);
+ debug_info("ERROR: %s: %s", command, errmsg);
+ free(errmsg);
+ return MOBILEACTIVATION_E_REQUEST_FAILED;
}
static mobileactivation_error_t mobileactivation_send_command_plist(mobileactivation_client_t client, plist_t command, plist_t *result)
diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c
index f4fde95..3726065 100644
--- a/src/mobilebackup2.c
+++ b/src/mobilebackup2.c
@@ -240,9 +240,8 @@ LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_
if (sent > 0) {
*bytes = sent;
return MOBILEBACKUP2_E_SUCCESS;
- } else {
- return MOBILEBACKUP2_E_MUX_ERROR;
}
+ return MOBILEBACKUP2_E_MUX_ERROR;
}
LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes)
@@ -265,11 +264,11 @@ LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_raw(mobilebacku
if (received > 0) {
*bytes = received;
return MOBILEBACKUP2_E_SUCCESS;
- } else if (received == 0) {
+ }
+ if (received == 0) {
return MOBILEBACKUP2_E_SUCCESS;
- } else {
- return MOBILEBACKUP2_E_MUX_ERROR;
}
+ return MOBILEBACKUP2_E_MUX_ERROR;
}
LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version)
diff --git a/src/preboard.c b/src/preboard.c
index b975f0e..4b3b444 100644
--- a/src/preboard.c
+++ b/src/preboard.c
@@ -162,7 +162,8 @@ static void* preboard_receive_status_loop_thread(void* arg)
preboard_error_t perr = preboard_receive_with_timeout(data->client, &pl, 1000);
if (perr == PREBOARD_E_TIMEOUT) {
continue;
- } else if (perr == PREBOARD_E_SUCCESS) {
+ }
+ if (perr == PREBOARD_E_SUCCESS) {
data->cbfunc(pl, data->user_data);
}
plist_free(pl);
diff --git a/src/restore.c b/src/restore.c
index 4e9d65a..591fd16 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -268,29 +268,27 @@ LIBIMOBILEDEVICE_API restored_error_t restored_query_value(restored_client_t cli
LIBIMOBILEDEVICE_API restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value)
{
+ plist_t item;
+
if (!client || !value || (value && *value))
return RESTORE_E_INVALID_ARG;
if (!client->info)
return RESTORE_E_NOT_ENOUGH_DATA;
- restored_error_t ret = RESTORE_E_SUCCESS;
- plist_t item = NULL;
-
if (!key) {
*value = plist_copy(client->info);
return RESTORE_E_SUCCESS;
- } else {
- item = plist_dict_get_item(client->info, key);
}
- if (item) {
- *value = plist_copy(item);
- } else {
- ret = RESTORE_E_PLIST_ERROR;
+ item = plist_dict_get_item(client->info, key);
+ if (!item) {
+ return RESTORE_E_PLIST_ERROR;
}
- return ret;
+ *value = plist_copy(item);
+ free(item);
+ return RESTORE_E_SUCCESS;
}
LIBIMOBILEDEVICE_API restored_error_t restored_client_new(idevice_t device, restored_client_t *client, const char *label)
diff --git a/src/syslog_relay.c b/src/syslog_relay.c
index c137297..ec9eca5 100644
--- a/src/syslog_relay.c
+++ b/src/syslog_relay.c
@@ -154,16 +154,15 @@ void *syslog_relay_worker(void *arg)
ret = syslog_relay_receive_with_timeout(srwt->client, &c, 1, &bytes, 100);
if (ret == SYSLOG_RELAY_E_TIMEOUT || ret == SYSLOG_RELAY_E_NOT_ENOUGH_DATA || ((bytes == 0) && (ret == SYSLOG_RELAY_E_SUCCESS))) {
continue;
- } else if (ret < 0) {
+ }
+ if (ret < 0) {
debug_info("Connection to syslog relay interrupted");
break;
}
if (srwt->is_raw) {
srwt->cbfunc(c, srwt->user_data);
- } else {
- if (c != 0) {
- srwt->cbfunc(c, srwt->user_data);
- }
+ } else if (c != 0) {
+ srwt->cbfunc(c, srwt->user_data);
}
}