fuse: add more options and establish connection on startup

This commit is contained in:
josch
2014-09-23 20:53:29 +02:00
parent 6e546fa3f3
commit 00ff91c15a
2 changed files with 61 additions and 20 deletions

View File

@@ -20,7 +20,7 @@ enable_testing()
add_executable(mediafire-fuse fuse/main.c) add_executable(mediafire-fuse fuse/main.c)
set_target_properties(mediafire-fuse PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror -D_FILE_OFFSET_BITS=64") set_target_properties(mediafire-fuse PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror -D_FILE_OFFSET_BITS=64")
target_link_libraries(mediafire-fuse curl ssl fuse) target_link_libraries(mediafire-fuse curl ssl fuse jansson mfapi mfutils)
add_test(iwyu ${CMAKE_SOURCE_DIR}/tests/iwyu.py ${CMAKE_BINARY_DIR}) add_test(iwyu ${CMAKE_SOURCE_DIR}/tests/iwyu.py ${CMAKE_BINARY_DIR})
add_test(indent ${CMAKE_SOURCE_DIR}/tests/indent.sh ${CMAKE_SOURCE_DIR}) add_test(indent ${CMAKE_SOURCE_DIR}/tests/indent.sh ${CMAKE_SOURCE_DIR})

View File

@@ -16,20 +16,19 @@
* *
*/ */
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <openssl/ssl.h>
#define FUSE_USE_VERSION 30 #define FUSE_USE_VERSION 30
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fuse/fuse.h>
#include <fuse/fuse_opt.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../mfapi/mfconn.h"
enum enum
{ {
@@ -37,12 +36,17 @@ enum
KEY_VERSION, KEY_VERSION,
}; };
mfconn *conn;
struct mediafirefs_user_options { struct mediafirefs_user_options {
char *username; char *username;
char *password; char *password;
char *configfile; char *configfile;
char *server;
int app_id;
char *api_key;
} mediafirefs_user_options = { } mediafirefs_user_options = {
NULL, NULL, NULL NULL, NULL, NULL, NULL, -1, NULL
}; };
static struct fuse_opt mediafirefs_opts[] = { static struct fuse_opt mediafirefs_opts[] = {
@@ -51,11 +55,16 @@ static struct fuse_opt mediafirefs_opts[] = {
FUSE_OPT_KEY("-V", KEY_VERSION), FUSE_OPT_KEY("-V", KEY_VERSION),
FUSE_OPT_KEY("--version", KEY_VERSION), FUSE_OPT_KEY("--version", KEY_VERSION),
{"-c %s", offsetof(struct mediafirefs_user_options, configfile), 0}, {"-c %s", offsetof(struct mediafirefs_user_options, configfile), 0},
{"--configfile=%s", offsetof(struct mediafirefs_user_options, configfile), 0}, {"--config=%s", offsetof(struct mediafirefs_user_options, configfile), 0},
{"-u %s", offsetof(struct mediafirefs_user_options, username), 0}, {"-u %s", offsetof(struct mediafirefs_user_options, username), 0},
{"--username %s", offsetof(struct mediafirefs_user_options, username), 0}, {"--username %s", offsetof(struct mediafirefs_user_options, username), 0},
{"-p %s", offsetof(struct mediafirefs_user_options, password), 0}, {"-p %s", offsetof(struct mediafirefs_user_options, password), 0},
{"--password %s", offsetof(struct mediafirefs_user_options, password), 0}, {"--password %s", offsetof(struct mediafirefs_user_options, password), 0},
{"--server %s", offsetof(struct mediafirefs_user_options, server), 0},
{"-i %d", offsetof(struct mediafirefs_user_options, app_id), 0},
{"--app-id %d", offsetof(struct mediafirefs_user_options, app_id), 0},
{"-k %s", offsetof(struct mediafirefs_user_options, api_key), 0},
{"--api-key %s", offsetof(struct mediafirefs_user_options, api_key), 0},
FUSE_OPT_END FUSE_OPT_END
}; };
@@ -69,9 +78,15 @@ static void usage(const char *progname)
" -V, --version show version information\n" " -V, --version show version information\n"
"\n" "\n"
"MediaFire FS options:\n" "MediaFire FS options:\n"
" -o user=str username\n" " -o, --username str username\n"
" -o password=str password\n" " -p, --password str password\n"
" -c config=str configuration file\n" " -c, --config file configuration file\n"
" --server domain server domain\n"
" -i, --app-id id App ID\n"
" -k, --api-key key API Key\n"
"\n"
"Notice that long options are separated from their arguments by\n"
"a space and not an equal sign.\n"
"\n", progname); "\n", progname);
} }
@@ -160,5 +175,31 @@ main(int argc, char *argv[])
{ {
exit(1); exit(1);
} }
if (mediafirefs_user_options.app_id == -1) {
mediafirefs_user_options.app_id = 42709;
}
if (mediafirefs_user_options.server == NULL) {
mediafirefs_user_options.server = "www.mediafire.com";
}
if (mediafirefs_user_options.username == NULL ||
mediafirefs_user_options.password == NULL) {
fprintf(stderr, "You must specify username and pasword\n");
exit(1);
}
conn = mfconn_create(mediafirefs_user_options.server,
mediafirefs_user_options.username,
mediafirefs_user_options.password,
mediafirefs_user_options.app_id,
mediafirefs_user_options.api_key);
if (conn == NULL) {
fprintf(stderr, "Cannot establish connection\n");
exit(1);
}
return fuse_main(args.argc, args.argv, &mediafirefs_oper, NULL); return fuse_main(args.argc, args.argv, &mediafirefs_oper, NULL);
} }