Source
static int eval_parse_expression(zbx_eval_context_t *ctx, const char *expression, zbx_uint64_t rules, char **error)
/*
** 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/>.
**/
ZBX_VECTOR_IMPL(eval_token, zbx_eval_token_t)
static int is_whitespace(char c)
{
return 0 != isspace((unsigned char)c) ? SUCCEED : FAIL;
}
/******************************************************************************
* *
* Purpose: finds number of following whitespace characters *
* *
* Parameters: ctx - [IN] evaluation context *
* pos - [IN] starting position *
* *
* Return value: number of whitespace characters found *
* *
******************************************************************************/
static size_t eval_get_whitespace_len(zbx_eval_context_t *ctx, size_t pos)
{
const char *ptr = ctx->expression + pos;
while (SUCCEED == is_whitespace(*ptr))
ptr++;
return ptr - ctx->expression - pos;
}
/******************************************************************************
* *
* Purpose: updates constant variable index in trigger expression *
* *
* Parameters: ctx - [IN] evaluation context *
* token - [IN] variable token *
* *
* Comments: The index is used to refer constant values by using $<N> in *
* trigger names. Function arguments are excluded. *
* *
******************************************************************************/
static void eval_update_const_variable(zbx_eval_context_t *ctx, zbx_eval_token_t *token)
{
zbx_variant_set_none(&token->value);
if (0 != (ctx->rules & ZBX_EVAL_PARSE_CONST_INDEX))
{
int i;
for (i = 0; i < ctx->ops.values_num; i++)
{
if (0 != (ctx->ops.values[i].type & ZBX_EVAL_CLASS_FUNCTION))
return;
}
token->opt = ctx->const_index++;
}
}
/******************************************************************************
* *
* Purpose: Checks if the character can be a part of a compound number *
* following a macro. *
* *
******************************************************************************/
static int eval_is_compound_number_char(char c, int pos)
{
if (0 != isdigit((unsigned char)c))
return SUCCEED;
switch (c)
{
case '.':
case '{':
return SUCCEED;