zabbix-agent2/src/libs/zbxdbupgrade/dbupgrade_5030.c
/******************************************************************************
 *                                                                            *
 * Function: dbpatch_update_expression                                        *
 *                                                                            *
 * Purpose: replace {functionid} occurrences in expression with the specified *
 *          replacement string                                                *
 *                                                                            *
 * Return value: SUCCEED - expression was changed                             *
 *               FAIL - otherwise                                             *
 *                                                                            *
 ******************************************************************************/
dbpatch_update_expression

Purpose: replace {functionid} occurrences in expression with the specified
replacement string

Return value: SUCCEED - expression was changed
FAIL - otherwise
dbpatch_update_expression Purpose : replace { functionid } occurrences in expression with the specified replacement string Return value : SUCCEED - expression was changed FAIL - otherwise
static int	dbpatch_update_expression(char **expression, zbx_uint64_t functionid, const char *replace)
{
	int		pos = 0, last_pos = 0;
	zbx_token_t	token;
	char		*out = NULL;
	size_t		out_alloc = 0, out_offset = 0;
	zbx_uint64_t	id;
	for (; SUCCEED == zbx_token_find(*expression, pos, &token, ZBX_TOKEN_SEARCH_FUNCTIONID |
			ZBX_TOKEN_SEARCH_SIMPLE_MACRO); pos++)
	{
		switch (token.type)
		{
			case ZBX_TOKEN_OBJECTID:
				if (SUCCEED == is_uint64_n(*expression + token.data.objectid.name.l,
						token.data.objectid.name.r - token.data.objectid.name.l + 1, &id) &&
						functionid == id)
				{
					zbx_strncpy_alloc(&out, &out_alloc, &out_offset,
							*expression + last_pos, token.loc.l - last_pos);
					zbx_strcpy_alloc(&out, &out_alloc, &out_offset, replace);
					last_pos = token.loc.r + 1;
				}
				pos = token.loc.r;
				break;
			case ZBX_TOKEN_MACRO:
			case ZBX_TOKEN_USER_MACRO:
			case ZBX_TOKEN_LLD_MACRO:
				pos = token.loc.r;
				break;
		}
	}
	if (NULL == out)
		return FAIL;
	zbx_strcpy_alloc(&out, &out_alloc, &out_offset, *expression + last_pos);
	zbx_free(*expression);
	*expression = out;
	return SUCCEED;
}
static int dbpatch_update_expression ( char * * expression , zbx_uint64_t functionid , const char * replace ) { int pos = 0 , last_pos = 0 ; zbx_token_t token ; char * out = NULL ; size_t out_alloc = 0 , out_offset = 0 ; zbx_uint64_t id ; for ( ; SUCCEED == zbx_token_find ( * expression , pos , & token , ZBX_TOKEN_SEARCH_FUNCTIONID | ZBX_TOKEN_SEARCH_SIMPLE_MACRO ) ; pos ++ ) { switch ( token . type ) { case ZBX_TOKEN_OBJECTID : if ( SUCCEED == is_uint64_n ( * expression + token . data . objectid . name . l , token . data . objectid . name . r - token . data . objectid . name . l + 1 , & id ) && functionid == id ) { zbx_strncpy_alloc ( & out , & out_alloc , & out_offset , * expression + last_pos , token . loc . l - last_pos ) ; zbx_strcpy_alloc ( & out , & out_alloc , & out_offset , replace ) ; last_pos = token . loc . r + 1 ; } pos = token . loc . r ; break ; case ZBX_TOKEN_MACRO : case ZBX_TOKEN_USER_MACRO : case ZBX_TOKEN_LLD_MACRO : pos = token . loc . r ; break ; } } if ( NULL == out ) return FAIL ; zbx_strcpy_alloc ( & out , & out_alloc , & out_offset , * expression + last_pos ) ; zbx_free ( * expression ) ; * expression = out ; return SUCCEED ; }
Function: dbpatch_update_expression                                        
                                                                            
 Purpose: replace {functionid} occurrences in expression with the specified 
          replacement string                                                
                                                                            
 Return value: SUCCEED - expression was changed                             
               FAIL - otherwise
Function : dbpatch_update_expression Purpose : replace { functionid } occurrences in expression with the specified replacement string Return value : SUCCEED - expression was changed FAIL - otherwise