diff options
author | Andris Zeila <andris.zeila@zabbix.com> | 2022-10-21 15:43:07 +0300 |
---|---|---|
committer | Andris Zeila <andris.zeila@zabbix.com> | 2022-10-21 15:43:07 +0300 |
commit | 61086f23d82d7cbe2669cadc0602dc4e79db5f91 (patch) | |
tree | bc24751c0fa3a5270d4dfefc6032a2c661d3a9b2 /include | |
parent | fbaa564aeae8b190db2b094c394abfad1375de1d (diff) |
.......PS. [ZBXNEXT-8040] added object based json parser and json path processing with indexing
Diffstat (limited to 'include')
-rw-r--r-- | include/zbxjson.h | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/include/zbxjson.h b/include/zbxjson.h index 28ed6fd68a6..209ddb4d216 100644 --- a/include/zbxjson.h +++ b/include/zbxjson.h @@ -21,6 +21,7 @@ #define ZABBIX_ZJSON_H #include "zbxtypes.h" +#include "zbxalgo.h" #define ZBX_PROTO_TAG_CLOCK "clock" #define ZBX_PROTO_TAG_NS "ns" @@ -250,7 +251,8 @@ typedef enum ZBX_JSON_TYPE_OBJECT, ZBX_JSON_TYPE_NULL, ZBX_JSON_TYPE_TRUE, - ZBX_JSON_TYPE_FALSE + ZBX_JSON_TYPE_FALSE, + ZBX_JSON_TYPE_NUMBER } zbx_json_type_t; @@ -333,8 +335,47 @@ typedef struct } zbx_jsonpath_t; -void zbx_jsonpath_clear(zbx_jsonpath_t *jsonpath); +typedef struct zbx_jsonobj zbx_jsonobj_t; + +ZBX_PTR_VECTOR_DECL(jsonobj_ptr, zbx_jsonobj_t *) + +typedef union +{ + char *string; + double number; + zbx_hashset_t object; + zbx_vector_jsonobj_ptr_t array; +} +zbx_jsonobj_data_t; + +typedef struct +{ + char *path; /* the path that was indexed - for example @.a.b.c */ + zbx_hashset_t objects; +} +zbx_jsonobj_index_t; + +struct zbx_jsonobj +{ + zbx_json_type_t type; + zbx_jsonobj_data_t data; + zbx_jsonobj_index_t *index; +}; + +typedef struct +{ + char *name; + zbx_jsonobj_t value; +} +zbx_jsonobj_el_t; + int zbx_jsonpath_compile(const char *path, zbx_jsonpath_t *jsonpath); int zbx_jsonpath_query(const struct zbx_json_parse *jp, const char *path, char **output); +void zbx_jsonpath_clear(zbx_jsonpath_t *jsonpath); + +int zbx_jsonobj_open(const char *data, zbx_jsonobj_t *obj); +void zbx_jsonobj_clear(zbx_jsonobj_t *obj); +int zbx_jsonobj_query(zbx_jsonobj_t *obj, const char *path, char **output); +int zbx_jsonobj_to_string(char **str, size_t *str_alloc, size_t *str_offset, zbx_jsonobj_t *obj); #endif /* ZABBIX_ZJSON_H */ |