Source
static int eval_parse_expression(zbx_eval_context_t *ctx, const char *expression, zbx_uint64_t rules, char **error)
/*
** 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.
**/
ZBX_VECTOR_IMPL(eval_token, zbx_eval_token_t)
static int is_whitespace(char c)
{
return 0 != isspace((unsigned char)c) ? SUCCEED : FAIL;
}
/******************************************************************************
* *
* Purpose: find the number of following whitespace characters *
* *
* Parameters: ctx - [IN] the evaluation context *
* pos - [IN] the starting position *
* *
* Return value: The 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: update constant variable index in the trigger expression *
* *
* Parameters: ctx - [IN] the evaluation context *
* token - [IN] the 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: check 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;