From ceefe00bf8c1498dfc2118d2b3666f67f91bb956 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 6 Mar 2013 17:08:05 +0800 Subject: [PATCH] discover: parse boot message from incoming ACTION_BOOT messages 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 --- discover/discover-server.c | 10 +++++++++- lib/pb-protocol/pb-protocol.c | 31 +++++++++++++++++++++++++++++++ lib/pb-protocol/pb-protocol.h | 3 +++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/discover/discover-server.c b/discover/discover-server.c index 7633134..76d03d1 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -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; } diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index 4e0af87..31637c6 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -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; +} diff --git a/lib/pb-protocol/pb-protocol.h b/lib/pb-protocol/pb-protocol.h index 2ec264c..6068f05 100644 --- a/lib/pb-protocol/pb-protocol.h +++ b/lib/pb-protocol/pb-protocol.h @@ -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 */ -- 2.39.2