Source
xxxxxxxxxx
int zbx_kvs_from_json_by_path_get(const char *path, const struct zbx_json_parse *jp_kvs_paths, zbx_kvs_t *kvs,
/*
** 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.
**/
static zbx_hash_t zbx_kv_hash(const void *data)
{
const zbx_kv_t *kv = (const zbx_kv_t *)data;
return ZBX_DEFAULT_STRING_HASH_ALGO(kv->key, strlen(kv->key), ZBX_DEFAULT_HASH_SEED);
}
static int zbx_kv_compare(const void *d1, const void *d2)
{
return strcmp(((const zbx_kv_t *)d1)->key, ((const zbx_kv_t *)d2)->key);
}
static void zbx_kv_clean(void *data)
{
zbx_kv_t *kv = (zbx_kv_t *)data;
zbx_free(kv->key);
zbx_free(kv->value);
}
void zbx_kvs_create(zbx_kvs_t *kvs, size_t init_size)
{
zbx_hashset_create_ext(kvs, init_size, zbx_kv_hash, zbx_kv_compare, zbx_kv_clean,
ZBX_DEFAULT_MEM_MALLOC_FUNC, ZBX_DEFAULT_MEM_REALLOC_FUNC, ZBX_DEFAULT_MEM_FREE_FUNC);
}
void zbx_kvs_clear(zbx_kvs_t *kvs)
{
zbx_hashset_clear(kvs);
}
void zbx_kvs_destroy(zbx_kvs_t *kvs)
{
zbx_hashset_destroy(kvs);
}
zbx_kv_t *zbx_kvs_search(zbx_kvs_t *kvs, const zbx_kv_t *data)
{
return zbx_hashset_search(kvs, data);
}