Compare commits
1 Commits
password-f
...
config-fil
Author | SHA1 | Date | |
---|---|---|---|
ee95a7a8fb |
43
src/main.c
43
src/main.c
@ -350,8 +350,8 @@ int main(int argc, char *argv[]) {
|
||||
xmppc_mode_t mode = UNKOWN;
|
||||
char *jid = NULL;
|
||||
char *pwd = NULL;
|
||||
char *pwd_file = NULL;
|
||||
char *account = NULL;
|
||||
char *config_file_path = NULL;
|
||||
|
||||
static struct option long_options[] = {
|
||||
/* These options set a flag. */
|
||||
@ -361,7 +361,6 @@ int main(int argc, char *argv[]) {
|
||||
{"account", required_argument, 0, 'a'},
|
||||
{"jid", required_argument, 0, 'j'},
|
||||
{"pwd", required_argument, 0, 'p'},
|
||||
{"pwd-file", required_argument, 0, 'P'},
|
||||
{"mode", required_argument, 0, 'm'},
|
||||
{"file", required_argument, 0, 'f'},
|
||||
{0, 0, 0, 0}};
|
||||
@ -375,7 +374,7 @@ int main(int argc, char *argv[]) {
|
||||
while (c > -1) {
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "hva:j:p:m:", long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "hva:j:p:m:c:", long_options, &option_index);
|
||||
if (c > -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
@ -383,7 +382,8 @@ int main(int argc, char *argv[]) {
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
case 'c':
|
||||
printf("option -c with value `%s'\n", optarg);
|
||||
config_file_path = malloc(strlen(optarg) + 1);
|
||||
strcpy(config_file_path, optarg);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
@ -405,11 +405,6 @@ int main(int argc, char *argv[]) {
|
||||
strcpy(pwd, optarg);
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
pwd_file = malloc(strlen(optarg) + 1);
|
||||
strcpy(pwd_file, optarg);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
for(int i = 0; map[i].name;i++ ) {
|
||||
if (strcmp(optarg, map[i].name) == 0) {
|
||||
@ -433,10 +428,22 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// Loading config file
|
||||
GString* configfile = g_string_new(NULL);
|
||||
if (config_file_path != NULL) {
|
||||
if (!g_file_test(config_file_path, G_FILE_TEST_IS_REGULAR)) {
|
||||
logError(&xmppc, "Passed config file does not exist: %s\n", config_file_path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
g_string_assign(configfile, config_file_path);
|
||||
|
||||
} else {
|
||||
g_string_assign(configfile, g_get_home_dir());
|
||||
g_string_append(configfile, "/.config/xmppc.conf");
|
||||
}
|
||||
|
||||
GKeyFile *config_file = g_key_file_new();
|
||||
GError *error = NULL;
|
||||
GString* configfile = g_string_new( g_get_home_dir());
|
||||
g_string_append(configfile,"/.config/xmppc.conf");
|
||||
gboolean configfilefound = g_key_file_load_from_file(
|
||||
config_file,
|
||||
configfile->str,
|
||||
@ -456,18 +463,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
error = NULL;
|
||||
|
||||
if (pwd_file) {
|
||||
gchar *pwd_file_contents = NULL;
|
||||
gsize pwd_file_length = 0;
|
||||
gboolean pwd_file_read = g_file_get_contents(pwd_file, &pwd_file_contents, &pwd_file_length, &error);
|
||||
if (!pwd_file_read) {
|
||||
logError(&xmppc, "Error loading password file: %s\n", error->message);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pwd = g_strstrip(pwd_file_contents);
|
||||
}
|
||||
|
||||
if(jid == NULL && pwd == NULL) {
|
||||
logInfo(&xmppc,"Loading default account\n");
|
||||
if( account == NULL ) {
|
||||
@ -563,7 +558,7 @@ static void _show_help() {
|
||||
printf(" -h / --help Display this information.\n");
|
||||
printf(" -j / --jid <jid> Jabber ID\n");
|
||||
printf(" -p / --pwd <password> Passwort\n");
|
||||
printf(" --pwd-file <file> File containing passwort\n");
|
||||
printf(" -c / --config <file> Config File (defaults to: ~/.config/xmppc.conf\n");
|
||||
printf(" -a / --account <account> Account\n");
|
||||
printf(" -m / --mode <mode> xmppc mode\n");
|
||||
printf("\n");
|
||||
|
Reference in New Issue
Block a user