]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Convert GenRandom to std::function.
authorPeter Powell <petpow@saberuk.com>
Sat, 25 Nov 2017 12:50:11 +0000 (12:50 +0000)
committerPeter Powell <petpow@saberuk.com>
Sat, 25 Nov 2017 13:38:02 +0000 (13:38 +0000)
include/inspircd.h
src/helperfuncs.cpp
src/inspircd.cpp
src/modules/extra/m_ssl_gnutls.cpp

index cbd43da43fc396f4cfbea7c7f960f21fe0597f17..00a705dd095328659f66f74998ce8ac733d9c945 100644 (file)
@@ -165,8 +165,6 @@ class serverstats
        }
 };
 
-DEFINE_HANDLER2(GenRandomHandler, void, char*, size_t);
-
 /** The main class of the irc server.
  * This class contains instances of all the other classes in this software.
  * Amongst other things, it contains a ModeParser, a DNS object, a CommandParser
@@ -209,9 +207,6 @@ class CoreExport InspIRCd
        /** Actions that must happen outside of the current call stack */
        ActionList AtomicActions;
 
-       /**** Functors ****/
-       GenRandomHandler HandleGenRandom;
-
        /** Globally accessible fake user record. This is used to force mode changes etc across s2s, etc.. bit ugly, but.. better than how this was done in 1.1
         * Reason for it:
         * kludge alert!
@@ -339,7 +334,14 @@ class CoreExport InspIRCd
        unsigned long GenRandomInt(unsigned long max);
 
        /** Fill a buffer with random bits */
-       caller2<void, char*, size_t> GenRandom;
+       TR1NS::function<void(char*, size_t)> GenRandom;
+
+       /** Fills the output buffer with the specified number of random characters.
+        * This is the default function for InspIRCd::GenRandom.
+        * @param output The output buffer to store random characters in.
+        * @param max The maximum number of random characters to put in the buffer.
+        */
+       static void DefaultGenRandom(char* output, size_t max);
 
        /** Bind all ports specified in the configuration file.
         * @return The number of ports bound without error
index a24401542293e3a10a02ef4821ec4503cf26db36..b80a3897c49abc12fc82f57be648bb14f07875ed 100644 (file)
@@ -415,7 +415,7 @@ unsigned long InspIRCd::GenRandomInt(unsigned long max)
 }
 
 // This is overridden by a higher-quality algorithm when SSL support is loaded
-void GenRandomHandler::Call(char *output, size_t max)
+void InspIRCd::DefaultGenRandom(char* output, size_t max)
 {
        for(unsigned int i=0; i < max; i++)
 #ifdef _WIN32
index 5f7dfd06fdace1a24c9a9bddeed3e41010e12f8e..d7b616ecc8ec2ca7a9ea666afeb612861498e4fc 100644 (file)
@@ -226,7 +226,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
          * THIS MUST MATCH THE ORDER OF DECLARATION OF THE FUNCTORS, e.g. the methods
          * themselves within the class.
          */
-        GenRandom(&HandleGenRandom),
+        GenRandom(&DefaultGenRandom),
         IsChannel(&DefaultIsChannel),
         IsNick(&DefaultIsNick),
         IsIdent(&DefaultIsIdent)
index 2d278c967b8b03d3cf605567a424c5c112706125..97fdf504c41b52619bffe2140606b135704bf6bd 100644 (file)
@@ -112,10 +112,10 @@ typedef gnutls_connection_end_t inspircd_gnutls_session_init_flags_t;
 
 static Module* thismod;
 
-class RandGen : public HandlerBase2<void, char*, size_t>
+class RandGen
 {
  public:
-       void Call(char* buffer, size_t len) CXX11_OVERRIDE
+       static void Call(char* buffer, size_t len)
        {
 #ifdef GNUTLS_HAS_RND
                gnutls_rnd(GNUTLS_RND_RANDOM, buffer, len);
@@ -1272,7 +1272,6 @@ class ModuleSSLGnuTLS : public Module
 
        // First member of the class, gets constructed first and destructed last
        GnuTLS::Init libinit;
-       RandGen randhandler;
        ProfileList profiles;
 
        void ReadProfiles()
@@ -1352,7 +1351,7 @@ class ModuleSSLGnuTLS : public Module
        {
                ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "GnuTLS lib version %s module was compiled for " GNUTLS_VERSION, gnutls_check_version(NULL));
                ReadProfiles();
-               ServerInstance->GenRandom = &randhandler;
+               ServerInstance->GenRandom = RandGen::Call;
        }
 
        void OnModuleRehash(User* user, const std::string &param) CXX11_OVERRIDE
@@ -1372,7 +1371,7 @@ class ModuleSSLGnuTLS : public Module
 
        ~ModuleSSLGnuTLS()
        {
-               ServerInstance->GenRandom = &ServerInstance->HandleGenRandom;
+               ServerInstance->GenRandom = &InspIRCd::DefaultGenRandom;
        }
 
        void OnCleanup(ExtensionItem::ExtensibleType type, Extensible* item) CXX11_OVERRIDE