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

XLineManager Class Reference

XLineManager is a class used to manage glines, klines, elines, zlines and qlines, or any other line created by a module. More...

#include <xline.h>

Inheritance diagram for XLineManager:

Inheritance graph
[legend]
Collaboration diagram for XLineManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 XLineManager (InspIRCd *Instance)
 Constructor.
 ~XLineManager ()
 Destructor.
IdentHostPair IdentSplit (const std::string &ident_and_host)
 Split an ident and host into two seperate strings.
void CheckELines ()
 Checks what users match e:lines and sets their ban exempt flag accordingly.
XLineLookupGetAll (const std::string &type)
 Get all lines of a certain type to an XLineLookup (std::map<std::string, XLine*>).
void DelAll (const std::string &type)
 Remove all lines of a certain type.
std::vector< std::stringGetAllTypes ()
 Return all known types of line currently stored by the XLineManager.
bool AddLine (XLine *line, User *user)
 Add a new XLine.
bool DelLine (const char *hostmask, const std::string &type, User *user, bool simulate=false)
 Delete an XLine.
bool RegisterFactory (XLineFactory *xlf)
 Registers an xline factory.
bool UnregisterFactory (XLineFactory *xlf)
 Unregisters an xline factory.
XLineFactoryGetFactory (const std::string &type)
 Get the XLineFactory for a specific type.
XLineMatchesLine (const std::string &type, User *user)
 Check if a user matches an XLine.
XLineMatchesLine (const std::string &type, const std::string &pattern)
 Check if a pattern matches an XLine.
void ExpireLine (ContainerIter container, LookupIter item)
 Expire a line given two iterators which identify it in the main map.
void ApplyLines ()
 Apply any new lines that are pending to be applied.
void InvokeStats (const std::string &type, int numeric, User *user, string_list &results)
 Handle /STATS for a given type.

Protected Attributes

InspIRCdServerInstance
 The owner/creator of this class.
std::vector< XLine * > pending_lines
 Used to hold XLines which have not yet been applied.
XLineFactMap line_factory
 Current xline factories.
GLineFactoryGFact
 Core xline factories for G/E/K/Q/Z lines (These generate GLine, ELine, KLine, QLine and ZLine respectively).
ELineFactoryEFact
KLineFactoryKFact
QLineFactoryQFact
ZLineFactoryZFact
XLineContainer lookup_lines
 Container of all lines, this is a map of maps which allows for fast lookup for add/remove of a line, and the shortest possible timed O(n) for checking a user against a line.

Detailed Description

XLineManager is a class used to manage glines, klines, elines, zlines and qlines, or any other line created by a module.

It also manages XLineFactory classes which can generate a specialized XLine for use by another module.

Definition at line 460 of file xline.h.


Constructor & Destructor Documentation

XLineManager::XLineManager InspIRCd Instance  ) 
 

Constructor.

Parameters:
Instance A pointer to the creator object

Definition at line 390 of file xline.cpp.

References EFact, GFact, KFact, QFact, RegisterFactory(), and ZFact.

XLineManager::~XLineManager  ) 
 

Destructor.

Definition at line 405 of file xline.cpp.

References EFact, GFact, KFact, lookup_lines, QFact, UnregisterFactory(), and ZFact.


Member Function Documentation

bool XLineManager::AddLine XLine line,
User user
 

Add a new XLine.

Parameters:
line The line to be added
user The user adding the line or NULL for the local server
Returns:
True if the line was added successfully

Definition at line 166 of file xline.cpp.

References XLineFactory::AutoApplyToUserList(), InspIRCd::BanCache, XLine::Displayable(), ExpireLine(), FOREACH_MOD, GetFactory(), I_OnAddLine, lookup_lines, pending_lines, BanCacheManager::RemoveEntries(), ServerInstance, InspIRCd::Time(), and XLine::type.

Referenced by TreeSocket::AddLine(), DoELine(), DoKLine(), DoQLine(), DoZLine(), CommandSvshold::Handle(), cmd_shun::Handle(), CommandRLine::Handle(), CommandCBan::Handle(), DNSBLResolver::OnLookupComplete(), FilterBase::OnPreCommand(), ModuleAntiBear::OnPreCommand(), ModuleConnectBan::OnUserConnect(), FilterBase::OnUserPreNotice(), and ModuleXLineDB::ReadDatabase().

void XLineManager::ApplyLines  ) 
 

Apply any new lines that are pending to be applied.

This will only apply lines in the pending_lines list, to save on CPU time.

Definition at line 342 of file xline.cpp.

References XLine::Apply(), UserManager::local_users, XLine::Matches(), pending_lines, ServerInstance, and InspIRCd::Users.

