InspIRCd  3.0
iohook.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2013 Attila Molnar <[email protected]>
5  *
6  * This file is part of InspIRCd. InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 #pragma once
21 
22 class StreamSocket;
23 
25 {
26  const bool middlehook;
27 
28  public:
29  enum Type
30  {
31  IOH_UNKNOWN,
32  IOH_SSL
33  };
34 
35  const Type type;
36 
43  IOHookProvider(Module* mod, const std::string& Name, Type hooktype = IOH_UNKNOWN, bool middle = false)
44  : ServiceProvider(mod, Name, SERVICE_IOHOOK), middlehook(middle), type(hooktype) { }
45 
50  bool IsMiddle() const { return middlehook; }
51 
58  virtual void OnAccept(StreamSocket* sock, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) = 0;
59 
63  virtual void OnConnect(StreamSocket* sock) = 0;
64 };
65 
66 class IOHook : public classbase
67 {
68  public:
73 
78  : prov(provider) { }
79 
87  virtual int OnStreamSocketWrite(StreamSocket* sock, StreamSocket::SendQueue& sendq) = 0;
88 
93  virtual void OnStreamSocketClose(StreamSocket* sock) = 0;
94 
102  virtual int OnStreamSocketRead(StreamSocket* sock, std::string& recvq) = 0;
103 };
104 
105 class IOHookMiddle : public IOHook
106 {
110 
113  std::string precvq;
114 
117  IOHook* nexthook;
118 
119  protected:
123  std::string& GetRecvQ() { return precvq; }
124 
128  StreamSocket::SendQueue& GetSendQ() { return sendq; }
129 
130  public:
135  : IOHook(provider)
136  , nexthook(NULL)
137  {
138  }
139 
143  const StreamSocket::SendQueue& GetSendQ() const { return sendq; }
144 
148  IOHook* GetNextHook() const { return nexthook; }
149 
153  void SetNextHook(IOHook* hook) { nexthook = hook; }
154 
160  {
161  if (hook->prov->IsMiddle())
162  return static_cast<IOHookMiddle*>(hook);
163  return NULL;
164  }
165 
166  friend class StreamSocket;
167 };
Definition: iohook.h:24
Definition: iohook.h:66
IOHookProvider(Module *mod, const std::string &Name, Type hooktype=IOH_UNKNOWN, bool middle=false)
Definition: iohook.h:43
Definition: socket.h:57
Definition: base.h:41
Definition: inspsocket.h:103
Definition: inspsocket.h:108
IOHook(IOHookProvider *provider)
Definition: iohook.h:77
virtual void OnAccept(StreamSocket *sock, irc::sockets::sockaddrs *client, irc::sockets::sockaddrs *server)=0
Definition: modules.h:245
Definition: iohook.h:105
virtual void OnConnect(StreamSocket *sock)=0
bool IsMiddle() const
Definition: iohook.h:50
IOHookProvider *const prov
Definition: iohook.h:72
const StreamSocket::SendQueue & GetSendQ() const
Definition: iohook.h:143
Definition: base.h:244
StreamSocket::SendQueue & GetSendQ()
Definition: iohook.h:128
IOHook * GetNextHook() const
Definition: iohook.h:148
void SetNextHook(IOHook *hook)
Definition: iohook.h:153
static IOHookMiddle * ToMiddleHook(IOHook *hook)
Definition: iohook.h:159
std::string & GetRecvQ()
Definition: iohook.h:123
IOHookMiddle(IOHookProvider *provider)
Definition: iohook.h:134