]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/iohook.h
Create IOHook interface (extracted from Module)
[user/henk/code/inspircd.git] / include / iohook.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
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
24 class IOHook : public ServiceProvider
25 {
26  public:
27         IOHook(Module* mod, const std::string& Name)
28                 : ServiceProvider(mod, Name, SERVICE_IOHOOK) { }
29
30         /** Called immediately after any connection is accepted. This is intended for raw socket
31          * processing (e.g. modules which wrap the tcp connection within another library) and provides
32          * no information relating to a user record as the connection has not been assigned yet.
33          * There are no return values from this call as all modules get an opportunity if required to
34          * process the connection.
35          * @param sock The socket in question
36          * @param client The client IP address and port
37          * @param server The server IP address and port
38          */
39         virtual void OnStreamSocketAccept(StreamSocket* sock, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) = 0;
40
41         /**
42          * Called when a hooked stream has data to write, or when the socket
43          * engine returns it as writable
44          * @param sock The socket in question
45          * @param sendq Data to send to the socket
46          * @return 1 if the sendq has been completely emptied, 0 if there is
47          *  still data to send, and -1 if there was an error
48          */
49         virtual int OnStreamSocketWrite(StreamSocket* sock, std::string& sendq) = 0;
50
51         /** Called immediately before any socket is closed. When this event is called, shutdown()
52          * has not yet been called on the socket.
53          * @param sock The socket in question
54          */
55         virtual void OnStreamSocketClose(StreamSocket* sock) = 0;
56
57         /** Called immediately upon connection of an outbound BufferedSocket which has been hooked
58          * by a module.
59          * @param sock The socket in question
60          */
61         virtual void OnStreamSocketConnect(StreamSocket* sock) = 0;
62
63         /**
64          * Called when the stream socket has data to read
65          * @param sock The socket that is ready
66          * @param recvq The receive queue that new data should be appended to
67          * @return 1 if new data has been read, 0 if no new data is ready (but the
68          *  socket is still connected), -1 if there was an error or close
69          */
70         virtual int OnStreamSocketRead(StreamSocket* sock, std::string& recvq) = 0;
71 };