diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-05-24 19:34:25 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-06-07 01:00:10 +0200 |
commit | 79db1cf848c64ba50bebadef4c683ae4237080b7 (patch) | |
tree | fcaed0d8034d5e750de24cb1cd9ee87570816d66 /include | |
parent | f2febe8ff61766f1b57305fae873071de4526d58 (diff) |
Create IOHook interface (extracted from Module)
Diffstat (limited to 'include')
-rw-r--r-- | include/inspsocket.h | 23 | ||||
-rw-r--r-- | include/iohook.h | 71 | ||||
-rw-r--r-- | include/modules.h | 42 | ||||
-rw-r--r-- | include/modules/ssl.h | 3 |
4 files changed, 85 insertions, 54 deletions
diff --git a/include/inspsocket.h b/include/inspsocket.h index ccc2301ed..720489b77 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -25,6 +25,8 @@ #include "timer.h" +class IOHook; + /** * States which a socket may be in */ @@ -101,8 +103,9 @@ class CoreExport SocketTimeout : public Timer */ class CoreExport StreamSocket : public EventHandler { - /** Module that handles raw I/O for this socket, or NULL */ - reference<Module> IOHook; + /** The IOHook that handles raw I/O for this socket, or NULL */ + IOHook* iohook; + /** Private send queue. Note that individual strings may be shared */ std::deque<std::string> sendq; @@ -113,10 +116,10 @@ class CoreExport StreamSocket : public EventHandler protected: std::string recvq; public: - StreamSocket() : sendq_len(0) {} - inline Module* GetIOHook(); - inline void AddIOHook(Module* m); - inline void DelIOHook(); + StreamSocket() : iohook(NULL), sendq_len(0) {} + IOHook* GetIOHook() const; + void AddIOHook(IOHook* hook); + void DelIOHook(); /** Handle event from socket engine. * This will call OnDataReady if there is *new* data in recvq */ @@ -228,8 +231,6 @@ class CoreExport BufferedSocket : public StreamSocket BufferedSocketError BeginConnect(const std::string &ipaddr, int aport, unsigned long maxtime, const std::string &connectbindip); }; -#include "modules.h" - -inline Module* StreamSocket::GetIOHook() { return IOHook; } -inline void StreamSocket::AddIOHook(Module* m) { IOHook = m; } -inline void StreamSocket::DelIOHook() { IOHook = NULL; } +inline IOHook* StreamSocket::GetIOHook() const { return iohook; } +inline void StreamSocket::AddIOHook(IOHook* hook) { iohook = hook; } +inline void StreamSocket::DelIOHook() { iohook = NULL; } diff --git a/include/iohook.h b/include/iohook.h new file mode 100644 index 000000000..87403681d --- /dev/null +++ b/include/iohook.h @@ -0,0 +1,71 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#pragma once + +class StreamSocket; + +class IOHook : public ServiceProvider +{ + public: + IOHook(Module* mod, const std::string& Name) + : ServiceProvider(mod, Name, SERVICE_IOHOOK) { } + + /** Called immediately after any connection is accepted. This is intended for raw socket + * processing (e.g. modules which wrap the tcp connection within another library) and provides + * no information relating to a user record as the connection has not been assigned yet. + * There are no return values from this call as all modules get an opportunity if required to + * process the connection. + * @param sock The socket in question + * @param client The client IP address and port + * @param server The server IP address and port + */ + virtual void OnStreamSocketAccept(StreamSocket* sock, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) = 0; + + /** + * Called when a hooked stream has data to write, or when the socket + * engine returns it as writable + * @param sock The socket in question + * @param sendq Data to send to the socket + * @return 1 if the sendq has been completely emptied, 0 if there is + * still data to send, and -1 if there was an error + */ + virtual int OnStreamSocketWrite(StreamSocket* sock, std::string& sendq) = 0; + + /** Called immediately before any socket is closed. When this event is called, shutdown() + * has not yet been called on the socket. + * @param sock The socket in question + */ + virtual void OnStreamSocketClose(StreamSocket* sock) = 0; + + /** Called immediately upon connection of an outbound BufferedSocket which has been hooked + * by a module. + * @param sock The socket in question + */ + virtual void OnStreamSocketConnect(StreamSocket* sock) = 0; + + /** + * Called when the stream socket has data to read + * @param sock The socket that is ready + * @param recvq The receive queue that new data should be appended to + * @return 1 if new data has been read, 0 if no new data is ready (but the + * socket is still connected), -1 if there was an error or close + */ + virtual int OnStreamSocketRead(StreamSocket* sock, std::string& recvq) = 0; +}; diff --git a/include/modules.h b/include/modules.h index 959025367..d04582901 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1169,48 +1169,6 @@ class CoreExport Module : public classbase, public usecountbase */ virtual ModResult OnAcceptConnection(int fd, ListenSocket* sock, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server); - /** Called immediately after any connection is accepted. This is intended for raw socket - * processing (e.g. modules which wrap the tcp connection within another library) and provides - * no information relating to a user record as the connection has not been assigned yet. - * There are no return values from this call as all modules get an opportunity if required to - * process the connection. - * @param sock The socket in question - * @param client The client IP address and port - * @param server The server IP address and port - */ - virtual void OnStreamSocketAccept(StreamSocket* sock, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server); - - /** - * Called when a hooked stream has data to write, or when the socket - * engine returns it as writable - * @param sock The socket in question - * @param sendq Data to send to the socket - * @return 1 if the sendq has been completely emptied, 0 if there is - * still data to send, and -1 if there was an error - */ - virtual int OnStreamSocketWrite(StreamSocket* sock, std::string& sendq); - - /** Called immediately before any socket is closed. When this event is called, shutdown() - * has not yet been called on the socket. - * @param sock The socket in question - */ - virtual void OnStreamSocketClose(StreamSocket* sock); - - /** Called immediately upon connection of an outbound BufferedSocket which has been hooked - * by a module. - * @param sock The socket in question - */ - virtual void OnStreamSocketConnect(StreamSocket* sock); - - /** - * Called when the stream socket has data to read - * @param sock The socket that is ready - * @param recvq The receive queue that new data should be appended to - * @return 1 if new data has been read, 0 if no new data is ready (but the - * socket is still connected), -1 if there was an error or close - */ - virtual int OnStreamSocketRead(StreamSocket* sock, std::string& recvq); - /** Called whenever a user sets away or returns from being away. * The away message is available as a parameter, but should not be modified. * At this stage, it has already been copied into the user record. diff --git a/include/modules/ssl.h b/include/modules/ssl.h index a79dcc9ef..a45121537 100644 --- a/include/modules/ssl.h +++ b/include/modules/ssl.h @@ -22,6 +22,7 @@ #include <map> #include <string> +#include "iohook.h" /** ssl_cert is a class which abstracts SSL certificate * and key information. @@ -138,7 +139,7 @@ struct SocketCertificateRequest : public Request ssl_cert* cert; SocketCertificateRequest(StreamSocket* ss, Module* Me) - : Request(Me, ss->GetIOHook(), "GET_SSL_CERT"), sock(ss), cert(NULL) + : Request(Me, (ss->GetIOHook() ? (Module*)ss->GetIOHook()->creator : NULL), "GET_SSL_CERT"), sock(ss), cert(NULL) { Send(); } |