[[project @ 2005-06-01 00:27:44 by unknown_lamer] unknown_lamer**20050601002744 Fixed bug in Parser that would put two entries for the bot into the userlist, fixed the formatting of a few files, and replaced some Strings with std::strings ] { hunk ./BUGS 3 + +FIXED: hunk ./ChangeLog 2 + + * source/UserList.C (save): Remove workaround for BUG #2 + + * source/Parser.C (parse001): make realNick lowercase when doing + the comparison to bot->nickName to prevent pushing a second copy + of the bot onto the userlist (closes BUG #2) + + * source/Bot.C (Bot): cleaned up constructor + (waitForInput): replaced gh_list with scm_list_n + + * source/UserList.C: Cleaned up some formatting + + * source/Main.C: Formatted code more cleanly + (real_main): changed a few Strings to std::strings hunk ./TODO 6 +* Compile without warnings hunk ./TODO 9 -* Compile without warnings hunk ./source/Bot.C 112 - if (initFile) { - String temp, alias, command; - int line = 0; - while (initFile >> temp, temp.length() != 0) { - line++; - StringTokenizer st(temp); - temp = Utils::trim_str (temp); - if (temp[(unsigned int)0]=='#') continue; - if (st.count_tokens (' ') != 2) { - std::cerr << "Error when reading alias file (" << initFileName - << ") line " << line << "...\n"; - continue; - } - alias = Utils::to_upper (st.next_token()); - command = Utils::to_upper (st.next_token()); + if (initFile) + { + // FIXME: these variables are current String instead of + // std::string because String>> reads an entire line. This code + // needs to be rewritten to use std::string and std::getline (or + // better yet, be removed entirely once BotConfig is in place) + String temp, alias, command; + int line = 0; hunk ./source/Bot.C 121 - // Does the function already exist ? - if (!userFunctions[alias]) + while (initFile >> temp, temp.length() != 0) hunk ./source/Bot.C 123 - if (userFunction *u = userFunctions[command]) - userFunctions[alias] = - new - userFunction(u->function, - u->minLevel, - u->needsChannelName); + StringTokenizer st(temp); + + line++; + temp = Utils::trim_str (temp); + + if (temp[0]=='#') + { + continue; + } + + if (st.count_tokens (' ') != 2) + { + std::cerr << "Error when reading alias file (" << initFileName + << ") line " << line << "...\n"; + continue; + } + + alias = Utils::to_upper (st.next_token()); + command = Utils::to_upper (st.next_token()); + + // Does the function already exist ? + if (!userFunctions[alias]) + { + if (userFunction *u = userFunctions[command]) + userFunctions[alias] = + new + userFunction(u->function, + u->minLevel, + u->needsChannelName); + } hunk ./source/Bot.C 155 - } hunk ./source/Bot.C 158 + hunk ./source/Bot.C 402 - // FIXME: uses gh_list + hunk ./source/Bot.C 404 - gh_list(Utils::str2scm (std::string (s)), - SCM_UNDEFINED)); + scm_list_n (Utils::str2scm (std::string (s)), + SCM_UNDEFINED)); hunk ./source/Bot.C 426 - if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::PING_TIME) && !sentPing) { - serverConnection->queue->sendPing("Testing connection"); - sentPing = true; - } + if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + + Bot::PING_TIME) && !sentPing) + { + serverConnection->queue->sendPing("Testing connection"); + sentPing = true; + } hunk ./source/Bot.C 433 - if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::TIMEOUT)) { - sentPing = false; - nextServer(); - } + if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + + Bot::TIMEOUT)) + { + sentPing = false; + nextServer(); + } hunk ./source/Bot.C 529 - d = new DCCChatConnection(this, from->getAddress (), - address, port); + { + d = new DCCChatConnection(this, from->getAddress (), + address, port); + } hunk ./source/Bot.C 534 - return; + { + return; + } hunk ./source/Bot.C 543 + hunk ./source/Commands.C 87 - mask = bot->getUserhost("", who); - if (mask.length() == 0) - return NotFound(who); - } + mask = bot->getUserhost("", who); + if (mask.length() == 0) + { + return NotFound(who); + } + } hunk ./source/Commands.C 97 - return AlreadyInUserlist(mask, maskChannel); + { + return AlreadyInUserlist(mask, maskChannel); + } hunk ./source/DCCManager.C 25 + hunk ./source/DCCManager.C 27 - delete dcc_map[temp]; + { + delete dcc_map[temp]; + } + hunk ./source/Interp.C 212 - interp_init_helper, 0); + interp_init_helper, 0); hunk ./source/Interp.C 231 + hunk ./source/Interp.C 233 - gh_eval_str_with_catch(command, ErrorHandler); + gh_eval_str_with_catch (command, ErrorHandler); + hunk ./source/Main.C 3 -// Copyright (C) 2002 Clinton Ebadi +// Copyright (C) 2002,2005 Clinton Ebadi hunk ./source/Main.C 23 -#include -#include hunk ./source/Main.C 28 +#include hunk ./source/Main.C 32 +#include +#include + hunk ./source/Main.C 43 -Bot *b; + Bot *b; hunk ./source/Main.C 45 -option bot_options[] = -{ - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'v' }, - { "no-background", no_argument, 0, 'b'}, - { "config-file", required_argument, 0, 'f'}, - { "config-dir", required_argument, 0, 'd'}, - { "config", required_argument, 0, 'c'}, - { "sys-config", required_argument, 0, 's'}, - { "user-config", required_argument, 0, 'u'}, - { "debug", no_argument, 0, 'D' } -}; + option bot_options[] = + { + { "help", no_argument, 0, 'h' }, + { "version", no_argument, 0, 'v' }, + { "no-background", no_argument, 0, 'b'}, + { "config-file", required_argument, 0, 'f'}, + { "config-dir", required_argument, 0, 'd'}, + { "config", required_argument, 0, 'c'}, + { "sys-config", required_argument, 0, 's'}, + { "user-config", required_argument, 0, 'u'}, + { "debug", no_argument, 0, 'D' } + }; hunk ./source/Main.C 58 -void sig_hup(int) { - if (b) { - b->userList->read(); - b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, ""); - b->reconnect(); + void sig_hup(int) { + if (b) { + b->userList->read(); + b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, ""); + b->reconnect(); + } hunk ./source/Main.C 65 -} hunk ./source/Main.C 66 -void print_version () -{ - std::cerr << VERSION_STRING << std::endl - << COPYRIGHT_STRING << std::endl - << PACKAGE" comes with ABSOLUTELY NO WARRANTY\n" - << "This is free software, and you are welcome to redistribute it\n" - << "under certain conditions; See the COPYING file for details.\n"; -} -void print_short_help (const char *name) -{ - std::cerr << "Usage: " - << name - << " [--help] [--version] [--no-background]\n\t" - << "[--config-file file] [--config-dir dir] [--debug]\n\t" - << "[--config dir-under-configpath]\n\t" - << "[--sys-config dir-in-sysconfdir]\n\t" - << "[--user-config dir-userdir] [--debug]\n" - << "\n--help shows long help.\n"; -} + void print_version () + { + std::cerr << VERSION_STRING << std::endl + << COPYRIGHT_STRING << std::endl + << PACKAGE" comes with ABSOLUTELY NO WARRANTY\n" + << "This is free software, and you are welcome to redistribute it\n" + << "under certain conditions; See the COPYING file for details.\n"; + } + void print_short_help (const char *name) + { + std::cerr << "Usage: " + << name + << " [--help] [--version] [--no-background]\n\t" + << "[--config-file file] [--config-dir dir] [--debug]\n\t" + << "[--config dir-under-configpath]\n\t" + << "[--sys-config dir-in-sysconfdir]\n\t" + << "[--user-config dir-userdir] [--debug]\n" + << "\n--help shows long help.\n"; + } hunk ./source/Main.C 86 -void print_long_help (const char *name) -{ - std::cerr << "Long Help for " << PACKAGE << std::endl; - std::cerr << - "The manual (info bobot++) will contain the best information on general\n" - "usage of Bobot++. Here is a detailed summary of the command line\n" - "arguments: (in long arg short arg format). All args are optional.\n"; - print_short_help (name); - std::cerr << -"[--help][-h] Shows this help and exits\n" -"[--version][-v] Shows version information and exits\n" -"[--no-background][-b] Run bobot++ in the foreground\n" -"[--config-file file][-f] Use file instead of bot.conf\n" -"[--config-dir dir][-d] Use dir as dir to load config file from\n" -"[--config dir][-c] Search your config path (defaults to\n" -" " - << getenv ("HOME") - << "/.bobotpp/config/ and then\n" - << -" /etc/bobotpp/) for dir and\n" -" then loads your config data using dir\n" -"[--sys-config dir][-s] Looks for config in /etc/bobotpp/dir. Note\n" -" that the user dir is still searched first\n" -"[--user-config dir][-u] Looks for config in\n" -" " - << getenv("HOME") - << "/.bobotpp/config/dir/.\n" - << -" Note that\n" -" the system dir is still searched after this if\n" -" dir is not found.\n" -"[--debug][-D] Makes Bobot++ print debugging info and run in\n" -" the foreground" - << std::endl - << std::endl - << "The default configuration is read from\n" - << getenv("HOME") - << "/.bobotpp/config/default/ and then\n" - "/etc/bobotpp/default/ if the user config is not found.\n"; -} + void print_long_help (const char *name) + { + std::cerr << "Long Help for " << PACKAGE << std::endl; + std::cerr << + "The manual (info bobot++) will contain the best information on general\n" + "usage of Bobot++. Here is a detailed summary of the command line\n" + "arguments: (in long arg short arg format). All args are optional.\n"; + print_short_help (name); + std::cerr << + "[--help][-h] Shows this help and exits\n" + "[--version][-v] Shows version information and exits\n" + "[--no-background][-b] Run bobot++ in the foreground\n" + "[--config-file file][-f] Use file instead of bot.conf\n" + "[--config-dir dir][-d] Use dir as dir to load config file from\n" + "[--config dir][-c] Search your config path (defaults to\n" + " " + << getenv ("HOME") + << "/.bobotpp/config/ and then\n" + << + " /etc/bobotpp/) for dir and\n" + " then loads your config data using dir\n" + "[--sys-config dir][-s] Looks for config in /etc/bobotpp/dir. Note\n" + " that the user dir is still searched first\n" + "[--user-config dir][-u] Looks for config in\n" + " " + << getenv("HOME") + << "/.bobotpp/config/dir/.\n" + << + " Note that\n" + " the system dir is still searched after this if\n" + " dir is not found.\n" + "[--debug][-D] Makes Bobot++ print debugging info and run in\n" + " the foreground" + << std::endl + << std::endl + << "The default configuration is read from\n" + << getenv("HOME") + << "/.bobotpp/config/default/ and then\n" + "/etc/bobotpp/default/ if the user config is not found.\n"; + } hunk ./source/Main.C 127 -static void real_main(void* DONOTUSE, int argc, char **argv) -{ - // FIXME: User directory - int opt; - bool background = true; - String configFile = "bot.conf"; - String cmd_directory = ""; - String sys_directory = "/etc/bobotpp/"; - String sys_subdir = "default"; - String user_directory = String(getenv ("HOME")) + "/.bobotpp/config/"; - String user_subdir = "default"; - bool debug = false; + static void real_main(void* DONOTUSE, int argc, char **argv) + { + // FIXME: User directory + int opt; + bool background = true; + std::string configFile = "bot.conf"; + std::string cmd_directory = ""; + std::string sys_directory = "/etc/bobotpp/"; + std::string sys_subdir = "default"; + std::string user_directory = + std::string (getenv ("HOME")) + "/.bobotpp/config/"; + String user_subdir = "default"; + bool debug = false; hunk ./source/Main.C 141 - std::signal(SIGPIPE, SIG_IGN); - std::signal(SIGALRM, SIG_IGN); - std::signal(SIGHUP, sig_hup); + std::signal(SIGPIPE, SIG_IGN); + std::signal(SIGALRM, SIG_IGN); + std::signal(SIGHUP, sig_hup); hunk ./source/Main.C 145 - // We parse the command line options - while ((opt = getopt_long (argc,argv,"vhbf:d:c:D", bot_options, 0)) - != -1) - switch (opt) { - case 'h': - print_long_help (argv[0]); - exit(0); - break; - case 'v': - print_version (); - exit (0); - break; - case 'b': - background = false; - break; - case 'f': - configFile = optarg; - break; - case 'd': - cmd_directory = optarg; - break; - case 'c': - sys_subdir = optarg; - user_subdir = optarg; - break; - case 'u': - user_subdir = optarg; - break; - case 's': - sys_subdir = optarg; - break; - case 'D': - debug = true; - break; - default: - print_short_help (argv[0]); - std::exit(1); - } + // We parse the command line options + while ((opt = getopt_long (argc,argv,"vhbf:d:c:D", bot_options, 0)) + != -1) + { + switch (opt) + { + case 'h': + print_long_help (argv[0]); + exit(0); + break; + case 'v': + print_version (); + exit (0); + break; + case 'b': + background = false; + break; + case 'f': + configFile = optarg; + break; + case 'd': + cmd_directory = optarg; + break; + case 'c': + sys_subdir = optarg; + user_subdir = optarg; + break; + case 'u': + user_subdir = optarg; + break; + case 's': + sys_subdir = optarg; + break; + case 'D': + debug = true; + break; + default: + print_short_help (argv[0]); + std::exit(1); + } + } hunk ./source/Main.C 187 - DIR * temp; - if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs"))) - mkdir (String(getenv ("HOME")) + "/.bobotpp/logs", - S_IRWXU); - else - closedir (temp); + DIR * temp; + + if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs"))) + { + mkdir (String(getenv ("HOME")) + "/.bobotpp/logs", + S_IRWXU); + } + else + { + closedir (temp); + } hunk ./source/Main.C 199 - if (!cmd_directory.length ()) - { - if (chdir(user_directory + user_subdir) < 0) - if (chdir(sys_directory + sys_subdir) < 0) + if (!cmd_directory.length ()) + { + if (chdir((user_directory + user_subdir).c_str ()) < 0) hunk ./source/Main.C 203 - std::cerr << "Dirs don't exist! Exiting\n"; - std::exit (2); // no execution + if (chdir ((sys_directory + sys_subdir).c_str ()) < 0) + { + std::cerr << "Dirs don't exist! Exiting\n"; + std::exit (2); // no execution + } hunk ./source/Main.C 209 - } - else - if (chdir(cmd_directory) < 0) + } + else hunk ./source/Main.C 212 - std::perror("Error: "); - std::cerr << "Exiting...\n"; - std::exit (2); + if (chdir (cmd_directory.c_str ()) < 0) + { + std::perror("Error: "); + std::cerr << "Exiting...\n"; + std::exit (2); + } hunk ./source/Main.C 220 - // std::cout << COPYRIGHT_STRING << - // "\n"PACKAGE" comes with ABSOLUTELY NO WARRANTY\n" - // "This is free software, and you are welcome to redistribute it\n" - // "under certain conditions; See the COPYING file for details.\n"; - print_version (); + print_version (); hunk ./source/Main.C 222 - // initialize the Parser - Parser::init (); + // initialize the Parser + Parser::init (); hunk ./source/Main.C 225 - if (!debug) { - if (background) - switch (fork()) { - case -1: - std::cout << "Could not run in the background. Exiting...\n"; - perror("fork"); - exit(1); - case 0: - break; - default: - std::cout << "Running in the background...\n"; - exit(0); - } - } + if (!debug) { + if (background) + switch (fork()) { + case -1: + std::cout << "Could not run in the background. Exiting...\n"; + perror("fork"); + exit(1); + case 0: + break; + default: + std::cout << "Running in the background...\n"; + exit(0); + } + } hunk ./source/Main.C 241 - Interp::Startup(); + Interp::Startup(); hunk ./source/Main.C 244 - b = new Bot(configFile, debug); - b->run(); - delete b; + b = new Bot(configFile, debug); + b->run(); + delete b; hunk ./source/Main.C 249 - Interp::Shutdown(); + Interp::Shutdown(); hunk ./source/Main.C 251 -} + } hunk ./source/Parser.C 116 - if ((cnx->bot->nickName).toLower () != realNick) + if ((cnx->bot->nickName).toLower () != realNick.toLower ()) hunk ./source/UserList.C 46 - if (!file) { - std::cerr << "I cannot find the file " << listFilename << std::endl; - return; - } - - while (file >> temp, temp.length() != 0) { - StringTokenizer st(temp); - if (st.count_tokens(':') != 7) { - std::cerr << "Error when reading userlist (" << listFilename << - ") line " << line << "...\n"; + if (!file) + { + std::cerr << "I cannot find the file " << listFilename << std::endl; hunk ./source/UserList.C 51 - String mask = st.next_token(':'); - String maskChannel = st.next_token(':'); - String level = st.next_token(':'); - String prot = st.next_token(':'); - String aop = st.next_token(':'); - String expiration = st.next_token(':'); - String password = Utils::trim_str (st.rest()); - if (password == "*NONE*") - password = ""; - l.push_back(new UserListItem(mask, maskChannel, atoi(level), - atoi(prot), atoi(aop), - atol(expiration), password)); - line++; - } + + while (file >> temp, temp.length() != 0) + { + StringTokenizer st(temp); + + if (st.count_tokens(':') != 7) + { + std::cerr << "Error when reading userlist (" << listFilename << + ") line " << line << "...\n"; + return; + } + + String mask = st.next_token(':'); + String maskChannel = st.next_token(':'); + String level = st.next_token(':'); + String prot = st.next_token(':'); + String aop = st.next_token(':'); + String expiration = st.next_token(':'); + String password = Utils::trim_str (st.rest()); + + if (password == "*NONE*") + { + password = ""; + } + + l.push_back(new UserListItem(mask, maskChannel, atoi(level), + atoi(prot), atoi(aop), + atol(expiration), password)); + line++; + } + hunk ./source/UserList.C 94 - // FIXME: fix bug (see BUGS) and inc once - ++it; ++it; // We skip the bot's entry + ++it; // Skip the bot's entry + hunk ./source/UserList.C 97 - if ((*it)->isStillValid()) { - file << (*it)->mask.getMask() << ":" - << (*it)->channelMask.getMask() << ":" - << (*it)->level << ":" - << (*it)->prot << ":" - << (*it)->aop << ":" - << (*it)->expirationDate << ":"; - if ((*it)->passwd == "") - file << "*NONE*"; - else - file << (*it)->passwd; - file << std::endl; + { + if ((*it)->isStillValid()) + { + file << (*it)->mask.getMask() << ":" + << (*it)->channelMask.getMask() << ":" + << (*it)->level << ":" + << (*it)->prot << ":" + << (*it)->aop << ":" + << (*it)->expirationDate << ":"; + + if ((*it)->passwd == "") + { + file << "*NONE*"; + } + else + { + file << (*it)->passwd; + } + + file << std::endl; + } hunk ./source/UserList.C 126 - while (!l.empty()) { - uli = (*l.begin()); - l.erase(l.begin()); - delete uli; - } + while (!l.empty()) + { + uli = (*l.begin()); + l.erase(l.begin()); + delete uli; + } hunk ./source/UserList.C 168 - if ((*it)->matches(nuh) && level < (*it)->level && - ((*it)->expirationDate == -1 || - (*it)->expirationDate > current_time) && - ((*it)->passwd == "" || (*it)->identified > 0)) - level = (*it)->level; + { + if ((*it)->matches(nuh) && level < (*it)->level + && ((*it)->expirationDate == -1 + || (*it)->expirationDate > current_time) + && ((*it)->passwd == "" + || (*it)->identified > 0)) + { + level = (*it)->level; + } + } }