diff mbox series

Added update description field support.

Message ID 1522161615-4794-1-git-send-email-afaustas@gmail.com
State Accepted
Headers show
Series Added update description field support. | expand

Commit Message

Faustas Azuolas Bagdonas March 27, 2018, 2:40 p.m. UTC
Signed-off-by: Faustas Azuolas Bagdonas <afaustas@gmail.com>
---
 doc/source/sw-description.rst |  4 ++++
 include/globals.h             |  1 +
 include/swupdate.h            |  1 +
 parser/parser.c               | 30 ++++++++++++++++++++++++------
 4 files changed, 30 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst
index 4498431..2944d3d 100644
--- a/doc/source/sw-description.rst
+++ b/doc/source/sw-description.rst
@@ -27,6 +27,7 @@  The following example explains better the implemented tags:
 	software =
 	{
 		version = "0.1.0";
+		description = "Firmware update for XXXXX Project";
 
 		hardware-compatibility: [ "1.0", "1.2", "1.3"];
 
@@ -898,6 +899,9 @@  There are 4 main sections inside sw-description:
    |             |          |            | compared with the entries in          |
    |             |          |            | sw-versions                           |
    +-------------+----------+------------+---------------------------------------+
+   | description | string   |            | user-friendly description of the      |
+   |             |          |            | swupdate archive (any string)         |
+   +-------------+----------+------------+---------------------------------------+
    | install-if  | bool     | images     | flag                                  |
    | different   |          | files      | if set, name and version are          |
    |             |          |            | compared with the entries in          |
diff --git a/include/globals.h b/include/globals.h
index 91f6c29..f797f4f 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -11,6 +11,7 @@ 
 #define BANNER "Swupdate v" SWU_VER "\n"
 
 #define SWUPDATE_GENERAL_STRING_SIZE	256
+#define SWUPDATE_UPDATE_DESCRIPTION_STRING_SIZE	512
 #define MAX_IMAGE_FNAME	SWUPDATE_GENERAL_STRING_SIZE
 #define MAX_URL		SWUPDATE_GENERAL_STRING_SIZE
 #define MAX_VOLNAME	SWUPDATE_GENERAL_STRING_SIZE
diff --git a/include/swupdate.h b/include/swupdate.h
index 6f0170d..6f57fab 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -113,6 +113,7 @@  struct swupdate_global_cfg {
 
 struct swupdate_cfg {
 	char name[SWUPDATE_GENERAL_STRING_SIZE];
+	char description[SWUPDATE_UPDATE_DESCRIPTION_STRING_SIZE];
 	char version[SWUPDATE_GENERAL_STRING_SIZE];
 	char software_set[SWUPDATE_GENERAL_STRING_SIZE];
 	char running_mode[SWUPDATE_GENERAL_STRING_SIZE];
diff --git a/parser/parser.c b/parser/parser.c
index 9b92480..1afb476 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -678,6 +678,7 @@  int parse_cfg (struct swupdate_cfg *swcfg, const char *filename)
 	char node[128];
 	parsertype p = LIBCFG_PARSER;
 	int ret;
+	config_setting_t *setting;
 
 	memset(&cfg, 0, sizeof(cfg));
 	config_init(&cfg);
@@ -695,16 +696,19 @@  int parse_cfg (struct swupdate_cfg *swcfg, const char *filename)
 		return -1;
 	}
 
-	snprintf(node, sizeof(node), "%s.version",
-			NODEROOT);
-
-	if (!config_lookup_string(&cfg, node, &str)) {
+	if((setting = find_node(p, &cfg, "version", swcfg)) == NULL) {
 		ERROR("Missing version in configuration file\n");
 		return -1;
 	} else {
-		strncpy(swcfg->version, str, sizeof(swcfg->version));
+		GET_FIELD_STRING(p, setting, NULL, swcfg->version);
 		TRACE("Version %s", swcfg->version);
 	}
+
+	if((setting = find_node(p, &cfg, "description", swcfg)) != NULL) {
+		GET_FIELD_STRING(p, setting, NULL, swcfg->description);
+		TRACE("Description %s", swcfg->description);
+	}
+
 	snprintf(node, sizeof(node), "%s.embedded-script",
 			NODEROOT);
 	if (config_lookup_string(&cfg, node, &str)) {
@@ -732,7 +736,7 @@  int parse_json(struct swupdate_cfg *swcfg, const char *filename)
 	struct stat stbuf;
 	unsigned int size;
 	char *string;
-	json_object *cfg;
+	json_object *cfg, *setting;
 	parsertype p = JSON_PARSER;
 
 	/* Read the file. If there is an error, report it and exit. */
@@ -762,6 +766,20 @@  int parse_json(struct swupdate_cfg *swcfg, const char *filename)
 		return -1;
 	}
 
+	if((setting = find_node(p, cfg, "version", swcfg)) == NULL) {
+		ERROR("Missing version in configuration file\n");
+		free(string);
+		return -1;
+	} else {
+		GET_FIELD_STRING(p, setting, NULL, swcfg->version);
+		TRACE("Version %s", swcfg->version);
+	}
+
+	if((setting = find_node(p, cfg, "description", swcfg)) != NULL) {
+		GET_FIELD_STRING(p, setting, NULL, swcfg->description);
+		TRACE("Description %s", swcfg->description);
+	}
+
 	ret = parser(p, cfg, swcfg);
 
 	json_object_put(cfg);