about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/commands.c36
-rw-r--r--src/ui/core.c2
-rw-r--r--src/xmpp/form.c46
-rw-r--r--src/xmpp/xmpp.h9
4 files changed, 72 insertions, 21 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 81e8660b..57687ea9 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1921,37 +1921,37 @@ cmd_room(gchar **args, struct cmd_help_t help)
             if (!form_tag_exists(current->form, tag)) {
                 ui_current_print_line("Form does not contain a field with tag %s", tag);
             } else {
-                form_field_type_t field_type = form_get_field_type_by_tag(current->form, tag);
+                form_field_type_t field_type = form_get_field_type(current->form, tag);
                 gboolean valid = FALSE;
                 switch (field_type) {
                 case FIELD_TEXT_SINGLE:
                 case FIELD_TEXT_PRIVATE:
                 case FIELD_JID_SINGLE:
-                    form_set_value_by_tag(current->form, tag, value);
+                    form_set_value(current->form, tag, value);
                     ui_current_print_line("%s set to %s", tag, value);
                     break;
                 case FIELD_BOOLEAN:
                     if (g_strcmp0(value, "on") == 0) {
-                        form_set_value_by_tag(current->form, tag, "1");
+                        form_set_value(current->form, tag, "1");
                         ui_current_print_line("%s set to %s", tag, value);
                     } else if (g_strcmp0(value, "off") == 0) {
-                        form_set_value_by_tag(current->form, tag, "0");
+                        form_set_value(current->form, tag, "0");
                         ui_current_print_line("%s set to %s", tag, value);
                     } else {
                         ui_current_print_line("Value %s not valid for boolean field: %s", value, tag);
                     }
                     break;
                 case FIELD_LIST_SINGLE:
-                    valid = form_field_contains_option_by_tag(current->form, tag, value);
+                    valid = form_field_contains_option(current->form, tag, value);
                     if (valid == TRUE) {
-                        form_set_value_by_tag(current->form, tag, value);
+                        form_set_value(current->form, tag, value);
                         ui_current_print_line("%s set to %s", tag, value);
                     } else {
                         ui_current_print_line("Value %s not a valid option for field: %s", value, tag);
                     }
                     break;
                 default:
-                    ui_current_print_line("Set command not valid for field: %s", value, tag);
+                    ui_current_print_line("Set command not valid for field: %s", tag);
                     break;
                 }
             }
@@ -1977,7 +1977,27 @@ cmd_room(gchar **args, struct cmd_help_t help)
             if (!form_tag_exists(current->form, tag)) {
                 ui_current_print_line("Form does not contain a field with tag %s", tag);
             } else {
-                ui_current_print_line("Add Tag: %s, Value: %s", tag, value);
+                form_field_type_t field_type = form_get_field_type(current->form, tag);
+                gboolean valid = FALSE;
+                switch (field_type) {
+                case FIELD_LIST_MULTI:
+                    valid = form_field_contains_option(current->form, tag, value);
+                    if (valid == TRUE) {
+                        form_add_value(current->form, tag, value);
+                        ui_current_print_line("Added %s to %s", value, tag);
+                    } else {
+                        ui_current_print_line("Value %s not a valid option for field: %s", value, tag);
+                    }
+                    break;
+                case FIELD_TEXT_MULTI:
+                case FIELD_JID_MULTI:
+                    form_add_value(current->form, tag, value);
+                    ui_current_print_line("Added %s to %s", value, tag);
+                    break;
+                default:
+                    ui_current_print_line("Add command not valid for field: %s", tag);
+                    break;
+                }
             }
         }
 
diff --git a/src/ui/core.c b/src/ui/core.c
index 5c876b15..5a83c485 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -1942,7 +1942,7 @@ _ui_handle_form_field(ProfWin *window, FormField *field)
             }
         }
         break;
