summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-widgets.c
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-02-26 15:58:10 +1100
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-02-27 11:43:37 +1100
commitfb8dbd274b4b2c4df52d09d2fe303ccdacdf546b (patch)
tree2c9f045c242ea2ee4c043423861f82ba424bbf1b /ui/ncurses/nc-widgets.c
parent7e0b9da2ae2f96d24c711c0ad4d12bb193ec49c0 (diff)
downloadtalos-petitboot-fb8dbd274b4b2c4df52d09d2fe303ccdacdf546b.tar.gz
talos-petitboot-fb8dbd274b4b2c4df52d09d2fe303ccdacdf546b.zip
ui/ncurses: Validate URL fieldv1.7.0
Make sure the URL field is a valid URL before allowing the user to proceed. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'ui/ncurses/nc-widgets.c')
-rw-r--r--ui/ncurses/nc-widgets.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ui/ncurses/nc-widgets.c b/ui/ncurses/nc-widgets.c
index 15cec80..93c882b 100644
--- a/ui/ncurses/nc-widgets.c
+++ b/ui/ncurses/nc-widgets.c
@@ -53,6 +53,7 @@
#include <util/util.h>
#include <i18n/i18n.h>
#include <fold/fold.h>
+#include <url/url.h>
#include "nc-cui.h"
#include "nc-widgets.h"
@@ -83,6 +84,7 @@ struct nc_widgetset {
/* custom validators */
FIELDTYPE *ipv4_multi_type;
+ FIELDTYPE *url_type;
};
struct nc_widget {
@@ -399,6 +401,20 @@ void widget_textbox_set_validator_integer(struct nc_widget_textbox *textbox,
set_field_type(textbox->widget.field, TYPE_INTEGER, 1, min, max);
}
+static bool check_url_field(FIELD *field,
+ const void *arg __attribute__((unused)))
+{
+ return is_url(field_buffer(field, 0));
+}
+
+void widget_textbox_set_validator_url(struct nc_widget_textbox *textbox)
+{
+ if (!textbox->set->url_type)
+ textbox->set->url_type = new_fieldtype(check_url_field, NULL);
+
+ set_field_type(textbox->widget.field, textbox->set->url_type);
+}
+
void widget_textbox_set_validator_ipv4(struct nc_widget_textbox *textbox)
{
set_field_type(textbox->widget.field, TYPE_IPV4);
OpenPOWER on IntegriCloud