The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ListModeBase Class Reference

The base class for list modes, should be inherited. More...

#include <u_listmode.h>

Inheritance diagram for ListModeBase:

Inheritance graph
[legend]
Collaboration diagram for ListModeBase:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ListModeBase (InspIRCd *Instance, char modechar, const std::string &eolstr, const std::string &lnum, const std::string &eolnum, bool autotidy, const std::string &ctag="banlist")
 Constructor.
std::pair< bool, std::stringModeSet (userrec *source, userrec *dest, chanrec *channel, const std::string &parameter)
 See mode.h.
virtual void DisplayList (userrec *user, chanrec *channel)
 Display the list for this mode.
virtual void DisplayEmptyList (userrec *user, chanrec *channel)
 If your mode is a listmode, this method will be called to display an empty list (just the end of list numeric).
virtual void RemoveMode (chanrec *channel)
 Remove all instances of the mode from a channel.
virtual void RemoveMode (userrec *user)
 See mode.h.
virtual void DoRehash ()
 Perform a rehash of this mode's configuration data.
virtual void DoImplements (char *List)
 Populate the Implements list with the correct events for a List Mode.
virtual ModeAction OnModeChange (userrec *source, userrec *dest, chanrec *channel, std::string &parameter, bool adding)
 Handle the list mode.
virtual std::stringGetInfoKey ()
 Get Extensible key for this mode.
virtual void DoChannelDelete (chanrec *chan)
 Handle channel deletion.
virtual void DoSyncChannel (chanrec *chan, Module *proto, void *opaque)
 Syncronize channel item list with another server.
virtual void DoCleanup (int target_type, void *item)
 Clean up module on unload.
virtual bool ValidateParam (userrec *source, chanrec *channel, std::string &parameter)
 Validate parameters.
virtual bool TellListTooLong (userrec *source, chanrec *channel, std::string &parameter)
 Tell the user the list is too long.
virtual void TellAlreadyOnList (userrec *source, chanrec *channel, std::string &parameter)
 Tell the user an item is already on the list.
virtual void TellNotSet (userrec *source, chanrec *channel, std::string &parameter)
 Tell the user that the parameter is not in the list.

Protected Attributes

std::string infokey
 Storage key.
std::string listnumeric
 Numeric to use when outputting the list.
std::string endoflistnumeric
 Numeric to indicate end of list.
std::string endofliststring
 String to send for end of list.
bool tidy
 Automatically tidy up entries.
std::string configtag
 Config tag to check for max items per channel.
limitlist chanlimits
 Limits on a per-channel basis read from the tag specified in ListModeBase::configtag.

Detailed Description

The base class for list modes, should be inherited.

Definition at line 97 of file u_listmode.h.


Constructor & Destructor Documentation

ListModeBase::ListModeBase InspIRCd Instance,
char  modechar,
const std::string eolstr,
const std::string lnum,
const std::string eolnum,
bool  autotidy,
const std::string ctag = "banlist"
[inline]
 

Constructor.

Parameters:
Instance The creator of this class
modechar Mode character
eolstr End of list string lnum List numeric
eolnum End of list numeric
autotidy Automatically tidy list entries on add
ctag Configuration tag to get limits from

Definition at line 133 of file u_listmode.h.

References DoRehash(), infokey, and ModeHandler::mode.

00134         : ModeHandler(Instance, modechar, 1, 1, true, MODETYPE_CHANNEL, false), listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy), configtag(ctag)
00135         {
00136                 this->DoRehash();
00137                 infokey = "listbase_mode_" + std::string(1, mode) + "_list";
00138         }


Member Function Documentation

virtual void ListModeBase::DisplayEmptyList userrec user,
chanrec channel
[inline, virtual]
 

If your mode is a listmode, this method will be called to display an empty list (just the end of list numeric).

Parameters:
user The user issuing the command
channel The channel tehy're requesting an item list of (e.g. a banlist, or an exception list etc)

Reimplemented from ModeHandler.

Definition at line 177 of file u_listmode.h.

References endoflistnumeric, endofliststring, chanrec::name, userrec::nick, and userrec::WriteServ().

00178         {
00179                 user->WriteServ("%s %s %s :%s", endoflistnumeric.c_str(), user->nick, channel->name, endofliststring.c_str());
00180         }

