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