Commit graph

22 commits

Author SHA1 Message Date
Petr Štetiar
c42f11cc7c jshn: main: fix leak of memory pointed to by 'vars'
Fixes following leak of memory:

 6,016 bytes in 1 blocks are possibly lost in loss record 1 of 1
    at 0x4C31B25: calloc
    by 0x1098F8: main (jshn.c:353)

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-11-24 13:26:58 +01:00
Petr Štetiar
93848ec96d jshn: refactor main into smaller pieces
Turn longer switch cases into separate functions in order to make it
easier to follow. Don't return from the cases as it makes future
cleaning up harder.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-11-24 13:26:58 +01:00
Roman Yeryomin
eb30a03048 libubox, jshn: add option to write output to a file
This would allow board_config_flush to run one command instead
of two and would be faster and safer than redirecting output
and moving a file between filesystems.

Originally discussed here:
http://lists.openwrt.org/pipermail/openwrt-devel/2017-December/010127.html

Signed-off-by: Roman Yeryomin <roman@advem.lv>
2019-10-21 14:21:41 +02:00
Felix Fietkau
42a8ecd858 jshn: fix format string for int64 type
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2018-04-07 10:36:38 +02:00
Christian Beier
9c4aeda962 jshn: add functionality to read big JSON
The existing read functionality feeds the complete JSON to jshn as a
cmdline argument, leading to `-ash: jshn: Argument list too long`
errors for JSONs bigger than ca. 100KB.

This commit adds the ability to read the JSON directly from a file if
wanted, removing this shell-imposed size limit.

Tested on x86-64 and ar71xx. An mmap()-based solution was also evaluated,
but found to make no performance difference on either platform.

Signed-off-by: Christian Beier <dontmind@freeshell.org>
2018-01-22 09:21:03 +01:00
Jo-Philipp Wich
1c08e80313 jshn: properly support JSON "null" type
Instead of abort parsing, properly deal with "null" values by implementing
support for reading and formatting such values.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2018-01-07 15:52:24 +01:00
Christian Beier
729f47fd52 jshn: read and write 64-bit integers
This allows for reading in and writing out bigger JSON Numbers.

Following test script (that fails to print correct values _without_ this
commit) verifies the functionality (tested on x86-64 as well as on ar71xx):

---snip---
# assumes you built jshn and sourced jshn.sh
echo testing reading-in JSON
SHELL_BIGNUM=12147483647
json_init
json_load "{ \"bignum\": $SHELL_BIGNUM }"
json_get_var BIGNUM bignum
echo jshn bignum: $BIGNUM
echo shll bignum: $SHELL_BIGNUM
echo testing writing-out JSON
json_init
json_add_int bigint $SHELL_BIGNUM
json_dump
--snap---

Signed-off-by: Christian Beier <dontmind@freeshell.org>
2017-11-06 10:05:42 +01:00
Matthias Schiffer
1f019ceea1 Fix various memory management issues
Consistently handle allocation failures. Some functions are changed to
return bool or int instead of void to allow returning an error.

Also fix a buffer size miscalculation in lua/uloop and use _exit() instead
of exit() on errors after forking.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
2016-06-26 12:53:51 +02:00
Felix Fietkau
dfe446e2a9 jshn: use an avl tree for env variables to speed up processing of bigger json files
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2016-03-05 18:51:31 +01:00
Yousong Zhou
8c6dadbe03 jshn: add error handling and fix memory leak in jshn_format().
Though currently jshn is more a one-shot data transformation tool and
won't leak much memory in its lifetime, people may use it as example
code, so do it right.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:58:42 +01:00
Felix Fietkau
0bfb44f590 jshn: shorten JSON_VAR to J_V
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 20:59:49 +01:00
Felix Fietkau
d59fa8d588 jshn: shorten variable names to speed up processing
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 20:02:51 +01:00
Felix Fietkau
c8fc0897cd avoid using the deprecated is_error() function from json-c
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-23 12:02:31 +02:00
John Crispin
dffbc09baf jshn: pretty print indented output with jshn -i -w
Signed-off-by: John Crispin <blogic@openwrt.org>
2014-08-04 20:01:16 +02:00
Felix Fietkau
00a833c5b6 jshn: add support for the double datatype
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-03-17 00:50:03 +01:00
Thomas Gstädtner
49e6e062b8 add pkgconfig support for json-c
this includes a fallback for legacy support
2013-03-05 10:44:48 +01:00
Felix Fietkau
0ab17bcb3a jshn: add copyright info
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-13 09:45:59 +01:00
Felix Fietkau
e16fa068a5 jshn: add support for namespaces
Can be used to fix variable namespace clashes in library code using jshn

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-16 17:46:08 +01:00
Felix Fietkau
a1a97eb11e jshn: support using characters in elements that do not conform to shell variable restrictions 2011-09-11 11:40:22 +02:00
Felix Fietkau
f1a44355bd change the include path for list.h in jshn.c 2011-08-12 11:12:50 -06:00
Felix Fietkau
bdf6363777 jshn: add an option for printing the json data without a terminating newline 2011-05-31 15:41:19 +02:00
Felix Fietkau
fda6079b30 add jshn 2011-05-23 22:21:27 +02:00