virtual void ListModeBase::DisplayList userrec user,
chanrec channel
[inline, virtual]
 

Display the list for this mode.

Parameters:
user The user to send the list to
channel The channel the user is requesting the list for

Reimplemented from ModeHandler.

Definition at line 163 of file u_listmode.h.

References InspIRCd::Config, endoflistnumeric, endofliststring, Extensible::GetExt(), infokey, listnumeric, chanrec::name, userrec::nick, ModeHandler::ServerInstance, ServerConfig::ServerName, and userrec::WriteServ().

00164         {
00165                 modelist* el;
00166                 channel->GetExt(infokey, el);
00167                 if (el)
00168                 {
00169                         for (modelist::reverse_iterator it = el->rbegin(); it != el->rend(); ++it)
00170                         {
00171                                 user->WriteServ("%s %s %s %s %s %s", listnumeric.c_str(), user->nick, channel->name, it->mask.c_str(), (it->nick.length() ? it->nick.c_str() : ServerInstance->Config->ServerName), it->time.c_str());
00172                         }
00173                 }
00174                 user->WriteServ("%s %s %s :%s", endoflistnumeric.c_str(), user->nick, channel->name, endofliststring.c_str());
00175         }

virtual void ListModeBase::DoChannelDelete chanrec chan  )  [inline, virtual]
 

Handle channel deletion.

See modules.h.

Parameters:
chan Channel being deleted

Definition at line 386 of file u_listmode.h.

References Extensible::GetExt(), infokey, ModeHandler::list, and Extensible::Shrink().

Referenced by ModuleInviteException::OnChannelDelete(), ModuleChanFilter::OnChannelDelete(), and ModuleBanException::OnChannelDelete().

00387         {
00388                 modelist* list;
00389                 chan->GetExt(infokey, list);
00390 
00391                 if (list)
00392                 {
00393                         chan->Shrink(infokey);
00394                         delete list;
00395                 }
00396         }

virtual void ListModeBase::DoCleanup int  target_type,
void *  item
[inline, virtual]
 

Clean up module on unload.

Parameters:
target_type Type of target to clean
item Item to clean

Definition at line 429 of file u_listmode.h.

Referenced by ModuleInviteException::OnCleanup(), ModuleChanFilter::OnCleanup(), and ModuleBanException::OnCleanup().

00430         {
00431         }

virtual void ListModeBase::DoImplements char *  List  )  [inline, virtual]
 

Populate the Implements list with the correct events for a List Mode.

Definition at line 251 of file u_listmode.h.

References I_OnChannelDelete, I_OnCleanup, I_OnRehash, and I_OnSyncChannel.

Referenced by ModuleInviteException::Implements(), ModuleChanFilter::Implements(), and ModuleBanException::Implements().

00252         {
00253                 List[I_OnChannelDelete] = List[I_OnSyncChannel] = List[I_OnCleanup] = List[I_OnRehash] = 1;
00254         }

virtual void ListModeBase::DoRehash  )  [inline, virtual]
 

Perform a rehash of this mode's configuration data.

Definition at line 224 of file u_listmode.h.

References chanlimits, Conf, configtag, ConfigReader::Enumerate(), ListLimit::limit, ListLimit::mask, ConfigReader::ReadInteger(), ConfigReader::ReadValue(), and ModeHandler::ServerInstance.

Referenced by ListModeBase(), ModuleInviteException::OnRehash(), ModuleChanFilter::OnRehash(), and ModuleBanException::OnRehash().

00225         {
00226                 ConfigReader Conf(ServerInstance);
00227 
00228                 chanlimits.clear();
00229 
00230                 for (int i = 0; i < Conf.Enumerate(configtag); i++)
00231                 {
00232                         // For each <banlist> tag
00233                         ListLimit limit;
00234                         limit.mask = Conf.ReadValue(configtag, "chan", i);
00235                         limit.limit = Conf.ReadInteger(configtag, "limit", i, true);
00236 
00237                         if (limit.mask.size() && limit.limit > 0)
00238                                 chanlimits.push_back(limit);
00239                 }
00240                 if (chanlimits.size() == 0)
00241                 {
00242                         ListLimit limit;
00243                         limit.mask = "*";
00244                         limit.limit = 64;
00245                         chanlimits.push_back(limit);
00246                 }
00247         }

