diff options
author | Andrejs Griščenko <andrejs.griscenko@zabbix.com> | 2021-05-07 17:01:32 +0300 |
---|---|---|
committer | Andrejs Griščenko <andrejs.griscenko@zabbix.com> | 2021-05-07 17:01:32 +0300 |
commit | 19e88a15b0d17fb5381df43db83e3e452c3ae35a (patch) | |
tree | 95582b6d1bbe9f7c42ccc26dab772e6599e7f704 /src | |
parent | 7968c3d4b1f4cacfd3191f11ba56a0f6f6601b29 (diff) | |
parent | 27d4e37650a3cd785ffc481dcb5c831c7b58f9e1 (diff) |
.......... [ZBXNEXT-6544] updated to the latest from 'feature/ZBXNEXT-6452-5.3'; resolved conflicts in:
- ui/include/classes/validators/CMathFunctionValidator.php
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/zbxeval/parse.c | 68 | ||||
-rw-r--r-- | src/libs/zbxserver/Makefile.am | 2 |
2 files changed, 63 insertions, 7 deletions
diff --git a/src/libs/zbxeval/parse.c b/src/libs/zbxeval/parse.c index 31ea12e5a51..db41384dfb0 100644 --- a/src/libs/zbxeval/parse.c +++ b/src/libs/zbxeval/parse.c @@ -1124,6 +1124,67 @@ static int eval_append_operator(zbx_eval_context_t *ctx, zbx_eval_token_t *token /****************************************************************************** * * + * Function: eval_append_operand * + * * + * Purpose: add operand token to evaluation stack * + * * + * Parameters: ctx - [IN] the evaluation context * + * token - [IN] the token to add * + * * + ******************************************************************************/ +static int eval_append_operand(zbx_eval_context_t *ctx, zbx_eval_token_t *token, char **error) +{ + if (0 == (ctx->last_token_type & ZBX_EVAL_BEFORE_OPERAND)) + { + *error = zbx_dsprintf(*error, "operand following another operand at \"%s\"", + ctx->expression + token->loc.l); + return FAIL; + } + + if (0 != (ctx->rules & ZBX_EVAL_PARSE_PROPERTY)) + { + int i; + zbx_eval_token_t *prop = NULL; + + for (i = ctx->stack.values_num - 1; i >= 0; i--) + { + if (0 != (ctx->stack.values[i].type & ZBX_EVAL_CLASS_PROPERTY)) + { + prop = &ctx->stack.values[i]; + continue; + } + + if (0 == (ctx->stack.values[i].type & ZBX_EVAL_CLASS_OPERAND)) + break; + } + + if (0 != (token->type & ZBX_EVAL_CLASS_PROPERTY)) + { + if (NULL != prop) + { + *error = zbx_dsprintf(*error, "property must be compared with a constant value at" + " \"%s\"", ctx->expression + prop->loc.l); + return FAIL; + } + prop = token; + } + + if (NULL != prop && 2 < ctx->stack.values_num - i) + { + *error = zbx_dsprintf(*error, "property must be compared with a constant value at" + " \"%s\"", ctx->expression + prop->loc.l); + return FAIL; + } + } + + zbx_vector_eval_token_append_ptr(&ctx->stack, token); + + return SUCCEED; +} + + +/****************************************************************************** + * * * Function: eval_append_arg_null * * * * Purpose: add null argument token to evaluation stack * @@ -1320,13 +1381,8 @@ static int eval_parse_expression(zbx_eval_context_t *ctx, const char *expression } else if (0 != (token.type & (ZBX_EVAL_CLASS_OPERAND | ZBX_EVAL_CLASS_PROPERTY))) { - if (0 == (ctx->last_token_type & ZBX_EVAL_BEFORE_OPERAND)) - { - *error = zbx_dsprintf(*error, "operand following another operand at \"%s\"", - ctx->expression + pos); + if (FAIL == eval_append_operand(ctx, &token, error)) goto out; - } - zbx_vector_eval_token_append_ptr(&ctx->stack, &token); } else if (0 != (token.type & ZBX_EVAL_CLASS_OPERATOR)) { diff --git a/src/libs/zbxserver/Makefile.am b/src/libs/zbxserver/Makefile.am index 920938c2a73..d0f0b47b169 100644 --- a/src/libs/zbxserver/Makefile.am +++ b/src/libs/zbxserver/Makefile.am @@ -6,7 +6,7 @@ libzbxserver_a_SOURCES = \ evalfunc.c \ evalfunc.h \ expression.c \ - expression.h ]\ + expression.h \ macrofunc.c \ macrofunc.h \ zabbix_stats.c \ |