diff options
author | Jurijs Klopovskis <jurijs.klopovskis@zabbix.com> | 2022-06-16 14:01:11 +0300 |
---|---|---|
committer | Jurijs Klopovskis <jurijs.klopovskis@zabbix.com> | 2022-06-16 14:01:11 +0300 |
commit | 58a3ef49d1c32fcf8c6f9e6e225810be4ce35235 (patch) | |
tree | e2ae9f73b0a8a02013a3f1e1e15e1804a0c7c5c7 | |
parent | 77a9334ce8313611dae33800dfa123baadd33629 (diff) |
...GI..PS. [ZBX-21064] reimplemented changes that were left out of previous cherry-pick commit
-rw-r--r-- | include/common.h | 5 | ||||
-rw-r--r-- | src/libs/zbxcommon/comms.c | 92 | ||||
-rw-r--r-- | src/zabbix_proxy/Makefile.am | 1 | ||||
-rw-r--r-- | src/zabbix_server/Makefile.am | 1 | ||||
-rw-r--r-- | src/zabbix_server/trapper/trapper.c | 92 |
5 files changed, 94 insertions, 97 deletions
diff --git a/include/common.h b/include/common.h index 513d00d84bc..35d9b84d089 100644 --- a/include/common.h +++ b/include/common.h @@ -1253,11 +1253,6 @@ void xml_free_data_dyn(char **data); char *xml_escape_dyn(const char *data); void xml_escape_xpath(char **data); -int comms_parse_response(char *xml, char *host, size_t host_len, char *key, size_t key_len, - char *data, size_t data_len, char *lastlogsize, size_t lastlogsize_len, - char *timestamp, size_t timestamp_len, char *source, size_t source_len, - char *severity, size_t severity_len); - /* misc functions */ int is_ip6(const char *ip); int is_ip4(const char *ip); diff --git a/src/libs/zbxcommon/comms.c b/src/libs/zbxcommon/comms.c index ba3277885a4..d72125e31bf 100644 --- a/src/libs/zbxcommon/comms.c +++ b/src/libs/zbxcommon/comms.c @@ -18,98 +18,6 @@ **/ #include "common.h" -#include "base64.h" - -int comms_parse_response(char *xml, char *host, size_t host_len, char *key, size_t key_len, - char *data, size_t data_len, char *lastlogsize, size_t lastlogsize_len, - char *timestamp, size_t timestamp_len, char *source, size_t source_len, - char *severity, size_t severity_len) -{ - int i, ret = SUCCEED; - char *data_b64 = NULL; - - assert(NULL != host && 0 != host_len); - assert(NULL != key && 0 != key_len); - assert(NULL != data && 0 != data_len); - assert(NULL != lastlogsize && 0 != lastlogsize_len); - assert(NULL != timestamp && 0 != timestamp_len); - assert(NULL != source && 0 != source_len); - assert(NULL != severity && 0 != severity_len); - - if (SUCCEED == xml_get_data_dyn(xml, "host", &data_b64)) - { - str_base64_decode(data_b64, host, (int)host_len - 1, &i); - host[i] = '\0'; - xml_free_data_dyn(&data_b64); - } - else - { - *host = '\0'; - ret = FAIL; - } - - if (SUCCEED == xml_get_data_dyn(xml, "key", &data_b64)) - { - str_base64_decode(data_b64, key, (int)key_len - 1, &i); - key[i] = '\0'; - xml_free_data_dyn(&data_b64); - } - else - { - *key = '\0'; - ret = FAIL; - } - - if (SUCCEED == xml_get_data_dyn(xml, "data", &data_b64)) - { - str_base64_decode(data_b64, data, (int)data_len - 1, &i); - data[i] = '\0'; - xml_free_data_dyn(&data_b64); - } - else - { - *data = '\0'; - ret = FAIL; - } - - if (SUCCEED == xml_get_data_dyn(xml, "lastlogsize", &data_b64)) - { - str_base64_decode(data_b64, lastlogsize, (int)lastlogsize_len - 1, &i); - lastlogsize[i] = '\0'; - xml_free_data_dyn(&data_b64); - } - else - *lastlogsize = '\0'; - - if (SUCCEED == xml_get_data_dyn(xml, "timestamp", &data_b64)) - { - str_base64_decode(data_b64, timestamp, (int)timestamp_len - 1, &i); - timestamp[i] = '\0'; - xml_free_data_dyn(&data_b64); - } - else - *timestamp = '\0'; - - if (SUCCEED == xml_get_data_dyn(xml, "source", &data_b64)) - { - str_base64_decode(data_b64, source, (int)source_len - 1, &i); - source[i] = '\0'; - xml_free_data_dyn(&data_b64); - } - else - *source = '\0'; - - if (SUCCEED == xml_get_data_dyn(xml, "severity", &data_b64)) - { - str_base64_decode(data_b64, severity, (int)severity_len - 1, &i); - severity[i] = '\0'; - xml_free_data_dyn(&data_b64); - } - else - *severity = '\0'; - - return ret; -} /****************************************************************************** * * diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am index 5a6c77d98b9..cdcda13c83b 100644 --- a/src/zabbix_proxy/Makefile.am +++ b/src/zabbix_proxy/Makefile.am @@ -67,6 +67,7 @@ zabbix_proxy_LDADD = \ $(top_builddir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_builddir)/src/libs/zbxcrypto/libzbxcrypto.a \ $(top_builddir)/src/libs/zbxcomms/libzbxcomms.a \ + $(top_builddir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_builddir)/src/libs/zbxcommshigh/libzbxcommshigh.a \ $(top_builddir)/src/libs/zbxjson/libzbxjson.a \ $(top_builddir)/src/libs/zbxhttp/libzbxhttp.a \ diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am index 96e778f8b44..23d1430c2db 100644 --- a/src/zabbix_server/Makefile.am +++ b/src/zabbix_server/Makefile.am @@ -101,6 +101,7 @@ zabbix_server_LDADD = \ $(top_builddir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_builddir)/src/libs/zbxcrypto/libzbxcrypto.a \ $(top_builddir)/src/libs/zbxcomms/libzbxcomms.a \ + $(top_builddir)/src/libs/zbxcommon/libzbxcommon.a \ $(top_builddir)/src/libs/zbxcommshigh/libzbxcommshigh.a \ $(top_builddir)/src/libs/zbxjson/libzbxjson.a \ $(top_builddir)/src/libs/zbxhttp/libzbxhttp.a \ diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c index 669365ba018..e52f7e22340 100644 --- a/src/zabbix_server/trapper/trapper.c +++ b/src/zabbix_server/trapper/trapper.c @@ -35,6 +35,7 @@ #include "trapper_expressions_evaluate.h" #include "trapper_item_test.h" #include "trapper_request.h" +#include "base64.h" #ifdef HAVE_NETSNMP # include "zbxrtc.h" @@ -949,6 +950,97 @@ static void active_passive_misconfig(zbx_socket_t *sock) zbx_free(msg); } +static int comms_parse_response(char *xml, char *host, size_t host_len, char *key, size_t key_len, + char *data, size_t data_len, char *lastlogsize, size_t lastlogsize_len, + char *timestamp, size_t timestamp_len, char *source, size_t source_len, + char *severity, size_t severity_len) +{ + int i, ret = SUCCEED; + char *data_b64 = NULL; + + assert(NULL != host && 0 != host_len); + assert(NULL != key && 0 != key_len); + assert(NULL != data && 0 != data_len); + assert(NULL != lastlogsize && 0 != lastlogsize_len); + assert(NULL != timestamp && 0 != timestamp_len); + assert(NULL != source && 0 != source_len); + assert(NULL != severity && 0 != severity_len); + + if (SUCCEED == xml_get_data_dyn(xml, "host", &data_b64)) + { + str_base64_decode(data_b64, host, (int)host_len - 1, &i); + host[i] = '\0'; + xml_free_data_dyn(&data_b64); + } + else + { + *host = '\0'; + ret = FAIL; + } + + if (SUCCEED == xml_get_data_dyn(xml, "key", &data_b64)) + { + str_base64_decode(data_b64, key, (int)key_len - 1, &i); + key[i] = '\0'; + xml_free_data_dyn(&data_b64); + } + else + { + *key = '\0'; + ret = FAIL; + } + + if (SUCCEED == xml_get_data_dyn(xml, "data", &data_b64)) + { + str_base64_decode(data_b64, data, (int)data_len - 1, &i); + data[i] = '\0'; + xml_free_data_dyn(&data_b64); + } + else + { + *data = '\0'; + ret = FAIL; + } + + if (SUCCEED == xml_get_data_dyn(xml, "lastlogsize", &data_b64)) + { + str_base64_decode(data_b64, lastlogsize, (int)lastlogsize_len - 1, &i); + lastlogsize[i] = '\0'; + xml_free_data_dyn(&data_b64); + } + else + *lastlogsize = '\0'; + + if (SUCCEED == xml_get_data_dyn(xml, "timestamp", &data_b64)) + { + str_base64_decode(data_b64, timestamp, (int)timestamp_len - 1, &i); + timestamp[i] = '\0'; + xml_free_data_dyn(&data_b64); + } + else + *timestamp = '\0'; + + if (SUCCEED == xml_get_data_dyn(xml, "source", &data_b64)) + { + str_base64_decode(data_b64, source, (int)source_len - 1, &i); + source[i] = '\0'; + xml_free_data_dyn(&data_b64); + } + else + *source = '\0'; + + if (SUCCEED == xml_get_data_dyn(xml, "severity", &data_b64)) + { + str_base64_decode(data_b64, severity, (int)severity_len - 1, &i); + severity[i] = '\0'; + xml_free_data_dyn(&data_b64); + } + else + *severity = '\0'; + + return ret; +} + static int process_trap(zbx_socket_t *sock, char *s, ssize_t bytes_received, zbx_timespec_t *ts) { int ret = SUCCEED; |