Source
xxxxxxxxxx
/*
** 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/>.
**/
/******************************************************************************
* *
* Purpose: expands user macros in IPMI port value and converts result to *
* unsigned short value *
* *
* Parameters: hostid - [IN] *
* port_orig - [IN] original port value *
* port - [OUT] resulting port value *
* error - [OUT] *
* *
* Return value: SUCCEED - value was converted successfully *
* FAIL - otherwise *
* *
******************************************************************************/
int zbx_ipmi_port_expand_macros(zbx_uint64_t hostid, const char *port_orig, unsigned short *port, char **error)
{
char *tmp = zbx_strdup(NULL, port_orig);
int ret = SUCCEED;
zbx_substitute_simple_macros(NULL, NULL, NULL, NULL, &hostid, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&tmp, ZBX_MACRO_TYPE_COMMON, NULL, 0);
if (FAIL == zbx_is_ushort(tmp, port) || 0 == *port)
{
*error = zbx_dsprintf(*error, "Invalid port value \"%s\"", port_orig);
ret = FAIL;
}
zbx_free(tmp);
return ret;
}