Files
mediafire-fuse/mfshell/main.c

93 lines
2.6 KiB
C
Raw Normal View History

/*
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
* 2014 Johannes Schauer <j.schauer@email.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <openssl/ssl.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "../utils/strings.h"
#include "mfshell.h"
2014-09-23 13:51:32 +02:00
#include "config.h"
#include "options.h"
2014-09-21 15:59:52 +02:00
int main(int argc, char *const argv[])
{
2014-09-21 00:03:20 +02:00
mfshell *shell;
char *auth_cmd;
2014-09-23 13:51:32 +02:00
struct mfshell_user_options opts = {
.username = NULL,
.password = NULL,
.command = NULL,
.server = NULL,
.config = NULL
};
SSL_library_init();
2014-09-23 13:51:32 +02:00
parse_argv(argc, argv, &opts);
2014-09-23 13:51:32 +02:00
parse_config(&opts);
// if server was neither set on the commandline nor in the config, set it
// to the default value
2014-09-23 13:51:32 +02:00
if (opts.server == NULL) {
opts.server = strdup("www.mediafire.com");
}
2014-09-21 00:03:20 +02:00
shell = mfshell_create(35860, "2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg",
2014-09-23 13:51:32 +02:00
opts.server);
// if at least username was set, authenticate automatically
2014-09-23 13:51:32 +02:00
if (opts.username != NULL) {
if (opts.password != NULL) {
auth_cmd = strdup_printf("auth %s %s",
2014-09-23 13:51:32 +02:00
opts.username,
opts.password);
} else {
2014-09-23 13:51:32 +02:00
auth_cmd = strdup_printf("auth %s", opts.username);
}
mfshell_parse_commands(shell, auth_cmd);
free(auth_cmd);
}
2014-09-23 13:51:32 +02:00
if (opts.command == NULL) {
// begin shell mode
2014-09-21 00:03:20 +02:00
mfshell_run(shell);
} else {
// interpret command
2014-09-23 13:51:32 +02:00
mfshell_parse_commands(shell, opts.command);
}
2014-09-21 00:03:20 +02:00
mfshell_destroy(shell);
2014-09-23 13:51:32 +02:00
if (opts.server != NULL)
free(opts.server);
if (opts.username != NULL)
free(opts.username);
if (opts.password != NULL)
free(opts.password);
if (opts.command != NULL)
free(opts.command);
if (opts.config != NULL)
free(opts.config);
2014-09-21 00:03:20 +02:00
return 0;
}