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