From 0316e2c1fb71c53b1299badab997a6f24fefa39e Mon Sep 17 00:00:00 2001 From: unknown_lamer Date: Wed, 1 Jun 2005 00:27:44 +0000 Subject: [PATCH] [project @ 2005-06-01 00:27:44 by unknown_lamer] 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 --- BUGS | 2 + ChangeLog | 14 ++ TODO | 2 +- source/Bot.C | 103 +++++---- source/Commands.C | 14 +- source/DCCManager.C | 6 +- source/Interp.C | 6 +- source/Main.C | 517 ++++++++++++++++++++++---------------------- source/Parser.C | 2 +- source/UserList.C | 121 +++++++---- 10 files changed, 437 insertions(+), 350 deletions(-) rewrite source/Main.C (79%) diff --git a/BUGS b/BUGS index 1f40990..e46f033 100644 --- a/BUGS +++ b/BUGS @@ -1,5 +1,7 @@ Known Bugs (-*- text -*-) [import these into the savannah bug tracker] + +FIXED: 2 - A really wierd thing is happening--the bot is adding _two_ copies of its own record to the UserList. The "real" one is at the front of the list, but there is a still a "fake" one behind that one. I diff --git a/ChangeLog b/ChangeLog index 3edeebc..e266572 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2005-05-31 Clinton Ebadi + * 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 + * source/String.C (operator): Made index signed again, it's not worth fixing this warning diff --git a/TODO b/TODO index 08b342d..1250161 100644 --- a/TODO +++ b/TODO @@ -3,9 +3,9 @@ Done: * Lots of hooks related stuff that I never wrote down * Abstract DCC support so that DCC FILE may be easily implemented * Wrote config database class +* Compile without warnings 2.2: -* Compile without warnings * Finish Texinfo manual * Utils::valid_nickname_p should have a configurable max nick length (now that most networks allow for longer than nine character diff --git a/source/Bot.C b/source/Bot.C index c3a83a1..9c67822 100644 --- a/source/Bot.C +++ b/source/Bot.C @@ -109,37 +109,53 @@ Bot::Bot(String filename, bool debug_on) // Let's read the alias file std::ifstream initFile(initFileName); - 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()); - - // Does the function already exist ? - if (!userFunctions[alias]) + 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; + + while (initFile >> temp, temp.length() != 0) { - 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); + } } } - } std::srand (std::time (0)); // srand for bot-random + #ifdef USESCRIPTS botInterp = new BotInterp(this, logs_dir + scriptLogFileName); botInterp->LoadScript(autoexecFileName); @@ -383,10 +399,10 @@ Bot::waitForInput() { char s[6]; std::sprintf(s, "%2d:%2d", thisTime->tm_hour, thisTime->tm_min); - // FIXME: uses gh_list + botInterp->RunHooks(Hook::TIMER, String(s), - gh_list(Utils::str2scm (std::string (s)), - SCM_UNDEFINED)); + scm_list_n (Utils::str2scm (std::string (s)), + SCM_UNDEFINED)); } #endif @@ -407,15 +423,19 @@ Bot::waitForInput() serverConnection->queue->sendJoin((*it).first, (*it).second->key); } - 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; + } - if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::TIMEOUT)) { - sentPing = false; - nextServer(); - } + if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + + Bot::TIMEOUT)) + { + sentPing = false; + nextServer(); + } } // We can change server if we will not lose op on a channel @@ -506,16 +526,21 @@ Bot::addDCC(Person * from, unsigned long address, int port, int type) DCCConnection *d = 0; if (type == CHAT) - d = new DCCChatConnection(this, from->getAddress (), - address, port); + { + d = new DCCChatConnection(this, from->getAddress (), + address, port); + } else - return; + { + return; + } if (!d->connect()) { logLine ("DCC Connection failed from " + from->getAddress ()); return; } + logLine ("DCC CHAT accepted from" + from->getAddress ()); dccConnections->addConnection (d); } diff --git a/source/Commands.C b/source/Commands.C index d007e33..df5711e 100644 --- a/source/Commands.C +++ b/source/Commands.C @@ -84,15 +84,19 @@ Commands::AddUser(Bot *bot, String who, String maskChannel, int level, if (!Utils::wildcard_p(who)) { - mask = bot->getUserhost("", who); - if (mask.length() == 0) - return NotFound(who); - } + mask = bot->getUserhost("", who); + if (mask.length() == 0) + { + return NotFound(who); + } + } // Aha! This was before the brace...segfault gone mask = Utils::make_wildcard(mask); if (bot->userList->isInUserList(mask, maskChannel)) - return AlreadyInUserlist(mask, maskChannel); + { + return AlreadyInUserlist(mask, maskChannel); + } bot->userList->addUser(mask, maskChannel, level, prot, aop, expire, password); diff --git a/source/DCCManager.C b/source/DCCManager.C index 8f51521..ad0c824 100644 --- a/source/DCCManager.C +++ b/source/DCCManager.C @@ -22,8 +22,12 @@ DCCManager::addConnection (DCCConnection *cnx) { DCCPerson *person = new DCCPerson (cnx); String temp = person->getAddress (); + if (dcc_map[temp]) - delete dcc_map[temp]; + { + delete dcc_map[temp]; + } + dcc_map[person->getAddress ()] = person; } diff --git a/source/Interp.C b/source/Interp.C index 2940561..3bd757b 100644 --- a/source/Interp.C +++ b/source/Interp.C @@ -209,7 +209,7 @@ void Interp::Startup() { bot_module = scm_c_define_module ("the-bot-module", - interp_init_helper, 0); + interp_init_helper, 0); scm_c_call_with_current_module (bot_module, interp_post_startup_helper, bot_module); @@ -228,8 +228,10 @@ Interp::Execute(Bot *b, String command) // We get the lock pthread_mutex_lock(&mutex); #endif + bot = b; - gh_eval_str_with_catch(command, ErrorHandler); + gh_eval_str_with_catch (command, ErrorHandler); + #ifdef MULTITHREAD // We release the lock pthread_mutex_unlock(&mutex); diff --git a/source/Main.C b/source/Main.C dissimilarity index 79% index 9bc36f0..c79624a 100644 --- a/source/Main.C +++ b/source/Main.C @@ -1,253 +1,264 @@ -// Main.C -*- C++ -*- -// Copyright (c) 1997, 1998 Etienne BERNARD -// Copyright (C) 2002 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef USESCRIPTS -#include "Interp.H" -#endif - -#include "Bot.H" - -namespace -{ -Bot *b; - -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' } -}; - -void sig_hup(int) { - if (b) { - b->userList->read(); - b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, ""); - b->reconnect(); - } -} - -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_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"; -} - -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; - - std::signal(SIGPIPE, SIG_IGN); - std::signal(SIGALRM, SIG_IGN); - std::signal(SIGHUP, sig_hup); - - // 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); - } - - DIR * temp; - if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs"))) - mkdir (String(getenv ("HOME")) + "/.bobotpp/logs", - S_IRWXU); - else - closedir (temp); - - if (!cmd_directory.length ()) - { - if (chdir(user_directory + user_subdir) < 0) - if (chdir(sys_directory + sys_subdir) < 0) - { - std::cerr << "Dirs don't exist! Exiting\n"; - std::exit (2); // no execution - } - } - else - if (chdir(cmd_directory) < 0) - { - std::perror("Error: "); - std::cerr << "Exiting...\n"; - std::exit (2); - } - - // 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 (); - - // initialize the Parser - Parser::init (); - - 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); - } - } - -#ifdef USESCRIPTS - Interp::Startup(); -#endif - - b = new Bot(configFile, debug); - b->run(); - delete b; - -#ifdef USESCRIPTS - Interp::Shutdown(); -#endif -} - -} // static functions and data - -int main(int argc, char **argv) -{ -#ifdef USESCRIPTS - scm_boot_guile (argc, argv, real_main, 0); -#else - real_main(0, argc, argv); -#endif - - return 0; -} +// Main.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 +// 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef USESCRIPTS +#include "Interp.H" +#endif + +#include "Bot.H" + +namespace +{ + Bot *b; + + 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' } + }; + + void sig_hup(int) { + if (b) { + b->userList->read(); + b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, ""); + b->reconnect(); + } + } + + 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_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"; + } + + 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; + + std::signal(SIGPIPE, SIG_IGN); + std::signal(SIGALRM, SIG_IGN); + std::signal(SIGHUP, sig_hup); + + // 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); + } + } + + DIR * temp; + + if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs"))) + { + mkdir (String(getenv ("HOME")) + "/.bobotpp/logs", + S_IRWXU); + } + else + { + closedir (temp); + } + + if (!cmd_directory.length ()) + { + if (chdir((user_directory + user_subdir).c_str ()) < 0) + { + if (chdir ((sys_directory + sys_subdir).c_str ()) < 0) + { + std::cerr << "Dirs don't exist! Exiting\n"; + std::exit (2); // no execution + } + } + } + else + { + if (chdir (cmd_directory.c_str ()) < 0) + { + std::perror("Error: "); + std::cerr << "Exiting...\n"; + std::exit (2); + } + } + + print_version (); + + // initialize the Parser + Parser::init (); + + 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); + } + } + +#ifdef USESCRIPTS + Interp::Startup(); +#endif + + b = new Bot(configFile, debug); + b->run(); + delete b; + +#ifdef USESCRIPTS + Interp::Shutdown(); +#endif + } + +} // static functions and data + +int main(int argc, char **argv) +{ +#ifdef USESCRIPTS + scm_boot_guile (argc, argv, real_main, 0); +#else + real_main(0, argc, argv); +#endif + + return 0; +} diff --git a/source/Parser.C b/source/Parser.C index 75768e0..122800e 100644 --- a/source/Parser.C +++ b/source/Parser.C @@ -113,7 +113,7 @@ Parser::parse001 (ServerConnection * cnx, Person * from, String rest) String temp = ""; StringTokenizer st (rest); String realNick = st.next_token (); - if ((cnx->bot->nickName).toLower () != realNick) + if ((cnx->bot->nickName).toLower () != realNick.toLower ()) { // Yes, this can happen, and it was a very subtle bug cnx->bot->nickName = realNick; diff --git a/source/UserList.C b/source/UserList.C index b5a795e..b2f75a6 100644 --- a/source/UserList.C +++ b/source/UserList.C @@ -43,32 +43,42 @@ UserList::read() clear(); - if (!file) { - std::cerr << "I cannot find the file " << listFilename << std::endl; - return; - } - - while (file >> temp, temp.length() != 0) { - StringTokenizer st(temp); - if (st.count_tokens(':') != 7) { - std::cerr << "Error when reading userlist (" << listFilename << - ") line " << line << "...\n"; + if (!file) + { + std::cerr << "I cannot find the file " << listFilename << std::endl; return; } - String mask = st.next_token(':'); - String maskChannel = st.next_token(':'); - String level = st.next_token(':'); - String prot = st.next_token(':'); - String aop = st.next_token(':'); - String expiration = st.next_token(':'); - String password = Utils::trim_str (st.rest()); - if (password == "*NONE*") - password = ""; - l.push_back(new UserListItem(mask, maskChannel, atoi(level), - atoi(prot), atoi(aop), - atol(expiration), password)); - line++; - } + + while (file >> temp, temp.length() != 0) + { + StringTokenizer st(temp); + + if (st.count_tokens(':') != 7) + { + std::cerr << "Error when reading userlist (" << listFilename << + ") line " << line << "...\n"; + return; + } + + String mask = st.next_token(':'); + String maskChannel = st.next_token(':'); + String level = st.next_token(':'); + String prot = st.next_token(':'); + String aop = st.next_token(':'); + String expiration = st.next_token(':'); + String password = Utils::trim_str (st.rest()); + + if (password == "*NONE*") + { + password = ""; + } + + l.push_back(new UserListItem(mask, maskChannel, atoi(level), + atoi(prot), atoi(aop), + atol(expiration), password)); + line++; + } + file.close(); } @@ -81,21 +91,30 @@ UserList::save() if (!file) return; - // FIXME: fix bug (see BUGS) and inc once - ++it; ++it; // We skip the bot's entry + ++it; // Skip the bot's entry + for ( ; it != l.end(); ++it) - if ((*it)->isStillValid()) { - file << (*it)->mask.getMask() << ":" - << (*it)->channelMask.getMask() << ":" - << (*it)->level << ":" - << (*it)->prot << ":" - << (*it)->aop << ":" - << (*it)->expirationDate << ":"; - if ((*it)->passwd == "") - file << "*NONE*"; - else - file << (*it)->passwd; - file << std::endl; + { + if ((*it)->isStillValid()) + { + file << (*it)->mask.getMask() << ":" + << (*it)->channelMask.getMask() << ":" + << (*it)->level << ":" + << (*it)->prot << ":" + << (*it)->aop << ":" + << (*it)->expirationDate << ":"; + + if ((*it)->passwd == "") + { + file << "*NONE*"; + } + else + { + file << (*it)->passwd; + } + + file << std::endl; + } } } @@ -104,11 +123,12 @@ UserList::clear() { UserListItem *uli; - while (!l.empty()) { - uli = (*l.begin()); - l.erase(l.begin()); - delete uli; - } + while (!l.empty()) + { + uli = (*l.begin()); + l.erase(l.begin()); + delete uli; + } } void @@ -145,11 +165,16 @@ UserList::getMaxLevel(String nuh) for (std::list::iterator it = l.begin(); it != l.end(); it++) - if ((*it)->matches(nuh) && level < (*it)->level && - ((*it)->expirationDate == -1 || - (*it)->expirationDate > current_time) && - ((*it)->passwd == "" || (*it)->identified > 0)) - level = (*it)->level; + { + if ((*it)->matches(nuh) && level < (*it)->level + && ((*it)->expirationDate == -1 + || (*it)->expirationDate > current_time) + && ((*it)->passwd == "" + || (*it)->identified > 0)) + { + level = (*it)->level; + } + } return level; } -- 2.20.1