discover: parse boot message from incoming ACTION_BOOT messages
authorJeremy Kerr <jk@ozlabs.org>
Wed, 6 Mar 2013 09:08:05 +0000 (17:08 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 15 Apr 2013 07:42:27 +0000 (15:42 +0800)
Add a function in the protocol code to deserialise a boot message, and
use it to extract a boot_command in the discover server.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/discover-server.c
lib/pb-protocol/pb-protocol.c
lib/pb-protocol/pb-protocol.h

index 7633134c2ea639b1ac410564465f8c2a9ca2dfee..76d03d1c10159924a3a73cf096d57827dd9ca31b 100644 (file)
@@ -130,6 +130,7 @@ static int write_remove_message(struct discover_server *server,
 static int discover_server_process_message(void *arg)
 {
        struct pb_protocol_message *message;
+       struct boot_command *boot_command;
        struct client *client = arg;
 
        message = pb_protocol_read_message(client, client->fd);
@@ -142,7 +143,14 @@ static int discover_server_process_message(void *arg)
                return 0;
        }
 
-       /* todo: process boot message */
+       boot_command = pb_protocol_deserialise_boot_command(client, message);
+       if (!boot_command) {
+               pb_log("%s: no boot command?", __func__);
+               return 0;
+       }
+
+       /* todo: pass boot_command to client->server->device_handler */
+
        return 0;
 }
 
index 4e0af873b710ad8d72707c9fa60190076197e865..31637c611c19993a390bd6e1fe86ff917a96ba58 100644 (file)
@@ -404,3 +404,34 @@ out_err:
        talloc_free(dev);
        return NULL;
 }
+
+struct boot_command *pb_protocol_deserialise_boot_command(void *ctx,
+               const struct pb_protocol_message *message)
+{
+       struct boot_command *cmd;
+       const char *pos;
+       unsigned int len;
+
+       len = message->payload_len;
+       pos = message->payload;
+
+       cmd = talloc(ctx, struct boot_command);
+
+       if (read_string(cmd, &pos, &len, &cmd->option_id))
+               goto out_err;
+
+       if (read_string(cmd, &pos, &len, &cmd->boot_image_file))
+               goto out_err;
+
+       if (read_string(cmd, &pos, &len, &cmd->initrd_file))
+               goto out_err;
+
+       if (read_string(cmd, &pos, &len, &cmd->boot_args))
+               goto out_err;
+
+       return cmd;
+
+out_err:
+       talloc_free(cmd);
+       return NULL;
+}
index 2ec264cce26a045ef68582ab5815449cca7a5f05..6068f05ca7b5ae495d0dc1a50d9ef4e9c6f533a9 100644 (file)
@@ -50,4 +50,7 @@ struct pb_protocol_message *pb_protocol_read_message(void *ctx, int fd);
 struct device *pb_protocol_deserialise_device(void *ctx,
                const struct pb_protocol_message *message);
 
+struct boot_command *pb_protocol_deserialise_boot_command(void *ctx,
+               const struct pb_protocol_message *message);
+
 #endif /* _PB_PROTOCOL_H */