[project @ 2005-06-01 00:27:44 by unknown_lamer]
[clinton/bobotpp.git] / source / UserList.C
index 8a414a1..b2f75a6 100644 (file)
@@ -1,6 +1,6 @@
 // Userlist.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (C) 2002 Clinton Ebadi
+// Copyright (C) 2002,2005 Clinton Ebadi
 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 
 #include "UserList.H"
 #include "StringTokenizer.H"
+#include "Utils.H"
 
 UserList::UserList(String filename)
   : listFilename(filename)
@@ -42,32 +43,42 @@ UserList::read()
 
   clear();
 
-  if (!file) {
-    std::cerr << "I cannot find the file " << listFilename << std::endl;
-    return;
-  }
-
-  while (file >> temp, temp.length() != 0) {
-    StringTokenizer st(temp);
-    if (st.countTokens(':') != 7) {
-      std::cerr << "Error when reading userlist (" << listFilename <<
-        ") line " << line << "...\n";
+  if (!file) 
+    {
+      std::cerr << "I cannot find the file " << listFilename << std::endl;
       return;
     }
-    String mask = st.nextToken(':');
-    String maskChannel = st.nextToken(':');
-    String level = st.nextToken(':');
-    String prot = st.nextToken(':');
-    String aop = st.nextToken(':');
-    String expiration = st.nextToken(':');
-    String password = st.rest().trim();
-    if (password == "*NONE*")
-      password = "";
-    l.push_back(new UserListItem(mask, maskChannel, atoi(level),
-                                 atoi(prot), atoi(aop),
-                                 atol(expiration), password));
-    line++;
-  }
+
+  while (file >> temp, temp.length() != 0) 
+    {
+      StringTokenizer st(temp);
+
+      if (st.count_tokens(':') != 7)
+       {
+         std::cerr << "Error when reading userlist (" << listFilename <<
+           ") line " << line << "...\n";
+         return;
+       }
+      
+      String mask = st.next_token(':');
+      String maskChannel = st.next_token(':');
+      String level = st.next_token(':');
+      String prot = st.next_token(':');
+      String aop = st.next_token(':');
+      String expiration = st.next_token(':');
+      String password = Utils::trim_str (st.rest());
+      
+      if (password == "*NONE*")
+       {
+         password = "";
+       }
+      
+      l.push_back(new UserListItem(mask, maskChannel, atoi(level),
+                                  atoi(prot), atoi(aop),
+                                  atol(expiration), password));
+      line++;
+    }
+
   file.close();
 }
 
@@ -80,20 +91,30 @@ UserList::save()
   if (!file)
     return;
 
-  ++it; // We skip the bot's entry
+  ++it; // Skip the bot's entry
+
   for ( ; it != l.end(); ++it)
-    if ((*it)->isStillValid()) {
-      file << (*it)->mask.getMask() << ":"
-           << (*it)->channelMask.getMask() << ":"
-           << (*it)->level << ":"
-           << (*it)->prot << ":"
-           << (*it)->aop << ":"
-           << (*it)->expirationDate << ":";
-      if ((*it)->passwd == "")
-        file << "*NONE*";
-      else
-        file << (*it)->passwd;
-      file << std::endl;
+    {
+      if ((*it)->isStillValid())
+       {
+         file << (*it)->mask.getMask() << ":"
+              << (*it)->channelMask.getMask() << ":"
+              << (*it)->level << ":"
+              << (*it)->prot << ":"
+              << (*it)->aop << ":"
+              << (*it)->expirationDate << ":";
+       
+         if ((*it)->passwd == "")
+           {
+             file << "*NONE*";
+           }
+         else
+           {
+             file << (*it)->passwd;
+           }
+
+         file << std::endl;
+       }
     }
 }
 
@@ -102,11 +123,12 @@ UserList::clear()
 {
   UserListItem *uli;
 
-  while (!l.empty()) {
-    uli = (*l.begin());
-    l.erase(l.begin());
-    delete uli;
-  }
+  while (!l.empty())
+    {
+      uli = (*l.begin());
+      l.erase(l.begin());
+      delete uli;
+    }
 }
 
 void
@@ -143,11 +165,16 @@ UserList::getMaxLevel(String nuh)
 
   for (std::list<UserListItem *>::iterator it = l.begin();
        it != l.end(); it++)
-    if ((*it)->matches(nuh) && level < (*it)->level &&
-        ((*it)->expirationDate == -1 ||
-         (*it)->expirationDate > current_time) &&
-        ((*it)->passwd == "" || (*it)->identified > 0))
-      level = (*it)->level;
+    {
+      if ((*it)->matches(nuh) && level < (*it)->level 
+         && ((*it)->expirationDate == -1 
+             || (*it)->expirationDate > current_time) 
+         && ((*it)->passwd == "" 
+             || (*it)->identified > 0))
+       {
+         level = (*it)->level;
+       }
+    }
 
   return level;
 }