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;
|
xmppc_mode_t mode = UNKOWN;
|
||||||
char *jid = NULL;
|
char *jid = NULL;
|
||||||
char *pwd = NULL;
|
char *pwd = NULL;
|
||||||
char *pwd_file = NULL;
|
|
||||||
char *account = NULL;
|
char *account = NULL;
|
||||||
|
char *config_file_path = NULL;
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
/* These options set a flag. */
|
/* These options set a flag. */
|
||||||
@@ -361,7 +361,6 @@ int main(int argc, char *argv[]) {
|
|||||||
{"account", required_argument, 0, 'a'},
|
{"account", required_argument, 0, 'a'},
|
||||||
{"jid", required_argument, 0, 'j'},
|
{"jid", required_argument, 0, 'j'},
|
||||||
{"pwd", required_argument, 0, 'p'},
|
{"pwd", required_argument, 0, 'p'},
|
||||||
{"pwd-file", required_argument, 0, 'P'},
|
|
||||||
{"mode", required_argument, 0, 'm'},
|
{"mode", required_argument, 0, 'm'},
|
||||||
{"file", required_argument, 0, 'f'},
|
{"file", required_argument, 0, 'f'},
|
||||||
{0, 0, 0, 0}};
|
{0, 0, 0, 0}};
|
||||||
@@ -375,7 +374,7 @@ int main(int argc, char *argv[]) {
|
|||||||
while (c > -1) {
|
while (c > -1) {
|
||||||
int option_index = 0;
|
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) {
|
if (c > -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'h':
|
case 'h':
|
||||||
@@ -383,7 +382,8 @@ int main(int argc, char *argv[]) {
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
printf("option -c with value `%s'\n", optarg);
|
config_file_path = malloc(strlen(optarg) + 1);
|
||||||
|
strcpy(config_file_path, optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
@@ -405,11 +405,6 @@ int main(int argc, char *argv[]) {
|
|||||||
strcpy(pwd, optarg);
|
strcpy(pwd, optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'P':
|
|
||||||
pwd_file = malloc(strlen(optarg) + 1);
|
|
||||||
strcpy(pwd_file, optarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
for(int i = 0; map[i].name;i++ ) {
|
for(int i = 0; map[i].name;i++ ) {
|
||||||
if (strcmp(optarg, map[i].name) == 0) {
|
if (strcmp(optarg, map[i].name) == 0) {
|
||||||
@@ -433,10 +428,22 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Loading config file
|
// 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();
|
GKeyFile *config_file = g_key_file_new();
|
||||||
GError *error = NULL;
|
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(
|
gboolean configfilefound = g_key_file_load_from_file(
|
||||||
config_file,
|
config_file,
|
||||||
configfile->str,
|
configfile->str,
|
||||||
@@ -456,18 +463,6 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
error = NULL;
|
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) {
|
if(jid == NULL && pwd == NULL) {
|
||||||
logInfo(&xmppc,"Loading default account\n");
|
logInfo(&xmppc,"Loading default account\n");
|
||||||
if( account == NULL ) {
|
if( account == NULL ) {
|
||||||
@@ -563,7 +558,7 @@ static void _show_help() {
|
|||||||
printf(" -h / --help Display this information.\n");
|
printf(" -h / --help Display this information.\n");
|
||||||
printf(" -j / --jid <jid> Jabber ID\n");
|
printf(" -j / --jid <jid> Jabber ID\n");
|
||||||
printf(" -p / --pwd <password> Passwort\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(" -a / --account <account> Account\n");
|
||||||
printf(" -m / --mode <mode> xmppc mode\n");
|
printf(" -m / --mode <mode> xmppc mode\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Reference in New Issue
Block a user