mirror of
https://github.com/znc/znc.git
synced 2026-05-08 22:34:45 +02:00
Partly undo psychon's last commit in favor of just removing all the
setter methods. Suggested by psychon himself. The second and more important part of this patch adds an optional web_only/irc_only token to the Listen config setting. Using this, you can make Listen ports listen for IRC or Web/HTTP connections only (or for both if you don't add any of the _only tokens). Examples: Listen = irc_only 3000 Listen4 = web_only +3001 Listen6 = ::1 6000 and so on. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1973 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
+6
-35
@@ -13,39 +13,6 @@ CListener::~CListener() {
|
||||
CZNC::Get().GetManager().DelSockByAddr(m_pListener);
|
||||
}
|
||||
|
||||
// Settings may not be changed when we are already listening
|
||||
#define CHECK() if (m_pListener) return;
|
||||
|
||||
void CListener::SetSSL(bool b) {
|
||||
CHECK();
|
||||
m_bSSL = b;
|
||||
}
|
||||
|
||||
void CListener::SetAddrType(EAddrType eAddr) {
|
||||
CHECK();
|
||||
m_eAddr = eAddr;
|
||||
}
|
||||
|
||||
void CListener::SetPort(unsigned short u) {
|
||||
CHECK();
|
||||
m_uPort = u;
|
||||
}
|
||||
|
||||
void CListener::SetBindHost(const CString& s) {
|
||||
CHECK();
|
||||
m_sBindHost = s;
|
||||
}
|
||||
|
||||
void CListener::SetRealListener(CRealListener* p) {
|
||||
CHECK();
|
||||
m_pListener = p;
|
||||
}
|
||||
|
||||
void CListener::SetAcceptType(AcceptType a) {
|
||||
CHECK();
|
||||
m_eAcceptType = a;
|
||||
}
|
||||
|
||||
bool CListener::Listen() {
|
||||
if (!m_uPort || m_pListener) {
|
||||
return false;
|
||||
@@ -65,8 +32,12 @@ bool CListener::Listen() {
|
||||
m_pListener, 0, m_eAddr);
|
||||
}
|
||||
|
||||
void CListener::ResetRealListener() {
|
||||
m_pListener = NULL;
|
||||
}
|
||||
|
||||
CRealListener::~CRealListener() {
|
||||
m_pParent->SetRealListener(NULL);
|
||||
m_pParent->ResetRealListener();
|
||||
}
|
||||
|
||||
bool CRealListener::ConnectionFrom(const CString& sHost, unsigned short uPort) {
|
||||
@@ -96,7 +67,7 @@ void CRealListener::SockError(int iErrno) {
|
||||
}
|
||||
}
|
||||
|
||||
CIncomingConnection::CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::AcceptType eAcceptType) : CZNCSock(sHostname, uPort) {
|
||||
CIncomingConnection::CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType) : CZNCSock(sHostname, uPort) {
|
||||
m_eAcceptType = eAcceptType;
|
||||
// The socket will time out in 120 secs, no matter what.
|
||||
// This has to be fixed up later, if desired.
|
||||
|
||||
+8
-16
@@ -21,38 +21,30 @@ public:
|
||||
ACCEPT_IRC,
|
||||
ACCEPT_HTTP,
|
||||
ACCEPT_ALL
|
||||
} AcceptType;
|
||||
} EAcceptType;
|
||||
|
||||
CListener(unsigned short uPort, const CString& sBindHost, bool bSSL, EAddrType eAddr) {
|
||||
CListener(unsigned short uPort, const CString& sBindHost, bool bSSL, EAddrType eAddr, EAcceptType eAccept = ACCEPT_ALL) {
|
||||
m_uPort = uPort;
|
||||
m_sBindHost = sBindHost;
|
||||
m_bSSL = bSSL;
|
||||
m_eAddr = eAddr;
|
||||
m_pListener = NULL;
|
||||
m_eAcceptType = ACCEPT_ALL;
|
||||
m_eAcceptType = eAccept;
|
||||
}
|
||||
|
||||
~CListener();
|
||||
|
||||
// Setters
|
||||
void SetSSL(bool b);
|
||||
void SetAddrType(EAddrType eAddr);
|
||||
void SetPort(unsigned short u);
|
||||
void SetBindHost(const CString& s);
|
||||
void SetRealListener(CRealListener* p);
|
||||
void SetAcceptType(AcceptType a);
|
||||
// !Setters
|
||||
|
||||
// Getters
|
||||
bool IsSSL() const { return m_bSSL; }
|
||||
EAddrType GetAddrType() const { return m_eAddr; }
|
||||
unsigned short GetPort() const { return m_uPort; }
|
||||
const CString& GetBindHost() const { return m_sBindHost; }
|
||||
CRealListener* GetRealListener() const { return m_pListener; }
|
||||
AcceptType GetAcceptType() const { return m_eAcceptType; }
|
||||
EAcceptType GetAcceptType() const { return m_eAcceptType; }
|
||||
// !Getters
|
||||
|
||||
bool Listen();
|
||||
void ResetRealListener();
|
||||
|
||||
private:
|
||||
protected:
|
||||
@@ -61,7 +53,7 @@ protected:
|
||||
unsigned short m_uPort;
|
||||
CString m_sBindHost;
|
||||
CRealListener* m_pListener;
|
||||
AcceptType m_eAcceptType;
|
||||
EAcceptType m_eAcceptType;
|
||||
};
|
||||
|
||||
class CRealListener : public CZNCSock {
|
||||
@@ -79,12 +71,12 @@ private:
|
||||
|
||||
class CIncomingConnection : public CZNCSock {
|
||||
public:
|
||||
CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::AcceptType eAcceptType);
|
||||
CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType);
|
||||
virtual ~CIncomingConnection() {}
|
||||
virtual void ReadLine(const CString& sData);
|
||||
|
||||
private:
|
||||
CListener::AcceptType m_eAcceptType;
|
||||
CListener::EAcceptType m_eAcceptType;
|
||||
};
|
||||
|
||||
#endif // !_LISTENER_H
|
||||
|
||||
@@ -556,6 +556,12 @@ bool CZNC::WriteConfig() {
|
||||
sHostPortion = sHostPortion.FirstLine() + " ";
|
||||
}
|
||||
|
||||
CString sAcceptProtocol;
|
||||
if(pListener->GetAcceptType() == CListener::ACCEPT_IRC)
|
||||
sAcceptProtocol = "irc_only ";
|
||||
else if(pListener->GetAcceptType() == CListener::ACCEPT_HTTP)
|
||||
sAcceptProtocol = "web_only ";
|
||||
|
||||
CString s6;
|
||||
switch (pListener->GetAddrType()) {
|
||||
case ADDR_IPV4ONLY:
|
||||
@@ -569,7 +575,8 @@ bool CZNC::WriteConfig() {
|
||||
break;
|
||||
}
|
||||
|
||||
m_LockFile.Write("Listen" + s6 + " = " + sHostPortion + CString((pListener->IsSSL()) ? "+" : "") + CString(pListener->GetPort()) + "\n");
|
||||
m_LockFile.Write("Listen" + s6 + " = " + sAcceptProtocol + sHostPortion +
|
||||
CString((pListener->IsSSL()) ? "+" : "") + CString(pListener->GetPort()) + "\n");
|
||||
}
|
||||
|
||||
m_LockFile.Write("ConnectDelay = " + CString(m_uiConnectDelay) + "\n");
|
||||
@@ -1455,7 +1462,6 @@ bool CZNC::DoRehash(CString& sError)
|
||||
}
|
||||
} else {
|
||||
if (sName.Equals("Listen") || sName.Equals("ListenPort") || sName.Equals("Listen6") || sName.Equals("Listen4")) {
|
||||
bool bSSL = false;
|
||||
EAddrType eAddr = ADDR_ALL;
|
||||
if (sName.Equals("Listen4")) {
|
||||
eAddr = ADDR_IPV4ONLY;
|
||||
@@ -1463,8 +1469,15 @@ bool CZNC::DoRehash(CString& sError)
|
||||
if (sName.Equals("Listen6")) {
|
||||
eAddr = ADDR_IPV6ONLY;
|
||||
}
|
||||
CString sPort;
|
||||
|
||||
CListener::EAcceptType eAccept = CListener::ACCEPT_ALL;
|
||||
if (sValue.TrimPrefix("irc_only "))
|
||||
eAccept = CListener::ACCEPT_IRC;
|
||||
else if (sValue.TrimPrefix("web_only "))
|
||||
eAccept = CListener::ACCEPT_HTTP;
|
||||
|
||||
bool bSSL = false;
|
||||
CString sPort;
|
||||
CString sBindHost;
|
||||
|
||||
if (ADDR_IPV4ONLY == eAddr) {
|
||||
@@ -1544,10 +1557,11 @@ bool CZNC::DoRehash(CString& sError)
|
||||
return false;
|
||||
}
|
||||
|
||||
CListener* pListener = new CListener(uPort, sBindHost, bSSL, eAddr);
|
||||
CListener* pListener = new CListener(uPort, sBindHost, bSSL, eAddr, eAccept);
|
||||
|
||||
if (!pListener->Listen()) {
|
||||
sError = "Unable to bind [" + CString(strerror(errno)) + "]";
|
||||
sError = (errno == 0 ? CString("unknown error, check the host name") : CString(strerror(errno)));
|
||||
sError = "Unable to bind [" + sError + "]";
|
||||
CUtils::PrintStatus(false, sError);
|
||||
delete pListener;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user