X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules.h;h=931d85032f512354264d3bdd11757b7be85456a2;hb=cc74fb0be4ce4a5f55719dcf4b1045fe156ded1b;hp=710a39193546dff81c4b0fbb6911ed66421a122b;hpb=d24619c012b34d5a3d4cfb93e7bea3ff3d5721e7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules.h b/include/modules.h index 710a39193..931d85032 100644 --- a/include/modules.h +++ b/include/modules.h @@ -250,7 +250,7 @@ enum Priority { PRIORITY_FIRST, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER } enum Implementation { I_BEGIN, - I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnRehash, + I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois, I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNick, I_OnUserMessage, I_OnMode, I_OnGetServerDescription, I_OnSyncUser, @@ -319,6 +319,13 @@ class CoreExport Module : public classbase, public usecountbase { } + /** This method is called when you should reload module specific configuration: + * on boot, on a /REHASH and on module load. + * @param status The current status, can be inspected for more information; + * also used for reporting configuration errors and warnings. + */ + virtual void ReadConfig(ConfigStatus& status); + /** Returns the version number of a Module. * The method should return a Version object with its version information assigned via * Version::Version @@ -409,14 +416,6 @@ class CoreExport Module : public classbase, public usecountbase */ virtual void OnModuleRehash(User* user, const std::string ¶meter); - /** Called on rehash. - * This method is called after a rehash has completed. You should use it to reload any module - * configuration from the main configuration file. - * @param user The user that performed the rehash, if it was initiated by a user and that user - * is still connected. - */ - virtual void OnRehash(User* user); - /** Called whenever a snotice is about to be sent to a snomask. * snomask and type may both be modified; the message may not. * @param snomask The snomask the message is going to (e.g. 'A') @@ -624,43 +623,32 @@ class CoreExport Module : public classbase, public usecountbase /** Allows modules to synchronize data which relates to users during a netburst. * When this function is called, it will be called from the module which implements - * the linking protocol. This currently is m_spanningtree.so. A pointer to this module - * is given in Module* proto, so that you may call its methods such as ProtoSendMode - * (see below). This function will be called for every user visible on your side - * of the burst, allowing you to for example set modes, etc. Do not use this call to - * synchronize data which you have stored using class Extensible -- There is a specialist - * function OnSyncUserMetaData and OnSyncChannelMetaData for this! + * the linking protocol. This currently is m_spanningtree.so. + * This function will be called for every user visible on your side + * of the burst, allowing you to for example set modes, etc. * @param user The user being syncronized - * @param proto A pointer to the module handling network protocol - * @param opaque An opaque pointer set by the protocol module, should not be modified! + * @param server The target of the burst */ - virtual void OnSyncUser(User* user, Module* proto, void* opaque); + virtual void OnSyncUser(User* user, ProtocolServer& server); /** Allows modules to synchronize data which relates to channels during a netburst. * When this function is called, it will be called from the module which implements - * the linking protocol. This currently is m_spanningtree.so. A pointer to this module - * is given in Module* proto, so that you may call its methods such as ProtoSendMode - * (see below). This function will be called for every user visible on your side - * of the burst, allowing you to for example set modes, etc. + * the linking protocol. This currently is m_spanningtree.so. + * This function will be called for every channel visible on your side of the burst, + * allowing you to for example set modes, etc. * * @param chan The channel being syncronized - * @param proto A pointer to the module handling network protocol - * @param opaque An opaque pointer set by the protocol module, should not be modified! + * @param server The target of the burst */ - virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque); + virtual void OnSyncChannel(Channel* chan, ProtocolServer& server); - /* Allows modules to syncronize metadata not related to users or channels, over the network during a netburst. - * Whenever the linking module wants to send out data, but doesnt know what the data - * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then - * this method is called. You should use the ProtoSendMetaData function after you've - * correctly decided how the data should be represented, to send the metadata on its way if - * if it belongs to your module. - * @param proto A pointer to the module handling network protocol - * @param opaque An opaque pointer set by the protocol module, should not be modified! - * @param displayable If this value is true, the data is going to be displayed to a user, - * and not sent across the network. Use this to determine wether or not to show sensitive data. + /** Allows modules to syncronize metadata not related to users or channels, over the network during a netburst. + * When the linking module has finished sending all data it wanted to send during a netburst, then + * this method is called. You should use the SendMetaData() function after you've + * correctly decided how the data should be represented, to send the data. + * @param server The target of the burst */ - virtual void OnSyncNetwork(Module* proto, void* opaque); + virtual void OnSyncNetwork(ProtocolServer& server); /** Allows module data, sent via ProtoSendMetaData, to be decoded again by a receiving module. * Please see src/modules/m_swhois.cpp for a working example of how to use this method call. @@ -670,34 +658,6 @@ class CoreExport Module : public classbase, public usecountbase */ virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata); - /** Implemented by modules which provide the ability to link servers. - * These modules will implement this method, which allows transparent sending of servermodes - * down the network link as a broadcast, without a module calling it having to know the format - * of the MODE command before the actual mode string. - * - * @param opaque An opaque pointer set by the protocol module, should not be modified! - * @param target_type The type of item to decode data for, TYPE_USER or TYPE_CHANNEL - * @param target The Channel* or User* that modes should be sent for - * @param modeline The modes and parameters to be sent - * @param translate The translation types of the mode parameters - */ - virtual void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::vector &modeline, const std::vector &translate); - - /** Implemented by modules which provide the ability to link servers. - * These modules will implement this method, which allows metadata (extra data added to - * user and channel records using class Extensible, Extensible::Extend, etc) to be sent - * to other servers on a netburst and decoded at the other end by the same module on a - * different server. - * - * More documentation to follow soon. Please see src/modules/m_swhois.cpp for example of - * how to use this function. - * @param opaque An opaque pointer set by the protocol module, should not be modified! - * @param target The Channel* or User* that metadata should be sent for - * @param extname The extension name to send metadata for - * @param extdata Encoded data for this extension name, which will be encoded at the oppsite end by an identical module using OnDecodeMetaData - */ - virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata); - /** Called whenever a user's hostname is changed. * This event triggers after the host has been set. * @param user The user whos host is being changed @@ -1169,15 +1129,14 @@ typedef IntModuleList::iterator EventHandlerIter; */ class CoreExport ModuleManager { + public: + typedef std::vector ServiceList; + private: /** Holds a string describing the last module error to occur */ std::string LastModuleError; - /** Total number of modules loaded into the ircd - */ - int ModCount; - /** List of loaded modules and shared object/dll handles * keyed by module name */ @@ -1191,7 +1150,18 @@ class CoreExport ModuleManager /** Internal unload module hook */ bool CanUnload(Module*); + + /** Loads all core modules (cmd_*) + */ + void LoadCoreModules(std::map& servicemap); + + /** Calls the Prioritize() method in all loaded modules + * @return True if all went well, false if a dependency loop was detected + */ + bool PrioritizeHooks(); + public: + typedef std::map ModuleMap; /** Event handler hooks. * This needs to be public to be used by FOREACH_MOD and friends. @@ -1201,6 +1171,16 @@ class CoreExport ModuleManager /** List of data services keyed by name */ std::multimap DataProviders; + /** A list of ServiceProviders waiting to be registered. + * Non-NULL when constructing a Module, NULL otherwise. + * When non-NULL ServiceProviders add themselves to this list on creation and the core + * automatically registers them (that is, call AddService()) after the Module is constructed, + * and before Module::init() is called. + * If a service is created after the construction of the Module (for example in init()) it + * has to be registered manually. + */ + ServiceList* NewServices; + /** Simple, bog-standard, boring constructor. */ ModuleManager(); @@ -1309,14 +1289,6 @@ class CoreExport ModuleManager void UnloadAll(); void DoSafeUnload(Module*); - /** Get the total number of currently loaded modules - * @return The number of loaded modules - */ - int GetCount() - { - return this->ModCount; - } - /** Find a module by name, and return a Module* to it. * This is preferred over iterating the module lists yourself. * @param name The module name to look up @@ -1330,6 +1302,11 @@ class CoreExport ModuleManager /** Unregister a service provided by a module */ void DelService(ServiceProvider&); + /** Register all services in a given ServiceList + * @param list The list containing the services to register + */ + void AddServices(const ServiceList& list); + inline void AddServices(ServiceProvider** list, int count) { for(int i=0; i < count; i++) @@ -1346,13 +1323,10 @@ class CoreExport ModuleManager return static_cast(FindService(SERVICE_DATA, name)); } - /** Return a list of all modules matching the given filter - * @param filter This int is a bitmask of flags set in Module::Flags, - * such as VF_VENDOR or VF_STATIC. If you wish to receive a list of - * all modules with no filtering, set this to 0. - * @return The list of module names + /** Get a map of all loaded modules keyed by their name + * @return A ModuleMap containing all loaded modules */ - const std::vector GetAllModuleNames(int filter); + const ModuleMap& GetModules() const { return Modules; } }; /** Do not mess with these functions unless you know the C preprocessor @@ -1382,11 +1356,7 @@ struct AllModuleList { }; #define MODULE_INIT(x) static Module* MK_ ## x() { return new x; } \ - static const AllModuleList PREP_ ## x(&MK_ ## x, MODNAMESTR); - -#define MODNAMESTR MODNAMESTR_FN_2(MODNAME) -#define MODNAMESTR_FN_2(x) MODNAMESTR_FN_1(x) -#define MODNAMESTR_FN_1(x) #x + static const AllModuleList PREP_ ## x(&MK_ ## x, MODNAME ".so"); #else @@ -1419,7 +1389,7 @@ struct AllModuleList { { \ return new y; \ } \ - extern "C" const char inspircd_src_version[] = VERSION " r" REVISION; + extern "C" DllExport const char inspircd_src_version[] = VERSION " " REVISION; #endif #define COMMAND_INIT(c) MODULE_INIT(CommandModule)