diff --git a/fuse/main.c b/fuse/main.c index 6171b94..884dbdb 100644 --- a/fuse/main.c +++ b/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"); diff --git a/mfapi/apicalls/folder_create.c b/mfapi/apicalls/folder_create.c index 8744946..7609510 100644 --- a/mfapi/apicalls/folder_create.c +++ b/mfapi/apicalls/folder_create.c @@ -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; diff --git a/mfapi/apicalls/folder_get_content.c b/mfapi/apicalls/folder_get_content.c index 63496e4..9aebc6f 100644 --- a/mfapi/apicalls/folder_get_content.c +++ b/mfapi/apicalls/folder_get_content.c @@ -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(); diff --git a/mfapi/apicalls/folder_get_info.c b/mfapi/apicalls/folder_get_info.c index ab69791..f455c81 100644 --- a/mfapi/apicalls/folder_get_info.c +++ b/mfapi/apicalls/folder_get_info.c @@ -17,7 +17,7 @@ * */ -#define _XOPEN_SOURCE // for strptime +#define _XOPEN_SOURCE // for strptime #include #include #include @@ -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(); diff --git a/mfapi/apicalls/user_session.c b/mfapi/apicalls/user_session.c index 8e4296c..245a14e 100644 --- a/mfapi/apicalls/user_session.c +++ b/mfapi/apicalls/user_session.c @@ -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; diff --git a/mfapi/mfconn.c b/mfapi/mfconn.c index f24c062..0c2e649 100644 --- a/mfapi/mfconn.c +++ b/mfapi/mfconn.c @@ -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; diff --git a/mfapi/mfconn.h b/mfapi/mfconn.h index 7d2b4d2..ef70d94 100644 --- a/mfapi/mfconn.h +++ b/mfapi/mfconn.h @@ -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, diff --git a/mfshell/commands.h b/mfshell/commands.h index ab49f74..8a9071a 100644 --- a/mfshell/commands.h +++ b/mfshell/commands.h @@ -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[]); diff --git a/mfshell/commands/folder.c b/mfshell/commands/folder.c index eebde24..4b8e349 100644 --- a/mfshell/commands/folder.c +++ b/mfshell/commands/folder.c @@ -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)); diff --git a/mfshell/commands/mkdir.c b/mfshell/commands/mkdir.c index cdd6139..a0fa16f 100644 --- a/mfshell/commands/mkdir.c +++ b/mfshell/commands/mkdir.c @@ -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; diff --git a/mfshell/config.c b/mfshell/config.c index 26da8af..35eedc9 100644 --- a/mfshell/config.c +++ b/mfshell/config.c @@ -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); diff --git a/mfshell/config.h b/mfshell/config.h index 497c470..06412ec 100644 --- a/mfshell/config.h +++ b/mfshell/config.h @@ -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 diff --git a/mfshell/main.c b/mfshell/main.c index 2a7e066..aa52faa 100644 --- a/mfshell/main.c +++ b/mfshell/main.c @@ -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); } diff --git a/mfshell/mfshell.c b/mfshell/mfshell.c index 295d87e..7b74054 100644 --- a/mfshell/mfshell.c +++ b/mfshell/mfshell.c @@ -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", "", "change active folder (default: root)", mfshell_cmd_chdir}, + {"cd", "", "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", "", "show folder information (default:root)", mfshell_cmd_folder}, + {"folder", "", "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}, diff --git a/mfshell/mfshell.h b/mfshell/mfshell.h index a236597..046a8e5 100644 --- a/mfshell/mfshell.h +++ b/mfshell/mfshell.h @@ -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 { diff --git a/mfshell/options.c b/mfshell/options.c index 2eac29a..3f842f3 100644 --- a/mfshell/options.c +++ b/mfshell/options.c @@ -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); } diff --git a/mfshell/options.h b/mfshell/options.h index 76464e5..a08c876 100644 --- a/mfshell/options.h +++ b/mfshell/options.h @@ -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 diff --git a/tests/indent.sh b/tests/indent.sh index 1e9d972..85bc68f 100755 --- a/tests/indent.sh +++ b/tests/indent.sh @@ -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