Source
/* zbx_trim_integer() stripped one '+' sign, so there's more than one '+' sign in the 'text' argument */
/*
** 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_VECTOR_IMPL(var, zbx_variant_t)
static void *zbx_variant_data_bin_copy(const void *bin)
{
zbx_uint32_t size;
void *value_bin;
memcpy(&size, bin, sizeof(size));
value_bin = zbx_malloc(NULL, size + sizeof(size));
memcpy(value_bin, bin, size + sizeof(size));
return value_bin;
}
void *zbx_variant_data_bin_create(const void *data, zbx_uint32_t size)
{
void *value_bin;
value_bin = zbx_malloc(NULL, size + sizeof(size));
memcpy(value_bin, &size, sizeof(size));
memcpy((unsigned char *)value_bin + sizeof(size), data, size);
return value_bin;
}
zbx_uint32_t zbx_variant_data_bin_get(const void *bin, void **data)
{
zbx_uint32_t size;
memcpy(&size, bin, sizeof(zbx_uint32_t));
if (NULL != data)
*data = ((unsigned char *)bin) + sizeof(size);
return size;
}
void zbx_variant_clear(zbx_variant_t *value)
{
switch (value->type)
{
case ZBX_VARIANT_STR:
zbx_free(value->data.str);
break;
case ZBX_VARIANT_BIN:
zbx_free(value->data.bin);
break;
case ZBX_VARIANT_ERR:
zbx_free(value->data.err);
break;
case ZBX_VARIANT_DBL_VECTOR:
zbx_vector_dbl_destroy(value->data.dbl_vector);
zbx_free(value->data.dbl_vector);
break;
}
value->type = ZBX_VARIANT_NONE;
}
/******************************************************************************
* *
* Setter functions assign passed data and set corresponding variant *
* type. Note that for complex data it means the pointer is simply copied *
* instead of making a copy of the specified data. *
* *
* The contents of the destination value are not freed. When setting already *
* initialized variant it's safer to clear it beforehand, even if the variant *
* contains primitive value (numeric). *