virtual void ListModeBase::DoSyncChannel chanrec chan,
Module proto,
void *  opaque
[inline, virtual]
 

Syncronize channel item list with another server.

See modules.h

Parameters:
chan Channel to syncronize
proto Protocol module pointer
opaque Opaque connection handle

Definition at line 404 of file u_listmode.h.

References assign(), Extensible::GetExt(), irc::stringjoiner::GetJoined(), irc::modestacker::GetStackedLine(), infokey, ModeHandler::list, ModeHandler::mode, Module::ProtoSendMode(), irc::modestacker::Push(), and TYPE_CHANNEL.

Referenced by ModuleInviteException::OnSyncChannel(), ModuleChanFilter::OnSyncChannel(), and ModuleBanException::OnSyncChannel().

00405         {
00406                 modelist* list;
00407                 chan->GetExt(infokey, list);
00408                 irc::modestacker modestack(true);
00409                 std::deque<std::string> stackresult;
00410                 if (list)
00411                 {
00412                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
00413                         {
00414                                 modestack.Push(std::string(1, mode)[0], assign(it->mask));
00415                         }
00416                 }
00417                 while (modestack.GetStackedLine(stackresult))
00418                 {
00419                         irc::stringjoiner mode_join(" ", stackresult, 0, stackresult.size() - 1);
00420                         std::string line = mode_join.GetJoined();
00421                         proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, line);
00422                 }
00423         }

virtual std::string& ListModeBase::GetInfoKey  )  [inline, virtual]
 

Get Extensible key for this mode.

Definition at line 377 of file u_listmode.h.

References infokey.

Referenced by ModuleBanException::OnCheckBan(), ModuleInviteException::OnCheckInvite(), ModuleInviteException::OnRequest(), ModuleBanException::OnRequest(), and ModuleChanFilter::ProcessMessages().

00378         {
00379                 return infokey;
00380         }

std::pair<bool,std::string> ListModeBase::ModeSet userrec source,
userrec dest,
chanrec channel,
const std::string parameter
[inline, virtual]
 

See mode.h.

Reimplemented from ModeHandler.

Definition at line 142 of file u_listmode.h.

References Extensible::GetExt(), and infokey.

00143         {
00144                 modelist* el;
00145                 channel->GetExt(infokey, el);
00146                 if (el)
00147                 {
00148                         for (modelist::iterator it = el->begin(); it != el->end(); it++)
00149                         {
00150                                 if(parameter == it->mask)
00151                                 {
00152                                         return std::make_pair(true, parameter);
00153                                 }
00154                         }
00155                 }
00156                 return std::make_pair(false, parameter);
00157         }

virtual ModeAction ListModeBase::OnModeChange userrec source,
userrec dest,
chanrec channel,
std::string parameter,
bool  adding
[inline, virtual]
 

Handle the list mode.

See mode.h

Reimplemented from ModeHandler.

Definition at line 259 of file u_listmode.h.

References assign(), chanlimits, ModeParser::CleanMask(), Extensible::Extend(), Extensible::GetExt(), infokey, ListItem::mask, match(), MODEACTION_ALLOW, MODEACTION_DENY, chanrec::name, userrec::nick, ListItem::nick, Extensible::Shrink(), stringtime(), TellAlreadyOnList(), TellListTooLong(), TellNotSet(), ListItem::time, ValidateParam(), and userrec::WriteServ().

