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

ModeParser Class Reference

The mode parser handles routing of modes and handling of mode strings. More...

#include <mode.h>

Inheritance diagram for ModeParser:

Inheritance graph
[legend]
Collaboration diagram for ModeParser:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ModeParser (InspIRCd *Instance)
 The constructor initializes all the RFC basic modes by using ModeParserAddMode().
UserSanityChecks (User *user, const char *dest, Channel *chan, int status)
 Used to check if user 'd' should be allowed to do operation 'MASK' on channel 'chan'.
const char * Grant (User *d, Channel *chan, int MASK)
 Grant a built in privilage (e.g.
const char * Revoke (User *d, Channel *chan, int MASK)
 Revoke a built in privilage (e.g.
const std::stringGetLastParse ()
 Get the last string to be processed, as it was sent to the user or channel.
bool AddMode (ModeHandler *mh)
 Add a mode to the mode parser.
bool DelMode (ModeHandler *mh)
 Delete a mode from the mode parser.
bool AddModeWatcher (ModeWatcher *mw)
 Add a mode watcher.
bool DelModeWatcher (ModeWatcher *mw)
 Delete a mode watcher.
void Process (const std::vector< std::string > &parameters, User *user, bool servermode)
 Process a set of mode changes from a server or user.
ModeHandlerFindMode (unsigned const char modeletter, ModeType mt)
 Find the mode handler for a given mode and type.
ModeHandlerFindPrefix (unsigned const char pfxletter)
 Find a mode handler by its prefix.
std::string UserModeList ()
 Returns a list of mode characters which are usermodes.
std::string ChannelModeList ()
 Returns a list of channel mode characters which are listmodes.
std::string ParaModeList ()
 Returns a list of channel mode characters which take parameters.
std::string GiveModeList (ModeMasks m)
 Generates a list of modes, comma seperated by type: 1; Listmodes EXCEPT those with a prefix 2; Modes that take a param when adding or removing 3; Modes that only take a param when adding 4; Modes that dont take a param.
std::string BuildPrefixes ()
 This returns the PREFIX=(ohv)%+ section of the 005 numeric.
std::string ModeString (User *user, Channel *channel, bool nick_suffix=true)
 This returns the privilages of a user upon a channel, in the format of a mode change.

Static Public Member Functions

static void CleanMask (std::string &mask)
 Tidy a banmask.
static bool PrefixComparison (prefixtype one, prefixtype two)
 Used by this class internally during std::sort and 005 generation.

Private Member Functions

void DisplayCurrentModes (User *user, User *targetuser, Channel *targetchannel, const char *text)
 Displays the current modes of a channel or user.

Private Attributes

InspIRCdServerInstance
 Creator/owner pointer.
ModeHandlermodehandlers [256]
 Mode handlers for each mode, to access a handler subtract 65 from the ascii value of the mode letter.
std::vector< ModeWatcher * > modewatchers [256]
 Mode watcher classes arranged in the same way as the mode handlers, except for instead of having 256 of them we have 256 lists of them.
std::string LastParse
 The string representing the last set of modes to be parsed.
unsigned int sent [256]
unsigned int seq

Detailed Description

The mode parser handles routing of modes and handling of mode strings.

It marshalls, controls and maintains both ModeWatcher and ModeHandler classes, parses client to server MODE strings for user and channel modes, and performs processing for the 004 mode list numeric, amongst other things.

Definition at line 411 of file mode.h.


Constructor & Destructor Documentation

ModeParser::ModeParser InspIRCd Instance  ) 
 

The constructor initializes all the RFC basic modes by using ModeParserAddMode().

Definition at line 1193 of file mode.cpp.

References AddMode(), LastParse, modehandlers, sent, and seq.


Member Function Documentation

bool ModeParser::AddMode ModeHandler mh  ) 
 

Add a mode to the mode parser.

Returns:
True if the mode was successfully added.

Definition at line 830 of file mode.cpp.

References ModeHandler::GetModeChar(), ModeHandler::GetModeType(), ModeHandler::GetPrefix(), MASK_CHANNEL, MASK_USER, modehandlers, and MODETYPE_USER.

