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/>.
**/
ZBX_PTR_VECTOR_IMPL(jsonobj_ptr, zbx_jsonobj_t *)
ZBX_VECTOR_IMPL(jsonobj_ref, zbx_jsonobj_ref_t)
/* jsonobject values hashset support */
static zbx_hash_t jsonobj_el_hash(const void *v)
{
const zbx_jsonobj_el_t *el = (const zbx_jsonobj_el_t *)v;
return ZBX_DEFAULT_STRING_HASH_FUNC(el->name);
}
static int jsonobj_el_compare(const void *v1, const void *v2)
{
const zbx_jsonobj_el_t *el1 = (const zbx_jsonobj_el_t *)v1;
const zbx_jsonobj_el_t *el2 = (const zbx_jsonobj_el_t *)v2;
return strcmp(el1->name, el2->name);
}
/******************************************************************************
* *
* Purpose: initialize json object structure *
* *
* Parameters: obj - [IN/OUT] the json object to initialize *
* type - [IN] the json object type *
* *
******************************************************************************/
void jsonobj_init(zbx_jsonobj_t *obj, zbx_json_type_t type)
{
obj->type = type;
switch (type)
{
case ZBX_JSON_TYPE_ARRAY:
zbx_vector_jsonobj_ptr_create(&obj->data.array);
break;
case ZBX_JSON_TYPE_OBJECT:
zbx_hashset_create(&obj->data.object, 0, jsonobj_el_hash, jsonobj_el_compare);
break;
default:
memset(&obj->data, 0, sizeof(obj->data));
break;