summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2012-07-17 19:39:59 +0200
committerGravatar Nikias Bassen2012-07-17 19:39:59 +0200
commitb946da48d08bc52f78103a196dc3c23b23889830 (patch)
tree88593e10e6000b99d9fa0a52426be4db4b1946f4
parent266b5cbbf49c8df964e6e44e711ee7a94f7dfc50 (diff)
downloadidevicerestore-b946da48d08bc52f78103a196dc3c23b23889830.tar.gz
idevicerestore-b946da48d08bc52f78103a196dc3c23b23889830.tar.bz2
tss: Don't crash on errors like failed connection attempts and be more verbose
-rw-r--r--src/idevicerestore.c3
-rw-r--r--src/tss.c22
2 files changed, 18 insertions, 7 deletions
diff --git a/src/idevicerestore.c b/src/idevicerestore.c
index 5080146..f33df1d 100644
--- a/src/idevicerestore.c
+++ b/src/idevicerestore.c
@@ -1302,7 +1302,6 @@ int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, unsign
return -1;
}
- info("Sending TSS request... ");
response = tss_send_request(request);
if (response == NULL) {
info("ERROR: Unable to send TSS request\n");
@@ -1310,7 +1309,7 @@ int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, unsign
return -1;
}
- info("received SHSH blobs\n");
+ info("Received SHSH blobs\n");
plist_free(request);
*tss = response;
diff --git a/src/tss.c b/src/tss.c
index d7c850d..62df0a4 100644
--- a/src/tss.c
+++ b/src/tss.c
@@ -304,14 +304,17 @@ size_t tss_write_callback(char* data, size_t size, size_t nmemb, tss_response* r
plist_t tss_send_request(plist_t tss_request) {
curl_global_init(CURL_GLOBAL_ALL);
- int status_code = -1;
char* request = NULL;
+ int status_code = -1;
int retry = 0;
int max_retries = 15;
unsigned int size = 0;
+ char curl_error_message[CURL_ERROR_SIZE];
+
plist_to_xml(tss_request, &request, &size);
tss_response* response = NULL;
+ memset(curl_error_message, '\0', CURL_ERROR_SIZE);
while (retry++ < max_retries) {
response = NULL;
@@ -334,6 +337,7 @@ plist_t tss_send_request(plist_t tss_request) {
response->content = malloc(1);
response->content[0] = '\0';
+ curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, &curl_error_message);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, (curl_write_callback)&tss_write_callback);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, header);
@@ -346,12 +350,15 @@ plist_t tss_send_request(plist_t tss_request) {
curl_easy_setopt(handle, CURLOPT_URL, "http://gs.apple.com/TSS/controller?action=2");
}
+ info("Sending TSS request attempt %d... ", retry);
+
curl_easy_perform(handle);
curl_slist_free_all(header);
curl_easy_cleanup(handle);
if (strstr(response->content, "MESSAGE=SUCCESS")) {
status_code = 0;
+ info("response successfully received\n");
break;
}
@@ -364,6 +371,7 @@ plist_t tss_send_request(plist_t tss_request) {
sscanf(status+7, "%d&%*s", &status_code);
}
if (status_code == -1) {
+ error("%s\n", curl_error_message);
// no status code in response. retry
free(response->content);
free(response);
@@ -387,20 +395,24 @@ plist_t tss_send_request(plist_t tss_request) {
}
if (status_code != 0) {
- char* message = strstr(response->content, "MESSAGE=") + strlen("MESSAGE=");
- error("ERROR: TSS request failed (status=%d, message=%s)\n", status_code, message);
+ if (strstr(response->content, "MESSAGE=") != NULL) {
+ char* message = strstr(response->content, "MESSAGE=") + strlen("MESSAGE=");
+ error("ERROR: TSS request failed (status=%d, message=%s)\n", status_code, message);
+ } else {
+ error("ERROR: TSS request failed: %s (status=%d)\n", curl_error_message, status_code);
+ }
+ free(request);
free(response->content);
free(response);
- free(request);
return NULL;
}
char* tss_data = strstr(response->content, "<?xml");
if (tss_data == NULL) {
error("ERROR: Incorrectly formatted TSS response\n");
+ free(request);
free(response->content);
free(response);
- free(request);
return NULL;
}