1
0
mirror of https://git.kore.io/kore.git synced 2024-11-11 04:39:00 +01:00
Commit Graph

24 Commits

Author SHA1 Message Date
Joris Vink
833ca646e7 i forgot, it's 2022. 2022-01-31 22:02:06 +01:00
Joris Vink
cc276e2471 Add kore_json_item_attach().
Allows a JSON subtree to be engrafted after creation.

from Joel Arbring via patches@
2021-04-08 09:10:58 +02:00
Joris Vink
9cfcd9a4be JSON API improvements.
- Try harder to mark integers as KORE_JSON_TYPE_INTEGER, especially if
  they fit in the internal representation of one (int64_t).

- Move error codes into the JSON code itself, rather then requiring
  a kore_json data structure. This allows the JSON API to relay errors
  such as "item not found" or "type mismatch" properly when looking at items.

- When asking for a KORE_JSON_TYPE_INTEGER_U64 and a KORE_JSON_TYPE_INTEGER
  was found with the same name, check if it could be returned properly and do
  so if possible.
2021-03-30 14:19:48 +02:00
Joris Vink
cef5ac4003 bump copyright year. 2021-01-11 23:46:08 +01:00
Joris Vink
fd2cda5a43 include inttypes.h in json.c 2020-11-27 16:34:38 +01:00
Joris Vink
5421b7726e kore_json_init() should take a const void for the data. 2020-11-23 10:48:04 +01:00
Joris Vink
802a78c0b0 Make sure we check if consume whitespace failed. 2020-11-21 13:01:42 +01:00
Joris Vink
d7fbce37f5 Better parsing of JSON integers and numbers.
Add 2 new types:
	KORE_JSON_TYPE_INTEGER
		signed integer type, internally stored as s64.

	KORE_JSON_TYPE_INTEGER_U64
		unsigned integer type, internally stored as u64.

Kore JSON parser will prefer marking integers as INTEGER_U64 if it
was unsigned and did not have fractions.
2020-11-19 14:56:17 +01:00
Joris Vink
760dff8b3c allow tab escape in JSON strings. 2020-11-19 09:55:41 +01:00
Joris Vink
e712e3a951 consume any initial whitespace in JSON data. 2020-11-19 09:22:16 +01:00
Joris Vink
8008fe8b60 Don't allow unknown escaped characters in JSON parser. 2020-11-19 09:10:12 +01:00
Joris Vink
8c32f8f63b Small improvements to JSON parser.
- Don't allow garbage at the end of the JSON data (except whitespace).
- Don't allow objects such as {"a":"b",} or [a,]
2020-11-19 09:07:42 +01:00
Joris Vink
f6af4a27f4 Enable type-limits warning.
Remove unneeded comparison in the JSON code.
via https://marc.info/?l=openbsd-ports&m=159958572325174&w=2
2020-09-08 19:29:15 +02:00
Joris Vink
8097d22da7 whitespace fixes 2020-08-24 10:17:53 +02:00
Joris Vink
40dddbc769 whitespace 2020-04-27 09:07:37 +02:00
Joris Vink
6ba56bb8f6 adjust copyright years 2020-02-10 15:35:41 +01:00
Joris Vink
9d0aef0079 bump copyright 2020-02-10 14:47:33 +01:00
Joris Vink
283cd6da54 allow NULL pointers to cleanup/free calls. 2019-11-19 09:44:13 +01:00
Joris Vink
699ba3c0fe Make sure json offset advanced upon end of object/array. 2019-10-30 10:02:51 +01:00
Joris Vink
5f03f991c9 Change kore_json_find() to operate on a kore_json_item.
This way you can call the lookup function on any JSON value that you
previously obtained (or the JSON context root).
2019-10-25 12:27:16 +02:00
Joris Vink
890eb78fd8 Improve our new JSON api a bit.
Allow JSON to be constructed via kore_json_create_item and its
handy macro family:
	- kore_json_create_object()
	- kore_json_create_array()
	- kore_json_create_string()
	- kore_json_create_number()
	- kore_json_create_literal().

Adds kore_json_item_tobuf() to convert a JSON item into a string
representation in a kore_buf data structure.

Renames the kore_json_get* family to kore_json_find* instead.

Allows for quite clean code:

	struct kore_buf		buf;
	struct kore_json_item	*root;

	root = kore_json_create_object(NULL, NULL);
	kore_json_create_string(root, "hello", "world");
	kore_json_create_number(root, "value", 2.241);

	kore_buf_init(&buf, 128);
	kore_json_item_tobuf(root, &buf);

	kore_json_item_free(root);
	kore_buf_cleanup(&buf);
2019-10-22 23:56:47 +02:00
Joris Vink
22ebfae240 missing kore_free() 2019-10-20 23:55:08 +02:00
Joris Vink
88330a5fcd missing kore_free() 2019-10-20 23:42:37 +02:00
Joris Vink
e94cc2f3a8 Yikes, add the actual JSON parser code.. 2019-10-20 23:30:10 +02:00