Referenced by ModeParser(), ModuleAllowInvite::ModuleAllowInvite(), ModuleAuditorium::ModuleAuditorium(), ModuleBanException::ModuleBanException(), ModuleBlockCAPS::ModuleBlockCAPS(), ModuleBlockColour::ModuleBlockColour(), ModuleBotMode::ModuleBotMode(), ModuleCallerID::ModuleCallerID(), ModuleCensor::ModuleCensor(), ModuleChanFilter::ModuleChanFilter(), ModuleChanProtect::ModuleChanProtect(), ModuleCloaking::ModuleCloaking(), ModuleDeaf::ModuleDeaf(), ModuleDelayJoin::ModuleDelayJoin(), ModuleHelpop::ModuleHelpop(), ModuleHideChans::ModuleHideChans(), ModuleHideOper::ModuleHideOper(), ModuleInvisible::ModuleInvisible(), ModuleInviteException::ModuleInviteException(), ModuleJoinFlood::ModuleJoinFlood(), ModuleKickNoRejoin::ModuleKickNoRejoin(), ModuleKnock::ModuleKnock(), ModuleMsgFlood::ModuleMsgFlood(), ModuleNickFlood::ModuleNickFlood(), ModuleNoCTCP::ModuleNoCTCP(), ModuleNoKicks::ModuleNoKicks(), ModuleNoNickChange::ModuleNoNickChange(), ModuleNoNotice::ModuleNoNotice(), ModuleOperChans::ModuleOperChans(), ModulePermanentChannels::ModulePermanentChannels(), ModulePrivacyMode::ModulePrivacyMode(), ModuleRedirect::ModuleRedirect(), ModuleServicesAccount::ModuleServicesAccount(), ModuleServProtectMode::ModuleServProtectMode(), ModuleShowwhois::ModuleShowwhois(), ModuleSSLModes::ModuleSSLModes(), and ModuleStripColor::ModuleStripColor().

bool ModeParser::AddModeWatcher ModeWatcher mw  ) 
 

Add a mode watcher.

A mode watcher is triggered before and after a mode handler is triggered. See the documentation of class ModeWatcher for more information.

Parameters:
mw The ModeWatcher you want to add
Returns:
True if the ModeWatcher was added correctly

Definition at line 1101 of file mode.cpp.

References ModeWatcher::GetModeChar(), ModeWatcher::GetModeType(), MASK_CHANNEL, MASK_USER, MODETYPE_USER, and modewatchers.

Referenced by ModuleBanRedirect::ModuleBanRedirect(), and ModuleInvisible::ModuleInvisible().

std::string ModeParser::BuildPrefixes  ) 
 

This returns the PREFIX=(ohv)%+ section of the 005 numeric.

Definition at line 1069 of file mode.cpp.

References ServerConfig::AllowHalfop, InspIRCd::Config, ModeHandler::GetPrefix(), MASK_CHANNEL, modehandlers, PrefixComparison(), and ServerInstance.

Referenced by InspIRCd::BuildISupport(), TreeSocket::Capab(), and TreeSocket::SendCapabilities().

std::string ModeParser::ChannelModeList  ) 
 

Returns a list of channel mode characters which are listmodes.

This is used in the 004 numeric when users connect.

Definition at line 927 of file mode.cpp.

References ServerConfig::AllowHalfop, InspIRCd::Config, MASK_CHANNEL, modehandlers, and ServerInstance.

Referenced by User::FullConnect().

void ModeParser::CleanMask std::string mask  )  [static]
 

Tidy a banmask.

This makes a banmask 'acceptable' if fields are left out. E.g.

nick -> nick!*@*

nick!ident -> nick!ident@*

host.name -> *!*.name

ident@host.name -> *!ident.name

This method can be used on both IPV4 and IPV6 user masks.

Definition at line 794 of file mode.cpp.

Referenced by ModeChannelBan::AddBan(), ModeChannelBan::DelBan(), CommandSilence::Handle(), and ListModeBase::OnModeChange().

bool ModeParser::DelMode ModeHandler mh  ) 
 

Delete a mode from the mode parser.

When a mode is deleted, the mode handler will be called for every user (if it is a user mode) or for every channel (if it is a channel mode) to unset the mode on all objects. This prevents modes staying in the system which no longer exist.

Parameters:
mh The mode handler to remove
Returns:
True if the mode was successfully removed.

Definition at line 859 of file mode.cpp.

References InspIRCd::chanlist, UserManager::clientlist, ModeHandler::GetModeChar(), ModeHandler::GetModeType(), MASK_CHANNEL, MASK_USER, modehandlers, MODETYPE_CHANNEL, MODETYPE_USER, ModeHandler::RemoveMode(), ServerInstance, and InspIRCd::Users.

