Source
static int token_parse_expression_macro(const char *expression, const char *macro, zbx_token_search_t token_search,
/*
** 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: parses user macro token *
* *
* Parameters: expression - [IN] the expression *
* macro - [IN] the beginning of the token *
* token - [OUT] the token data *
* *
* Return value: SUCCEED - the 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))