zabbix-agent2/src/libs/zbxserver/expression.c
/******************************************************************************
 *                                                                            *
 * Function: item_description                                                 *
 *                                                                            *
 * Purpose: substitute key parameters and user macros in                      *
 *          the item description string with real values                      *
 *                                                                            *
 ******************************************************************************/
item_description

Purpose: substitute key parameters and user macros in
the item description string with real values
item_description Purpose : substitute key parameters and user macros in the item description string with real values
static void	item_description(char **data, const char *key, zbx_uint64_t hostid)
{
	AGENT_REQUEST	request;
	char		c, *p, *m, *n, *str_out = NULL, *replace_to = NULL;
	int		macro_r, context_l, context_r, warning = 0;
	init_request(&request);
	if (SUCCEED != parse_item_key(key, &request))
		goto out;
	p = *data;
	while (NULL != (m = strchr(p, '$')))
	{
		if (m > p && '{' == *(m - 1) && FAIL != zbx_user_macro_parse(m - 1, &macro_r, &context_l, &context_r,
				NULL))
		{
			n = m + macro_r;
			c = *n;
			*n = '\0';
			DCget_user_macro(&hostid, 1, m - 1, &replace_to);
			if (NULL != replace_to)
			{
				*(m - 1) = '\0';
				str_out = zbx_strdcat(str_out, p);
				*(m - 1) = '{';
				str_out = zbx_strdcat(str_out, replace_to);
				zbx_free(replace_to);
			}
			else
				str_out = zbx_strdcat(str_out, p);
			*n = c;
			p = n;
		}
		else
		{
			if (0 == warning && '1' <= *(m + 1) && *(m + 1) <= '9')
			{
				zabbix_log(LOG_LEVEL_WARNING, "Use of positional macros ($1,$2... $9 - referring to the"
						" first, second... ninth parameter of the item key '%s') is "
						"no longer supported", key);
				warning = 1;
			}
			c = *++m;
			*m = '\0';
			str_out = zbx_strdcat(str_out, p);
			*m = c;
			p = m;
		}
	}
	if (NULL != str_out)
	{
		str_out = zbx_strdcat(str_out, p);
		zbx_free(*data);
		*data = str_out;
	}
out:
	free_request(&request);
}
static void item_description ( char * * data , const char * key , zbx_uint64_t hostid ) { AGENT_REQUEST request ; char c , * p , * m , * n , * str_out = NULL , * replace_to = NULL ; int macro_r , context_l , context_r , warning = 0 ; init_request ( & request ) ; if ( SUCCEED != parse_item_key ( key , & request ) ) goto out ; p = * data ; while ( NULL != ( m = strchr ( p , ' ' ) ) ) { if ( m > p && ' ' == * ( m - 1 ) && FAIL != zbx_user_macro_parse ( m - 1 , & macro_r , & context_l , & context_r , NULL ) ) { n = m + macro_r ; c = * n ; * n = ' \0 ' ; DCget_user_macro ( & hostid , 1 , m - 1 , & replace_to ) ; if ( NULL != replace_to ) { * ( m - 1 ) = ' \0 ' ; str_out = zbx_strdcat ( str_out , p ) ; * ( m - 1 ) = ' ' ; str_out = zbx_strdcat ( str_out , replace_to ) ; zbx_free ( replace_to ) ; } else str_out = zbx_strdcat ( str_out , p ) ; * n = c ; p = n ; } else { if ( 0 == warning && ' ' <= * ( m + 1 ) && * ( m + 1 ) <= ' ' ) { zabbix_log ( LOG_LEVEL_WARNING , " " " " " " , key ) ; warning = 1 ; } c = * ++ m ; * m = ' \0 ' ; str_out = zbx_strdcat ( str_out , p ) ; * m = c ; p = m ; } } if ( NULL != str_out ) { str_out = zbx_strdcat ( str_out , p ) ; zbx_free ( * data ) ; * data = str_out ; } out : free_request ( & request ) ; }
Function: item_description                                                 
                                                                            
 Purpose: substitute key parameters and user macros in                      
          the item description string with real values
Function : item_description Purpose : substitute key parameters and user macros in the item description string with real values
/* user macros */ /* macros $1, $2, ... */ /* just a dollar sign */