ZNC  trunk
Listener.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2024 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 
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();
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
EAddrType
Definition: Socket.h:77
Definition: Listener.h:88
virtual ~CIncomingConnection()
Definition: Listener.h:93
CIncomingConnection(const CString &sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType, const CString &sURIPrefix)
void ReadLine(const CString &sData) override
void ReachedMaxBuffer() override
This WARNING event is called when your buffer for readline exceeds the warning threshold and triggers...
Definition: Listener.h:27
CString m_sURIPrefix
Definition: Listener.h:70
unsigned short m_uPort
Definition: Listener.h:68
EAcceptType
Definition: Listener.h:29
@ ACCEPT_ALL
Definition: Listener.h:29
@ ACCEPT_HTTP
Definition: Listener.h:29
@ ACCEPT_IRC
Definition: Listener.h:29
EAcceptType m_eAcceptType
Definition: Listener.h:72
EAddrType GetAddrType() const
Definition: Listener.h:49
CRealListener * m_pListener
Definition: Listener.h:71
CListener & operator=(const CListener &)=delete
EAddrType m_eAddr
Definition: Listener.h:67
EAcceptType GetAcceptType() const
Definition: Listener.h:54
CString m_sBindHost
Definition: Listener.h:69
void SetAcceptType(EAcceptType eType)
Definition: Listener.h:59
bool Listen()
void ResetRealListener()
const CString & GetURIPrefix() const
Definition: Listener.h:53
unsigned short GetPort() const
Definition: Listener.h:50
CListener(const CListener &)=delete
bool m_bSSL
Definition: Listener.h:66
CListener(unsigned short uPort, const CString &sBindHost, const CString &sURIPrefix, bool bSSL, EAddrType eAddr, EAcceptType eAccept)
Definition: Listener.h:31
const CString & GetBindHost() const
Definition: Listener.h:51
bool IsSSL() const
Definition: Listener.h:48
CRealListener * GetRealListener() const
Definition: Listener.h:52
Definition: Listener.h:75
bool ConnectionFrom(const CString &sHost, unsigned short uPort) override
virtual ~CRealListener()
CRealListener(CListener &listener)
Definition: Listener.h:77
Csock * GetSockObj(const CString &sHost, unsigned short uPort) override
void SockError(int iErrno, const CString &sDescription) override
String class that is used inside ZNC.
Definition: ZNCString.h:68
Definition: Socket.h:27
Basic socket class.
Definition: Csocket.h:564