discover: Reimplement native-parser as a Bison parser
[petitboot] / discover / native / native.c
1 #include <assert.h>
2 #include <string.h>
3 #include <i18n/i18n.h>
4
5 #include <talloc/talloc.h>
6 #include <url/url.h>
7
8 #include <discover/resource.h>
9 #include <discover/parser.h>
10 #include <discover/parser-utils.h>
11
12 #include "native.h"
13
14 static const char *const native_conf_files[] = {
15         "/boot/petitboot.conf",
16         "/petitboot.conf",
17         NULL
18 };
19
20 static int native_parse(struct discover_context *dc)
21 {
22         const char * const *filename;
23         struct native_parser *parser;
24         int len, rc;
25         char *buf;
26
27         /* Support block device boot only at present */
28         if (dc->event)
29                 return -1;
30
31         for (filename = native_conf_files; *filename; filename++) {
32                 rc = parser_request_file(dc, dc->device, *filename, &buf, &len);
33                 if (rc)
34                         continue;
35
36                 parser = native_parser_create(dc);
37                 native_parser_parse(parser, *filename, buf, len);
38                 device_handler_status_dev_info(dc->handler, dc->device,
39                                 _("Parsed native configuration from %s"),
40                                 *filename);
41                 talloc_free(buf);
42                 talloc_free(parser);
43                 break;
44         }
45
46         return 0;
47 }
48
49 static struct parser native_parser = {
50         .name                   = "native",
51         .parse                  = native_parse,
52         .resolve_resource       = resolve_devpath_resource,
53 };
54
55 register_parser(native_parser);