about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/config/accounts.c43
-rw-r--r--src/config/conflists.c49
-rw-r--r--src/config/conflists.h2
3 files changed, 52 insertions, 42 deletions
diff --git a/src/config/accounts.c b/src/config/accounts.c
index 234bed1f..385e86f3 100644
--- a/src/config/accounts.c
+++ b/src/config/accounts.c
@@ -558,48 +558,7 @@ accounts_add_otr_policy(const char *const account_name, const char *const contac
     if (accounts_account_exists(account_name)) {
         GString *key = g_string_new("otr.");
         g_string_append(key, policy);
-        gsize length;
-        gchar **list = g_key_file_get_string_list(accounts, account_name, key->str, &length, NULL);
-        GList *glist = NULL;
-
-        // list found
-        if (list) {
-            int i = 0;
-            for (i = 0; i < length; i++) {
-                // item already in list, exit function
-                if (strcmp(list[i], contact_jid) == 0) {
-                    g_list_free_full(glist, g_free);
-                    g_strfreev(list);
-                    return;
-                }
-                // add item to our g_list
-                glist = g_list_append(glist, strdup(list[i]));
-            }
-
-            // item not found, add to our g_list
-            glist = g_list_append(glist, strdup(contact_jid));
-
-            // create the new list entry
-            const gchar* new_list[g_list_length(glist)+1];
-            GList *curr = glist;
-            i = 0;
-            while (curr) {
-                new_list[i++] = strdup(curr->data);
-                curr = g_list_next(curr);
-            }
-            new_list[i] = NULL;
-            g_key_file_set_string_list(accounts, account_name, key->str, new_list, g_list_length(glist));
-
-        // list not found
-        } else {
-            const gchar* new_list[2];
-            new_list[0] = strdup(contact_jid);
-            new_list[1] = NULL;
-            g_key_file_set_string_list(accounts, account_name, key->str, new_list, 1);
-        }
-
-        g_strfreev(list);
-        g_list_free_full(glist, g_free);
+        conf_string_list_add(accounts, account_name, key->str, contact_jid);
         g_string_free(key, TRUE);
 
         // check for and remove from other lists
diff --git a/src/config/conflists.c b/src/config/conflists.c
index bf5bc482..474969e6 100644
--- a/src/config/conflists.c
+++ b/src/config/conflists.c
@@ -36,6 +36,55 @@
 #include <glib.h>
 
 gboolean
+conf_string_list_add(GKeyFile *keyfile, const char *const group, const char *const key, const char *const item)
+{
+    gsize length;
+    gchar **list = g_key_file_get_string_list(keyfile, group, key, &length, NULL);
+    GList *glist = NULL;
+
+    // list found
+    if (list) {
+        int i = 0;
+        for (i = 0; i < length; i++) {
+            // item already in list, exit function
+            if (strcmp(list[i], item) == 0) {
+                g_list_free_full(glist, g_free);
+                g_strfreev(list);
+                return FALSE;
+            }
+            // add item to our g_list
+            glist = g_list_append(glist, strdup(list[i]));
+        }
+
+        // item not found, add to our g_list
+        glist = g_list_append(glist, strdup(item));
+
+        // create the new list entry
+        const gchar* new_list[g_list_length(glist)+1];
+        GList *curr = glist;
+        i = 0;
+        while (curr) {
+            new_list[i++] = strdup(curr->data);
+            curr = g_list_next(curr);
+        }
+        new_list[i] = NULL;
+        g_key_file_set_string_list(keyfile, group, key, new_list, g_list_length(glist));
+
+    // list not found
+    } else {
+        const gchar* new_list[2];
+        new_list[0] = strdup(item);
+        new_list[1] = NULL;
+        g_key_file_set_string_list(keyfile, group, key, new_list, 1);
+    }
+
+    g_strfreev(list);
+    g_list_free_full(glist, g_free);
+
+    return TRUE;
+}
+
+gboolean
 conf_string_list_remove(GKeyFile *keyfile, const char *const group, const char *const key, const char *const item)
 {
     gsize length;
diff --git a/src/config/conflists.h b/src/config/conflists.h
index f67e58b8..2254732c 100644
--- a/src/config/conflists.h
+++ b/src/config/conflists.h
@@ -34,5 +34,7 @@
 
 #include <glib.h>
 
+gboolean conf_string_list_add(GKeyFile *keyfile, const char *const group, const char *const key,
+    const char *const item);
 gboolean conf_string_list_remove(GKeyFile *keyfile, const char *const group, const char *const key,
     const char *const item);