X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=include%2Fmodules.h;h=b7cffd1a080d740ff33c7ffcc18fa93cc815464f;hb=02830985a18950497003f3392cf8d6cc30c15c50;hp=e81f9465c1f41dc4de30e9f8998cc6d437fc5195;hpb=d349f981fbe70fb11e3db4c486f59749ffe74c2b;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules.h b/include/modules.h index e81f9465c..b7cffd1a0 100644 --- a/include/modules.h +++ b/include/modules.h @@ -623,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. @@ -669,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 @@ -1117,44 +1078,6 @@ class CoreExport Module : public classbase, public usecountbase virtual void OnSetUserIP(LocalUser* user); }; -/** Provides an easy method of reading a text file into memory. */ -class CoreExport FileReader : public classbase -{ - /** The lines of text in the file. - */ - std::vector lines; - - /** Content size in bytes - */ - unsigned long totalSize; - - public: - /** Initializes a new file reader. - */ - FileReader() : totalSize(0) { } - - /** Initializes a new file reader and reads the specified file. - * @param filename The file to read into memory. - */ - FileReader(const std::string& filename); - - /** Loads a text file from disk. - * @param filename The file to read into memory. - * @throw CoreException The file can not be loaded. - */ - void Load(const std::string& filename); - - /** Retrieves the entire contents of the file cache as a single string. - */ - std::string GetString(); - - /** Retrieves the entire contents of the file cache as a vector of strings. - */ - const std::vector& GetVector() { return lines; } - - unsigned long TotalSize() { return totalSize; } -}; - /** A list of modules */ typedef std::vector IntModuleList; @@ -1168,15 +1091,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,6 +1113,15 @@ 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; @@ -1202,6 +1133,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(); @@ -1310,14 +1251,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 @@ -1331,6 +1264,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++) @@ -1380,11 +1318,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 @@ -1417,7 +1351,7 @@ struct AllModuleList { { \ return new y; \ } \ - extern "C" const char inspircd_src_version[] = VERSION " " REVISION; + extern "C" DllExport const char inspircd_src_version[] = VERSION " " REVISION; #endif #define COMMAND_INIT(c) MODULE_INIT(CommandModule)