zabbix-agent2/src/libs/zbxdbcache/dbconfig.c
/******************************************************************************
 *                                                                            *
 * Function: dc_expand_user_macros                                            *
 *                                                                            *
 * Purpose: expand user macros in the specified text value                    *
 * WARNING - DO NOT USE FOR TRIGGERS, for triggers use the dedicated function *
 *                                                                            *
 * Parameters: text           - [IN] the text value to expand                 *
 *             hostids        - [IN] an array of related hostids              *
 *             hostids_num    - [IN] the number of hostids                    *
 *                                                                            *
 * Return value: The text value with expanded user macros. Unknown or invalid *
 *               macros will be left unresolved.                              *
 *                                                                            *
 * Comments: The returned value must be freed by the caller.                  *
 *           This function must be used only by configuration syncer          *
 *                                                                            *
 ******************************************************************************/
dc_expand_user_macros

Purpose: expand user macros in the specified text value
WARNING - DO NOT USE FOR TRIGGERS, for triggers use the dedicated function

Parameters: text           - [IN] the text value to expand
hostids        - [IN] an array of related hostids
hostids_num    - [IN] the number of hostids

Return value: The text value with expanded user macros. Unknown or invalid
macros will be left unresolved.

Comments: The returned value must be freed by the caller.
This function must be used only by configuration syncer
dc_expand_user_macros Purpose : expand user macros in the specified text value WARNING - DO NOT USE FOR TRIGGERS for triggers use the dedicated function Parameters : text - [ IN ] the text value to expand hostids - [ IN ] an array of related hostids hostids_num - [ IN ] the number of hostids Return value : The text value with expanded user macros . Unknown or invalid macros will be left unresolved . Comments : The returned value must be freed by the caller . This function must be used only by configuration syncer
char	*dc_expand_user_macros(const char *text, zbx_uint64_t *hostids, int hostids_num)
{
	zbx_token_t	token;
	int		pos = 0, len, last_pos = 0;
	char		*str = NULL, *name = NULL, *context = NULL, *value = NULL;
	size_t		str_alloc = 0, str_offset = 0;
	if ('\0' == *text)
		return zbx_strdup(NULL, text);
	for (; SUCCEED == zbx_token_find(text, pos, &token, ZBX_TOKEN_SEARCH_BASIC); pos++)
	{
		if (ZBX_TOKEN_USER_MACRO != token.type)
			continue;
		if (SUCCEED != zbx_user_macro_parse_dyn(text + token.loc.l, &name, &context, &len, NULL))
			continue;
		zbx_strncpy_alloc(&str, &str_alloc, &str_offset, text + last_pos, token.loc.l - last_pos);
		dc_get_user_macro(hostids, hostids_num, name, context, &value);
		if (NULL != value)
		{
			zbx_strcpy_alloc(&str, &str_alloc, &str_offset, value);
			zbx_free(value);
		}
		else
		{
			zbx_strncpy_alloc(&str, &str_alloc, &str_offset, text + token.loc.l,
					token.loc.r - token.loc.l + 1);
		}
		zbx_free(name);
		zbx_free(context);
		pos = token.loc.r;
		last_pos = pos + 1;
	}
	zbx_strcpy_alloc(&str, &str_alloc, &str_offset, text + last_pos);
	return str;
}
char * dc_expand_user_macros ( const char * text , zbx_uint64_t * hostids , int hostids_num ) { zbx_token_t token ; int pos = 0 , len , last_pos = 0 ; char * str = NULL , * name = NULL , * context = NULL , * value = NULL ; size_t str_alloc = 0 , str_offset = 0 ; if ( ' \0 ' == * text ) return zbx_strdup ( NULL , text ) ; for ( ; SUCCEED == zbx_token_find ( text , pos , & token , ZBX_TOKEN_SEARCH_BASIC ) ; pos ++ ) { if ( ZBX_TOKEN_USER_MACRO != token . type ) continue ; if ( SUCCEED != zbx_user_macro_parse_dyn ( text + token . loc . l , & name , & context , & len , NULL ) ) continue ; zbx_strncpy_alloc ( & str , & str_alloc , & str_offset , text + last_pos , token . loc . l - last_pos ) ; dc_get_user_macro ( hostids , hostids_num , name , context , & value ) ; if ( NULL != value ) { zbx_strcpy_alloc ( & str , & str_alloc , & str_offset , value ) ; zbx_free ( value ) ; } else { zbx_strncpy_alloc ( & str , & str_alloc , & str_offset , text + token . loc . l , token . loc . r - token . loc . l + 1 ) ; } zbx_free ( name ) ; zbx_free ( context ) ; pos = token . loc . r ; last_pos = pos + 1 ; } zbx_strcpy_alloc ( & str , & str_alloc , & str_offset , text + last_pos ) ; return str ; }
Function: dc_expand_user_macros                                            
                                                                            
 Purpose: expand user macros in the specified text value                    
 WARNING - DO NOT USE FOR TRIGGERS, for triggers use the dedicated function 
                                                                            
 Parameters: text           - [IN] the text value to expand                 
             hostids        - [IN] an array of related hostids              
             hostids_num    - [IN] the number of hostids                    
                                                                            
 Return value: The text value with expanded user macros.
Function : dc_expand_user_macros Purpose : expand user macros in the specified text value WARNING - DO NOT USE FOR TRIGGERS for triggers use the dedicated function Parameters : text - [ IN ] the text value to expand hostids - [ IN ] an array of related hostids hostids_num - [ IN ] the number of hostids Return value : The text value with expanded user macros .