if apicall failed - retry

This commit is contained in:
josch
2014-12-06 11:04:04 +01:00
parent dd3291a9c4
commit 8468a39c0a
20 changed files with 579 additions and 211 deletions

View File

@@ -38,6 +38,7 @@ int mfconn_api_file_get_info(mfconn * conn, mffile * file,
int retval;
int len;
mfhttp *http;
int i;
if (conn == NULL)
return -1;
@@ -53,16 +54,34 @@ int mfconn_api_file_get_info(mfconn * conn, mffile * file,
if (len != 11 && len != 15)
return -1;
api_call = mfconn_create_signed_get(conn, 0, "file/get_info.php",
"?quick_key=%s&response_format=json",
quickkey);
for (i = 0; i < mfconn_get_max_num_retries(conn); i++) {
api_call = mfconn_create_signed_get(conn, 0, "file/get_info.php",
"?quick_key=%s"
"&response_format=json", quickkey);
http = http_create();
retval = http_get_buf(http, api_call, _decode_file_get_info, file);
http_destroy(http);
mfconn_update_secret_key(conn);
http = http_create();
retval = http_get_buf(http, api_call, _decode_file_get_info, file);
http_destroy(http);
mfconn_update_secret_key(conn);
free((void *)api_call);
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;
}