[project @ 2005-01-12 05:36:40 by unknown_lamer]
authorunknown_lamer <unknown>
Wed, 12 Jan 2005 05:36:40 +0000 (05:36 +0000)
committerunknown_lamer <unknown>
Wed, 12 Jan 2005 05:36:40 +0000 (05:36 +0000)
String removal phase 1: added trim, toLower, toUpper, and long2str to
Utils. Converted StringTokenizer to use std::string internally. Did
the same to Utils. Converted both to use _'s between tokens instead of
CamelCase (because we all know that CamelCase is
unreadable...). BotConfig is 99% done (just have to fix
read_config). Fixed a potential but extremely unlikely buffer
overflow.

24 files changed:
ChangeLog
NEWS
source/Bot.C
source/BotConfig.C
source/BotConfig.H
source/BotInterp.C
source/Channel.C
source/Commands.C
source/DCCChatConnection.C
source/DCCParser.C
source/Parser.C
source/Person.C
source/ScriptCommands.C
source/ServerQueue.C
source/ServerQueueItem.C
source/ShitList.C
source/String.C
source/String.H
source/StringTokenizer.C
source/StringTokenizer.H
source/UserCommands.C
source/UserList.C
source/Utils.C
source/Utils.H

index 64028fe..48c763a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,123 @@
+2005-01-12  Clinton Ebadi  <clinton@unknownlamer.org>
+
+       * source/UserList.C: Made to work with new Utils/StringTokenizer names
+
+       * source/UserCommands.C: Made to work with new
+       Utils/StringTokenizer names
+
+       * source/ShitList.C: Uses Utils.H now (Utils::trim_str & friends)
+
+2005-01-11  Clinton Ebadi  <clinton@unknownlamer.org>
+
+       * source/ShitList.C: Made to work with new StringTokenizer names
+
+       * source/ServerQueueItem.C: Made to work with new StringTokenizer names
+
+       * source/ServerQueue.C: Made to work with new Utils names
+
+       * source/ScriptCommands.C: Made work with new Utils names
+
+       * source/Person.C (getNick): Made work with new Utils names
+
+       * source/String.H: Added substr prototypes
+
+       * source/String.C (substr): Added substr as an alias of subString
+       (for compat with std::string before the transition)
+
+       * source/Parser.C: Made to work with new Utils/StringTokenizer names
+
+       * source/DCCParser.C: Made to work with new Utils names
+
+       * source/DCCChatConnection.C: Made to work new Utils names
+
+       * source/Commands.C: Made to work with new Utils names
+
+       * source/Channel.C: Made to work with new Utils names
+
+       * source/BotInterp.C: Made to work with new Utils
+
+       * source/Bot.C: Made to work with new Utils/StringTokenizer names
+
+       * source/String.C (operator=): Unremoved operator=(std::string)
+
+       * source/String.H: Unremoved operator=(std::string)
+
+       * source/BotConfig.C (read_config): Use Utils::trim_str
+
+       * source/String.C (trim): Fixed bug (p->s[i] == '\r', s/i/j/)
+
+       * source/Utils.C (trim_str): Implemented
+
+       * source/Utils.H: Added tim_str (replaces String::trim)
+
+       * source/BotConfig.C: Made everything work with new
+       StringTokenizer and Utils names
+
+       * source/Utils.H: Added to_lower
+       Added to_upper
+
+       * source/StringTokenizer.C (rest): uses std::isspace instead of
+       checking st[pos] against ' ' and '\t'
+
+       * source/StringTokenizer.H: Removed CamelCasing
+       Renamed hasMoreTokens to more_tokens_p
+
+       * source/StringTokenizer.C: Converted to use std::string
+
+       * source/StringTokenizer.H: Converted to use std::string
+
+       * source/String.C: Removed operator=(std::string)
+
+       * source/String.H: Removed operator=(std::string)
+
+       * source/Utils.C: Added copyright
+       Reformatted to match GNU coding standard more closely
+       Converted everything to use std::string
+       (get_nick): Renamed from getNick
+       (get_userhost): Renamed from getUserHost
+       (get_key): Renamed from getKey
+       (IP_p): Renamed from isIP
+       (make_wildcard): Renamed from makeWildcard
+       (channel_p): Renamed from isChannel
+       (wildcard_p): Renamed from isWildcard
+       (valid_channel_name_p): Renamed from isValidChannelName
+       (valid_nickname_p): Renamed from isValidNickName
+       (get_level): Renamed from getLevel
+       (str2time): Renamed from strToTime
+       (str2time): Fixed potential buffer overflow (num[512] => std::string)
+       (level2str): Renamed from levelToStr
+       (prot2str): Renamed from protToStr
+       (bool2str): Renamed from boolToStr
+       (long2str): Implemented
+       (scm2str): Renamed from scm2String
+       (str2scm): Renamed from string2SCM
+
+       * source/BotConfig.C: Reformatted to fit GNU coding style more closely
+
+       * source/Utils.H: Added long2str (long int -> std::string)
+
+       * source/String.H: Added 2003 copyright (the year I last modified
+       it in)
+
+       * source/String.C: Added 2002 copyright (the year I last modified
+       it in)
+
+       * source/Utils.H: Updated Copyright
+       s/String/std::string/g
+       Removed camel casing and is* = *_p
+       xToY = x2y
+
+       * source/BotConfig.C: Updated Copyright
+
+       * source/BotConfig.H: Updated copyright
+
 2005-01-08  Clinton Ebadi  <clinton@unknownlamer.org>
 
+       * source/BotConfig.C (set_option_value): Take care of the case
+       where key is not already in the db
+       (add_watcher): Implemented
+       (read_config): Removed ',' token parsing (not needed)
+
        * configure.ac: Add AC_LANG([C++]) so we can check for C++ libs
        AC_CHECK_LIB ccgnu2 (CommonC++2)
 
diff --git a/NEWS b/NEWS
index 647eaae..a0da5de 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ Version 2.1.5: Cleanups
   Friend of the bot
 - Implemented bot:ctcp-quote
 - The Bot Configuration section of the manual has been completed.
+- Fixed a potential (but unlikely) buffer overflow in Utils::strToTime
+  (if there were more than 512 digits in part of the string form of
+  the time the buffer would overflow)
 - Misc. Bugfixes
 
 Version 2.1.4: DCC Support Enhancements
index 5b59b4c..e799f0f 100644 (file)
@@ -1,6 +1,6 @@
 // Bot.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (C) 2002,2003 Clinton Ebadi
+// Copyright (C) 2002,2003,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
@@ -109,15 +109,15 @@ Bot::Bot(String filename, bool debug_on)
     while (initFile >> temp, temp.length() != 0) {
       line++;
       StringTokenizer st(temp);
-      temp = temp.trim();
+      temp = Utils::trim_str (temp);
       if (temp[0]=='#') continue;
-      if (st.countTokens(' ') != 2) {
+      if (st.count_tokens (' ') != 2) {
         std::cerr << "Error when reading alias file (" << initFileName 
                  << ") line " << line << "...\n";
         continue;
       }
-      alias = st.nextToken().toUpper();
-      command = st.nextToken().toUpper();
+      alias = Utils::to_upper (st.next_token());
+      command = Utils::to_upper (st.next_token());
 
       // Does the function already exist ?
       if (!userFunctions[alias])
@@ -209,8 +209,8 @@ Bot::readConfig()
     }
     
     StringTokenizer st(temp);
-    String command = st.nextToken('=').trim().toUpper();
-    String parameters = st.nextToken('=').trim();
+    String command = Utils::to_upper (Utils::trim_str (st.next_token('=')));
+    String parameters = Utils::trim_str (st.next_token('='));
 
     if (command == "NICK" || command == "NICKNAME")
       nickName = wantedNickName = parameters;
@@ -231,15 +231,15 @@ Bot::readConfig()
                  << " I will use compatibility mode, but you're really"
                  << " missing something.\n";
         StringTokenizer st2(parameters);
-        String name = st2.nextToken().toLower();
-        String key = st2.nextToken();
+        String name = Utils::to_lower (st2.next_token());
+        String key = st2.next_token();
         wantedChannels[name] = new wantedChannel("", "", key);
       } else {
         StringTokenizer st2(parameters);
-        String name = st2.nextToken(':').toLower();
-        String mode = st2.nextToken(':');
-        String keep = st2.nextToken(':');
-        String key = st2.nextToken(':');
+        String name = Utils::to_lower (st2.next_token(':'));
+        String mode = st2.next_token(':');
+        String keep = st2.next_token(':');
+        String key = st2.next_token(':');
         wantedChannels[name] = new wantedChannel(mode, keep, key);
       }
     }
@@ -271,11 +271,11 @@ Bot::readConfig()
         serverList->addServer(new Server(parameters));
       else {
         StringTokenizer st2(parameters);
-        String name = st2.nextToken();
-        int port = std::atoi(st2.nextToken());
+        String name = st2.next_token();
+        int port = std::atoi(st2.next_token().c_str());
         serverList->addServer(new Server(name,
                                          port,
-                                         st2.nextToken()));
+                                         st2.next_token()));
       }
     }
     else {
@@ -395,8 +395,9 @@ Bot::waitForInput()
       {
        char s[6];
        std::sprintf(s, "%2d:%2d", thisTime->tm_hour, thisTime->tm_min);
+       // FIXME: uses gh_list
        botInterp->RunHooks(Hook::TIMER, String(s),
-                           gh_list(Utils::string2SCM(String(s)), 
+                           gh_list(Utils::str2scm (std::string (s)), 
                                    SCM_UNDEFINED));
       }
 #endif
index 87c3edd..82a8035 100644 (file)
@@ -1,5 +1,5 @@
 // BotConfig.C  -*- C++ -*-
-// Copyright (C) 2004 Clinton Ebadi
+// Copyright (C) 2004,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
@@ -18,6 +18,7 @@
 #include "BotConfig.H"
 #include "Bot.H"
 #include "StringTokenizer.H"
+#include "Utils.H"
 #include <iostream>
 #include <string>
 #include <list>
@@ -27,7 +28,8 @@ BotConfig::BotConfig (std::string cf)
   : config_filename (cf)
 { }
 
-bool BotConfig::read_config ()
+bool
+BotConfig::read_config ()
 {
   std::ifstream config_file (config_filename.c_str ());
   std::string current_line;
@@ -54,22 +56,22 @@ bool BotConfig::read_config ()
          continue;
        }
       
+      // This is broken because overwrites existing values
       StringTokenizer st (current_line);
-      std::string command = st.nextToken('=').trim().toUpper();
-      StringTokenizer params (st.nextToken('=').trim());
+      std::string command = Utils::to_upper (Utils::trim_str(st.next_token('=')));
+      StringTokenizer params (Utils::trim_str (st.next_token('=')));
 
       options_db[command] = t_option_values (t_value_list (), 
-                                           t_watcher_list ());
-      while (params.hasMoreTokens (','))
-       {
-         options_db[command].first.push_back (params.nextToken (',').trim());
-       }
+                                            t_watcher_list ());
+      options_db[command].first.push_back (params.rest ());
+    
     }
   return true;
 }
 
 
-BotConfig::t_option_values BotConfig::get_option_values (std::string key)
+BotConfig::t_option_values
+BotConfig::get_option_values (std::string key)
 {
   t_options_db::const_iterator cf_iter = 
     options_db.find (key);
@@ -80,7 +82,8 @@ BotConfig::t_option_values BotConfig::get_option_values (std::string key)
     return t_option_values (); // Empty vector
 }
 
-std::string BotConfig::set_config_file (std::string fname)
+std::string
+BotConfig::set_config_file (std::string fname)
 {
   std::string old_config_filename = config_filename;
   config_filename = fname;
@@ -122,7 +125,8 @@ namespace
   };
 }
 
