InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
InspIRCd Class Reference

#include <inspircd.h>

Public Member Functions

std::string GetUID ()
 
UserFindUUID (const std::string &uid)
 
UserFindUUID (const char *uid)
 
void BuildISupport ()
 
time_t Time ()
 
long Time_ns ()
 
void UpdateTime ()
 
std::string GenRandomStr (int length, bool printable=true)
 
unsigned long GenRandomInt (unsigned long max)
 
int BindPorts (FailedPortList &failed_ports)
 
bool BindSocket (int sockfd, int port, const char *addr, bool dolisten=true)
 
std::string GetServerDescription (const std::string &servername)
 
UserFindNick (const std::string &nick)
 
UserFindNick (const char *nick)
 
UserFindNickOnly (const char *nick)
 
UserFindNickOnly (const std::string &nick)
 
ChannelFindChan (const std::string &chan)
 
ChannelFindChan (const char *chan)
 
void CheckRoot ()
 
bool OpenLog (char **argv, int argc)
 
void SignalHandler (int signal)
 
void Exit (int status)
 
long ChannelCount ()
 
void SendError (const std::string &s)
 
bool AddResolver (Resolver *r, bool cached)
 
void AddCommand (Command *f)
 
void SendMode (const std::vector< std::string > &parameters, User *user)
 
void SendGlobalMode (const std::vector< std::string > &parameters, User *user)
 
CmdResult CallCommandHandler (const std::string &commandname, const std::vector< std::string > &parameters, User *user)
 
bool IsValidModuleCommand (const std::string &commandname, int pcnt, User *user)
 
bool IsValidMask (const std::string &mask)
 
void RehashServer ()
 
bool NickMatchesEveryone (const std::string &nick, User *user)
 
bool IPMatchesEveryone (const std::string &ip, User *user)
 
bool HostMatchesEveryone (const std::string &mask, User *user)
 
long Duration (const std::string &str)
 
int PassCompare (Extensible *ex, const std::string &data, const std::string &input, const std::string &hashtype)
 
bool ULine (const std::string &server)
 
bool SilentULine (const std::string &server)
 
std::string GetVersionString (bool rawversion=false)
 
void WritePID (const std::string &filename)
 
 InspIRCd (int argc, char **argv)
 
void SendWhoisLine (User *user, User *dest, int numeric, const std::string &text)
 
void SendWhoisLine (User *user, User *dest, int numeric, const char *format,...)
 
void DoWhois (User *user, User *dest, unsigned long signon, unsigned long idle, const char *nick)
 
void Restart (const std::string &reason)
 
void Cleanup ()
 
void RehashUsersAndChans ()
 
void ResetMaxBans ()
 
std::string TimeString (time_t curtime)
 
int Run ()
 
void AddExtBanChar (char c)
 
char * GetReadBuffer ()
 

Static Public Member Functions

static void SetSignal (int signal)
 
static void QuickExit (int status)
 
static bool Match (const std::string &str, const std::string &mask, unsigned const char *map=NULL)
 
static bool Match (const char *str, const char *mask, unsigned const char *map=NULL)
 
static bool MatchCIDR (const std::string &str, const std::string &mask, unsigned const char *map=NULL)
 
static bool MatchCIDR (const char *str, const char *mask, unsigned const char *map=NULL)
 
static void StripColor (std::string &sentence)
 
static void ProcessColors (file_cache &input)
 

Public Attributes

CullList GlobalCulls
 
ActionList AtomicActions
 
IsNickHandler HandleIsNick
 
IsIdentHandler HandleIsIdent
 
FloodQuitUserHandler HandleFloodQuitUser
 
OnCheckExemptionHandler HandleOnCheckExemption
 
IsChannelHandler HandleIsChannel
 
IsSIDHandler HandleIsSID
 
RehashHandler HandleRehash
 
GenRandomHandler HandleGenRandom
 
FakeUserFakeClient
 
time_t startup_time
 
std::string ConfigFileName
 
ExtensionManager Extensions
 
ModeParserModes
 
CommandParserParser
 
SocketEngineSE
 
ThreadEngineThreads
 
ConfigReaderThreadConfigThread
 
LogManagerLogs
 
ModuleManagerModules
 
BanCacheManagerBanCache
 
serverstatsstats
 
ServerConfigConfig
 
SnomaskManagerSNO
 
DNSRes
 
TimerManagerTimers
 
XLineManagerXLines
 
UserManagerUsers
 
chan_hash * chanlist
 