Referenced by TreeSocket::AddLine(), TreeServer::FinishBurst(), CommandSvshold::Handle(), cmd_shun::Handle(), CommandRLine::Handle(), CommandCBan::Handle(), InspIRCd::InspIRCd(), DNSBLResolver::OnLookupComplete(), FilterBase::OnPreCommand(), ModuleAntiBear::OnPreCommand(), ModuleConnectBan::OnUserConnect(), FilterBase::OnUserPreNotice(), and InspIRCd::Run().

void XLineManager::CheckELines  ) 
 

Checks what users match e:lines and sets their ban exempt flag accordingly.

Definition at line 60 of file xline.cpp.

References User::exempt, UserManager::local_users, lookup_lines, XLine::Matches(), ServerInstance, and InspIRCd::Users.

Referenced by DoneELine(), InspIRCd::InspIRCd(), InspIRCd::Run(), and ELine::Unset().

void XLineManager::DelAll const std::string type  ) 
 

Remove all lines of a certain type.

Definition at line 118 of file xline.cpp.

References ExpireLine(), and lookup_lines.

Referenced by ModuleRLine::OnRehash(), ModuleCBan::~ModuleCBan(), ModuleRLine::~ModuleRLine(), ModuleShun::~ModuleShun(), and ModuleSVSHold::~ModuleSVSHold().

bool XLineManager::DelLine const char *  hostmask,
const std::string type,
User user,
bool  simulate = false
 

Delete an XLine.

Parameters:
hostmask The xline-specific string identifying the line, e.g. "*@foo"
type The type of xline
user The user removing the line or NULL if its the local server
simulate If this is true, don't actually remove the line, just return
Returns:
True if the line was deleted successfully

Definition at line 202 of file xline.cpp.

References InspIRCd::BanCache, FOREACH_MOD, I_OnDelLine, lookup_lines, pending_lines, BanCacheManager::RemoveEntries(), and ServerInstance.

Referenced by TreeSocket::DelLine(), CommandSvshold::Handle(), cmd_shun::Handle(), CommandRLine::Handle(), and CommandCBan::Handle().

void XLineManager::ExpireLine ContainerIter  container,
LookupIter  item
 

Expire a line given two iterators which identify it in the main map.

Parameters:
container Iterator to the first level of entries the map
item Iterator to the second level of entries in the map

Definition at line 321 of file xline.cpp.

References FOREACH_MOD, I_OnExpireLine, and pending_lines.

Referenced by AddLine(), DelAll(), GetAll(), InvokeStats(), and MatchesLine().

XLineLookup * XLineManager::GetAll const std::string type  ) 
 

Get all lines of a certain type to an XLineLookup (std::map<std::string, XLine*>).

NOTE: When this function runs any expired items are removed from the list before it is returned to the caller.

Parameters:
The type to look up
Returns:
A list of all XLines of the given type.

Definition at line 93 of file xline.cpp.

References ExpireLine(), lookup_lines, ServerInstance, and InspIRCd::Time().

Referenced by TreeSocket::SendXLines().

std::vector< std::string > XLineManager::GetAllTypes  ) 
 

Return all known types of line currently stored by the XLineManager.

Returns:
A vector containing all known line types currently stored in the main list.

Definition at line 134 of file xline.cpp.

References lookup_lines.

Referenced by TreeSocket::SendXLines().

XLineFactory * XLineManager::GetFactory const std::string type  ) 
 

Get the XLineFactory for a specific type.

Returns NULL if there is no known handler for this xline type.

Parameters:
type The type of XLine you require the XLineFactory for

Definition at line 678 of file xline.cpp.

References line_factory.

Referenced by AddLine(), TreeSocket::AddLine(), and ModuleXLineDB::ReadDatabase().

IdentHostPair XLineManager::IdentSplit const std::string ident_and_host  ) 
 

Split an ident and host into two seperate strings.

This allows for faster matching.

Definition at line 142 of file xline.cpp.

Referenced by DoELine(), DoKLine(), KLineFactory::Generate(), ELineFactory::Generate(), and GLineFactory::Generate().

void XLineManager::InvokeStats const std::string type,
int  numeric,
User user,
string_list results
 

Handle /STATS for a given type.

NOTE: Any items in the list for this particular line type which have expired will be expired and removed before the list is displayed.

Parameters:
numeric The numeric to give to each result line
user The username making the query
results The string_list to receive the results

Definition at line 359 of file xline.cpp.

References InspIRCd::Config, ConvToStr(), ExpireLine(), lookup_lines, User::nick, ServerInstance, ServerConfig::ServerName, and InspIRCd::Time().