Referenced by ModuleAllowInvite::~ModuleAllowInvite(), ModuleAuditorium::~ModuleAuditorium(), ModuleBanException::~ModuleBanException(), ModuleBlockCAPS::~ModuleBlockCAPS(), ModuleBlockColour::~ModuleBlockColour(), ModuleBotMode::~ModuleBotMode(), ModuleCallerID::~ModuleCallerID(), ModuleCensor::~ModuleCensor(), ModuleChanFilter::~ModuleChanFilter(), ModuleChanProtect::~ModuleChanProtect(), ModuleCloaking::~ModuleCloaking(), ModuleDeaf::~ModuleDeaf(), ModuleDelayJoin::~ModuleDelayJoin(), ModuleHelpop::~ModuleHelpop(), ModuleHideChans::~ModuleHideChans(), ModuleHideOper::~ModuleHideOper(), ModuleInvisible::~ModuleInvisible(), ModuleInviteException::~ModuleInviteException(), ModuleJoinFlood::~ModuleJoinFlood(), ModuleKickNoRejoin::~ModuleKickNoRejoin(), ModuleKnock::~ModuleKnock(), ModuleMsgFlood::~ModuleMsgFlood(), ModuleNickFlood::~ModuleNickFlood(), ModuleNoCTCP::~ModuleNoCTCP(), ModuleNoKicks::~ModuleNoKicks(), ModuleNoNickChange::~ModuleNoNickChange(), ModuleNoNotice::~ModuleNoNotice(), ModuleOperChans::~ModuleOperChans(), ModulePermanentChannels::~ModulePermanentChannels(), ModulePrivacyMode::~ModulePrivacyMode(), ModuleRedirect::~ModuleRedirect(), ModuleServicesAccount::~ModuleServicesAccount(), ModuleServProtectMode::~ModuleServProtectMode(), ModuleShowwhois::~ModuleShowwhois(), ModuleSSLModes::~ModuleSSLModes(), and ModuleStripColor::~ModuleStripColor().

bool ModeParser::DelModeWatcher ModeWatcher mw  ) 
 

Delete a mode watcher.

A mode watcher is triggered before and after a mode handler is triggered. See the documentation of class ModeWatcher for more information.

Parameters:
mw The ModeWatcher you want to delete
Returns:
True if the ModeWatcher was deleted correctly

Definition at line 1120 of file mode.cpp.

References ModeWatcher::GetModeChar(), ModeWatcher::GetModeType(), MASK_CHANNEL, MASK_USER, MODETYPE_USER, and modewatchers.

Referenced by ModuleBanRedirect::~ModuleBanRedirect(), and ModuleInvisible::~ModuleInvisible().

void ModeParser::DisplayCurrentModes User user,
User targetuser,
Channel targetchannel,
const char *  text
[private]
 

Displays the current modes of a channel or user.

Used by ModeParser::Process.

Definition at line 323 of file mode.cpp.

References classbase::age, Channel::ChanModes(), ERR_NOSUCHNICK, ERR_USERSDONTMATCH, User::FormatModes(), User::FormatNoticeMasks(), User::HasPrivPermission(), Channel::HasUser(), IS_OPER, Channel::name, User::nick, RPL_CHANNELCREATED, RPL_CHANNELMODEIS, RPL_SNOMASKIS, RPL_UMODEIS, User::Visibility, VisData::VisibleTo(), and User::WriteNumeric().

Referenced by Process().

ModeHandler * ModeParser::FindMode unsigned const char  modeletter,
ModeType  mt
 

Find the mode handler for a given mode and type.

Parameters:
modeletter mode letter to search for
type of mode to search for, user or channel
Returns:
a pointer to a ModeHandler class, or NULL of there isnt a handler for the given mode

Definition at line 897 of file mode.cpp.

References MASK_CHANNEL, MASK_USER, modehandlers, and MODETYPE_USER.

Referenced by User::DecrementModes(), TreeSocket::ForceJoin(), User::FormatModes(), UserManager::ModeCount(), ModulePermanentChannels::OnRehash(), TreeSocket::ParseUID(), Process(), Channel::SetDefaultModes(), and User::UnOper().

ModeHandler * ModeParser::FindPrefix unsigned const char  pfxletter  ) 
 

Find a mode handler by its prefix.

If there is no mode handler with the given prefix, NULL will be returned.

Parameters:
pfxletter The prefix to find, e.g. '@'
Returns:
The mode handler which handles this prefix, or NULL if there is none.

Definition at line 965 of file mode.cpp.

References MASK_CHANNEL, and modehandlers.

