]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/iohook.h
Pass sendq to OnStreamSocketWrite
[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 IOHookProvider : public ServiceProvider
25 {
26  public:
27         enum Type
28         {
29                 IOH_UNKNOWN,
30                 IOH_SSL
31         };
32
33         const Type type;
34
35         IOHookProvider(Module* mod, const std::string& Name, Type hooktype = IOH_UNKNOWN)
36                 : ServiceProvider(mod, Name, SERVICE_IOHOOK), type(hooktype) { }
37
38         /** Called immediately after a 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          * @param sock The socket in question
42          * @param client The client IP address and port
43          * @param server The server IP address and port
44          */
45         virtual void OnAccept(StreamSocket* sock, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) = 0;
46
47         /** Called immediately upon connection of an outbound BufferedSocket which has been hooked
48          * by a module.
49          * @param sock The socket in question
50          */
51         virtual void OnConnect(StreamSocket* sock) = 0;
52 };
53
54 class IOHook : public classbase
55 {
56  public:
57         /** The IOHookProvider for this hook, contains information about the hook,
58          * such as the module providing it and the hook type.
59          */
60         IOHookProvider* const prov;
61
62         IOHook(IOHookProvider* provider)
63                 : prov(provider) { }
64
65         /**
66          * Called when a hooked stream has data to write, or when the socket
67          * engine returns it as writable
68          * @param sock The socket in question
69          * @param sendq Send queue to send data from
70          * @return 1 if the sendq has been completely emptied, 0 if there is
71          *  still data to send, and -1 if there was an error
72          */
73         virtual int OnStreamSocketWrite(StreamSocket* sock, StreamSocket::SendQueue& sendq) = 0;
74
75         /** Called immediately before any socket is closed. When this event is called, shutdown()
76          * has not yet been called on the socket.
77          * @param sock The socket in question
78          */
79         virtual void OnStreamSocketClose(StreamSocket* sock) = 0;
80
81         /**
82          * Called when the stream socket has data to read
83          * @param sock The socket that is ready
84          * @param recvq The receive queue that new data should be appended to
85          * @return 1 if new data has been read, 0 if no new data is ready (but the
86          *  socket is still connected), -1 if there was an error or close
87          */
88         virtual int OnStreamSocketRead(StreamSocket* sock, std::string& recvq) = 0;
89 };