X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules.h;h=9928ad32618c1098c9f9239d0ff2927e40925e7c;hb=5e9a6b9186a8cbaaf65ae7d9cd9c0c033c91b497;hp=ef103a1a595d7ce78fc5db71bcddddac57a88657;hpb=e65c1d261c26702dac82a6390be3fa757bbed6ec;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules.h b/include/modules.h index ef103a1a5..9928ad326 100644 --- a/include/modules.h +++ b/include/modules.h @@ -75,7 +75,7 @@ enum MessageType { * ipv4 servers, so this value will be ten times as * high on ipv6 servers. */ -#define NATIVE_API_VERSION 11008 +#define NATIVE_API_VERSION 11009 #ifdef IPV6 #define API_VERSION (NATIVE_API_VERSION * 10) #else @@ -117,9 +117,9 @@ typedef std::map > interfacelist; { \ ServerInstance->modules[_i]->x ; \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - ServerInstance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \ + ServerInstance->Log(DEFAULT,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } @@ -131,9 +131,9 @@ typedef std::map > interfacelist; { \ z->modules[_i]->x ; \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - z->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \ + z->Log(DEFAULT,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } @@ -154,9 +154,9 @@ typedef std::map > interfacelist; break; \ } \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - ServerInstance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ + ServerInstance->Log(DEFAULT,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } \ @@ -175,9 +175,9 @@ typedef std::map > interfacelist; break; \ } \ } \ - catch (ModuleException& modexcept) \ + catch (CoreException& modexcept) \ { \ - z->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ + z->Log(DEBUG,"Exception cought: %s",modexcept.GetReason()); \ } \ } \ } \ @@ -328,13 +328,18 @@ class CoreException : public std::exception /** Holds the error message to be displayed */ const std::string err; + const std::string source; public: /** Default constructor, just uses the error mesage 'Core threw an exception'. */ - CoreException() : err("Core threw an exception") {} + CoreException() : err("Core threw an exception"), source("The core") {} /** This constructor can be used to specify an error message before throwing. */ - CoreException(const std::string &message) : err(message) {} + CoreException(const std::string &message) : err(message), source("The core") {} + /** This constructor can be used to specify an error message before throwing, + * and to specify the source of the exception. + */ + CoreException(const std::string &message, const std::string &src) : err(message), source(src) {} /** This destructor solves world hunger, cancels the world debt, and causes the world to end. * Actually no, it does nothing. Never mind. * @throws Nothing! @@ -347,6 +352,11 @@ class CoreException : public std::exception { return err.c_str(); } + + virtual const char* GetSource() + { + return source.c_str(); + } }; class ModuleException : public CoreException @@ -354,11 +364,11 @@ class ModuleException : public CoreException public: /** Default constructor, just uses the error mesage 'Module threw an exception'. */ - ModuleException() : CoreException("Module threw an exception") {} + ModuleException() : CoreException("Module threw an exception", "A Module") {} /** This constructor can be used to specify an error message before throwing. */ - ModuleException(const std::string &message) : CoreException(message) {} + ModuleException(const std::string &message) : CoreException(message, "A Module") {} /** This destructor solves world hunger, cancels the world debt, and causes the world to end. * Actually no, it does nothing. Never mind. * @throws Nothing! @@ -384,7 +394,7 @@ enum Implementation { I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUse I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan, I_OnDelBan, I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList, - I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect }; + I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine, I_OnBuildExemptList, I_OnRawSocketConnect, I_OnGarbageCollect }; /** Base class for all InspIRCd modules * This class is the base class for InspIRCd modules. All modules must inherit from this class, @@ -1331,6 +1341,13 @@ class Module : public Extensible * receive it, or zero to allow the line to be sent. */ virtual int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text); + + /** Called at intervals for modules to garbage-collect any hashes etc. + * Certain data types such as hash_map 'leak' buckets, which must be + * tidied up and freed by copying into a new item every so often. This + * method is called when it is time to do that. + */ + virtual void OnGarbageCollect(); }; @@ -1377,17 +1394,33 @@ class ConfigReader : public classbase * This method destroys the ConfigReader class. */ ~ConfigReader(); + /** Retrieves a value from the config file. * This method retrieves a value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. */ std::string ReadValue(const std::string &tag, const std::string &name, int index, bool allow_linefeeds = false); + /** Retrieves a value from the config file. + * This method retrieves a value from the config file. Where multiple copies of the tag + * exist in the config file, index indicates which of the values to retrieve. If the + * tag is not found the default value is returned instead. + */ + std::string ReadValue(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool allow_linefeeds = false); + /** Retrieves a boolean value from the config file. * This method retrieves a boolean value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" * and "true" in the config file count as true to ReadFlag, and any other value counts as false. */ bool ReadFlag(const std::string &tag, const std::string &name, int index); + /** Retrieves a boolean value from the config file. + * This method retrieves a boolean value from the config file. Where multiple copies of the tag + * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" + * and "true" in the config file count as true to ReadFlag, and any other value counts as false. + * If the tag is not found, the default value is used instead. + */ + bool ReadFlag(const std::string &tag, const std::string &name, const std::string &default_value, int index); + /** Retrieves an integer value from the config file. * This method retrieves an integer value from the config file. Where multiple copies of the tag * exist in the config file, index indicates which of the values to retrieve. Any invalid integer @@ -1397,6 +1430,16 @@ class ConfigReader : public classbase * will return CONF_NOT_UNSIGNED */ long ReadInteger(const std::string &tag, const std::string &name, int index, bool needs_unsigned); + /** Retrieves an integer value from the config file. + * This method retrieves an integer value from the config file. Where multiple copies of the tag + * exist in the config file, index indicates which of the values to retrieve. Any invalid integer + * values in the tag will cause the objects error value to be set, and any call to GetError() will + * return CONF_INVALID_NUMBER to be returned. needs_unsigned is set if the number must be unsigned. + * If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError() + * will return CONF_NOT_UNSIGNED. If the tag is not found, the default value is used instead. + */ + long ReadInteger(const std::string &tag, const std::string &name, const std::string &default_value, int index, bool needs_unsigned); + /** Returns the last error to occur. * Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition. * A call to GetError() resets the error flag back to 0.