about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-12 00:21:28 +0100
committerJames Booth <boothj5@gmail.com>2014-09-12 00:21:28 +0100
commit38959e0c33f292a7824aeb64ddb6f5e2b2831206 (patch)
treeeb0988ad904ea8a8d79e105cf78ad1be5dc27fa7 /src/xmpp
parent42a14d018274d2ab306e95765a735ee25aafa6ee (diff)
downloadprofani-tty-38959e0c33f292a7824aeb64ddb6f5e2b2831206.tar.gz
Added setting of *-single room config values
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/form.c23
-rw-r--r--src/xmpp/xmpp.h1
2 files changed, 24 insertions, 0 deletions
diff --git a/src/xmpp/form.c b/src/xmpp/form.c
index 3ee31a6b..c23ffa26 100644
--- a/src/xmpp/form.c
+++ b/src/xmpp/form.c
@@ -382,9 +382,32 @@ _form_get_field_by_var(DataForm *form, const char * const var)
     return NULL;
 }
 
+static void
+_form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
+{
+    char *var = g_hash_table_lookup(form->tag_to_var, tag);
+    if (var != NULL) {
+        GSList *curr = form->fields;
+        while (curr != NULL) {
+            FormField *field = curr->data;
+            if (g_strcmp0(field->var, var) == 0) {
+                if (g_slist_length(field->values) == 0) {
+                    field->values = g_slist_append(field->values, strdup(value));
+                } else if (g_slist_length(field->values) == 1) {
+                    free(field->values->data);
+                    field->values->data = strdup(value);
+                    return;
+                }
+            }
+            curr = g_slist_next(curr);
+        }
+    }
+}
+
 void
 form_init_module(void)
 {
     form_destroy = _form_destroy;
     form_get_field_by_var = _form_get_field_by_var;
+    form_set_value_by_tag = _form_set_value_by_tag;
 }
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 0186fba5..97a405ed 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -206,5 +206,6 @@ void (*roster_send_remove)(const char * const barejid);
 
 void (*form_destroy)(DataForm *form);
 char * (*form_get_field_by_var)(DataForm *form, const char * const var);
+void (*form_set_value_by_tag)(DataForm *form, const char * const tag, char *value);
 
 #endif