ZNC  trunk
Listener.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2021 ZNC, see the NOTICE file for details.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ZNC_LISTENER_H
18 #define ZNC_LISTENER_H
19 
20 #include <znc/zncconfig.h>
21 #include <znc/Socket.h>
22 
23 // Forward Declarations
24 class CRealListener;
25 // !Forward Declarations
26 
27 class CListener {
28  public:
30 
31  CListener(unsigned short uPort, const CString& sBindHost,
32  const CString& sURIPrefix, bool bSSL, EAddrType eAddr,
33  EAcceptType eAccept)
34  : m_bSSL(bSSL),
35  m_eAddr(eAddr),
36  m_uPort(uPort),
37  m_sBindHost(sBindHost),
38  m_sURIPrefix(sURIPrefix),
39  m_pListener(nullptr),
40  m_eAcceptType(eAccept) {}
41 
42  ~CListener();
43 
44  CListener(const CListener&) = delete;
45  CListener& operator=(const CListener&) = delete;
46 
47  // Getters
48  bool IsSSL() const { return m_bSSL; }
49  EAddrType GetAddrType() const { return m_eAddr; }
50  unsigned short GetPort() const { return m_uPort; }
51  const CString& GetBindHost() const { return m_sBindHost; }
53  const CString& GetURIPrefix() const { return m_sURIPrefix; }
55  // !Getters
56 
57  // It doesn't make sense to change any of the settings after Listen()
58  // except this one, so don't add other setters!
59  void SetAcceptType(EAcceptType eType) { m_eAcceptType = eType; }
60 
61  bool Listen();
62  void ResetRealListener();
63 
64  private:
65  protected:
66  bool m_bSSL;
68  unsigned short m_uPort;
73 };
74 
75 class CRealListener : public CZNCSock {
76  public:
77  CRealListener(CListener& listener) : CZNCSock(), m_Listener(listener) {}
78  virtual ~CRealListener();
79 
80  bool ConnectionFrom(const CString& sHost, unsigned short uPort) override;
81  Csock* GetSockObj(const CString& sHost, unsigned short uPort) override;
82  void SockError(int iErrno, const CString& sDescription) override;
83 
84  private:
85  CListener& m_Listener;
86 };
87 
88 class CIncomingConnection : public CZNCSock {
89  public:
90  CIncomingConnection(const CString& sHostname, unsigned short uPort,
91  CListener::EAcceptType eAcceptType,
92  const CString& sURIPrefix);
93  virtual ~CIncomingConnection() {}
94  void ReadLine(const CString& sData) override;
95  void ReachedMaxBuffer() override;
96 
97  private:
98  CListener::EAcceptType m_eAcceptType;
99  const CString m_sURIPrefix;
100 };
101 
102 #endif // !ZNC_LISTENER_H
CListener::GetPort
unsigned short GetPort() const
Definition: Listener.h:50
CListener::m_eAcceptType
EAcceptType m_eAcceptType
Definition: Listener.h:72
CListener::CListener
CListener(unsigned short uPort, const CString &sBindHost, const CString &sURIPrefix, bool bSSL, EAddrType eAddr, EAcceptType eAccept)
Definition: Listener.h:31
CListener::m_bSSL
bool m_bSSL
Definition: Listener.h:66
CIncomingConnection::ReachedMaxBuffer
void ReachedMaxBuffer() override
This WARNING event is called when your buffer for readline exceeds the warning threshold and triggers...
CListener::ACCEPT_HTTP
@ ACCEPT_HTTP
Definition: Listener.h:29
CListener::m_sURIPrefix
CString m_sURIPrefix
Definition: Listener.h:70
CIncomingConnection::ReadLine
void ReadLine(const CString &sData) override
CListener::ACCEPT_IRC
@ ACCEPT_IRC
Definition: Listener.h:29
CListener::ACCEPT_ALL
@ ACCEPT_ALL
Definition: Listener.h:29
Csock
Basic socket class.
Definition: Csocket.h:564
CIncomingConnection
Definition: Listener.h:88
CListener::~CListener
~CListener()
CListener::ResetRealListener
void ResetRealListener()
CListener::m_eAddr
EAddrType m_eAddr
Definition: Listener.h:67
CIncomingConnection::~CIncomingConnection
virtual ~CIncomingConnection()
Definition: Listener.h:93
CListener::Listen
bool Listen()
CRealListener::ConnectionFrom
bool ConnectionFrom(const CString &sHost, unsigned short uPort) override
CString
String class that is used inside ZNC.
Definition: ZNCString.h:68
CListener::GetAcceptType
EAcceptType GetAcceptType() const
Definition: Listener.h:54
CListener::m_pListener
CRealListener * m_pListener
Definition: Listener.h:71
EAddrType
EAddrType
Definition: Socket.h:77
CListener::GetBindHost
const CString & GetBindHost() const
Definition: Listener.h:51
Socket.h
CListener::m_uPort
unsigned short m_uPort
Definition: Listener.h:68
CListener::GetURIPrefix
const CString & GetURIPrefix() const
Definition: Listener.h:53
CListener
Definition: Listener.h:27
CListener::m_sBindHost
CString m_sBindHost
Definition: Listener.h:69
CListener::SetAcceptType
void SetAcceptType(EAcceptType eType)
Definition: Listener.h:59
CIncomingConnection::CIncomingConnection
CIncomingConnection(const CString &sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType, const CString &sURIPrefix)
CRealListener::SockError
void SockError(int iErrno, const CString &sDescription) override
CListener::GetAddrType
EAddrType GetAddrType() const
Definition: Listener.h:49
CRealListener::CRealListener
CRealListener(CListener &listener)
Definition: Listener.h:77
CRealListener::~CRealListener
virtual ~CRealListener()
CListener::EAcceptType
EAcceptType
Definition: Listener.h:29
CListener::IsSSL
bool IsSSL() const
Definition: Listener.h:48
CListener::operator=
CListener & operator=(const CListener &)=delete
CZNCSock
Definition: Socket.h:27
CListener::GetRealListener
CRealListener * GetRealListener() const
Definition: Listener.h:52
CRealListener
Definition: Listener.h:75
CRealListener::GetSockObj
Csock * GetSockObj(const CString &sHost, unsigned short uPort) override