about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-11-20 02:09:34 +0000
committerJames Booth <boothj5@gmail.com>2016-11-20 02:09:34 +0000
commit609d05366c00670c176c842a19be760ad54f384b (patch)
tree1d178adc18bf1956bc63234a553935b9eccdee28 /src/config
parent44979ac7540510f8dccbe0f37782eb7d862e93a3 (diff)
downloadprofani-tty-609d05366c00670c176c842a19be760ad54f384b.tar.gz
Use server features for account muc service
issue #878
Diffstat (limited to 'src/config')
-rw-r--r--src/config/account.c57
-rw-r--r--src/config/accounts.c96
-rw-r--r--src/config/accounts.h1
3 files changed, 83 insertions, 71 deletions
diff --git a/src/config/account.c b/src/config/account.c
index 3e8c8cf1..40b91224 100644
--- a/src/config/account.c
+++ b/src/config/account.c
@@ -115,17 +115,10 @@ account_new(const gchar *const name, const gchar *const jid,
     new_account->priority_xa = priority_xa;
     new_account->priority_dnd = priority_dnd;
 
-    if (muc_service == NULL) {
-        GString *g_muc_service = g_string_new("conference.");
-        Jid *jidp = jid_create(new_account->jid);
-        g_string_append(g_muc_service, jidp->domainpart);
-
-        new_account->muc_service = g_muc_service->str;
-
-        g_string_free(g_muc_service, FALSE);
-        jid_destroy(jidp);
-    } else {
+    if (muc_service) {
         new_account->muc_service = strdup(muc_service);
+    } else {
+        new_account->muc_service = NULL;
     }
 
     if (muc_nick == NULL) {
@@ -224,25 +217,27 @@ account_eval_password(ProfAccount *account)
 void
 account_free(ProfAccount *account)
 {
-    if (account) {
-        free(account->name);
-        free(account->jid);
-        free(account->password);
-        free(account->eval_password);
-        free(account->resource);
-        free(account->server);
-        free(account->last_presence);
-        free(account->login_presence);
-        free(account->muc_service);
-        free(account->muc_nick);
-        free(account->otr_policy);
-        free(account->pgp_keyid);
-        free(account->startscript);
-        free(account->theme);
-        free(account->tls_policy);
-        g_list_free_full(account->otr_manual, g_free);
-        g_list_free_full(account->otr_opportunistic, g_free);
-        g_list_free_full(account->otr_always, g_free);
-        free(account);
-    }
+    if (account == NULL) {
+        return;
+    }
+
+    free(account->name);
+    free(account->jid);
+    free(account->password);
+    free(account->eval_password);
+    free(account->resource);
+    free(account->server);
+    free(account->last_presence);
+    free(account->login_presence);
+    free(account->muc_service);
+    free(account->muc_nick);
+    free(account->otr_policy);
+    free(account->pgp_keyid);
+    free(account->startscript);
+    free(account->theme);
+    free(account->tls_policy);
+    g_list_free_full(account->otr_manual, g_free);
+    g_list_free_full(account->otr_opportunistic, g_free);
+    g_list_free_full(account->otr_always, g_free);
+    free(account);
 }
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 96168b5b..233a5aa8 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -133,46 +133,46 @@ accounts_add(const char *account_name, const char *altdomain, const int port, co
         }
     }
 
-    // doesn't yet exist
-    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);
-        g_key_file_set_string(accounts, account_name, "resource", resource);
-        if (altdomain) {
-            g_key_file_set_string(accounts, account_name, "server", altdomain);
-        }
-        if (port != 0) {
-            g_key_file_set_integer(accounts, account_name, "port", port);
-        }
-        if (tls_policy) {
-            g_key_file_set_string(accounts, account_name, "tls.policy", tls_policy);
-        }
+    if (g_key_file_has_group(accounts, account_name)) {
+        jid_destroy(jid);
+        return;
+    }
 
-        Jid *jidp = jid_create(barejid);
-        GString *muc_service = g_string_new("conference.");
-        g_string_append(muc_service, jidp->domainpart);
-        g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str);
-        g_string_free(muc_service, TRUE);
-        if (jidp->localpart == NULL) {
-            g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
-        } else {
-            g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
-        }
-        jid_destroy(jidp);
+    g_key_file_set_boolean(accounts, account_name, "enabled", TRUE);
+    g_key_file_set_string(accounts, account_name, "jid", barejid);
+    g_key_file_set_string(accounts, account_name, "resource", resource);
+    if (altdomain) {
+        g_key_file_set_string(accounts, account_name, "server", altdomain);
+    }
+    if (port != 0) {
+        g_key_file_set_integer(accounts, account_name, "port", port);
+    }
+    if (tls_policy) {
+        g_key_file_set_string(accounts, account_name, "tls.policy", tls_policy);
+    }
 
