Logo Search packages:      
Sourcecode: sbnc version File versions  Download package

void CCore::UpdateUserConfig ( void   )  [private]

UpdateUserConfig

Updates the user list in the main config file.

Definition at line 1227 of file Core.cpp.

References m_Config, and m_Users.

Referenced by CreateUser(), and RemoveUser().

                                 {
#define MEMORYBLOCKSIZE 4096
      size_t Size;
      int i;
      char *Out = NULL;
      size_t Blocks = 0, NewBlocks = 1, Length = 1;
      size_t Offset = 0, NameLength;
      bool WasNull = true;

      i = 0;
      while (hash_t<CUser *> *User = m_Users.Iterate(i++)) {
            NameLength = strlen(User->Name);
            Length += NameLength + 1;

            NewBlocks += Length / MEMORYBLOCKSIZE;
            Length -= (Length / MEMORYBLOCKSIZE) * MEMORYBLOCKSIZE;

            if (NewBlocks > Blocks) {
                  Size = (NewBlocks + 1) * MEMORYBLOCKSIZE;
                  Out = (char *)realloc(Out, Size);
            }

            Blocks = NewBlocks;

            if (Out == NULL) {
                  LOGERROR("realloc() failed. Userlist in sbnc.conf might be out of date.");

                  return;
            }

#undef strcpy
            if (!WasNull) {
                  Out[Offset] = ' ';
                  Offset++;
                  strcpy(Out + Offset, User->Name);
            } else {
                  WasNull = false;
            }

            strcpy(Out + Offset, User->Name);
            Offset += NameLength;
      }

      if (m_Config != NULL) {
            CacheSetString(m_ConfigCache, users, Out);
      }

      free(Out);
}


Generated by  Doxygen 1.6.0   Back to index