mirror of
https://github.com/znc/znc.git
synced 2026-08-07 01:13:25 +02:00
Instead of (ab)using a CClient for listening, use an own class this job
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1178 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
-11
@@ -601,11 +601,6 @@ bool CClient::SendMotd() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CClient::ConnectionFrom(const CString& sHost, unsigned short uPort) {
|
||||
DEBUG_ONLY(cout << GetSockName() << " == ConnectionFrom(" << sHost << ", " << uPort << ")" << endl);
|
||||
return CZNC::Get().IsHostAllowed(sHost);
|
||||
}
|
||||
|
||||
void CClient::AuthUser() {
|
||||
/*
|
||||
#ifdef _MODULES
|
||||
@@ -729,12 +724,6 @@ void CClient::IRCDisconnected() {
|
||||
m_pIRCSock = NULL;
|
||||
}
|
||||
|
||||
Csock* CClient::GetSockObj(const CString& sHost, unsigned short uPort) {
|
||||
CClient* pSock = new CClient(sHost, uPort);
|
||||
pSock->StartLoginTimeout();
|
||||
return pSock;
|
||||
}
|
||||
|
||||
void CClient::PutIRC(const CString& sLine) {
|
||||
if (m_pIRCSock) {
|
||||
m_pIRCSock->PutIRC(sLine);
|
||||
|
||||
@@ -65,17 +65,7 @@ protected:
|
||||
|
||||
class CClient : public Csock {
|
||||
public:
|
||||
CClient() : Csock() {
|
||||
InitClient();
|
||||
}
|
||||
|
||||
CClient(const CString& sHostname, unsigned short uPort, int iTimeout = 60) : Csock(sHostname, uPort, iTimeout) {
|
||||
InitClient();
|
||||
}
|
||||
|
||||
virtual ~CClient();
|
||||
|
||||
void InitClient() {
|
||||
m_pUser = NULL;
|
||||
m_pTimeout = NULL;
|
||||
m_pIRCSock = NULL;
|
||||
@@ -85,8 +75,12 @@ public:
|
||||
m_bNamesx = false;
|
||||
m_bUHNames = false;
|
||||
EnableReadLine();
|
||||
|
||||
StartLoginTimeout();
|
||||
}
|
||||
|
||||
virtual ~CClient();
|
||||
|
||||
void AcceptLogin(CUser& User);
|
||||
void RefuseLogin(const CString& sReason);
|
||||
void StartLoginTimeout();
|
||||
@@ -118,8 +112,6 @@ public:
|
||||
virtual void Connected();
|
||||
virtual void Disconnected();
|
||||
virtual void ConnectionRefused();
|
||||
virtual bool ConnectionFrom(const CString& sHost, unsigned short uPort);
|
||||
virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort);
|
||||
|
||||
void SetNick(const CString& s);
|
||||
CUser* GetUser() const { return m_pUser; }
|
||||
|
||||
@@ -223,6 +223,21 @@ protected:
|
||||
CConnectUserTimer *m_pConnectUserTimer;
|
||||
};
|
||||
|
||||
class CRealListener : public Csock {
|
||||
public:
|
||||
CRealListener() : Csock() {}
|
||||
~CRealListener() {}
|
||||
|
||||
virtual bool ConnectionFrom(const CString& sHost, unsigned short uPort) {
|
||||
DEBUG_ONLY(cout << GetSockName() << " == ConnectionFrom(" << sHost << ", " << uPort << ")" << endl);
|
||||
return CZNC::Get().IsHostAllowed(sHost);
|
||||
}
|
||||
|
||||
virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort) {
|
||||
return new CClient(sHost, uPort);
|
||||
}
|
||||
};
|
||||
|
||||
class CListener {
|
||||
public:
|
||||
CListener(unsigned short uPort, const CString& sBindHost, bool bSSL, bool bIPV6) {
|
||||
@@ -230,12 +245,12 @@ public:
|
||||
m_sBindHost = sBindHost;
|
||||
m_bSSL = bSSL;
|
||||
m_bIPV6 = bIPV6;
|
||||
m_pClient = NULL;
|
||||
m_pListener = NULL;
|
||||
}
|
||||
|
||||
virtual ~CListener() {
|
||||
if (m_pClient)
|
||||
CZNC::Get().GetManager().DelSockByAddr(m_pClient);
|
||||
if (m_pListener)
|
||||
CZNC::Get().GetManager().DelSockByAddr(m_pListener);
|
||||
}
|
||||
|
||||
// Setters
|
||||
@@ -253,21 +268,22 @@ public:
|
||||
// !Getters
|
||||
|
||||
bool Listen() {
|
||||
if (!m_uPort || m_pClient) {
|
||||
if (!m_uPort || m_pListener) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pClient = new CClient;
|
||||
m_pListener = new CRealListener;
|
||||
|
||||
bool bSSL = false;
|
||||
#ifdef HAVE_LIBSSL
|
||||
if (IsSSL()) {
|
||||
bSSL = true;
|
||||
m_pClient->SetPemLocation(CZNC::Get().GetPemLocation());
|
||||
m_pListener->SetPemLocation(CZNC::Get().GetPemLocation());
|
||||
}
|
||||
#endif
|
||||
|
||||
return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN, m_pClient, 0, m_bIPV6);
|
||||
return CZNC::Get().GetManager().ListenHost(m_uPort, "_LISTENER", m_sBindHost, bSSL, SOMAXCONN,
|
||||
m_pListener, 0, m_bIPV6);
|
||||
}
|
||||
private:
|
||||
protected:
|
||||
@@ -275,7 +291,7 @@ protected:
|
||||
bool m_bIPV6;
|
||||
unsigned short m_uPort;
|
||||
CString m_sBindHost;
|
||||
CClient* m_pClient;
|
||||
CRealListener* m_pListener;
|
||||
};
|
||||
|
||||
#endif // !_ZNC_H
|
||||
|
||||
Reference in New Issue
Block a user