mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 21:24:28 -08:00
if apicall failed - retry
This commit is contained in:
@@ -39,6 +39,8 @@ int mfconn_api_device_get_updates(mfconn * conn, const char *quickkey,
|
||||
int len;
|
||||
mfhttp *http;
|
||||
int retval;
|
||||
int i,
|
||||
j;
|
||||
|
||||
if (conn == NULL)
|
||||
return -1;
|
||||
@@ -54,27 +56,56 @@ int mfconn_api_device_get_updates(mfconn * conn, const char *quickkey,
|
||||
if (len != 15)
|
||||
return -1;
|
||||
|
||||
if (target_revision == 0) {
|
||||
api_call = mfconn_create_signed_get(conn, 0, "device/get_updates.php",
|
||||
"?quick_key=%s"
|
||||
"&revision=%" PRIu64
|
||||
"&response_format=json", quickkey,
|
||||
revision);
|
||||
} else {
|
||||
api_call = mfconn_create_signed_get(conn, 0, "device/get_updates.php",
|
||||
"?quick_key=%s"
|
||||
"&revision=%" PRIu64
|
||||
"&target_revision=%" PRIu64
|
||||
"&response_format=json", quickkey,
|
||||
revision, target_revision);
|
||||
}
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_device_get_updates,
|
||||
(void *)patches);
|
||||
http_destroy(http);
|
||||
mfconn_update_secret_key(conn);
|
||||
for (i = 0; i < mfconn_get_max_num_retries(conn); i++) {
|
||||
if (*patches != NULL) {
|
||||
for (j = 0; (*patches)[j] != NULL; j++) {
|
||||
patch_free((*patches)[j]);
|
||||
}
|
||||
free(*patches);
|
||||
*patches = NULL;
|
||||
}
|
||||
|
||||
free((void *)api_call);
|
||||
if (target_revision == 0) {
|
||||
api_call = mfconn_create_signed_get(conn, 0,
|
||||
"device/get_updates.php",
|
||||
"?quick_key=%s"
|
||||
"&revision=%" PRIu64
|
||||
"&response_format=json",
|
||||
quickkey, revision);
|
||||
} else {
|
||||
api_call = mfconn_create_signed_get(conn, 0,
|
||||
"device/get_updates.php",
|
||||
"?quick_key=%s"
|
||||
"&revision=%" PRIu64
|
||||
"&target_revision=%" PRIu64
|
||||
"&response_format=json",
|
||||
quickkey, revision,
|
||||
target_revision);
|
||||
}
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_device_get_updates,
|
||||
(void *)patches);
|
||||
http_destroy(http);
|
||||
mfconn_update_secret_key(conn);
|
||||
|
||||
free((void *)api_call);
|
||||
|
||||
if (retval != 127 && retval != 28)
|
||||
break;
|
||||
|
||||
// if there was either a curl timeout or a token error, get a new
|
||||
// token and try again
|
||||
//
|
||||
// on a curl timeout we get a new token because it is likely that we
|
||||
// lost signature synchronization (we don't know whether the server
|
||||
// accepted or rejected the last call)
|
||||
fprintf(stderr, "got error %d - negotiate a new token\n", retval);
|
||||
retval = mfconn_refresh_token(conn);
|
||||
if (retval != 0) {
|
||||
fprintf(stderr, "failed to get a new token\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user