diff mbox series

[OpenWrt-Devel] Subject: [PATCH 1/1] blobmsg_json: allow to add full json files

Message ID DM5PR17MB09230F70AD09E8304B20C222DBEE0@DM5PR17MB0923.namprd17.prod.outlook.com
State Changes Requested
Delegated to: Petr Štetiar
Headers show
Series [OpenWrt-Devel] Subject: [PATCH 1/1] blobmsg_json: allow to add full json files | expand

Commit Message

Adrian Panella Feb. 22, 2020, 8:11 p.m. UTC
Current function "blobmsg_add_json_from_file" only adds json file if it
is an object,  and it only returns the properties, not a full object
attribute.
This version allows to read any valid json file and returns the complete
corresponding attribute.

Signed-off-by: Adrian Panella <ianchi74@outlook.com>
---
 blobmsg_json.c | 16 ++++++++++++++++
 blobmsg_json.h |  1 +
 2 files changed, 17 insertions(+)

Comments

Petr Štetiar June 3, 2020, 10:03 a.m. UTC | #1
Hi,

next time please do:

 $ git format-patch -s1 --subject-prefix "PATCH libubox" ...

as described in https://openwrt.org/submitting-patches

Adrian Panella <ianchi74@outlook.com> [2020-02-22 20:11:28]:

> Current function "blobmsg_add_json_from_file" only adds json file if it is
> an object,  and it only returns the properties, not a full object attribute.
> This version allows to read any valid json file and returns the complete
> corresponding attribute.

...

>  }
>  

whitespace issue

> +bool blobmsg_add_json_file(struct blob_buf *b,  const char *name, const char *file)
> +{
> +	struct json_object *obj;
> +	bool ret;
> +	

whitespace issue

Apart from this whitespace nitpicks which I could fix by myself as well, I
would like to ask you for adding test case under tests directory for this new
function, so we can later assure on CI, that there are no memleaks or other
issues in this code and spot any regression later as well.

Please note, that test cases are not mandatory, but it is going to help merge
your valuable contribution faster :-) Thanks!

-- ynezz
Adrian Panella June 3, 2020, 11:38 p.m. UTC | #2
Hi,

Is there any documentation on the testing infrastructure being used, and what kind of unit test are expected.
I couldn't find any guide on the wiki, and I'm more familiarized with the Node JS based workflows, and if there is some guide it will be faster than going thru the code.
If you point me in the right direction I can add the corresponding tests.

Adrián

-----Original Message-----
From: Petr Štetiar <ynezz@true.cz> 
Sent: miércoles, 3 de junio de 2020 05:03 a. m.
To: Adrian Panella <ianchi74@outlook.com>
Cc: openwrt-devel@lists.openwrt.org
Subject: Re: [OpenWrt-Devel] Subject: [PATCH 1/1] blobmsg_json: allow to add full json files

Hi,

next time please do:

 $ git format-patch -s1 --subject-prefix "PATCH libubox" ...

as described in https://openwrt.org/submitting-patches

Adrian Panella <ianchi74@outlook.com> [2020-02-22 20:11:28]:

> Current function "blobmsg_add_json_from_file" only adds json file if 
> it is an object,  and it only returns the properties, not a full object attribute.
> This version allows to read any valid json file and returns the 
> complete corresponding attribute.

...

>  }
>  

whitespace issue

> +bool blobmsg_add_json_file(struct blob_buf *b,  const char *name, 
> +const char *file) {
> +	struct json_object *obj;
> +	bool ret;
> +	

whitespace issue

Apart from this whitespace nitpicks which I could fix by myself as well, I would like to ask you for adding test case under tests directory for this new function, so we can later assure on CI, that there are no memleaks or other issues in this code and spot any regression later as well.

Please note, that test cases are not mandatory, but it is going to help merge your valuable contribution faster :-) Thanks!

-- ynezz
diff mbox series

Patch

diff --git a/blobmsg_json.c b/blobmsg_json.c
index dce81e9..b8f91f1 100644
--- a/blobmsg_json.c
+++ b/blobmsg_json.c
@@ -87,6 +87,22 @@  bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object
 	return ret;
 }
 
+bool blobmsg_add_json_file(struct blob_buf *b,  const char *name, const char *file)
+{
+	struct json_object *obj;
+	bool ret;
+	
+	obj = json_object_from_file(file);
+
+	if (!obj)
+		return false;
+
+	ret = blobmsg_add_json_element(b, name, obj);
+
+	json_object_put(obj);
+	return ret;
+}
+
 static bool __blobmsg_add_json(struct blob_buf *b, json_object *obj)
 {
 	bool ret = false;
diff --git a/blobmsg_json.h b/blobmsg_json.h
index 9dfc02d..61cdbe5 100644
--- a/blobmsg_json.h
+++ b/blobmsg_json.h
@@ -23,6 +23,7 @@  struct json_object;
 
 bool blobmsg_add_object(struct blob_buf *b, struct json_object *obj);
 bool blobmsg_add_json_element(struct blob_buf *b, const char *name, struct json_object *obj);
+bool blobmsg_add_json_file(struct blob_buf *b,  const char *name, const char *file);
 bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str);
 bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file);