summaryrefslogtreecommitdiff
path: root/include/inspircd.h
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-09 02:22:27 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-02-09 02:22:27 +0000
commitaab7998583ca16590a32c7bdb80955a18b090700 (patch)
treea2b7f6d82a523e683347b7489ab77f0e940bdede /include/inspircd.h
parentdb790d9d1516c9c7cd48738340e5df1c8a2bebe3 (diff)
Add random number generation functions to InspIRCd class.
Default implementation uses libc random(), which can be better than rand(). If gnutls is loaded, gcrypt will be used to provide random numbers. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12404 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include/inspircd.h')
-rw-r--r--include/inspircd.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 25ba846bc..b4fd12026 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -234,6 +234,7 @@ class serverstats
};
DEFINE_HANDLER2(IsNickHandler, bool, const char*, size_t);
+DEFINE_HANDLER2(GenRandomHandler, void, char*, size_t);
DEFINE_HANDLER1(IsIdentHandler, bool, const char*);
DEFINE_HANDLER1(FloodQuitUserHandler, void, User*);
DEFINE_HANDLER2(IsChannelHandler, bool, const char*, size_t);
@@ -310,6 +311,7 @@ class CoreExport InspIRCd
IsChannelHandler HandleIsChannel;
IsSIDHandler HandleIsSID;
RehashHandler HandleRehash;
+ 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:
@@ -449,6 +451,20 @@ class CoreExport InspIRCd
/** Update the current time. Don't call this unless you have reason to do so. */
void UpdateTime();
+ /** Generate a random string with the given length
+ * @param length The length in bytes
+ * @param printable if false, the string will use characters 0-255; otherwise,
+ * it will be limited to 0x30-0x7E ('0'-'~', nonspace printable characters)
+ */
+ std::string GenRandomStr(int length, bool printable = true);
+ /** Generate a random integer.
+ * This is generally more secure than rand()
+ */
+ unsigned long GenRandomInt(unsigned long max);
+
+ /** Fill a buffer with random bits */
+ caller2<void, char*, size_t> GenRandom;
+
/** Bind all ports specified in the configuration file.
* @return The number of ports bound without error
*/