Source
xxxxxxxxxx
int zbx_eval_get_group_filter(zbx_eval_context_t *ctx, zbx_vector_str_t *groups, char **filter, 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/>.
**/
/* The tag expression token is virtual token used during item query filter processing. */
/******************************************************************************
* *
* Purpose: parses item query /host/key?[filter] into host, key and filter *
* components *
* *
* Parameters: str - [IN] item query *
* len - [IN] query length *
* query - [IN] parsed item query *
* *
* Return value: number of parsed characters *
* *
******************************************************************************/
size_t zbx_eval_parse_query(const char *str, size_t len, zbx_item_query_t *query)
{
size_t n;
const char *host, *key, *filter;
if (0 == (n = eval_parse_query(str, &host, &key, &filter)) || n != len)
return 0;
query->host = (host != key - 1 ? zbx_substr(host, 0, key - host - 2) : NULL);
if (NULL != filter)
{
query->key = zbx_substr(key, 0, (filter - key) - 3);
query->filter = zbx_substr(filter, 0, (str + len - filter) - 2);
}
else
{
query->key = zbx_substr(key, 0, (str + len - key) - 1);
query->filter = NULL;
}
return n;
}
/******************************************************************************
* *
* Purpose: frees resources allocated by item reference *
* *
******************************************************************************/
void zbx_eval_clear_query(zbx_item_query_t *query)
{
zbx_free(query->host);
zbx_free(query->key);
zbx_free(query->filter);
}
/******************************************************************************
* *
* Purpose: Prepares filter expression by converting property comparisons *
* prop =/<> "value" to prop("value")/not prop("value") function *
* calls. *
* *
* Parameters: ctx - [IN] evaluation context *
* *
******************************************************************************/
void zbx_eval_prepare_filter(zbx_eval_context_t *ctx)
{
int i, j;
for (i = 0; i < ctx->stack.values_num; i++)
{
zbx_eval_token_t *prop = &ctx->stack.values[i];
if (0 == (prop->type & ZBX_EVAL_CLASS_PROPERTY))
continue;
for (j = i + 1; j < ctx->stack.values_num; j++)