]> git.ozlabs.org Git - petitboot/commitdiff
lib: Add plugin_option type and protocol
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 14 Feb 2017 04:56:55 +0000 (15:56 +1100)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 15 Aug 2017 01:40:09 +0000 (11:40 +1000)
Add a new struct 'plugin_option' to represent pb-plugins that are
installed on the system. This consists of plugin metadata and an array
of installed executables.
This also adds two new pb-protocol actions to advertise the addition of
a new plugin_option, and to remove known plugin_options.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
lib/pb-protocol/pb-protocol.c
lib/pb-protocol/pb-protocol.h
lib/types/types.h

index 18edf57e24ca341e88a21fa2e06891685c297c0a..ed61fe149b1bbac074dae847cb7d359a3417d3cd 100644 (file)
@@ -340,6 +340,26 @@ int pb_protocol_url_len(const char *url)
        return 4 + optional_strlen(url);
 }
 
        return 4 + optional_strlen(url);
 }
 
+
+int pb_protocol_plugin_option_len(const struct plugin_option *opt)
+{
+       unsigned int i, len = 0;
+
+       len += 4 + optional_strlen(opt->id);
+       len += 4 + optional_strlen(opt->name);
+       len += 4 + optional_strlen(opt->vendor);
+       len += 4 + optional_strlen(opt->vendor_id);
+       len += 4 + optional_strlen(opt->version);
+       len += 4 + optional_strlen(opt->date);
+       len += 4 + optional_strlen(opt->plugin_file);
+
+       len += 4; /* n_executables */
+       for (i = 0; i < opt->n_executables; i++)
+               len += 4 + optional_strlen(opt->executables[i]);
+
+       return len;
+}
+
 int pb_protocol_serialise_device(const struct device *dev,
                char *buf, int buf_len)
 {
 int pb_protocol_serialise_device(const struct device *dev,
                char *buf, int buf_len)
 {
@@ -611,6 +631,32 @@ int pb_protocol_serialise_url(const char *url, char *buf, int buf_len)
        return 0;
 }
 
        return 0;
 }
 
