Source
xxxxxxxxxx
int get_value_java(unsigned char request, const zbx_dc_item_t *item, AGENT_RESULT *result, int config_timeout,
/*
** 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/>.
**/
static int parse_response(AGENT_RESULT *results, int *errcodes, int num, char *response,
char *error, int max_error_len)
{
const char *p;
struct zbx_json_parse jp, jp_data, jp_row;
char *value = NULL;
size_t value_alloc = 0;
int ret = GATEWAY_ERROR;
if (SUCCEED == zbx_json_open(response, &jp))
{
if (SUCCEED != zbx_json_value_by_name_dyn(&jp, ZBX_PROTO_TAG_RESPONSE, &value, &value_alloc, NULL))
{
zbx_snprintf(error, max_error_len, "No '%s' tag in received JSON", ZBX_PROTO_TAG_RESPONSE);
goto exit;
}
if (0 == strcmp(value, ZBX_PROTO_VALUE_SUCCESS))
{
if (SUCCEED != zbx_json_brackets_by_name(&jp, ZBX_PROTO_TAG_DATA, &jp_data))
{
zbx_strlcpy(error, "Cannot open data array in received JSON", max_error_len);
goto exit;
}
p = NULL;
for (int i = 0; i < num; i++)
{
if (SUCCEED != errcodes[i])
continue;
if (NULL == (p = zbx_json_next(&jp_data, p)))
{
zbx_strlcpy(error, "Not all values included in received JSON", max_error_len);
goto exit;
}
if (SUCCEED != zbx_json_brackets_open(p, &jp_row))
{
zbx_strlcpy(error, "Cannot open value object in received JSON", max_error_len);
goto exit;
}
if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_VALUE, &value,
&value_alloc, NULL))
{
zbx_set_agent_result_type(&results[i], ITEM_VALUE_TYPE_TEXT, value);
errcodes[i] = SUCCEED;
}
else if (SUCCEED == zbx_json_value_by_name_dyn(&jp_row, ZBX_PROTO_TAG_ERROR, &value,
&value_alloc, NULL))
{
SET_MSG_RESULT(&results[i], zbx_strdup(NULL, value));
errcodes[i] = NOTSUPPORTED;
}
else
{
SET_MSG_RESULT(&results[i], zbx_strdup(NULL, "Cannot get item value or "
"error message"));
errcodes[i] = AGENT_ERROR;
}
}
ret = SUCCEED;
}
else if (0 == strcmp(value, ZBX_PROTO_VALUE_FAILED))
{
if (SUCCEED == zbx_json_value_by_name(&jp, ZBX_PROTO_TAG_ERROR, error, max_error_len, NULL))
{