diff options
Diffstat (limited to 'src/libs/zbxjson/json_parser.c')
-rw-r--r-- | src/libs/zbxjson/json_parser.c | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/src/libs/zbxjson/json_parser.c b/src/libs/zbxjson/json_parser.c index 05533bd6761..92997d357b7 100644 --- a/src/libs/zbxjson/json_parser.c +++ b/src/libs/zbxjson/json_parser.c @@ -24,7 +24,6 @@ #include "log.h" -static int json_parse_value(const char *start, char **error); static int json_parse_object(const char *start, char **error); /****************************************************************************** @@ -43,18 +42,14 @@ static int json_parse_object(const char *start, char **error); * Author: Andris Zeila * * * ******************************************************************************/ -static int json_error(const char *message, const char* json_buffer, char** error) +static int json_error(const char *message, const char *json_buffer, char **error) { - size_t size = 1024, offset = 0; - if (NULL != error) { - *error = zbx_malloc(*error, size); - if (NULL != json_buffer) - zbx_snprintf_alloc(error, &size, &offset, "%s at: '%s'", message, json_buffer); + *error = zbx_dsprintf(*error, "%s at: '%s'", message, json_buffer); else - zbx_snprintf_alloc(error, &size, &offset, "%s", message); + *error = zbx_strdup(*error, message); } return 0; @@ -69,7 +64,7 @@ static int json_error(const char *message, const char* json_buffer, char** error * Parameters: start - [IN] the JSON data without leading whitespace * * error - [OUT] the parsing error message (can be NULL) * * * - * Return value: the number of characters parsed. On error 0 is returned and * + * Return value: The number of characters parsed. On error 0 is returned and * * error parameter (if not NULL) contains allocated error * * message. * * * @@ -131,7 +126,7 @@ static int json_parse_string(const char *start, char **error) * Parameters: start - [IN] the JSON data without leading whitespace * * error - [OUT] the parsing error message (can be NULL) * * * - * Return value: the number of characters parsed. On error 0 is returned and * + * Return value: The number of characters parsed. On error 0 is returned and * * error parameter (if not NULL) contains allocated error * * message. * * * @@ -180,7 +175,7 @@ static int json_parse_array(const char *start, char **error) * Parameters: start - [IN] the JSON data without leading whitespace * * error - [OUT] the parsing error message (can be NULL) * * * - * Return value: the number of characters parsed. On error 0 is returned and * + * Return value: The number of characters parsed. On error 0 is returned and * * error parameter (if not NULL) contains allocated error * * message. * * * @@ -256,7 +251,7 @@ static int json_parse_number(const char *start, char **error) * text - [IN] the literal value to parse * * error - [OUT] the parsing error message (can be NULL) * * * - * Return value: the number of characters parsed. On error 0 is returned and * + * Return value: The number of characters parsed. On error 0 is returned and * * error parameter (if not NULL) contains allocated error * * message. * * * @@ -287,21 +282,20 @@ static int json_parse_literal(const char *start, const char *text, char **error) * * * Purpose: Parses JSON object value * * * - * Parameters: start - [IN/OUT] the JSON data; returns the reference the real * - * data (without spaces) * + * Parameters: start - [IN] the JSON data * * error - [OUT] the parsing error message (can be NULL) * * * - * Return value: the number of characters parsed. On error 0 is returned and * + * Return value: The number of characters parsed. On error 0 is returned and * * error parameter (if not NULL) contains allocated error * * message. * * * * Author: Andris Zeila * * * ******************************************************************************/ -static int json_parse_value(const char *start, char **error) +int json_parse_value(const char *start, char **error) { const char *ptr = start; - int len = 0; + int len; SKIP_WHITESPACE(ptr); @@ -360,11 +354,10 @@ static int json_parse_value(const char *start, char **error) * * * Purpose: Parses JSON object * * * - * Parameters: start - [IN/OUT] the JSON data; returns the reference the real * - * data (without spaces) * + * Parameters: start - [IN] the JSON data * * error - [OUT] the parsing error message (can be NULL) * * * - * Return value: the number of characters parsed. On error 0 is returned and * + * Return value: The number of characters parsed. On error 0 is returned and * * error parameter (if not NULL) contains allocated error * * message. * * * @@ -428,19 +421,18 @@ static int json_parse_object(const char *start, char **error) return ptr - start + 1; } - /****************************************************************************** * * * Function: zbx_json_validate * * * * Purpose: Validates JSON object * * * - * Parameters: start - [IN] the string to validate * - * error - [OUT] the parse error message. If the error value is * - * set it must be freed by caller after it has * - * been used (can be NULL). * + * Parameters: start - [IN] the string to validate * + * error - [OUT] the parse error message. If the error value is * + * set it must be freed by caller after it has * + * been used (can be NULL). * * * - * Return value: the number of characters parsed. On error 0 is returned and * + * Return value: The number of characters parsed. On error 0 is returned and * * error parameter (if not NULL) contains allocated error * * message. * * * @@ -462,4 +454,3 @@ int zbx_json_validate(const char *start, char **error) return len; } - |