Source
xxxxxxxxxx
/*
** 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/>.
**/
/******************************************************************************
* *
* Purpose: compares two macros by name *
* *
* Parameters: d1 - [IN] first macro *
* d2 - [IN] second macro *
* *
* Return value: <0 - first macro name is 'less' than second *
* 0 - macro names are equal *
* >0 - first macro name is 'greater' than second *
* *
******************************************************************************/
static int httpmacro_cmp_func(const void *d1, const void *d2)
{
const zbx_ptr_pair_t *pair1 = (const zbx_ptr_pair_t *)d1;
const zbx_ptr_pair_t *pair2 = (const zbx_ptr_pair_t *)d2;
return strcmp((char *)pair1->first, (char *)pair2->first);
}
/******************************************************************************
* *
* Purpose: find macros *
* *
* Parameters: pmacro - [IN] macro values *
* key - [IN] searching value data *
* loc - [IN] searching value location in key *
* *
* Return value: index in pmacro *
* FAIL - not found *
* *
******************************************************************************/
static int zbx_macro_variable_search(const zbx_vector_ptr_pair_t *pmacro, const char *key, const zbx_strloc_t loc)
{
for (int i = 0; i < pmacro->values_num; i++)
{
if (SUCCEED == zbx_strloc_cmp(key, &loc, pmacro->values[i].first, strlen(pmacro->values[i].first)))
return i;
}
return FAIL;
}
/******************************************************************************
* *
* Purpose: Appends key/value pair to the HTTP test macro cache. *
* If the value format is 'regex:<pattern>', then regular expression *
* match is performed against the supplied data value and specified *
* pattern. The first captured group is assigned to the macro value. *
* *
* Parameters: httptest - [IN/OUT] HTTP test data *
* pkey - [IN] pointer to macro name (key) data *
* nkey - [IN] macro name (key) size *
* pvalue - [IN] pointer to macro value data *
* nvalue - [IN] value size *
* data - [IN] data for regexp matching (optional) *
* err_str - [OUT] error message (optional) *
* *
* Return value: SUCCEED - key/value pair was added successfully *
* FAIL - key/value pair adding to cache failed *
* The failure reason can be either empty key/value, *
* wrong key format or failed regular expression *
* match. *
* *
******************************************************************************/
static int httpmacro_append_pair(zbx_httptest_t *httptest, const char *pkey, size_t nkey,
const char *pvalue, size_t nvalue, const char *data, char **err_str)
{