+int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
+               char *buf, int buf_len)
+{
+       char *pos = buf;
+       unsigned int i;
+
+       pos += pb_protocol_serialise_string(pos, opt->id);
+       pos += pb_protocol_serialise_string(pos, opt->name);
+       pos += pb_protocol_serialise_string(pos, opt->vendor);
+       pos += pb_protocol_serialise_string(pos, opt->vendor_id);
+       pos += pb_protocol_serialise_string(pos, opt->version);
+       pos += pb_protocol_serialise_string(pos, opt->date);
+       pos += pb_protocol_serialise_string(pos, opt->plugin_file);
+
+       *(uint32_t *)pos = __cpu_to_be32(opt->n_executables);
+       pos += 4;
+
+       for (i = 0; i < opt->n_executables; i++)
+               pos += pb_protocol_serialise_string(pos, opt->executables[i]);
+
+       assert(pos <= buf + buf_len);
+       (void)buf_len;
+
+       return 0;
+}
+
 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
 {
        int total_len, rc;
 int pb_protocol_write_message(int fd, struct pb_protocol_message *message)
 {
        int total_len, rc;
@@ -1150,3 +1196,61 @@ int pb_protocol_deserialise_config(struct config *config,
 out:
        return rc;
 }
 out:
        return rc;
 }
+
+int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
+               const struct pb_protocol_message *message)
+{
+       unsigned int len, i, tmp;
+       const char *pos;
+       int rc = -1;
+       char *str;
+
+       len = message->payload_len;
+       pos = message->payload;
+
+       if (read_string(opt, &pos, &len, &str))
+               goto out;
+       opt->id = str;
+
+       if (read_string(opt, &pos, &len, &str))
+               goto out;
+       opt->name = str;
+
+       if (read_string(opt, &pos, &len, &str))
+               goto out;
+       opt->vendor = str;
+
+       if (read_string(opt, &pos, &len, &str))
+               goto out;
+       opt->vendor_id = str;
+
+       if (read_string(opt, &pos, &len, &str))
+               goto out;
+       opt->version = str;
+
+       if (read_string(opt, &pos, &len, &str))
+               goto out;
+       opt->date = str;
+
+       if (read_string(opt, &pos, &len, &str))
+               goto out;
+       opt->plugin_file = str;
+
+       if (read_u32(&pos, &len, &tmp))
+               goto out;
+       opt->n_executables = tmp;
+
+       opt->executables = talloc_zero_array(opt, char *, opt->n_executables);
+       if (!opt->executables)
+               goto out;
+
+       for (i = 0; i < opt->n_executables; i++) {
+               if (read_string(opt, &pos, &len, &str))
+                       goto out;
+               opt->executables[i] = talloc_strdup(opt, str);
+       }
+
+       rc = 0;
+out:
+       return rc;
+}
index a8cd20686ca563d5ea512f9c48d30d00984eed50..ce876d01786e2315b9cf474ffb9b74417fc4b5b4 100644 (file)
@@ -23,6 +23,8 @@ enum pb_protocol_action {
        PB_PROTOCOL_ACTION_CONFIG               = 0x9,
        PB_PROTOCOL_ACTION_REINIT               = 0xa,
        PB_PROTOCOL_ACTION_ADD_URL              = 0xb,
        PB_PROTOCOL_ACTION_CONFIG               = 0x9,
        PB_PROTOCOL_ACTION_REINIT               = 0xa,
        PB_PROTOCOL_ACTION_ADD_URL              = 0xb,
+       PB_PROTOCOL_ACTION_PLUGIN_OPTION_ADD    = 0xc,
+       PB_PROTOCOL_ACTION_PLUGINS_REMOVE       = 0xd,
 };
 
 struct pb_protocol_message {
 };
 
 struct pb_protocol_message {
@@ -40,6 +42,7 @@ int pb_protocol_boot_status_len(const struct status *status);
 int pb_protocol_system_info_len(const struct system_info *sysinfo);
 int pb_protocol_config_len(const struct config *config);
 int pb_protocol_url_len(const char *url);
 int pb_protocol_system_info_len(const struct system_info *sysinfo);
 int pb_protocol_config_len(const struct config *config);
 int pb_protocol_url_len(const char *url);
+int pb_protocol_plugin_option_len(const struct plugin_option *opt);
 int pb_protocol_device_cmp(const struct device *a, const struct device *b);
 
 int pb_protocol_boot_option_cmp(const struct boot_option *a,
 int pb_protocol_device_cmp(const struct device *a, const struct device *b);
 
 int pb_protocol_boot_option_cmp(const struct boot_option *a,
@@ -62,6 +65,8 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo,
 int pb_protocol_serialise_config(const struct config *config,
                char *buf, int buf_len);
 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len);
 int pb_protocol_serialise_config(const struct config *config,
                char *buf, int buf_len);
 int pb_protocol_serialise_url(const char *url, char *buf, int buf_len);
+int pb_protocol_serialise_plugin_option(const struct plugin_option *opt,
+               char *buf, int buf_len);
 
 int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
 
 
 int pb_protocol_write_message(int fd, struct pb_protocol_message *message);
 
@@ -87,4 +92,7 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
 
 int pb_protocol_deserialise_config(struct config *config,
                const struct pb_protocol_message *message);
 
 int pb_protocol_deserialise_config(struct config *config,
                const struct pb_protocol_message *message);
+
+int pb_protocol_deserialise_plugin_option(struct plugin_option *opt,
+               const struct pb_protocol_message *message);
 #endif /* _PB_PROTOCOL_H */
 #endif /* _PB_PROTOCOL_H */
index 7f4ae1fced1fa182055398d838dd441258680323..36841cd20b50fed4345579a78b9e25a09b685339 100644 (file)
@@ -60,6 +60,21 @@ struct boot_option {
        void            *ui_info;
 };
 
        void            *ui_info;
 };
 
+struct plugin_option {
+       char            *id;
+       char            *name;
+       char            *vendor;
+       char            *vendor_id;
+       char            *version;
+       char            *date;
+       char            *plugin_file;
+
+       unsigned int    n_executables;
+       char            **executables;
+
+       void            *ui_info;
+};
+
 struct boot_command {
        char *option_id;
        char *boot_image_file;
 struct boot_command {
        char *option_id;
        char *boot_image_file;