std::vector< ListenSocket * > ports
 
ProtocolInterfacePI
 
LocalIntExt NICKForced
 
LocalStringExt OperQuit
 
caller2< void, char *, size_t > GenRandom
 
caller2< bool, const char
*, size_t > 
IsChannel
 
caller1< bool, const
std::string & > 
IsSID
 
caller1< void, const
std::string & > 
Rehash
 
caller2< bool, const char
*, size_t > 
IsNick
 
caller1< bool, const char * > IsIdent
 
caller1< void, User * > FloodQuitUser
 
caller3< ModResult, User
*, Channel *, const
std::string & > 
OnCheckExemption
 

Static Public Attributes

static const char LogHeader []
 
static sig_atomic_t s_signal = 0
 

Friends

class TestSuite
 

Detailed Description

The main class of the irc server. This class contains instances of all the other classes in this software. Amongst other things, it contains a ModeParser, a DNS object, a CommandParser object, and a list of active Module objects, and facilities for Module objects to interact with the core system it implements.

Constructor & Destructor Documentation

InspIRCd::InspIRCd ( int  argc,
char **  argv 
)

This constructor initialises all the subsystems and reads the config file.

Parameters
argcThe argument count passed to main()
argvThe argument list passed to main()
Exceptions
<anything>If anything is thrown from here and makes it to you, you should probably just give up and go home. Yes, really. It's that bad. Higher level classes should catch any non-fatal exceptions.

Member Function Documentation

void InspIRCd::AddCommand ( Command f)
inline

Add a command to this server's command parser

Parameters
fA Command command handler object to add
Exceptions
ModuleExceptionWill throw ModuleExcption if the command already exists
void InspIRCd::AddExtBanChar ( char  c)

Adds an extban char to the 005 token.

bool InspIRCd::AddResolver ( Resolver r,
bool  cached 
)

Add a dns Resolver class to this server's active set

Parameters
rThe resolver to add
cachedIf this value is true, then the cache will be searched for the DNS result, immediately. If the value is false, then a request will be sent to the nameserver, and the result will not be immediately available. You should usually use the boolean value which you passed to the Resolver constructor, which Resolver will set appropriately depending on if cached results are available and haven't expired. It is however safe to force this value to false, forcing a remote DNS lookup, but not an update of the cache.
Returns
True if the operation completed successfully. Note that if this method returns true, you should not attempt to access the resolver class you pass it after this call, as depending upon the request given, the object may be deleted!
int InspIRCd::BindPorts ( FailedPortList &  failed_ports)

Bind all ports specified in the configuration file.

Returns
The number of ports bound without error
bool InspIRCd::BindSocket ( int  sockfd,
int  port,
const char *  addr,
bool  dolisten = true 
)

Binds a socket on an already open file descriptor

Parameters
sockfdA valid file descriptor of an open socket
portThe port number to bind to
addrThe address to bind to (IP only)
dolistenShould this port be listened on?
Returns
True if the port was bound successfully

This will bind a socket to a port. It works for UDP/TCP. It can only bind to IP addresses, if you wish to bind to hostnames you should first resolve them using class 'Resolver'.

void InspIRCd::BuildISupport ( )

Build the ISUPPORT string by triggering all modules On005Numeric events

CmdResult InspIRCd::CallCommandHandler ( const std::string &  commandname,
const std::vector< std::string > &  parameters,
User user 
)

Call the handler for a given command.

Parameters
commandnameThe command whos handler you wish to call
parametersThe mode parameters
userThe user to execute the command as
Returns
True if the command handler was called successfully
long InspIRCd::ChannelCount ( )

Return a count of channels on the network

Returns
The number of channels
void InspIRCd::CheckRoot ( )

Check we aren't running as root, and exit if we are

Returns
Depending on the configuration, this function may never return
void InspIRCd::Cleanup ( )

Prepare the ircd for restart or shutdown. This function unloads all modules which can be unloaded, closes all open sockets, and closes the logfile.

void InspIRCd::DoWhois ( User user,
User dest,
unsigned long  signon,
unsigned long  idle,
const char *  nick 
)

Handle /WHOIS

long InspIRCd::Duration ( const std::string &  str)

Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s

Parameters
strA string containing a time in the form 1y2w3d4h6m5s (one year, two weeks, three days, four hours, six minutes and five seconds)
Returns
The total number of seconds

Refactored by Brain, Jun 2009. Much faster with some clever O(1) array lookups and pointer maths.

void InspIRCd::Exit ( int  status)