-void BotConfig::set_option_value (std::string key, t_value_list values, 
+void
+BotConfig::set_option_value (std::string key, t_value_list values, 
                                  bool append)
 {
   t_options_db::iterator cf_iter = options_db.find (key);
@@ -138,9 +142,25 @@ void BotConfig::set_option_value (std::string key, t_value_list values,
       else
        cf_iter->second.first = values;
     }
+  else
+    options_db[key] = t_option_values (values, t_watcher_list ());
 
   // Call Watchers
   std::for_each (cf_iter->second.second.begin (),
                 cf_iter->second.second.end (),
                 run_fun_ (key, values, append));
 }
+
+bool
+BotConfig::add_watcher (std::string key, t_watcher new_watcher)
+{
+  t_options_db::iterator cf_iter = options_db.find (key); 
+
+  if (cf_iter != options_db.end ())
+    {
+      cf_iter->second.second.push_front (new_watcher);
+      return true;
+    }
+  else
+    return false;
+}
index 5d6c61d..a65ca4c 100644 (file)
@@ -1,5 +1,5 @@
 // BotConfig.H  -*- C++ -*-
-// Copyright (C) 2004 Clinton Ebadi
+// Copyright (C) 2004,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
@@ -20,6 +20,9 @@
   map<key,pair<list<string>,list<watcher>>
   void watcher (key, options, appended?)
 
+  NOTE: The key is always UPPERCASE internally. Keys are converted
+  automagically to uppercase by the anything that 
+
 */
 
 #include <map>
@@ -45,9 +48,9 @@ private:
   std::string config_filename;
 
 public:
-  BotConfig (std::string);
+  BotConfig (std::string); // sets config_filename but DOES NOT read config!
 
-  bool read_config (); // true if read successfully
+  bool read_config (); // true if read successfully. This also clears the option_db.
   bool write_config (); // true if written succesfully
 
   // Getters
index e6659a3..9abeb99 100644 (file)
@@ -35,8 +35,8 @@ extern "C"
 BotInterp::BotInterp(Bot *b, String fn)
   : bot(b), counter(0)
 {
-  logPort = scm_open_file(Utils::string2SCM(fn),
-                          Utils::string2SCM("a"));
+  logPort = scm_open_file(Utils::str2scm (fn),
+                          Utils::str2scm ("a"));
   scm_gc_protect_object(logPort);
 }
 
@@ -74,7 +74,7 @@ BotInterp::AddHook(int hooktype, SCM regex, SCM function, int pri, bool fall,
                   String name) {
   if (scm_string_p(regex) == SCM_BOOL_F)
     return false;
-  String rx = Utils::scm2String(regex).toUpper();
+  String rx = Utils::to_upper (Utils::scm2str (regex));
   SCM r = scm_make_regexp(regex,
                           scm_listify (gh_lookup("regexp/icase"),
                                   SCM_UNDEFINED));
@@ -113,7 +113,7 @@ BotInterp::RunHooks(int hooktype, String match, SCM args)
   wrapper_data wd;
   wd.args = args;
   for ( ; it != it2; ++it) {
-    if (scm_regexp_exec((*it)->regex, Utils::string2SCM(match),
+    if (scm_regexp_exec((*it)->regex, Utils::str2scm (match),
                         SCM_UNDEFINED, SCM_UNDEFINED) != SCM_BOOL_F)
       {
        wd.func = (*it)->function;
index 3fd751c..6d0c67d 100644 (file)
@@ -1,6 +1,6 @@
 // Channel.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
@@ -198,7 +198,7 @@ Channel::parseMode(Person *from, String mode)
 {
   char sign = '-';
   StringTokenizer st(mode);
-  String m = st.nextToken(), n;
+  String m = st.next_token(), n;
   User *u = 0;
   if (from)
     u = getUser(from->getNick());
@@ -275,11 +275,11 @@ Channel::parseMode(Person *from, String mode)
         else
           cnx->queue->sendChannelMode(channelName, "-l", "");
       }
-      channelLimit = (sign == '+' ? atoi(st.nextToken()) :
+      channelLimit = (sign == '+' ? std::atoi(st.next_token().c_str()) :
                       channelLimit = 0);
       break;
     case 'k':
-      channelKey = st.nextToken();
+      channelKey = st.next_token();
       if (keepModes.find('k') != -1 && doNotObey) {
         if (sign == '-' && wantedModes.find('k') != -1)
           cnx->queue->sendChannelMode(channelName, "+k", channelKey);
@@ -290,7 +290,7 @@ Channel::parseMode(Person *from, String mode)
                                                String(""));
       break;
     case 'o':
-      n = st.nextToken();
+      n = st.next_token();
       u = getUser(n);
       if (joined)
         sign == '+' ? countOp++ : countOp--;
@@ -324,12 +324,12 @@ Channel::parseMode(Person *from, String mode)
       }
       break;
     case 'v':
-      u = getUser(st.nextToken());
+      u = getUser(st.next_token());
       u->mode = (sign == '+' ? u->mode |= User::VOICE_MODE :
                  u->mode &= ~User::VOICE_MODE);
       break;
     case  'b':
-      String m = st.nextToken();
+      String m = st.next_token();
       sign == '+' ? addBan(m) : delBan(m);
       if (sign == '-') {
         ShitEntry * se =
index 8d289a9..44fc761 100644 (file)
@@ -1,6 +1,6 @@
 // Commands.C  -*- C++ -*-
 // Copyright (c) 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
@@ -82,14 +82,14 @@ Commands::AddUser(Bot *bot, String who, String maskChannel, int level,
 
   String mask;
 
-  if (!Utils::isWildcard(who)) 
+  if (!Utils::wildcard_p(who)) 
     {
     mask = bot->getUserhost("", who);
     if (mask.length() == 0)
       return NotFound(who);
   }
   // Aha! This was before the brace...segfault gone
-  mask = Utils::makeWildcard(mask);
+  mask = Utils::make_wildcard(mask);
 
   if (bot->userList->isInUserList(mask, maskChannel))
     return AlreadyInUserlist(mask, maskChannel);
@@ -127,11 +127,11 @@ Commands::AddShit(Bot *bot, String mask, String maskChannel,
 
   String who = mask;
 
-  if (!Utils::isWildcard(mask)) {
+  if (!Utils::wildcard_p(mask)) {
     mask = bot->getUserhost("", who);
     if (mask.length() == 0)
       return NotFound(who);
-    mask = Utils::makeWildcard(mask);
+    mask = Utils::make_wildcard(mask);
     if (bot->shitList->getShit(mask, maskChannel))
       return AlreadyInShitlist(mask, maskChannel);
   }
@@ -160,7 +160,7 @@ Commands::Ban(Bot *bot, String channel, String who)
 
   String dest;
 
-  if (!Utils::isWildcard(who))
+  if (!Utils::wildcard_p(who))
     dest = bot->getUserhost(channel, who);
   else
     dest = who;
@@ -168,7 +168,7 @@ Commands::Ban(Bot *bot, String channel, String who)
   if (dest.length() == 0)
     return NotFound(who);
 
-  dest = Utils::makeWildcard(dest);
+  dest = Utils::make_wildcard(dest);
   Mask m(dest);
 
   for (std::list<UserListItem *>::iterator it = bot->userList->l.begin();
@@ -218,7 +218,7 @@ Commands::Deban(Bot *bot, String channel, String who)
 
   String dest;
 
-  if (!Utils::isWildcard(who))
+  if (!Utils::wildcard_p(who))
     dest = bot->getUserhost(channel, who);
   else
     dest = who;
@@ -226,7 +226,7 @@ Commands::Deban(Bot *bot, String channel, String who)
   if (dest.length() == 0)
     return UserNotFound(who, channel);
 
-  dest = Utils::makeWildcard(dest);
+  dest = Utils::make_wildcard(dest);
   Mask m(dest);
   
   for (std::vector<BanEntry *>::iterator it = c->channelBanlist.begin();
@@ -261,11 +261,11 @@ Commands::DelUser(Bot *bot, String who, String maskChannel)
 
   String dest;
 
-  if (!Utils::isWildcard(who)) {
+  if (!Utils::wildcard_p(who)) {
     dest = bot->getUserhost("", who);
     if (dest.length() == 0)
       return NotFound(who);
-    dest = Utils::makeWildcard(who);
+    dest = Utils::make_wildcard(who);
   }
 
   if (!bot->userList->isInUserList(dest, maskChannel))
@@ -285,11 +285,11 @@ Commands::DelShit(Bot *bot, String who, String maskChannel)
 
   String dest;
 
-  if (!Utils::isWildcard(who)) {
+  if (!Utils::wildcard_p(who)) {
     dest = bot->getUserhost("", who);
     if (dest.length() == 0)
       return NotFound(who);
-    dest = Utils::makeWildcard(who);
+    dest = Utils::make_wildcard(who);
   }
 
   if (!bot->shitList->getShit(dest, maskChannel))
@@ -313,7 +313,7 @@ Commands::Deop(Bot *bot, String channel, String who)
   if (!bot->iAmOp(channel))
     return NotChannelOp(channel);
 
-  if (!Utils::isWildcard(who)) {
+  if (!Utils::wildcard_p(who)) {
     User *u = c->getUser(who);
     if (!u)
       return UserNotFound(who, channel);
@@ -376,7 +376,7 @@ Commands::Join(Bot *bot, String channel, String key)
 {
   CHECK_CONNECTION;
 
-  if (!Utils::isValidChannelName(channel))
+  if (!Utils::valid_channel_name_p(channel))
     return InvalidChannel(channel);
 
   // We change the key only if we are not on the channel.
@@ -421,7 +421,7 @@ Commands::Kick(Bot *bot, String channel, String who, String reason)
   if (!bot->iAmOp(channel))
     return NotChannelOp(channel);
 
-  if (Utils::isWildcard(who)) {
+  if (Utils::wildcard_p(who)) {
     Mask m(who);
     for (std::map<String, User *, std::less<String> >::iterator it =
            c->channelMemory.begin();
@@ -496,7 +496,7 @@ Commands::Msg(Bot *bot, String who, String message)
   if (who == "")
     return EmptyAddressee;
 
-  if (Utils::isChannel(who))
+  if (Utils::channel_p(who))
     return NotToChannel;
 
   if (message == "")
@@ -529,7 +529,7 @@ Commands::Nick(Bot *bot, String nick)
 {
   CHECK_CONNECTION;
 
-  if (nick == "" || !Utils::isValidNickName(nick))
+  if (nick == "" || !Utils::valid_nickname_p(nick))
     return InvalidNick(nick);
   
   bot->wantedNickName = nick;
@@ -546,7 +546,7 @@ Commands::Notice(Bot *bot, String who, String message)
   if (who == "")
     return EmptyAddressee;
 
-  if (Utils::isChannel(who))
+  if (Utils::channel_p(who))
     return NotToChannel;
 
   if (message == "")
@@ -570,7 +570,7 @@ Commands::Op(Bot *bot, String channel, String who)
   if (!bot->iAmOp(channel))
     return NotChannelOp(channel);
 
-  if (Utils::isWildcard(who))
+  if (Utils::wildcard_p(who))
     return MassOpNotAllowed;
 
   User *u = c->getUser(who);
@@ -688,7 +688,7 @@ Commands::TBan(Bot *bot, String channel, String who, int seconds)
 
   String dest;
 
-  if (!Utils::isWildcard(who))
+  if (!Utils::wildcard_p(who))
     dest = bot->getUserhost(channel, who);
   else
     dest = who;
@@ -696,7 +696,7 @@ Commands::TBan(Bot *bot, String channel, String who, int seconds)
   if (dest.length() == 0)
     return UserNotFound(who, channel);
 
-  dest = Utils::makeWildcard(dest);
+  dest = Utils::make_wildcard(dest);
   Mask m(dest);
 
   for (std::list<UserListItem *>::iterator it = bot->userList->l.begin();
index 6af7d10..2de2f65 100644 (file)
@@ -1,6 +1,6 @@
 // DCCConnection.C  -*- C++ -*-
 // Copyright (c) 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
@@ -39,7 +39,7 @@ DCCChatConnection::connect()
 
   DCCPerson *from = new DCCPerson (this);
 
-  if (Utils::getLevel (bot, from->getAddress()) < User::FRIEND)
+  if (Utils::get_level (bot, from->getAddress()) < User::FRIEND)
     {
       from->sendNotice 
        ("\002You do not have permission to DCC CHAT the bot\002");
@@ -52,7 +52,7 @@ DCCChatConnection::connect()
   bot->botInterp->RunHooks (Hook::DCC_CHAT_BEGIN, 
                            from->getAddress (),
                            scm_list_n (Utils::
-                                       string2SCM (from->getAddress ()),
+                                       str2scm (from->getAddress ()),
                                        SCM_UNDEFINED));
 #endif
 
index 859ce79..215ec80 100644 (file)
@@ -1,6 +1,6 @@
 // DCCParser.C  -*- C++ -*-
 // Copyright (c) 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
@@ -34,9 +34,8 @@ DCCParser::parseLine(DCCConnection *cnx, String line)
   // Call hooks/dcc/chat-message hook functions
   cnx->get_bot()->botInterp->RunHooks (Hook::DCC_CHAT_MESSAGE, 
                                 from->getAddress () + " " + line,
-                                scm_list_n (Utils::
-                                            string2SCM (from->getAddress ()),
-                                            Utils::string2SCM (line),
+                                scm_list_n (Utils::str2scm (from->getAddress ()),
+                                            Utils::str2scm (line),
                                             SCM_UNDEFINED));
 #endif
   Parser::parseMessage(cnx->get_bot()->serverConnection, 
index 030ea8f..33b0809 100644 (file)
@@ -1,6 +1,6 @@
 // Parser.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (C) 2002,2003 Clinton Ebadi
+// Copyright (C) 2002,2003,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
@@ -79,17 +79,17 @@ Parser::parseLine (ServerConnection * cnx, String line)
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::RAW, line,
                                 scm_listify (Utils::
-                                             string2SCM (line),
+                                             str2scm (line),
                                              SCM_UNDEFINED));
 #endif
   if (line[0] == ':')
     {
-      String fromMask = st.nextToken ().subString (1);
+      String fromMask = st.next_token ().substr (1);
       if (fromMask.find ('!') != -1)
        from = new Person (cnx->bot, fromMask);
     }
 
-  String command = st.nextToken ();
+  String command = st.next_token ();
   String rest = st.rest ();
 
   if (fptr temp_func = functions[command])
@@ -102,7 +102,7 @@ Parser::parse001 (ServerConnection * cnx, Person * from, String rest)
 {
   String temp = "";
   StringTokenizer st (rest);
-  String realNick = st.nextToken ();
+  String realNick = st.next_token ();
   if ((cnx->bot->nickName).toLower () != realNick)
     {
       // Yes, this can happen, and it was a very subtle bug
@@ -135,12 +135,12 @@ Parser::parse302 (ServerConnection * cnx, Person * from, String rest)
 {
   unsigned long num = cnx->bot->receivedUserhostID++;
   StringTokenizer st (rest);
-  st.nextToken (':');
+  st.next_token (':');
   if (st.rest ().length ())
     {
-      st.nextToken ('=');
+      st.next_token ('=');
       String parameters = st.rest ();
-      parameters = parameters.subString (1);
+      parameters = parameters.substr (1);
       cnx->bot->userhostMap[num] = parameters;
     }
   else
@@ -151,10 +151,10 @@ void
 Parser::parse311 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String nuh = st.nextToken () + "!";
-  String uh = st.nextToken () + "@";
-  uh = uh + st.nextToken ();
+  st.next_token ();
+  String nuh = st.next_token () + "!";
+  String uh = st.next_token () + "@";
+  uh = uh + st.next_token ();
   nuh = nuh + uh;
   cnx->bot->userList->addUserFirst (nuh, "*", 0, 3, true, -1, "");
   cnx->bot->userHost = uh;
@@ -164,8 +164,8 @@ void
 Parser::parse315 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String channel = st.nextToken ();
+  st.next_token ();
+  String channel = st.next_token ();
   Channel *c = cnx->bot->channelList->getChannel (channel);
   if (!c)
     return;
@@ -176,8 +176,8 @@ void
 Parser::parse324 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String channel = st.nextToken ();
+  st.next_token ();
+  String channel = st.next_token ();
   if (Channel * c = cnx->bot->channelList->getChannel (channel))
     if (c)
       c->parseMode (from, st.rest ());
@@ -187,24 +187,24 @@ void
 Parser::parse332 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String channel = st.nextToken ();
+  st.next_token ();
+  String channel = st.next_token ();
   if (Channel * c = cnx->bot->channelList->getChannel (channel))
     if (c)
-      c->channelTopic = st.rest ().subString (1);
+      c->channelTopic = st.rest ().substr (1);
 }
 
 void
 Parser::parse352 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String ch = st.nextToken ();
-  String uh = st.nextToken () + "@";
-  uh = uh + st.nextToken ();
-  st.nextToken ();
-  String n = st.nextToken ();
-  String m = st.nextToken ();
+  st.next_token ();
+  String ch = st.next_token ();
+  String uh = st.next_token () + "@";
+  uh = uh + st.next_token ();
+  st.next_token ();
+  String n = st.next_token ();
+  String m = st.next_token ();
   int mode = 0;
   for (int i = 0; i < m.length (); i++)
     switch (m[i])
@@ -235,24 +235,24 @@ Parser::parse353 (ServerConnection * cnx, Person * from, String rest)
   int mode = 0;
   String nick;
   StringTokenizer st (rest);
-  st.nextToken ();
-  st.nextToken ();
-  Channel *c = cnx->bot->channelList->getChannel (st.nextToken ());
+  st.next_token ();
+  st.next_token ();
+  Channel *c = cnx->bot->channelList->getChannel (st.next_token ());
   if (!c)
     return;
-  StringTokenizer st2 (st.nextToken (':'));
-  while (st2.hasMoreTokens ())
+  StringTokenizer st2 (st.next_token (':'));
+  while (st2.more_tokens_p ())
     {
-      nick = st2.nextToken ();
+      nick = st2.next_token ();
       if (nick[0] == '@')
        {
          mode = User::OP_MODE;
-         nick = nick.subString (1);
+         nick = nick.substr (1);
        }
       else if (nick[0] == '+')
        {
          mode = User::VOICE_MODE;
-         nick = nick.subString (1);
+         nick = nick.substr (1);
        }
       c->addNick (nick, "", mode, 0, true);
     }
@@ -262,8 +262,8 @@ void
 Parser::parse366 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String ch = st.nextToken ();
+  st.next_token ();
+  String ch = st.next_token ();
   if (Channel * c = cnx->bot->channelList->getChannel (ch))
     c->joined = true;
 }
@@ -272,18 +272,18 @@ void
 Parser::parse367 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String ch = st.nextToken ();
+  st.next_token ();
+  String ch = st.next_token ();
   if (Channel * c = cnx->bot->channelList->getChannel (ch))
-    c->addBan (st.nextToken (), -1);
+    c->addBan (st.next_token (), -1);
 }
 
 void
 Parser::parse401 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
-  String nick = st.nextToken ();
+  st.next_token ();
+  String nick = st.next_token ();
   if (cnx->bot->spyList.find (nick) != cnx->bot->spyList.end ())
     {
       delete cnx->bot->spyList[nick];
@@ -304,11 +304,11 @@ Parser::parse433 (ServerConnection * cnx, Person * from, String rest)
           && cnx->bot->nickName[i] == '_'; i++);
       if (i < cnx->bot->nickName.length ())
        cnx->bot->nickName =
-         cnx->bot->nickName.subString (0,
+         cnx->bot->nickName.substr (0,
                                        i - 1) + "_" +
-         cnx->bot->nickName.subString (i + 1);
+         cnx->bot->nickName.substr (i + 1);
       else
-       cnx->bot->nickName = cnx->bot->nickName.subString (0, 4) +
+       cnx->bot->nickName = cnx->bot->nickName.substr (0, 4) +
          String ((long) (rand () % 10000));
     }
   else
@@ -320,9 +320,9 @@ void
 Parser::parse473 (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  st.nextToken ();
+  st.next_token ();
   cnx->bot->logLine (String ("Unable to join channel ") +
-                    st.nextToken () + ".");
+                    st.next_token () + ".");
 }
 
 void
@@ -341,15 +341,15 @@ Parser::parseInvite (ServerConnection * cnx, Person * from, String rest)
 {
   String nick = from->getNick ();
   StringTokenizer st (rest);
-  st.nextToken (':');
+  st.next_token (':');
   String channel = st.rest ();
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::INVITE,
                                 nick + " " + channel,
                                 scm_listify (Utils::
-                                             string2SCM (nick),
+                                             str2scm (nick),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (channel), SCM_UNDEFINED));
 #endif
   if (cnx->bot->wantedChannels.find (channel) !=
@@ -361,25 +361,25 @@ void
 Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (from->getAddress ());
-  String n = st.nextToken ('!');
-  String uh = st.nextToken ();
+  String n = st.next_token ('!');
+  String uh = st.next_token ();
   StringTokenizer st2 (rest);
-  String c = st2.nextToken (':');
+  String c = st2.next_token (':');
   String mode;
   bool joinAndMode = false;
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::JOIN, n + " " + c,
                                 scm_listify (Utils::
-                                             string2SCM (n),
+                                             str2scm (n),
                                              Utils::
-                                             string2SCM (c), SCM_UNDEFINED));
+                                             str2scm (c), SCM_UNDEFINED));
 #endif
   // This part of code is for the combined JOIN & MODE of ircd 2.9
   if (c.find ('\007') >= 0)
     {
       joinAndMode = true;
       StringTokenizer st3 (c);
-      c = st3.nextToken ('\007');
+      c = st3.next_token ('\007');
       String m = st3.rest ();
       mode = c + " +" + m;
       for (int i = 0; i < m.length (); i++)
@@ -417,7 +417,7 @@ Parser::parseJoin (ServerConnection * cnx, Person * from, String rest)
          && !(ch->getUser (n)->mode & User::OP_MODE) && cnx->bot->iAmOp (c))
        {
          // This is a part of the antispoof code
-         ch->getUser (n)->userkey = Utils::getKey ();
+         ch->getUser (n)->userkey = Utils::get_key ();
          cnx->queue->sendCTCP (n, "PING",
                                ch->getUser (n)->userkey + " " + c);
        }
@@ -431,26 +431,26 @@ void
 Parser::parseKick (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  String channel = st.nextToken ();
-  String target = st.nextToken ();
-  String reason = st.rest ().subString (1);
+  String channel = st.next_token ();
+  String target = st.next_token ();
+  String reason = st.rest ().substr (1);
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::KICK,
                                 target + " " +
                                 from->getNick () + " " +
                                 channel + " " + reason,
                                 scm_listify (Utils::
-                                             string2SCM
+                                             str2scm
                                              (target),
                                              Utils::
-                                             string2SCM (from->
+                                             str2scm (from->
                                                          getNick
                                                          ()),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (channel),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (reason), SCM_UNDEFINED));
 #endif
   if (target == cnx->bot->nickName)
@@ -490,7 +490,7 @@ void
 Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  String ch = st.nextToken ();
+  String ch = st.next_token ();
   String modes = st.rest ();
 #ifdef USESCRIPTS
   if (from)
@@ -498,16 +498,16 @@ Parser::parseMode (ServerConnection * cnx, Person * from, String rest)
                                   from->getNick () + " " + ch +
                                   " " + modes,
                                   scm_listify (Utils::
-                                               string2SCM (from->
+                                               str2scm (from->
                                                            getNick
                                                            ()),
                                                Utils::
-                                               string2SCM (ch),
+                                               str2scm (ch),
                                                Utils::
-                                               string2SCM (modes),
+                                               str2scm (modes),
                                                SCM_UNDEFINED));
 #endif
-  if (Utils::isChannel (ch))
+  if (Utils::channel_p (ch))
     {
       Channel *c = cnx->bot->channelList->getChannel (ch);
       if (!c)
@@ -524,16 +524,16 @@ Parser::parseNick (ServerConnection * cnx, Person * from, String rest)
 {
   String on_orig = from->getNick ();
   String on = on_orig.toLower ();
-  String nn = rest.subString (1);
+  String nn = rest.substr (1);
   String nn_lower = nn.toLower ();
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::NICKNAME,
                                 on_orig + " " + nn,
                                 scm_listify (Utils::
-                                             string2SCM
+                                             str2scm
                                              (on_orig),
                                              Utils::
-                                             string2SCM (nn),
+                                             str2scm (nn),
                                              SCM_UNDEFINED));
 #endif
   if ((cnx->bot->nickName).toLower () == on)
@@ -568,53 +568,53 @@ Parser::parseNotice (ServerConnection * cnx, Person * from, String rest)
   if (from)
     nick = from->getNick ();
   StringTokenizer st (rest);
-  String to = st.nextToken ();
-  rest = st.rest ().subString (1);
+  String to = st.next_token ();
+  rest = st.rest ().substr (1);
   if (rest[0] != '\001')
     {
 #ifdef USESCRIPTS
-      if (Utils::isChannel (to))
+      if (Utils::channel_p (to))
        cnx->bot->botInterp->RunHooks (Hook::PUBLIC_NOTICE,
                                       nick + " " + to + " " + rest,
                                       scm_listify (Utils::
-                                                   string2SCM (nick),
+                                                   str2scm (nick),
                                                    Utils::
-                                                   string2SCM (to),
+                                                   str2scm (to),
                                                    Utils::
-                                                   string2SCM (rest),
+                                                   str2scm (rest),
                                                    SCM_UNDEFINED));
       else
        cnx->bot->botInterp->RunHooks (Hook::NOTICE, nick + " " + rest,
                                       scm_listify (Utils::
-                                                   string2SCM (nick),
+                                                   str2scm (nick),
                                                    Utils::
-                                                   string2SCM (rest),
+                                                   str2scm (rest),
                                                    SCM_UNDEFINED));
 #endif
       return;
     }
 
-  rest = rest.subString (1, rest.length () - 2);
+  rest = rest.substr (1, rest.length () - 2);
   StringTokenizer st2 (rest);
-  String command = st2.nextToken ();
+  String command = st2.next_token ();
   rest = st2.rest ();
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::CTCP_REPLY,
                                 nick + " " + command + " " +
                                 rest,
                                 scm_listify (Utils::
-                                             string2SCM (nick),
+                                             str2scm (nick),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (command),
                                              Utils::
-                                             string2SCM (rest),
+                                             str2scm (rest),
                                              SCM_UNDEFINED));
 #endif
   if (command == "PING")
     {
       StringTokenizer st3 (rest);
-      rest = st3.nextToken ();
+      rest = st3.next_token ();
       String c = st3.rest ();
       if (cnx->bot->channelList->getChannel (c) &&
          cnx->bot->channelList->getChannel (c)->getUser (nick) &&
@@ -633,9 +633,9 @@ Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
 {
   String nick = from->getNick ();
   StringTokenizer st (rest);
-  String to = st.nextToken ();
-  String fromUserhost = Utils::getUserhost (from->getAddress ());
-  rest = st.rest ().subString (1);
+  String to = st.next_token ();
+  String fromUserhost = Utils::get_userhost (from->getAddress ());
+  rest = st.rest ().substr (1);
   if (++(cnx->bot->ignoredUserhosts[fromUserhost]) > Bot::MAX_MESSAGES)
     {
       if (cnx->bot->ignoredUserhosts[fromUserhost] == Bot::MAX_MESSAGES + 1)
@@ -643,13 +643,13 @@ Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
 #ifdef USESCRIPTS
          cnx->bot->botInterp->RunHooks (Hook::FLOOD, nick,
                                         scm_listify (Utils::
-                                                     string2SCM (nick),
+                                                     str2scm (nick),
                                                      SCM_UNDEFINED));
 #endif
          cnx->bot->ignoredUserhosts[fromUserhost] += Bot::IGNORE_DELAY;
          cnx->bot->logLine (from->getAddress () +
                             " is flooding me. We will ignore him/her/it.");
-         if (!Utils::isChannel (to))
+         if (!Utils::channel_p (to))
            from->
              sendNotice (String ("\002You are now being ignored for ") +
                          String ((long) Bot::IGNORE_DELAY) +
@@ -671,8 +671,8 @@ Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
 
   if (rest[0] == '\001')
     {
-      rest = rest.subString (1, rest.length () - 2);
-      if (!Utils::isChannel (to))
+      rest = rest.substr (1, rest.length () - 2);
+      if (!Utils::channel_p (to))
        for (std::map < String, Person *,
             std::less < String > >::iterator it =
             cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
@@ -683,10 +683,10 @@ Parser::parsePrivmsg (ServerConnection * cnx, Person * from, String rest)
   else
     {
       if ((rest.length () < 5 ||
-          rest.subString (1, 5).toUpper () != "IDENT") &&
+          rest.substr (1, 5).toUpper () != "IDENT") &&
          (rest.length () < 8 ||
-          rest.subString (1, 8).toUpper () != "PASSWORD") &&
-         !Utils::isChannel (to))
+          rest.substr (1, 8).toUpper () != "PASSWORD") &&
+         !Utils::channel_p (to))
        for (std::map < String, Person *,
             std::less < String > >::iterator it =
             cnx->bot->spyList.begin (); it != cnx->bot->spyList.end (); ++it)
@@ -700,13 +700,13 @@ Parser::parsePart (ServerConnection * cnx, Person * from, String rest)
 {
   String n = from->getNick ();
   StringTokenizer st (rest);
-  String channel = st.nextToken ();
+  String channel = st.next_token ();
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::LEAVE, n + " " + channel,
                                 scm_listify (Utils::
-                                             string2SCM (n),
+                                             str2scm (n),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (channel), SCM_UNDEFINED));
 #endif
   if (n.toLower () == cnx->bot->nickName.toLower ())
@@ -749,9 +749,9 @@ Parser::parseQuit (ServerConnection * cnx, Person * from, String rest)
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::SIGNOFF, n + " " + rest,
                                 scm_listify (Utils::
-                                             string2SCM (n),
+                                             str2scm (n),
                                              Utils::
-                                             string2SCM (rest),
+                                             str2scm (rest),
                                              SCM_UNDEFINED));
 #endif
   if (n == cnx->bot->nickName)
@@ -767,22 +767,22 @@ void
 Parser::parseTopic (ServerConnection * cnx, Person * from, String rest)
 {
   StringTokenizer st (rest);
-  String channel = st.nextToken ();
-  String newTopic = st.rest ().subString (1);
+  String channel = st.next_token ();
+  String newTopic = st.rest ().substr (1);
   Channel *c = cnx->bot->channelList->getChannel (channel);
 #ifdef USESCRIPTS
   cnx->bot->botInterp->RunHooks (Hook::TOPIC,
                                 from->getNick () + " " +
                                 channel + " " + newTopic,
                                 scm_listify (Utils::
-                                             string2SCM (from->
+                                             str2scm (from->
                                                          getNick
                                                          ()),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (channel),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (newTopic), SCM_UNDEFINED));
 #endif
   if (!c)
@@ -797,10 +797,10 @@ Parser::parseCTCP (ServerConnection * cnx,
                   Person * from, String to, String parameters)
 {
   StringTokenizer st (parameters);
-  String command = st.nextToken ().toUpper ();
+  String command = Utils::to_upper (st.next_token ());
   String nick = from->getNick ();
   String rest;
-  if (st.hasMoreTokens ())
+  if (st.more_tokens_p ())
     rest = st.rest ();
   else
     rest = "";
@@ -809,14 +809,14 @@ Parser::parseCTCP (ServerConnection * cnx,
                                 nick + " " + to + " " +
                                 command + " " + rest,
                                 scm_listify (Utils::
-                                             string2SCM (nick),
+                                             str2scm (nick),
                                              Utils::
-                                             string2SCM (to),
+                                             str2scm (to),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (command),
                                              Utils::
-                                             string2SCM (rest),
+                                             str2scm (rest),
                                              SCM_UNDEFINED));
 #endif
   if (command == "PING")
@@ -844,15 +844,15 @@ Parser::parseCTCP (ServerConnection * cnx,
   else if (command == "DCC")
     {
       StringTokenizer st2 (rest);
-      command = st2.nextToken ().toUpper ();
+      command = Utils::to_upper (st2.next_token ());
       if (command == "CHAT")
        {
          // FIXME: debug DCC
-         st2.nextToken ();
+         st2.next_token ();
          unsigned long address =
-           strtoul ((const char *) st2.nextToken (), 0, 0);
-         int port = atoi ((const char *) st2.nextToken ());
-         if (port >= 1024 && Utils::getLevel (cnx->bot, from->getAddress ()))
+           std::strtoul (st2.next_token ().c_str(), 0, 0);
+         int port = std::atoi (st2.next_token().c_str());
+         if (port >= 1024 && Utils::get_level (cnx->bot, from->getAddress ()))
            cnx->bot->addDCC (from, address, port, Bot::CHAT);
          else
            cnx->bot->logLine ("DCC Chat Failed in Parser");
@@ -865,13 +865,13 @@ Parser::parseCTCP (ServerConnection * cnx,
                                     from->getAddress () + " " + to +
                                     " " + rest,
                                     scm_listify (Utils::
-                                                 string2SCM (from->
+                                                 str2scm (from->
                                                              getAddress
                                                              ()),
                                                  Utils::
-                                                 string2SCM (to),
+                                                 str2scm (to),
                                                  Utils::
-                                                 string2SCM (rest),
+                                                 str2scm (rest),
                                                  SCM_UNDEFINED));
     }
 #endif
@@ -882,37 +882,37 @@ Parser::parseMessage (ServerConnection * cnx,
                      Person * from, String to, String parameters)
 {
 #ifdef USESCRIPTS
-  if (Utils::isChannel (to))
+  if (Utils::channel_p (to))
     cnx->bot->botInterp->RunHooks (Hook::PUBLIC,
                                   from->getNick () + " " + to +
                                   " " + parameters,
                                   scm_listify (Utils::
-                                               string2SCM (from->
+                                               str2scm (from->
                                                            getNick
                                                            ()),
                                                Utils::
-                                               string2SCM (to),
+                                               str2scm (to),
                                                Utils::
-                                               string2SCM
+                                               str2scm
                                                (parameters), SCM_UNDEFINED));
   else
     cnx->bot->botInterp->RunHooks (Hook::MESSAGE,
                                   from->getNick () + " " +
                                   parameters,
                                   scm_listify (Utils::
-                                               string2SCM (from->
+                                               str2scm (from->
                                                            getNick
                                                            ()),
                                                Utils::
-                                               string2SCM
+                                               str2scm
                                                (parameters), SCM_UNDEFINED));
 #endif
   if (parameters[0] != cnx->bot->commandChar)
     return;
 
   StringTokenizer st (parameters);
-  String command = st.nextToken ().subString (1).toUpper ();
-  String rest = st.rest ().trim ();
+  String command = Utils::to_upper (st.next_token ().substr (1));
+  String rest = Utils::trim_str (st.rest ());
   int level;
   bool identified = false;
   std::map<std::string, class userFunction*, 
@@ -929,13 +929,13 @@ Parser::parseMessage (ServerConnection * cnx,
     {
       if (f->needsChannelName)
        {
-         if (Utils::isChannel (rest))
+         if (Utils::channel_p (rest))
            {
              StringTokenizer st2 (rest);
-             to = st.nextToken ();
+             to = st.next_token ();
              rest = st.rest ();
            }
-         if (!Utils::isChannel (to))
+         if (!Utils::channel_p (to))
            {
              from->sendNotice ("\002You need to supply a channel name"
                                " for this command\002");
@@ -947,7 +947,7 @@ Parser::parseMessage (ServerConnection * cnx,
                                to);
              return;
            }
-         level = Utils::getLevel (cnx->bot, from->getAddress (), to);
+         level = Utils::get_level (cnx->bot, from->getAddress (), to);
          User *u = 0;
          if (Channel * c = cnx->bot->channelList->getChannel (to))
            u = c->getUser (from->getNick ());
@@ -959,7 +959,7 @@ Parser::parseMessage (ServerConnection * cnx,
        }
       else
            {
-             level = Utils::getLevel (cnx->bot, from->getAddress ());
+             level = Utils::get_level (cnx->bot, from->getAddress ());
              identified = true;
            }
       if (level >= f->minLevel)
@@ -1005,7 +1005,7 @@ Parser::parseScriptFunction (ServerConnection * cnx,
     {
       args_list = gh_append2 (args_list,
                              scm_listify (Utils::
-                                          string2SCM (channel),
+                                          str2scm (channel),
                                           SCM_UNDEFINED));
       argsCount--;
     }
@@ -1016,9 +1016,9 @@ Parser::parseScriptFunction (ServerConnection * cnx,
       if (i == 1)
        param = st.rest ();
       else
-       param = st.nextToken ();
+       param = st.next_token ();
       args_list = gh_append2 (args_list,
-                             scm_listify (Utils::string2SCM (param),
+                             scm_listify (Utils::str2scm (param),
                                           SCM_UNDEFINED));
     }
 
index 2a757b6..eda4a31 100644 (file)
@@ -1,5 +1,6 @@
 // Person.C  -*- C++ -*-
 // Copyright (c) 1998 Etienne BERNARD
+// Copyright (c) 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
@@ -35,7 +36,7 @@ Person::copy()
 String
 Person::getNick() const
 {
-  return Utils::getNick(address);
+  return Utils::get_nick (address);
 }
 
 String
index 241f814..310fd4b 100644 (file)
@@ -1,6 +1,6 @@
 // ScriptCommands.C  -*- C++ -*-
 // Copyright (c) 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
@@ -44,8 +44,8 @@ ScriptCommands::Action(SCM channel, SCM message)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(message);
-  Message m = Commands::Action(Interp::bot, Utils::scm2String(channel),
-                               Utils::scm2String(message));
+  Message m = Commands::Action(Interp::bot, Utils::scm2str(channel),
+                               Utils::scm2str(message));
   return scm_long2num(m.getCode());
 }
 
@@ -58,8 +58,8 @@ ScriptCommands::AddUser(SCM who, SCM maskChannel, SCM level,
   VERIFY_STRING (maskChannel);
   VERIFY_NUMBER (level);
 
-  String wwho = Utils::scm2String (who);
-  String mask = Utils::scm2String (maskChannel);
+  String wwho = Utils::scm2str (who);
+  String mask = Utils::scm2str (maskChannel);
   String passwd; 
   std::time_t eexpire;
 
@@ -68,14 +68,14 @@ ScriptCommands::AddUser(SCM who, SCM maskChannel, SCM level,
   else
     {
       VERIFY_STRING (password);
-      passwd = Utils::scm2String (password);
+      passwd = Utils::scm2str (password);
     }
   if (SCM_UNBNDP (expire))
     eexpire = -1;
   else
     {
       VERIFY_STRING (expire);
-      eexpire = Utils::strToTime (Utils::scm2String (expire));
+      eexpire = Utils::str2time (Utils::scm2str (expire));
       if (!eexpire) eexpire = -1;
     }
 
@@ -97,7 +97,7 @@ ScriptCommands::AddServer(SCM servername, SCM port)
   if (SCM_NUMBERP(port))
     p = scm_num2long(port, SCM_ARG1, "ScriptCommands::AddServer");
   Message m = Commands::AddServer(Interp::bot,
-                                  Utils::scm2String(servername),
+                                  Utils::scm2str(servername),
                                   p);
   return scm_long2num(m.getCode());
 }
@@ -110,8 +110,8 @@ ScriptCommands::AddShit(SCM mask, SCM maskChannel, SCM level,
   VERIFY_STRING (mask);
   VERIFY_STRING (maskChannel);
   VERIFY_NUMBER (level);
-  String mmask = Utils::scm2String (mask);
-  String mmaskChannel = Utils::scm2String (maskChannel);
+  String mmask = Utils::scm2str (mask);
+  String mmaskChannel = Utils::scm2str (maskChannel);
   int llevel = scm_num2int (level, SCM_ARG1, "ScriptCommands::AddShit");
   std::time_t expire;
   String rreason;
@@ -121,7 +121,7 @@ ScriptCommands::AddShit(SCM mask, SCM maskChannel, SCM level,
   else
     {
       VERIFY_STRING (expiration);
-      expire = Utils::strToTime (Utils::scm2String (expiration));
+      expire = Utils::str2time (Utils::scm2str (expiration));
       if (!expire) expire = -1;
     }
   if (SCM_UNBNDP (reason))
@@ -129,7 +129,7 @@ ScriptCommands::AddShit(SCM mask, SCM maskChannel, SCM level,
   else
     {
       VERIFY_STRING (reason);
-      rreason = Utils::scm2String (reason);
+      rreason = Utils::scm2str (reason);
     }
   Message m = Commands::AddShit (Interp::bot, mmask, mmaskChannel,
                                 llevel, expire, rreason);
@@ -142,8 +142,8 @@ ScriptCommands::Ban(SCM channel, SCM who)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(who);
-  Message m = Commands::Ban(Interp::bot, Utils::scm2String(channel),
-                            Utils::scm2String(who));
+  Message m = Commands::Ban(Interp::bot, Utils::scm2str(channel),
+                            Utils::scm2str(who));
   return scm_long2num(m.getCode());
 }
 
@@ -178,7 +178,7 @@ SCM
 ScriptCommands::Cycle(SCM channel)
 {
   VERIFY_STRING(channel);
-  Message m = Commands::Cycle(Interp::bot, Utils::scm2String(channel));
+  Message m = Commands::Cycle(Interp::bot, Utils::scm2str(channel));
   return scm_long2num(m.getCode());
 }
 
@@ -187,8 +187,8 @@ ScriptCommands::Deban(SCM channel, SCM who)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(who);
-  Message m = Commands::Deban(Interp::bot, Utils::scm2String(channel),
-                              Utils::scm2String(who));
+  Message m = Commands::Deban(Interp::bot, Utils::scm2str(channel),
+                              Utils::scm2str(who));
   return scm_long2num(m.getCode());
 }
 
@@ -207,8 +207,8 @@ ScriptCommands::DelUser(SCM who, SCM maskChannel)
 {
   VERIFY_STRING(who);
   VERIFY_STRING(maskChannel);
-  Message m = Commands::DelUser(Interp::bot, Utils::scm2String(who),
-                                Utils::scm2String(maskChannel));
+  Message m = Commands::DelUser(Interp::bot, Utils::scm2str(who),
+                                Utils::scm2str(maskChannel));
   return scm_long2num(m.getCode());
 }
 
@@ -217,8 +217,8 @@ ScriptCommands::DelShit(SCM who, SCM maskChannel)
 {
   VERIFY_STRING(who);
   VERIFY_STRING(maskChannel);
-  Message m = Commands::DelShit(Interp::bot, Utils::scm2String(who),
-                                Utils::scm2String(maskChannel));
+  Message m = Commands::DelShit(Interp::bot, Utils::scm2str(who),
+                                Utils::scm2str(maskChannel));
   return scm_long2num(m.getCode());
 }
 
@@ -227,8 +227,8 @@ ScriptCommands::Deop(SCM channel, SCM who)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(who);
-  Message m = Commands::Deop(Interp::bot, Utils::scm2String(channel),
-                             Utils::scm2String(who));
+  Message m = Commands::Deop(Interp::bot, Utils::scm2str(channel),
+                             Utils::scm2str(who));
   return scm_long2num(m.getCode());
 }
 
@@ -237,7 +237,7 @@ ScriptCommands::Die(SCM reason)
 {
   String r = "Leaving";
   if (SCM_STRINGP(reason))
-    r = Utils::scm2String(reason);
+    r = Utils::scm2str(reason);
   Message m = Commands::Die(Interp::bot, r);
   return scm_long2num(m.getCode());
 }
@@ -246,7 +246,7 @@ SCM
 ScriptCommands::Do(SCM command)
 {
   VERIFY_STRING(command);
-  Message m = Commands::Do(Interp::bot, Utils::scm2String(command));
+  Message m = Commands::Do(Interp::bot, Utils::scm2str(command));
   return scm_long2num(m.getCode());
 }
 
@@ -255,8 +255,8 @@ ScriptCommands::Invite(SCM channel, SCM who)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(who);
-  Message m = Commands::Invite(Interp::bot, Utils::scm2String(channel),
-                               Utils::scm2String(who));
+  Message m = Commands::Invite(Interp::bot, Utils::scm2str(channel),
+                               Utils::scm2str(who));
   return scm_long2num(m.getCode());
 }
 
@@ -266,8 +266,8 @@ ScriptCommands::Join(SCM channel, SCM key)
   VERIFY_STRING(channel);
   String k = "";
   if (SCM_STRINGP(key))
-    k = Utils::scm2String(key);
-  Message m = Commands::Join(Interp::bot, Utils::scm2String(channel),
+    k = Utils::scm2str(key);
+  Message m = Commands::Join(Interp::bot, Utils::scm2str(channel),
                              k);
   return scm_long2num(m.getCode());
 }
@@ -277,8 +277,8 @@ ScriptCommands::Keep(SCM channel, SCM modes)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(modes);
-  Message m = Commands::Keep(Interp::bot, Utils::scm2String(channel),
-                             Utils::scm2String(modes));
+  Message m = Commands::Keep(Interp::bot, Utils::scm2str(channel),
+                             Utils::scm2str(modes));
   return scm_long2num(m.getCode());
 }
 
@@ -290,10 +290,10 @@ ScriptCommands::Kick(SCM channel, SCM who, SCM reason)
 
   String r = "";
   if (SCM_STRINGP(reason))
-    r = Utils::scm2String(reason);
+    r = Utils::scm2str(reason);
 
-  Message m = Commands::Kick(Interp::bot, Utils::scm2String(channel),
-                             Utils::scm2String(who), r);
+  Message m = Commands::Kick(Interp::bot, Utils::scm2str(channel),
+                             Utils::scm2str(who), r);
   return scm_long2num(m.getCode());
 }
 
@@ -304,9 +304,9 @@ ScriptCommands::KickBan(SCM channel, SCM who, SCM reason)
   VERIFY_STRING(who);
   String r = "";
   if (SCM_STRINGP(reason))
-    r = Utils::scm2String(reason);
-  Message m = Commands::KickBan(Interp::bot, Utils::scm2String(channel),
-                                Utils::scm2String(who), r);
+    r = Utils::scm2str(reason);
+  Message m = Commands::KickBan(Interp::bot, Utils::scm2str(channel),
+                                Utils::scm2str(who), r);
   return scm_long2num(m.getCode());
 }
 
@@ -314,7 +314,7 @@ SCM
 ScriptCommands::Lock(SCM channel)
 {
   VERIFY_STRING(channel);
-  Message m = Commands::Lock(Interp::bot, Utils::scm2String(channel));
+  Message m = Commands::Lock(Interp::bot, Utils::scm2str(channel));
   return scm_long2num(m.getCode());
 }
 
@@ -329,8 +329,8 @@ ScriptCommands::Mode(SCM channel, SCM mode)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(mode);
-  Message m = Commands::Mode(Interp::bot, Utils::scm2String(channel),
-                             Utils::scm2String(mode));
+  Message m = Commands::Mode(Interp::bot, Utils::scm2str(channel),
+                             Utils::scm2str(mode));
   return scm_long2num(m.getCode());
 }
 
@@ -339,8 +339,8 @@ ScriptCommands::Msg(SCM nick, SCM message)
 {
   VERIFY_STRING(nick);
   VERIFY_STRING(message);
-  Message m = Commands::Msg(Interp::bot, Utils::scm2String(nick),
-                            Utils::scm2String(message));
+  Message m = Commands::Msg(Interp::bot, Utils::scm2str(nick),
+                            Utils::scm2str(message));
   return scm_long2num(m.getCode());
 
 }
@@ -356,7 +356,7 @@ SCM
 ScriptCommands::Nick(SCM nick)
 {
   VERIFY_STRING(nick);
-  Message m = Commands::Nick(Interp::bot, Utils::scm2String(nick));
+  Message m = Commands::Nick(Interp::bot, Utils::scm2str(nick));
   return scm_long2num(m.getCode());
 }
 
@@ -365,8 +365,8 @@ ScriptCommands::Op(SCM channel, SCM who)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(who);
-  Message m = Commands::Op(Interp::bot, Utils::scm2String(channel),
-                           Utils::scm2String(who));
+  Message m = Commands::Op(Interp::bot, Utils::scm2str(channel),
+                           Utils::scm2str(who));
   return scm_long2num(m.getCode());
 }
 
@@ -374,7 +374,7 @@ SCM
 ScriptCommands::Part(SCM channel)
 {
   VERIFY_STRING(channel);
-  Message m = Commands::Part(Interp::bot, Utils::scm2String(channel));
+  Message m = Commands::Part(Interp::bot, Utils::scm2str(channel));
   return scm_long2num(m.getCode());
 }
 
@@ -390,8 +390,8 @@ ScriptCommands::Say(SCM channel, SCM message)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(message);
-  Message m = Commands::Say(Interp::bot, Utils::scm2String(channel),
-                            Utils::scm2String(message));
+  Message m = Commands::Say(Interp::bot, Utils::scm2str(channel),
+                            Utils::scm2str(message));
   return scm_long2num(m.getCode());
 }
 
@@ -415,7 +415,7 @@ ScriptCommands::SetFloodRate(SCM rate)
 SCM
 ScriptCommands::SetVersion(SCM version)
 {
-  Message m = Commands::SetVersion(Interp::bot, Utils::scm2String(version));
+  Message m = Commands::SetVersion(Interp::bot, Utils::scm2str(version));
   return scm_long2num(m.getCode());
 }
 
@@ -425,8 +425,8 @@ ScriptCommands::TBan(SCM channel, SCM who, SCM seconds)
   VERIFY_STRING(channel);
   VERIFY_STRING(who);
   VERIFY_NUMBER(seconds);
-  Message m = Commands::TBan(Interp::bot, Utils::scm2String(channel),
-                             Utils::scm2String(who), gh_scm2long(seconds));
+  Message m = Commands::TBan(Interp::bot, Utils::scm2str(channel),
+                             Utils::scm2str(who), gh_scm2long(seconds));
   return scm_long2num(m.getCode());
 }
 
@@ -438,9 +438,9 @@ ScriptCommands::TKBan(SCM channel, SCM who, SCM seconds, SCM reason)
   VERIFY_NUMBER(seconds);
   String r = "";
   if (SCM_STRINGP(reason))
-    r = Utils::scm2String(reason);
-  Message m = Commands::TKBan(Interp::bot, Utils::scm2String(channel),
-                              Utils::scm2String(who),
+    r = Utils::scm2str(reason);
+  Message m = Commands::TKBan(Interp::bot, Utils::scm2str(channel),
+                              Utils::scm2str(who),
                               gh_scm2long(seconds), r);
   return scm_long2num(m.getCode());
 }
@@ -450,8 +450,8 @@ ScriptCommands::Topic(SCM channel, SCM topic)
 {
   VERIFY_STRING(channel);
   VERIFY_STRING(topic);
-  Message m = Commands::Topic(Interp::bot, Utils::scm2String(channel),
-                              Utils::scm2String(topic));
+  Message m = Commands::Topic(Interp::bot, Utils::scm2str(channel),
+                              Utils::scm2str(topic));
   return scm_long2num(m.getCode());
 }
 
@@ -459,14 +459,14 @@ SCM
 ScriptCommands::Unlock(SCM channel)
 {
   VERIFY_STRING(channel);
-  Message m = Commands::Unlock(Interp::bot, Utils::scm2String(channel));
+  Message m = Commands::Unlock(Interp::bot, Utils::scm2str(channel));
   return scm_long2num(m.getCode());
 }
 
 SCM
 ScriptCommands::getNickname(void)
 {
-  return Utils::string2SCM(Interp::bot->nickName);
+  return Utils::str2scm(Interp::bot->nickName);
 }
 
 SCM
@@ -476,9 +476,9 @@ ScriptCommands::getServer(void)
   int serverNumber = Interp::bot->serverList->currentNumber;
 
   return gh_list(scm_long2num(serverNumber),
-                 Utils::string2SCM(serv->getHostName()),
+                 Utils::str2scm(serv->getHostName()),
                  scm_long2num(serv->getPort()),
-                 Utils::string2SCM(serv->getPassword()),
+                 Utils::str2scm(serv->getPassword()),
                  SCM_UNDEFINED);
 }
 
@@ -494,9 +494,9 @@ ScriptCommands::getServerList(void)
     s = (*it);
     res = gh_append2(res,
                      gh_list(gh_list(scm_long2num(i++),
-                                     Utils::string2SCM(s->getHostName()),
+                                     Utils::str2scm(s->getHostName()),
                                      scm_long2num(s->getPort()),
-                                     Utils::string2SCM(s->getPassword()),
+                                     Utils::str2scm(s->getPassword()),
                                      SCM_UNDEFINED), SCM_UNDEFINED));
   }
   return res;
@@ -538,7 +538,7 @@ ScriptCommands::addCommand(SCM scm_commandName, SCM scm_function,
     return SCM_BOOL_F;
 
   // We check that the command does not exist
-  String commandName = Utils::scm2String(scm_commandName).toUpper();
+  String commandName = Utils::to_upper (Utils::scm2str(scm_commandName));
   if (Interp::bot->userFunctions[commandName])
     return SCM_BOOL_F;
 
@@ -583,7 +583,7 @@ ScriptCommands::delCommand(SCM scm_commandName)
     return SCM_BOOL_F;
 
   // We check that the command does exist
-  String commandName = Utils::scm2String(scm_commandName).toUpper();
+  String commandName = Utils::to_upper (Utils::scm2str(scm_commandName));
   if (!Interp::bot->userFunctions[commandName])
     return SCM_BOOL_F;
 
@@ -606,7 +606,7 @@ ScriptCommands::AddHook(SCM type, SCM regex, SCM function, SCM pri, SCM fall,
   if (!SCM_UNBNDP (fall))
     fallt = SCM_NFALSEP (fall);
   if (!SCM_UNBNDP (name))
-    rname = Utils::scm2String (name);
+    rname = Utils::scm2str (name);
   return SCM_BOOL (Interp::bot->botInterp->AddHook(gh_scm2long(type),
                                                   regex, function,
                                                   priority, fallt, rname));
@@ -629,8 +629,8 @@ ScriptCommands::sendDCCChatMessage (SCM to, SCM message)
 {
 
   return SCM_BOOL (Interp::bot->dccConnections->sendMessage 
-                  (Utils::scm2String (to),
-                   Utils::scm2String (message)));
+                  (Utils::scm2str (to),
+                   Utils::scm2str (message)));
 }
 
 // Message sending
@@ -645,8 +645,8 @@ ScriptCommands::sendCTCP(SCM to, SCM command , SCM message)
   VERIFY_STRING(command);
   VERIFY_STRING(message);
 
-  IQUEUE->sendCTCP (Utils::scm2String (to), Utils::scm2String (command),
-                  Utils::scm2String (message));
+  IQUEUE->sendCTCP (Utils::scm2str (to), Utils::scm2str (command),
+                  Utils::scm2str (message));
   return SCM_UNSPECIFIED;
 }
 #endif
index d63ac4f..ebba328 100644 (file)
@@ -1,6 +1,6 @@
 // ServerQueue.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
@@ -99,11 +99,11 @@ ServerQueue::sendCTCP(String to, String command,
                                        MNICK + " " + to +
                                        " " + message,
                                        scm_listify (Utils::
-                                                 string2SCM (MNICK),
+                                                 str2scm (MNICK),
                                                  Utils::
-                                                 string2SCM (to),
+                                                 str2scm (to),
                                                  Utils::
-                                                 string2SCM (message),
+                                                 str2scm (message),
                                                  SCM_UNDEFINED));
     }
   else
@@ -111,14 +111,14 @@ ServerQueue::sendCTCP(String to, String command,
                                   MNICK + " " + to + " " +
                                   command + " " + message,
                                   scm_listify (Utils::
-                                             string2SCM (MNICK),
+                                             str2scm (MNICK),
                                              Utils::
-                                             string2SCM (to),
+                                             str2scm (to),
                                              Utils::
-                                             string2SCM
+                                             str2scm
                                              (command),
                                              Utils::
-                                             string2SCM (message),
+                                             str2scm (message),
                                                SCM_UNDEFINED));
 #endif
 
@@ -221,25 +221,25 @@ ServerQueue::sendPrivmsg(String dest, String message)
   // hook stuff
 #ifdef USESCRIPTS
   if (message[0] != '\001')
-    if (Utils::isChannel (dest))
+    if (Utils::channel_p (dest))
       Interp::bot->botInterp->RunHooks (Hook::SEND_PUBLIC,
                                        Interp::bot->nickName + " " + dest +
                                        " " + message,
                                        scm_listify (Utils::
-                                                    string2SCM (Interp::bot->nickName),
+                                                    str2scm (Interp::bot->nickName),
                                                     Utils::
-                                                    string2SCM (dest),
+                                                    str2scm (dest),
                                                     Utils::
-                                                    string2SCM
+                                                    str2scm
                                                     (message), SCM_UNDEFINED));
     else
       Interp::bot->botInterp->RunHooks (Hook::SEND_MESSAGE,
                                        Interp::bot->nickName + " " +
                                        message,
                                        scm_listify (Utils::
-                                                    string2SCM (Interp::bot->nickName),
+                                                    str2scm (Interp::bot->nickName),
                                                     Utils::
-                                                    string2SCM
+                                                    str2scm
                                                     (message), SCM_UNDEFINED));
 #endif
 }
index 7b98320..d510619 100644 (file)
@@ -1,5 +1,6 @@
 // ServerQueueItem.C  -*- C++ -*-
 // Copyright (c) 1998 Etienne BERNARD
+// Copyright (c) 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
@@ -45,7 +46,7 @@ ServerQueueChannelModeItem::ServerQueueChannelModeItem(String c, String m, Strin
     channel(c), mode(m), parameters(p)
 {
   StringTokenizer st(p);
-  paramcount = st.countTokens();
+  paramcount = st.count_tokens();
 }
 
 bool
index f5e124e..ca22f77 100644 (file)
@@ -1,6 +1,6 @@
 // ShitList.C  -*- C++ -*-
 // Copyright (c) 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
@@ -24,6 +24,7 @@
 
 #include "ShitList.H"
 #include "StringTokenizer.H"
+#include "Utils.H"
 
 ShitList::ShitList(String filename)
   : listFileName(filename)
@@ -55,11 +56,11 @@ ShitList::read()
 
   while (file >> temp, temp.length() != 0) {
     StringTokenizer st(temp);
-    String mask = st.nextToken(':');
-    String channelMask = st.nextToken(':');
-    String level = st.nextToken(':');
-    String expiration = st.nextToken(':');
-    String reason = st.rest().trim();
+    String mask = st.next_token(':');
+    String channelMask = st.next_token(':');
+    String level = st.next_token(':');
+    String expiration = st.next_token(':');
+    String reason = Utils::trim_str (st.rest());
     l.push_back (new ShitEntry(mask, channelMask, std::atoi(level), 
                              std::atol(expiration), reason));
     line++;
index d257111..060d820 100644 (file)
@@ -1,5 +1,6 @@
 // String.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
+// 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
@@ -186,12 +187,24 @@ String::subString(int debut, int fin)
   return res;
 }
 
+String
+String::substr (int s, int e)
+{
+  return subString (s, e);
+}
+
 String
 String::subString(int debut)
 {
   return subString(debut, len - 1);
 }
 
+String
+String::substr (int s)
+{
+  return subString (s);
+}
+
 String
 String::toLower()
 {
@@ -232,7 +245,7 @@ String::trim()
   while (i < j && (p->s[i] == ' ' || p->s[i] == '\t' || p->s[i] == '\r'))
     i++;
   
-  while (j > 0 && (p->s[j] == ' ' || p->s[j] == '\t' || p->s[i] == '\r'))
+  while (j > 0 && (p->s[j] == ' ' || p->s[j] == '\t' || p->s[j] == '\r'))
     j--;
   
   return subString(i, j);
index 697520f..70f6a55 100644 (file)
@@ -1,6 +1,6 @@
 // String.H  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (c) 2002 Clinton Ebadi
+// Copyright (c) 2002.2003,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
@@ -54,6 +54,9 @@ public:
 
   String subString(int);
   String subString(int, int);
+  
+  String substr(int);
+  String substr(int, int);
 
   String toLower();
   String toUpper();
index f4bea1e..c4dfeb7 100644 (file)
@@ -1,5 +1,6 @@
 // StringTokenizer.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
+// Copyright (c) 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
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 
 #include "StringTokenizer.H"
+#include <string>
+#include <cstring>
 
-StringTokenizer::StringTokenizer(String string)
-  : st(string), pos(0)
+StringTokenizer::StringTokenizer(std::string s)
+  : st(s), pos(0)
 { }
 
 bool
-StringTokenizer::hasMoreTokens()
+StringTokenizer::more_tokens_p ()
 {
   if (pos == st.length())
     return false;
@@ -35,7 +38,7 @@ StringTokenizer::hasMoreTokens()
 }
 
 bool
-StringTokenizer::hasMoreTokens(char c)
+StringTokenizer::more_tokens_p (char c)
 {
   if (pos == st.length())
     return false;
@@ -48,35 +51,37 @@ StringTokenizer::hasMoreTokens(char c)
 }
 
 int
-StringTokenizer::countTokens()
+StringTokenizer::count_tokens ()
 {
   int i = 0;
-  StringTokenizer s(st);
+  StringTokenizer s (st);
+  
+  while (s.more_tokens_p ())
+    {
+      s.next_token ();
+      i++;
+    }
   
-  while (s.hasMoreTokens()) {
-    s.nextToken();
-    i++;
-  }
-
   return i;
 }
 
 int
-StringTokenizer::countTokens(char c)
+StringTokenizer::count_tokens (char c)
 {
   int i = 0;
   StringTokenizer s(st);
   
-  while (s.hasMoreTokens(c)) {
-    s.nextToken(c);
-    i++;
-  }
-
+  while (s.more_tokens_p (c))
+    {
+      s.next_token (c);
+      i++;
+    }
+  
   return i;
 }
 
-String
-StringTokenizer::nextToken()
+std::string
+StringTokenizer::next_token()
 {
   int i = pos;
   
@@ -84,43 +89,46 @@ StringTokenizer::nextToken()
     i++;
   
   for (int j = i; j < st.length(); j++)
-    if (st[j] == ' ' || st[j] == '\t') {
-      pos = j + 1;
-      return st.subString(i, j - 1);
-    }
+    if (st[j] == ' ' || st[j] == '\t') 
+      {
+       pos = j + 1;
+       return st.substr (i, j - 1);
+      }
 
   pos = st.length();
-  return st.subString(i, st.length() - 1);
+  return st.substr (i, st.length() - 1);
 }
 
-String
-StringTokenizer::nextToken(char c, bool empty)
+std::string
+StringTokenizer::next_token (char c, bool empty)
 {
   int i = pos;
 
   while (i < st.length() && (st[i] == c))
     i++;
   for (int j = i; j < st.length(); j++)
-    if (st[j] == c) {
-      pos = j + 1;
-      return st.subString(i, j - 1);
-    }
+    if (st[j] == c)
+      {
+       pos = j + 1;
+       return st.substr (i, j - 1);
+      }
 
   if (empty)
     return "";
-
+  
   pos = st.length();
-  return st.subString(i, st.length() - 1);
+  return st.substr (i, st.length() - 1);
 }
 
-String
+std::string
 StringTokenizer::rest()
 {
   if (pos == st.length())
     return "";
 
-  while (pos < st.length() && (st[pos] == ' ' || st[pos] == '\t'))
+  // Skip whitespace
+  while (pos < st.length() && (std::isspace (st[pos])))
     pos++;
 
-  return st.subString(pos, st.length() - 1);
+  return st.substr (pos, st.length() - 1);
 }
index 8733a30..a950e20 100644 (file)
@@ -1,5 +1,6 @@
 // StringTokenizer.H  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
+// Copyright (c) 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
 #ifndef STRINGTOKENIZER_H
 #define STRINGTOKENIZER_H
 
-#include "String.H"
+#include <string>
 
-class StringTokenizer {
-  String st;
+class StringTokenizer
+{
+  std::string st;
   int pos;
 public:
-  StringTokenizer(String);
+  StringTokenizer(std::string);
   StringTokenizer(StringTokenizer &);
   
-  bool hasMoreTokens();
-  bool hasMoreTokens(char);
+  bool more_tokens_p ();
+  bool more_tokens_p (char);
   
-  int countTokens();
-  int countTokens(char);
+  int count_tokens();
+  int count_tokens(char);
   
-  String nextToken();
-  String nextToken(char, bool = false);
+  std::string next_token();
+  std::string next_token(char, bool = false);
   
-  String rest();
+  std::string rest();
 };
 
 #endif
index 3bcfc50..7e4685d 100644 (file)
@@ -1,6 +1,6 @@
 // UserCommands.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
 
 #include <fstream>
 #include <map>
+#include <string>
+#include <cctype>
+#include <cstdlib>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#include <ctype.h>
 #include <cstdlib>
 #ifndef _X_OPEN_SOURCE
 #define _X_OPEN_SOURCE
@@ -72,13 +74,13 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
   String mask, who, maskChannel, level, prot,
     aop, expiration, passwd;
 
-  mask = who = st.nextToken();
-  maskChannel = st.nextToken();
-  level = st.nextToken();
-  prot = st.nextToken();
-  aop = st.nextToken();
-  expiration = st.nextToken();
-  passwd = st.nextToken();
+  mask = who = st.next_token();
+  maskChannel = st.next_token();
+  level = st.next_token();
+  prot = st.next_token();
+  aop = st.next_token();
+  expiration = st.next_token();
+  passwd = st.next_token();
 
   if (mask == "" || maskChannel == "" || level == "" ||
       prot == "" || aop == "") {
@@ -86,13 +88,13 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
     return;
   }
 
-//   if (!Utils::isWildcard(mask)) {
+//   if (!Utils::wildcard_p(mask)) {
 //     mask = cnx->bot->getUserhost(channel, who);
 //     if (mask == "") {
 //       from->sendNotice(String("\002I can not find\002 ") + who);
 //       return;
 //     }
-//     mask = Utils::makeWildcard(mask);
+//     mask = Utils::make_wildcard(mask);
 //   }
   
 //   if (cnx->bot->userList->isInUserList(mask, maskChannel)) {
@@ -108,7 +110,7 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
   l = atoi((const char *)level);
   if (l < 0 || l > User::FRIEND)
     return;
-  if (l > Utils::getLevel(cnx->bot, from->getAddress())) {
+  if (l > Utils::get_level(cnx->bot, from->getAddress())) {
     from->sendNotice("\002You can not give a level greater than yours.\002");
     return;
   }
@@ -119,7 +121,7 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
   if (a != 0 && a != 1)
     return;
 
-  e = Utils::strToTime(expiration);
+  e = Utils::str2time(expiration);
 
   if (!e)
     e = -1;
@@ -133,11 +135,11 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
       from->sendNotice(String("\002Added\002 ") + mask +
                       " \002on channels\002 " + maskChannel);
       from->sendNotice(String("\002Level:\002 ") +
-                      Utils::levelToStr(l) +
+                      Utils::level2str(l) +
                       "  \002Protection:\002 " +
-                      Utils::protToStr(p) +
+                      Utils::prot2str(p) +
                       "  \002Auto-op:\002 " +
-                      Utils::boolToStr(a));
+                      Utils::bool2str(a));
     }
   else
     from->sendNotice(m.getMessage ());
@@ -155,11 +157,11 @@ UserCommands::AddServer(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String serverName = st.nextToken();
+  String serverName = st.next_token();
   int port = 6667;
 
-  if (st.hasMoreTokens()) {
-    String temp = st.nextToken();
+  if (st.more_tokens_p()) {
+    String temp = st.next_token();
     port = atoi((const char *)temp);
   }
 
@@ -181,11 +183,11 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from,
   StringTokenizer st(rest);
   String mask, who, maskChannel, level, expiration, reason;
 
-  mask = who = st.nextToken();
-  maskChannel = st.nextToken();
-  level = st.nextToken();
-  expiration = st.nextToken();
-  reason = st.rest().trim();
+  mask = who = st.next_token();
+  maskChannel = st.next_token();
+  level = st.next_token();
+  expiration = st.next_token();
+  reason = Utils::trim_str (st.rest());
 
   /*  if (mask == "" || maskChannel == "" || level == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
@@ -199,13 +201,13 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from,
   */
 
   /*
-  if (!Utils::isWildcard(mask)) {
+  if (!Utils::wildcard_p(mask)) {
     mask = cnx->bot->getUserhost(channel, who);
     if (mask == "") {
       from->sendNotice(String("\002I can not find\002 ") + who);
       return;
     }
-    mask = Utils::makeWildcard(mask);
+    mask = Utils::make_wildcard(mask);
     if (cnx->bot->shitList->getShit(mask, maskChannel)) {
       from->sendNotice(mask + " \002is already in shitlist on channel(s)\002 " +
                        maskChannel);
@@ -220,7 +222,7 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from,
   if (l < 0 || l > ShitEntry::SHIT_NODEBAN)
     return;
 
-  e = Utils::strToTime(expiration);
+  e = Utils::str2time(expiration);
 
   if (!e)
     e = -1;
@@ -250,8 +252,8 @@ UserCommands::Alias(ServerConnection *cnx, Person *from,
                     String channel, String rest)
 {
   StringTokenizer st(rest);
-  String newF = st.nextToken().toUpper();
-  String oldF = st.nextToken().toUpper();
+  String newF = Utils::to_upper (st.next_token());
+  String oldF = Utils::to_upper (st.next_token());
 
   if (newF == "" || oldF == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
@@ -320,16 +322,16 @@ UserCommands::BanList(ServerConnection *cnx, Person *from,
 //   StringTokenizer st(rest);
   
 //   String who;
-//   String mask = who = st.nextToken();
-//   String maskChannel = st.nextToken();
-//   String level = st.nextToken();
+//   String mask = who = st.next_token();
+//   String maskChannel = st.next_token();
+//   String level = st.next_token();
   
 //   if (mask == "" || maskChannel == "" || level == "") {
 //     from->sendNotice("\002Invalid syntax for this command.\002");
 //     return;
 //   }
   
-//   if (!Utils::isWildcard(mask)) {
+//   if (!Utils::wildcard_p(mask)) {
 //     mask = cnx->bot->getUserhost(channel, who);
 //     if (mask == "") {
 //       from->sendNotice(String("\002I can not find\002 ") + who);
@@ -354,12 +356,12 @@ UserCommands::BanList(ServerConnection *cnx, Person *from,
 //     return;
 //   }
   
-//   if (l > Utils::getLevel(cnx->bot, from->getAddress())) {
+//   if (l > Utils::get_level(cnx->bot, from->getAddress())) {
 //     from->sendNotice("\002You can not give a level greater than yours.\002");
 //     return;
 //   }
   
-//   if (Utils::getLevel(cnx->bot, from->getAddress()) < uli->level) {
+//   if (Utils::get_level(cnx->bot, from->getAddress()) < uli->level) {
 //     from->sendNotice("\002You can not change the level for a person "
 //                      "whose level is greater than yours.\002");
 //     return;
@@ -462,21 +464,21 @@ UserCommands::DelUser(ServerConnection *cnx, Person *from,
   StringTokenizer st(rest);
 
   String who;
-  String mask = who = st.nextToken();
-  String maskChannel = st.nextToken();
+  String mask = who = st.next_token();
+  String maskChannel = st.next_token();
 
   if (mask == "" || maskChannel == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
     return;
   }
 
-  if (!Utils::isWildcard(mask)) {
+  if (!Utils::wildcard_p(mask)) {
     mask = cnx->bot->getUserhost(channel, who);
     if (mask == "") {
       from->sendNotice(String("\002I can not find\002 ") + who);
       return;
     }
-    mask = Utils::makeWildcard(mask);
+    mask = Utils::make_wildcard(mask);
   }
   
   if (!cnx->bot->userList->isInUserList(mask, maskChannel)) {
@@ -498,21 +500,21 @@ UserCommands::DelShit(ServerConnection *cnx, Person *from,
   StringTokenizer st(rest);
   
   String who;
-  String mask = who = st.nextToken();
-  String maskChannel = st.nextToken();
+  String mask = who = st.next_token();
+  String maskChannel = st.next_token();
 
   if (mask == "" || maskChannel == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
     return;
   }
 
-  if (!Utils::isWildcard(mask)) {
+  if (!Utils::wildcard_p(mask)) {
     mask = cnx->bot->getUserhost(channel, who);
     if (mask == "") {
       from->sendNotice(String("\002I can not find\002 ") + who);
       return;
     }
-    mask = Utils::makeWildcard(mask);
+    mask = Utils::make_wildcard(mask);
   }
   
   if (!cnx->bot->shitList->getShit(mask, maskChannel)) {
@@ -577,7 +579,7 @@ UserCommands::Help(ServerConnection *cnx, Person *from,
 {
   if (rest.length() == 0) {
     from->sendNotice("\002Available topics for you are:\002");
-    int level = Utils::getLevel(cnx->bot, from->getAddress());
+    int level = Utils::get_level(cnx->bot, from->getAddress());
     String result = "";
     int length = 0;
     std::map<std::string, class userFunction*, std::less<std::string> >::iterator it;
@@ -598,7 +600,7 @@ UserCommands::Help(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String command = st.nextToken().toUpper();
+  String command = Utils::to_upper (st.next_token());
   std::ifstream helpFile(cnx->bot->helpFileName);
 
   if (!helpFile) {
@@ -688,9 +690,9 @@ UserCommands::Join(ServerConnection *cnx, Person *from,
                    String channel, String rest)
 {
   StringTokenizer st(rest);
-  channel = st.nextToken();
+  channel = st.next_token();
 
-  if (!Utils::isValidChannelName(channel)) {
+  if (!Utils::valid_channel_name_p(channel)) {
     from->sendNotice(String("\002") + channel +
                      " is not a valid channel name\002");
     return;
@@ -741,9 +743,9 @@ UserCommands::Kick(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String who = st.nextToken();
+  String who = st.next_token();
 
-  if (Utils::isWildcard(who)) {
+  if (Utils::wildcard_p(who)) {
     User * u = c->getUser(nick);
     if (!u)
       return;
@@ -760,7 +762,7 @@ UserCommands::Kick(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (Utils::isWildcard(who)) {
+  if (Utils::wildcard_p(who)) {
     Mask m(who);
     for (std::map<String, User *, std::less<String> >::iterator it =
            c->channelMemory.begin();
@@ -793,7 +795,7 @@ UserCommands::KickBan(ServerConnection *cnx, Person *from,
 {
   StringTokenizer st(rest);
 
-  Ban(cnx, 0, channel, st.nextToken());
+  Ban(cnx, 0, channel, st.next_token());
   Kick(cnx, from, channel, rest);
 }
 
@@ -854,7 +856,7 @@ UserCommands::Msg(ServerConnection *cnx, Person *from,
                    String channel, String rest)
 {
   StringTokenizer st(rest);
-  String who = st.nextToken();
+  String who = st.next_token();
   String message = st.rest();
 
   Message m = Commands::Msg(cnx->bot, who, message);
@@ -926,14 +928,14 @@ UserCommands::Nick(ServerConnection *cnx, Person *from,
 {
   // We parse the parameters
   StringTokenizer st(rest);
-  String nick = st.nextToken();
+  String nick = st.next_token();
 
   if (rest == "") {
     from->sendNotice(String("\002No nickname given.\002"));
     return;
   }
 
-  if (!Utils::isValidNickName(nick)) {
+  if (!Utils::valid_nickname_p(nick)) {
     from->sendNotice(String("\002") + nick +
                      " is not a valid nickname\002");
     return;
@@ -957,7 +959,7 @@ UserCommands::NsLookup(ServerConnection *cnx, Person *from,
 
   if (rest.find('.') == -1) {
     StringTokenizer st(cnx->bot->getUserhost("", rest));
-    st.nextToken('@');
+    st.next_token('@');
     target = st.rest();
     if (target.length() == 0) {
       from->sendNotice(String("\002I could not find\002 ") +
@@ -1009,7 +1011,7 @@ UserCommands::Op(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (Utils::isWildcard(rest)) {
+  if (Utils::wildcard_p(rest)) {
     from->sendNotice("\002Mass op is not allowed.\002");
     return;
   }
@@ -1301,8 +1303,8 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
   Channel * c = cnx->bot->channelList->getChannel(channel);
 
   StringTokenizer st(rest);
-  String who = st.nextToken();
-  String t = st.nextToken();
+  String who = st.next_token();
+  String t = st.next_token();
   String dest;
 
   if (who == "" || t == "") {
@@ -1311,7 +1313,7 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (Utils::isWildcard(who) && from) {
+  if (Utils::wildcard_p(who) && from) {
     User * u = c->getUser(from->getNick());
     if (u && u->getLevel() < User::TRUSTED_USER) {
       if (from)
@@ -1328,7 +1330,7 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (!Utils::isWildcard(who))
+  if (!Utils::wildcard_p(who))
     dest = cnx->bot->getUserhost(channel, who);
   else
     dest = who;
@@ -1341,13 +1343,13 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
 
   time_t w;
 
-  if ((w = Utils::strToTime(t)) == 0) {
+  if ((w = Utils::str2time(t)) == 0) {
     if (from)
       from->sendNotice(t + " \002is an invalid time.\002");
     return;
   }
 
-  dest = Utils::makeWildcard(dest);
+  dest = Utils::make_wildcard(dest);
   Mask m(dest);
 
   for (std::list<UserListItem *>::iterator it = cnx->bot->userList->l.begin();
@@ -1379,8 +1381,8 @@ UserCommands::TKBan(ServerConnection *cnx, Person *from,
                    String channel, String rest)
 {
   StringTokenizer st(rest);
-  String who = st.nextToken();
-  String t = st.nextToken();
+  String who = st.next_token();
+  String t = st.next_token();
 
   TBan(cnx, 0, channel, who + " " + t);
   Kick(cnx, from, channel, who + " " + st.rest());
@@ -1420,13 +1422,18 @@ UserCommands::UserList(ServerConnection *cnx, Person *from,
   for (std::list<UserListItem *>::iterator it = cnx->bot->userList->l.begin();
        it != cnx->bot->userList->l.end();
        it++)
-    from->sendNotice((*it)->mask.getMask().pad(25) + " " +
-                     (*it)->channelMask.getMask().pad(10) + " " +
-                     Utils::levelToStr((*it)->level).pad(12) + " " +
-                     Utils::protToStr((*it)->prot).pad(7) + " " +
-                     Utils::boolToStr((*it)->aop).pad(5) + " " +
-                     String((long)(*it)->expirationDate));
-
+    from->sendNotice((*it)->mask.getMask().pad(25)
+                    + " "
+                    + (*it)->channelMask.getMask().pad(10)
+                    + " " +
+                    String(Utils::level2str((*it)->level)).pad(12)
+                    + " " +
+                    String(Utils::prot2str((*it)->prot)).pad(7)
+                    + " " +
+                    String(Utils::bool2str((*it)->aop)).pad(5)
+                    + " " +
+                    String(Utils::long2str ((*it)->expirationDate)));
+  
   from->sendNotice("\002End of userlist.\002");
 }
 
@@ -1449,16 +1456,16 @@ UserCommands::Who(ServerConnection *cnx, Person *from,
                       uli->mask.getMask() + " \002on\002 " +
                       uli->channelMask.getMask());
     from->sendNotice(String("\002Lvl:\002 ") +
-                     Utils::levelToStr(uli->level) +
+                     Utils::level2str(uli->level) +
                      " \002Prot:\002 " +
-                     Utils::protToStr(uli->prot) +
+                     Utils::prot2str(uli->prot) +
                      " \002Aop:\002 " +
-                     Utils::boolToStr(uli->aop) +
+                     Utils::bool2str(uli->aop) +
                      " \002Expired:\002 " +
-                     Utils::boolToStr(!uli->isStillValid()) +
+                     Utils::bool2str(!uli->isStillValid()) +
                      " \002Ident:\002 " +
                      (uli && !uli->identified ? "\026" : "") +
-                     Utils::boolToStr(uli && uli->identified) +
+                     Utils::bool2str(uli && uli->identified) +
                      (uli && !uli->identified ? "\026" : ""));
   } else
     from->sendNotice(String("\002You are not in the userlist for\002 ") +
@@ -1477,7 +1484,7 @@ UserCommands::Whois(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String otherNick = st.nextToken();
+  String otherNick = st.next_token();
 
   User * u = cnx->bot->channelList->getChannel(channel)->getUser(otherNick);
   UserListItem * uli;
@@ -1495,15 +1502,15 @@ UserCommands::Whois(ServerConnection *cnx, Person *from,
                      " \002is\002 " + uli->mask.getMask() +
                      " \002on\002 " + uli->channelMask.getMask());
     from->sendNotice(String("\002Lvl:\002 ") +
-                     Utils::levelToStr(uli->level) +
+                     Utils::level2str(uli->level) +
                      " \002Prot:\002 " +
-                     Utils::protToStr(uli->prot) +
+                     Utils::prot2str(uli->prot) +
                      " \002Aop:\002 " +
-                     Utils::boolToStr(uli->aop) +
+                     Utils::bool2str(uli->aop) +
                      " \002Expired:\002 " +
-                     Utils::boolToStr(!uli->isStillValid()) +
+                     Utils::bool2str(!uli->isStillValid()) +
                      " \002Ident:\002 " +
-                     Utils::boolToStr(uli && uli->identified));
+                     Utils::bool2str(uli && uli->identified));
   } else
     from->sendNotice(otherNick +
                       " \002is not in the userlist for\002 " +
index 235df93..b5a795e 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)
@@ -49,18 +50,18 @@ UserList::read()
 
   while (file >> temp, temp.length() != 0) {
     StringTokenizer st(temp);
-    if (st.countTokens(':') != 7) {
+    if (st.count_tokens(':') != 7) {
       std::cerr << "Error when reading userlist (" << listFilename <<
         ") line " << line << "...\n";
       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();
+    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),
dissimilarity index 62%
index 73ea786..7cc0fa1 100644 (file)
-// Utils.C  -*- C++ -*-
-// Copyright (c) 1997, 1998 Etienne BERNARD
-
-// 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
-// the Free Software Foundation; either version 2 of the License, or
-// any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-
-// 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.
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <cctype>
-#include <cstdlib>
-
-#include "Utils.H"
-#include "StringTokenizer.H"
-
-String
-Utils::getNick(String nuh)
-{
-  StringTokenizer st(nuh);
-  return st.nextToken('!');
-}
-
-String
-Utils::getUserhost(String nuh)
-{
-  StringTokenizer st(nuh);
-  st.nextToken('@');
-  return st.rest();
-}
-
-String
-Utils::getKey()
-{
-  return String((long)rand());
-}
-
-bool
-Utils::isIP(String host)
-{
-  for (int i = 0; i < host.length(); i++)
-    if (!isdigit(host[i]) && host[i]!='.')
-      return false;
-  return true;
-}
-
-String
-Utils::makeWildcard(String mask)
-{
-  StringTokenizer st(mask);
-
-  st.nextToken('!', true);
-  String nick = "*";
-
-  String user = st.nextToken('@', true);
-  if (user[0] == '~' || user[0] == '^' ||
-      user[0] == '+' || user[0] == '-' ||
-      user[0] == '*')
-    user = user.subString(1);
-  if (user.length() < 10)
-    user = String("*") + user;
-
-  String host = st.rest();
-  StringTokenizer st2(host);
-  if (!isWildcard(host)) {
-    if (isIP(host)) {
-      host = st2.nextToken('.') + ".";
-      host = host + st2.nextToken('.') + ".";
-      host = host + st2.nextToken('.') + ".*";
-    } else {
-      st2.nextToken('.', true);
-      if (st2.countTokens('.') > 1)
-        host = String("*.") + st2.rest();
-    }
-  } else {
-    if (host == "") host = "*";
-  }
-
-  std::cout << nick + "!" + user + "@" + host << std::endl;
-
-  return nick + "!" + user + "@" + host;
-}
-
-bool
-Utils::isChannel(String c)
-{
-  return (c[0] == '#' || c[0] == '&');
-}
-
-bool
-Utils::isWildcard(String c)
-{
-  return (c.find('*') != -1);
-}
-
-bool
-Utils::isValidChannelName(String c)
-{
-  return isChannel(c) && c.find(',') == -1;
-}
-
-#define isvalid(c) (((c) >= 'A' && (c) <= '~') || isdigit(c) || (c) == '-')
-
-bool
-Utils::isValidNickName(String n)
-{
-  if (n[0] == '-' || isdigit(n[0]) || n.length() > 9)
-    return false;
-
-  for (int i = 0; i < n.length(); i++)
-    if (!isvalid(n[i]) || isspace(n[i]))
-      return false;
-
-  return true;
-}
-
-int
-Utils::getLevel(Bot * b, String nuh)
-{
-  return b->userList->getMaxLevel(nuh);
-}
-
-int
-Utils::getLevel(Bot * b, String nuh, String channel)
-{
-  if (!isChannel(channel))
-    return getLevel(b, nuh);
-
-  if (Channel * c =  b->channelList->getChannel(channel)) {
-    User * u = c->getUser(getNick(nuh));
-    if (u)
-      return u->getLevel();
-  } else {
-    return -1;
-  }
-
-  return b->userList->getLevel(nuh, channel);
-}
-
-String
-Utils::levelToStr(int l)
-{
-  switch (l) {
-  case User::USER: return "User";
-  case User::TRUSTED_USER: return "Trusted User";
-  case User::FRIEND: return "Friend";
-  case User::MASTER: return "Master";
-  }
-  return "None";
-}
-
-String
-Utils::protToStr(int p)
-{
-  switch (p) {
-  case User::NO_BAN: return "No ban";
-  case User::NO_KICK: return "No kick";
-  case User::NO_DEOP: return "No deop";
-  }
-  return "None";
-}
-
-String
-Utils::boolToStr(bool b)
-{
-  return b ? "True" : "False";
-}
-
-time_t
-Utils::strToTime(String str)
-{
-  char num[512];
-  int len = 0;
-  time_t ans = 0;
-
-  num[0]='\0';
-
-  if (str.toLower() == "Inf")
-    return -1;
-
-  if (!isdigit(str[0]))
-    return 0;
-
-  for (int i = 0; i < str.length(); i++) {
-    switch (str[i]) {
-    case 'y':
-    case 'Y':
-      num[len] = '\0';
-      len = 0;
-      ans += (atoi(num) * 31557600);
-      break;
-    case 'M':
-      num[len] = '\0';
-      len = 0;
-      ans += (atoi(num) * 2629800);
-      break;
-    case 'd':
-    case 'D':
-      num[len] = '\0';
-      len = 0;
-      ans += (atoi(num) * 86400);
-      break;
-    case 'h':
-    case 'H':
-      num[len] = '\0';
-      len = 0;
-      ans += (atoi(num) * 3600);
-      break;
-    case 'm':
-      num[len] = '\0';
-      len = 0;
-      ans += (atoi(num) * 60);
-      break;
-    case 's':
-    case 'S':
-      num[len] = '\0';
-      len = 0;
-      ans += atoi(num);
-    default:
-      if (isdigit(str[i])) {
-        num[len++] = str[i];
-        num[len] = '\0';
-      } else
-        return 0;
-    }
-  }
-
-  if (len)
-    ans += atoi(num);
-
-  return time(0) + ans;
-}
-
-#ifdef USESCRIPTS
-// Returns a String from an SCM argument
-String
-Utils::scm2String(SCM s)
-{
-  char *tmp = gh_scm2newstr(s, 0);
-  String temp(tmp);
-  free(tmp);
-  return temp;
-}
-
-// Returns a SCM from an String argument
-SCM
-Utils::string2SCM(String s)
-{
-  return gh_str02scm((char *)(const char *)s);
-}
-#endif
+// Utils.C  -*- C++ -*-
+// Copyright (c) 1997, 1998 Etienne BERNARD
+// Copyright (c) 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
+// the Free Software Foundation; either version 2 of the License, or
+// any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// 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.
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <cctype>
+#include <cstdlib>
+#include <string>
+#include <sstream>
+
+#include "Utils.H"
+#include "StringTokenizer.H"
+
+std::string
+Utils::get_nick (std::string nuh)
+{
+  StringTokenizer st(nuh);
+  return st.next_token('!');
+}
+
+std::string
+Utils::get_userhost (std::string nuh)
+{
+  StringTokenizer st(nuh);
+  st.next_token('@');
+  return st.rest();
+}
+
+std::string
+Utils::get_key()
+{
+  return long2str (std::rand());
+}
+
+bool
+Utils::IP_p (std::string host)
+{
+  for (int i = 0; i < host.length(); i++)
+    if (!std::isdigit (host[i]) && host[i] !='.')
+      return false;
+  return true;
+}
+
+std::string
+Utils::make_wildcard (std::string mask)
+{
+  StringTokenizer st (mask);
+
+  st.next_token('!', true);
+  std::string nick = "*";
+
+  std::string user = st.next_token('@', true);
+  if (user[0] == '~' || user[0] == '^' ||
+      user[0] == '+' || user[0] == '-' ||
+      user[0] == '*')
+    user = user.substr (1);
+  if (user.length() < 10)
+    user = std::string("*") + user;
+
+  std::string host = st.rest();
+  StringTokenizer st2(host);
+
+  if (!wildcard_p (host))
+    {
+      if (IP_p (host))
+       {
+         host = st2.next_token('.') + ".";
+         host = host + st2.next_token('.') + ".";
+         host = host + st2.next_token('.') + ".*";
+       } 
+      else 
+       {
+         st2.next_token('.', true);
+         if (st2.count_tokens('.') > 1)
+           host = std::string("*.") + st2.rest();
+       }
+    } 
+  else
+    {
+      if (host == "") host = "*";
+    }
+
+  std::cout << nick + "!" + user + "@" + host << std::endl;
+  
+  return nick + "!" + user + "@" + host;
+}
+
+bool
+Utils::channel_p(std::string c)
+{
+  return (c[0] == '#' || c[0] == '&');
+}
+
+bool
+Utils::wildcard_p (std::string c)
+{
+  return (c.find('*') != std::string::npos);
+}
+
+bool
+Utils::valid_channel_name_p (std::string c)
+{
+  return channel_p (c) && c.find(',') == std::string::npos;
+}
+
+#define isvalid(c) (((c) >= 'A' && (c) <= '~') || std::isdigit(c) || (c) == '-')
+
+bool
+Utils::valid_nickname_p (std::string n)
+{
+  // FIXME: make max nick length configurable
+  if (n[0] == '-' || std::isdigit(n[0]) || n.length() > 9)
+    return false;
+
+  for (int i = 0; i < n.length(); i++)
+    if (!isvalid(n[i]) || std::isspace (n[i]))
+      return false;
+
+  return true;
+}
+
+int
+Utils::get_level (Bot * b, std::string nuh)
+{
+  return b->userList->getMaxLevel(nuh);
+}
+
+int
+Utils::get_level (Bot * b, std::string nuh, std::string channel)
+{
+  if (!channel_p (channel))
+    return get_level(b, nuh);
+
+  if (Channel * c =  b->channelList->getChannel(channel))
+    {
+      User * u = c->getUser(get_nick (nuh));
+      if (u)
+       return u->getLevel();
+    } 
+  else {
+    return -1;
+  }
+
+  return b->userList->getLevel(nuh, channel);
+}
+
+std::string
+Utils::level2str(int l)
+{
+  switch (l)
+    {
+    case User::USER: return "User";
+    case User::TRUSTED_USER: return "Trusted User";
+    case User::FRIEND: return "Friend";
+    case User::MASTER: return "Master";
+    }
+
+  return "None";
+}
+
+std::string
+Utils::prot2str(int p)
+{
+  switch (p)
+    {
+    case User::NO_BAN: return "No ban";
+    case User::NO_KICK: return "No kick";
+    case User::NO_DEOP: return "No deop";
+    }
+
+  return "None";
+}
+
+std::string
+Utils::bool2str(bool b)
+{
+  // FIXME: should these be lowercase?
+  return b ? "True" : "False";
+}
+
+std::string
+Utils::long2str (long l)
+{
+  std::ostringstream temp;
+  temp << l;
+  
+  return temp.str ();
+}
+
+time_t
+Utils::str2time(std::string str)
+{
+  std::string num;
+  time_t ans = 0;
+  
+  // Make sure that str is nominally valid before allocating a buffer
+  if (to_lower (str) == "inf")
+    return -1;
+  
+  if (!std::isdigit (str[0]))
+    return 0;
+
+  num.reserve (512); // reverse a buffer to speed things up
+  
+  for (int i = 0; i < str.length(); i++)
+    {
+      switch (str[i])
+       {
+       case 'y':
+       case 'Y':
+         ans += (std::atoi (num.c_str ()) * 31557600);
+         num.clear ();
+         break;
+       case 'M':
+         ans += (std::atoi (num.c_str ()) * 2629800);
+         num.clear ();
+         break;
+       case 'd':
+       case 'D':
+         ans += (std::atoi (num.c_str ()) * 86400);
+         num.clear ();
+         break;
+       case 'h':
+       case 'H':
+         ans += (std::atoi (num.c_str ()) * 3600);
+         num.clear ();
+         break;
+       case 'm':
+         ans += (std::atoi (num.c_str ()) * 60);
+         num.clear ();
+         break;
+       case 's':
+       case 'S':
+         ans += std::atoi (num.c_str ());
+         num.clear ();
+       default:
+         if (std::isdigit(str[i])) 
+           num += str[i];
+         else
+           return 0;
+       }
+    }
+  
+  if (!num.empty ())
+    ans += std::atoi (num.c_str ());
+  
+  return std::time (0) + ans;
+}
+
+std::string
+Utils::to_lower (std::string s)
+{
+  std::string::iterator it;
+
+  for (it = s.begin (); it != s.end (); ++it)
+    *it = std::tolower (*it);
+
+  return s;
+}
+
+std::string
+Utils::to_upper (std::string s)
+{
+  std::string::iterator it;
+
+  for (it = s.begin (); it != s.end (); ++it)
+    *it = std::toupper (*it);
+
+  return s;
+}
+
+std::string
+Utils::trim_str (std::string s)
+{
+  int i = 0, j = s.length () - 1;
+
+  while (i < j && std::isspace (s[i]))
+    i++;
+  
+  while (j > 0 && std::isspace (s[j]))
+    j--;
+  
+  return s.substr (i, j);
+}
+
+#ifdef USESCRIPTS
+// Returns a std::string from an SCM argument
+std::string
+Utils::scm2str (SCM s)
+{
+  // FIXME: uses gh_, replace with scm_
+  char *tmp = gh_scm2newstr(s, 0);
+  std::string temp (tmp);
+
+  free(tmp);
+
+  return temp;
+}
+
+// Returns a SCM from an std::string argument
+SCM
+Utils::str2scm (std::string s)
+{
+  return gh_str02scm (s.c_str ());
+}
+#endif
index 0115847..bfc4e57 100644 (file)
@@ -1,6 +1,6 @@
 // Utils.H  -*- 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
@@ -24,7 +24,8 @@
 #endif
 
 #include <ctime>
-#include "String.H"
+#include <string>
+
 #include "Bot.H"
 
 #ifdef USESCRIPTS
 
 class Utils {
 public:
-  static String getNick(String);
-  static String getUserhost(String);
-  static String getKey();
-  static String makeWildcard(String);
+  static std::string get_nick (std::string);
+  static std::string get_userhost (std::string);
+  static std::string get_key();
+
+  static int get_level (Bot *, std::string);
+  static int get_level (Bot *, std::string, std::string);
+
+  static std::string make_wildcard (std::string);
+
+  // predicates
+  static bool channel_p (std::string);
+  static bool wildcard_p (std::string);
+  static bool valid_channel_name_p (std::string);
+  static bool valid_nickname_p (std::string);
+  static bool IP_p (std::string);
 
-  static bool isChannel(String);
-  static bool isWildcard(String);
-  static bool isValidChannelName(String);
-  static bool isValidNickName(String);
-  static bool isIP(String);
+  static std::string level2str (int);
+  static std::string prot2str (int);
+  static std::string bool2str (bool);
+  static std::string long2str (long);
 
-  static int getLevel(Bot *, String);
-  static int getLevel(Bot *, String, String);
+  static std::time_t str2time(std::string);
 
-  static String levelToStr(int);
-  static String protToStr(int);
-  static String boolToStr(bool);
+  // string case conversion
+  static std::string to_lower (std::string);
+  static std::string to_upper (std::string);
 
-  static std::time_t strToTime(String);
+  static std::string trim_str (std::string);
 
 #ifdef USESCRIPTS
-  static String scm2String(SCM);
-  static SCM string2SCM(String);
+  static std::string scm2str (SCM);
+  static SCM str2scm (std::string);
 #endif
 };