From 480589f0aec93b5b83d287a221c69d0388f2ec3f Mon Sep 17 00:00:00 2001 From: Tomás Senart Date: Mon, 14 Oct 2013 20:15:51 +0200 Subject: Use passwords from the accounts file This commit makes it so that if the password in an account in the accounts file is present, then use it. Otherwise ask for the password to the user. --- src/command/command.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/command') diff --git a/src/command/command.c b/src/command/command.c index e8232405..d824ebc5 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -20,6 +20,7 @@ * */ +#include #include #include #include @@ -68,6 +69,7 @@ typedef struct cmd_t { typedef char*(*autocompleter)(char*, int*); +static void _ask_password(char * passwd); static void _update_presence(const resource_presence_t presence, const char * const show, gchar **args); static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, @@ -1347,13 +1349,6 @@ _cmd_connect(gchar **args, struct cmd_help_t help) char *lower = g_utf8_strdown(user, -1); char *jid; - status_bar_get_password(); - status_bar_refresh(); - char passwd[21]; - inp_block(); - inp_get_password(passwd); - inp_non_block(); - ProfAccount *account = accounts_get_account(lower); if (account != NULL) { if (account->resource != NULL) { @@ -1361,9 +1356,16 @@ _cmd_connect(gchar **args, struct cmd_help_t help) } else { jid = strdup(account->jid); } + + if (strlen(account->password) == 0) { + account->password = (gchar *) realloc(account->password, 21); + _ask_password(account->password); + } cons_show("Connecting with account %s as %s", account->name, jid); - conn_status = jabber_connect_with_account(account, passwd); + conn_status = jabber_connect_with_account(account); } else { + char passwd[21]; + _ask_password(passwd); jid = strdup(lower); cons_show("Connecting as %s", jid); conn_status = jabber_connect_with_details(jid, passwd, altdomain); @@ -3525,6 +3527,18 @@ _cmd_xa(gchar **args, struct cmd_help_t help) return TRUE; } +// helper function that asks the user for a password and saves it in passwd + +static void +_ask_password(char * passwd) { + assert(passwd != NULL); + status_bar_get_password(); + status_bar_refresh(); + inp_block(); + inp_get_password(passwd); + inp_non_block(); +} + // helper function for status change commands static void -- cgit 1.4.1-2-gfad0