Causes the server to exit after unloading modules and closing all open file descriptors.

Parameters
statusThe exit code to give to the operating system (See the ExitStatus enum for valid values)
Channel * InspIRCd::FindChan ( const std::string &  chan)

Find a channel in the channels hash

Parameters
chanThe channel to find
Returns
A pointer to the channel, or NULL if the channel does not exist
Channel * InspIRCd::FindChan ( const char *  chan)

Find a channel in the channels hash

Parameters
chanThe channel to find
Returns
A pointer to the channel, or NULL if the channel does not exist
User * InspIRCd::FindNick ( const std::string &  nick)

Find a user in the nick hash. If the user cant be found in the nick hash check the uuid hash

Parameters
nickThe nickname to find
Returns
A pointer to the user, or NULL if the user does not exist
User * InspIRCd::FindNick ( const char *  nick)

Find a user in the nick hash. If the user cant be found in the nick hash check the uuid hash

Parameters
nickThe nickname to find
Returns
A pointer to the user, or NULL if the user does not exist
User * InspIRCd::FindNickOnly ( const char *  nick)

Find a user in the nick hash ONLY

User * InspIRCd::FindNickOnly ( const std::string &  nick)

Find a user in the nick hash ONLY

User * InspIRCd::FindUUID ( const std::string &  uid)

Find a user in the UUID hash

Parameters
uidThe UUID to find
Returns
A pointer to the user, or NULL if the user does not exist
User * InspIRCd::FindUUID ( const char *  uid)

Find a user in the UUID hash

Parameters
uidThe UUID to find
Returns
A pointer to the user, or NULL if the user does not exist
unsigned long InspIRCd::GenRandomInt ( unsigned long  max)

Generate a random integer. This is generally more secure than rand()

std::string InspIRCd::GenRandomStr ( int  length,
bool  printable = true 
)

Generate a random string with the given length

Parameters
lengthThe length in bytes
printableif false, the string will use characters 0-255; otherwise, it will be limited to 0x30-0x7E ('0'-'~', nonspace printable characters)
std::string InspIRCd::GetServerDescription ( const std::string &  servername)

Gets the GECOS (description) field of the given server. If the servername is not that of the local server, the name is passed to handling modules which will attempt to determine the GECOS that bleongs to the given servername.

Parameters
servernameThe servername to find the description of
Returns
The description of this server, or of the local server
std::string InspIRCd::GetUID ( )

Returns the next available UID for this server.

std::string InspIRCd::GetVersionString ( bool  rawversion = false)

Returns the full version string of this ircd

Returns
The version string
bool InspIRCd::HostMatchesEveryone ( const std::string &  mask,
User user 
)

Check if the given hostmask matches too many users, send errors to the given user

Parameters
maskA hostmask to match against
userA user to send error text to
Returns
True if the host matches too many users
bool InspIRCd::IPMatchesEveryone ( const std::string &  ip,
User user 
)

Check if the given IP mask matches too many users, send errors to the given user

Parameters
ipAn ipmask to match against
userA user to send error text to
Returns
True if the ip matches too many users
bool InspIRCd::IsValidMask ( const std::string &  mask)

Return true if the given parameter is a valid nick!user@host mask

Parameters
maskA nick!user@host masak to match against
Returns
True i the mask is valid
bool InspIRCd::IsValidModuleCommand ( const std::string &  commandname,
int  pcnt,
User user 
)

Return true if the command is a module-implemented command and the given parameters are valid for it

Parameters
commandnameThe command name to check
pcntThe parameter count
userThe user to test-execute the command as
Returns
True if the command handler is a module command, and there are enough parameters and the user has permission to the command
CoreExport bool InspIRCd::Match ( const std::string &  str,
const std::string &  mask,
unsigned const char *  map = NULL 
)
static

Match two strings using pattern matching, optionally, with a map to check case against (may be NULL). If map is null, match will be case insensitive.

Parameters
strThe literal string to match against
maskThe glob pattern to match against.
mapThe character map to use when matching.
CoreExport bool InspIRCd::MatchCIDR ( const std::string &  str,
const std::string &  mask,
unsigned const char *  map = NULL 
)
static

Match two strings using pattern matching, optionally, with a map to check case against (may be NULL). If map is null, match will be case insensitive. Supports CIDR patterns as well as globs.

Parameters
strThe literal string to match against
maskThe glob or CIDR pattern to match against.
mapThe character map to use when matching.
bool InspIRCd::NickMatchesEveryone ( const std::string &  nick,
User user 
)

