]> git.ozlabs.org Git - petitboot/blob - discover/parser.h
ui/ncurses: Add nc-subset selection screen
[petitboot] / discover / parser.h
1 #ifndef _PARSER_H
2 #define _PARSER_H
3
4 #include <stdbool.h>
5
6 #include "device-handler.h"
7
8 struct discover_context;
9 struct device_handler;
10 struct resource;
11
12 /**
13  * Our config parser.
14  *
15  * Each parser is responsible for creating discover_boot_options from config
16  * files found on new devices. The boot items discovered during parse will have
17  * 'resources' attached (see @discover_boot_option), which may already be
18  * resolved (in the case of a device-local filename, or a URL), or unresolved
19  * (in the case of a filename on another device).
20  *
21  * If the boot option contains references to unresolved resources, the
22  * device handler will not inform clients about the boot options, as
23  * they're not properly "available" at this stage. The handler will attempt to
24  * resolve them whenever new devices are discovered, by calling the parser's
25  * resolve_resource function. Once a boot option's resources are full resolved,
26  * the option can be sent to clients.
27  */
28 struct parser {
29         char                    *name;
30         int                     (*parse)(struct discover_context *ctx);
31         bool                    (*resolve_resource)(
32                                                 struct device_handler *handler,
33                                                 struct resource *res);
34 };
35
36 enum generic_icon_type {
37         ICON_TYPE_DISK,
38         ICON_TYPE_USB,
39         ICON_TYPE_OPTICAL,
40         ICON_TYPE_NETWORK,
41         ICON_TYPE_UNKNOWN
42 };
43
44 #define streq(a,b) (!strcasecmp((a),(b)))
45
46 void parser_init(void);
47
48 void iterate_parsers(struct discover_context *ctx);
49 int parse_user_event(struct discover_context *ctx, struct event *event);
50
51 /* File IO functions for parsers; these should be the only interface that
52  * parsers use to access a device's filesystem.
53  *
54  * These are intended for small amounts of data, typically text configuration
55  * and state files.
56  */
57 int parser_request_file(struct discover_context *ctx,
58                 struct discover_device *dev, const char *filename,
59                 char **buf, int *len);
60 int parser_replace_file(struct discover_context *ctx,
61                 struct discover_device *dev, const char *filename,
62                 char *buf, int len);
63 int parser_request_url(struct discover_context *ctx, struct pb_url *url,
64                 char **buf, int *len);
65 int parser_check_dir(struct discover_context *ctx,
66                 struct discover_device *dev, const char *dirname);
67
68 #endif /* _PARSER_H */