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/>.
**/
int zbx_is_strict_macro(const char *macro)
{
const char *strict_macros[] = {MVAR_HOST_IP, MVAR_IPADDRESS, MVAR_HOST_DNS,
MVAR_HOST_CONN, MVAR_HOST_TARGET_DNS, MVAR_HOST_TARGET_CONN,
MVAR_HOST_TARGET_IP};
for (int i = 0; i < (int)ARRSIZE(strict_macros); i++)
{
if (0 == strcmp(strict_macros[i], macro))
return SUCCEED;
}
return FAIL;
}
/******************************************************************************
* *
* Purpose: checks if a token contains indexed macro. *
* *
******************************************************************************/
int zbx_is_indexed_macro(const char *str, const zbx_token_t *token)
{
const char *p;
switch (token->type)
{
case ZBX_TOKEN_MACRO:
p = str + token->loc.r - 1;
break;
case ZBX_TOKEN_USER_FUNC_MACRO:
case ZBX_TOKEN_FUNC_MACRO:
p = str + token->data.func_macro.macro.r - 1;
break;
default:
THIS_SHOULD_NEVER_HAPPEN;
return FAIL;
}
return '1' <= *p && *p <= '9' ? 1 : 0;
}
/******************************************************************************
* *
* Purpose: checks if a macro in string is one of list and extracts index. *