about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-12-08 23:48:07 +0000
committerJames Booth <boothj5@gmail.com>2013-12-08 23:48:07 +0000
commitd17cd3f5739e08a994bf0b260a8d196e4c27d542 (patch)
treeaaeeb7c32abdc633ad5d127210b573c57a5929b3
parent6bba79eed4b98aec9a31f3b722e05b27b70b596f (diff)
parent1c2661f1c3d5750f8f82f0b51b42eb64093e6d58 (diff)
downloadprofani-tty-d17cd3f5739e08a994bf0b260a8d196e4c27d542.tar.gz
Merge branch 'master' into refactor
-rw-r--r--src/command/command.c45
-rw-r--r--src/config/accounts.c9
-rw-r--r--src/config/accounts.h1
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
@@ -444,6 +444,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)
 {
     if (accounts_account_exists(account_name)) {
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