mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
mfconn_create_signed_get: add more verbosity to error conditions
This commit is contained in:
@@ -57,6 +57,10 @@ int mfconn_api_device_get_changes(mfconn * conn, uint64_t revision,
|
||||
api_call = mfconn_create_signed_get(conn, 0, "device/get_changes.php",
|
||||
"?revision=%" PRIu64
|
||||
"&response_format=json", revision);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval =
|
||||
|
||||
@@ -61,6 +61,10 @@ int mfconn_api_device_get_patch(mfconn * conn, mfpatch * patch,
|
||||
"&target_revision=%" PRIu64
|
||||
"&response_format=json", quickkey,
|
||||
source_revision, target_revision);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_device_get_patch,
|
||||
|
||||
@@ -41,6 +41,10 @@ int mfconn_api_device_get_status(mfconn * conn, uint64_t * revision)
|
||||
for (i = 0; i < mfconn_get_max_num_retries(conn); i++) {
|
||||
api_call = mfconn_create_signed_get(conn, 0, "device/get_status.php",
|
||||
"?response_format=json");
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval =
|
||||
|
||||
@@ -82,6 +82,11 @@ int mfconn_api_device_get_updates(mfconn * conn, const char *quickkey,
|
||||
quickkey, revision,
|
||||
target_revision);
|
||||
}
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_device_get_updates,
|
||||
(void *)patches);
|
||||
|
||||
@@ -45,6 +45,10 @@ int mfconn_api_file_delete(mfconn * conn, const char *quickkey)
|
||||
api_call = mfconn_create_signed_get(conn, 0, "file/delete.php",
|
||||
"?quick_key=%s"
|
||||
"&response_format=json", quickkey);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval =
|
||||
|
||||
@@ -58,6 +58,10 @@ int mfconn_api_file_get_info(mfconn * conn, mffile * file,
|
||||
api_call = mfconn_create_signed_get(conn, 0, "file/get_info.php",
|
||||
"?quick_key=%s"
|
||||
"&response_format=json", quickkey);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_file_get_info, file);
|
||||
|
||||
@@ -56,6 +56,10 @@ int mfconn_api_file_get_links(mfconn * conn, mffile * file,
|
||||
api_call = mfconn_create_signed_get(conn, 0, "file/get_links.php",
|
||||
"?quick_key=%s"
|
||||
"&response_format=json", quickkey);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_file_get_links, file);
|
||||
|
||||
@@ -59,6 +59,10 @@ int mfconn_api_folder_create(mfconn * conn, const char *parent,
|
||||
"?foldername=%s&response_format=json",
|
||||
name);
|
||||
}
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, mfapi_decode_common,
|
||||
|
||||
@@ -46,6 +46,10 @@ int mfconn_api_folder_delete(mfconn * conn, const char *folderkey)
|
||||
"?folder_key=%s"
|
||||
"&response_format=json",
|
||||
folderkey);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, mfapi_decode_common,
|
||||
|
||||
@@ -99,6 +99,10 @@ mfconn_api_folder_get_content(mfconn * conn, const int mode,
|
||||
"&response_format=json",
|
||||
folderkey, content_type);
|
||||
}
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
if (mode == 0)
|
||||
|
||||
@@ -61,6 +61,10 @@ mfconn_api_folder_get_info(mfconn * conn, mffolder * folder,
|
||||
"&response_format=json",
|
||||
folderkey);
|
||||
}
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_folder_get_info, folder);
|
||||
|
||||
@@ -89,6 +89,10 @@ mfconn_api_upload_patch(mfconn * conn, const char *quickkey,
|
||||
"&quickkey=%s", source_hash,
|
||||
target_hash, target_size,
|
||||
quickkey);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
custom_headers = curl_slist_append(custom_headers,
|
||||
"x-filename: dummy.patch");
|
||||
|
||||
@@ -56,6 +56,10 @@ mfconn_api_upload_poll_upload(mfconn * conn, const char *upload_key,
|
||||
"upload/poll_upload.php",
|
||||
"?response_format=json"
|
||||
"&key=%s", upload_key);
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_unsigned_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_upload_poll_upload,
|
||||
|
||||
@@ -90,7 +90,10 @@ mfconn_api_upload_simple(mfconn * conn, const char *folderkey,
|
||||
"?response_format=json"
|
||||
"&folder_key=%s", folderkey);
|
||||
}
|
||||
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
// make sure that we are at the beginning of the file
|
||||
rewind(fh);
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ int mfconn_api_user_get_info(mfconn * conn)
|
||||
|
||||
api_call = mfconn_create_signed_get(conn, 0, "user/get_info.php",
|
||||
"?response_format=json");
|
||||
if (api_call == NULL) {
|
||||
fprintf(stderr, "mfconn_create_signed_get failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
retval = http_get_buf(http, api_call, _decode_user_get_info, NULL);
|
||||
|
||||
@@ -225,18 +225,24 @@ const char *mfconn_create_unsigned_get(mfconn * conn, int ssl,
|
||||
int api_len;
|
||||
va_list ap;
|
||||
|
||||
if (conn == NULL)
|
||||
if (conn == NULL) {
|
||||
fprintf(stderr, "conn cannot be NULL\n");
|
||||
return NULL;
|
||||
if (conn->server == NULL)
|
||||
}
|
||||
if (conn->server == NULL) {
|
||||
fprintf(stderr, "server cannot be NULL\n");
|
||||
return NULL;
|
||||
|
||||
}
|
||||
// make sure the api (ex: user/get_info.php) is sane
|
||||
if (api == NULL)
|
||||
if (api == NULL) {
|
||||
fprintf(stderr, "api call cannot be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
api_len = strlen(api);
|
||||
if (api_len < 3)
|
||||
if (api_len < 3) {
|
||||
fprintf(stderr, "api call length cannot be less than 3\n");
|
||||
return NULL;
|
||||
|
||||
}
|
||||
// calculate how big of a buffer we need
|
||||
va_start(ap, fmt);
|
||||
api_args_len = (vsnprintf(NULL, 0, fmt, ap) + 1); // + 1 for NULL
|
||||
@@ -252,8 +258,10 @@ const char *mfconn_create_unsigned_get(mfconn * conn, int ssl,
|
||||
va_end(ap);
|
||||
|
||||
// correct user error of trailing slash
|
||||
if (api[api_len - 1] == '/')
|
||||
if (api[api_len - 1] == '/') {
|
||||
fprintf(stderr, "api call must not end with slash\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
api_request = strdup_printf("%s//%s/api/%s",
|
||||
(ssl ? "https:" : "http:"), conn->server, api);
|
||||
@@ -290,22 +298,32 @@ const char *mfconn_create_signed_get(mfconn * conn, int ssl,
|
||||
int api_len;
|
||||
va_list ap;
|
||||
|
||||
if (conn == NULL)
|
||||
if (conn == NULL) {
|
||||
fprintf(stderr, "conn cannot be NULL\n");
|
||||
return NULL;
|
||||
if (conn->server == NULL)
|
||||
}
|
||||
if (conn->server == NULL) {
|
||||
fprintf(stderr, "server cannot be NULL\n");
|
||||
return NULL;
|
||||
if (conn->secret_time == NULL)
|
||||
}
|
||||
if (conn->secret_time == NULL) {
|
||||
fprintf(stderr, "secret_time cannot be NULL\n");
|
||||
return NULL;
|
||||
if (conn->session_token == NULL)
|
||||
}
|
||||
if (conn->session_token == NULL) {
|
||||
fprintf(stderr, "session_token cannot be NULL\n");
|
||||
return NULL;
|
||||
|
||||
}
|
||||
// make sure the api (ex: user/get_info.php) is sane
|
||||
if (api == NULL)
|
||||
if (api == NULL) {
|
||||
fprintf(stderr, "api name cannot be NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
api_len = strlen(api);
|
||||
if (api_len < 3)
|
||||
if (api_len < 3) {
|
||||
fprintf(stderr, "api name length cannot be less than 3\n");
|
||||
return NULL;
|
||||
|
||||
}
|
||||
// calculate how big of a buffer we need
|
||||
va_start(ap, fmt);
|
||||
api_args_len = (vsnprintf(NULL, 0, fmt, ap) + 1); // + 1 for NULL
|
||||
@@ -328,8 +346,10 @@ const char *mfconn_create_signed_get(mfconn * conn, int ssl,
|
||||
free(session_token);
|
||||
|
||||
// correct user error of trailing slash
|
||||
if (api[api_len - 1] == '/')
|
||||
if (api[api_len - 1] == '/') {
|
||||
fprintf(stderr, "api name cannot end with slash\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
api_request = strdup_printf("%s//%s/api/%s",
|
||||
(ssl ? "https:" : "http:"), conn->server, api);
|
||||
|
||||
Reference in New Issue
Block a user