zabbix-agent2/src/libs/zbxeval/misc.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_eval_deserialize_dyn                                         *
 *                                                                            *
 * Purpose: deserialize expression and extract specified tokens into values   *
 *                                                                            *
 * Parameters: data       - [IN] the serialized expression                    *
 *             expression - [IN] the original expression                      *
 *             mask       - [IN] the tokens to extract                        *
 *                                                                            *
 * Return value: Expression evaluation context.                               *
 *                                                                            *
 ******************************************************************************/
zbx_eval_deserialize_dyn

Purpose: deserialize expression and extract specified tokens into values

Parameters: data       - [IN] the serialized expression
expression - [IN] the original expression
mask       - [IN] the tokens to extract

Return value: Expression evaluation context.
zbx_eval_deserialize_dyn Purpose : deserialize expression and extract specified tokens into values Parameters : data - [ IN ] the serialized expression expression - [ IN ] the original expression mask - [ IN ] the tokens to extract Return value : Expression evaluation context .
zbx_eval_context_t	*zbx_eval_deserialize_dyn(const unsigned char *data, const char *expression,
		zbx_uint64_t mask)
{
	zbx_eval_context_t	*ctx;
	int			i;
	zbx_uint64_t		functionid;
	char			*value;
	ctx = (zbx_eval_context_t *)zbx_malloc(NULL, sizeof(zbx_eval_context_t));
	zbx_eval_deserialize(ctx, expression, ZBX_EVAL_TRIGGER_EXPRESSION, data);
	for (i = 0; i < ctx->stack.values_num; i++)
	{
		zbx_eval_token_t	*token = &ctx->stack.values[i];
		switch (token->type)
		{
			case ZBX_EVAL_TOKEN_FUNCTIONID:
				if (0 == (mask & ZBX_EVAL_EXTRACT_FUNCTIONID))
					continue;
				expression_extract_functionid(expression, token, &functionid);
				break;
			case ZBX_EVAL_TOKEN_VAR_STR:
				if (0 != (mask & ZBX_EVAL_EXTRACT_VAR_STR) && ZBX_VARIANT_NONE == token->value.type)
				{
					value = zbx_substr_unquote(expression, token->loc.l, token->loc.r);
					zbx_variant_set_str(&token->value, value);
				}
				break;
			case ZBX_EVAL_TOKEN_VAR_MACRO:
				if (0 != (mask & ZBX_EVAL_EXTRACT_VAR_MACRO) && ZBX_VARIANT_NONE == token->value.type)
				{
					value = zbx_substr_unquote(expression, token->loc.l, token->loc.r);
					zbx_variant_set_str(&token->value, value);
				}
				break;
		}
	}
	return ctx;
}
zbx_eval_context_t * zbx_eval_deserialize_dyn ( const unsigned char * data , const char * expression , zbx_uint64_t mask ) { zbx_eval_context_t * ctx ; int i ; zbx_uint64_t functionid ; char * value ; ctx = ( zbx_eval_context_t * ) zbx_malloc ( NULL , sizeof ( zbx_eval_context_t ) ) ; zbx_eval_deserialize ( ctx , expression , ZBX_EVAL_TRIGGER_EXPRESSION , data ) ; for ( i = 0 ; i < ctx -> stack . values_num ; i ++ ) { zbx_eval_token_t * token = & ctx -> stack . values [ i ] ; switch ( token -> type ) { case ZBX_EVAL_TOKEN_FUNCTIONID : if ( 0 == ( mask & ZBX_EVAL_EXTRACT_FUNCTIONID ) ) continue ; expression_extract_functionid ( expression , token , & functionid ) ; break ; case ZBX_EVAL_TOKEN_VAR_STR : if ( 0 != ( mask & ZBX_EVAL_EXTRACT_VAR_STR ) && ZBX_VARIANT_NONE == token -> value . type ) { value = zbx_substr_unquote ( expression , token -> loc . l , token -> loc . r ) ; zbx_variant_set_str ( & token -> value , value ) ; } break ; case ZBX_EVAL_TOKEN_VAR_MACRO : if ( 0 != ( mask & ZBX_EVAL_EXTRACT_VAR_MACRO ) && ZBX_VARIANT_NONE == token -> value . type ) { value = zbx_substr_unquote ( expression , token -> loc . l , token -> loc . r ) ; zbx_variant_set_str ( & token -> value , value ) ; } break ; } } return ctx ; }
Function: zbx_eval_deserialize_dyn                                         
                                                                            
 Purpose: deserialize expression and extract specified tokens into values   
                                                                            
 Parameters: data       - [IN] the serialized expression                    
             expression - [IN] the original expression                      
             mask       - [IN] the tokens to extract                        
                                                                            
 Return value: Expression evaluation context.
Function : zbx_eval_deserialize_dyn Purpose : deserialize expression and extract specified tokens into values Parameters : data - [ IN ] the serialized expression expression - [ IN ] the original expression mask - [ IN ] the tokens to extract Return value : Expression evaluation context .
/* extract string variable value for macro resolving */ /* extract macro for resolving */