CListener: Split out common code to setup ssl

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter
2017-11-02 12:03:08 +01:00
parent 811f453efb
commit b5d77a8ade
2 changed files with 16 additions and 15 deletions

View File

@@ -57,6 +57,8 @@ class CListener {
private:
protected:
void setupSSL(CRealListener* listener) const;
bool m_bSSL;
CString m_sURIPrefix;
CRealListener* m_pListener;

View File

@@ -39,6 +39,17 @@ CConfig CListener::ToConfig() const {
return listenerConfig;
}
void CListener::setupSSL(CRealListener* listener) const {
#ifdef HAVE_LIBSSL
if (IsSSL()) {
m_pListener->SetSSL(true);
m_pListener->SetPemLocation(CZNC::Get().GetPemLocation());
m_pListener->SetKeyLocation(CZNC::Get().GetKeyLocation());
m_pListener->SetDHParamLocation(CZNC::Get().GetDHParamLocation());
}
#endif
}
CTCPListener::~CTCPListener() {
}
@@ -50,14 +61,10 @@ bool CTCPListener::Listen() {
m_pListener = new CRealListener(*this);
setupSSL(m_pListener);
bool bSSL = false;
#ifdef HAVE_LIBSSL
if (IsSSL()) {
bSSL = true;
m_pListener->SetPemLocation(CZNC::Get().GetPemLocation());
m_pListener->SetKeyLocation(CZNC::Get().GetKeyLocation());
m_pListener->SetDHParamLocation(CZNC::Get().GetDHParamLocation());
}
bSSL = IsSSL();
#endif
// If e.g. getaddrinfo() fails, the following might not set errno.
@@ -90,15 +97,7 @@ bool CUnixListener::Listen() {
CString sName = "unix:" + m_sPath;
m_pListener = new CRealListener(*this);
#ifdef HAVE_LIBSSL
if (IsSSL()) {
m_pListener->SetSSL(true);
m_pListener->SetPemLocation(CZNC::Get().GetPemLocation());
m_pListener->SetKeyLocation(CZNC::Get().GetKeyLocation());
m_pListener->SetDHParamLocation(CZNC::Get().GetDHParamLocation());
}
#endif
setupSSL(m_pListener);
CZNC::Get().GetManager().AddSock(m_pListener, sName);
return m_pListener->ListenUnix(m_sPath);