Referenced by SpanningTreeUtilities::DoOneToAllButSenderRaw(), Channel::ForceChan(), ModuleChanProtect::LoadSettings(), Process(), and TreeSocket::ServerMessage().

const std::string & ModeParser::GetLastParse  ) 
 

Get the last string to be processed, as it was sent to the user or channel.

Use this to display a string you just sent to be parsed, as the actual output may be different to what you sent after it has been 'cleaned up' by the parser.

Returns:
Last parsed string, as seen by users.

Definition at line 789 of file mode.cpp.

References LastParse.

Referenced by CommandSamode::Handle(), ModuleTimedBans::OnBackgroundTimer(), and ModuleOverride::OnPostCommand().

std::string ModeParser::GiveModeList ModeMasks  m  ) 
 

Generates a list of modes, comma seperated by type: 1; Listmodes EXCEPT those with a prefix 2; Modes that take a param when adding or removing 3; Modes that only take a param when adding 4; Modes that dont take a param.

Definition at line 1013 of file mode.cpp.

References ServerConfig::AllowHalfop, InspIRCd::Config, ModeHandler::GetModeChar(), modehandlers, and ServerInstance.

Referenced by InspIRCd::BuildISupport(), TreeSocket::Capab(), and TreeSocket::SendCapabilities().

const char * ModeParser::Grant User d,
Channel chan,
int  MASK
 

Grant a built in privilage (e.g.

ops, halfops, voice) to a user on a channel

Definition at line 263 of file mode.cpp.

References User::chans, User::nick, UCMODE_HOP, UCMODE_OP, and UCMODE_VOICE.

Referenced by ModeChannelHalfOp::AddHalfOp(), ModeChannelOp::AddOp(), and ModeChannelVoice::AddVoice().

std::string ModeParser::ModeString User user,
Channel channel,
bool  nick_suffix = true
 

This returns the privilages of a user upon a channel, in the format of a mode change.

For example, if a user has privilages +avh, this will return the string "avh nick nick nick". This is used by the core when cycling a user to refresh their hostname. You may use it for similar purposes.

Parameters:
user The username to look up
channel The channel name to look up the privilages of the user for
nick_suffix true (the default) if you want nicknames in the mode string, for easy use with the mode stacker, false if you just want the "avh" part of "avh nick nick nick".
Returns:
The mode string.

Definition at line 979 of file mode.cpp.

References ModeHandler::GetModeChar(), ModeHandler::GetNumParams(), MASK_CHANNEL, modehandlers, ModeHandler::ModeSet(), and User::nick.

Referenced by User::ChangeDisplayedHost(), User::ChangeIdent(), Channel::ForceChan(), InvisibleMode::OnModeChange(), ModuleServProtectMode::OnRawMode(), ModuleDelayJoin::OnText(), ModuleSpanningTree::OnUserJoin(), and TreeSocket::SendFJoins().

std::string ModeParser::ParaModeList  ) 
 

Returns a list of channel mode characters which take parameters.

This is used in the 004 numeric when users connect.

Definition at line 946 of file mode.cpp.

References ServerConfig::AllowHalfop, InspIRCd::Config, MASK_CHANNEL, modehandlers, and ServerInstance.

Referenced by User::FullConnect().

bool ModeParser::PrefixComparison prefixtype  one,
prefixtype  two
[static]
 

Used by this class internally during std::sort and 005 generation.

Definition at line 1064 of file mode.cpp.

Referenced by BuildPrefixes(), and Channel::SetPrefix().

void ModeParser::Process const std::vector< std::string > &  parameters,
User user,
bool  servermode
 

Process a set of mode changes from a server or user.

Parameters:
parameters The parameters of the mode change, in the format they would be from a MODE command.
user The user setting or removing the modes. When the modes are set by a server, an 'uninitialized' User is used, where *usernick == NULL and *user->server == NULL.
servermode True if a server is setting the mode.

Definition at line 360 of file mode.cpp.

