mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Check room config tag exists before setting
This commit is contained in:
parent
38959e0c33
commit
6c45f8ffae
@ -1901,19 +1901,23 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
if (args[1] != NULL) {
|
if (args[1] != NULL) {
|
||||||
tag = args[1];
|
tag = args[1];
|
||||||
} else {
|
} else {
|
||||||
cons_show("Usage: %s", help.usage);
|
ui_current_print_line("/room set command requires a field tag and value");
|
||||||
g_strfreev(split_recipient);
|
g_strfreev(split_recipient);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (args[2] != NULL) {
|
if (args[2] != NULL) {
|
||||||
value = args[2];
|
value = args[2];
|
||||||
} else {
|
} else {
|
||||||
cons_show("Usage: %s", help.usage);
|
ui_current_print_line("/room set command requires a field tag and value");
|
||||||
g_strfreev(split_recipient);
|
g_strfreev(split_recipient);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
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);
|
form_set_value_by_tag(current->form, tag, value);
|
||||||
cons_show("Field set.");
|
ui_current_print_line("%s set to %s", tag, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((g_strcmp0(args[0], "submit") == 0) ||
|
if ((g_strcmp0(args[0], "submit") == 0) ||
|
||||||
|
@ -382,6 +382,20 @@ _form_get_field_by_var(DataForm *form, const char * const var)
|
|||||||
return NULL;
|
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
|
static void
|
||||||
_form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
|
_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_destroy = _form_destroy;
|
||||||
form_get_field_by_var = _form_get_field_by_var;
|
form_get_field_by_var = _form_get_field_by_var;
|
||||||
form_set_value_by_tag = _form_set_value_by_tag;
|
form_set_value_by_tag = _form_set_value_by_tag;
|
||||||
|
form_tag_exists = _form_tag_exists;
|
||||||
}
|
}
|
||||||
|
@ -207,5 +207,6 @@ void (*roster_send_remove)(const char * const barejid);
|
|||||||
void (*form_destroy)(DataForm *form);
|
void (*form_destroy)(DataForm *form);
|
||||||
char * (*form_get_field_by_var)(DataForm *form, const char * const var);
|
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);
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user