Source
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/******************************************************************************
* *
* Purpose: Prepares JSON parsing error message *
* *
* Parameters: message - [IN] the error message *
* ptr - [IN] the failing data fragment *
* error - [OUT] the parsing error message (can be NULL) *
* *
* Return value: 0 - the json_error() function always returns 0 value *
* so it can be used to return from failed parses *
* *
******************************************************************************/
zbx_int64_t json_error(const char *message, const char *ptr, char **error)
{
if (NULL != error)
{
if (NULL != ptr)
{
if (128 < strlen(ptr))
*error = zbx_dsprintf(*error, "%s at: '%128s...'", message, ptr);
else
*error = zbx_dsprintf(*error, "%s at: '%s'", message, ptr);
}
else
*error = zbx_strdup(*error, message);
}
return 0;
}
/******************************************************************************
* *
* Purpose: Parses JSON string value or object name *
* *
* Parameters: start - [IN] the JSON data without leading whitespace *
* str - [OUT] the parsed unquoted string (can be NULL) *
* error - [OUT] the parsing error message (can be NULL) *
* *
* Return value: The number of characters parsed. On error 0 is returned and *
* error parameter (if not NULL) contains allocated error *
* message. *
* *
******************************************************************************/