00260         {
00261                 // Try and grab the list
00262                 modelist* el;
00263                 channel->GetExt(infokey, el);
00264 
00265                 if (adding)
00266                 {
00267                         // If there was no list
00268                         if (!el)
00269                         {
00270                                 // Make one
00271                                 el = new modelist;
00272                                 channel->Extend(infokey, el);
00273                         }
00274 
00275                         // Clean the mask up
00276                         if (this->tidy)
00277                                 ModeParser::CleanMask(parameter);
00278 
00279                         // Check if the item already exists in the list
00280                         for (modelist::iterator it = el->begin(); it != el->end(); it++)
00281                         {
00282                                 if (parameter == it->mask)
00283                                 {
00284                                         /* Give a subclass a chance to error about this */
00285                                         TellAlreadyOnList(source, channel, parameter);
00286                                         
00287                                         // it does, deny the change
00288                                         return MODEACTION_DENY;
00289                                 }
00290                         }
00291 
00292                         unsigned int maxsize = 0;
00293 
00294                         for (limitlist::iterator it = chanlimits.begin(); it != chanlimits.end(); it++)
00295                         {
00296                                 if (match(channel->name, it->mask.c_str()))
00297                                 {
00298                                         // We have a pattern matching the channel...
00299                                         maxsize = el->size();
00300                                         if (maxsize < it->limit)
00301                                         {
00302                                                 /* Ok, it *could* be allowed, now give someone subclassing us
00303                                                  * a chance to validate the parameter.
00304                                                  * The param is passed by reference, so they can both modify it
00305                                                  * and tell us if we allow it or not.
00306                                                  *
00307                                                  * eg, the subclass could:
00308                                                  * 1) allow
00309                                                  * 2) 'fix' parameter and then allow
00310                                                  * 3) deny
00311                                                  */
00312                                                 if (ValidateParam(source, channel, parameter))
00313                                                 {
00314                                                         // And now add the mask onto the list...
00315                                                         ListItem e;
00316                                                         e.mask = assign(parameter);
00317                                                         e.nick = source->nick;
00318                                                         e.time = stringtime();
00319 
00320                                                         el->push_back(e);
00321                                                         return MODEACTION_ALLOW;
00322                                                 }
00323                                                 else
00324                                                 {
00325                                                         /* If they deny it they have the job of giving an error message */
00326                                                         return MODEACTION_DENY;
00327                                                 }
00328                                         }
00329                                 }
00330                         }
00331 
00332                         /* List is full, give subclass a chance to send a custom message */
00333                         if (!TellListTooLong(source, channel, parameter))
00334                         {
00335                                 source->WriteServ("478 %s %s %s :Channel ban/ignore list is full", source->nick, channel->name, parameter.c_str());
00336                         }
00337                         
00338                         parameter = "";
00339                         return MODEACTION_DENY; 
00340                 }
00341                 else
00342                 {
00343                         // We're taking the mode off
00344                         if (el)
00345                         {
00346                                 for (modelist::iterator it = el->begin(); it != el->end(); it++)
00347                                 {
00348                                         if (parameter == it->mask)
00349                                         {
00350                                                 el->erase(it);
00351                                                 if (el->size() == 0)
00352                                                 {
00353                                                         channel->Shrink(infokey);
00354                                                         delete el;
00355                                                 }
00356                                                 return MODEACTION_ALLOW;
00357                                         }
00358                                 }
00359                                 /* Tried to remove something that wasn't set */
00360                                 TellNotSet(source, channel, parameter);
00361                                 parameter = "";
00362                                 return MODEACTION_DENY;
00363                         }
00364                         else
00365                         {
00366                                 /* Hmm, taking an exception off a non-existant list, DIE */
00367                                 TellNotSet(source, channel, parameter);
00368                                 parameter = "";
00369                                 return MODEACTION_DENY;
00370                         }
00371                 }
00372                 return MODEACTION_DENY;
00373         }

virtual void ListModeBase::RemoveMode userrec user  )  [inline, virtual]
 

See mode.h.

Reimplemented from ModeHandler.

Definition at line 217 of file u_listmode.h.

00218         {
00219                 /* Listmodes dont get set on users */
00220         }

virtual void ListModeBase::RemoveMode chanrec channel  )  [inline, virtual]
 

Remove all instances of the mode from a channel.

See mode.h

Parameters:
channel The channel to remove all instances of the mode from

Reimplemented from ModeHandler.

Definition at line 186 of file u_listmode.h.

References assign(), FD_MAGIC_NUMBER, Extensible::GetExt(), irc::modestacker::GetStackedLine(), infokey, MAXMODES, chanrec::name, irc::modestacker::Push(), InspIRCd::SendMode(), ModeHandler::ServerInstance, and EventHandler::SetFd().

