Source
int zbx_user_macro_parse(const char *macro, int *macro_r, int *context_l, int *context_r, unsigned char *context_op)
/*
** 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/>.
**/
/******************************************************************************
* *
* Return value: SUCCEED - char is allowed in macro name *
* FAIL - otherwise *
* *
* Comments: allowed characters in macro names: '0-9A-Z._' *
* !!! Don't forget to sync the code with PHP !!! *
* *
******************************************************************************/
int zbx_is_macro_char(unsigned char c)
{
if (0 != isupper(c))
return SUCCEED;
if ('.' == c || '_' == c)
return SUCCEED;
if (0 != isdigit(c))
return SUCCEED;
return FAIL;
}
/******************************************************************************
* *
* Purpose: checks if name is valid discovery macro *
* *
* Return value: SUCCEED - name is valid discovery macro *
* FAIL - otherwise *
* *
******************************************************************************/
int zbx_is_discovery_macro(const char *name)
{
if ('{' != *name++ || '#' != *name++)
return FAIL;
do
{
if (SUCCEED != zbx_is_macro_char(*name++))
return FAIL;
} while ('}' != *name);
if ('\0' != name[1])
return FAIL;
return SUCCEED;