Source
static int item_param_check_field(const zbx_item_param_t *item_param, zbx_item_param_field_t type, char **error)
/*
** 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(item_param_ptr, zbx_item_param_t *)
zbx_item_param_t *zbx_item_param_create(const char *item_param_name,
const char *item_param_value)
{
zbx_item_param_t *item_param;
item_param = (zbx_item_param_t *)zbx_malloc(NULL, sizeof(zbx_item_param_t));
item_param->item_parameterid = 0;
item_param->flags = ZBX_FLAG_ITEM_PARAM_UPDATE_RESET;
item_param->name = zbx_strdup(NULL, item_param_name);
item_param->name_orig = NULL;
item_param->value = zbx_strdup(NULL, item_param_value);
item_param->value_orig = NULL;
return item_param;
}
void zbx_item_param_free(zbx_item_param_t *param)
{
if (0 != (param->flags & ZBX_FLAG_ITEM_PARAM_UPDATE_NAME))
zbx_free(param->name_orig);
zbx_free(param->name);
if (0 != (param->flags & ZBX_FLAG_ITEM_PARAM_UPDATE_VALUE))
zbx_free(param->value_orig);
zbx_free(param->value);
zbx_free(param);
}
/******************************************************************************
* *
* Purpose: roll back item_param updates done during merge process *
* *
* Return value: SUCCEED - updates were rolled back *
* FAIL - new item_param, rollback impossible *
* *
******************************************************************************/
static int item_param_rollback(zbx_item_param_t *item_param)
{
if (0 == item_param->item_parameterid)
return FAIL;
if (0 != (item_param->flags & ZBX_FLAG_ITEM_PARAM_UPDATE_NAME))
{
zbx_free(item_param->name);
item_param->name = item_param->name_orig;
item_param->name_orig = NULL;
item_param->flags &= (~ZBX_FLAG_ITEM_PARAM_UPDATE_NAME);
}
if (0 != (item_param->flags & ZBX_FLAG_ITEM_PARAM_UPDATE_VALUE))
{
zbx_free(item_param->value);
item_param->value = item_param->value_orig;
item_param->value_orig = NULL;
item_param->flags &= (~ZBX_FLAG_ITEM_PARAM_UPDATE_VALUE);
}
return SUCCEED;
}
typedef enum
{
ZBX_ITEM_PARAM_NAME,
ZBX_ITEM_PARAM_VALUE
}
zbx_item_param_field_t;
/******************************************************************************