wip json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
diff --git a/.gitignore b/.gitignore
index 71441d0..027d744 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,7 +44,10 @@ kc3s/kc3s_cov
kc3s/kc3s_debug
*.la
lib/kc3/0.1/ekc3.so
+lib/kc3/0.1/event.so
lib/kc3/0.1/http.so
+lib/kc3/0.1/json.so
+lib/kc3/0.1/socket.so
.libs/
*.lo
macos/kc3-v*
diff --git a/Makefile b/Makefile
index b2e4a1c..78b1198 100644
--- a/Makefile
+++ b/Makefile
@@ -321,8 +321,17 @@ gdb_test_json:
${MAKE} -C ucd2c
${MAKE} -C libkc3 debug
${MAKE} -C ikc3 debug
+ ${MAKE} -C json debug
${MAKE} -C test gdb_test_json
+gdb_test_json_asan:
+ ${MAKE} -C libtommath asan
+ ${MAKE} -C ucd2c
+ ${MAKE} -C libkc3 asan
+ ${MAKE} -C ikc3 asan
+ ${MAKE} -C json asan
+ ${MAKE} -C test gdb_test_json_asan
+
gen:
${MAKE} -C libkc3 gen
diff --git a/json/json.c b/json/json.c
index 2c07d04..beba289 100644
--- a/json/json.c
+++ b/json/json.c
@@ -35,6 +35,48 @@
return r;
}*/
+s_tag * json_buf_parse_map (s_buf *buf, s_tag *dest)
+{
+ s_list **k;
+ s_list *keys;
+ sw r;
+ s_buf_save save;
+ s_list **v;
+ s_list *values;
+ assert(buf);
+ assert(dest);
+ buf_save_init(buf, &save);
+ if ((r = buf_read_1(buf, "{")) <= 0)
+ goto clean;
+ keys = NULL;
+ k = &keys;
+ values = NULL;
+ v = &values;
+ while (1) {
+ if ((r = buf_ignore_spaces(buf)) <= 0)
+ goto restore;
+ if ((r = buf_read_1(buf, "}")) < 0)
+ goto restore;
+ if (r > 0)
+ break;
+ buf_parse_tag_str(buf, &(*k)->tag);
+ buf_parse_tag(buf, &(*v)->tag);
+ }
+ dest->type = TAG_MAP;
+ if (! map_init_from_lists(&dest->data.map, keys, values))
+ goto restore;
+ list_delete_all(keys);
+ list_delete_all(values);
+ return dest;
+ restore:
+ buf_save_restore_rpos(buf, &save);
+ clean:
+ list_delete_all(keys);
+ list_delete_all(values);
+ buf_save_clean(buf, &save);
+ return NULL;
+}
+
s_tag * json_buf_parse_numbers (s_buf *buf, s_tag *dest)
{
s_buf_save save;
@@ -60,6 +102,9 @@ s_tag * json_buf_parse (s_buf *buf, s_tag *dest)
if ((r =buf_peek_character_utf8(buf, &c)) < 0)
return NULL;
switch (c) {
+ case '{':
+ json_buf_parse_map(buf, &tmp);
+ break;
case '"':
buf_parse_tag_str(buf, &tmp);
break;
diff --git a/test/Makefile b/test/Makefile
index caf73a7..96e8c1f 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -95,6 +95,9 @@ gdb_test_ikc3:
gdb_test_json:
cd json && ${GDB} ../../ikc3/.libs/ikc3_debug
+gdb_test_json_asan:
+ cd json && ${GDB} ../../ikc3/.libs/ikc3_asan
+
lldb_test: debug
if [ -f libkc3_test_debug.core ]; then lldb .libs/libkc3_test_debug libkc3_test_debug.core; else lldb .libs/libkc3_test_debug; fi