]> git.ozlabs.org Git - petitboot/blobdiff - discover/parser.c
discover: Add configuration methods
[petitboot] / discover / parser.c
index 1f3674d3ee461cc24fac0f9ca5a8fc11d765fb1c..c04a0afca610b31bfb07468824770445cfc94d92 100644 (file)
 #include "parser-utils.h"
 #include "paths.h"
 
-struct parser __grub2_parser;
-struct parser __kboot_parser;
-struct parser __native_parser;
-struct parser __yaboot_parser;
-
-static const struct parser *const parsers[] = {
-//     &__native_parser,
-       &__kboot_parser,
-       &__grub2_parser,
-       &__yaboot_parser,
-       NULL
-};
+static int n_parsers;
+static struct parser **parsers;
 
 static const int max_file_size = 1024 * 1024;
 
@@ -77,12 +67,17 @@ err_close:
        return -1;
 }
 
+static char *local_path(struct discover_context *ctx,
+               const char *filename)
+{
+       return join_paths(ctx, ctx->device->mount_path, filename);
+}
+
 static void iterate_parser_files(struct discover_context *ctx,
                const struct parser *parser)
 {
        const char * const *filename;
-       const char *path, *url;
-       unsigned int tempfile;
+       const char *path;
 
        if (!parser->filenames)
                return;
@@ -91,12 +86,7 @@ static void iterate_parser_files(struct discover_context *ctx,
                int rc, len;
                char *buf;
 
-               url = resolve_path(ctx, *filename, ctx->device->device_path);
-               if (!url)
-                       continue;
-
-               path = load_file(ctx, url, &tempfile);
-
+               path = local_path(ctx, *filename);
                if (!path)
                        continue;
 
@@ -105,26 +95,35 @@ static void iterate_parser_files(struct discover_context *ctx,
                        parser->parse(ctx, buf, len);
                        talloc_free(buf);
                }
-
-               if (tempfile)
-                       unlink(path);
-
        }
-
 }
 
-void iterate_parsers(struct discover_context *ctx)
+void iterate_parsers(struct discover_context *ctx, enum conf_method method)
 {
        int i;
 
        pb_log("trying parsers for %s\n", ctx->device->device->id);
 
-       for (i = 0; parsers[i]; i++) {
-               pb_log("\ttrying parser '%s'\n", parsers[i]->name);
-               iterate_parser_files(ctx, parsers[i]);
+       if (method == CONF_METHOD_LOCAL_FILE) {
+               for (i = 0; i < n_parsers; i++) {
+                       if (parsers[i]->method != CONF_METHOD_LOCAL_FILE)
+                               continue;
+
+                       pb_log("\ttrying parser '%s'\n", parsers[i]->name);
+                       ctx->parser = parsers[i];
+                       iterate_parser_files(ctx, ctx->parser);
+               }
+               ctx->parser = NULL;
        }
 }
 
+void __register_parser(struct parser *parser)
+{
+       parsers = talloc_realloc(NULL, parsers, struct parser *, n_parsers + 1);
+       parsers[n_parsers] = parser;
+       n_parsers++;
+}
+
 void parser_init(void)
 {
 }