static int calcitem_parse_expression(DC_ITEM *dc_item, expression_t *exp, char *error, int max_error_len) { const char *__function_name = "calcitem_parse_expression"; char *e, *f, *func = NULL, *params = NULL; int functionid, exp_alloc = 128, exp_offset = 0, ret; zabbix_log(LOG_LEVEL_DEBUG, "In %s() expression:'%s'", __function_name, dc_item->params_orig); assert(dc_item); assert(exp); exp->exp = zbx_malloc(exp->exp, exp_alloc); for (e = dc_item->params_orig; '\0' != *e; e++) { if (NULL != strchr(" \t\r\n", *e)) continue; f = e; if (FAIL == parse_function(&e, &func, ¶ms)) { e = f; calcitem_exp_addchr(&exp->exp, &exp_alloc, &exp_offset, 128, *f); continue; } else e--; functionid = calcitem_add_function(exp, func, params); zabbix_log(LOG_LEVEL_DEBUG, "%s() functionid:%d function:'%s(%s)'", __function_name, functionid, func, params); func = NULL; params = NULL; zbx_snprintf_alloc(&exp->exp, &exp_alloc, &exp_offset, 16, "{%d}", functionid); } calcitem_exp_addchr(&exp->exp, &exp_alloc, &exp_offset, 1, '\0'); zabbix_log(LOG_LEVEL_DEBUG, "%s() expression:'%s'", __function_name, exp->exp); if (FAIL == (ret = substitute_simple_macros(NULL, NULL, NULL, dc_item, NULL, &exp->exp, MACRO_TYPE_ITEM_EXPRESSION, error, max_error_len))) ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
static int calcitem_parse_expression(DC_ITEM *dc_item, expression_t *exp, char *error, int max_error_len) { const char *__function_name = "calcitem_parse_expression"; char *e, *f, *func = NULL, *params = NULL; size_t exp_alloc = 128, exp_offset = 0, len; int functionid, ret; zabbix_log(LOG_LEVEL_DEBUG, "In %s() expression:'%s'", __function_name, dc_item->params); assert(dc_item); assert(exp); exp->exp = zbx_malloc(exp->exp, exp_alloc); for (e = dc_item->params; '\0' != *e; e++) { if (SUCCEED != is_function_char(*e)) { zbx_chrcpy_alloc(&exp->exp, &exp_alloc, &exp_offset, *e); continue; } if ((0 == strncmp("and", e, len = 3) || 0 == strncmp("not", e, 3) || 0 == strncmp("or", e, len = 2)) && NULL != strchr("()" ZBX_WHITESPACE, e[len])) { zbx_strncpy_alloc(&exp->exp, &exp_alloc, &exp_offset, e, len); e += len - 1; continue; } f = e; if (SUCCEED != parse_function(&e, &func, ¶ms)) { e = f; zbx_chrcpy_alloc(&exp->exp, &exp_alloc, &exp_offset, *f); continue; } else e--; functionid = calcitem_add_function(exp, func, params); zabbix_log(LOG_LEVEL_DEBUG, "%s() functionid:%d function:'%s(%s)'", __function_name, functionid, func, params); func = NULL; params = NULL; zbx_snprintf_alloc(&exp->exp, &exp_alloc, &exp_offset, "{%d}", functionid); } zabbix_log(LOG_LEVEL_DEBUG, "%s() expression:'%s'", __function_name, exp->exp); if (FAIL == (ret = substitute_simple_macros(NULL, NULL, NULL, NULL, NULL, &dc_item->host, NULL, NULL, &exp->exp, MACRO_TYPE_ITEM_EXPRESSION, error, max_error_len))) ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }