diff options
author | Peter Powell <petpow@saberuk.com> | 2017-11-25 12:15:35 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2017-11-25 13:38:02 +0000 |
commit | 7ece928bab20881d6fe24c4479f4ff9e0a8a7179 (patch) | |
tree | 9006cd8dc53b482da1edc62546bedcef5542dad0 | |
parent | 4ac124cf89b175a0c78025e97205f4ad14fcc39d (diff) |
Convert IsNick to std::function.
-rw-r--r-- | include/compat.h | 2 | ||||
-rw-r--r-- | include/inspircd.h | 15 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 2 | ||||
-rw-r--r-- | src/inspircd.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_nationalchars.cpp | 9 |
5 files changed, 16 insertions, 14 deletions
diff --git a/include/compat.h b/include/compat.h index 1e6fc3d45..4678de12a 100644 --- a/include/compat.h +++ b/include/compat.h @@ -28,11 +28,13 @@ #if defined _LIBCPP_VERSION || defined _WIN32 # define TR1NS std # include <array> +# include <functional> # include <unordered_map> # include <type_traits> #else # define TR1NS std::tr1 # include <tr1/array> +# include <tr1/functional> # include <tr1/unordered_map> # include <tr1/type_traits> #endif diff --git a/include/inspircd.h b/include/inspircd.h index 47ec9e0e2..da86698a6 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -165,7 +165,6 @@ class serverstats } }; -DEFINE_HANDLER1(IsNickHandler, bool, const std::string&); DEFINE_HANDLER2(GenRandomHandler, void, char*, size_t); DEFINE_HANDLER1(IsIdentHandler, bool, const std::string&); DEFINE_HANDLER1(IsChannelHandler, bool, const std::string&); @@ -213,8 +212,6 @@ class CoreExport InspIRCd ActionList AtomicActions; /**** Functors ****/ - - IsNickHandler HandleIsNick; IsIdentHandler HandleIsIdent; IsChannelHandler HandleIsChannel; GenRandomHandler HandleGenRandom; @@ -417,11 +414,15 @@ class CoreExport InspIRCd static const char* Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2); static const char* Format(va_list &vaList, const char* formatString) CUSTOM_PRINTF(2, 0); - /** Return true if a nickname is valid - * @param n A nickname to verify - * @return True if the nick is valid + /** Determines whether a nickname is valid. */ + TR1NS::function<bool(const std::string&)> IsNick; + + /** Determines whether a nickname is valid according to the RFC 1459 rules. + * This is the default function for InspIRCd::IsNick. + * @param nick The nickname to validate. + * @return True if the nickname is valid according to RFC 1459 rules; otherwise, false. */ - caller1<bool, const std::string&> IsNick; + static bool DefaultIsNick(const std::string& nick); /** Return true if an ident is valid * @param An ident to verify diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index ddcff5e55..5d4778b63 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -216,7 +216,7 @@ bool IsChannelHandler::Call(const std::string& chname) } /* true for valid nickname, false else */ -bool IsNickHandler::Call(const std::string& n) +bool InspIRCd::DefaultIsNick(const std::string& n) { if (n.empty() || n.length() > ServerInstance->Config->Limits.NickMax) return false; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 6c45a1a0d..20001dbca 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -228,7 +228,7 @@ InspIRCd::InspIRCd(int argc, char** argv) : */ GenRandom(&HandleGenRandom), IsChannel(&HandleIsChannel), - IsNick(&HandleIsNick), + IsNick(&DefaultIsNick), IsIdent(&HandleIsIdent) { ServerInstance = this; diff --git a/src/modules/m_nationalchars.cpp b/src/modules/m_nationalchars.cpp index bb95ecc93..81c2d2959 100644 --- a/src/modules/m_nationalchars.cpp +++ b/src/modules/m_nationalchars.cpp @@ -28,10 +28,10 @@ #include "inspircd.h" #include <fstream> -class lwbNickHandler : public HandlerBase1<bool, const std::string&> +class lwbNickHandler { public: - bool Call(const std::string&) CXX11_OVERRIDE; + static bool Call(const std::string&); }; /*,m_reverse_additionalUp[256];*/ @@ -217,10 +217,9 @@ bool lwbNickHandler::Call(const std::string& nick) class ModuleNationalChars : public Module { - lwbNickHandler myhandler; std::string charset; unsigned char m_additional[256], m_additionalUp[256], m_lower[256], m_upper[256]; - caller1<bool, const std::string&> rememberer; + TR1NS::function<bool(const std::string&)> rememberer; bool forcequit; const unsigned char * lowermap_rememberer; unsigned char prev_map[256]; @@ -259,7 +258,7 @@ class ModuleNationalChars : public Module memcpy(m_lower, rfc_case_insensitive_map, 256); national_case_insensitive_map = m_lower; - ServerInstance->IsNick = &myhandler; + ServerInstance->IsNick = &lwbNickHandler::Call; } void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE |