[PATCH] Extend the "add url" function to allow file:// URLs

Samuel Mendoza-Jonas sam at mendozajonas.com
Wed May 4 15:16:45 AEST 2016


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 at mendozajonas.com>
---
 discover/device-handler.c | 10 ++++++++--
 ui/ncurses/nc-menu.c      |  6 ++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/discover/device-handler.c b/discover/device-handler.c
index 43b9541..cc48747 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -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;
 
diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
index dda7626..723d348 100644
--- a/ui/ncurses/nc-menu.c
+++ b/ui/ncurses/nc-menu.c
@@ -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 */
-- 
2.8.2



More information about the Petitboot mailing list