From ab728c93daa9252d15366c40dfed7f812d8cc953 Mon Sep 17 00:00:00 2001 From: josch Date: Tue, 23 Sep 2014 19:18:23 +0200 Subject: [PATCH] make App ID and API Key configurable via commandline --- mfshell/main.c | 13 +++++++++++-- mfshell/options.c | 10 ++++++++++ mfshell/options.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mfshell/main.c b/mfshell/main.c index 1ec113f..2a7e066 100644 --- a/mfshell/main.c +++ b/mfshell/main.c @@ -37,7 +37,9 @@ int main(int argc, char *const argv[]) .password = NULL, .command = NULL, .server = NULL, - .config = NULL + .config = NULL, + .app_id = -1, + .api_key = NULL, }; SSL_library_init(); @@ -52,7 +54,12 @@ int main(int argc, char *const argv[]) opts.server = strdup("www.mediafire.com"); } - shell = mfshell_create(35860, NULL, + // 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); if (shell == NULL) { fprintf(stderr, "cannot create shell\n"); @@ -92,6 +99,8 @@ int main(int argc, char *const argv[]) free(opts.command); if (opts.config != NULL) free(opts.config); + if (opts.api_key != NULL) + free(opts.api_key); return 0; } diff --git a/mfshell/options.c b/mfshell/options.c index 103deba..2eac29a 100644 --- a/mfshell/options.c +++ b/mfshell/options.c @@ -35,6 +35,8 @@ void print_help(const char *cmd) fprintf(stderr, " -u, --username= Login username\n"); fprintf(stderr, " -p, --password= Login password\n"); fprintf(stderr, " -s, --server= Login server\n"); + fprintf(stderr, " -i, --app-id= App ID\n"); + fprintf(stderr, " -k, --api-key= API Key\n"); fprintf(stderr, "\n"); fprintf(stderr, "Username and password are optional. If not given, they\n" @@ -72,6 +74,8 @@ void parse_argv(int argc, char *const argv[], struct mfshell_user_options *opts) {"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'}, {"server", required_argument, 0, 's'}, + {"app-id", required_argument, 0, 'i'}, + {"api-key", required_argument, 0, 'k'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, {0, 0, 0, 0} @@ -107,6 +111,12 @@ void parse_argv(int argc, char *const argv[], struct mfshell_user_options *opts) case 'f': if (opts->config == NULL) opts->config = strdup(optarg); + case 'i': + if (opts->app_id == -1) + opts->app_id = atoi(optarg); + case 'k': + if (opts->api_key == NULL) + opts->api_key = strdup(optarg); case 'h': print_help(argv[0]); exit(0); diff --git a/mfshell/options.h b/mfshell/options.h index 0a9f97b..76464e5 100644 --- a/mfshell/options.h +++ b/mfshell/options.h @@ -25,6 +25,8 @@ struct mfshell_user_options { char *command; char *server; char *config; + int app_id; + char *api_key; }; void print_help(const char *cmd);