Check if the given nickmask matches too many users, send errors to the given user

Parameters
nickA nickmask to match against
userA user to send error text to
Returns
True if the nick matches too many users
bool InspIRCd::OpenLog ( char **  argv,
int  argc 
)

Determine the right path for, and open, the logfile

Parameters
argvThe argv passed to main() initially, used to calculate program path
argcThe argc passed to main() initially, used to calculate program path
Returns
True if the log could be opened, false if otherwise
int InspIRCd::PassCompare ( Extensible ex,
const std::string &  data,
const std::string &  input,
const std::string &  hashtype 
)

Attempt to compare a password to a string from the config file. This will be passed to handling modules which will compare the data against possible hashed equivalents in the input string.

Parameters
exThe object (user, server, whatever) causing the comparison.
dataThe data from the config file
inputThe data input by the oper
hashtypeThe hash from the config file
Returns
0 if the strings match, 1 or -1 if they do not
void InspIRCd::ProcessColors ( file_cache &  input)
static

Parses color codes from string values to actual color codes

Parameters
inputThe data to process
void InspIRCd::QuickExit ( int  status)
static

Causes the server to exit immediately with exit code 0. The status code is required for signal handlers, and ignored.

void InspIRCd::RehashServer ( )

Rehash the local server

void InspIRCd::RehashUsersAndChans ( )

This copies the user and channel hash_maps into new hash maps. This frees memory used by the hash_map allocator (which it neglects to free, most of the time, using tons of ram)

Because hash_map doesn't free its buckets when we delete items, we occasionally recreate the hash to free them up. We do this by copying the entries from the old hash to a new hash, causing all empty buckets to be weeded out of the hash. Since this is quite expensive, it's not done very often.

void InspIRCd::ResetMaxBans ( )

Resets the cached max bans value on all channels. Called by rehash.

void InspIRCd::Restart ( const std::string &  reason)

Restart the server. This function will not return. If an error occurs, it will throw an instance of CoreException.

Parameters
reasonThe restart reason to show to all clients
Exceptions
CoreExceptionAn instance of CoreException indicating the error from execv().
int InspIRCd::Run ( )

Begin execution of the server. NOTE: this function NEVER returns. Internally, it will repeatedly loop.

Returns
The return value for this function is undefined.
void InspIRCd::SendError ( const std::string &  s)

Send an error notice to all local users, opered and unopered

Parameters
sThe error string to send
void InspIRCd::SendGlobalMode ( const std::vector< std::string > &  parameters,
User user 
)

Send a modechange and route it to the network. The parameters provided are identical to that sent to the handler for class cmd_mode.

Parameters
parametersThe mode parameters
userThe user to send error messages to
void InspIRCd::SendMode ( const std::vector< std::string > &  parameters,
User user 
)

Send a modechange. The parameters provided are identical to that sent to the handler for class cmd_mode.

Parameters
parametersThe mode parameters
userThe user to send error messages to
void InspIRCd::SendWhoisLine ( User user,
User dest,
int  numeric,
const std::string &  text 
)

Send a line of WHOIS data to a user.

Parameters
useruser to send the line to
destuser being WHOISed
numericNumeric to send
textText of the numeric
void InspIRCd::SendWhoisLine ( User user,
User dest,
int  numeric,
const char *  format,
  ... 
)

Send a line of WHOIS data to a user.

Parameters
useruser to send the line to
destuser being WHOISed
numericNumeric to send
formatFormat string for the numeric
...Parameters for the format string
void InspIRCd::SetSignal ( int  signal)
static

Sets the signal recieved

Parameters
signalthe signal recieved
void InspIRCd::SignalHandler ( int  signal)

Handles incoming signals after being set

Parameters
signalthe signal recieved
bool InspIRCd::SilentULine ( const std::string &  server)

Returns true if the uline is 'silent' (doesnt generate remote connect notices etc).

void InspIRCd::StripColor ( std::string &  sentence)
static

Strips all color codes from the given string

Parameters
sentenceThe string to strip from
time_t InspIRCd::Time ( )
inline

Get the current time Because this only calls time() once every time around the mainloop, it is much faster than calling time() directly.

Returns
The current time as an epoch value (time_t)
long InspIRCd::Time_ns ( )
inline

The fractional time at the start of this mainloop iteration (nanoseconds)

std::string InspIRCd::TimeString ( time_t  curtime)

Return a time_t as a human-readable string.

bool InspIRCd::ULine ( const std::string &  server)

