Source
xxxxxxxxxx
/*
** 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.
**/
/******************************************************************************
* *
* Purpose: expands user macros in IPMI port value and converts the result to *
* to unsigned short value *
* *
* Parameters: hostid - [IN] the host identifier *
* port_orig - [IN] the original port value *
* port - [OUT] the resulting port value *
* error - [OUT] the error message *
* *
* Return value: SUCCEED - the 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;
int ret = SUCCEED;
tmp = zbx_strdup(NULL, port_orig);
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);