make App ID and API Key configurable via commandline

This commit is contained in:
josch
2014-09-23 19:18:23 +02:00
parent 036954df35
commit ab728c93da
3 changed files with 23 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -35,6 +35,8 @@ void print_help(const char *cmd)
fprintf(stderr, " -u, --username=<USER> Login username\n");
fprintf(stderr, " -p, --password=<PASS> Login password\n");
fprintf(stderr, " -s, --server=<SERVER> Login server\n");
fprintf(stderr, " -i, --app-id=<id> App ID\n");
fprintf(stderr, " -k, --api-key=<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);

View File

@@ -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);