Skip to content

Commit

Permalink
activation: Improve code readability by removing unnecessary conditio…
Browse files Browse the repository at this point in the history
…nals
  • Loading branch information
zbalaton committed Jul 12, 2017
1 parent 1535df6 commit ae905b1
Showing 1 changed file with 30 additions and 51 deletions.
81 changes: 30 additions & 51 deletions src/activation.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,24 +705,19 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_request_new
fprintf(stderr, "%s: Unable to get SerialNumber from lockdownd\n", __func__);
plist_free(fields);
return IDEVICE_ACTIVATION_E_INCOMPLETE_INFO;
} else {
plist_dict_set_item(fields, "AppleSerialNumber", plist_copy(node));
}
if (node) {
plist_free(node);
node = NULL;
}
plist_dict_set_item(fields, "AppleSerialNumber", plist_copy(node));
plist_free(node);
node = NULL;

// check if device has telephone capability
if ((lockdownd_get_value(lockdown, NULL, "TelephonyCapability", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_BOOLEAN)) {
has_telephony_capability = 0;
} else {
plist_get_bool_val(node, &has_telephony_capability);
}
if (node) {
plist_free(node);
node = NULL;
}
plist_free(node);
node = NULL;

if (has_telephony_capability) {
// add IMEI
Expand All @@ -732,10 +727,8 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_request_new
plist_dict_set_item(fields, "IMEI", plist_copy(node));
has_mobile_equipment_id = 1;
}
if (node) {
plist_free(node);
node = NULL;
}
plist_free(node);
node = NULL;

// add MEID
if ((lockdownd_get_value(lockdown, NULL, "MobileEquipmentIdentifier", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
Expand All @@ -748,10 +741,8 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_request_new
} else {
plist_dict_set_item(fields, "MEID", plist_copy(node));
}
if (node) {
plist_free(node);
node = NULL;
}
plist_free(node);
node = NULL;

// add IMSI
if ((lockdownd_get_value(lockdown, NULL, "InternationalMobileSubscriberIdentity", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
Expand All @@ -760,10 +751,8 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_request_new
} else {
plist_dict_set_item(fields, "IMSI", plist_copy(node));
}
if (node) {
plist_free(node);
node = NULL;
}
plist_free(node);
node = NULL;

// add ICCID
if ((lockdownd_get_value(lockdown, NULL, "IntegratedCircuitCardIdentity", &node) != LOCKDOWN_E_SUCCESS) || !node || (plist_get_node_type(node) != PLIST_STRING)) {
Expand All @@ -772,10 +761,8 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_request_new
} else {
plist_dict_set_item(fields, "ICCID", plist_copy(node));
}
if (node) {
plist_free(node);
node = NULL;
}
plist_free(node);
node = NULL;
}

// add activation-info
Expand Down Expand Up @@ -829,9 +816,7 @@ IDEVICE_ACTIVATION_API void idevice_activation_request_free(idevice_activation_r
if (!request)
return;

if (request->fields)
plist_free(request->fields);

plist_free(request->fields);
free(request);
}

Expand Down Expand Up @@ -1009,16 +994,17 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_response_to

IDEVICE_ACTIVATION_API void idevice_activation_response_free(idevice_activation_response_t response)
{
if (response) {
free(response->raw_content);
free(response->title);
free(response->description);
plist_free(response->activation_record);
plist_free(response->fields);
plist_free(response->fields_require_input);
plist_free(response->labels);
free(response);
}
if (!response)
return;

free(response->raw_content);
free(response->title);
free(response->description);
plist_free(response->activation_record);
plist_free(response->fields);
plist_free(response->fields_require_input);
plist_free(response->labels);
free(response);
}

IDEVICE_ACTIVATION_API void idevice_activation_response_get_field(idevice_activation_response_t response, const char* key, char** value)
Expand Down Expand Up @@ -1102,10 +1088,7 @@ IDEVICE_ACTIVATION_API int idevice_activation_response_field_requires_input(idev
if (!response || !key)
return 0;

if (plist_dict_get_item(response->fields_require_input, key)) {
return 1;
}
return 0;
return (plist_dict_get_item(response->fields_require_input, key) ? 1 : 0);
}

IDEVICE_ACTIVATION_API int idevice_activation_response_has_errors(idevice_activation_response_t response)
Expand Down Expand Up @@ -1174,8 +1157,7 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_send_reques

curl_formadd(&form, &last, CURLFORM_COPYNAME, key, CURLFORM_COPYCONTENTS, svalue, CURLFORM_END);

if (svalue)
free(svalue);
free(svalue);
svalue = NULL;
}
}
Expand All @@ -1194,8 +1176,7 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_send_reques
plist_get_string_val(value_node, &svalue);
} else {
// only strings supported
if (postdata)
free(postdata);
free(postdata);
result = IDEVICE_ACTIVATION_E_UNSUPPORTED_FIELD_TYPE;
goto cleanup;
}
Expand All @@ -1208,8 +1189,7 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_send_reques
free(value_encoded);
}

if (svalue)
free(svalue);
free(svalue);
svalue = NULL;
}
}
Expand Down Expand Up @@ -1271,8 +1251,7 @@ IDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_send_reques
result = IDEVICE_ACTIVATION_E_SUCCESS;

cleanup:
if (iter)
free(iter);
free(iter);
if (form)
curl_formfree(form);
if (slist)
Expand Down

0 comments on commit ae905b1

Please sign in to comment.