diff mbox series

[RFC,v1,2/4] tools: add swupdate-gethawkbitstatus

Message ID 20210924092411.10768-3-roland.gaudig-oss@weidmueller.com
State Changes Requested
Headers show
Series suricatta: ipc: add request to get hawkbit server status | expand

Commit Message

Roland Gaudig Sept. 24, 2021, 9:24 a.m. UTC
From: Roland Gaudig <roland.gaudig@weidmueller.com>

Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
---

 tools/Makefile                    |  1 +
 tools/swupdate-gethawkbitstatus.c | 45 +++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 tools/swupdate-gethawkbitstatus.c
diff mbox series

Patch

diff --git a/tools/Makefile b/tools/Makefile
index 013022b..8c495c9 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -10,6 +10,7 @@ 
 
 lib-y += \
 	 swupdate-client.o \
+	 swupdate-gethawkbitstatus.o \
 	 swupdate-progress.o \
 	 swupdate-hawkbitcfg.o \
 	 swupdate-sendtohawkbit.o \
diff --git a/tools/swupdate-gethawkbitstatus.c b/tools/swupdate-gethawkbitstatus.c
new file mode 100644
index 0000000..fb08617
--- /dev/null
+++ b/tools/swupdate-gethawkbitstatus.c
@@ -0,0 +1,45 @@ 
+/*
+ * Copyright (C) 2021 Weidmueller Interface GmbH & Co. KG
+ * Roland Gaudig <roland.gaudig@weidmueller.com>
+ *
+ * SPDX-License-Identifier:     GPL-2.0-only
+ */
+
+/*
+ * This is a small example how to retrieve the hawkBit server status
+ * from surricata.
+ */
+
+#include <stdio.h>
+#include <json-c/json.h>
+
+#include <network_ipc.h>
+
+int main(int argc, char *argv[])
+{
+	ipc_message msg;
+	struct json_object *parsed_json;
+	struct json_object *server;
+	struct json_object *status;
+	struct json_object *time;
+
+	msg.type = SWUPDATE_SUBPROCESS;
+	msg.data.procmsg.source = SOURCE_SURICATTA;
+	msg.data.procmsg.cmd = CMD_GET_STATUS;
+
+	msg.data.procmsg.buf[0] = '\0';
+	msg.data.procmsg.len = 0;
+
+	int result = ipc_send_cmd(&msg);
+
+	printf("%s\n", msg.data.procmsg.buf);  // TODO remove this line
+
+	parsed_json = json_tokener_parse(msg.data.procmsg.buf);
+	json_object_object_get_ex(parsed_json, "server", &server);
+	json_object_object_get_ex(server, "status", &status);
+	json_object_object_get_ex(server, "time", &time);
+
+	printf("status: %d, time: %d\n",
+	       json_object_get_int(status),
+	       json_object_get_int(time));
+}