]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Use std::string internally in UIDGenerator, move UUID_LENGTH into the class as a...
authorattilamolnar <attilamolnar@hush.com>
Sun, 14 Apr 2013 16:35:41 +0000 (18:35 +0200)
committerattilamolnar <attilamolnar@hush.com>
Sun, 14 Apr 2013 16:35:41 +0000 (18:35 +0200)
include/uid.h
src/modules/m_spanningtree/netburst.cpp
src/modules/m_spanningtree/treesocket2.cpp
src/server.cpp
src/testsuite.cpp

index 8be003628393e8aa286f419f77a3c95367b6ea1a..772c8a7165fafb9b36e35db98b4885afa1be1add 100644 (file)
 
 #pragma once
 
-/**
- * This is the maximum length of a UUID (unique user identifier).
- * This length is set in compliance with TS6 protocol, and really should not be changed. Ever.
- * It allows for a lot of clients as-is. -- w00t.
- */
-#define UUID_LENGTH 10
-
 class TestSuite;
 
 class CoreExport UIDGenerator
@@ -33,13 +26,20 @@ class CoreExport UIDGenerator
 
        /** Holds the current UID. Used to generate the next one.
         */
-       char current_uid[UUID_LENGTH];
+       std::string current_uid;
 
        /** Increments the current UID by one.
         */
        void IncrementUID(unsigned int pos);
 
  public:
+       /**
+       * This is the maximum length of a UUID (unique user identifier).
+       * This length is set in compliance with TS6 protocol, and really should not be changed. Ever.
+       * It allows for a lot of clients as-is. -- w00t.
+       */
+       static const unsigned int UUID_LENGTH = 9;
+
        /** Initializes this UID generator with the given SID
         * @param sid SID that conforms to InspIRCd::IsSID()
         */
index ee5707fdb3f26b502b83890af02bf533dcee79fd..21404e68ee2c1e54b657874c3560b2f80f1ddf28 100644 (file)
@@ -102,7 +102,7 @@ void TreeSocket::SendFJoins(Channel* c)
        for (UserMembCIter i = ulist->begin(); i != ulist->end(); ++i)
        {
                const std::string& modestr = i->second->modes;
-               if ((line.length() + modestr.length() + (UUID_LENGTH-1) + 2) > 480)
+               if ((line.length() + modestr.length() + UIDGenerator::UUID_LENGTH + 2) > 480)
                {
                        this->WriteLine(line);
                        line.erase(erase_from);
index e91214041eb837ab1b3c293d0d35c8255d152b54..1504a88075d4e6b326a57b859a53faa5a53d66b9 100644 (file)
@@ -241,7 +241,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                         * crossing the users QUIT further upstream from the server. Thanks jilles!
                         */
 
-                       if ((prefix.length() == UUID_LENGTH-1) && (isdigit(prefix[0])) &&
+                       if ((prefix.length() == UIDGenerator::UUID_LENGTH) && (isdigit(prefix[0])) &&
                                ((command == "FMODE") || (command == "MODE") || (command == "KICK") || (command == "TOPIC") || (command == "KILL") || (command == "ADDLINE") || (command == "DELLINE")))
                        {
                                /* Special case, we cannot drop these commands as they've been committed already on a
index c49e17b565a8549f0cb3b093138b4c511b483b21..6790b45e77715a37020345b72db58948635c90f9 100644 (file)
@@ -143,15 +143,10 @@ void UIDGenerator::init(const std::string& sid)
         *              -- w
         */
 
+       current_uid.resize(UUID_LENGTH, '9');
        current_uid[0] = sid[0];
        current_uid[1] = sid[1];
        current_uid[2] = sid[2];
-
-       for (int i = 3; i < (UUID_LENGTH - 1); i++)
-               current_uid[i] = '9';
-
-       // Null terminator. Important.
-       current_uid[UUID_LENGTH - 1] = '\0';
 }
 
 /*
@@ -162,7 +157,7 @@ std::string UIDGenerator::GetUID()
        while (1)
        {
                // Add one to the last UID
-               this->IncrementUID(UUID_LENGTH - 2);
+               this->IncrementUID(UUID_LENGTH - 1);
 
                if (!ServerInstance->FindUUID(current_uid))
                        break;
index c107217b74d6ab68315187bffefdd2de3912c3bc..539827cf8d484d0d586d367e643b61df1bc0ee4a 100644 (file)
@@ -331,23 +331,25 @@ bool TestSuite::DoThreadTests()
 
 bool TestSuite::DoGenerateUIDTests()
 {
+       const unsigned int UUID_LENGTH = UIDGenerator::UUID_LENGTH;
        UIDGenerator uidgen;
        uidgen.init(ServerInstance->Config->GetSID());
        std::string first_uid = uidgen.GetUID();
-       if (first_uid.length() != UUID_LENGTH-1)
+
+       if (first_uid.length() != UUID_LENGTH)
        {
                std::cout << "GENERATEUID: Generated UID is " << first_uid.length() << " characters long instead of " << UUID_LENGTH-1 << std::endl;
                return false;
        }
 
-       if (uidgen.current_uid[UUID_LENGTH-1] != '\0')
+       if (uidgen.current_uid.c_str()[UUID_LENGTH] != '\0')
        {
                std::cout << "GENERATEUID: The null terminator is missing from the end of current_uid" << std::endl;
                return false;
        }
 
        // The correct UID when generating one for the first time is ...AAAAAA
-       std::string correct_uid = ServerInstance->Config->sid + std::string(UUID_LENGTH - 4, 'A');
+       std::string correct_uid = ServerInstance->Config->sid + std::string(UUID_LENGTH - 3, 'A');
        if (first_uid != correct_uid)
        {
                std::cout << "GENERATEUID: Generated an invalid first UID: " << first_uid << " instead of " << correct_uid << std::endl;
@@ -356,7 +358,7 @@ bool TestSuite::DoGenerateUIDTests()
 
        // Set current_uid to be ...Z99999
        uidgen.current_uid[3] = 'Z';
-       for (unsigned int i = 4; i < UUID_LENGTH-1; i++)
+       for (unsigned int i = 4; i < UUID_LENGTH; i++)
                uidgen.current_uid[i] = '9';
 
        // Store the UID we'll be incrementing so we can display what's wrong later if necessary
@@ -364,7 +366,7 @@ bool TestSuite::DoGenerateUIDTests()
        std::string generated_uid = uidgen.GetUID();
 
        // Correct UID after incrementing ...Z99999 is ...0AAAAA
-       correct_uid = ServerInstance->Config->sid + "0" + std::string(UUID_LENGTH - 5, 'A');
+       correct_uid = ServerInstance->Config->sid + "0" + std::string(UUID_LENGTH - 4, 'A');
 
        if (generated_uid != correct_uid)
        {
@@ -373,7 +375,7 @@ bool TestSuite::DoGenerateUIDTests()
        }
 
        // Set current_uid to be ...999999 to see if it rolls over correctly
-       for (unsigned int i = 3; i < UUID_LENGTH-1; i++)
+       for (unsigned int i = 3; i < UUID_LENGTH; i++)
                uidgen.current_uid[i] = '9';
 
        before_increment.assign(uidgen.current_uid);