diff options
author | James Booth <boothj5@gmail.com> | 2014-09-12 00:39:37 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-09-12 00:39:37 +0100 |
commit | 6c45f8ffae8adae7edc827f8f97f66e7355aff7a (patch) | |
tree | 9b86016392941ca0cfe992fd934b8db242ed29cc | |
parent | 38959e0c33f292a7824aeb64ddb6f5e2b2831206 (diff) | |
download | profani-tty-6c45f8ffae8adae7edc827f8f97f66e7355aff7a.tar.gz |
Check room config tag exists before setting
-rw-r--r-- | src/command/commands.c | 12 | ||||
-rw-r--r-- | src/xmpp/form.c | 15 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 1 |
3 files changed, 24 insertions, 4 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index 33b93dbb..d0e906d8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1901,19 +1901,23 @@ cmd_room(gchar **args, struct cmd_help_t help) if (args[1] != NULL) { tag = args[1]; } else { - cons_show("Usage: %s", help.usage); + ui_current_print_line("/room set command requires a field tag and value"); g_strfreev(split_recipient); return TRUE; } if (args[2] != NULL) { value = args[2]; } else { - cons_show("Usage: %s", help.usage); + ui_current_print_line("/room set command requires a field tag and value"); g_strfreev(split_recipient); return TRUE; } - form_set_value_by_tag(current->form, tag, value); - cons_show("Field set."); + if (!form_tag_exists(current->form, tag)) { + ui_current_print_line("Form does not contain a field with tag %s", tag); + } else { + form_set_value_by_tag(current->form, tag, value); + ui_current_print_line("%s set to %s", tag, value); + } } if ((g_strcmp0(args[0], "submit") == 0) || diff --git a/src/xmpp/form.c b/src/xmpp/form.c index c23ffa26..d3f588c7 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -382,6 +382,20 @@ _form_get_field_by_var(DataForm *form, const char * const var) return NULL; } +static gboolean +_form_tag_exists(DataForm *form, const char * const tag) +{ + GList *tags = g_hash_table_get_keys(form->tag_to_var); + GList *curr = tags; + while (curr != NULL) { + if (g_strcmp0(curr->data, tag) == 0) { + return TRUE; + } + curr = g_list_next(curr); + } + return FALSE; +} + static void _form_set_value_by_tag(DataForm *form, const char * const tag, char *value) { @@ -410,4 +424,5 @@ 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; + form_tag_exists = _form_tag_exists; } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 97a405ed..1637e87d 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -207,5 +207,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); +gboolean (*form_tag_exists)(DataForm *form, const char * const tag); #endif |