summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-04-14 18:20:02 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-14 18:20:02 +0200
commit48f7fa6b11a0a6b1526c54914e60ddbe51ede8c4 (patch)
tree2f913e22d7de15e80b8a269bb4213bfd3d7b1406 /include
parentf8127cf8c51d7991e4cf809f161701aac5276975 (diff)
Extract UID/SID generation logic into a new class: UIDGenerator
Diffstat (limited to 'include')
-rw-r--r--include/inspircd.h18
-rw-r--r--include/testsuite.h1
-rw-r--r--include/uid.h32
3 files changed, 34 insertions, 17 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index b0fadb336..929674eb3 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -294,8 +294,6 @@ DEFINE_HANDLER2(IsChannelHandler, bool, const std::string&, size_t);
DEFINE_HANDLER1(RehashHandler, void, const std::string&);
DEFINE_HANDLER3(OnCheckExemptionHandler, ModResult, User*, Channel*, const std::string&);
-class TestSuite;
-
/** 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
@@ -305,10 +303,6 @@ class TestSuite;
class CoreExport InspIRCd
{
private:
- /** Holds the current UID. Used to generate the next one.
- */
- char current_uid[UUID_LENGTH];
-
/** Set up the signal handlers
*/
void SetSignals();
@@ -323,10 +317,6 @@ class CoreExport InspIRCd
*/
void DoSocketTimeouts(time_t TIME);
- /** Increments the current UID by one.
- */
- void IncrementUID(int pos);
-
/** Perform background user events such as PING checks
*/
void DoBackgroundUserStuff();
@@ -348,6 +338,8 @@ class CoreExport InspIRCd
public:
+ UIDGenerator UIDGen;
+
/** Global cull list, will be processed on next iteration
*/
CullList GlobalCulls;
@@ -373,10 +365,6 @@ class CoreExport InspIRCd
*/
FakeUser* FakeClient;
- /** Returns the next available UID for this server.
- */
- std::string GetUID();
-
static const char LogHeader[];
/** Find a user in the UUID hash
@@ -828,8 +816,6 @@ class CoreExport InspIRCd
{
return this->ReadBuffer;
}
-
- friend class TestSuite;
};
ENTRYPOINT;
diff --git a/include/testsuite.h b/include/testsuite.h
index 43064b063..7f0b2236a 100644
--- a/include/testsuite.h
+++ b/include/testsuite.h
@@ -20,7 +20,6 @@
class TestSuite
{
- bool RealGenerateUIDTests();
public:
TestSuite();
~TestSuite();
diff --git a/include/uid.h b/include/uid.h
index 3783e7ada..8be003628 100644
--- a/include/uid.h
+++ b/include/uid.h
@@ -25,3 +25,35 @@
*/
#define UUID_LENGTH 10
+class TestSuite;
+
+class CoreExport UIDGenerator
+{
+ friend class TestSuite;
+
+ /** Holds the current UID. Used to generate the next one.
+ */
+ char current_uid[UUID_LENGTH];
+
+ /** Increments the current UID by one.
+ */
+ void IncrementUID(unsigned int pos);
+
+ public:
+ /** Initializes this UID generator with the given SID
+ * @param sid SID that conforms to InspIRCd::IsSID()
+ */
+ void init(const std::string& sid);
+
+ /** Returns the next available UID for this server.
+ */
+ std::string GetUID();
+
+ /** Generates a pseudorandom SID based on a servername and a description
+ * Guaranteed to return the same if invoked with the same parameters
+ * @param servername The server name to use as seed
+ * @param serverdesc The server description to use as seed
+ * @return A valid SID
+ */
+ static std::string GenerateSID(const std::string& servername, const std::string& serverdesc);
+};