2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
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.
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
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/>.
24 class IOHookProvider : public ServiceProvider
35 IOHookProvider(Module* mod, const std::string& Name, Type hooktype = IOH_UNKNOWN)
36 : ServiceProvider(mod, Name, SERVICE_IOHOOK), type(hooktype) { }
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
45 virtual void OnAccept(StreamSocket* sock, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) = 0;
47 /** Called immediately upon connection of an outbound BufferedSocket which has been hooked
49 * @param sock The socket in question
51 virtual void OnConnect(StreamSocket* sock) = 0;
54 class IOHook : public classbase
57 /** The IOHookProvider for this hook, contains information about the hook,
58 * such as the module providing it and the hook type.
60 IOHookProvider* const prov;
62 IOHook(IOHookProvider* provider)
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 Data to send to the socket
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
73 virtual int OnStreamSocketWrite(StreamSocket* sock, std::string& sendq) = 0;
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
79 virtual void OnStreamSocketClose(StreamSocket* sock) = 0;
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
88 virtual int OnStreamSocketRead(StreamSocket* sock, std::string& recvq) = 0;