From fed67019b43c57f1ff8a94771fe448b53ecd2372 Mon Sep 17 00:00:00 2001 From: Jan Friesse Date: Mon, 12 Aug 2019 16:45:31 +0200 Subject: [PATCH] qdevice: Merge msg_decode_error functions Signed-off-by: Jan Friesse --- qdevices/Makefile.am | 1 + qdevices/log-common.c | 23 +++++++++++++++++++++++ qdevices/log-common.h | 2 ++ qdevices/log.c | 23 ----------------------- qdevices/log.h | 2 -- qdevices/qdevice-net-msg-received.c | 26 ++------------------------ qdevices/qnetd-client-msg-received.c | 3 ++- 7 files changed, 30 insertions(+), 50 deletions(-) diff --git a/qdevices/Makefile.am b/qdevices/Makefile.am index 806703d..02f0730 100644 --- a/qdevices/Makefile.am +++ b/qdevices/Makefile.am @@ -50,6 +50,7 @@ corosync_qnetd_SOURCES = corosync-qnetd.c \ nss-sock.c nss-sock.h qnetd-client.c qnetd-client.h \ qnetd-client-list.c qnetd-client-list.h log.c log.h \ pr-poll-array.c pr-poll-array.h timer-list.c timer-list.h tlv.c tlv.h \ + log-common.c log-common.h \ send-buffer-list.c send-buffer-list.h node-list.c node-list.h \ qnetd-algo-test.c qnetd-algo-test.h qnetd-algorithm.c qnetd-algorithm.h \ qnetd-algo-utils.c qnetd-algo-utils.h \ diff --git a/qdevices/log-common.c b/qdevices/log-common.c index a4cb593..a4d1246 100644 --- a/qdevices/log-common.c +++ b/qdevices/log-common.c @@ -54,3 +54,26 @@ log_common_debug_dump_node_list(const struct node_list *nlist) zi++; } } + +void +log_common_msg_decode_error(int ret) +{ + + switch (ret) { + case -1: + log(LOG_WARNING, "Received message with option with invalid length"); + break; + case -2: + log(LOG_CRIT, "Can't allocate memory"); + break; + case -3: + log(LOG_WARNING, "Received inconsistent msg (tlv len > msg size)"); + break; + case -4: + log(LOG_WARNING, "Received message with option with invalid value"); + break; + default: + log(LOG_ERR, "Unknown error occurred when decoding message"); + break; + } +} diff --git a/qdevices/log-common.h b/qdevices/log-common.h index 8ccfa93..e0fa483 100644 --- a/qdevices/log-common.h +++ b/qdevices/log-common.h @@ -43,6 +43,8 @@ extern "C" { extern void log_common_debug_dump_node_list(const struct node_list *nlist); +extern void log_common_msg_decode_error(int ret); + #ifdef __cplusplus } #endif diff --git a/qdevices/log.c b/qdevices/log.c index 29847c9..278fafa 100644 --- a/qdevices/log.c +++ b/qdevices/log.c @@ -178,26 +178,3 @@ log_set_target(int target, int syslog_facility) openlog(log_config_ident, LOG_PID, log_config_syslog_facility); } } - -void -log_msg_decode_error(int ret) -{ - - switch (ret) { - case -1: - log(LOG_WARNING, "Received message with option with invalid length"); - break; - case -2: - log(LOG_CRIT, "Can't allocate memory"); - break; - case -3: - log(LOG_WARNING, "Received inconsistent msg (tlv len > msg size)"); - break; - case -4: - log(LOG_WARNING, "Received message with option with invalid value"); - break; - default: - log(LOG_ERR, "Unknown error occurred when decoding message"); - break; - } -} diff --git a/qdevices/log.h b/qdevices/log.h index dc43c9f..f8b9155 100644 --- a/qdevices/log.h +++ b/qdevices/log.h @@ -69,8 +69,6 @@ extern void log_set_priority_bump(int enabled); extern void log_set_target(int target, int syslog_facility); -extern void log_msg_decode_error(int ret); - #ifdef __cplusplus } #endif diff --git a/qdevices/qdevice-net-msg-received.c b/qdevices/qdevice-net-msg-received.c index 14311c5..27a0c10 100644 --- a/qdevices/qdevice-net-msg-received.c +++ b/qdevices/qdevice-net-msg-received.c @@ -33,6 +33,7 @@ */ #include "log.h" +#include "log-common.h" #include "qdevice-net-algorithm.h" #include "qdevice-net-cast-vote-timer.h" #include "qdevice-net-heuristics.h" @@ -83,29 +84,6 @@ qdevice_net_msg_received_check_tls_compatibility(enum tlv_tls_supported server_t return (res); } -static void -qdevice_net_msg_received_log_msg_decode_error(int ret) -{ - - switch (ret) { - case -1: - log(LOG_WARNING, "Received message with option with invalid length"); - break; - case -2: - log(LOG_CRIT, "Can't allocate memory"); - break; - case -3: - log(LOG_WARNING, "Received inconsistent msg (tlv len > msg size)"); - break; - case -4: - log(LOG_ERR, "Received message with option with invalid value"); - break; - default: - log(LOG_ERR, "Unknown error occurred when decoding message"); - break; - } -} - static int qdevice_net_msg_received_unexpected_msg(struct qdevice_net_instance *instance, const struct msg_decoded *msg, const char *msg_str) @@ -881,7 +859,7 @@ qdevice_net_msg_received(struct qdevice_net_instance *instance) /* * Error occurred. Disconnect. */ - qdevice_net_msg_received_log_msg_decode_error(res); + log_common_msg_decode_error(res); log(LOG_ERR, "Disconnecting from server"); instance->disconnect_reason = QDEVICE_NET_DISCONNECT_REASON_MSG_DECODE_ERROR; diff --git a/qdevices/qnetd-client-msg-received.c b/qdevices/qnetd-client-msg-received.c index 1cc1763..84b6866 100644 --- a/qdevices/qnetd-client-msg-received.c +++ b/qdevices/qnetd-client-msg-received.c @@ -35,6 +35,7 @@ #include #include "log.h" +#include "log-common.h" #include "qnetd-algorithm.h" #include "qnetd-instance.h" #include "qnetd-log-debug.h" @@ -1142,7 +1143,7 @@ qnetd_client_msg_received(struct qnetd_instance *instance, struct qnetd_client * /* * Error occurred. Send server error. */ - log_msg_decode_error(res); + log_common_msg_decode_error(res); log(LOG_INFO, "Sending back error message"); if (qnetd_client_send_err(client, msg.seq_number_set, msg.seq_number,