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