Source
static int token_parse_expression_macro(const char *expression, const char *macro, zbx_token_search_t token_search,
/*
** 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/>.
**/
/******************************************************************************
* *
* Parameters: expression - [IN] *
* macro - [IN] beginning of the token *
* token - [OUT] token data *
* *
* Return value: SUCCEED - user macro was parsed successfully *
* FAIL - macro does not point at valid user macro *
* *
* Comments: If the macro points at valid user macro in the expression then *
* the generic token fields are set and the token->data.user_macro *
* structure is filled with user macro specific data. *
* *
******************************************************************************/
static int token_parse_user_macro(const char *expression, const char *macro, zbx_token_t *token)
{
size_t offset;
int macro_r, context_l, context_r;
zbx_token_user_macro_t *data;
if (SUCCEED != zbx_user_macro_parse(macro, ¯o_r, &context_l, &context_r, NULL))
return FAIL;
offset = macro - expression;
/* initialize token */
token->type = ZBX_TOKEN_USER_MACRO;
token->loc.l = offset;
token->loc.r = offset + macro_r;
/* initialize token data */
data = &token->data.user_macro;
data->name.l = offset + 2;
if (0 != context_l)
{
const char *ptr = macro + context_l;
/* find the context separator ':' by stripping spaces before context */
while (' ' == *(--ptr))
;
data->name.r = offset + (ptr - macro) - 1;
data->context.l = offset + context_l;
data->context.r = offset + context_r;
}
else
{
data->name.r = token->loc.r - 1;
data->context.l = 0;
data->context.r = 0;
}
return SUCCEED;
}
/******************************************************************************
* *
* Parameters: expression - [IN] *
* macro - [IN] beginning of token *
* token - [OUT] *
* *
* Return value: SUCCEED - lld macro was parsed successfully *
* FAIL - macro does not point at valid lld macro *
* *
* Comments: If the macro points at valid lld macro in the expression then *
* the generic token fields are set and the token->data.lld_macro *
* structure is filled with lld macro specific data. *
* *
******************************************************************************/
static int token_parse_lld_macro(const char *expression, const char *macro, zbx_token_t *token)
{
const char *ptr;
size_t offset;