]> git.ozlabs.org Git - petitboot/blobdiff - discover/yaboot-parser.c
parsers: change parser.parse to accept a buffer
[petitboot] / discover / yaboot-parser.c
index 1000505b9681df66da2bfff4e17709d503c0175e..d7a0a9f80744ef9e533b705637b1b98f87a86b24 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "log/log.h"
 #include "talloc/talloc.h"
-#include "pb-protocol/pb-protocol.h"
+#include "types/types.h"
 #include "parser-conf.h"
 #include "parser-utils.h"
 #include "paths.h"
@@ -22,10 +22,10 @@ struct yaboot_state {
 static void yaboot_finish(struct conf_context *conf)
 {
        struct yaboot_state *state = conf->parser_info;
+       struct device *dev = conf->dc->device->device;
 
        if (!state->desc_image) {
-               pb_log("%s: %s: no image found\n", __func__,
-                       conf->dc->device->id);
+               pb_log("%s: %s: no image found\n", __func__, dev->id);
                return;
        }
 
@@ -46,8 +46,9 @@ static void yaboot_finish(struct conf_context *conf)
 
        /* opt is persistent, so must be associated with device */
 
-       device_add_boot_option(conf->dc->device, state->opt);
-       state->opt = talloc_zero(conf->dc->device, struct boot_option);
+       discover_context_add_boot_option(conf->dc, state->opt);
+
+       state->opt = talloc_zero(conf->dc, struct boot_option);
        state->opt->boot_args = talloc_strdup(state->opt, "");
 }
 
@@ -111,7 +112,7 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
                                "%s%s", g_boot, value);
                } else {
                        state->opt->boot_image_file = resolve_path(state->opt,
-                               value, conf->dc->device_path);
+                               value, conf->dc->device->device_path);
                        state->desc_image = talloc_strdup(state->opt, value);
                }
 
@@ -137,16 +138,16 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
 
                if (*value == '/') {
                        state->opt->boot_image_file = resolve_path(state->opt,
-                               value, conf->dc->device_path);
+                               value, conf->dc->device->device_path);
                        state->desc_image = talloc_strdup(state->opt, value);
                } else {
                        state->opt->boot_image_file = resolve_path(state->opt,
-                               suse_fp->image, conf->dc->device_path);
+                               suse_fp->image, conf->dc->device->device_path);
                        state->desc_image = talloc_strdup(state->opt,
                                suse_fp->image);
 
                        state->opt->initrd_file = resolve_path(state->opt,
-                               suse_fp->initrd, conf->dc->device_path);
+                               suse_fp->initrd, conf->dc->device->device_path);
                        state->desc_initrd = talloc_asprintf(state, "initrd=%s",
                                suse_fp->initrd);
                }
@@ -181,7 +182,7 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
                                "initrd=%s%s", g_boot, value);
                } else {
                        state->opt->initrd_file = resolve_path(state->opt,
-                               value, conf->dc->device_path);
+                               value, conf->dc->device->device_path);
                        state->desc_initrd = talloc_asprintf(state, "initrd=%s",
                                value);
                }
@@ -192,7 +193,7 @@ static void yaboot_process_pair(struct conf_context *conf, const char *name,
 
        if (streq(name, "label")) {
                state->opt->id = talloc_asprintf(state->opt, "%s#%s",
-                       conf->dc->device->id, value);
+                       conf->dc->device->device->id, value);
                state->opt->name = talloc_strdup(state->opt, value);
                return;
        }
@@ -286,21 +287,20 @@ static const char *yaboot_known_names[] = {
        NULL
 };
 
-static int yaboot_parse(struct discover_context *dc)
+static int yaboot_parse(struct discover_context *dc, char *buf, int len)
 {
        struct conf_context *conf;
        struct yaboot_state *state;
-       int rc;
 
        conf = talloc_zero(dc, struct conf_context);
 
        if (!conf)
-               return -1;
+               return 0;
 
        conf->dc = dc;
        conf->global_options = yaboot_global_options,
        conf_init_global_options(conf);
-       conf->conf_files = yaboot_conf_files,
+       conf->get_pair = conf_get_pair_equal;
        conf->process_pair = yaboot_process_pair;
        conf->finish = yaboot_finish;
        conf->parser_info = state = talloc_zero(conf, struct yaboot_state);
@@ -312,10 +312,14 @@ static int yaboot_parse(struct discover_context *dc)
        state->opt = talloc_zero(conf->dc->device, struct boot_option);
        state->opt->boot_args = talloc_strdup(state->opt, "");
 
-       rc = conf_parse(conf);
+       conf_parse_buf(conf, buf, len);
 
        talloc_free(conf);
-       return rc;
+       return 1;
 }
 
-define_parser(yaboot, 99, yaboot_parse);
+struct parser __yaboot_parser = {
+       .name           = "yaboot",
+       .parse          = yaboot_parse,
+       .filenames      = yaboot_conf_files,
+};