discover: log unresolved boot options
[petitboot] / discover / pxe-parser.c
1
2 #include <string.h>
3
4 #include <talloc/talloc.h>
5 #include <url/url.h>
6
7 #include "parser.h"
8 #include "parser-conf.h"
9 #include "parser-utils.h"
10 #include "resource.h"
11
12 static void pxe_finish(struct conf_context *conf)
13 {
14         printf("%s\n", __func__);
15         discover_context_add_boot_option(conf->dc, conf->parser_info);
16 }
17
18 static void pxe_process_pair(struct conf_context *ctx,
19                 const char *name, char *value)
20 {
21         struct discover_boot_option *opt = ctx->parser_info;
22         struct pb_url *url;
23
24         if (streq(name, "LABEL")) {
25                 if (opt)
26                         pxe_finish(ctx);
27
28                 opt = discover_boot_option_create(ctx->dc, ctx->dc->device);
29                 ctx->parser_info = opt;
30
31                 opt->option->device_id = ctx->dc->device->device->id;
32                 opt->option->name = talloc_strdup(opt, value);
33                 opt->option->id = talloc_asprintf(opt, "%s@%p",
34                                 opt->option->device_id, opt);
35                 return;
36         }
37
38         /* all other parameters need an option */
39         if (!opt)
40                 return;
41
42         if (streq(name, "KERNEL")) {
43                 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
44                 opt->boot_image = create_url_resource(opt, url);
45
46         } else if (streq(name, "APPEND")) {
47                 opt->option->boot_args = talloc_strdup(opt->option, value);
48                 /* todo: initrd extraction */
49         }
50 }
51
52 static int pxe_parse(struct discover_context *dc, char *buf, int len)
53 {
54         struct conf_context *conf;
55
56         conf = talloc_zero(dc, struct conf_context);
57
58         if (!conf)
59                 return 0;
60
61         conf->dc = dc;
62         conf->get_pair = conf_get_pair_space;
63         conf->process_pair = pxe_process_pair;
64         conf->finish = pxe_finish;
65
66         conf_parse_buf(conf, buf, len);
67
68         talloc_free(conf);
69         return 1;
70 }
71
72 static struct parser pxe_parser = {
73         .name                   = "pxe",
74         .parse                  = pxe_parse,
75         .method                 = CONF_METHOD_DHCP,
76 };
77
78 register_parser(pxe_parser);