/** Used to define a set of behavior bits for a module
*/
enum ModuleFlags {
+ VF_NONE = 0, // module is not special at all
VF_STATIC = 1, // module is static, cannot be /unloadmodule'd
VF_VENDOR = 2, // module is a vendor module (came in the original tarball, not 3rd party)
VF_SERVICEPROVIDER = 4, // module provides a service to other modules (can be a dependency)
} \
} while (0);
-/**
- * This #define allows us to call a method in all
- * loaded modules in a readable simple way and pass
- * an instance pointer to the macro. e.g.:
- * 'FOREACH_MOD_I(Instance, OnConnect, OnConnect(user));'
- */
-#define FOREACH_MOD_I(z,y,x) do { \
- EventHandlerIter safei; \
- for (EventHandlerIter _i = z->Modules->EventHandlers[y].begin(); _i != z->Modules->EventHandlers[y].end(); ) \
- { \
- safei = _i; \
- ++safei; \
- try \
- { \
- (*_i)->x ; \
- } \
- catch (CoreException& modexcept) \
- { \
- z->Logs->Log("MODULE",DEFAULT,"Exception caught: %s",modexcept.GetReason()); \
- } \
- _i = safei; \
- } \
-} while (0);
-
/**
* Custom module result handling loop. This is a paired macro, and should only
* be used with while_each_hook.
*
* See src/channels.cpp for an example of use.
*/
-#define DO_EACH_HOOK(z,n,v,args) \
+#define DO_EACH_HOOK(n,v,args) \
do { \
- EventHandlerIter iter_ ## n = z->Modules->EventHandlers[I_ ## n].begin(); \
- while (iter_ ## n != z->Modules->EventHandlers[I_ ## n].end()) \
+ EventHandlerIter iter_ ## n = ServerInstance->Modules->EventHandlers[I_ ## n].begin(); \
+ while (iter_ ## n != ServerInstance->Modules->EventHandlers[I_ ## n].end()) \
{ \
Module* mod_ ## n = *iter_ ## n; \
iter_ ## n ++; \
{ \
v = (mod_ ## n)->n args;
-#define WHILE_EACH_HOOK(z,n) \
+#define WHILE_EACH_HOOK(n) \
} \
catch (CoreException& except_ ## n) \
{ \
- z->Logs->Log("MODULE",DEFAULT,"Exception caught: %s", (except_ ## n).GetReason()); \
+ ServerInstance->Logs->Log("MODULE",DEFAULT,"Exception caught: %s", (except_ ## n).GetReason()); \
(void) mod_ ## n; /* catch mismatched pairs */ \
} \
} \
* Runs the given hook until some module returns a useful result.
*
* Example: ModResult result;
- * FIRST_MOD_RESULT(ServerInstance, OnUserPreNick, result, (user, newnick))
+ * FIRST_MOD_RESULT(OnUserPreNick, result, (user, newnick))
*/
-#define FIRST_MOD_RESULT(z,n,v,args) do { \
+#define FIRST_MOD_RESULT(n,v,args) do { \
v = MOD_RES_PASSTHRU; \
- DO_EACH_HOOK(z,n,v,args) \
+ DO_EACH_HOOK(n,v,args) \
{ \
if (v != MOD_RES_PASSTHRU) \
break; \
} \
- WHILE_EACH_HOOK(z,n); \
+ WHILE_EACH_HOOK(n); \
} while (0)
/** Represents a non-local user.
/** Is a remote user */
#define IS_REMOTE(x) (x->GetFd() < 0)
/** Is a fake user */
-#define IS_FAKE(x) (x->GetFd() == FD_FAKEUSER_NUMBER)
+#define IS_SERVER(x) (x->GetFd() == FD_FAKEUSER_NUMBER)
/** Is a module created user */
#define IS_MODULE_CREATED(x) (x->GetFd() == FD_MAGIC_NUMBER)
/** Is an oper */
class CoreExport Version : public classbase
{
public:
+ /** Module description
+ */
+ const std::string description;
/** Version information.
*/
const std::string version;
/** Initialize version class
*/
- Version(const std::string &customver, int flags,
+ Version(const std::string &desc, int flags,
int api_ver = API_VERSION, const std::string& src_rev = VERSION " r" REVISION);
};
* The return result of an Event::Send() will always be NULL as
* no replies are expected.
*/
- char* Send(InspIRCd* ServerInstance);
+ char* Send();
};
/** Priority types which can be returned from Module::Prioritize()
I_OnRawMode, I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnCheckChannelBan, I_OnExtBanCheck,
I_OnStats, I_OnChangeLocalUserHost, I_OnChangeLocalUserGecos, I_OnPreTopicChange,
I_OnPostTopicChange, I_OnEvent, I_OnRequest, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan,
- I_OnDelBan, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead,
- I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete,
+ I_OnDelBan, I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete,
I_OnPostOper, I_OnSyncNetwork, I_OnSetAway, I_OnUserList, I_OnPostCommand, I_OnPostJoin,
- I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect, I_OnBufferFlushed,
+ I_OnWhoisLine, I_OnBuildExemptList, I_OnGarbageCollect,
I_OnText, I_OnPassCompare, I_OnRunTestSuite, I_OnNamesListItem, I_OnNumeric, I_OnHookIO,
I_OnHostCycle, I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine, I_OnChangeIdent,
I_END
* @param Me An instance of the InspIRCd class which will be saved into ServerInstance for your use
* \exception ModuleException Throwing this class, or any class derived from ModuleException, causes loading of the module to abort.
*/
- Module(InspIRCd* Me = ServerInstance);
+ Module();
/** Default destructor.
* destroys a module class
* The method should return a Version object with its version information assigned via
* Version::Version
*/
- virtual Version GetVersion();
+ virtual Version GetVersion() = 0;
/** Called when a user connects.
* The details of the connecting user are available to you in the parameter User *user
* @param user The item to possibly install the I/O hook on
* @param via The port that <user> connected on
*/
- virtual void OnHookIO(EventHandler* user, ListenSocketBase* via);
+ virtual void OnHookIO(StreamSocket*, ListenSocketBase* via);
- /** Called immediately after any connection is accepted. This is intended for raw socket
+ /** 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
* @param server The server IP address and port
* @param localport The local port number the user connected to
*/
- virtual void OnRawSocketAccept(int fd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
+ virtual void OnStreamSocketAccept(StreamSocket*, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
- /** Called immediately before any write() operation on a user's socket in the core. Because
- * this event is a low level event no user information is associated with it. It is intended
- * for use by modules which may wrap connections within another API such as SSL for example.
- * return a non-zero result if you have handled the write operation, in which case the core
- * will not call write().
- * @param fd The file descriptor of the socket
- * @param buffer A char* buffer being written
- * @param Number of characters to write
- * @return Number of characters actually written or 0 if you didn't handle the operation
+ /**
+ * Called when a hooked stream has data to write, or when the socket
+ * engine returns it as writable
+ * @param socket 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 OnRawSocketWrite(int fd, const char* buffer, int count);
+ virtual int OnStreamSocketWrite(StreamSocket*, 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 fd The file descriptor of the socket prior to close()
*/
- virtual void OnRawSocketClose(int fd);
+ virtual void OnStreamSocketClose(StreamSocket*);
/** Called immediately upon connection of an outbound BufferedSocket which has been hooked
* by a module.
* @param fd The file descriptor of the socket immediately after connect()
*/
- virtual void OnRawSocketConnect(int fd);
-
- /** Called immediately before any read() operation on a client socket in the core.
- * This occurs AFTER the select() or poll() so there is always data waiting to be read
- * when this event occurs.
- * Your event should return 1 if it has handled the reading itself, which prevents the core
- * just using read(). You should place any data read into buffer, up to but NOT GREATER THAN
- * the value of count. The value of readresult must be identical to an actual result that might
- * be returned from the read() system call, for example, number of bytes read upon success,
- * 0 upon EOF or closed socket, and -1 for error. If your function returns a nonzero value,
- * you MUST set readresult.
- * @param fd The file descriptor of the socket
- * @param buffer A char* buffer being read to
- * @param count The size of the buffer
- * @param readresult The amount of characters read, or 0
- * @return nonzero if the event was handled, in which case readresult must be valid on exit
- */
- virtual int OnRawSocketRead(int fd, char* buffer, unsigned int count, int &readresult);
+ virtual void OnStreamSocketConnect(StreamSocket*);
+
+ /**
+ * Called when the stream socket has data to read
+ * @param socket 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*, 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.
*/
virtual void OnGarbageCollect();
- /** Called whenever a user's write buffer has been completely sent.
- * This is called when the user's write buffer is completely empty, and
- * there are no more pending bytes to be written and no pending write events
- * in the socket engine's queue. This may be used to refill the buffer with
- * data which is being spooled in a controlled manner, e.g. LIST lines.
- * @param user The user who's buffer is now empty.
- */
- virtual void OnBufferFlushed(User* user);
-
/** Add test suite hooks here. These are used for testing functionality of a module
* via the --testsuite debugging parameter.
*/
* This constructor initialises the ConfigReader class to read the inspircd.conf file
* as specified when running ./configure.
*/
- ConfigReader(InspIRCd* Instance = ServerInstance);
+ ConfigReader();
/** Default destructor.
* This method destroys the ConfigReader class.
*/
* This method does not load any file into memory, you must use the LoadFile method
* after constructing the class this way.
*/
- FileReader(InspIRCd* Instance = ServerInstance);
+ FileReader();
/** Secondary constructor.
* This method initialises the class with a file loaded into it ready for GetLine and
* and other methods to be called. If the file could not be loaded, FileReader::FileSize
* returns 0.
*/
- FileReader(InspIRCd* Instance, const std::string &filename);
+ FileReader(const std::string &filename);
/** Default destructor.
* This deletes the memory allocated to the file.
#ifdef WINDOWS
#define MODULE_INIT(y) \
- extern "C" DllExport Module * init_module(InspIRCd* Me) \
+ extern "C" DllExport Module * init_module() \
{ \
- return new y(Me); \
+ return new y; \
} \
BOOLEAN WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) \
{ \
#else
#define MODULE_INIT(y) \
- extern "C" DllExport Module * init_module(InspIRCd* Me) \
+ extern "C" DllExport Module * init_module() \
{ \
- return new y(Me); \
+ return new y; \
}
#endif