mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 21:24:28 -08:00
use gnu indent to enforce coding style and adapt source
- indent options are listed in ./.indent.pro - use test case to run indent
This commit is contained in:
@@ -17,40 +17,39 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _MFSHELL_COMMAND_H_
|
||||
#define _MFSHELL_COMMAND_H_
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
int mfshell_cmd_help(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_help(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_debug(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_debug(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_host(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_host(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_auth(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_auth(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_whomai(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_whomai(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_list(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_list(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_chdir(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_chdir(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_pwd(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_pwd(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_lpwd(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_lpwd(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_lcd(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_file(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_file(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_links(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_links(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_mkdir(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_mkdir(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_get(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_get(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_cmd_whoami(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_cmd_whoami(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -27,22 +26,21 @@
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
static char*
|
||||
_get_login_from_user(void);
|
||||
static char *_get_login_from_user(void);
|
||||
|
||||
static char*
|
||||
_get_passwd_from_user(void);
|
||||
static char *_get_passwd_from_user(void);
|
||||
|
||||
int
|
||||
mfshell_cmd_auth(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_auth(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
char *username;
|
||||
char *password;
|
||||
char *username;
|
||||
char *password;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->server == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
if (mfshell->server == NULL)
|
||||
return -1;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
@@ -62,10 +60,11 @@ mfshell_cmd_auth(mfshell *mfshell, int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(username == NULL || password == NULL) return -1;
|
||||
if (username == NULL || password == NULL)
|
||||
return -1;
|
||||
|
||||
mfshell->conn = mfconn_create(mfshell->server, username, password,
|
||||
mfshell->app_id, mfshell->app_key);
|
||||
mfshell->app_id, mfshell->app_key);
|
||||
|
||||
if (mfshell->conn != NULL)
|
||||
printf("\n\rAuthentication SUCCESS\n\r");
|
||||
@@ -75,39 +74,35 @@ mfshell_cmd_auth(mfshell *mfshell, int argc, char **argv)
|
||||
return (mfshell->conn != NULL);
|
||||
}
|
||||
|
||||
char*
|
||||
_get_login_from_user(void)
|
||||
char *_get_login_from_user(void)
|
||||
{
|
||||
char *login = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
char *login = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
|
||||
printf("login: ");
|
||||
bytes_read = getline(&login,&len,stdin);
|
||||
bytes_read = getline(&login, &len, stdin);
|
||||
|
||||
if(bytes_read < 3)
|
||||
{
|
||||
if(login != NULL)
|
||||
{
|
||||
if (bytes_read < 3) {
|
||||
if (login != NULL) {
|
||||
free(login);
|
||||
login = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (login[strlen(login)-1] == '\n')
|
||||
login[strlen(login)-1] = '\0';
|
||||
|
||||
if (login[strlen(login) - 1] == '\n')
|
||||
login[strlen(login) - 1] = '\0';
|
||||
|
||||
return login;
|
||||
}
|
||||
|
||||
char*
|
||||
_get_passwd_from_user(void)
|
||||
char *_get_passwd_from_user(void)
|
||||
{
|
||||
char *passwd = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
struct termios old, new;
|
||||
char *passwd = NULL;
|
||||
size_t len;
|
||||
ssize_t bytes_read;
|
||||
struct termios old,
|
||||
new;
|
||||
|
||||
printf("passwd: ");
|
||||
|
||||
@@ -118,22 +113,19 @@ _get_passwd_from_user(void)
|
||||
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &new) != 0)
|
||||
return NULL;
|
||||
|
||||
bytes_read = getline(&passwd,&len,stdin);
|
||||
bytes_read = getline(&passwd, &len, stdin);
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSAFLUSH, &old);
|
||||
|
||||
if(bytes_read < 3)
|
||||
{
|
||||
if(passwd != NULL)
|
||||
{
|
||||
if (bytes_read < 3) {
|
||||
if (passwd != NULL) {
|
||||
free(passwd);
|
||||
passwd = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (passwd[strlen(passwd)-1] == '\n')
|
||||
passwd[strlen(passwd)-1] = '\0';
|
||||
if (passwd[strlen(passwd) - 1] == '\n')
|
||||
passwd[strlen(passwd) - 1] = '\0';
|
||||
|
||||
return passwd;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -25,18 +24,18 @@
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/folder.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_chdir(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_chdir(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
mffolder *folder_new;
|
||||
const char *folder_curr;
|
||||
const char *folder_parent;
|
||||
const char *folderkey;
|
||||
int retval;
|
||||
mffolder *folder_new;
|
||||
const char *folder_curr;
|
||||
const char *folder_parent;
|
||||
const char *folderkey;
|
||||
int retval;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -44,67 +43,60 @@ mfshell_cmd_chdir(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
folderkey = argv[1];
|
||||
if(folderkey == NULL) return -1;
|
||||
if (folderkey == NULL)
|
||||
return -1;
|
||||
|
||||
// change to root
|
||||
if(strcmp(folderkey,"/") == 0) folderkey = "myfiles";
|
||||
if (strcmp(folderkey, "/") == 0)
|
||||
folderkey = "myfiles";
|
||||
|
||||
// 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
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
if(folder_curr == NULL) return 0;
|
||||
if(strcmp(folder_curr,"myfiles") == 0) return 0;
|
||||
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;
|
||||
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)
|
||||
{
|
||||
if (strlen(folderkey) != 13) {
|
||||
// as a folder moniker, "myfiles" is an exception
|
||||
if(strcmp(folderkey,"myfiles") != 0) return -1;
|
||||
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");
|
||||
if (strcmp(folderkey, "myfiles") == 0) {
|
||||
folder_set_key(folder_new, "myfiles");
|
||||
retval = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
retval = mfconn_api_folder_get_info(mfshell->conn,
|
||||
folder_new,(char*)folderkey);
|
||||
folder_new, (char *)folderkey);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
}
|
||||
|
||||
if(retval == 0)
|
||||
{
|
||||
if(mfshell->folder_curr != NULL)
|
||||
{
|
||||
if (retval == 0) {
|
||||
if (mfshell->folder_curr != NULL) {
|
||||
folder_free(mfshell->folder_curr);
|
||||
mfshell->folder_curr = NULL;
|
||||
}
|
||||
|
||||
mfshell->folder_curr = folder_new;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
folder_free(folder_new);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_debug(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_debug(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
if (argc != 1) {
|
||||
@@ -35,35 +33,21 @@ mfshell_cmd_debug(mfshell *mfshell, int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"server:",
|
||||
mfshell->server);
|
||||
printf(" %-15.15s %s\n\r", "server:", mfshell->server);
|
||||
|
||||
const char *session_token = mfconn_get_session_token(mfshell->conn);
|
||||
const char *secret_time = mfconn_get_secret_time(mfshell->conn);
|
||||
uint32_t secret_key = mfconn_get_secret_key(mfshell->conn);
|
||||
if(session_token != NULL && secret_time != NULL)
|
||||
{
|
||||
printf(" %-15.15s %"PRIu32"\n\r",
|
||||
"secret key:",
|
||||
secret_key);
|
||||
const char *session_token = mfconn_get_session_token(mfshell->conn);
|
||||
const char *secret_time = mfconn_get_secret_time(mfshell->conn);
|
||||
uint32_t secret_key = mfconn_get_secret_key(mfshell->conn);
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"secret time:",
|
||||
secret_time);
|
||||
if (session_token != NULL && secret_time != NULL) {
|
||||
printf(" %-15.15s %" PRIu32 "\n\r", "secret key:", secret_key);
|
||||
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"status:",
|
||||
"Authenticated");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" %-15.15s %s\n\r",
|
||||
"status:",
|
||||
"Not authenticated");
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -25,19 +24,19 @@
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/file.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_file(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_file(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
mffile *file;
|
||||
int len;
|
||||
int retval;
|
||||
const char *quickkey;
|
||||
const char *name;
|
||||
const char *hash;
|
||||
mffile *file;
|
||||
int len;
|
||||
int retval;
|
||||
const char *quickkey;
|
||||
const char *name;
|
||||
const char *hash;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -45,15 +44,17 @@ mfshell_cmd_file(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
quickkey = argv[1];
|
||||
if(quickkey == NULL) return -1;
|
||||
if (quickkey == NULL)
|
||||
return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
if (len != 11 && len != 15)
|
||||
return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
retval = mfconn_api_file_get_info(mfshell->conn,file,(char*)quickkey);
|
||||
retval = mfconn_api_file_get_info(mfshell->conn, file, (char *)quickkey);
|
||||
if (retval != 0) {
|
||||
fprintf(stderr, "api call unsuccessful\n");
|
||||
}
|
||||
@@ -63,20 +64,16 @@ mfshell_cmd_file(mfshell *mfshell, int argc, char **argv)
|
||||
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 (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 (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);
|
||||
if (hash != NULL && hash[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r", "hash:", hash);
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -28,18 +27,18 @@
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/file.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_get(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_get(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
mffile *file;
|
||||
int len;
|
||||
int retval;
|
||||
ssize_t bytes_read;
|
||||
const char *quickkey;
|
||||
mffile *file;
|
||||
int len;
|
||||
int retval;
|
||||
ssize_t bytes_read;
|
||||
const char *quickkey;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -47,45 +46,42 @@ mfshell_cmd_get(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
quickkey = argv[1];
|
||||
if(quickkey == NULL) return -1;
|
||||
if (quickkey == NULL)
|
||||
return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
if (len != 11 && len != 15)
|
||||
return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
// get file name
|
||||
retval = mfconn_api_file_get_info(mfshell->conn,file,(char*)quickkey);
|
||||
retval = mfconn_api_file_get_info(mfshell->conn, file, (char *)quickkey);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
|
||||
if(retval == -1)
|
||||
{
|
||||
if (retval == -1) {
|
||||
file_free(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// request a direct download (streaming) link
|
||||
retval = mfconn_api_file_get_links(mfshell->conn,file,(char*)quickkey);
|
||||
retval = mfconn_api_file_get_links(mfshell->conn, file, (char *)quickkey);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
|
||||
if(retval == -1)
|
||||
{
|
||||
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);
|
||||
if (mfshell->local_working_dir == NULL) {
|
||||
mfshell->local_working_dir = (char *)calloc(PATH_MAX + 1, sizeof(char));
|
||||
getcwd(mfshell->local_working_dir, PATH_MAX);
|
||||
}
|
||||
|
||||
bytes_read = file_download_direct(file, mfshell->local_working_dir);
|
||||
|
||||
if(bytes_read != -1)
|
||||
printf("\r Downloaded %zd bytes OK!\n\r",bytes_read);
|
||||
if (bytes_read != -1)
|
||||
printf("\r Downloaded %zd bytes OK!\n\r", bytes_read);
|
||||
else
|
||||
printf("\r\n Download FAILED!\n\r");
|
||||
|
||||
@@ -93,4 +89,3 @@ mfshell_cmd_get(mfshell *mfshell, int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,33 +17,29 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_help(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_help(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
unsigned int column1_width = 0;
|
||||
unsigned int column2_width = 0;
|
||||
mfcmd *curr_cmd;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf(
|
||||
" arguments:\n\r"
|
||||
" <optional>\n\r"
|
||||
" [required]\n\r");
|
||||
printf(" arguments:\n\r"
|
||||
" <optional>\n\r" " [required]\n\r");
|
||||
|
||||
printf("\n\r");
|
||||
|
||||
unsigned int column1_width = 0;
|
||||
unsigned int column2_width = 0;
|
||||
|
||||
mfcmd* 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);
|
||||
@@ -52,10 +48,9 @@ mfshell_cmd_help(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
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);
|
||||
printf("%*s %*s %s\n", column1_width, curr_cmd->name,
|
||||
column2_width, curr_cmd->argstring, curr_cmd->help);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -25,16 +24,14 @@
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
static char*
|
||||
_get_host_from_user(void);
|
||||
static char *_get_host_from_user(void);
|
||||
|
||||
int
|
||||
mfshell_cmd_host(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_host(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
char *alt_host = NULL;
|
||||
char *host;
|
||||
char *alt_host = NULL;
|
||||
char *host;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
@@ -49,17 +46,15 @@ mfshell_cmd_host(mfshell *mfshell, int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(mfshell->server != NULL)
|
||||
{
|
||||
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);
|
||||
if (strcmp(mfshell->server, host) == 0) {
|
||||
if (alt_host != NULL)
|
||||
free(alt_host);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(mfshell->server != NULL)
|
||||
{
|
||||
if (mfshell->server != NULL) {
|
||||
free(mfshell->server);
|
||||
mfshell->server = NULL;
|
||||
}
|
||||
@@ -69,27 +64,26 @@ mfshell_cmd_host(mfshell *mfshell, int argc, char **argv)
|
||||
|
||||
mfconn_destroy(mfshell->conn);
|
||||
|
||||
if(alt_host != NULL) free(alt_host);
|
||||
if (alt_host != NULL)
|
||||
free(alt_host);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char*
|
||||
_get_host_from_user(void)
|
||||
char *_get_host_from_user(void)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *host = NULL;
|
||||
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';
|
||||
getline(&host, &len, stdin);
|
||||
if (host[strlen(host) - 1] == '\n')
|
||||
host[strlen(host) - 1] = '\0';
|
||||
|
||||
if(host == NULL)
|
||||
if (host == NULL)
|
||||
return strdup("www.mediafire.com");
|
||||
|
||||
if(strlen(host) < 2)
|
||||
{
|
||||
if (strlen(host) < 2) {
|
||||
free(host);
|
||||
return strdup("www.mediafire.com");
|
||||
}
|
||||
|
||||
@@ -17,22 +17,21 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_lcd(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
int retval;
|
||||
const char *dir;
|
||||
int retval;
|
||||
const char *dir;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -40,15 +39,15 @@ mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
dir = argv[1];
|
||||
if(dir == NULL) return -1;
|
||||
if (dir == NULL)
|
||||
return -1;
|
||||
|
||||
if(strlen(dir) < 1) return -1;
|
||||
if (strlen(dir) < 1)
|
||||
return -1;
|
||||
|
||||
retval = chdir(dir);
|
||||
if(retval == 0)
|
||||
{
|
||||
if(mfshell->local_working_dir != NULL)
|
||||
{
|
||||
if (retval == 0) {
|
||||
if (mfshell->local_working_dir != NULL) {
|
||||
free(mfshell->local_working_dir);
|
||||
mfshell->local_working_dir = NULL;
|
||||
}
|
||||
@@ -58,4 +57,3 @@ mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv)
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -25,20 +24,20 @@
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/file.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_links(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_links(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
mffile *file;
|
||||
int len;
|
||||
int retval;
|
||||
const char *quickkey;
|
||||
const char *share_link;
|
||||
const char *direct_link;
|
||||
const char *onetime_link;
|
||||
mffile *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 (mfshell == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -46,15 +45,17 @@ mfshell_cmd_links(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
quickkey = argv[1];
|
||||
if(quickkey == NULL) return -1;
|
||||
if (quickkey == NULL)
|
||||
return -1;
|
||||
|
||||
len = strlen(quickkey);
|
||||
|
||||
if(len != 11 && len != 15) return -1;
|
||||
if (len != 11 && len != 15)
|
||||
return -1;
|
||||
|
||||
file = file_alloc();
|
||||
|
||||
retval = mfconn_api_file_get_links(mfshell->conn,file,(char*)quickkey);
|
||||
retval = mfconn_api_file_get_links(mfshell->conn, file, (char *)quickkey);
|
||||
if (retval != 0) {
|
||||
fprintf(stderr, "api call unsuccessful\n");
|
||||
}
|
||||
@@ -64,20 +65,16 @@ mfshell_cmd_links(mfshell *mfshell, int argc, char **argv)
|
||||
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 (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 (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);
|
||||
if (onetime_link != NULL && onetime_link[0] != '\0')
|
||||
printf(" %-15.15s %s\n\r", "1-time url:", onetime_link);
|
||||
|
||||
file_free(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,23 +17,22 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../mfapi/apicalls.h"
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/folder.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_list(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_list(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -43,22 +42,22 @@ mfshell_cmd_list(mfshell *mfshell, int argc, char **argv)
|
||||
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");
|
||||
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");
|
||||
if (folder_curr[0] == '\0')
|
||||
folder_set_key(mfshell->folder_curr, "myfiles");
|
||||
|
||||
// first folders
|
||||
retval = mfconn_api_folder_get_content(mfshell->conn, 0, mfshell->folder_curr);
|
||||
retval =
|
||||
mfconn_api_folder_get_content(mfshell->conn, 0, mfshell->folder_curr);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
|
||||
// then files
|
||||
retval = mfconn_api_folder_get_content(mfshell->conn, 1, mfshell->folder_curr);
|
||||
retval =
|
||||
mfconn_api_folder_get_content(mfshell->conn, 1, mfshell->folder_curr);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,34 +17,31 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../mfshell.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_lpwd(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_lpwd(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
if(mfshell == NULL) return -1;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,23 +17,22 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../mfapi/apicalls.h"
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/folder.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_mkdir(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_mkdir(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
const char *name;
|
||||
int retval;
|
||||
const char *folder_curr;
|
||||
const char *name;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -41,24 +40,25 @@ mfshell_cmd_mkdir(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
name = argv[1];
|
||||
if (name == NULL) return -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");
|
||||
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");
|
||||
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->conn,(char*)folder_curr,(char*)name);
|
||||
retval =
|
||||
mfconn_api_folder_create(mfshell->conn, (char *)folder_curr,
|
||||
(char *)name);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,24 +17,24 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../../utils/strings.h"
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/folder.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_pwd(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_pwd(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
const char *folder_name;
|
||||
char *folder_name_tmp = NULL;
|
||||
const char *folder_name;
|
||||
char *folder_name_tmp = NULL;
|
||||
|
||||
if(mfshell == NULL) return -1;
|
||||
if(mfshell->folder_curr == NULL) return -1;
|
||||
if (mfshell == NULL)
|
||||
return -1;
|
||||
if (mfshell->folder_curr == NULL)
|
||||
return -1;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -42,16 +42,15 @@ mfshell_cmd_pwd(mfshell *mfshell, int argc, char **argv)
|
||||
}
|
||||
|
||||
folder_name = folder_get_name(mfshell->folder_curr);
|
||||
if(folder_name[0] == '\0') return -1;
|
||||
if (folder_name[0] == '\0')
|
||||
return -1;
|
||||
|
||||
folder_name_tmp = strdup_printf("< %s >",folder_name);
|
||||
folder_name_tmp = strdup_printf("< %s >", folder_name);
|
||||
|
||||
printf("%-15.13s %-50.50s\n\r",
|
||||
folder_get_key(mfshell->folder_curr),
|
||||
folder_name_tmp);
|
||||
folder_get_key(mfshell->folder_curr), folder_name_tmp);
|
||||
|
||||
free(folder_name_tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,19 +17,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../mfapi/apicalls.h"
|
||||
#include "../mfshell.h"
|
||||
#include "../../mfapi/mfconn.h"
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
#include "../commands.h" // IWYU pragma: keep
|
||||
|
||||
int
|
||||
mfshell_cmd_whoami(mfshell *mfshell, int argc, char **argv)
|
||||
int mfshell_cmd_whoami(mfshell * mfshell, int argc, char **argv)
|
||||
{
|
||||
(void)argv;
|
||||
int retval;
|
||||
int retval;
|
||||
|
||||
if (argc != 1) {
|
||||
fprintf(stderr, "Invalid number of arguments\n");
|
||||
@@ -41,5 +39,3 @@ mfshell_cmd_whoami(mfshell *mfshell, int argc, char **argv)
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
110
mfshell/main.c
110
mfshell/main.c
@@ -27,11 +27,9 @@
|
||||
|
||||
#include "mfshell.h"
|
||||
|
||||
static void
|
||||
mfshell_run(mfshell *mfshell);
|
||||
static void mfshell_run(mfshell * mfshell);
|
||||
|
||||
static void
|
||||
mfshell_parse_commands(mfshell *mfshell, char *command);
|
||||
static void mfshell_parse_commands(mfshell * mfshell, char *command);
|
||||
|
||||
void print_help(char *cmd)
|
||||
{
|
||||
@@ -46,33 +44,36 @@ void print_help(char *cmd)
|
||||
fprintf(stderr, " -p, --password=<PASS> Login password\n");
|
||||
fprintf(stderr, " -s, --server=<SERVER> Login server\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "Username and password are optional. If not given, they\n"
|
||||
"have to be entered via standard input.\n");
|
||||
fprintf(stderr,
|
||||
"Username and password are optional. If not given, they\n"
|
||||
"have to be entered via standard input.\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "You should not pass your password as a commandline\n"
|
||||
"argument as other users with access to the list of\n"
|
||||
"running processes will then be able to see it.\n");
|
||||
"argument as other users with access to the list of\n"
|
||||
"running processes will then be able to see it.\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "Use the \"help\" command to print a list of available\n"
|
||||
"commands in the interactive environment:\n");
|
||||
fprintf(stderr,
|
||||
"Use the \"help\" command to print a list of available\n"
|
||||
"commands in the interactive environment:\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, " %s -c help\n", cmd);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void parse_argv(int argc, char **argv, char **username,
|
||||
char **password, char **server, char **command)
|
||||
void
|
||||
parse_argv(int argc, char **argv, char **username,
|
||||
char **password, char **server, char **command)
|
||||
{
|
||||
static struct option long_options[] = {
|
||||
{"command", required_argument, 0, 'c'},
|
||||
{"command", required_argument, 0, 'c'},
|
||||
{"username", required_argument, 0, 'u'},
|
||||
{"password", required_argument, 0, 'p'},
|
||||
{"server", required_argument, 0, 's'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'v'}
|
||||
{"server", required_argument, 0, 's'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'v'}
|
||||
};
|
||||
int c;
|
||||
|
||||
int c;
|
||||
for (;;) {
|
||||
c = getopt_long(argc, argv, "c:u:p:s:hv", long_options, NULL);
|
||||
if (c == -1)
|
||||
@@ -116,20 +117,21 @@ void parse_argv(int argc, char **argv, char **username,
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
mfshell *mfshell;
|
||||
char *server = "www.mediafire.com";
|
||||
char *username = NULL;
|
||||
char *password = NULL;
|
||||
char *command = NULL;
|
||||
mfshell *mfshell;
|
||||
char *server = "www.mediafire.com";
|
||||
char *username = NULL;
|
||||
char *password = NULL;
|
||||
char *command = NULL;
|
||||
|
||||
SSL_library_init();
|
||||
|
||||
parse_argv(argc, argv, &username, &password, &server, &command);
|
||||
|
||||
mfshell = mfshell_create(35860,
|
||||
"2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg",server);
|
||||
"2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg",
|
||||
server);
|
||||
|
||||
if (command == NULL) {
|
||||
// begin shell mode
|
||||
@@ -142,23 +144,33 @@ int main(int argc,char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
mfshell_parse_commands(mfshell *mfshell, char *command)
|
||||
static void mfshell_parse_commands(mfshell * mfshell, char *command)
|
||||
{
|
||||
char *next;
|
||||
int ret;
|
||||
wordexp_t p;
|
||||
char *next;
|
||||
int ret;
|
||||
wordexp_t p;
|
||||
|
||||
// FIXME: don't split by semicolon but by unescaped/unquoted semicolon
|
||||
while ((next = strsep(&command, ";")) != NULL) {
|
||||
// FIXME: handle non-zero return value of wordexp
|
||||
ret = wordexp(next, &p, WRDE_SHOWERR | WRDE_UNDEF);
|
||||
if (ret != 0) {
|
||||
switch (ret) {
|
||||
case WRDE_BADCHAR: fprintf(stderr, "wordexp: WRDE_BADCHAR\n"); break;
|
||||
case WRDE_BADVAL: fprintf(stderr, "wordexp: WRDE_BADVAL\n"); break;
|
||||
case WRDE_CMDSUB: fprintf(stderr, "wordexp: WRDE_CMDSUB\n"); break;
|
||||
case WRDE_NOSPACE: fprintf(stderr, "wordexp: WRDE_NOSPACE\n"); break;
|
||||
case WRDE_SYNTAX: fprintf(stderr, "wordexp: WRDE_SYNTAX\n"); break;
|
||||
case WRDE_BADCHAR:
|
||||
fprintf(stderr, "wordexp: WRDE_BADCHAR\n");
|
||||
break;
|
||||
case WRDE_BADVAL:
|
||||
fprintf(stderr, "wordexp: WRDE_BADVAL\n");
|
||||
break;
|
||||
case WRDE_CMDSUB:
|
||||
fprintf(stderr, "wordexp: WRDE_CMDSUB\n");
|
||||
break;
|
||||
case WRDE_NOSPACE:
|
||||
fprintf(stderr, "wordexp: WRDE_NOSPACE\n");
|
||||
break;
|
||||
case WRDE_SYNTAX:
|
||||
fprintf(stderr, "wordexp: WRDE_SYNTAX\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p.we_wordc < 1) {
|
||||
@@ -170,45 +182,41 @@ mfshell_parse_commands(mfshell *mfshell, char *command)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mfshell_run(mfshell *mfshell)
|
||||
static void mfshell_run(mfshell * mfshell)
|
||||
{
|
||||
char *cmd = NULL;
|
||||
size_t len;
|
||||
int abort = 0;
|
||||
int retval;
|
||||
char *cmd = NULL;
|
||||
size_t len;
|
||||
int abort = 0;
|
||||
int retval;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
printf("\n\rmfshell > ");
|
||||
|
||||
retval = getline(&cmd,&len,stdin);
|
||||
retval = getline(&cmd, &len, stdin);
|
||||
if (retval == -1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (cmd[strlen(cmd)-1] == '\n')
|
||||
cmd[strlen(cmd)-1] = '\0';
|
||||
if (cmd[strlen(cmd) - 1] == '\n')
|
||||
cmd[strlen(cmd) - 1] = '\0';
|
||||
|
||||
printf("\n\r");
|
||||
|
||||
if(strcmp(cmd,"exit") == 0)
|
||||
{
|
||||
if (strcmp(cmd, "exit") == 0) {
|
||||
abort = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strcmp(cmd,"quit") == 0)
|
||||
{
|
||||
if (strcmp(cmd, "quit") == 0) {
|
||||
abort = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
retval = mfshell_exec_shell_command(mfshell,cmd);
|
||||
retval = mfshell_exec_shell_command(mfshell, cmd);
|
||||
free(cmd);
|
||||
cmd = NULL;
|
||||
}
|
||||
while(abort == 0);
|
||||
while (abort == 0);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -27,46 +26,49 @@
|
||||
#include "mfshell.h"
|
||||
#include "../mfapi/folder.h"
|
||||
|
||||
struct mfcmd commands[] = {
|
||||
{"help", "", "show this help", mfshell_cmd_help},
|
||||
{"debug", "", "show debug information", mfshell_cmd_debug},
|
||||
{"host", "<server>", "change target server", mfshell_cmd_host},
|
||||
{"auth", "<user <pass>>", "authenticate with active server",
|
||||
mfshell_cmd_auth},
|
||||
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
||||
{"ls", "", "show contents of active folder",
|
||||
mfshell_cmd_list},
|
||||
{"cd", "[folderkey]", "change active folder", mfshell_cmd_chdir},
|
||||
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
||||
{"lpwd", "", "show the local working directory",
|
||||
mfshell_cmd_lpwd},
|
||||
{"lcd", "[dir]", "change the local working directory",
|
||||
mfshell_cmd_lcd},
|
||||
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
||||
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
||||
{"links", "[quickkey]", "show access urls for the file",
|
||||
mfshell_cmd_links},
|
||||
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
struct mfcmd commands[] = {
|
||||
{"help", "", "show this help", mfshell_cmd_help},
|
||||
{"debug", "", "show debug information", mfshell_cmd_debug},
|
||||
{"host", "<server>", "change target server", mfshell_cmd_host},
|
||||
{"auth", "<user <pass>>", "authenticate with active server",
|
||||
mfshell_cmd_auth},
|
||||
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
||||
{"ls", "", "show contents of active folder",
|
||||
mfshell_cmd_list},
|
||||
{"cd", "[folderkey]", "change active folder", mfshell_cmd_chdir},
|
||||
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
||||
{"lpwd", "", "show the local working directory",
|
||||
mfshell_cmd_lpwd},
|
||||
{"lcd", "[dir]", "change the local working directory",
|
||||
mfshell_cmd_lcd},
|
||||
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
||||
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
||||
{"links", "[quickkey]", "show access urls for the file",
|
||||
mfshell_cmd_links},
|
||||
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
mfshell*
|
||||
mfshell_create(int app_id,char *app_key,char *server)
|
||||
mfshell *mfshell_create(int app_id, char *app_key, char *server)
|
||||
{
|
||||
mfshell *shell;
|
||||
mfshell *shell;
|
||||
|
||||
if(app_id <= 0) return NULL;
|
||||
if(app_key == NULL) return NULL;
|
||||
if(server == NULL) return NULL;
|
||||
if (app_id <= 0)
|
||||
return NULL;
|
||||
if (app_key == NULL)
|
||||
return NULL;
|
||||
if (server == NULL)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
check to see if the server contains a forward-slash. if so,
|
||||
the caller did not understand the API and passed in the wrong
|
||||
type of server resource.
|
||||
*/
|
||||
if(strchr(server,'/') != NULL) return NULL;
|
||||
check to see if the server contains a forward-slash. if so,
|
||||
the caller did not understand the API and passed in the wrong
|
||||
type of server resource.
|
||||
*/
|
||||
if (strchr(server, '/') != NULL)
|
||||
return NULL;
|
||||
|
||||
shell = (mfshell*)calloc(1,sizeof(mfshell));
|
||||
shell = (mfshell *) calloc(1, sizeof(mfshell));
|
||||
|
||||
shell->app_id = app_id;
|
||||
shell->app_key = strdup(app_key);
|
||||
@@ -74,7 +76,7 @@ mfshell_create(int app_id,char *app_key,char *server)
|
||||
|
||||
// object to track folder location
|
||||
shell->folder_curr = folder_alloc();
|
||||
folder_set_key(shell->folder_curr,"myfiles");
|
||||
folder_set_key(shell->folder_curr, "myfiles");
|
||||
|
||||
// shell commands
|
||||
shell->commands = commands;
|
||||
@@ -82,10 +84,10 @@ mfshell_create(int app_id,char *app_key,char *server)
|
||||
return shell;
|
||||
}
|
||||
|
||||
int
|
||||
mfshell_exec(mfshell *shell, int argc, char **argv)
|
||||
int mfshell_exec(mfshell * shell, int argc, char **argv)
|
||||
{
|
||||
mfcmd* curr_cmd;
|
||||
mfcmd *curr_cmd;
|
||||
|
||||
for (curr_cmd = shell->commands; curr_cmd->name != NULL; curr_cmd++) {
|
||||
if (strcmp(argv[0], curr_cmd->name) == 0) {
|
||||
return curr_cmd->handler(shell, argc, argv);
|
||||
@@ -94,24 +96,35 @@ mfshell_exec(mfshell *shell, int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
mfshell_exec_shell_command(mfshell *shell,char *command)
|
||||
int mfshell_exec_shell_command(mfshell * shell, char *command)
|
||||
{
|
||||
wordexp_t p;
|
||||
int retval;
|
||||
|
||||
if(shell == NULL) return -1;
|
||||
if(command == NULL) return -1;
|
||||
if (shell == NULL)
|
||||
return -1;
|
||||
if (command == NULL)
|
||||
return -1;
|
||||
|
||||
// FIXME: handle non-zero return value of wordexp
|
||||
retval = wordexp(command, &p, WRDE_SHOWERR | WRDE_UNDEF);
|
||||
if (retval != 0) {
|
||||
switch (retval) {
|
||||
case WRDE_BADCHAR: fprintf(stderr, "wordexp: WRDE_BADCHAR\n"); break;
|
||||
case WRDE_BADVAL: fprintf(stderr, "wordexp: WRDE_BADVAL\n"); break;
|
||||
case WRDE_CMDSUB: fprintf(stderr, "wordexp: WRDE_CMDSUB\n"); break;
|
||||
case WRDE_NOSPACE: fprintf(stderr, "wordexp: WRDE_NOSPACE\n"); break;
|
||||
case WRDE_SYNTAX: fprintf(stderr, "wordexp: WRDE_SYNTAX\n"); break;
|
||||
case WRDE_BADCHAR:
|
||||
fprintf(stderr, "wordexp: WRDE_BADCHAR\n");
|
||||
break;
|
||||
case WRDE_BADVAL:
|
||||
fprintf(stderr, "wordexp: WRDE_BADVAL\n");
|
||||
break;
|
||||
case WRDE_CMDSUB:
|
||||
fprintf(stderr, "wordexp: WRDE_CMDSUB\n");
|
||||
break;
|
||||
case WRDE_NOSPACE:
|
||||
fprintf(stderr, "wordexp: WRDE_NOSPACE\n");
|
||||
break;
|
||||
case WRDE_SYNTAX:
|
||||
fprintf(stderr, "wordexp: WRDE_SYNTAX\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,4 +141,3 @@ mfshell_exec_shell_command(mfshell *shell,char *command)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _MFSHELL_H_
|
||||
#define _MFSHELL_H_
|
||||
|
||||
@@ -27,42 +26,39 @@
|
||||
struct mfcmd;
|
||||
struct mfshell;
|
||||
|
||||
typedef struct mfcmd mfcmd;
|
||||
typedef struct mfshell mfshell;
|
||||
typedef struct mfcmd mfcmd;
|
||||
typedef struct mfshell mfshell;
|
||||
|
||||
struct mfcmd
|
||||
{
|
||||
char *name;
|
||||
char *argstring;
|
||||
char *help;
|
||||
int (*handler) (mfshell *mfshell, int argc, char **argv);
|
||||
struct mfcmd {
|
||||
char *name;
|
||||
char *argstring;
|
||||
char *help;
|
||||
int (*handler) (mfshell * mfshell, int argc, char **argv);
|
||||
};
|
||||
|
||||
struct mfshell
|
||||
{
|
||||
int app_id;
|
||||
char *app_key;
|
||||
char *server;
|
||||
struct mfshell {
|
||||
int app_id;
|
||||
char *app_key;
|
||||
char *server;
|
||||
|
||||
/* REST API tracking */
|
||||
mffolder *folder_curr;
|
||||
mffolder *folder_curr;
|
||||
|
||||
/* Local tracking */
|
||||
char *local_working_dir;
|
||||
char *local_working_dir;
|
||||
|
||||
/* shell commands */
|
||||
mfcmd *commands;
|
||||
mfcmd *commands;
|
||||
|
||||
mfconn *conn;
|
||||
mfconn *conn;
|
||||
};
|
||||
|
||||
mfshell* mfshell_create(int app_id,char *app_key,char *server);
|
||||
mfshell *mfshell_create(int app_id, char *app_key, char *server);
|
||||
|
||||
int mfshell_authenticate_user(mfshell *mfshell);
|
||||
int mfshell_authenticate_user(mfshell * mfshell);
|
||||
|
||||
int mfshell_exec(mfshell *mfshell, int argc, char **argv);
|
||||
int mfshell_exec(mfshell * mfshell, int argc, char **argv);
|
||||
|
||||
int mfshell_exec_shell_command(mfshell *mfshell,char *command);
|
||||
int mfshell_exec_shell_command(mfshell * mfshell, char *command);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user