Source
int zbx_replace_key_params_dyn(char **data, int key_type, zbx_replace_key_param_f cb, void *cb_data, 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.
**/
/******************************************************************************
* *
* Purpose: return parameter by index (num) from parameter list (param) *
* *
* Parameters: *
* p - [IN] parameter list *
* num - [IN] requested parameter index *
* buf - [OUT] pointer of output buffer *
* max_len - [IN] size of output buffer *
* type - [OUT] parameter type (may be NULL) *
* *
* Return value: *
* 1 - requested parameter missing or buffer overflow *
* 0 - requested parameter found (value - 'buf' can be empty string) *
* *
* Comments: delimiter for parameters is ',' *
* *
******************************************************************************/
int zbx_get_param(const char *p, int num, char *buf, size_t max_len, zbx_request_parameter_type_t *type)
{
/* buffer overflow */ \
buf[buf_i++] = *p; \
}
int state; /* 0 - init, 1 - inside quoted param, 2 - inside unquoted param */
int array, idx = 1;
size_t buf_i = 0;
if (NULL != type)
*type = REQUEST_PARAMETER_TYPE_UNDEFINED;
if (0 == max_len)
return 1; /* buffer overflow */
max_len--; /* '\0' */
for (state = 0, array = 0; '\0' != *p && idx <= num; p++)
{
switch (state)
{
/* init state */
case 0:
if (',' == *p)
{
if (0 == array)
idx++;
else if (idx == num)
ZBX_ASSIGN_PARAM;
}
else if ('"' == *p)
{
state = 1;
if (idx == num)
{
if (NULL != type && REQUEST_PARAMETER_TYPE_UNDEFINED == *type)
*type = REQUEST_PARAMETER_TYPE_STRING;
if (0 != array)
ZBX_ASSIGN_PARAM;
}
}
else if ('[' == *p)