7 #include "types/types.h"
9 #include <talloc/talloc.h>
11 #include "device-handler.h"
13 #include "parser-utils.h"
18 struct list_item list;
19 struct parser *parser;
24 static char *local_path(struct discover_context *ctx,
27 return join_paths(ctx, ctx->device->mount_path, filename);
30 static int download_config(struct discover_context *ctx, char **buf, int *len)
36 file = load_url(ctx, ctx->conf_url, &tempfile);
40 rc = read_file(ctx, file, buf, len);
52 static void iterate_parser_files(struct discover_context *ctx,
53 const struct parser *parser)
55 const char * const *filename;
58 if (!parser->filenames)
61 for (filename = parser->filenames; *filename; filename++) {
65 path = local_path(ctx, *filename);
69 rc = read_file(ctx, path, &buf, &len);
71 pb_log("Running parser %s on file %s\n",
72 parser->name, *filename);
73 parser->parse(ctx, buf, len);
79 void iterate_parsers(struct discover_context *ctx, enum conf_method method)
85 pb_log("trying parsers for %s\n", ctx->device->device->id);
88 case CONF_METHOD_LOCAL_FILE:
89 list_for_each_entry(&parsers, i, list) {
90 if (i->parser->method != CONF_METHOD_LOCAL_FILE)
93 pb_log("\ttrying parser '%s'\n", i->parser->name);
94 ctx->parser = i->parser;
95 iterate_parser_files(ctx, ctx->parser);
100 case CONF_METHOD_DHCP:
101 rc = download_config(ctx, &buf, &len);
103 pb_log("\tdownload failed, aborting\n");
107 list_for_each_entry(&parsers, i, list) {
108 if (i->parser->method != method)
111 pb_log("\ttrying parser '%s'\n", i->parser->name);
112 ctx->parser = i->parser;
113 i->parser->parse(ctx, buf, len);
118 case CONF_METHOD_UNKNOWN:
124 void __register_parser(struct parser *parser)
126 struct p_item* i = talloc(NULL, struct p_item);
129 list_add(&parsers, &i->list);
132 void parser_init(void)