mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Move CListener and CRealListener into their own files
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1924 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
58
Listener.cpp
Normal file
58
Listener.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2010 See the AUTHORS file for details.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "Listener.h"
|
||||
|
||||
bool CListener::Listen() {
|
||||
if (!m_uPort || m_pListener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pListener = new CRealListener(this);
|
||||
|
||||
bool bSSL = false;
|
||||
#ifdef HAVE_LIBSSL
|
||||
if (IsSSL()) {
|
||||
bSSL = true;
|
||||
m_pListener->SetPemLocation(CZNC::Get().GetPemLocation());
|
||||
}
|
||||
#endif
|
||||
|
||||
return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN,
|
||||
m_pListener, 0, m_eAddr);
|
||||
}
|
||||
|
||||
CRealListener::~CRealListener() {
|
||||
m_pParent->SetRealListener(NULL);
|
||||
}
|
||||
|
||||
bool CRealListener::ConnectionFrom(const CString& sHost, unsigned short uPort) {
|
||||
bool bHostAllowed = CZNC::Get().IsHostAllowed(sHost);
|
||||
DEBUG(GetSockName() << " == ConnectionFrom(" << sHost << ", " << uPort << ") [" << (bHostAllowed ? "Allowed" : "Not allowed") << "]");
|
||||
return bHostAllowed;
|
||||
}
|
||||
|
||||
Csock* CRealListener::GetSockObj(const CString& sHost, unsigned short uPort) {
|
||||
CClient *pClient = new CClient(sHost, uPort);
|
||||
if (CZNC::Get().AllowConnectionFrom(sHost)) {
|
||||
CZNC::Get().GetModules().OnClientConnect(pClient, sHost, uPort);
|
||||
} else {
|
||||
pClient->RefuseLogin("Too many anonymous connections from your IP");
|
||||
CZNC::Get().GetModules().OnFailedLogin("", sHost);
|
||||
}
|
||||
return pClient;
|
||||
}
|
||||
|
||||
void CRealListener::SockError(int iErrno) {
|
||||
DEBUG(GetSockName() << " == SockError(" << strerror(iErrno) << ")");
|
||||
if (iErrno == EMFILE) {
|
||||
// We have too many open fds, let's close this listening port to be able to continue
|
||||
// to work, next rehash will (try to) reopen it.
|
||||
Close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user