[project @ 2005-06-28 03:16:45 by unknown_lamer]
[clinton/bobotpp.git] / source / Parser.C
index 9be4f08..9ea7733 100644 (file)
@@ -1,6 +1,6 @@
 // Parser.C  -*- 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
@@ -14,7 +14,7 @@
 
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -79,21 +79,31 @@ 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])
-    temp_func (cnx, from, rest);
+  // We must use map<>::find or else a new entry will be created in
+  // the map which will cause another lookup of the same invalid
+  // command to segfault the bot
+  std::map<std::string, fptr, std::less<std::string> >::const_iterator cit 
+    = functions.find (command);
+
+  if (cit != functions.end ())
+    {
+      fptr temp_func = cit->second;
+      temp_func (cnx, from, rest);
+    }
+
   delete from;
 }
 
@@ -102,8 +112,8 @@ Parser::parse001 (ServerConnection * cnx, Person * from, String rest)
 {
   String temp = "";
   StringTokenizer st (rest);
-  String realNick = st.nextToken ();
-  if ((cnx->bot->nickName).toLower () != realNick)
+  String realNick = st.next_token ();
+  if ((cnx->bot->nickName).toLower () != realNick.toLower ())
     {
       // Yes, this can happen, and it was a very subtle bug
       cnx->bot->nickName = realNick;
@@ -135,12 +145,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 +161,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 +174,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 +186,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 +197,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 +245,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 +272,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 +282,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 +314,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 +330,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 +351,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 +371,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 +427,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 +441,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 +500,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 +508,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 +534,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 +578,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 +643,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 +653,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 +681,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 +693,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 +710,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 +759,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 +777,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 +807,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,20 +819,22 @@ 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")
     cnx->queue->sendCTCPReply (nick, "PING", rest);
   else if (command == "VERSION")
-    cnx->queue->sendCTCPReply (nick, "VERSION", cnx->bot->versionString);
+    {
+      cnx->queue->sendCTCPReply (nick, "VERSION", cnx->bot->versionString);
+    }
   else if (command == "CLOCK")
     {
       time_t diff = time (NULL) - cnx->bot->startTime;
@@ -844,16 +856,16 @@ 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 ()))
-           cnx->bot->addDCC (from, address, port);
+           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");
        }
@@ -862,16 +874,23 @@ Parser::parseCTCP (ServerConnection * cnx,
   else if (command == "ACTION")
     {
       cnx->bot->botInterp->RunHooks (Hook::ACTION,
+                                    // FIXME: from->getAddress should
+                                    // be nick. MAYBE, depending on
+                                    // whether this could be
+                                    // considered a bug or a feature
+                                    // change to normalize
+                                    // hooks/action with the other
+                                    // hooks. Maybe a 3.0 change?
                                     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,105 +901,114 @@ 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;
-  userFunction * f = cnx->bot->userFunctions[command];
+  std::map<std::string, class userFunction*, 
+    std::less<std::string> >::const_iterator  uf_iter 
+    = cnx->bot->userFunctions.find (command);
+  userFunction * f = 0;
+  
+  if (uf_iter != cnx->bot->userFunctions.end ())
+    f = uf_iter->second;
+  else
+    return;
+  
   if (f)
     {
       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))
-             {
-               from->sendNotice ("\002You need to supply a channel name"
-                                 " for this command\002");
-               return;
-             }
-           if (!cnx->bot->channelList->getChannel (to))
-             {
-               from->sendNotice (String ("\002I am not on channel\002 ") +
-                                 to);
-               return;
-             }
-           level = Utils::getLevel (cnx->bot, from->getAddress (), to);
-           User *u = 0;
-           if (Channel * c = cnx->bot->channelList->getChannel (to))
-             u = c->getUser (from->getNick ());
-           if (!u || !u->userListItem)
-             identified = true;
-           else
-             identified = u->userListItem->passwd == ""
-               || u->userListItem->identified > 0;
-         }
-       else
-         {
-           level = Utils::getLevel (cnx->bot, from->getAddress ());
+         if (!Utils::channel_p (to))
+           {
+             from->sendNotice ("\002You need to supply a channel name"
+                               " for this command\002");
+             return;
+           }
+         if (!cnx->bot->channelList->getChannel (to))
+           {
+             from->sendNotice (String ("\002I am not on channel\002 ") +
+                               to);
+             return;
+           }
+         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 ());
+         if (!u || !u->userListItem)
            identified = true;
-         }
-       if (level >= f->minLevel)
-         {
-           cnx->bot->logLine (from->getAddress () + " did " + command +
-                              " " + rest);
+         else
+           identified = u->userListItem->passwd == ""
+             || u->userListItem->identified > 0;
+       }
+      else
+           {
+             level = Utils::get_level (cnx->bot, from->getAddress ());
+             identified = true;
+           }
+      if (level >= f->minLevel)
+       {
+         cnx->bot->logLine (from->getAddress () + " did " + command +
+                            " " + rest);
 #ifdef USESCRIPTS
-           if (f->argsCount != -1)
-             {
-               Parser::parseScriptFunction (cnx, to, f->needsChannelName,
-                                            f->scmFunc, f->argsCount,
-                                            rest);
-             }
-           else
-             {
-               f->function (cnx, from, to, rest);
-             }
+         if (f->argsCount != -1)
+           {
+             Parser::parseScriptFunction (cnx, to, f->needsChannelName,
+                                          f->scmFunc, f->argsCount,
+                                          rest);
+           }
+         else
+           {
+             f->function (cnx, from, to, rest);
+           }
 #else
-           f->function (cnx, from, to, rest);
+         f->function (cnx, from, to, rest);
 #endif
-         }
-       else
-         {
-           if (!identified)
-             from->
-               sendNotice (String
-                           ("\002You are not identified on channel\002 ") +
-                           to);
-         }
-      }
+       }
+      else
+       {
+         if (!identified)
+           from->
+             sendNotice (String
+                         ("\002You are not identified on channel\002 ") +
+                         to);
+       }
+    }
 }
 
 #ifdef USESCRIPTS
@@ -996,7 +1024,7 @@ Parser::parseScriptFunction (ServerConnection * cnx,
     {
       args_list = gh_append2 (args_list,
                              scm_listify (Utils::
-                                          string2SCM (channel),
+                                          str2scm (channel),
                                           SCM_UNDEFINED));
       argsCount--;
     }
@@ -1007,9 +1035,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));
     }