00187         {
00188                 modelist* el;
00189                 channel->GetExt(infokey, el);
00190                 if (el)
00191                 {
00192                         irc::modestacker modestack(false);
00193                         std::deque<std::string> stackresult;
00194                         const char* mode_junk[MAXMODES+2];
00195                         mode_junk[0] = channel->name;
00196                         userrec* n = new userrec(ServerInstance);
00197                         n->SetFd(FD_MAGIC_NUMBER);
00198                         for (modelist::iterator it = el->begin(); it != el->end(); it++)
00199                         {
00200                                 modestack.Push(this->GetModeChar(), assign(it->mask));
00201                         }
00202                         while (modestack.GetStackedLine(stackresult))
00203                         {
00204                                 for (size_t j = 0; j < stackresult.size(); j++)
00205                                 {
00206                                         mode_junk[j+1] = stackresult[j].c_str();
00207                                 }
00208                                 ServerInstance->SendMode(mode_junk, stackresult.size() + 1, n);         
00209                         }
00210 
00211                         delete n;
00212                 }
00213         }

virtual void ListModeBase::TellAlreadyOnList userrec source,
chanrec channel,
std::string parameter
[inline, virtual]
 

Tell the user an item is already on the list.

Overridden by implementing module.

Parameters:
source Source user adding the parameter
channel Channel the parameter is being added to
parameter The actual parameter being added

Reimplemented in ChanFilter.

Definition at line 463 of file u_listmode.h.

Referenced by OnModeChange().

00464         {
00465         }

virtual bool ListModeBase::TellListTooLong userrec source,
chanrec channel,
std::string parameter
[inline, virtual]
 

Tell the user the list is too long.

Overridden by implementing module.

Parameters:
source Source user adding the parameter
channel Channel the parameter is being added to
parameter The actual parameter being added
Returns:
Ignored

Reimplemented in ChanFilter.

Definition at line 452 of file u_listmode.h.

Referenced by OnModeChange().

00453         {
00454                 return false;
00455         }

virtual void ListModeBase::TellNotSet userrec source,
chanrec channel,
std::string parameter
[inline, virtual]
 

Tell the user that the parameter is not in the list.

Overridden by implementing module.

Parameters:
source Source user removing the parameter
channel Channel the parameter is being removed from
parameter The actual parameter being removed

Reimplemented in ChanFilter.

Definition at line 473 of file u_listmode.h.

Referenced by OnModeChange().

00474         {
00475         }

virtual bool ListModeBase::ValidateParam userrec source,
chanrec channel,
std::string parameter
[inline, virtual]
 

Validate parameters.

Overridden by implementing module.

Parameters:
source Source user adding the parameter
channel Channel the parameter is being added to
parameter The actual parameter being added
Returns:
true if the parameter is valid

Reimplemented in ChanFilter.

Definition at line 440 of file u_listmode.h.

Referenced by OnModeChange().

00441         {
00442                 return true;
00443         }


Member Data Documentation

limitlist ListModeBase::chanlimits [protected]
 

Limits on a per-channel basis read from the tag specified in ListModeBase::configtag.

Definition at line 121 of file u_listmode.h.

Referenced by DoRehash(), and OnModeChange().

std::string ListModeBase::configtag [protected]
 

Config tag to check for max items per channel.

Definition at line 117 of file u_listmode.h.

Referenced by DoRehash().

std::string ListModeBase::endoflistnumeric [protected]
 

Numeric to indicate end of list.

Definition at line 108 of file u_listmode.h.

Referenced by DisplayEmptyList(), and DisplayList().

std::string ListModeBase::endofliststring [protected]
 

String to send for end of list.

Definition at line 111 of file u_listmode.h.

Referenced by DisplayEmptyList(), and DisplayList().

std::string ListModeBase::infokey [protected]
 

Storage key.

Definition at line 102 of file u_listmode.h.

Referenced by DisplayList(), DoChannelDelete(), DoSyncChannel(), GetInfoKey(), ListModeBase(), ModeSet(), OnModeChange(), and RemoveMode().

std::string ListModeBase::listnumeric [protected]
 

Numeric to use when outputting the list.

Definition at line 105 of file u_listmode.h.

Referenced by DisplayList().

bool ListModeBase::tidy [protected]
 

Automatically tidy up entries.

Definition at line 114 of file u_listmode.h.


The documentation for this class was generated from the following file: