zabbix-agent2/src/libs/zbxeval/misc.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_get_serialized_expression_functionids                        *
 *                                                                            *
 * Purpose: extract functionids from serialized expression                    *
 *                                                                            *
 * Parameters: expression  - [IN] the original expression                     *
 *             data        - [IN] the serialized expression                   *
 *             functionids - [OUT] the extracted functionids                  *
 *                                                                            *
 ******************************************************************************/
zbx_get_serialized_expression_functionids

Purpose: extract functionids from serialized expression

Parameters: expression  - [IN] the original expression
data        - [IN] the serialized expression
functionids - [OUT] the extracted functionids
zbx_get_serialized_expression_functionids Purpose : extract functionids from serialized expression Parameters : expression - [ IN ] the original expression data - [ IN ] the serialized expression functionids - [ OUT ] the extracted functionids
void	zbx_get_serialized_expression_functionids(const char *expression, const unsigned char *data,
	zbx_vector_uint64_t *functionids)
{
	zbx_uint32_t		i, tokens_num, len, loc_l, loc_r, opt;
	zbx_token_type_t	type;
	zbx_uint64_t		functionid;
	unsigned char		var_type;
	data += zbx_deserialize_uint31_compact(data, &len);
	data += zbx_deserialize_uint31_compact(data, &tokens_num);
	for (i = 0; i < tokens_num; i++)
	{
		data += zbx_deserialize_value(data, &type);
		data += zbx_deserialize_uint31_compact(data, &opt);
		data += zbx_deserialize_uint31_compact(data, &loc_l);
		data += zbx_deserialize_uint31_compact(data, &loc_r);
		data += zbx_deserialize_char(data, &var_type);
		switch (var_type)
		{
			case ZBX_VARIANT_UI64:
				data += sizeof(zbx_uint64_t);
				break;
			case ZBX_VARIANT_DBL:
				data += sizeof(double);
				break;
			case ZBX_VARIANT_STR:
				data += strlen((const char *)data) + 1;
				break;
			case ZBX_VARIANT_NONE:
				break;
			default:
				THIS_SHOULD_NEVER_HAPPEN;
				return;
		}
		if (ZBX_EVAL_TOKEN_FUNCTIONID == type)
		{
			if (SUCCEED == is_uint64_n(expression + loc_l + 1, loc_r - loc_l - 1, &functionid))
				zbx_vector_uint64_append(functionids, functionid);
			else
				THIS_SHOULD_NEVER_HAPPEN;
		}
	}
	zbx_vector_uint64_sort(functionids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
	zbx_vector_uint64_uniq(functionids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
}
void zbx_get_serialized_expression_functionids ( const char * expression , const unsigned char * data , zbx_vector_uint64_t * functionids ) { zbx_uint32_t i , tokens_num , len , loc_l , loc_r , opt ; zbx_token_type_t type ; zbx_uint64_t functionid ; unsigned char var_type ; data += zbx_deserialize_uint31_compact ( data , & len ) ; data += zbx_deserialize_uint31_compact ( data , & tokens_num ) ; for ( i = 0 ; i < tokens_num ; i ++ ) { data += zbx_deserialize_value ( data , & type ) ; data += zbx_deserialize_uint31_compact ( data , & opt ) ; data += zbx_deserialize_uint31_compact ( data , & loc_l ) ; data += zbx_deserialize_uint31_compact ( data , & loc_r ) ; data += zbx_deserialize_char ( data , & var_type ) ; switch ( var_type ) { case ZBX_VARIANT_UI64 : data += sizeof ( zbx_uint64_t ) ; break ; case ZBX_VARIANT_DBL : data += sizeof ( double ) ; break ; case ZBX_VARIANT_STR : data += strlen ( ( const char * ) data ) + 1 ; break ; case ZBX_VARIANT_NONE : break ; default : THIS_SHOULD_NEVER_HAPPEN ; return ; } if ( ZBX_EVAL_TOKEN_FUNCTIONID == type ) { if ( SUCCEED == is_uint64_n ( expression + loc_l + 1 , loc_r - loc_l - 1 , & functionid ) ) zbx_vector_uint64_append ( functionids , functionid ) ; else THIS_SHOULD_NEVER_HAPPEN ; } } zbx_vector_uint64_sort ( functionids , ZBX_DEFAULT_UINT64_COMPARE_FUNC ) ; zbx_vector_uint64_uniq ( functionids , ZBX_DEFAULT_UINT64_COMPARE_FUNC ) ; }
Function: zbx_get_serialized_expression_functionids                        
                                                                            
 Purpose: extract functionids from serialized expression                    
                                                                            
 Parameters: expression  - [IN] the original expression                     
             data        - [IN] the serialized expression                   
             functionids - [OUT] the extracted functionids
Function : zbx_get_serialized_expression_functionids Purpose : extract functionids from serialized expression Parameters : expression - [ IN ] the original expression data - [ IN ] the serialized expression functionids - [ OUT ] the extracted functionids