+ return conf;
+}
+
+static int pxe_parse(struct discover_context *dc)
+{
+ struct pb_url *pxe_base_url, *file_url;
+ struct conf_context *conf = NULL;
+ struct load_url_result *result;
+ void *ctx = talloc_parent(dc);
+ struct pxe_parser_info *info;
+ char **pxe_conf_files;
+ bool complete_url;
+
+ /* Expects dhcp event parameters to support network boot */
+ if (!dc->event)
+ return -1;
+
+ dc->conf_url = user_event_parse_conf_url(dc, dc->event, &complete_url);
+ if (!dc->conf_url)
+ return -1;
+
+ /*
+ * Retrieving PXE configs over the network can take some time depending
+ * on factors such as slow network, malformed paths, bad DNS, and
+ * overzealous firewalls. Instead of blocking the discover server while
+ * we wait for these, spawn an asynchronous job that will attempt to
+ * retrieve each possible URL until it successfully finds one, and
+ * parse and process the resulting file in a callback.
+ */
+ conf = copy_context(ctx, dc);
+ if (!conf)
+ return -1;
+
+ if (complete_url) {
+ /* Check if this file has already been downloaded */
+ if (event_get_param(dc->event, "pxeconffile-local"))
+ file_url = pb_url_parse(dc, event_get_param(dc->event,
+ "pxeconffile-local"));
+ else
+ file_url = dc->conf_url;
+
+ if (!file_url) {
+ pb_log("%s: Failed to parse conf url!\n", __func__);
+ goto out_conf;
+ }
+
+ device_handler_status_dev_info(conf->dc->handler,
+ dc->device,
+ _("Requesting config %s"),
+ pb_url_to_string(conf->dc->conf_url));
+
+ /* we have a complete URL; use this and we're done. */
+ result = load_url_async(conf->dc, file_url,
+ pxe_conf_parse_cb, conf, NULL, ctx);
+ if (!result) {
+ pb_log("load_url_async fails for %s\n",
+ dc->conf_url->path);
+ goto out_conf;
+ } else if (result->status == LOAD_OK) {
+ /* Local load - call pxe_conf_parse_cb() now */
+ pxe_conf_parse_cb(result, conf);
+ }
+ } else {
+ pxe_conf_files = user_event_parse_conf_filenames(dc, dc->event);
+ if (!pxe_conf_files)
+ goto out_conf;
+
+ pxe_base_url = pb_url_join(dc, dc->conf_url, pxelinux_prefix);
+ if (!pxe_base_url)
+ goto out_pxe_conf;
+
+ info = conf->parser_info;
+ info->pxe_conf_files = pxe_conf_files;
+ info->pxe_base_url = pxe_base_url;
+
+ device_handler_status_dev_info(conf->dc->handler,
+ conf->dc->device,
+ _("Probing from base %s"),
+ pb_url_to_string(pxe_base_url));
+
+ pxe_load_next_filename(conf);
+ }
+
+ return 0;