Remove String->const char* conversion operator in favor of c_str method
[clinton/bobotpp.git] / source / UserList.C
index b5a795e..afd49fa 100644 (file)
 
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
 
+#include <cstdlib>
 #include <fstream>
 #include <iostream>
 
@@ -37,38 +39,48 @@ UserList::~UserList()
 void
 UserList::read()
 {
-  std::ifstream file(listFilename);
+  std::ifstream file(listFilename.c_str ());
   String temp, empty = "";
   int line = 1;
 
   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.count_tokens(':') != 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.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++;
-  }
+
+  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, std::atoi(level.c_str ()),
+                                  std::atoi(prot.c_str ()), std::atoi(aop.c_str ()),
+                                  std::atol(expiration.c_str ()), password));
+      line++;
+    }
+
   file.close();
 }
 
@@ -76,26 +88,35 @@ void
 UserList::save()
 {
   std::list<UserListItem *>::iterator it = l.begin();
-  std::ofstream file(listFilename);
+  std::ofstream file(listFilename.c_str ());
   
   if (!file)
     return;
 
-  // FIXME: fix bug (see BUGS) and inc once
-  ++it; ++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;
+       }
     }
 }
 
@@ -104,11 +125,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
@@ -145,11 +167,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;
 }