diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-04-14 18:20:02 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-14 18:20:02 +0200 |
commit | 48f7fa6b11a0a6b1526c54914e60ddbe51ede8c4 (patch) | |
tree | 2f913e22d7de15e80b8a269bb4213bfd3d7b1406 /include/uid.h | |
parent | f8127cf8c51d7991e4cf809f161701aac5276975 (diff) |
Extract UID/SID generation logic into a new class: UIDGenerator
Diffstat (limited to 'include/uid.h')
-rw-r--r-- | include/uid.h | 32 |
1 files changed, 32 insertions, 0 deletions
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); +}; |