From 1c2661f1c3d5750f8f82f0b51b42eb64093e6d58 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 8 Dec 2013 23:36:00 +0000 Subject: Added clear command to /account for password clearing fixes #267 --- src/command/command.c | 45 ++++++++++++++++++++++++++++++++++++--------- src/config/accounts.c | 9 +++++++++ src/config/accounts.h | 1 + 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index d86af195..43acbd09 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -746,16 +746,18 @@ static struct cmd_t command_defs[] = { "/account [command] [account] [property] [value]", "-----------------------------------------------", "Commands for creating and managing accounts.", - "list : List all accounts.", - "show account : Show information about an account.", - "enable account : Enable the account, it will be used for autocomplete.", - "disable account : Disable the account.", - "add account : Create a new account.", - "rename account newname : Rename account to newname.", - "set account property value : Set 'property' of 'account' to 'value'.", + "list : List all accounts.", + "show account : Show information about an account.", + "enable account : Enable the account, it will be used for autocomplete.", + "disable account : Disable the account.", + "add account : Create a new account.", + "rename account newname : Rename account to newname.", + "set account property value : Set 'property' of 'account' to 'value'.", + "clear account property value : Clear 'property' of 'account'.", "", "When connected, the /account command can be called with no arguments, to show current account settings.", - "The 'property' may be one of.", + "", + "The set command may use one of the following for 'property'.", "jid : The Jabber ID of the account, the account name will be used if this property is not set.", "server : The chat server, if different to the domainpart of the JID.", "status : The presence status to use on login, use 'last' to use whatever your last status was.", @@ -766,6 +768,9 @@ static struct cmd_t command_defs[] = "muc : The default MUC chat service to use.", "nick : The default nickname to use when joining chat rooms.", "", + "The clear command may use one of the following for 'property'.", + "password : Clears the password for the account.", + "", "Example : /account add work", " : /account set work jid myuser@mycompany.com", " : /account set work server talk.google.com", @@ -993,6 +998,7 @@ cmd_init(void) autocomplete_add(account_ac, "disable"); autocomplete_add(account_ac, "rename"); autocomplete_add(account_ac, "set"); + autocomplete_add(account_ac, "clear"); close_ac = autocomplete_new(); autocomplete_add(close_ac, "read"); @@ -1579,6 +1585,27 @@ _cmd_account(gchar **args, struct cmd_help_t help) } } } + } else if (strcmp(command, "clear") == 0) { + if (g_strv_length(args) != 3) { + cons_show("Usage: %s", help.usage); + } else { + char *account_name = args[1]; + char *property = args[2]; + + if (!accounts_account_exists(account_name)) { + cons_show("Account %s doesn't exist", account_name); + cons_show(""); + } else { + if (strcmp(property, "password") == 0) { + accounts_clear_password(account_name); + cons_show("Removed password for account %s", account_name); + cons_show(""); + } else { + cons_show("Invalid property: %s", property); + cons_show(""); + } + } + } } else { cons_show(""); } @@ -3883,7 +3910,7 @@ _account_autocomplete(char *input, int *size) char *result = NULL; int i = 0; gchar *account_choice[] = { "/account set", "/account show", "/account enable", - "/account disable", "/account rename" }; + "/account disable", "/account rename", "/account clear" }; for (i = 0; i < ARRAY_SIZE(account_choice); i++) { result = autocomplete_param_with_func(input, size, account_choice[i], diff --git a/src/config/accounts.c b/src/config/accounts.c index 6bfc7bef..0422a991 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -443,6 +443,15 @@ accounts_set_password(const char * const account_name, const char * const value) } } +void +accounts_clear_password(const char * const account_name) +{ + if (accounts_account_exists(account_name)) { + g_key_file_remove_key(accounts, account_name, "password", NULL); + _save_accounts(); + } +} + void accounts_set_muc_service(const char * const account_name, const char * const value) { diff --git a/src/config/accounts.h b/src/config/accounts.h index 118b5c80..96289952 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -80,5 +80,6 @@ void accounts_set_priority_dnd(const char * const account_name, const gint value void accounts_set_priority_all(const char * const account_name, const gint value); gint accounts_get_priority_for_presence_type(const char * const account_name, resource_presence_t presence_type); +void accounts_clear_password(const char * const account_name); #endif -- cgit 1.4.1-2-gfad0