Commit 1f180573233161d31cf87efd5fd0234171403809

Baptiste 2024-08-14T14:54:19

wip json

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