-        g_key_file_set_string(accounts, account_name, "presence.last", "online");
-        g_key_file_set_string(accounts, account_name, "presence.login", "online");
-        g_key_file_set_integer(accounts, account_name, "priority.online", 0);
-        g_key_file_set_integer(accounts, account_name, "priority.chat", 0);
-        g_key_file_set_integer(accounts, account_name, "priority.away", 0);
-        g_key_file_set_integer(accounts, account_name, "priority.xa", 0);
-        g_key_file_set_integer(accounts, account_name, "priority.dnd", 0);
+    Jid *jidp = jid_create(barejid);
 
-        _save_accounts();
-        autocomplete_add(all_ac, account_name);
-        autocomplete_add(enabled_ac, account_name);
+    if (jidp->localpart == NULL) {
+        g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
+    } else {
+        g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
     }
 
+    jid_destroy(jidp);
+
+    g_key_file_set_string(accounts, account_name, "presence.last", "online");
+    g_key_file_set_string(accounts, account_name, "presence.login", "online");
+    g_key_file_set_integer(accounts, account_name, "priority.online", 0);
+    g_key_file_set_integer(accounts, account_name, "priority.chat", 0);
+    g_key_file_set_integer(accounts, account_name, "priority.away", 0);
+    g_key_file_set_integer(accounts, account_name, "priority.xa", 0);
+    g_key_file_set_integer(accounts, account_name, "priority.dnd", 0);
+
+    _save_accounts();
+    autocomplete_add(all_ac, account_name);
+    autocomplete_add(enabled_ac, account_name);
+
     jid_destroy(jid);
 }
 
@@ -223,7 +223,18 @@ accounts_get_account(const char *const name)
         int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL);
         int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL);
 
-        gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
+        gchar *muc_service = NULL;
+        if (g_key_file_has_key(accounts, name, "muc.service", NULL)) {
+            muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
+        } else {
+            jabber_conn_status_t conn_status = connection_get_status();
+            if (conn_status == JABBER_CONNECTED) {
+                char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
+                if (conf_jid) {
+                    muc_service = strdup(conf_jid);
+                }
+            }
+        }
         gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);
 
         gchar *otr_policy = NULL;
@@ -416,10 +427,6 @@ accounts_set_jid(const char *const account_name, const char *const value)
                 g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart);
             }
 
-            GString *muc_service = g_string_new("conference.");
-            g_string_append(muc_service, jid->domainpart);
-            g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str);
-            g_string_free(muc_service, TRUE);
             if (jid->localpart == NULL) {
                 g_key_file_set_string(accounts, account_name, "muc.nick", jid->domainpart);
             } else {
@@ -569,6 +576,15 @@ accounts_clear_theme(const char *const account_name)
 }
 
 void
+accounts_clear_muc(const char *const account_name)
+{
+    if (accounts_account_exists(account_name)) {
+        g_key_file_remove_key(accounts, account_name, "muc.service", NULL);
+        _save_accounts();
+    }
+}
+
+void
 accounts_clear_otr(const char *const account_name)
 {
     if (accounts_account_exists(account_name)) {
diff --git a/src/config/accounts.h b/src/config/accounts.h
index 7524c65e..6c6cb1c9 100644
--- a/src/config/accounts.h
+++ b/src/config/accounts.h
@@ -93,6 +93,7 @@ void accounts_clear_otr(const char *const account_name);
 void accounts_clear_pgp_keyid(const char *const account_name);
 void accounts_clear_script_start(const char *const account_name);
 void accounts_clear_theme(const char *const account_name);
+void accounts_clear_muc(const char *const account_name);
 void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy);
 
 #endif