References AC_GENERAL_MODE, ACR_ALLOW, ACR_DENY, ModeHandler::ChangeCount(), InspIRCd::Config, ServerConfig::DisabledCModes, ServerConfig::DisabledUModes, DisplayCurrentModes(), ModeHandler::DisplayEmptyList(), ModeHandler::DisplayList(), ERR_CHANOPRIVSNEEDED, ERR_NOPRIVILEGES, ERR_NOSUCHNICK, ERR_USERSDONTMATCH, InspIRCd::FindChan(), FindMode(), InspIRCd::FindNick(), FindPrefix(), FOREACH_MOD, FOREACH_RESULT, Channel::GetAllPrefixChars(), ModeHandler::GetModeChar(), ModeHandler::GetNeededPrefix(), ModeHandler::GetPrefixRank(), Channel::GetStatus(), User::HasModePermission(), User::HasPrivPermission(), ServerConfig::HideModeLists, I_OnAccessCheck, I_OnMode, I_OnRawMode, IS_LOCAL, IS_OPER, ModeHandler::IsListMode(), LastParse, ServerConfig::Limits, MASK_CHANNEL, MASK_USER, ServerLimits::MaxModes, MODEACTION_ALLOW, modehandlers, MODETYPE_CHANNEL, MODETYPE_USER, modewatchers, Channel::name, User::nick, ModeHandler::OnModeChange(), ModeHandler::OnParameterMissing(), User::oper, sent, seq, User::server, ServerInstance, ServerConfig::ServerName, Channel::SetPrefix(), STATUS_HOP, TYPE_CHANNEL, TYPE_USER, InspIRCd::ULine(), Channel::WriteChannel(), Channel::WriteChannelWithServ(), User::WriteNumeric(), User::WriteServ(), and User::WriteTo().

Referenced by InvisibleDeOper::BeforeMode(), ModeHandler::RemoveMode(), and InspIRCd::SendMode().

const char * ModeParser::Revoke User d,
Channel chan,
int  MASK
 

Revoke a built in privilage (e.g.

ops, halfops, voice) to a user on a channel

Definition at line 293 of file mode.cpp.

References User::chans, User::nick, UCMODE_HOP, UCMODE_OP, and UCMODE_VOICE.

Referenced by ModeChannelHalfOp::DelHalfOp(), ModeChannelOp::DelOp(), and ModeChannelVoice::DelVoice().

User * ModeParser::SanityChecks User user,
const char *  dest,
Channel chan,
int  status
 

Used to check if user 'd' should be allowed to do operation 'MASK' on channel 'chan'.

for example, should 'user A' be able to 'op' on 'channel B'.

Definition at line 247 of file mode.cpp.

References ERR_NOSUCHNICK, InspIRCd::FindNick(), User::nick, ServerInstance, and User::WriteNumeric().

Referenced by ModeChannelHalfOp::AddHalfOp(), ModeChannelOp::AddOp(), ModeChannelVoice::AddVoice(), ModeChannelHalfOp::DelHalfOp(), ModeChannelOp::DelOp(), and ModeChannelVoice::DelVoice().

std::string ModeParser::UserModeList  ) 
 

Returns a list of mode characters which are usermodes.

This is used in the 004 numeric when users connect.

Definition at line 911 of file mode.cpp.

References MASK_USER, and modehandlers.

Referenced by User::FullConnect().


Member Data Documentation

std::string ModeParser::LastParse [private]
 

The string representing the last set of modes to be parsed.

Use GetLastParse() to get this value, to be used for display purposes.

Definition at line 437 of file mode.h.

Referenced by GetLastParse(), ModeParser(), and Process().

ModeHandler* ModeParser::modehandlers[256] [private]
 

Mode handlers for each mode, to access a handler subtract 65 from the ascii value of the mode letter.

The upper bit of the value indicates if its a usermode or a channel mode, so we have 256 of them not 64.

Definition at line 423 of file mode.h.

Referenced by AddMode(), BuildPrefixes(), ChannelModeList(), DelMode(), FindMode(), FindPrefix(), GiveModeList(), ModeParser(), ModeString(), ParaModeList(), Process(), and UserModeList().

std::vector<ModeWatcher*> ModeParser::modewatchers[256] [private]
 

Mode watcher classes arranged in the same way as the mode handlers, except for instead of having 256 of them we have 256 lists of them.

Definition at line 428 of file mode.h.

Referenced by AddModeWatcher(), DelModeWatcher(), and Process().

unsigned int ModeParser::sent[256] [private]
 

Definition at line 439 of file mode.h.

Referenced by ModeParser(), and Process().

unsigned int ModeParser::seq [private]
 

Definition at line 441 of file mode.h.

Referenced by ModeParser(), and Process().

InspIRCd* ModeParser::ServerInstance [private]
 

Creator/owner pointer.

Definition at line 417 of file mode.h.

Referenced by BuildPrefixes(), ChannelModeList(), DelMode(), GiveModeList(), ParaModeList(), Process(), and SanityChecks().


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