Check if a given server is a uline. An empty string returns true, this is by design.

Parameters
serverThe server to check for uline status
Returns
True if the server is a uline OR the string is empty
void InspIRCd::UpdateTime ( )

Update the current time. Don't call this unless you have reason to do so.

void InspIRCd::WritePID ( const std::string &  filename)

Attempt to write the process id to a given file

Parameters
filenameThe PID file to attempt to write to
Returns
This function may bail if the file cannot be written

Member Data Documentation

ActionList InspIRCd::AtomicActions

Actions that must happen outside of the current call stack

BanCacheManager* InspIRCd::BanCache

BanCacheManager is used to speed up checking of restrictions on connection to the IRCd.

chan_hash* InspIRCd::chanlist

Channel list, a hash_map containing all channels XXX move to channel manager class

ServerConfig* InspIRCd::Config

Server Config class, holds configuration file data

std::string InspIRCd::ConfigFileName

Config file pathname specified on the commandline or via ./configure

ConfigReaderThread* InspIRCd::ConfigThread

The thread/class used to read config files in REHASH and on startup

FakeUser* InspIRCd::FakeClient

Globally accessible fake user record. This is used to force mode changes etc across s2s, etc.. bit ugly, but.. better than how this was done in 1.1 Reason for it: kludge alert! SendMode expects a User* to send the numeric replies back to, so we create it a fake user that isnt in the user hash and set its descriptor to FD_MAGIC_NUMBER so the data falls into the abyss :p

caller1<void, User*> InspIRCd::FloodQuitUser

Quit a user for excess flood, and if they are not fully registered yet, temporarily zline their IP.

Parameters
currentuser to quit
caller2<void, char*, size_t> InspIRCd::GenRandom

Fill a buffer with random bits

CullList InspIRCd::GlobalCulls

Global cull list, will be processed on next iteration

caller2<bool, const char*, size_t> InspIRCd::IsChannel

Return true if a channel name is valid

Parameters
chnameA channel name to verify
Returns
True if the name is valid
caller1<bool, const char*> InspIRCd::IsIdent

Return true if an ident is valid

Parameters
Anident to verify
Returns
True if the ident is valid
caller2<bool, const char*, size_t> InspIRCd::IsNick

Return true if a nickname is valid

Parameters
nA nickname to verify
Returns
True if the nick is valid
caller1<bool, const std::string&> InspIRCd::IsSID

Return true if str looks like a server ID

Parameters
stringto check against
const char InspIRCd::LogHeader
static
Initial value:
=
"Log started for " VERSION " (" REVISION ", " MODULE_INIT_STR ")"
" - compiled on " SYSTEM
LogManager* InspIRCd::Logs

LogManager handles logging.

ModeParser* InspIRCd::Modes

Mode handler, handles mode setting and removal

ModuleManager* InspIRCd::Modules

ModuleManager contains everything related to loading/unloading modules.

LocalIntExt InspIRCd::NICKForced

Holds extensible for user nickforced

caller3<ModResult, User*, Channel*, const std::string&> InspIRCd::OnCheckExemption

Called to check whether a channel restriction mode applies to a user

Parameters
Userthat is attempting some action
Channelthat the action is being performed on
Actionname
LocalStringExt InspIRCd::OperQuit

Holds extensible for user operquit

CommandParser* InspIRCd::Parser

Command parser, handles client to server commands

ProtocolInterface* InspIRCd::PI

Protocol interface, overridden by server protocol modules

std::vector<ListenSocket*> InspIRCd::ports

List of the open ports

caller1<void, const std::string&> InspIRCd::Rehash

Rehash the local server

DNS* InspIRCd::Res

DNS class, provides resolver facilities to the core and modules

sig_atomic_t InspIRCd::s_signal = 0
static

Set to the current signal recieved

SocketEngine* InspIRCd::SE

Socket engine, handles socket activity events

SnomaskManager* InspIRCd::SNO

Snomask manager - handles routing of snomask messages to opers.

time_t InspIRCd::startup_time

Time this ircd was booted

serverstats* InspIRCd::stats

Stats class, holds miscellaneous stats counters

ThreadEngine* InspIRCd::Threads

Thread engine, Handles threading where required

TimerManager* InspIRCd::Timers

Timer manager class, triggers Timer timer events

UserManager* InspIRCd::Users

User manager. Various methods and data associated with users.

XLineManager* InspIRCd::XLines

X-Line manager. Handles G/K/Q/E line setting, removal and matching


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