diff options
-rw-r--r-- | include/alias.h | 4 | ||||
-rw-r--r-- | src/libs/zbxcommon/alias.c | 32 |
2 files changed, 26 insertions, 10 deletions
diff --git a/include/alias.h b/include/alias.h index 6e07ec24a16..95ec768f569 100644 --- a/include/alias.h +++ b/include/alias.h @@ -20,12 +20,10 @@ #ifndef ZABBIX_ALIAS_H #define ZABBIX_ALIAS_H -#define MAX_ALIAS_NAME 120 - typedef struct zbx_alias { struct zbx_alias *next; - char name[MAX_ALIAS_NAME]; + char *name; char *value; } ALIAS; diff --git a/src/libs/zbxcommon/alias.c b/src/libs/zbxcommon/alias.c index 532231540ce..478fc66fee8 100644 --- a/src/libs/zbxcommon/alias.c +++ b/src/libs/zbxcommon/alias.c @@ -36,19 +36,14 @@ void add_alias(const char *name, const char *value) { ALIAS *alias = NULL; - assert(name); - assert(value); - for (alias = aliasList; ; alias = alias->next) { /* add new Alias */ if (NULL == alias) { alias = (ALIAS *)zbx_malloc(alias, sizeof(ALIAS)); - memset(alias, 0, sizeof(ALIAS)); - - zbx_strlcpy(alias->name, name, MAX_ALIAS_NAME - 1); + alias->name = strdup(name); alias->value = strdup(value); alias->next = aliasList; aliasList = alias; @@ -77,6 +72,7 @@ void alias_list_free() curr = next; next = curr->next; zbx_free(curr->value); + zbx_free(curr->name); zbx_free(curr); } @@ -85,7 +81,11 @@ void alias_list_free() const char *zbx_alias_get(const char *orig) { - ALIAS *alias; + ALIAS *alias; + size_t len_name, len_value; + ZBX_THREAD_LOCAL static char *buffer = NULL; + ZBX_THREAD_LOCAL static size_t buffer_alloc = 0; + size_t buffer_offset = 0; for (alias = aliasList; NULL != alias; alias = alias->next) { @@ -93,5 +93,23 @@ const char *zbx_alias_get(const char *orig) return alias->value; } + for (alias = aliasList; NULL != alias; alias = alias->next) + { + len_name = strlen(alias->name); + if (0 != strcmp(alias->name + len_name - 3, "[*]")) + continue; + + if (0 != strncmp(alias->name, orig, len_name - 2)) + continue; + + len_value = strlen(alias->value); + if (0 != strcmp(alias->value + len_value - 3, "[*]")) + return alias->value; + + zbx_strncpy_alloc(&buffer, &buffer_alloc, &buffer_offset, alias->value, len_value - 3); + zbx_strcpy_alloc(&buffer, &buffer_alloc, &buffer_offset, orig + len_name - 3); + return buffer; + } + return orig; } |