Referenced by ModuleSVSHold::OnStats(), ModuleShun::OnStats(), ModuleRLine::OnStats(), and ModuleCBan::OnStats().

XLine * XLineManager::MatchesLine const std::string type,
const std::string pattern
 

Check if a pattern matches an XLine.

Parameters:
type The type of line to look up
pattern A pattern string specific to the xline type
Returns:
The matching XLine if there is a match, or NULL if there is no match

Definition at line 285 of file xline.cpp.

References ExpireLine(), lookup_lines, ServerInstance, and InspIRCd::Time().

XLine * XLineManager::MatchesLine const std::string type,
User user
 

Check if a user matches an XLine.

Parameters:
type The type of line to look up
user The user to match against (what is checked is specific to the xline type)
Returns:
The reason for the line if there is a match, or NULL if there is no match

Definition at line 248 of file xline.cpp.

References ExpireLine(), lookup_lines, ServerInstance, and InspIRCd::Time().

Referenced by UserManager::AddUser(), User::CheckLines(), ModuleShun::OnPreCommand(), ModuleShun::OnUserConnect(), ModuleRLine::OnUserConnect(), ModuleRLine::OnUserPostNick(), ModuleCBan::OnUserPreJoin(), and ModuleSVSHold::OnUserPreNick().

bool XLineManager::RegisterFactory XLineFactory xlf  ) 
 

Registers an xline factory.

An xline factory is a class which when given a particular xline type, will generate a new XLine specialized to that type. For example if you pass the XLineFactory that handles glines some data it will return a pointer to a GLine, polymorphically represented as XLine. This is used where you do not know the full details of the item you wish to create, e.g. in a server protocol module like m_spanningtree, when you receive xlines from other servers.

Parameters:
xlf XLineFactory pointer to register

Definition at line 654 of file xline.cpp.

References XLineFactory::GetType(), and line_factory.

Referenced by ModuleCBan::ModuleCBan(), ModuleRLine::ModuleRLine(), ModuleShun::ModuleShun(), ModuleSVSHold::ModuleSVSHold(), and XLineManager().

bool XLineManager::UnregisterFactory XLineFactory xlf  ) 
 

Unregisters an xline factory.

You must do this when your module unloads.

Parameters:
xlf XLineFactory pointer to unregister

Definition at line 666 of file xline.cpp.

References XLineFactory::GetType(), and line_factory.

Referenced by ModuleCBan::~ModuleCBan(), ModuleRLine::~ModuleRLine(), ModuleShun::~ModuleShun(), ModuleSVSHold::~ModuleSVSHold(), and ~XLineManager().


Member Data Documentation

ELineFactory* XLineManager::EFact [protected]
 

Definition at line 480 of file xline.h.

Referenced by XLineManager(), and ~XLineManager().

GLineFactory* XLineManager::GFact [protected]
 

Core xline factories for G/E/K/Q/Z lines (These generate GLine, ELine, KLine, QLine and ZLine respectively).

Definition at line 479 of file xline.h.

Referenced by XLineManager(), and ~XLineManager().

KLineFactory* XLineManager::KFact [protected]
 

Definition at line 481 of file xline.h.

Referenced by XLineManager(), and ~XLineManager().

XLineFactMap XLineManager::line_factory [protected]
 

Current xline factories.

Definition at line 473 of file xline.h.

Referenced by GetFactory(), RegisterFactory(), and UnregisterFactory().

XLineContainer XLineManager::lookup_lines [protected]
 

Container of all lines, this is a map of maps which allows for fast lookup for add/remove of a line, and the shortest possible timed O(n) for checking a user against a line.

Definition at line 490 of file xline.h.

Referenced by AddLine(), CheckELines(), DelAll(), DelLine(), GetAll(), GetAllTypes(), InvokeStats(), MatchesLine(), and ~XLineManager().

std::vector<XLine *> XLineManager::pending_lines [protected]
 

Used to hold XLines which have not yet been applied.

Definition at line 469 of file xline.h.

Referenced by AddLine(), ApplyLines(), DelLine(), and ExpireLine().

QLineFactory* XLineManager::QFact [protected]
 

Definition at line 482 of file xline.h.

Referenced by XLineManager(), and ~XLineManager().

InspIRCd* XLineManager::ServerInstance [protected]
 

The owner/creator of this class.

Definition at line 465 of file xline.h.

Referenced by AddLine(), ApplyLines(), CheckELines(), DelLine(), GetAll(), InvokeStats(), and MatchesLine().

ZLineFactory* XLineManager::ZFact [protected]
 

Definition at line 483 of file xline.h.

Referenced by XLineManager(), and ~XLineManager().


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