mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
remove "myfiles" as a moniker for the root. Use NULL or empty string instead
This commit is contained in:
@@ -32,14 +32,14 @@ int mfconn_api_file_get_info(mfconn * conn, mffile * file,
|
|||||||
int mfconn_api_file_get_links(mfconn * conn, mffile * file,
|
int mfconn_api_file_get_links(mfconn * conn, mffile * file,
|
||||||
char *quickkey);
|
char *quickkey);
|
||||||
|
|
||||||
int mfconn_api_folder_create(mfconn * conn, char *parent,
|
int mfconn_api_folder_create(mfconn * conn, const char *parent,
|
||||||
char *name);
|
const char *name);
|
||||||
|
|
||||||
long mfconn_api_folder_get_content(mfconn * conn, int mode,
|
long mfconn_api_folder_get_content(mfconn * conn, int mode,
|
||||||
mffolder * folder_curr);
|
mffolder * folder_curr);
|
||||||
|
|
||||||
int mfconn_api_folder_get_info(mfconn * conn, mffolder * folder,
|
int mfconn_api_folder_get_info(mfconn * conn, mffolder * folder,
|
||||||
char *folderkey);
|
const char *folderkey);
|
||||||
|
|
||||||
int mfconn_api_user_get_info(mfconn * conn);
|
int mfconn_api_user_get_info(mfconn * conn);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#include "../mfconn.h"
|
#include "../mfconn.h"
|
||||||
#include "../apicalls.h" // IWYU pragma: keep
|
#include "../apicalls.h" // IWYU pragma: keep
|
||||||
|
|
||||||
int mfconn_api_folder_create(mfconn * conn, char *parent, char *name)
|
int mfconn_api_folder_create(mfconn * conn, const char *parent, const char *name)
|
||||||
{
|
{
|
||||||
const char *api_call;
|
const char *api_call;
|
||||||
int retval;
|
int retval;
|
||||||
@@ -39,19 +39,15 @@ int mfconn_api_folder_create(mfconn * conn, char *parent, char *name)
|
|||||||
if (strlen(name) < 1)
|
if (strlen(name) < 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// key must either be 11 chars or "myfiles"
|
// key must either be 13 chars or NULL
|
||||||
if (parent != NULL) {
|
if (parent != NULL && strlen(parent) != 13) {
|
||||||
if (strlen(parent) != 13) {
|
return -1;
|
||||||
// if it is myfiles, set paret to NULL
|
|
||||||
if (strcmp(parent, "myfiles") == 0)
|
|
||||||
parent = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent != NULL) {
|
if (parent != NULL) {
|
||||||
api_call =
|
api_call =
|
||||||
mfconn_create_signed_get(conn, 0, "folder/create.php",
|
mfconn_create_signed_get(conn, 0, "folder/create.php",
|
||||||
"?parent_key=%s" "&foldername=%s"
|
"?parent_key=%s&foldername=%s"
|
||||||
"&response_format=json", parent, name);
|
"&response_format=json", parent, name);
|
||||||
} else {
|
} else {
|
||||||
api_call =
|
api_call =
|
||||||
|
|||||||
@@ -51,18 +51,17 @@ mfconn_api_folder_get_content(mfconn * conn, int mode, mffolder * folder_curr)
|
|||||||
|
|
||||||
folderkey = folder_get_key(folder_curr);
|
folderkey = folder_get_key(folder_curr);
|
||||||
if (folderkey == NULL) {
|
if (folderkey == NULL) {
|
||||||
fprintf(stderr, "folder_get_key NULL\n");
|
api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php",
|
||||||
return 0;
|
"?content_type=%s"
|
||||||
}
|
"&response_format=json",
|
||||||
/*if (folderkey[0] == '\0') {
|
content_type);
|
||||||
fprintf(stderr, "folder_get_key '\\0'\n");
|
} else {
|
||||||
return 0;
|
|
||||||
} */
|
|
||||||
api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php",
|
api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php",
|
||||||
"?folder_key=%s"
|
"?folder_key=%s"
|
||||||
"&content_type=%s"
|
"&content_type=%s"
|
||||||
"&response_format=json",
|
"&response_format=json",
|
||||||
folderkey, content_type);
|
folderkey, content_type);
|
||||||
|
}
|
||||||
|
|
||||||
http = http_create();
|
http = http_create();
|
||||||
if (mode == 0)
|
if (mode == 0)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
static int _decode_folder_get_info(mfhttp * conn, void *data);
|
static int _decode_folder_get_info(mfhttp * conn, void *data);
|
||||||
|
|
||||||
int
|
int
|
||||||
mfconn_api_folder_get_info(mfconn * conn, mffolder * folder, char *folderkey)
|
mfconn_api_folder_get_info(mfconn * conn, mffolder * folder, const char *folderkey)
|
||||||
{
|
{
|
||||||
const char *api_call;
|
const char *api_call;
|
||||||
int retval;
|
int retval;
|
||||||
@@ -42,18 +42,21 @@ mfconn_api_folder_get_info(mfconn * conn, mffolder * folder, char *folderkey)
|
|||||||
|
|
||||||
if (folder == NULL)
|
if (folder == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if (folderkey == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
// key must either be 11 chars or "myfiles"
|
// key must either be 13 chars or NULL
|
||||||
if (strlen(folderkey) != 13) {
|
if (folderkey != NULL && strlen(folderkey) != 13) {
|
||||||
if (strcmp(folderkey, "myfiles") == 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (folderkey == NULL) {
|
||||||
api_call = mfconn_create_signed_get(conn, 0, "folder/get_info.php",
|
api_call = mfconn_create_signed_get(conn, 0, "folder/get_info.php",
|
||||||
"?folder_key=%s&response_format=json",
|
"?response_format=json");
|
||||||
|
} else {
|
||||||
|
api_call = mfconn_create_signed_get(conn, 0, "folder/get_info.php",
|
||||||
|
"?folder_key=%s"
|
||||||
|
"&response_format=json",
|
||||||
folderkey);
|
folderkey);
|
||||||
|
}
|
||||||
|
|
||||||
http = http_create();
|
http = http_create();
|
||||||
retval = http_get_buf(http, api_call, _decode_folder_get_info, folder);
|
retval = http_get_buf(http, api_call, _decode_folder_get_info, folder);
|
||||||
@@ -96,9 +99,9 @@ static int _decode_folder_get_info(mfhttp * conn, void *data)
|
|||||||
if (parent_folder != NULL) {
|
if (parent_folder != NULL) {
|
||||||
folder_set_parent(folder, json_string_value(parent_folder));
|
folder_set_parent(folder, json_string_value(parent_folder));
|
||||||
}
|
}
|
||||||
// infer that the parent folder must be "myfiles" root
|
// infer that the parent folder must be root
|
||||||
if (parent_folder == NULL && folderkey != NULL)
|
if (parent_folder == NULL && folderkey != NULL)
|
||||||
folder_set_parent(folder, "myfiles");
|
folder_set_parent(folder, NULL);
|
||||||
|
|
||||||
if (folderkey == NULL)
|
if (folderkey == NULL)
|
||||||
retval = -1;
|
retval = -1;
|
||||||
|
|||||||
@@ -55,14 +55,16 @@ int folder_set_key(mffolder * folder, const char *key)
|
|||||||
{
|
{
|
||||||
if (folder == NULL)
|
if (folder == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if (key == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
|
if (key == NULL) {
|
||||||
|
memset(folder->folderkey, 0, sizeof(folder->folderkey));
|
||||||
|
} else {
|
||||||
if (strlen(key) != 13)
|
if (strlen(key) != 13)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(folder->folderkey, 0, sizeof(folder->folderkey));
|
memset(folder->folderkey, 0, sizeof(folder->folderkey));
|
||||||
strncpy(folder->folderkey, key, sizeof(folder->folderkey) - 1);
|
strncpy(folder->folderkey, key, sizeof(folder->folderkey) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -72,23 +74,28 @@ const char *folder_get_key(mffolder * folder)
|
|||||||
if (folder == NULL)
|
if (folder == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (folder->folderkey[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
return folder->folderkey;
|
return folder->folderkey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int folder_set_parent(mffolder * folder, const char *parent_key)
|
int folder_set_parent(mffolder * folder, const char *parent_key)
|
||||||
{
|
{
|
||||||
if (folder == NULL)
|
if (folder == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if (parent_key == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
|
if (parent_key == NULL) {
|
||||||
|
memset(folder->parent, 0, sizeof(folder->parent));
|
||||||
|
} else {
|
||||||
if (strlen(parent_key) != 13) {
|
if (strlen(parent_key) != 13) {
|
||||||
if (strcmp(parent_key, "myfiles") != 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(folder->parent, 0, sizeof(folder->parent));
|
memset(folder->parent, 0, sizeof(folder->parent));
|
||||||
strncpy(folder->parent, parent_key, sizeof(folder->parent) - 1);
|
strncpy(folder->parent, parent_key, sizeof(folder->parent) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,19 +37,18 @@ int mfshell_cmd_chdir(mfshell * mfshell, int argc, char *const argv[])
|
|||||||
if (mfshell == NULL)
|
if (mfshell == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (argc != 2) {
|
switch (argc) {
|
||||||
|
case 1:
|
||||||
|
folderkey = NULL;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
folderkey = argv[1];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
fprintf(stderr, "Invalid number of arguments\n");
|
fprintf(stderr, "Invalid number of arguments\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
folderkey = argv[1];
|
|
||||||
if (folderkey == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
// change to root
|
|
||||||
if (strcmp(folderkey, "/") == 0)
|
|
||||||
folderkey = "myfiles";
|
|
||||||
|
|
||||||
// user wants to navigate up a level
|
// user wants to navigate up a level
|
||||||
if (strcmp(folderkey, "..") == 0) {
|
if (strcmp(folderkey, "..") == 0) {
|
||||||
// do several sanity checks to see if we're already at the root
|
// do several sanity checks to see if we're already at the root
|
||||||
@@ -57,8 +56,6 @@ int mfshell_cmd_chdir(mfshell * mfshell, int argc, char *const argv[])
|
|||||||
|
|
||||||
if (folder_curr == NULL)
|
if (folder_curr == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
if (strcmp(folder_curr, "myfiles") == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
folder_parent = folder_get_parent(mfshell->folder_curr);
|
folder_parent = folder_get_parent(mfshell->folder_curr);
|
||||||
|
|
||||||
@@ -69,17 +66,15 @@ int mfshell_cmd_chdir(mfshell * mfshell, int argc, char *const argv[])
|
|||||||
folderkey = folder_parent;
|
folderkey = folder_parent;
|
||||||
}
|
}
|
||||||
// check the lenght of the key
|
// check the lenght of the key
|
||||||
if (strlen(folderkey) != 13) {
|
if (folderkey != NULL && strlen(folderkey) != 13) {
|
||||||
// as a folder moniker, "myfiles" is an exception
|
|
||||||
if (strcmp(folderkey, "myfiles") != 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// create a new folder object to store the results
|
// create a new folder object to store the results
|
||||||
folder_new = folder_alloc();
|
folder_new = folder_alloc();
|
||||||
|
|
||||||
// navigate to root is a special case
|
// navigate to root is a special case
|
||||||
if (strcmp(folderkey, "myfiles") == 0) {
|
if (folderkey == NULL) {
|
||||||
folder_set_key(folder_new, "myfiles");
|
folder_set_key(folder_new, NULL);
|
||||||
retval = 0;
|
retval = 0;
|
||||||
} else {
|
} else {
|
||||||
retval = mfconn_api_folder_get_info(mfshell->conn,
|
retval = mfconn_api_folder_get_info(mfshell->conn,
|
||||||
|
|||||||
@@ -41,14 +41,6 @@ int mfshell_cmd_list(mfshell * mfshell, int argc, char *const argv[])
|
|||||||
|
|
||||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||||
|
|
||||||
// safety check... this should never happen
|
|
||||||
if (folder_curr == NULL)
|
|
||||||
folder_set_key(mfshell->folder_curr, "myfiles");
|
|
||||||
|
|
||||||
// safety check... this should never happen
|
|
||||||
if (folder_curr[0] == '\0')
|
|
||||||
folder_set_key(mfshell->folder_curr, "myfiles");
|
|
||||||
|
|
||||||
// first folders
|
// first folders
|
||||||
retval =
|
retval =
|
||||||
mfconn_api_folder_get_content(mfshell->conn, 0, mfshell->folder_curr);
|
mfconn_api_folder_get_content(mfshell->conn, 0, mfshell->folder_curr);
|
||||||
|
|||||||
@@ -45,18 +45,9 @@ int mfshell_cmd_mkdir(mfshell * mfshell, int argc, char *const argv[])
|
|||||||
|
|
||||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||||
|
|
||||||
// safety check... this should never happen
|
|
||||||
if (folder_curr == NULL)
|
|
||||||
folder_set_key(mfshell->folder_curr, "myfiles");
|
|
||||||
|
|
||||||
// safety check... this should never happen
|
|
||||||
if (folder_curr[0] == '\0')
|
|
||||||
folder_set_key(mfshell->folder_curr, "myfiles");
|
|
||||||
|
|
||||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||||
|
|
||||||
retval =
|
retval = mfconn_api_folder_create(mfshell->conn, folder_curr,
|
||||||
mfconn_api_folder_create(mfshell->conn, (char *)folder_curr,
|
|
||||||
(char *)name);
|
(char *)name);
|
||||||
mfconn_update_secret_key(mfshell->conn);
|
mfconn_update_secret_key(mfshell->conn);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ struct mfcmd commands[] = {
|
|||||||
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
||||||
{"ls", "", "show contents of active folder",
|
{"ls", "", "show contents of active folder",
|
||||||
mfshell_cmd_list},
|
mfshell_cmd_list},
|
||||||
{"cd", "[folderkey]", "change active folder", mfshell_cmd_chdir},
|
{"cd", "<folderkey>", "change active folder (default: root)", mfshell_cmd_chdir},
|
||||||
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
||||||
{"lpwd", "", "show the local working directory",
|
{"lpwd", "", "show the local working directory",
|
||||||
mfshell_cmd_lpwd},
|
mfshell_cmd_lpwd},
|
||||||
@@ -43,6 +43,7 @@ struct mfcmd commands[] = {
|
|||||||
mfshell_cmd_lcd},
|
mfshell_cmd_lcd},
|
||||||
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
||||||
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
||||||
|
{"folder", "<folderkey>", "show folder information (default:root)", mfshell_cmd_folder},
|
||||||
{"links", "[quickkey]", "show access urls for the file",
|
{"links", "[quickkey]", "show access urls for the file",
|
||||||
mfshell_cmd_links},
|
mfshell_cmd_links},
|
||||||
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
||||||
@@ -79,7 +80,8 @@ mfshell *mfshell_create(int app_id, char *app_key, char *server)
|
|||||||
|
|
||||||
// object to track folder location
|
// object to track folder location
|
||||||
shell->folder_curr = folder_alloc();
|
shell->folder_curr = folder_alloc();
|
||||||
folder_set_key(shell->folder_curr, "myfiles");
|
// set current folder to root
|
||||||
|
folder_set_key(shell->folder_curr, NULL);
|
||||||
|
|
||||||
// shell commands
|
// shell commands
|
||||||
shell->commands = commands;
|
shell->commands = commands;
|
||||||
|
|||||||
Reference in New Issue
Block a user