mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
fix indent test and indentation
This commit is contained in:
55
fuse/main.c
55
fuse/main.c
@@ -30,24 +30,22 @@
|
||||
|
||||
#include "../mfapi/mfconn.h"
|
||||
|
||||
enum
|
||||
{
|
||||
enum {
|
||||
KEY_HELP,
|
||||
KEY_VERSION,
|
||||
};
|
||||
|
||||
mfconn *conn;
|
||||
mfconn *conn;
|
||||
|
||||
struct mediafirefs_user_options {
|
||||
char *username;
|
||||
char *password;
|
||||
char *configfile;
|
||||
char *server;
|
||||
int app_id;
|
||||
char *api_key;
|
||||
char *username;
|
||||
char *password;
|
||||
char *configfile;
|
||||
char *server;
|
||||
int app_id;
|
||||
char *api_key;
|
||||
} mediafirefs_user_options = {
|
||||
NULL, NULL, NULL, NULL, -1, NULL
|
||||
};
|
||||
NULL, NULL, NULL, NULL, -1, NULL};
|
||||
|
||||
static struct fuse_opt mediafirefs_opts[] = {
|
||||
FUSE_OPT_KEY("-h", KEY_HELP),
|
||||
@@ -86,8 +84,7 @@ static void usage(const char *progname)
|
||||
" -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);
|
||||
"a space and not an equal sign.\n" "\n", progname);
|
||||
}
|
||||
|
||||
static int mediafirefs_getattr(const char *path, struct stat *stbuf)
|
||||
@@ -105,7 +102,8 @@ static int mediafirefs_getattr(const char *path, struct stat *stbuf)
|
||||
}
|
||||
|
||||
static int mediafirefs_readdir(const char *path, void *buf,
|
||||
fuse_fill_dir_t filldir, off_t offset, struct fuse_file_info *info)
|
||||
fuse_fill_dir_t filldir, off_t offset,
|
||||
struct fuse_file_info *info)
|
||||
{
|
||||
(void)path;
|
||||
(void)offset;
|
||||
@@ -144,19 +142,17 @@ static int
|
||||
mediafirefs_opt_proc(void *data, const char *arg, int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
(void)data; // unused
|
||||
(void)arg; // unused
|
||||
(void)data; // unused
|
||||
(void)arg; // unused
|
||||
|
||||
if(key == KEY_HELP)
|
||||
{
|
||||
if (key == KEY_HELP) {
|
||||
usage(outargs->argv[0]);
|
||||
fuse_opt_add_arg(outargs, "-ho");
|
||||
fuse_main(outargs->argc, outargs->argv, &mediafirefs_oper, NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(key == KEY_VERSION)
|
||||
{
|
||||
if (key == KEY_VERSION) {
|
||||
fuse_opt_add_arg(outargs, "--version");
|
||||
fuse_main(outargs->argc, outargs->argv, &mediafirefs_oper, NULL);
|
||||
exit(0);
|
||||
@@ -165,14 +161,13 @@ mediafirefs_opt_proc(void *data, const char *arg, int key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
|
||||
if(fuse_opt_parse
|
||||
(&args, &mediafirefs_user_options, mediafirefs_opts,
|
||||
mediafirefs_opt_proc) == -1)
|
||||
{
|
||||
|
||||
if (fuse_opt_parse
|
||||
(&args, &mediafirefs_user_options, mediafirefs_opts,
|
||||
mediafirefs_opt_proc) == -1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -191,10 +186,10 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
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);
|
||||
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");
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
#include "../mfconn.h"
|
||||
#include "../apicalls.h" // IWYU pragma: keep
|
||||
|
||||
int mfconn_api_folder_create(mfconn * conn, const char *parent, const char *name)
|
||||
int mfconn_api_folder_create(mfconn * conn, const char *parent,
|
||||
const char *name)
|
||||
{
|
||||
const char *api_call;
|
||||
int retval;
|
||||
|
||||
@@ -52,15 +52,15 @@ mfconn_api_folder_get_content(mfconn * conn, int mode, mffolder * folder_curr)
|
||||
folderkey = folder_get_key(folder_curr);
|
||||
if (folderkey == NULL) {
|
||||
api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php",
|
||||
"?content_type=%s"
|
||||
"&response_format=json",
|
||||
content_type);
|
||||
"?content_type=%s"
|
||||
"&response_format=json",
|
||||
content_type);
|
||||
} else {
|
||||
api_call = mfconn_create_signed_get(conn, 0, "folder/get_content.php",
|
||||
"?folder_key=%s"
|
||||
"&content_type=%s"
|
||||
"&response_format=json",
|
||||
folderkey, content_type);
|
||||
"?folder_key=%s"
|
||||
"&content_type=%s"
|
||||
"&response_format=json",
|
||||
folderkey, content_type);
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE // for strptime
|
||||
#define _XOPEN_SOURCE // for strptime
|
||||
#include <jansson.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -33,7 +33,8 @@
|
||||
static int _decode_folder_get_info(mfhttp * conn, void *data);
|
||||
|
||||
int
|
||||
mfconn_api_folder_get_info(mfconn * conn, mffolder * folder, const char *folderkey)
|
||||
mfconn_api_folder_get_info(mfconn * conn, mffolder * folder,
|
||||
const char *folderkey)
|
||||
{
|
||||
const char *api_call;
|
||||
int retval;
|
||||
@@ -56,8 +57,7 @@ mfconn_api_folder_get_info(mfconn * conn, mffolder * folder, const char *folderk
|
||||
} else {
|
||||
api_call = mfconn_create_signed_get(conn, 0, "folder/get_info.php",
|
||||
"?folder_key=%s"
|
||||
"&response_format=json",
|
||||
folderkey);
|
||||
"&response_format=json", folderkey);
|
||||
}
|
||||
|
||||
http = http_create();
|
||||
|
||||
@@ -42,8 +42,7 @@ mfconn_api_user_get_session_token(mfconn * conn, const char *server,
|
||||
const char *username, const char *password,
|
||||
int app_id, const char *app_key,
|
||||
uint32_t * secret_key,
|
||||
char **secret_time,
|
||||
char **session_token)
|
||||
char **secret_time, char **session_token)
|
||||
{
|
||||
char *login_url;
|
||||
char *post_args;
|
||||
|
||||
@@ -109,8 +109,7 @@ const char *mfconn_create_user_signature(mfconn * conn,
|
||||
return NULL;
|
||||
|
||||
if (app_key == NULL) {
|
||||
signature_raw = strdup_printf("%s%s%d",
|
||||
username, password, app_id);
|
||||
signature_raw = strdup_printf("%s%s%d", username, password, app_id);
|
||||
} else {
|
||||
signature_raw = strdup_printf("%s%s%d%s",
|
||||
username, password, app_id, app_key);
|
||||
@@ -170,8 +169,7 @@ const char *mfconn_create_call_signature(mfconn * conn, const char *url,
|
||||
}
|
||||
|
||||
const char *mfconn_create_signed_get(mfconn * conn, int ssl,
|
||||
const char *api,
|
||||
const char *fmt, ...)
|
||||
const char *api, const char *fmt, ...)
|
||||
{
|
||||
char *api_request = NULL;
|
||||
char *api_args = NULL;
|
||||
|
||||
@@ -35,8 +35,7 @@ void mfconn_destroy(mfconn * conn);
|
||||
ssize_t mfconn_download_direct(mffile * file, const char *local_dir);
|
||||
|
||||
const char *mfconn_create_signed_get(mfconn * conn, int ssl,
|
||||
const char *api, const char *fmt,
|
||||
...);
|
||||
const char *api, const char *fmt, ...);
|
||||
|
||||
const char *mfconn_create_user_signature(mfconn * conn,
|
||||
const char *username,
|
||||
|
||||
@@ -56,7 +56,7 @@ int mfshell_cmd_file(mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
|
||||
int mfshell_cmd_folder(mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
char *const argv[]);
|
||||
|
||||
int mfshell_cmd_links(mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
int mfshell_cmd_folder(mfshell * mfshell, int argc, char *const argv[])
|
||||
{
|
||||
mffolder *folder;
|
||||
mffolder *folder;
|
||||
int retval;
|
||||
const char *folderkey;
|
||||
const char *name;
|
||||
@@ -93,7 +93,7 @@ int mfshell_cmd_folder(mfshell * mfshell, int argc, char *const argv[])
|
||||
printf(" %-15.15s %s\n\r", "parent:", parent);
|
||||
|
||||
if (revision != 0)
|
||||
printf(" %-15.15s %"PRIu32"\n\r", "revision:", revision);
|
||||
printf(" %-15.15s %" PRIu32 "\n\r", "revision:", revision);
|
||||
|
||||
if (epoch != 0) {
|
||||
memset(&tm, 0, sizeof(struct tm));
|
||||
|
||||
@@ -47,8 +47,7 @@ int mfshell_cmd_mkdir(mfshell * mfshell, int argc, char *const argv[])
|
||||
|
||||
folder_curr = folder_get_key(mfshell->folder_curr);
|
||||
|
||||
retval = mfconn_api_folder_create(mfshell->conn, folder_curr,
|
||||
(char *)name);
|
||||
retval = mfconn_api_folder_create(mfshell->conn, folder_curr, (char *)name);
|
||||
mfconn_update_secret_key(mfshell->conn);
|
||||
|
||||
return retval;
|
||||
|
||||
@@ -30,27 +30,25 @@
|
||||
|
||||
void parse_config(struct mfshell_user_options *opts)
|
||||
{
|
||||
FILE *fp;
|
||||
char *homedir;
|
||||
FILE *fp;
|
||||
char *homedir;
|
||||
|
||||
// parse the configuration file
|
||||
// if a value is not set (it is NULL) then it has not been set by the
|
||||
// commandline and should be set by the configuration file
|
||||
|
||||
// try set config file first if set
|
||||
if (opts->config != NULL &&
|
||||
(fp = fopen(opts->config, "r")) != NULL) {
|
||||
if (opts->config != NULL && (fp = fopen(opts->config, "r")) != NULL) {
|
||||
parse_config_file(fp, opts);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
// try "./.mediafire-tools.conf" second
|
||||
if ((fp = fopen("./.mediafire-tools.conf", "r")) != NULL) {
|
||||
parse_config_file(fp, opts);
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
// try "~/.mediafire-tools.conf" third
|
||||
if ((homedir = getenv("HOME")) == NULL) {
|
||||
homedir = getpwuid(getuid())->pw_dir;
|
||||
@@ -63,17 +61,18 @@ void parse_config(struct mfshell_user_options *opts)
|
||||
free(homedir);
|
||||
}
|
||||
|
||||
void parse_config_file(FILE *fp, struct mfshell_user_options *opts)
|
||||
void parse_config_file(FILE * fp, struct mfshell_user_options *opts)
|
||||
{
|
||||
// read the config file line by line and pass each line to wordexp to
|
||||
// retain proper quoting
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
wordexp_t p;
|
||||
int ret, i;
|
||||
int argc;
|
||||
char **argv;
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read;
|
||||
wordexp_t p;
|
||||
int ret,
|
||||
i;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
while ((read = getline(&line, &len, fp)) != -1) {
|
||||
if (line[0] == '#')
|
||||
@@ -108,10 +107,10 @@ void parse_config_file(FILE *fp, struct mfshell_user_options *opts)
|
||||
// parse it
|
||||
argc = p.we_wordc + 1;
|
||||
// allocate one more than argc for trailing NULL
|
||||
argv = (char **)malloc(sizeof(char*)*(argc+1));
|
||||
argv[0] = ""; // dummy program name
|
||||
argv = (char **)malloc(sizeof(char *) * (argc + 1));
|
||||
argv[0] = ""; // dummy program name
|
||||
for (i = 1; i < argc; i++)
|
||||
argv[i] = p.we_wordv[i-1];
|
||||
argv[i] = p.we_wordv[i - 1];
|
||||
argv[argc] = NULL;
|
||||
parse_argv(argc, argv, opts);
|
||||
free(argv);
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
#include "options.h"
|
||||
|
||||
void parse_config(struct mfshell_user_options *opts);
|
||||
void parse_config(struct mfshell_user_options *opts);
|
||||
|
||||
void parse_config_file(FILE *fp, struct mfshell_user_options *opts);
|
||||
void parse_config_file(FILE * fp, struct mfshell_user_options *opts);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,7 @@ int main(int argc, char *const argv[])
|
||||
{
|
||||
mfshell *shell;
|
||||
char *auth_cmd;
|
||||
|
||||
struct mfshell_user_options opts = {
|
||||
.username = NULL,
|
||||
.password = NULL,
|
||||
@@ -53,25 +54,21 @@ int main(int argc, char *const argv[])
|
||||
if (opts.server == NULL) {
|
||||
opts.server = strdup("www.mediafire.com");
|
||||
}
|
||||
|
||||
// if app_id was neither set on the commandline nor in the config, set it
|
||||
// to the default value
|
||||
if (opts.app_id == -1)
|
||||
opts.app_id = 42709;
|
||||
|
||||
shell = mfshell_create(opts.app_id, opts.api_key,
|
||||
opts.server);
|
||||
shell = mfshell_create(opts.app_id, opts.api_key, opts.server);
|
||||
if (shell == NULL) {
|
||||
fprintf(stderr, "cannot create shell\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// if at least username was set, authenticate automatically
|
||||
if (opts.username != NULL) {
|
||||
if (opts.password != NULL) {
|
||||
auth_cmd = strdup_printf("auth %s %s",
|
||||
opts.username,
|
||||
opts.password);
|
||||
opts.username, opts.password);
|
||||
} else {
|
||||
auth_cmd = strdup_printf("auth %s", opts.username);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ struct mfcmd commands[] = {
|
||||
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
|
||||
{"ls", "", "show contents of active folder",
|
||||
mfshell_cmd_list},
|
||||
{"cd", "<folderkey>", "change active folder (default: root)", mfshell_cmd_chdir},
|
||||
{"cd", "<folderkey>", "change active folder (default: root)",
|
||||
mfshell_cmd_chdir},
|
||||
{"pwd", "", "show the active folder", mfshell_cmd_pwd},
|
||||
{"lpwd", "", "show the local working directory",
|
||||
mfshell_cmd_lpwd},
|
||||
@@ -43,7 +44,8 @@ struct mfcmd commands[] = {
|
||||
mfshell_cmd_lcd},
|
||||
{"mkdir", "[folder name]", "create a new folder", mfshell_cmd_mkdir},
|
||||
{"file", "[quickkey]", "show file information", mfshell_cmd_file},
|
||||
{"folder", "<folderkey>", "show folder information (default:root)", mfshell_cmd_folder},
|
||||
{"folder", "<folderkey>", "show folder information (default:root)",
|
||||
mfshell_cmd_folder},
|
||||
{"links", "[quickkey]", "show access urls for the file",
|
||||
mfshell_cmd_links},
|
||||
{"get", "[quickkey]", "download a file", mfshell_cmd_get},
|
||||
|
||||
@@ -33,7 +33,8 @@ struct mfcmd {
|
||||
char *name;
|
||||
char *argstring;
|
||||
char *help;
|
||||
int (*handler) (mfshell * mfshell, int argc, char *const argv[]);
|
||||
int (*handler) (mfshell * mfshell, int argc,
|
||||
char *const argv[]);
|
||||
};
|
||||
|
||||
struct mfshell {
|
||||
|
||||
@@ -136,8 +136,7 @@ void parse_argv(int argc, char *const argv[], struct mfshell_user_options *opts)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (opts->password != NULL &&
|
||||
opts->username == NULL) {
|
||||
if (opts->password != NULL && opts->username == NULL) {
|
||||
fprintf(stderr, "You cannot pass the password without the username\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -20,17 +20,18 @@
|
||||
#define _MFSHELL_OPTIONS_H_
|
||||
|
||||
struct mfshell_user_options {
|
||||
char *username;
|
||||
char *password;
|
||||
char *command;
|
||||
char *server;
|
||||
char *config;
|
||||
int app_id;
|
||||
char *api_key;
|
||||
char *username;
|
||||
char *password;
|
||||
char *command;
|
||||
char *server;
|
||||
char *config;
|
||||
int app_id;
|
||||
char *api_key;
|
||||
};
|
||||
|
||||
void print_help(const char *cmd);
|
||||
void print_help(const char *cmd);
|
||||
|
||||
void parse_argv(int argc, char *const argv[], struct mfshell_user_options *opts);
|
||||
void parse_argv(int argc, char *const argv[],
|
||||
struct mfshell_user_options *opts);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,6 @@ case $# in
|
||||
;;
|
||||
esac
|
||||
|
||||
ret=0
|
||||
find "$source_dir" -name "*.c" -o -name "*.h" | while read f; do
|
||||
case $f in
|
||||
${source_dir}/*/CMakeFiles/*)
|
||||
@@ -21,10 +20,11 @@ find "$source_dir" -name "*.c" -o -name "*.h" | while read f; do
|
||||
${source_dir}/CMakeFiles/*)
|
||||
;;
|
||||
*)
|
||||
INDENT_PROFILE="${source_dir}/.indent.pro" indent -st "$f" | diff -u "$f" -
|
||||
INDENT_PROFILE="${source_dir}/.indent.pro" indent -st "$f" | diff -u "$f" - >&2
|
||||
ret=$((ret+$?))
|
||||
echo $ret
|
||||
;;
|
||||
esac
|
||||
done | sort -n | tail --lines=1 | while read ret; do
|
||||
exit $ret
|
||||
done
|
||||
|
||||
exit $ret
|
||||
|
||||
Reference in New Issue
Block a user