]> git.ozlabs.org Git - petitboot/blob - discover/pxe-parser.c
discover/pxe-parser: All options are name <space> value pairs
[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 (!name)
25                 return;
26
27         if (streq(name, "LABEL")) {
28                 if (opt)
29                         pxe_finish(ctx);
30
31                 opt = discover_boot_option_create(ctx->dc, ctx->dc->device);
32                 ctx->parser_info = opt;
33
34                 opt->option->name = talloc_strdup(opt, value);
35                 opt->option->id = talloc_asprintf(opt, "%s@%p",
36                                 ctx->dc->device->device->id, opt);
37                 return;
38         }
39
40         /* all other parameters need an option */
41         if (!opt)
42                 return;
43
44         if (streq(name, "KERNEL")) {
45                 url = pb_url_join(ctx->dc, ctx->dc->conf_url, value);
46                 opt->boot_image = create_url_resource(opt, url);
47
48         } else if (streq(name, "APPEND")) {
49                 opt->option->boot_args = talloc_strdup(opt->option, value);
50                 /* todo: initrd extraction */
51         }
52 }
53
54 static int pxe_parse(struct discover_context *dc, char *buf, int len)
55 {
56         struct conf_context *conf;
57
58         conf = talloc_zero(dc, struct conf_context);
59
60         if (!conf)
61                 return 0;
62
63         conf->dc = dc;
64         conf->get_pair = conf_get_pair_space;
65         conf->process_pair = pxe_process_pair;
66         conf->finish = pxe_finish;
67
68         conf_parse_buf(conf, buf, len);
69
70         talloc_free(conf);
71         return 1;
72 }
73
74 static struct parser pxe_parser = {
75         .name                   = "pxe",
76         .parse                  = pxe_parse,
77         .method                 = CONF_METHOD_DHCP,
78 };
79
80 register_parser(pxe_parser);