mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
Refactor code into utils, mfapi and mfshell
- utils is the low level library used by the others - mfapi uses utils and implements the api and some wrappers - mfshell uses mfapi and utils to provide a shell
This commit is contained in:
138
mfshell/commands/auth.c
Normal file
138
mfshell/commands/auth.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
|
||||
static char*
|
||||
_get_login_from_user(void);
|
||||
|
||||
static char*
|
||||
_get_passwd_from_user(void);
|
||||
|
||||
int
|
||||
mfshell_cmd_auth(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
int retval;
|
||||
char *username;
|
||||
char *password;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->server == NULL) return -1;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
username = _get_login_from_user();
|
||||
password = _get_passwd_from_user();
|
||||
break;
|
||||
case 2:
|
||||
username = argv[1];
|
||||
password = _get_passwd_from_user();
|
||||
break;
|
||||
case 3:
|
||||
username = argv[1];
|
||||
password = argv[2];
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(username == NULL || password == NULL) return -1;
|
||||
|
||||
mfshell->mfconn = mfconn_create(mfshell->server, username, password,
|
||||
mfshell->app_id, mfshell->app_key);
|
||||
|
||||
if (mfshell->mfconn != NULL)
|
||||
printf("\n\rAuthentication SUCCESS\n\r");
|
||||
else
|
||||
printf("\n\rAuthentication FAILURE\n\r");
|
||||
|
||||
return (mfshell->mfconn != NULL);
|
||||
}
|
||||
|
||||
char*
|
||||
_get_login_from_user(void)
|
||||
{
|
||||
char *login = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
|
||||
printf("login: ");
|
||||
bytes_read = getline(&login,&len,stdin);
|
||||
|
||||
if(bytes_read < 3)
|
||||
{
|
||||
if(login != NULL)
|
||||
{
|
||||
free(login);
|
||||
login = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (login[strlen(login)-1] == '\n')
|
||||
login[strlen(login)-1] = '\0';
|
||||
|
||||
|
||||
return login;
|
||||
}
|
||||
|
||||
char*
|
||||
_get_passwd_from_user(void)
|
||||
{
|
||||
char *passwd = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
struct termios old, new;
|
||||
|
||||
printf("passwd: ");
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &old) != 0)
|
||||
return NULL;
|
||||
new = old;
|
||||
new.c_lflag &= ~ECHO;
|
||||
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &new) != 0)
|
||||
return NULL;
|
||||
|
||||
bytes_read = getline(&passwd,&len,stdin);
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &old);
|
||||
|
||||
if(bytes_read < 3)
|
||||
{
|
||||
if(passwd != NULL)
|
||||
{
|
||||
free(passwd);
|
||||
passwd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (passwd[strlen(passwd)-1] == '\n')
|
||||
passwd[strlen(passwd)-1] = '\0';
|
||||
|
||||
return passwd;
|
||||
}
|
||||
|
||||
109
mfshell/commands/chdir.c
Normal file
109
mfshell/commands/chdir.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
#include "../../mfapi/apicalls.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_chdir(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
folder_t *folder_new;
|
||||
const char *folder_curr;
|
||||
const char *folder_parent;
|
||||
const char *folderkey;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
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
|
||||
if(strcmp(folderkey,"..") == 0)
|
||||
{
|
||||
// do several sanity checks to see if we're already at the root
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
if(folder_curr == NULL) return 0;
|
||||
if(strcmp(folder_curr,"myfiles") == 0) return 0;
|
||||
|
||||
folder_parent = folder_get_parent(mfshell->folder_curr);
|
||||
|
||||
if(folder_parent == NULL) return 0;
|
||||
|
||||
// it's pretty sure that we're not at the root
|
||||
folderkey = folder_parent;
|
||||
}
|
||||
|
||||
// check the lenght of the key
|
||||
if(strlen(folderkey) != 13)
|
||||
{
|
||||
// as a folder moniker, "myfiles" is an exception
|
||||
if(strcmp(folderkey,"myfiles") != 0) return -1;
|
||||
}
|
||||
|
||||
// create a new folder object to store the results
|
||||
folder_new = folder_alloc();
|
||||
|
||||
// navigate to root is a special case
|
||||
if(strcmp(folderkey,"myfiles") == 0)
|
||||
{
|
||||
folder_set_key(folder_new,"myfiles");
|
||||
retval = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = mfconn_api_folder_get_info(mfshell->mfconn,
|
||||
folder_new,(char*)folderkey);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
}
|
||||
|
||||
if(retval == 0)
|
||||
{
|
||||
if(mfshell->folder_curr != NULL)
|
||||
{
|
||||
folder_free(mfshell->folder_curr);
|
||||
mfshell->folder_curr = NULL;
|
||||
}
|
||||
|
||||
mfshell->folder_curr = folder_new;
|
||||
}
|
||||
else
|
||||
{
|
||||
folder_free(folder_new);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
69
mfshell/commands/debug.c
Normal file
69
mfshell/commands/debug.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_debug(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"server:",
|
||||
mfshell->server);
|
||||
|
||||
const char *session_token = mfconn_get_session_token(mfshell->mfconn);
|
||||
const char *secret_time = mfconn_get_secret_time(mfshell->mfconn);
|
||||
uint32_t secret_key = mfconn_get_secret_key(mfshell->mfconn);
|
||||
if(session_token != NULL && secret_time != NULL)
|
||||
{
|
||||
printf(" %-15.15s %"PRIu32"\n\r",
|
||||
"secret key:",
|
||||
secret_key);
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"secret time:",
|
||||
secret_time);
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"status:",
|
||||
"Authenticated");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"status:",
|
||||
"Not authenticated");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
77
mfshell/commands/file.c
Normal file
77
mfshell/commands/file.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
#include "../../mfapi/apicalls.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_file(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
file_t *file;
|
||||
int len;
|
||||
int retval;
|
||||
const char *quickkey;
|
||||
const char *name;
|
||||
const char *hash;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
quickkey = argv[1];
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
retval = mfconn_api_file_get_info(mfshell->mfconn,file,(char*)quickkey);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
quickkey = file_get_key(file);
|
||||
name = file_get_name(file);
|
||||
hash = file_get_hash(file);
|
||||
|
||||
if(name != NULL && name[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"filename:", name);
|
||||
|
||||
if(quickkey != NULL && quickkey[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"quickkey:", quickkey);
|
||||
|
||||
if(hash != NULL && hash[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"hash:", hash);
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
94
mfshell/commands/get.c
Normal file
94
mfshell/commands/get.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
#include "../../mfapi/apicalls.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_get(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
file_t *file;
|
||||
int len;
|
||||
int retval;
|
||||
ssize_t bytes_read;
|
||||
const char *quickkey;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
quickkey = argv[1];
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
// get file name
|
||||
retval = mfconn_api_file_get_info(mfshell->mfconn,file,(char*)quickkey);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
if(retval == -1)
|
||||
{
|
||||
file_free(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// request a direct download (streaming) link
|
||||
retval = mfconn_api_file_get_links(mfshell->mfconn,file,(char*)quickkey);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
if(retval == -1)
|
||||
{
|
||||
file_free(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// make sure we have a valid working directory to download to
|
||||
if(mfshell->local_working_dir == NULL)
|
||||
{
|
||||
mfshell->local_working_dir = (char*)calloc(PATH_MAX + 1,sizeof(char));
|
||||
getcwd(mfshell->local_working_dir,PATH_MAX);
|
||||
}
|
||||
|
||||
retval = file_download_direct(file, mfshell->local_working_dir);
|
||||
|
||||
if(retval != -1)
|
||||
printf("\r Downloaded %zd bytes OK!\n\r",bytes_read);
|
||||
else
|
||||
printf("\r\n Download FAILED!\n\r");
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
56
mfshell/commands/help.c
Normal file
56
mfshell/commands/help.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_help(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
printf(
|
||||
" arguments:\n\r"
|
||||
" <optional>\n\r"
|
||||
" [required]\n\r");
|
||||
|
||||
printf("\n\r");
|
||||
|
||||
int column1_width = 0;
|
||||
int column2_width = 0;
|
||||
|
||||
_cmd_t* curr_cmd;
|
||||
for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) {
|
||||
if (strlen(curr_cmd->name) > column1_width)
|
||||
column1_width = strlen(curr_cmd->name);
|
||||
if (strlen(curr_cmd->argstring) > column2_width)
|
||||
column2_width = strlen(curr_cmd->argstring);
|
||||
}
|
||||
|
||||
for (curr_cmd = mfshell->commands; curr_cmd->name != NULL; curr_cmd++) {
|
||||
printf("%*s %*s %s\n", column1_width, curr_cmd->name, column2_width, curr_cmd->argstring, curr_cmd->help);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
96
mfshell/commands/host.c
Normal file
96
mfshell/commands/host.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
|
||||
static char*
|
||||
_get_host_from_user(void);
|
||||
|
||||
int
|
||||
mfshell_cmd_host(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
char *alt_host = NULL;
|
||||
char *host;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
alt_host = _get_host_from_user();
|
||||
host = alt_host;
|
||||
break;
|
||||
case 2:
|
||||
host = argv[1];
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(mfshell->server != NULL)
|
||||
{
|
||||
// do nothing if the server is exactly the same
|
||||
if(strcmp(mfshell->server,host) == 0)
|
||||
{
|
||||
if(alt_host != NULL) free(alt_host);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(mfshell->server != NULL)
|
||||
{
|
||||
free(mfshell->server);
|
||||
mfshell->server = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
mfshell->server = strdup(host);
|
||||
|
||||
mfconn_destroy(mfshell->mfconn);
|
||||
|
||||
if(alt_host != NULL) free(alt_host);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char*
|
||||
_get_host_from_user(void)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *host = NULL;
|
||||
|
||||
printf("host: [www.mediafire.com] ");
|
||||
getline(&host,&len,stdin);
|
||||
if (host[strlen(host)-1] == '\n')
|
||||
host[strlen(host)-1] = '\0';
|
||||
|
||||
if(host == NULL)
|
||||
return strdup("www.mediafire.com");
|
||||
|
||||
if(strlen(host) < 2)
|
||||
{
|
||||
free(host);
|
||||
return strdup("www.mediafire.com");
|
||||
}
|
||||
|
||||
return host;
|
||||
}
|
||||
61
mfshell/commands/lcd.c
Normal file
61
mfshell/commands/lcd.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_lcd(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
int retval;
|
||||
const char *dir;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dir = argv[1];
|
||||
if(dir == NULL) return -1;
|
||||
|
||||
if(strlen(dir) < 1) return -1;
|
||||
|
||||
retval = chdir(dir);
|
||||
if(retval == 0)
|
||||
{
|
||||
if(mfshell->local_working_dir != NULL)
|
||||
{
|
||||
free(mfshell->local_working_dir);
|
||||
mfshell->local_working_dir = NULL;
|
||||
}
|
||||
|
||||
mfshell->local_working_dir = strdup(dir);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
78
mfshell/commands/links.c
Normal file
78
mfshell/commands/links.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
#include "../../mfapi/apicalls.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_links(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
file_t *file;
|
||||
int len;
|
||||
int retval;
|
||||
const char *quickkey;
|
||||
const char *share_link;
|
||||
const char *direct_link;
|
||||
const char *onetime_link;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
quickkey = argv[1];
|
||||
if(quickkey == NULL) return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
retval = mfconn_api_file_get_links(mfshell->mfconn,file,(char*)quickkey);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
share_link = file_get_share_link(file);
|
||||
direct_link = file_get_direct_link(file);
|
||||
onetime_link = file_get_onetime_link(file);
|
||||
|
||||
if(share_link != NULL && share_link[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"sharing url:", share_link);
|
||||
|
||||
if(direct_link != NULL && direct_link[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"direct url:", direct_link);
|
||||
|
||||
if(onetime_link != NULL && onetime_link[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"1-time url:", onetime_link);
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
63
mfshell/commands/list.c
Normal file
63
mfshell/commands/list.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
#include "../../mfapi/apicalls.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_list(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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
|
||||
retval = mfconn_api_folder_get_content(mfshell->mfconn, 0, mfshell->folder_curr);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
// then files
|
||||
retval = mfconn_api_folder_get_content(mfshell->mfconn, 1, mfshell->folder_curr);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
49
mfshell/commands/lpwd.c
Normal file
49
mfshell/commands/lpwd.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_lpwd(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of argumens\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(mfshell->local_working_dir == NULL)
|
||||
{
|
||||
mfshell->local_working_dir = (char*)calloc(PATH_MAX + 1,sizeof(char));
|
||||
getcwd(mfshell->local_working_dir,PATH_MAX);
|
||||
}
|
||||
|
||||
printf("%s\n\r", mfshell->local_working_dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
64
mfshell/commands/mkdir.c
Normal file
64
mfshell/commands/mkdir.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h"
|
||||
#include "../../mfapi/apicalls.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_mkdir(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
const char *name;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = argv[1];
|
||||
if (name == NULL) return -1;
|
||||
|
||||
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);
|
||||
|
||||
retval = mfconn_api_folder_create(mfshell->mfconn,(char*)folder_curr,(char*)name);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
56
mfshell/commands/pwd.c
Normal file
56
mfshell/commands/pwd.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../commands.h"
|
||||
#include "../mfshell.h"
|
||||
#include "../../utils/strings.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_pwd(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
const char *folder_name;
|
||||
char *folder_name_tmp = NULL;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->folder_curr == NULL) return -1;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
folder_name = folder_get_name(mfshell->folder_curr);
|
||||
if(folder_name[0] == '\0') return -1;
|
||||
|
||||
folder_name_tmp = strdup_printf("< %s >",folder_name);
|
||||
|
||||
printf("%-15.13s %-50.50s\n\r",
|
||||
folder_get_key(mfshell->folder_curr),
|
||||
folder_name_tmp);
|
||||
|
||||
free(folder_name_tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
45
mfshell/commands/whoami.c
Normal file
45
mfshell/commands/whoami.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
* 2014 Johannes Schauer <j.schauer@email.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2, as published by
|
||||
* the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../commands.h"
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/apicalls.h"
|
||||
|
||||
int
|
||||
mfshell_cmd_whoami(mfshell_t *mfshell, int argc, char **argv)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
retval = mfconn_api_user_get_info(mfshell->mfconn);
|
||||
mfconn_update_secret_key(mfshell->mfconn);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user