Skip to content

Commit

Permalink
add schema version to connect message
Browse files Browse the repository at this point in the history
Signed-off-by: John Crispin <john@phrozen.org>
  • Loading branch information
blogic committed Mar 25, 2024
1 parent 2e88c13 commit 35c7881
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ADD_DEFINITIONS(-Os -std=gnu99 -g3 -Wmissing-declarations -Wno-unused-parameter)

SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

SET(SOURCES main.c config.c proto.c ubus.c task.c cmd.c apply.c upload.c rebootlog.c event.c collide.c)
SET(SOURCES main.c config.c proto.c ubus.c task.c cmd.c apply.c upload.c rebootlog.c event.c collide.c version.c)

FIND_LIBRARY(ubus NAMES ubus)
FIND_LIBRARY(blobmsg_json NAMES blobmsg_json)
Expand Down
1 change: 1 addition & 0 deletions proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ connect_send(void)

blobmsg_add_string(&proto, "serial", client.serial);
blobmsg_add_string(&proto, "firmware", client.firmware);
version_init(&proto);
if (client.recovery)
blobmsg_add_u64(&proto, "uuid", 0);
else
Expand Down
2 changes: 2 additions & 0 deletions ucentral.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ void password_notify(char *pwd);
void venue_broadcast_handle(struct blob_attr *rpc);
void venue_broadcast_send(struct blob_attr *payload);

void version_init(struct blob_buf *b);

static inline void safe_free(char **mem)
{
if (!*mem)
Expand Down
46 changes: 46 additions & 0 deletions version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#include "ucentral.h"

#define VERSION "/etc/ucentral/version.json"

static struct blob_buf version;
enum {
MAJOR,
MINOR,
PATCH,
__VERSION_MAX,
};

static const struct blobmsg_policy version_policy[_VERSION_MAX] = {
[MAJOR] = { .name = "major", .type = BLOBMSG_TYPE_INT32 },
[MINOR] = { .name = "minor", .type = BLOBMSG_TYPE_INT32 },
[PATCH] = { .name = "patch", .type = BLOBMSG_TYPE_INT32 },
};


void
version_init(struct blob_buf *b)
{
struct blob_attr *tb[__VERSION_MAX] = {};
struct stat s = {};

if (stat(VERSION, &s))
return;

blob_buf_init(&version, 0);
if (blobmsg_add_json_from_file(&version, VERSION)) {
void *c = blobmsg_open_table(&b, "version");
blobmsg_parse(version_policy, __VERSION_MAX, tb, blob_data(version.head),
blob_len(version.head));

if (tb[MAJOR])
blobmsg_add_u32(b, "major", blobmsg_get_u32(tb[MAJOR]);
if (tb[MINOR])
blobmsg_add_u32(b, "minor", blobmsg_get_u32(tb[MINOR]);
if (tb[PATCH])
blobmsg_add_u32(b, "patch", blobmsg_get_u32(tb[PATCH]);
blobmsg_close_table(b, c);
}
blob_buf_free(&version);
}

0 comments on commit 35c7881

Please sign in to comment.