Source
(void)json_error("invalid object format, expected opening character '{' or '['", data, &error);
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
ZBX_PTR_VECTOR_IMPL(jsonobj_ptr, zbx_jsonobj_t *)
ZBX_VECTOR_IMPL(jsonobj_ref, zbx_jsonobj_ref_t)
/* jsonobject index hashset support */
static zbx_hash_t jsonobj_index_el_hash(const void *v)
{
const zbx_jsonobj_index_el_t *el = (const zbx_jsonobj_index_el_t *)v;
return ZBX_DEFAULT_STRING_HASH_FUNC(el->value);
}
static int jsonobj_index_el_compare(const void *v1, const void *v2)
{
const zbx_jsonobj_index_el_t *el1 = (const zbx_jsonobj_index_el_t *)v1;
const zbx_jsonobj_index_el_t *el2 = (const zbx_jsonobj_index_el_t *)v2;
return strcmp(el1->value, el2->value);
}
/* 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;
}
obj->index = NULL;
obj->index_num = 0;
}