-    case FIELD_LIST_MUTLI:
+    case FIELD_LIST_MULTI:
         if (curr_value != NULL) {
             win_save_newline(window);
             GSList *options = field->options;
diff --git a/src/xmpp/form.c b/src/xmpp/form.c
index 65d6e431..b2192b61 100644
--- a/src/xmpp/form.c
+++ b/src/xmpp/form.c
@@ -162,7 +162,7 @@ _get_field_type(const char * const type)
         return FIELD_LIST_SINGLE;
     }
     if (g_strcmp0(type, "list-multi") == 0) {
-        return FIELD_LIST_MUTLI;
+        return FIELD_LIST_MULTI;
     }
     if (g_strcmp0(type, "jid-single") == 0) {
         return FIELD_JID_SINGLE;
@@ -300,7 +300,7 @@ form_create_submission(DataForm *form)
                 break;
 
             case FIELD_TEXT_MULTI:
-            case FIELD_LIST_MUTLI:
+            case FIELD_LIST_MULTI:
             case FIELD_JID_MULTI:
                 curr_value = field->values;
                 while (curr_value != NULL) {
@@ -403,7 +403,7 @@ _form_tag_exists(DataForm *form, const char * const tag)
 }
 
 static form_field_type_t
-_form_get_field_type_by_tag(DataForm *form, const char * const tag)
+_form_get_field_type(DataForm *form, const char * const tag)
 {
     char *var = g_hash_table_lookup(form->tag_to_var, tag);
     if (var != NULL) {
@@ -420,7 +420,7 @@ _form_get_field_type_by_tag(DataForm *form, const char * const tag)
 }
 
 static void
-_form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
+_form_set_value(DataForm *form, const char * const tag, char *value)
 {
     char *var = g_hash_table_lookup(form->tag_to_var, tag);
     if (var != NULL) {
@@ -441,8 +441,37 @@ _form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
     }
 }
 
+static void
+_form_add_value(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) {
+                gboolean already_set = FALSE;
+                GSList *curr_value = field->values;
+                while (curr_value != NULL) {
+                    if (g_strcmp0(curr_value->data, value) == 0) {
+                        already_set = TRUE;
+                        break;
+                    }
+                    curr_value = g_slist_next(curr_value);
+                }
+
+                if (!already_set) {
+                    field->values = g_slist_append(field->values, strdup(value));
+                }
+                return;
+            }
+            curr = g_slist_next(curr);
+        }
+    }
+}
+
 static gboolean
-_form_field_contains_option_by_tag(DataForm *form, const char * const tag, char *value)
+_form_field_contains_option(DataForm *form, const char * const tag, char *value)
 {
     char *var = g_hash_table_lookup(form->tag_to_var, tag);
     if (var != NULL) {
@@ -471,8 +500,9 @@ form_init_module(void)
 {
     form_destroy = _form_destroy;
     form_get_form_type_field = _form_get_form_type_field;
-    form_get_field_type_by_tag = _form_get_field_type_by_tag;
-    form_set_value_by_tag = _form_set_value_by_tag;
-    form_field_contains_option_by_tag = _form_field_contains_option_by_tag;
+    form_get_field_type = _form_get_field_type;
+    form_set_value = _form_set_value;
+    form_add_value = _form_add_value;
+    form_field_contains_option = _form_field_contains_option;
     form_tag_exists = _form_tag_exists;
 }
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 52d0037a..aa5d912f 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -94,7 +94,7 @@ typedef enum {
     FIELD_TEXT_MULTI,
     FIELD_BOOLEAN,
     FIELD_LIST_SINGLE,
-    FIELD_LIST_MUTLI,
+    FIELD_LIST_MULTI,
     FIELD_JID_SINGLE,
     FIELD_JID_MULTI,
     FIELD_FIXED,
@@ -208,9 +208,10 @@ void (*roster_send_remove)(const char * const barejid);
 
 void (*form_destroy)(DataForm *form);
 char * (*form_get_form_type_field)(DataForm *form);
-void (*form_set_value_by_tag)(DataForm *form, const char * const tag, char *value);
+void (*form_set_value)(DataForm *form, const char * const tag, char *value);
+void (*form_add_value)(DataForm *form, const char * const tag, char *value);
 gboolean (*form_tag_exists)(DataForm *form, const char * const tag);
-form_field_type_t (*form_get_field_type_by_tag)(DataForm *form, const char * const tag);
-gboolean (*form_field_contains_option_by_tag)(DataForm *form, const char * const tag, char *value);
+form_field_type_t (*form_get_field_type)(DataForm *form, const char * const tag);
+gboolean (*form_field_contains_option)(DataForm *form, const char * const tag, char *value);
 
 #endif