ui/ncurses: Validate URL field
[petitboot] / ui / ncurses / nc-widgets.c
index 15cec80f3594ae3600f2cecf891db28d4532901e..93c882b0849af43a00cbe417584e7edd375eb46b 100644 (file)
@@ -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);