diff options
-rw-r--r-- | include/zbxjson.h | 1 | ||||
-rw-r--r-- | src/libs/zbxjson/json.c | 35 |
2 files changed, 33 insertions, 3 deletions
diff --git a/include/zbxjson.h b/include/zbxjson.h index f77d1674..6ebd7a2d 100644 --- a/include/zbxjson.h +++ b/include/zbxjson.h @@ -99,6 +99,7 @@ const char *zbx_json_pair_next(struct zbx_json_parse *jp, const char *p, char *n const char *zbx_json_pair_by_name(struct zbx_json_parse *jp, const char *name); int zbx_json_value_by_name(struct zbx_json_parse *jp, const char *name, char *string, size_t len); int zbx_json_brackets_open(const char *p, struct zbx_json_parse *jp); +int zbx_json_brackets_by_name(struct zbx_json_parse *jp, const char *name, struct zbx_json_parse *out); zbx_json_type_t zbx_json_type(const char *p); #endif /* ZABBIX_ZJSON_H */ diff --git a/src/libs/zbxjson/json.c b/src/libs/zbxjson/json.c index 809cc396..131e1e08 100644 --- a/src/libs/zbxjson/json.c +++ b/src/libs/zbxjson/json.c @@ -554,7 +554,7 @@ static const char *zbx_json_decodeint(const char *p, char *string, size_t len) char *o = string; while (*p != '\0') { /* this should never happen */ - if (*p < '0' || *p > '9') { + if ((*p < '0' || *p > '9') && *p != '-') { *o = '\0'; return p; } else if (o - string < len - 1/*'\0'*/) @@ -684,7 +684,7 @@ int zbx_json_brackets_open(const char *p, struct zbx_json_parse *jp) { if (NULL == (jp->end = __zbx_json_rbracket(p))) { zbx_set_json_strerror("Can't open JSON object or array \"%.64s\"", - p); + p); return FAIL; } @@ -695,6 +695,35 @@ int zbx_json_brackets_open(const char *p, struct zbx_json_parse *jp) /****************************************************************************** * * + * Function: zbx_json_brackets_by_name * + * * + * Purpose: * + * * + * Parameters: * + * * + * Return value: SUCCESS - processed succesfully * + * FAIL - an error occured * + * * + * Author: Aleksander Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +int zbx_json_brackets_by_name(struct zbx_json_parse *jp, const char *name, struct zbx_json_parse *out) +{ + const char *p = NULL; + + if (NULL == (p = zbx_json_pair_by_name(jp, name))) + return FAIL; + + if (FAIL == zbx_json_brackets_open(p, out)) + return FAIL; + + return SUCCEED; +} + +/****************************************************************************** + * * * Function: zbx_json_type * * * * Purpose: return type of pointed value * @@ -712,7 +741,7 @@ zbx_json_type_t zbx_json_type(const char *p) { if (*p == '"') return ZBX_JSON_TYPE_STRING; - if (*p >= '0' && *p <= '9') + if ((*p >= '0' && *p <= '9') || *p == '-') return ZBX_JSON_TYPE_INT; if (*p == '[') return ZBX_JSON_TYPE_ARRAY; |