From b8d99f2674a3dc5dccb7cf70d8e2cad4fc9ea391 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 12 Jan 2017 11:00:37 +0100 Subject: [PATCH] Implement CListener::ToConfig() This will later reduce some code duplication. Signed-off-by: Uli Schlachter --- include/znc/Listener.h | 2 +- src/Listener.cpp | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/znc/Listener.h b/include/znc/Listener.h index 92d2f581..c16ef1c1 100644 --- a/include/znc/Listener.h +++ b/include/znc/Listener.h @@ -53,7 +53,7 @@ class CListener { virtual bool Listen() = 0; void ResetRealListener(); - virtual CConfig ToConfig() const = 0; + virtual CConfig ToConfig() const; private: protected: diff --git a/src/Listener.cpp b/src/Listener.cpp index a8cce98a..40b8e388 100644 --- a/src/Listener.cpp +++ b/src/Listener.cpp @@ -22,6 +22,23 @@ CListener::~CListener() { if (m_pListener) CZNC::Get().GetManager().DelSockByAddr(m_pListener); } +CConfig CListener::ToConfig() const { + CConfig listenerConfig; + + listenerConfig.AddKeyValuePair("URIPrefix", GetURIPrefix() + "/"); + + listenerConfig.AddKeyValuePair("SSL", CString(IsSSL())); + + listenerConfig.AddKeyValuePair( + "AllowIRC", + CString(GetAcceptType() != CListener::ACCEPT_HTTP)); + listenerConfig.AddKeyValuePair( + "AllowWeb", + CString(GetAcceptType() != CListener::ACCEPT_IRC)); + + return listenerConfig; +} + CTCPListener::~CTCPListener() { } @@ -53,10 +70,9 @@ bool CTCPListener::Listen() { } CConfig CTCPListener::ToConfig() const { - CConfig listenerConfig; + CConfig listenerConfig = CListener::ToConfig(); listenerConfig.AddKeyValuePair("Host", GetBindHost()); - listenerConfig.AddKeyValuePair("URIPrefix", GetURIPrefix() + "/"); listenerConfig.AddKeyValuePair("Port", CString(GetPort())); listenerConfig.AddKeyValuePair( @@ -64,15 +80,6 @@ CConfig CTCPListener::ToConfig() const { listenerConfig.AddKeyValuePair( "IPv6", CString(GetAddrType() != ADDR_IPV4ONLY)); - listenerConfig.AddKeyValuePair("SSL", CString(IsSSL())); - - listenerConfig.AddKeyValuePair( - "AllowIRC", - CString(GetAcceptType() != CListener::ACCEPT_HTTP)); - listenerConfig.AddKeyValuePair( - "AllowWeb", - CString(GetAcceptType() != CListener::ACCEPT_IRC)); - return listenerConfig; }