about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-26 22:19:20 +0000
committerJames Booth <boothj5@gmail.com>2013-01-26 22:19:20 +0000
commita8d80ef5586b2590c1bcd060beea0250d2a5eac5 (patch)
tree4dd96a9f76e0391a7718bced822b48df2bca6219
parent4092498de8ccb03d5f119fbd3d10d4fd4e0e73de (diff)
downloadprofani-tty-a8d80ef5586b2590c1bcd060beea0250d2a5eac5.tar.gz
Parse account name as jid on account add, handle resource part
-rw-r--r--src/accounts.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/accounts.c b/src/accounts.c
index 08e73b90..f2340300 100644
--- a/src/accounts.c
+++ b/src/accounts.c
@@ -26,9 +26,10 @@
 #include <glib.h>
 
 #include "accounts.h"
+#include "autocomplete.h"
 #include "files.h"
+#include "jid.h"
 #include "log.h"
-#include "autocomplete.h"
 
 static gchar *accounts_loc;
 static GKeyFile *accounts;
@@ -102,26 +103,48 @@ accounts_reset_enabled_search(void)
 }
 
 void
-accounts_add_login(const char *jid, const char *altdomain)
+accounts_add_login(const char *account_name, const char *altdomain)
 {
+    const char *barejid = account_name;
+    const char *resource = NULL;
+
+    Jid *jid = jid_create(account_name);
+
+    if (jid != NULL) {
+        barejid = jid->barejid;
+        resource = jid->resourcepart;
+    }
+
     // doesn't yet exist
-    if (!g_key_file_has_group(accounts, jid)) {
-        g_key_file_set_boolean(accounts, jid, "enabled", TRUE);
-        g_key_file_set_string(accounts, jid, "jid", jid);
+    if (!g_key_file_has_group(accounts, account_name)) {
+        g_key_file_set_boolean(accounts, account_name, "enabled", TRUE);
+        g_key_file_set_string(accounts, account_name, "jid", barejid);
+        if (resource != NULL) {
+            g_key_file_set_string(accounts, account_name, "resource", resource);
+        } else {
+            g_key_file_set_string(accounts, account_name, "resource", "profanity");
+        }
+
         if (altdomain != NULL) {
-            g_key_file_set_string(accounts, jid, "server", altdomain);
+            g_key_file_set_string(accounts, account_name, "server", altdomain);
         }
 
         _save_accounts();
-        autocomplete_add(all_ac, strdup(jid));
-        autocomplete_add(enabled_ac, strdup(jid));
+        autocomplete_add(all_ac, strdup(account_name));
+        autocomplete_add(enabled_ac, strdup(account_name));
 
     // already exists, update old style accounts
     } else {
-        g_key_file_set_string(accounts, jid, "jid", jid);
+        g_key_file_set_string(accounts, account_name, "jid", barejid);
+        if (resource != NULL) {
+            g_key_file_set_string(accounts, account_name, "resource", resource);
+        } else {
+            g_key_file_set_string(accounts, account_name, "resource", "profanity");
+        }
         _save_accounts();
     }
 
+    jid_destroy(jid);
 }
 
 gchar**