+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)
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
// 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
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])
}
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;
<< " 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);
}
}
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 {
{
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
// 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
#include "BotConfig.H"
#include "Bot.H"
#include "StringTokenizer.H"
+#include "Utils.H"
#include <iostream>
#include <string>
#include <list>
: config_filename (cf)
{ }
-bool BotConfig::read_config ()
+bool
+BotConfig::read_config ()
{
std::ifstream config_file (config_filename.c_str ());
std::string current_line;
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);
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;
};
}
-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);
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;
+}
// 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
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>
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
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);
}
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));
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;
// 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
{
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());
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);
String(""));
break;
case 'o':
- n = st.nextToken();
+ n = st.next_token();
u = getUser(n);
if (joined)
sign == '+' ? countOp++ : countOp--;
}
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 =
// 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
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);
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);
}
String dest;
- if (!Utils::isWildcard(who))
+ if (!Utils::wildcard_p(who))
dest = bot->getUserhost(channel, who);
else
dest = 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();
String dest;
- if (!Utils::isWildcard(who))
+ if (!Utils::wildcard_p(who))
dest = bot->getUserhost(channel, who);
else
dest = 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();
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))
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))
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);
{
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.
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();
if (who == "")
return EmptyAddressee;
- if (Utils::isChannel(who))
+ if (Utils::channel_p(who))
return NotToChannel;
if (message == "")
{
CHECK_CONNECTION;
- if (nick == "" || !Utils::isValidNickName(nick))
+ if (nick == "" || !Utils::valid_nickname_p(nick))
return InvalidNick(nick);
bot->wantedNickName = nick;
if (who == "")
return EmptyAddressee;
- if (Utils::isChannel(who))
+ if (Utils::channel_p(who))
return NotToChannel;
if (message == "")
if (!bot->iAmOp(channel))
return NotChannelOp(channel);
- if (Utils::isWildcard(who))
+ if (Utils::wildcard_p(who))
return MassOpNotAllowed;
User *u = c->getUser(who);
String dest;
- if (!Utils::isWildcard(who))
+ if (!Utils::wildcard_p(who))
dest = bot->getUserhost(channel, who);
else
dest = who;
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();
// 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
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");
bot->botInterp->RunHooks (Hook::DCC_CHAT_BEGIN,
from->getAddress (),
scm_list_n (Utils::
- string2SCM (from->getAddress ()),
+ str2scm (from->getAddress ()),
SCM_UNDEFINED));
#endif
// 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
// 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,
// 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
#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])
{
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
{
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
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;
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;
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 ());
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])
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);
}
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;
}
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];
&& 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
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
{
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) !=
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++)
&& !(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);
}
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)
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)
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)
{
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)
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) &&
{
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)
#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) +
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)
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)
{
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 ())
#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)
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)
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 = "";
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")
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");
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
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*,
{
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");
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 ());
}
else
{
- level = Utils::getLevel (cnx->bot, from->getAddress ());
+ level = Utils::get_level (cnx->bot, from->getAddress ());
identified = true;
}
if (level >= f->minLevel)
{
args_list = gh_append2 (args_list,
scm_listify (Utils::
- string2SCM (channel),
+ str2scm (channel),
SCM_UNDEFINED));
argsCount--;
}
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));
}
// 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
String
Person::getNick() const
{
- return Utils::getNick(address);
+ return Utils::get_nick (address);
}
String
// 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
{
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());
}
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;
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;
}
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());
}
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;
else
{
VERIFY_STRING (expiration);
- expire = Utils::strToTime (Utils::scm2String (expiration));
+ expire = Utils::str2time (Utils::scm2str (expiration));
if (!expire) expire = -1;
}
if (SCM_UNBNDP (reason))
else
{
VERIFY_STRING (reason);
- rreason = Utils::scm2String (reason);
+ rreason = Utils::scm2str (reason);
}
Message m = Commands::AddShit (Interp::bot, mmask, mmaskChannel,
llevel, expire, rreason);
{
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());
}
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());
}
{
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());
}
{
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());
}
{
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());
}
{
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());
}
{
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());
}
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());
}
{
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());
}
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());
}
{
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());
}
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());
}
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());
}
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());
}
{
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());
}
{
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());
}
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());
}
{
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());
}
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());
}
{
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());
}
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());
}
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());
}
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());
}
{
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());
}
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
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);
}
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;
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;
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;
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));
{
return SCM_BOOL (Interp::bot->dccConnections->sendMessage
- (Utils::scm2String (to),
- Utils::scm2String (message)));
+ (Utils::scm2str (to),
+ Utils::scm2str (message)));
}
// Message sending
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
// 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
MNICK + " " + to +
" " + message,
scm_listify (Utils::
- string2SCM (MNICK),
+ str2scm (MNICK),
Utils::
- string2SCM (to),
+ str2scm (to),
Utils::
- string2SCM (message),
+ str2scm (message),
SCM_UNDEFINED));
}
else
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
// 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
}
// 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
channel(c), mode(m), parameters(p)
{
StringTokenizer st(p);
- paramcount = st.countTokens();
+ paramcount = st.count_tokens();
}
bool
// 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
#include "ShitList.H"
#include "StringTokenizer.H"
+#include "Utils.H"
ShitList::ShitList(String filename)
: listFileName(filename)
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++;
// 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
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()
{
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);
// 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
String subString(int);
String subString(int, int);
+
+ String substr(int);
+ String substr(int, int);
String toLower();
String toUpper();
// 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;
}
bool
-StringTokenizer::hasMoreTokens(char c)
+StringTokenizer::more_tokens_p (char c)
{
if (pos == st.length())
return false;
}
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;
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);
}
// 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
// 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
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 == "") {
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)) {
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;
}
if (a != 0 && a != 1)
return;
- e = Utils::strToTime(expiration);
+ e = Utils::str2time(expiration);
if (!e)
e = -1;
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 ());
}
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);
}
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");
*/
/*
- 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);
if (l < 0 || l > ShitEntry::SHIT_NODEBAN)
return;
- e = Utils::strToTime(expiration);
+ e = Utils::str2time(expiration);
if (!e)
e = -1;
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");
// 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);
// 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;
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)) {
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)) {
{
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;
}
StringTokenizer st(rest);
- String command = st.nextToken().toUpper();
+ String command = Utils::to_upper (st.next_token());
std::ifstream helpFile(cnx->bot->helpFileName);
if (!helpFile) {
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;
}
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;
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();
{
StringTokenizer st(rest);
- Ban(cnx, 0, channel, st.nextToken());
+ Ban(cnx, 0, channel, st.next_token());
Kick(cnx, from, channel, rest);
}
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);
{
// 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;
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 ") +
return;
}
- if (Utils::isWildcard(rest)) {
+ if (Utils::wildcard_p(rest)) {
from->sendNotice("\002Mass op is not allowed.\002");
return;
}
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 == "") {
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)
return;
}
- if (!Utils::isWildcard(who))
+ if (!Utils::wildcard_p(who))
dest = cnx->bot->getUserhost(channel, who);
else
dest = who;
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();
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());
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");
}
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 ") +
}
StringTokenizer st(rest);
- String otherNick = st.nextToken();
+ String otherNick = st.next_token();
User * u = cnx->bot->channelList->getChannel(channel)->getUser(otherNick);
UserListItem * uli;
" \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 " +
// 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
#include "UserList.H"
#include "StringTokenizer.H"
+#include "Utils.H"
UserList::UserList(String filename)
: listFilename(filename)
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),
-// 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
// 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
#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
};