X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fevent-parser.c;h=240f8976249c13decf3b720f740d2580560553c0;hp=c09c5babc27a1e44d642c31f523688b55b652ff4;hb=4c223e2bce76adb831708fb557b826d731ae75ed;hpb=12a5c9153ce95ddde7fb14eaba9d779933a3637c diff --git a/discover/event-parser.c b/discover/event-parser.c index c09c5ba..240f897 100644 --- a/discover/event-parser.c +++ b/discover/event-parser.c @@ -4,8 +4,36 @@ #include "log/log.h" #include "talloc/talloc.h" +#include "url/url.h" + +#include "resource.h" #include "event.h" #include "parser-utils.h" +#include "device-handler.h" + +static struct resource *user_event_resource(struct discover_boot_option *opt, + struct event *event, const char *param_name) +{ + struct resource *res; + struct pb_url *url; + const char *val; + + val = event_get_param(event, param_name); + if (!val) + return NULL; + + url = pb_url_parse(opt, val); + if (!url) + return NULL; + + res = create_url_resource(opt, url); + if (!res) { + talloc_free(url); + return NULL; + } + + return res; +} /** * parse_user_event - Parse a user event. @@ -13,14 +41,19 @@ * Understands params: name, image, args. */ -struct boot_option *parse_user_event(struct device *device, struct event *event) +int parse_user_event(struct discover_context *ctx, struct event *event) { + struct discover_boot_option *d_opt; struct boot_option *opt; + struct device *dev; const char *p; - opt = talloc_zero(device, struct boot_option); + dev = ctx->device->device; + + d_opt = discover_boot_option_create(ctx, ctx->device); + opt = d_opt->option; - if (!opt) + if (!d_opt) goto fail; p = event_get_param(event, "name"); @@ -30,33 +63,31 @@ struct boot_option *parse_user_event(struct device *device, struct event *event) goto fail; } - opt->id = talloc_asprintf(opt, "%s#%s", device->id, p); - opt->device_id = talloc_strdup(opt, device->id); + opt->id = talloc_asprintf(opt, "%s#%s", dev->id, p); opt->name = talloc_strdup(opt, p); - p = event_get_param(event, "image"); - assert(p); - - if (!p) { - pb_log("%s: no image found\n", __func__); + d_opt->boot_image = user_event_resource(d_opt, event, "image"); + if (!d_opt->boot_image) { + pb_log("%s: no boot image found for %s!\n", __func__, + opt->name); goto fail; } - opt->boot_image_file = talloc_strdup(opt, p); + d_opt->initrd = user_event_resource(d_opt, event, "initrd"); p = event_get_param(event, "args"); - assert(p); - opt->boot_args = talloc_strdup(opt, p); + if (p) + opt->boot_args = talloc_strdup(opt, p); opt->description = talloc_asprintf(opt, "%s %s", opt->boot_image_file, - opt->boot_args); + opt->boot_args ? : ""); - device_add_boot_option(device, opt); + discover_context_add_boot_option(ctx, d_opt); - return opt; + return 0; fail: - talloc_free(opt); - return NULL; + talloc_free(d_opt); + return -1; }