Source
int zbx_user_macro_parse(const char *macro, int *macro_r, int *context_l, int *context_r, unsigned char *context_op)
/*
** 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.
**/
/******************************************************************************
* *
* 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);