about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-13 22:39:06 +0100
committerJames Booth <boothj5@gmail.com>2014-09-13 22:39:06 +0100
commitb111419693c5f6ac790a9723d75f33dad09a0b64 (patch)
tree042916c349ad27a9f281dfb7f1be38edd11137d6 /src/xmpp
parentc4b4cb557fa97a1dcafe6894e9d6cfb059d37548 (diff)
downloadprofani-tty-b111419693c5f6ac790a9723d75f33dad09a0b64.tar.gz
Added form type check on set
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/form.c22
-rw-r--r--src/xmpp/xmpp.h1
2 files changed, 21 insertions, 2 deletions
diff --git a/src/xmpp/form.c b/src/xmpp/form.c
index b07e51ef..df3f2dd2 100644
--- a/src/xmpp/form.c
+++ b/src/xmpp/form.c
@@ -277,6 +277,8 @@ form_create_submission(DataForm *form)
         GSList *curr_value = NULL;
 
         switch (field->type_t) {
+            case FIELD_HIDDEN:
+            case FIELD_FIXED:
             case FIELD_TEXT_SINGLE:
             case FIELD_TEXT_PRIVATE:
             case FIELD_BOOLEAN:
@@ -319,8 +321,6 @@ form_create_submission(DataForm *form)
                     curr_value = g_slist_next(curr_value);
                 }
                 break;
-            case FIELD_HIDDEN:
-            case FIELD_FIXED:
             default:
                 break;
         }
@@ -402,6 +402,23 @@ _form_tag_exists(DataForm *form, const char * const tag)
     return FALSE;
 }
 
+static form_field_type_t
+_form_get_field_type_by_tag(DataForm *form, const char * const tag)
+{
+    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) {
+                return field->type_t;
+            }
+            curr = g_slist_next(curr);
+        }
+    }
+    return FIELD_UNKNOWN;
+}
+
 static void
 _form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
 {
@@ -429,6 +446,7 @@ 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_tag_exists = _form_tag_exists;
 }
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 75a67285..cf78bb45 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -210,5 +210,6 @@ 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);
 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);
 
 #endif