]> git.ozlabs.org Git - petitboot/commitdiff
Extend the "add url" function to allow file:// URLs
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 4 May 2016 05:06:45 +0000 (15:06 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 24 May 2016 01:08:15 +0000 (11:08 +1000)
This allows URLs of the form file:///path/to/local/file.conf to be used
in nc-add-url, in order to access configuration files relative
to the root directory. This is primarily a debugging tool aimed at
developers rather than an expected use case.

The DEVICE_TYPE_ANY enum is used in this case to represent that a
resulting boot option is not associated with any device in the
traditional sense, and in the UI is represented as a "Custom Local
Option".

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/device-handler.c
ui/ncurses/nc-menu.c

index 43b9541aba9187c2198593f88f85cd5699763b60..cc48747331dc6f3c6d161583499f5ca2d9ce5524 100644 (file)
@@ -1177,13 +1177,17 @@ void device_handler_process_url(struct device_handler *handler,
        }
 
        pb_url = pb_url_parse(event, event->params->value);
-       if (!pb_url || !pb_url->host) {
+       if (!pb_url || (pb_url->scheme != pb_url_file && !pb_url->host)) {
                status->message = talloc_asprintf(handler,
                                        _("Invalid config URL!"));
                goto msg;
        }
 
-       event->device = device_from_addr(event, pb_url);
+       if (pb_url->scheme == pb_url_file)
+               event->device = talloc_asprintf(event, "local");
+       else
+               event->device = device_from_addr(event, pb_url);
+
        if (!event->device) {
                status->message = talloc_asprintf(status,
                                        _("Unable to route to host %s"),
@@ -1192,6 +1196,8 @@ void device_handler_process_url(struct device_handler *handler,
        }
 
        dev = discover_device_create(handler, event->device);
+       if (pb_url->scheme == pb_url_file)
+               dev->device->type = DEVICE_TYPE_ANY;
        ctx = device_handler_discover_context_create(handler, dev);
        ctx->event = event;
 
index dda7626410974ec778089f8a24b9ed6f6857bc2d..723d3489f2a4a521175e3009aee696ebec8b8973 100644 (file)
@@ -285,6 +285,12 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
                                _("Network"), intf->name, hwaddr);
                }
                break;
+       case DEVICE_TYPE_ANY:
+               /* This is an option found from a file:// url, not associated
+                * with any device */
+               snprintf(buf, sizeof(buf), "[Custom Local Options]");
+               matched = true;
+               break;
 
        default:
                /* Assume the device may be able to boot */