ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Listener.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2014 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 _LISTENER_H
18 #define _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:
29  typedef enum {
33  } EAcceptType;
34 
35  CListener(unsigned short uPort, const CString& sBindHost, const CString& sURIPrefix, bool bSSL, EAddrType eAddr, EAcceptType eAccept) {
36  m_uPort = uPort;
37  m_sBindHost = sBindHost;
38  m_bSSL = bSSL;
39  m_eAddr = eAddr;
40  m_sURIPrefix = sURIPrefix;
41  m_pListener = NULL;
42  m_eAcceptType = eAccept;
43  }
44 
45  ~CListener();
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  virtual bool ConnectionFrom(const CString& sHost, unsigned short uPort);
81  virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort);
82  virtual void SockError(int iErrno, const CString& sDescription);
83 
84 private:
85  CListener& m_Listener;
86 };
87 
88 class CIncomingConnection : public CZNCSock {
89 public:
90  CIncomingConnection(const CString& sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType, const CString& sURIPrefix);
91  virtual ~CIncomingConnection() {}
92  virtual void ReadLine(const CString& sData);
93  virtual void ReachedMaxBuffer();
94 
95 private:
96  CListener::EAcceptType m_eAcceptType;
97  const CString m_sURIPrefix;
98 };
99 
100 #endif // !_LISTENER_H
virtual ~CRealListener()
bool IsSSL() const
Definition: Listener.h:48
EAddrType
Definition: Socket.h:40
EAcceptType m_eAcceptType
Definition: Listener.h:72
CRealListener * m_pListener
Definition: Listener.h:71
Definition: Listener.h:32
EAcceptType
Definition: Listener.h:29
const CString & GetBindHost() const
Definition: Listener.h:51
virtual ~CIncomingConnection()
Definition: Listener.h:91
CRealListener * GetRealListener() const
Definition: Listener.h:52
Definition: Socket.h:26
virtual void SockError(int iErrno, const CString &sDescription)
void ResetRealListener()
Basic socket class.
Definition: Csocket.h:537
virtual void ReadLine(const CString &sData)
void SetAcceptType(EAcceptType eType)
Definition: Listener.h:59
Definition: Listener.h:31
String class that is used inside ZNC.
Definition: ZNCString.h:67
CListener(unsigned short uPort, const CString &sBindHost, const CString &sURIPrefix, bool bSSL, EAddrType eAddr, EAcceptType eAccept)
Definition: Listener.h:35
bool m_bSSL
Definition: Listener.h:66
CString m_sURIPrefix
Definition: Listener.h:70
EAcceptType GetAcceptType() const
Definition: Listener.h:54
bool Listen()
CIncomingConnection(const CString &sHostname, unsigned short uPort, CListener::EAcceptType eAcceptType, const CString &sURIPrefix)
virtual bool ConnectionFrom(const CString &sHost, unsigned short uPort)
Definition: Listener.h:27
EAddrType m_eAddr
Definition: Listener.h:67
Definition: Listener.h:30
unsigned short m_uPort
Definition: Listener.h:68
unsigned short GetPort() const
Definition: Listener.h:50
virtual void ReachedMaxBuffer()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
Definition: Listener.h:75
CString m_sBindHost
Definition: Listener.h:69
virtual Csock * GetSockObj(const CString &sHost, unsigned short uPort)
EAddrType GetAddrType() const
Definition: Listener.h:49
CRealListener(CListener &listener)
Definition: Listener.h:77
Definition: Listener.h:88
const CString & GetURIPrefix() const
Definition: Listener.h:53