2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /* Forward ref for typedefs */
31 /** Everything known about one nick
33 struct Nick : public intrusive_list_node<Nick>
35 /** A group of users related by nickname
37 typedef std::deque<WhoWasGroup*> List;
39 /** Container where each element has information about one occurrence of this nick
43 /** Time this nick was added to the database
47 /** Nickname whose information is stored in this class
49 const std::string nick;
51 /** Constructor to initialize fields
53 Nick(const std::string& nickname);
55 /** Destructor, deallocates all elements in the entries container
63 /** Add a user to the whowas database. Called when a user quits.
64 * @param user The user to add to the database
68 /** Retrieves statistics about the whowas database
69 * @return Whowas statistics
71 std::string GetStats() const;
73 /** Expires old entries
77 /** Updates the current configuration which may result in the database being pruned if the
78 * new values are lower than the current ones.
79 * @param NewGroupSize Maximum number of nicks allowed in the database. In case there are this many nicks
80 * in the database and one more is added, the oldest one is removed (FIFO).
81 * @param NewMaxGroups Maximum number of entries per nick
82 * @param NewMaxKeep Seconds how long each nick should be kept
84 void UpdateConfig(unsigned int NewGroupSize, unsigned int NewMaxGroups, unsigned int NewMaxKeep);
86 /** Retrieves all data known about a given nick
87 * @param nick Nickname to find, case insensitive (IRC casemapping)
88 * @return A pointer to a WhoWas::Nick if the nick was found, NULL otherwise
90 const Nick* FindNick(const std::string& nick) const;
92 /** Returns true if WHOWAS is enabled according to the current configuration
93 * @return True if WHOWAS is enabled according to the configuration, false if WHOWAS is disabled
95 bool IsEnabled() const;
106 /** Order in which the users were added into the map, used to remove oldest nick
108 typedef intrusive_list_tail<Nick> FIFO;
110 /** Sets of users in the whowas system
112 typedef TR1NS::unordered_map<std::string, WhoWas::Nick*, irc::insensitive, irc::StrHashComp> whowas_users;
114 /** Primary container, links nicknames tracked by WHOWAS to a list of records
118 /** List of nicknames in the order they were inserted into the map
122 /** Max number of WhoWas entries per user.
124 unsigned int GroupSize;
126 /** Max number of cumulative user-entries in WhoWas.
127 * When max reached and added to, push out oldest entry FIFO style.
129 unsigned int MaxGroups;
131 /** Max seconds a user is kept in WhoWas before being pruned.
133 unsigned int MaxKeep;
135 /** Shrink all data structures to honor the current settings
141 /** Handle /WHOWAS. These command handlers can be reloaded by the core,
142 * and handle basic RFC1459 commands. Commands within modules work
143 * the same way, however, they can be fully unloaded, where these
146 class CommandWhowas : public Command
149 /** Manager handling all whowas database related tasks
151 WhoWas::Manager manager;
153 CommandWhowas(Module* parent);
155 * @param parameters The parameters to the comamnd
156 * @param pcnt The number of parameters passed to teh command
157 * @param user The user issuing the command
158 * @return A value from CmdResult to indicate command success or failure.
160 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
163 /** Used to hold WHOWAS information
187 /** Initialize this WhoWasFroup with a user
189 WhoWasGroup(User* user);