+ if (load_url_async(conf, url, pxe_conf_parse_cb, conf,
+ NULL, NULL))
+ break;
+ }
+
+ return;
+}
+
+/*
+ * Callback for asynchronous loads from pxe_parse()
+ * @param result Result of load_url_async()
+ * @param data Pointer to associated conf_context
+ */
+static void pxe_conf_parse_cb(struct load_url_result *result, void *data)
+{
+ struct conf_context *conf = data;
+ struct device_handler *handler;
+ struct pxe_parser_info *info;
+ char *buf = NULL;
+ int len, rc = 0;
+
+ if (!data)
+ return;
+
+ handler = talloc_parent(conf);
+
+ if (result && result->status == LOAD_OK)
+ rc = read_file(conf, result->local, &buf, &len);
+ if (!result || result->status != LOAD_OK || rc) {
+ /* This load failed so try the next available filename */
+ info = conf->parser_info;
+ if (!info->pxe_conf_files) {
+ device_handler_status_dev_err(handler,
+ conf->dc->device,
+ _("Failed to download %s"),
+ pb_url_to_string(result->url));
+
+ return;
+ }
+
+ info->current++;
+ pxe_load_next_filename(conf);
+ if (info->pxe_conf_files[info->current] == NULL) {
+ /* Nothing left to try */
+ device_handler_status_dev_err(handler,
+ conf->dc->device,
+ _("PXE autoconfiguration failed"));
+ goto out_clean;
+ }
+ return;
+ }
+
+ /*
+ * Parse the first successfully downloaded file. We only want to parse
+ * the first because otherwise we could parse options from both a
+ * machine-specific config and a 'fallback' default config
+ */
+
+ conf_parse_buf(conf, buf, len);
+
+ /* We may be called well after the original caller of iterate_parsers(),
+ * commit any new boot options ourselves */
+ device_handler_discover_context_commit(handler, conf->dc);
+
+ /*
+ * TRANSLATORS: the format specifier in this string is a URL
+ * eg. tftp://192.168.1.1/pxelinux.cfg
+ */
+ device_handler_status_dev_info(handler, conf->dc->device,
+ _("Parsed PXE config from %s"),
+ pb_url_to_string(result->url));
+
+ talloc_free(buf);
+out_clean:
+ if (result->cleanup_local)
+ unlink(result->local);
+ talloc_free(conf);
+}
+
+/**
+ * Return a new conf_context and increment the talloc reference count on
+ * the discover_context struct.
+ * @param ctx Parent talloc context
+ * @param orig Original discover_context
+ * @return Pointer to new conf_context
+ */
+static struct conf_context *copy_context(void *ctx, struct discover_context *dc)
+{
+ struct pxe_parser_info *info;
+ struct conf_context *conf;
+
+ conf = talloc_zero(ctx, struct conf_context);