- list_init(&dev->boot_options);
-
- for (i = 0; i < n_options; i++) {
- struct boot_option *opt;
-
- opt = talloc(dev, struct boot_option);
-
- if (read_string(opt, &pos, &len, &opt->id))
- goto out_err;
- if (read_string(opt, &pos, &len, &opt->name))
- goto out_err;
- if (read_string(opt, &pos, &len,
- &opt->description))
- goto out_err;
- if (read_string(opt, &pos, &len,
- &opt->icon_file))
- goto out_err;
- if (read_string(opt, &pos, &len,
- &opt->boot_image_file))
- goto out_err;
- if (read_string(opt, &pos, &len,
- &opt->initrd_file))
- goto out_err;
- if (read_string(opt, &pos, &len,
- &opt->boot_args))
- goto out_err;
-
- list_add(&dev->boot_options, &opt->list);
+ rc = 0;
+
+out:
+ return rc;
+}
+
+int pb_protocol_deserialise_system_info(struct system_info *sysinfo,
+ const struct pb_protocol_message *message)
+{
+ unsigned int len, i;
+ const char *pos;
+ int rc = -1;
+
+ len = message->payload_len;
+ pos = message->payload;
+
+ /* type and identifier strings */
+ if (read_string(sysinfo, &pos, &len, &sysinfo->type))
+ goto out;
+
+ if (read_string(sysinfo, &pos, &len, &sysinfo->identifier))
+ goto out;
+
+ /* number of interfaces */
+ if (read_u32(&pos, &len, &sysinfo->n_interfaces))
+ goto out;
+
+ sysinfo->interfaces = talloc_array(sysinfo, struct interface_info *,
+ sysinfo->n_interfaces);
+
+ for (i = 0; i < sysinfo->n_interfaces; i++) {
+ struct interface_info *if_info = talloc(sysinfo,
+ struct interface_info);
+
+ if (read_u32(&pos, &len, &if_info->hwaddr_size))
+ goto out;
+
+ if (len < if_info->hwaddr_size)
+ goto out;
+
+ if_info->hwaddr = talloc_memdup(if_info, pos,
+ if_info->hwaddr_size);
+ pos += if_info->hwaddr_size;
+ len -= if_info->hwaddr_size;
+
+ if (read_string(if_info, &pos, &len, &if_info->name))
+ goto out;
+
+ if_info->link = *(bool *)pos;
+ pos += sizeof(if_info->link);
+
+ sysinfo->interfaces[i] = if_info;
+ }
+
+ /* number of interfaces */
+ if (read_u32(&pos, &len, &sysinfo->n_blockdevs))
+ goto out;
+
+ sysinfo->blockdevs = talloc_array(sysinfo, struct blockdev_info *,
+ sysinfo->n_blockdevs);
+
+ for (i = 0; i < sysinfo->n_blockdevs; i++) {
+ struct blockdev_info *bd_info = talloc(sysinfo,
+ struct blockdev_info);
+
+ if (read_string(bd_info, &pos, &len, &bd_info->name))
+ goto out;
+
+ if (read_string(bd_info, &pos, &len, &bd_info->uuid))
+ goto out;
+
+ if (read_string(bd_info, &pos, &len, &bd_info->mountpoint))
+ goto out;
+
+ sysinfo->blockdevs[i] = bd_info;
+ }
+ rc = 0;
+
+out:
+ return rc;
+}
+
+static int pb_protocol_deserialise_config_interface(const char **buf,
+ unsigned int *len, struct interface_config *iface)
+{
+ unsigned int tmp;
+
+ if (*len < sizeof(iface->hwaddr))
+ return -1;
+
+ memcpy(iface->hwaddr, *buf, sizeof(iface->hwaddr));
+ *buf += sizeof(iface->hwaddr);
+ *len -= sizeof(iface->hwaddr);
+
+ if (read_u32(buf, len, &tmp))
+ return -1;
+ iface->ignore = !!tmp;
+
+ if (iface->ignore)
+ return 0;
+
+ if (read_u32(buf, len, &iface->method))
+ return -1;
+
+ if (iface->method == CONFIG_METHOD_STATIC) {
+ if (read_string(iface, buf, len, &iface->static_config.address))
+ return -1;
+
+ if (read_string(iface, buf, len, &iface->static_config.gateway))
+ return -1;
+ }
+
+ return 0;
+}
+
+int pb_protocol_deserialise_config(struct config *config,
+ 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_u32(&pos, &len, &tmp))
+ goto out;
+ config->autoboot_enabled = !!tmp;
+
+ if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
+ goto out;
+
+ if (read_u32(&pos, &len, &tmp))
+ goto out;
+ config->safe_mode = !!tmp;
+
+ if (read_u32(&pos, &len, &config->network.n_interfaces))
+ goto out;
+
+ config->network.interfaces = talloc_array(config,
+ struct interface_config *, config->network.n_interfaces);
+
+ for (i = 0; i < config->network.n_interfaces; i++) {
+ struct interface_config *iface = talloc_zero(
+ config->network.interfaces,
+ struct interface_config);
+ if (pb_protocol_deserialise_config_interface(&pos, &len, iface))
+ goto out;
+ config->network.interfaces[i] = iface;
+ }
+
+ if (read_u32(&pos, &len, &config->network.n_dns_servers))
+ goto out;
+ config->network.dns_servers = talloc_array(config, const char *,
+ config->network.n_dns_servers);
+
+ for (i = 0; i < config->network.n_dns_servers; i++) {
+ if (read_string(config->network.dns_servers, &pos, &len, &str))
+ goto out;
+ config->network.dns_servers[i] = str;