From fa82890696c498f38643df7df6891434c91c9269 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 24 Apr 2010 17:18:25 -0400 Subject: Moved Commands stuff to its own file and changed Command::name to be ci::string - Will be used after hashing system is rewritten --- include/commands.h | 113 +++++++++++++++++++++++++++++++++++++++++++++++++---- include/modules.h | 92 +------------------------------------------ include/pseudo.h | 2 +- 3 files changed, 108 insertions(+), 99 deletions(-) (limited to 'include') diff --git a/include/commands.h b/include/commands.h index d139fa01a..5d43f556b 100644 --- a/include/commands.h +++ b/include/commands.h @@ -11,17 +11,116 @@ * */ - #include "modules.h" +#ifndef COMMAND_H_ +#define COMMAND_H_ -/*************************************************************************/ +#define MAX_CMD_HASH 1024 +#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */ -/* Routines for looking up commands. Command lists are arrays that must be - * terminated with a NULL name. - */ +#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */ +#define BOTSERV BS_cmdTable +#define MEMOSERV MS_cmdTable +#define NICKSERV NS_cmdTable +#define CHANSERV CS_cmdTable +#define OPERSERV OS_cmdTable + +#ifndef _WIN32 +#define MDE +#else +#ifndef MODULE_COMPILE +#define MDE __declspec(dllexport) +#else +#define MDE __declspec(dllimport) +#endif +#endif + +/** The return value from commands. + * */ +enum CommandReturn +{ + MOD_CONT, + MOD_STOP +}; + +class Command; extern MDE Command *lookup_cmd(Command *list, char *name); extern MDE void mod_help_cmd(char *service, User *u, CommandHash *cmdTable[], const char *cmd); extern MDE void mod_run_cmd(const std::string &service, User *u, CommandHash *cmdTable[], const char *cmd); -//extern MDE void do_help_limited(char *service, User * u, Command * c); -/*************************************************************************/ +struct CommandHash { + char *name; /* Name of the command */ + Command *c; /* Actual command */ + CommandHash *next; /* Next command */ +}; + +extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH]; +extern MDE CommandHash *BOTSERV[MAX_CMD_HASH]; +extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH]; +extern MDE CommandHash *NICKSERV[MAX_CMD_HASH]; +extern MDE CommandHash *CHANSERV[MAX_CMD_HASH]; +extern MDE CommandHash *OPERSERV[MAX_CMD_HASH]; + +enum CommandFlag +{ + CFLAG_ALLOW_UNREGISTERED, + CFLAG_ALLOW_FORBIDDEN, + CFLAG_ALLOW_SUSPENDED, + CFLAG_ALLOW_UNREGISTEREDCHANNEL, + CFLAG_STRIP_CHANNEL, + CFLAG_DISABLE_FANTASY +}; + +/** Every services command is a class, inheriting from Command. + */ +class CoreExport Command : public Flags +{ + public: + size_t MaxParams; + size_t MinParams; + ci::string name; + std::string permission; + + /** Create a new command. + * @param sname The command name + * @param min_params The minimum number of parameters the parser will require to execute this command + * @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument. + * NOTE: If max_params is not set (default), there is no limit to the max number of params. + */ + Command(const ci::string &sname, size_t min_params, size_t max_params = 0, const std::string &spermission = ""); + + virtual ~Command(); + + /** Execute this command. + * @param u The user executing the command. + */ + virtual CommandReturn Execute(User *u, const std::vector &); + + /** Requested when the user is requesting help on this command. Help on this command should be sent to the user. + * @param u The user requesting help + * @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of +"FOO BAR LOL") + * @return true if help was provided to the user, false otherwise. + */ + virtual bool OnHelp(User *u, const ci::string &subcommand); + + /** Requested when the user provides bad syntax to this command (not enough params, etc). + * @param u The user executing the command. + * @param subcommand The subcommand the user tried to use + */ + virtual void OnSyntaxError(User *u, const ci::string &subcommand); + + /** Set which command permission (e.g. chanserv/forbid) is required for this command. + * @param reststr The permission required to successfully execute this command + */ + void SetPermission(const std::string &reststr); + + /* Module related stuff */ + int core; /* Can this command be deleted? */ + char *mod_name; /* Name of the module who owns us, NULL for core's */ + char *service; /* Service we provide this command for */ + Command *next; +}; + +#endif + diff --git a/include/modules.h b/include/modules.h index bd553c2cc..dcaac342c 100644 --- a/include/modules.h +++ b/include/modules.h @@ -19,6 +19,7 @@ #include "timers.h" #include "hashcomp.h" #include "version.h" +#include "commands.h" /* Cross OS compatibility macros */ #ifdef _WIN32 @@ -113,23 +114,7 @@ enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFOR /*************************************************************************/ -#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */ -#define MAX_CMD_HASH 1024 -/** The return value from commands. - */ -enum CommandReturn -{ - MOD_CONT, - MOD_STOP -}; - -#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */ -#define BOTSERV BS_cmdTable -#define MEMOSERV MS_cmdTable -#define NICKSERV NS_cmdTable -#define CHANSERV CS_cmdTable -#define OPERSERV OS_cmdTable #define IRCD IRCD_cmdTable #define MODULE_HASH Module_table #define EVENT EVENT_cmdTable @@ -191,7 +176,6 @@ typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation; /*************************************************************************/ /* Structure for information about a *Serv command. */ -struct CommandHash; typedef struct ModuleLang_ ModuleLang; typedef struct ModuleHash_ ModuleHash; typedef struct Message_ Message; @@ -199,15 +183,6 @@ typedef struct MessageHash_ MessageHash; /*************************************************************************/ - - - -extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH]; -extern MDE CommandHash *BOTSERV[MAX_CMD_HASH]; -extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH]; -extern MDE CommandHash *NICKSERV[MAX_CMD_HASH]; -extern MDE CommandHash *CHANSERV[MAX_CMD_HASH]; -extern MDE CommandHash *OPERSERV[MAX_CMD_HASH]; extern MDE MessageHash *IRCD[MAX_CMD_HASH]; extern MDE ModuleHash *MODULE_HASH[MAX_CMD_HASH]; @@ -216,65 +191,6 @@ struct ModuleLang_ { char **argv; }; -enum CommandFlag -{ - CFLAG_ALLOW_UNREGISTERED, - CFLAG_ALLOW_FORBIDDEN, - CFLAG_ALLOW_SUSPENDED, - CFLAG_ALLOW_UNREGISTEREDCHANNEL, - CFLAG_STRIP_CHANNEL, - CFLAG_DISABLE_FANTASY -}; - -/** Every services command is a class, inheriting from Command. - */ -class CoreExport Command : public Flags -{ - public: - size_t MaxParams; - size_t MinParams; - std::string name; - std::string permission; - - /** Create a new command. - * @param min_params The minimum number of parameters the parser will require to execute this command - * @param max_params The maximum number of parameters the parser will create, after max_params, all will be combined into the last argument. - * NOTE: If max_params is not set (default), there is no limit to the max number of params. - */ - Command(const std::string &sname, size_t min_params, size_t max_params = 0, const std::string &spermission = ""); - - virtual ~Command(); - - /** Execute this command. - * @param u The user executing the command. - */ - virtual CommandReturn Execute(User *u, const std::vector &); - - /** Requested when the user is requesting help on this command. Help on this command should be sent to the user. - * @param u The user requesting help - * @param subcommand The subcommand the user is requesting help on, or an empty string. (e.g. /ns help set foo bar lol gives a subcommand of "FOO BAR LOL") - * @return true if help was provided to the user, false otherwise. - */ - virtual bool OnHelp(User *u, const ci::string &subcommand); - - /** Requested when the user provides bad syntax to this command (not enough params, etc). - * @param u The user executing the command. - * @param subcommand The subcommand the user tried to use - */ - virtual void OnSyntaxError(User *u, const ci::string &subcommand); - - /** Set which command permission (e.g. chanserv/forbid) is required for this command. - * @param reststr The permission required to successfully execute this command - */ - void SetPermission(const std::string &reststr); - - /* Module related stuff */ - int core; /* Can this command be deleted? */ - char *mod_name; /* Name of the module who owns us, NULL for core's */ - char *service; /* Service we provide this command for */ - Command *next; -}; - class Version { private: @@ -1324,12 +1240,6 @@ struct ModuleHash_ { ModuleHash *next; }; -struct CommandHash { - char *name; /* Name of the command */ - Command *c; /* Actual command */ - CommandHash *next; /* Next command */ -}; - struct Message_ { char *name; int (*func)(const char *source, int ac, const char **av); diff --git a/include/pseudo.h b/include/pseudo.h index d24c43963..3ad6b518a 100644 --- a/include/pseudo.h +++ b/include/pseudo.h @@ -11,7 +11,7 @@ * */ -#include "commands.h" +#include "modules.h" #include "language.h" #include "timers.h" #include "slist.h" -- cgit From c1d161dec451ea790ff87078b5d80b1f71a3e9f0 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 29 Apr 2010 17:31:34 -0400 Subject: Rewrote all of the server handling code --- include/extern.h | 36 +---------- include/modules.h | 9 +-- include/servers.h | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/services.h | 93 +--------------------------- 4 files changed, 188 insertions(+), 129 deletions(-) create mode 100644 include/servers.h (limited to 'include') diff --git a/include/extern.h b/include/extern.h index 5ede04dc8..79f1702f9 100644 --- a/include/extern.h +++ b/include/extern.h @@ -23,8 +23,6 @@ E void ModuleRunTimeDirCleanUp(); -E char *uplink; - /* IRC Variables */ E IRCDVar *ircd; @@ -423,7 +421,7 @@ E int add_szline(User * u, const char *mask, const char *by, E void expire_szlines(); E int check_szline(const char *nick, char *ip); -E Server *server_global(Server * s, char *msg); +E void server_global(Server *s, const std::string &message); E std::vector News; @@ -459,37 +457,6 @@ E void notice_lang(const std::string &source, User *dest, int message, ...); // E void notice_help(const char *source, User *dest, int message, ...); // MARK_DEPRECATED; -/**** servers.c ****/ - -E Server *servlist; -E Server *me_server; -E Server *serv_uplink; -E Flags Capab; -E CapabInfo Capab_Info[]; - -E Server *first_server(ServerFlag flag); -E Server *next_server(ServerFlag flag); - -E void CapabParse(int ac, const char **av); -E int is_ulined(const char *server); -E int is_sync(Server *server); - -E Server *new_server(Server * uplink, const char *name, const char *desc, ServerFlag flag, const std::string &suid); - -E Server *findserver(Server *s, const char *name); - -E void do_server(const char *source, const char *servername, const char *hops, const char *descript, const std::string &numeric); -E void do_squit(const char *source, int ac, const char **av); -E int anope_check_sync(const char *name); - -E void finish_sync(Server *serv, int sync_links); - -E void ts6_uid_init(); -E void ts6_uid_increment(unsigned int slot); -E const char *ts6_uid_retrieve(); - -E const char *ts6_sid_retrieve(); - /**** sessions.c ****/ E Exception *exceptions; @@ -550,7 +517,6 @@ E User *first_uid(); E User *next_uid(); E Server *findserver_uid(Server * s, const char *name); E char *TS6SID; -E char *TS6UPLINK; E User *do_nick(const char *source, const char *nick, const char *username, const char *host, const char *server, const char *realname, time_t ts, uint32 ip, const char *vhost, const char *uid); diff --git a/include/modules.h b/include/modules.h index dcaac342c..afc6806d1 100644 --- a/include/modules.h +++ b/include/modules.h @@ -585,9 +585,9 @@ class CoreExport Module */ virtual void OnServerConnect() { } - /** Called when we are done synching with the uplink, just before we send the EOB + /** Called when we are almost done synching with the uplink, just before we send the EOB */ - virtual void OnFinishSync(Server *serv) { } + virtual void OnPreUplinkSync(Server *serv) { } /** Called when Anope disconnects from its uplink, before it tries to reconnect */ @@ -1060,8 +1060,9 @@ class CoreExport Module virtual void OnServerSync(Server *s) { } /** Called when we sync with our uplink + * @param s Our uplink */ - virtual void OnUplinkSync() { } + virtual void OnUplinkSync(Server *s) { } }; @@ -1109,7 +1110,7 @@ enum Implementation I_OnModuleLoad, I_OnModuleUnload, /* Other */ - I_OnReload, I_OnPreServerConnect, I_OnNewServer, I_OnServerConnect, I_OnFinishSync, I_OnServerDisconnect, I_OnPreCommandRun, + I_OnReload, I_OnPreServerConnect, I_OnNewServer, I_OnServerConnect, I_OnPreUplinkSync, I_OnServerDisconnect, I_OnPreCommandRun, I_OnPreCommand, I_OnPostCommand, I_OnPreDatabaseExpire, I_OnPreRestart, I_OnRestart, I_OnPreShutdown, I_OnShutdown, I_OnSignal, I_OnServerQuit, I_OnTopicUpdated, I_OnEncrypt, I_OnEncryptInPlace, I_OnEncryptCheckLen, I_OnDecrypt, I_OnCheckPassword, diff --git a/include/servers.h b/include/servers.h new file mode 100644 index 000000000..f6a5933ed --- /dev/null +++ b/include/servers.h @@ -0,0 +1,179 @@ +/* Anope */ +extern CoreExport Server *Me; + +extern CoreExport void CapabParse(int ac, const char **av); + +extern CoreExport void do_server(const std::string &source, const std::string &servername, unsigned int hops, const std::string &descript, const std::string &numeric); +extern CoreExport void do_squit(const char *source, int ac, const char **av); + +extern CoreExport const char *ts6_uid_retrieve(); +extern CoreExport const char *ts6_sid_retrieve(); + +/* Types of capab + */ +enum CapabType +{ + CAPAB_BEGIN, + + CAPAB_NOQUIT, + CAPAB_TSMODE, + CAPAB_UNCONNECT, + CAPAB_NICKIP, + CAPAB_NSJOIN, + CAPAB_ZIP, + CAPAB_BURST, + CAPAB_TS3, + CAPAB_TS5, + CAPAB_DKEY, + CAPAB_DOZIP, + CAPAB_DODKEY, + CAPAB_QS, + CAPAB_SCS, + CAPAB_PT4, + CAPAB_UID, + CAPAB_KNOCK, + CAPAB_CLIENT, + CAPAB_IPV6, + CAPAB_SSJ5, + CAPAB_SN2, + CAPAB_VHOST, + CAPAB_TOKEN, + CAPAB_SSJ3, + CAPAB_NICK2, + CAPAB_VL, + CAPAB_TLKEXT, + CAPAB_CHANMODE, + CAPAB_SJB64, + CAPAB_NICKCHARS, + + CAPAB_END +}; + +/* CAPAB stuffs */ +struct CapabInfo +{ + std::string Token; + CapabType Flag; +}; + +extern CoreExport Flags Capab; +extern CoreExport CapabInfo Capab_Info[]; + +/** Flags set on servers + */ +enum ServerFlag +{ + /* Server is syncing */ + SERVER_SYNCING, + /* This server was juped */ + SERVER_JUPED +}; + +/** Class representing a server + */ +class Server : public Flags +{ + private: + /* Server name */ + std::string Name; + /* Hops between services and server */ + unsigned int Hops; + /* Server description */ + std::string Description; + /* Server ID */ + std::string SID; + /* Links for this server */ + std::list* Links; + /* Uplink for this server */ + Server *UplinkServer; + + /* Reason this server was quit */ + std::string QReason; + + public: + /** Constructor + * @param uplink The uplink this server is from, is only NULL when creating Me + * @param name The server name + * @param hops Hops from services server + * @param description Server rdescription + * @param sid Server sid/numeric + */ + Server(Server *uplink, const std::string &name, unsigned int hops, const std::string &description, const std::string &sid); + + /** Destructor + */ + ~Server(); + + /** Delete this server with a reason + * @param reason The reason + */ + void Delete(const std::string &reason); + + /** Get the name for this server + * @return The name + */ + const std::string& GetName() const; + + /** Get the number of hops this server is from services + * @return Number of hops + */ + unsigned int GetHops() const; + + /** Set the server description + * @param desc The new description + */ + void SetDescription(const std::string& desc); + + /** Get the server description + * @return The server description + */ + const std::string& GetDescription() const; + + /** Get the server numeric/SID + * @return The numeric/SID + */ + const std::string& GetSID() const; + + /** Get the list of links this server has, or NULL if it has none + * @return A list of servers + */ + const std::list* GetLinks() const; + + /** Get the uplink server for this server, if this is our uplink will be Me + * @return The servers uplink + */ + Server* GetUplink() const; + + /** Adds a link to this server + * @param s The linking server + */ + void AddLink(Server *s); + + /** Delinks a server from this server + * @param s The server + */ + void DelLink(Server *s); + + /** Finish syncing this server and optionally all links to it + * @param SyncLinks True to sync the links for this server too (if any) + */ + void Sync(bool SyncLinks); + + /** Check if this server is synced + * @return true or false + */ + bool IsSynced() const; + + /** Check if this server is ULined + * @return true or false + */ + bool IsULined() const; + + /** Find a server + * @param name The name or SID/numeric + * @param s The server list to search for this server on, defaults to our Uplink + * @return The server + */ + static Server* Find(const std::string &name, Server *s = NULL); +}; + diff --git a/include/services.h b/include/services.h index 2741e0178..4dd35a751 100644 --- a/include/services.h +++ b/include/services.h @@ -348,6 +348,7 @@ template class Flags class User; class ChannelInfo; class Channel; +class Server; struct EList; typedef struct bandata_ BanData; @@ -675,50 +676,9 @@ typedef struct { } LevelInfo; -/*************************************************************************/ - -/* Server data */ - -typedef enum { - SSYNC_IN_PROGRESS = 0, /* Sync is currently in progress */ - SSYNC_DONE = 1 /* We're in sync */ -} SyncState; - -/** Flags set on servers - */ -enum ServerFlag -{ - SERVER_START, - - /* This server is me */ - SERVER_ISME, - /* This server was juped */ - SERVER_JUPED, - /* This server is the current uplink */ - SERVER_ISUPLINK, - - SERVER_END -}; - -class Server : public Flags -{ - public: - Server *next, *prev; - - char *name; /* Server name */ - uint16 hops; /* Hops between services and server */ - char *desc; /* Server description */ - char *suid; /* Server Univeral ID */ - SyncState sync; /* Server sync state (see above) */ - - Server *links; /* Linked list head for linked servers */ - Server *uplink; /* Server which pretends to be the uplink */ -}; - /*************************************************************************/ #include "users.h" - /* This structure stocks ban data since it must not be removed when * user is kicked. */ @@ -920,55 +880,6 @@ enum DefconLevel /*************************************************************************/ -/* Types of capab - */ -enum CapabType -{ - CAPAB_BEGIN, - - CAPAB_NOQUIT, - CAPAB_TSMODE, - CAPAB_UNCONNECT, - CAPAB_NICKIP, - CAPAB_NSJOIN, - CAPAB_ZIP, - CAPAB_BURST, - CAPAB_TS3, - CAPAB_TS5, - CAPAB_DKEY, - CAPAB_DOZIP, - CAPAB_DODKEY, - CAPAB_QS, - CAPAB_SCS, - CAPAB_PT4, - CAPAB_UID, - CAPAB_KNOCK, - CAPAB_CLIENT, - CAPAB_IPV6, - CAPAB_SSJ5, - CAPAB_SN2, - CAPAB_VHOST, - CAPAB_TOKEN, - CAPAB_SSJ3, - CAPAB_NICK2, - CAPAB_VL, - CAPAB_TLKEXT, - CAPAB_CHANMODE, - CAPAB_SJB64, - CAPAB_NICKCHARS, - - CAPAB_END -}; - -/* CAPAB stuffs */ -struct CapabInfo -{ - std::string Token; - CapabType Flag; -}; - -/*************************************************************************/ - /** * RFC: defination of a valid nick * nickname = ( letter / special ) *8( letter / digit / special / "-" ) @@ -986,7 +897,9 @@ struct CapabInfo class IRCDProto; struct Uplink; class ServerConfig; + #include "extern.h" +#include "servers.h" #include "configreader.h" class CoreExport IRCDProto -- cgit From 503958aa77382a85a041e195d04b7a2ec51589e3 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 29 Apr 2010 18:56:31 -0400 Subject: Prevent negaitve mode changes, kicks, bans, and autokicks from affecting users with unreal usermode +q or similar --- include/extern.h | 1 - include/users.h | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/extern.h b/include/extern.h index 79f1702f9..c8382db8e 100644 --- a/include/extern.h +++ b/include/extern.h @@ -526,7 +526,6 @@ E void do_quit(const char *source, int ac, const char **av); E void do_kill(const std::string &source, const std::string &reason); E int is_oper(User * user); -E int is_protected(User * user); E int is_excepted(ChannelInfo * ci, User * user); E int is_excepted_mask(ChannelInfo * ci, const char *mask); diff --git a/include/users.h b/include/users.h index d94dca9bd..b11c17875 100644 --- a/include/users.h +++ b/include/users.h @@ -258,5 +258,10 @@ class CoreExport User : public Extensible * @return The channel container, or NULL */ ChannelContainer *FindChannel(Channel *c); + + /** Check if the user is protected from kicks and negative mode changes + * @return true or false + */ + bool IsProtected() const; }; -- cgit From 031bc4a8b0dc456aca4d70dc260f626b64cd82b3 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 5 May 2010 18:14:06 -0400 Subject: Merged branch threadingengine with master - Added a threading engine --- include/services.h | 1 + include/threadengine.h | 116 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 include/threadengine.h (limited to 'include') diff --git a/include/services.h b/include/services.h index 4dd35a751..43e91a21b 100644 --- a/include/services.h +++ b/include/services.h @@ -358,6 +358,7 @@ typedef struct exception_ Exception; typedef struct session_ Session; #include "extensible.h" +#include "threadengine.h" #include "bots.h" #include "opertype.h" #include "modes.h" diff --git a/include/threadengine.h b/include/threadengine.h new file mode 100644 index 000000000..e2125c6bd --- /dev/null +++ b/include/threadengine.h @@ -0,0 +1,116 @@ +#ifdef _WIN32 +typedef HANDLE ThreadHandle; +typedef CRITICAL_SECTION MutexHandle; +typedef HANDLE CondHandle; +#else +# include +typedef pthread_t ThreadHandle; +typedef pthread_mutex_t MutexHandle; +typedef pthread_cond_t CondHandle; +#endif + +class ThreadEngine; +class Thread; + +extern CoreExport ThreadEngine threadEngine; + +class ThreadEngine +{ + public: + /** Threadengines constructor + */ + ThreadEngine(); + + /** Threadengines destructor + */ + ~ThreadEngine(); + + /** Start a new thread + * @param thread A pointer to a newley allocated thread + */ + void Start(Thread *thread); +}; + +class Thread : public Extensible +{ + private: + /* Set to true to tell the thread to finish and we are waiting for it */ + bool Exit; + + /** Join to the thread, sets the exit state to true + */ + void Join(); + public: + /* Handle for this thread */ + ThreadHandle Handle; + + /** Threads constructor + */ + Thread(); + + /** Threads destructor + */ + virtual ~Thread(); + + /** Sets the exit state as true informing the thread we want it to shut down + */ + void SetExitState(); + + /** Returns the exit state of the thread + * @return true if we want to exit + */ + bool GetExitState() const; + + /** Called to run the thread, should be overloaded + */ + virtual void Run(); +}; + +class Mutex +{ + protected: + /* A mutex, used to keep threads in sync */ + MutexHandle mutex; + + public: + /** Constructor + */ + Mutex(); + + /** Destructor + */ + ~Mutex(); + + /** Attempt to lock the mutex, will hang until a lock can be achieved + */ + void Lock(); + + /** Unlock the mutex, it must be locked first + */ + void Unlock(); +}; + +class Condition : public Mutex +{ + private: + /* A condition */ + CondHandle cond; + + public: + /** Constructor + */ + Condition(); + + /** Destructor + */ + ~Condition(); + + /** Called to wakeup the waiter + */ + void Wakeup(); + + /** Called to wait for a Wakeup() call + */ + void Wait(); +}; + -- cgit From 5d437d9ab5988c36def1a78c7d3d3077eb6804e3 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 6 May 2010 14:16:59 -0400 Subject: Renamed the init_module function to AnopeInit - Some systems have an init_module function outside of Anope which causes a crash if you try to load a non-Anope module --- include/services.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/services.h b/include/services.h index 43e91a21b..ae36f8dbd 100644 --- a/include/services.h +++ b/include/services.h @@ -158,12 +158,12 @@ extern int strncasecmp(const char *, const char *, size_t); /** This definition is used as shorthand for the various classes * and functions needed to make a module loadable by the OS. - * It defines the class factory and external init_module function. + * It defines the class factory and external AnopeInit and AnopeFini functions. */ #ifdef _WIN32 #define MODULE_INIT(x) \ - extern "C" DllExport Module *init_module(const std::string &, const std::string &); \ - extern "C" Module *init_module(const std::string &modname, const std::string &creator) \ + extern "C" DllExport Module *AnopeInit(const std::string &, const std::string &); \ + extern "C" Module *AnopeInit(const std::string &modname, const std::string &creator) \ { \ return new x(modname, creator); \ } \ @@ -177,19 +177,19 @@ extern int strncasecmp(const char *, const char *, size_t); } \ return TRUE; \ } \ - extern "C" DllExport void destroy_module(x *); \ - extern "C" void destroy_module(x *m) \ + extern "C" DllExport void AnopeFini(x *); \ + extern "C" void AnopeFini(x *m) \ { \ delete m; \ } #else #define MODULE_INIT(x) \ - extern "C" DllExport Module *init_module(const std::string &modname, const std::string &creator) \ + extern "C" DllExport Module *AnopeInit(const std::string &modname, const std::string &creator) \ { \ return new x(modname, creator); \ } \ - extern "C" DllExport void destroy_module(x *m) \ + extern "C" DllExport void AnopeFini(x *m) \ { \ delete m; \ } -- cgit From a93be9ff1c417d73015fd53a9ee778ea2a642328 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 6 May 2010 14:42:21 -0400 Subject: Added two events called in ns_info and cs_info that allows modules to easially add info output. Made os_info use this --- include/modules.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/modules.h b/include/modules.h index afc6806d1..6e7de5188 100644 --- a/include/modules.h +++ b/include/modules.h @@ -868,6 +868,13 @@ class CoreExport Module */ virtual void OnAkickDel(ChannelInfo *ci, AutoKick *ak) { } + /** Called when a user requests info for a channel + * @param u The user requesting info + * @param ci The channel the user is requesting info for + * @param ShowHidden true if we should show the user everything + */ + virtual void OnChanInfo(User *u, ChannelInfo *ci, bool ShowHidden) { } + /** Called when a nick is dropped * @param nick The nick */ @@ -946,13 +953,20 @@ class CoreExport Module */ virtual void OnNickAddAccess(NickCore *nc, const std::string &entry) { } - /** called from NickCore::EraseAccess() + /** Called from NickCore::EraseAccess() * @param nc pointer to the NickCore * @param entry The access mask */ virtual void OnNickEraseAccess(NickCore *nc, const std::string &entry) { } - /** called when a vhost is deleted + /** Called when a user requests info for a nick + * @param u The user requesting info + * @param na The nick the user is requesting info from + * @param ShowHidden true if we should show the user everything + */ + virtual void OnNickInfo(User *u, NickAlias *na, bool ShowHidden) { } + + /** Called when a vhost is deleted * @param na The nickalias of the vhost */ virtual void OnDeleteVhost(NickAlias *na) { } @@ -1077,11 +1091,13 @@ enum Implementation I_OnNickRegister, I_OnNickSuspended, I_OnNickUnsuspended, I_OnDelNick, I_OnDelCore, I_OnChangeCoreDisplay, I_OnDelNickRequest, I_OnMakeNickRequest, I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess, + I_OnNickInfo, /* ChanServ */ I_OnChanServHelp, I_OnChanForbidden, I_OnChanSuspend, I_OnChanDrop, I_OnPreChanExpire, I_OnChanExpire, I_OnAccessAdd, I_OnAccessChange, I_OnAccessDel, I_OnAccessClear, I_OnLevelChange, I_OnChanRegistered, I_OnChanUnsuspend, I_OnDelChan, I_OnChannelCreate, I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, + I_OnChanInfo, /* BotServ */ I_OnBotServHelp, I_OnBotJoin, I_OnBotKick, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnBotAssign, I_OnBotUnAssign, -- cgit From 9439cac6b126254bc488c2375b9e7ff5fd4fce74 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 7 May 2010 14:11:21 -0400 Subject: Added m_ssl.cpp which allows Anope to use SSL when connecting to its uplink --- include/extern.h | 1 + include/modules.h | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/extern.h b/include/extern.h index c8382db8e..7998b7c74 100644 --- a/include/extern.h +++ b/include/extern.h @@ -286,6 +286,7 @@ E int m_version(const char *source, int ac, const char **av); /**** misc.c ****/ +E bool IsFile(const std::string &filename); E int toupper(char); E int tolower(char); E char *strscpy(char *d, const char *s, size_t len); diff --git a/include/modules.h b/include/modules.h index 6e7de5188..3f5de12da 100644 --- a/include/modules.h +++ b/include/modules.h @@ -578,8 +578,9 @@ class CoreExport Module virtual void OnChanExpire(const char *chname) { } /** Called before anope connects to its uplink + * @return Other than EVENT_CONTINUE to stop attempting to connect */ - virtual void OnPreServerConnect() { } + virtual EventReturn OnPreServerConnect() { return EVENT_CONTINUE; } /** Called when Anope connects to its uplink */ -- cgit From ebfff71599fbedb72009d71cd40c264713b43b5a Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 7 May 2010 15:29:41 -0400 Subject: Made opertypes inheritable --- include/opertype.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/opertype.h b/include/opertype.h index b7fdc67cb..59c9eea6a 100644 --- a/include/opertype.h +++ b/include/opertype.h @@ -31,6 +31,10 @@ class CoreExport OperType * as we don't invoke it often. */ std::list commands; + + /** Set of opertypes we inherit from + */ + std::set inheritances; public: /** Create a new opertype of the given name. * @param nname The opertype name, e.g. "sra". @@ -62,4 +66,9 @@ class CoreExport OperType /** Returns the name of this opertype. */ const ci::string &GetName() const; + + /** Make this opertype inherit commands and privs from another opertype + * @param ot The opertype to inherit from + */ + void Inherits(OperType *ot); }; -- cgit From af805e5b45f75dec7f4ce16ffc322c8880f9859c Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 7 May 2010 21:04:18 -0400 Subject: Allow enabling ssl on a per-uplink basis --- include/modules.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/modules.h b/include/modules.h index 3f5de12da..174fb6e04 100644 --- a/include/modules.h +++ b/include/modules.h @@ -577,10 +577,12 @@ class CoreExport Module */ virtual void OnChanExpire(const char *chname) { } - /** Called before anope connects to its uplink + /** Called before Anope connects to its uplink + * @param u The uplink we're going to connect to + * @param Number What number the uplink is * @return Other than EVENT_CONTINUE to stop attempting to connect */ - virtual EventReturn OnPreServerConnect() { return EVENT_CONTINUE; } + virtual EventReturn OnPreServerConnect(Uplink *u, int Number) { return EVENT_CONTINUE; } /** Called when Anope connects to its uplink */ -- cgit From e78a055c2b5c9fe3a4e4ef32058f161eceb3df1c Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 8 May 2010 13:46:13 -0400 Subject: Removed old config.h and moved configreader.h to config.h --- include/config.h | 920 +++++++++++++++++++++++++++++++++++++++++++++++-- include/configreader.h | 903 ------------------------------------------------ include/services.h | 5 +- include/sockets.h | 2 + 4 files changed, 897 insertions(+), 933 deletions(-) delete mode 100644 include/configreader.h (limited to 'include') diff --git a/include/config.h b/include/config.h index 825cc9af4..c6dbbefb8 100644 --- a/include/config.h +++ b/include/config.h @@ -1,39 +1,903 @@ -/* Services configuration. - * - * (C) 2003-2010 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for furhter details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * +#ifndef _CONFIGREADER_H_ +#define _CONFIGREADER_H_ + +#include +#include +#include +#include +#include +#include + +/** A configuration key and value pair + */ +typedef std::pair KeyVal; + +/** A list of related configuration keys and values + */ +typedef std::vector KeyValList; + +/** An entire config file, built up of KeyValLists + */ +typedef std::multimap ConfigDataHash; + +// Required forward definitions +class ServerConfig; + +/** Types of data in the core config + */ +enum ConfigDataType { + DT_NOTHING, // No data + DT_INTEGER, // Integer + DT_UINTEGER, // Unsigned Integer + DT_LUINTEGER, // Long Unsigned Integer + DT_CHARPTR, // Char pointer + DT_STRING, // std::string + DT_BOOLEAN, // Boolean + DT_HOSTNAME, // Hostname syntax + DT_NOSPACES, // No spaces + DT_IPADDRESS, // IP address (v4, v6) + DT_TIME, // Time value + DT_NORELOAD = 32, // Item can't be reloaded after startup + DT_ALLOW_WILD = 64, // Allow wildcards/CIDR in DT_IPADDRESS + DT_ALLOW_NEWLINE = 128 // New line characters allowed in DT_CHARPTR +}; + +/** Holds a config value, either string, integer or boolean. + * Callback functions receive one or more of these, either on + * their own as a reference, or in a reference to a deque of them. + * The callback function can then alter the values of the ValueItem + * classes to validate the settings. + */ +class ValueItem +{ + /** Actual data */ + std::string v; + public: + /** Initialize with an int */ + ValueItem(int); + /** Initialize with a bool */ + ValueItem(bool); + /** Initialize with a char pointer */ + ValueItem(const char *); + /** Initialize with an std::string */ + ValueItem(const std::string &); + /** Initialize with a long */ + ValueItem(long); + /** Change value to a char pointer */ + //void Set(char *); + /** Change value to a const char pointer */ + void Set(const char *); + /** Change value to an std::string */ + void Set(const std::string &); + /** Change value to an int */ + void Set(int); + /** Get value as an int */ + int GetInteger(); + /** Get value as a string */ + const char *GetString() const; + /** Get value as a string */ + inline const std::string &GetValue() const { return v; } + /** Get value as a bool */ + bool GetBool(); +}; + +/** The base class of the container 'ValueContainer' + * used internally by the core to hold core values. + */ +class ValueContainerBase +{ + public: + /** Constructor */ + ValueContainerBase() { } + /** Destructor */ + virtual ~ValueContainerBase() { } +}; + +/** ValueContainer is used to contain pointers to different + * core values such as the server name, maximum number of + * clients etc. + * It is specialized to hold a data type, then pointed at + * a value in the ServerConfig class. When the value has been + * read and validated, the Set method is called to write the + * value safely in a type-safe manner. + */ +template class ValueContainer : public ValueContainerBase +{ + /** Contained item */ + T val; + public: + /** Initialize with nothing */ + ValueContainer() : ValueContainerBase(), val(NULL) { } + /** Initialize with a value of type T */ + ValueContainer(T Val) : ValueContainerBase(), val(Val) { } + /** Initialize with a copy */ + ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { } + ValueContainer &operator=(const ValueContainer &Val) + { + val = Val.val; + return *this; + } + /** Change value to type T of size s */ + void Set(const T newval, size_t s) + { + memcpy(val, newval, s); + } +}; + +/** This a specific version of ValueContainer to handle character arrays specially + */ +template<> class ValueContainer : public ValueContainerBase +{ + /** Contained item */ + char **val; + public: + /** Initialize with nothing */ + ValueContainer() : ValueContainerBase(), val(NULL) { } + /** Initialize with a value of type T */ + ValueContainer(char **Val) : ValueContainerBase(), val(Val) { } + /** Initialize with a copy */ + ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { } + ValueContainer &operator=(const ValueContainer &Val) + { + val = Val.val; + return *this; + } + /** Change value to type T of size s */ + void Set(const char *newval, size_t s) + { + if (*val) delete [] *val; + if (!*newval) { + *val = NULL; + return; + } + *val = new char[s]; + strlcpy(*val, newval, s); + } +}; + +/** This a specific version of ValueContainer to handle std::string specially + */ +template<> class ValueContainer : public ValueContainerBase +{ + /** Contained item */ + std::string *val; + public: + /** Initialize with nothing */ + ValueContainer() : ValueContainerBase(), val(NULL) { } + /** Initialize with an std::string */ + ValueContainer(std::string *Val) : ValueContainerBase(), val(Val) { } + /** Initialize with a copy */ + ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { } + ValueContainer &operator=(const ValueContainer &Val) + { + val = Val.val; + return *this; + } + /** Change value to given std::string */ + void Set(const std::string &newval) + { + *val = newval; + } + /** Change value to given char pointer */ + void Set(const char *newval) + { + *val = newval; + } +}; + +/** A specialization of ValueContainer to hold a pointer to a bool + */ +typedef ValueContainer ValueContainerBool; + +/** A specialization of ValueContainer to hold a pointer to + * an unsigned int + */ +typedef ValueContainer ValueContainerUInt; + +/** A specialization of ValueContainer to hold a pointer to + * a long unsigned int + */ +typedef ValueContainer ValueContainerLUInt; + +/** A specialization of ValueContainer to hold a pointer to + * a char array. + */ +typedef ValueContainer ValueContainerChar; + +/** A specialization of ValueContainer to hold a pointer to + * an int + */ +typedef ValueContainer ValueContainerInt; + +/** A specialization of ValueContainer to hold a pointer to + * a time_t + */ +typedef ValueContainer ValueContainerTime; + +/** A specialization of ValueContainer to hold a pointer to + * an std::string + */ +typedef ValueContainer ValueContainerString; + +/** A set of ValueItems used by multi-value validator functions + */ +typedef std::deque ValueList; + +/** A callback for validating a single value + */ +typedef bool (*Validator)(ServerConfig *, const char *, const char *, ValueItem &); +/** A callback for validating multiple value entries + */ +typedef bool (*MultiValidator)(ServerConfig *, const char *, const char **, ValueList &, int *, bool); +/** A callback indicating the end of a group of entries + */ +typedef bool (*MultiNotify)(ServerConfig *, const char *, bool); + +/** Holds a core configuration item and its callbacks + */ +struct InitialConfig +{ + /** Tag name */ + const char *tag; + /** Value name */ + const char *value; + /** Default, if not defined */ + const char *default_value; + /** Value containers */ + ValueContainerBase *val; + /** Data types */ + int datatype; + /** Validation function */ + Validator validation_function; +}; + +/** Holds a core configuration item and its callbacks + * where there may be more than one item + */ +struct MultiConfig +{ + /** Tag name */ + const char *tag; + /** One or more items within tag */ + const char *items[17]; + /** One or more defaults for items within tags */ + const char *items_default[17]; + /** One or more data types */ + int datatype[17]; + /** Initialization function */ + MultiNotify init_function; + /** Validation function */ + MultiValidator validation_function; + /** Completion function */ + MultiNotify finish_function; +}; + +/** This class holds the bulk of the runtime configuration for the ircd. + * It allows for reading new config values, accessing configuration files, + * and storage of the configuration data needed to run the ircd, such as + * the servername, connect classes, /ADMIN data, MOTDs and filenames etc. */ +class ServerConfig +{ + private: + /** This variable holds the names of all + * files included from the main one. This + * is used to make sure that no files are + * recursively included. + */ + std::vector include_stack; + /** Check that there is only one of each configuration item + */ + bool CheckOnce(const char *); + public: + std::ostringstream errstr; + ConfigDataHash newconfig; + /** This holds all the information in the config file, + * it's indexed by tag name to a vector of key/values. + */ + ConfigDataHash config_data; + /** Construct a new ServerConfig + */ + ServerConfig(); + /** Clears the include stack in preperation for a Read() call. + */ + void ClearStack(); + /** Read the entire configuration into memory + * and initialize this class. All other methods + * should be used only by the core. + */ + int Read(bool); + /** Report a configuration error given in errormessage. + * @param bail If this is set to true, the error is sent to the console, and the program exits + * @param connection If this is set to a non-null value, and bail is false, the errors are spooled to + * this connection as SNOTICEs. + * If the parameter is NULL, the messages are spooled to all connections via WriteOpers as SNOTICEs. + */ + void ReportConfigError(const std::string &, bool); + /** Load 'filename' into 'target', with the new config parser everything is parsed into + * tag/key/value at load-time rather than at read-value time. + */ + bool LoadConf(ConfigDataHash &, const char *, std::ostringstream &); + /** Load 'filename' into 'target', with the new config parser everything is parsed into + * tag/key/value at load-time rather than at read-value time. + */ + bool LoadConf(ConfigDataHash &, const std::string &, std::ostringstream &); + // Both these return true if the value existed or false otherwise + /** Writes 'length' chars into 'result' as a string + */ + bool ConfValue(ConfigDataHash &, const char *, const char *, int, char *, int, bool = false); + /** Writes 'length' chars into 'result' as a string + */ + bool ConfValue(ConfigDataHash &, const char *, const char *, const char *, int, char *, int, bool = false); + /** Writes 'length' chars into 'result' as a string + */ + bool ConfValue(ConfigDataHash &, const std::string &, const std::string &, int, std::string &, bool = false); + /** Writes 'length' chars into 'result' as a string + */ + bool ConfValue(ConfigDataHash &, const std::string &, const std::string &, const std::string &, int, std::string &, bool = false); + /** Tries to convert the value to an integer and write it to 'result' + */ + bool ConfValueInteger(ConfigDataHash &, const char *, const char *, int, int &); + /** Tries to convert the value to an integer and write it to 'result' + */ + bool ConfValueInteger(ConfigDataHash &, const char *, const char *, const char *, int, int &); + /** Tries to convert the value to an integer and write it to 'result' + */ + bool ConfValueInteger(ConfigDataHash &, const std::string &, const std::string &, int, int &); + /** Tries to convert the value to an integer and write it to 'result' + */ + bool ConfValueInteger(ConfigDataHash &, const std::string &, const std::string &, const std::string &, int, int &); + /** Returns true if the value exists and has a true value, false otherwise + */ + bool ConfValueBool(ConfigDataHash &, const char *, const char *, int); + /** Returns true if the value exists and has a true value, false otherwise + */ + bool ConfValueBool(ConfigDataHash &, const char *, const char *, const char *, int); + /** Returns true if the value exists and has a true value, false otherwise + */ + bool ConfValueBool(ConfigDataHash &, const std::string &, const std::string &, int); + /** Returns true if the value exists and has a true value, false otherwise + */ + bool ConfValueBool(ConfigDataHash &, const std::string &, const std::string &, const std::string &, int); + /** Returns the number of occurences of tag in the config file + */ + int ConfValueEnum(ConfigDataHash &, const char *); + /** Returns the number of occurences of tag in the config file + */ + int ConfValueEnum(ConfigDataHash &, const std::string &); + /** Returns the numbers of vars inside the index'th 'tag in the config file + */ + int ConfVarEnum(ConfigDataHash &, const char *, int); + /** Returns the numbers of vars inside the index'th 'tag in the config file + */ + int ConfVarEnum(ConfigDataHash &, const std::string &, int); + void ValidateHostname(const char *, const std::string &, const std::string &); + void ValidateIP(const char *p, const std::string &, const std::string &, bool); + void ValidateNoSpaces(const char *, const std::string &, const std::string &); + + + + /** Below here is a list of variables which contain the config files values + */ + /* IRCd module in use */ + char *IRCDModule; -#ifndef CONFIG_H -#define CONFIG_H + /* Host to connect to **/ + char *LocalHost; + /* List of uplink servers to try and connect to */ + std::list Uplinks; -/* Note that most of the options which used to be here have been moved to - * services.conf. */ + /* Our server name */ + char *ServerName; + /* Our servers description */ + char *ServerDesc; + /* The username/ident of services clients */ + char *ServiceUser; + /* The hostname if services clients */ + char *ServiceHost; -/*************************************************************************/ + /* Help channel, ops here get usermode +h **/ + char *HelpChannel; + /* Log channel */ + char *LogChannel; + /* Name of the network were on */ + char *NetworkName; + /* The max legnth of nicks */ + unsigned NickLen; + /* Max length of idents */ + unsigned UserLen; + /* Max lenght of hostnames */ + unsigned HostLen; -/******* General configuration *******/ + /* Max length of passwords */ + unsigned PassLen; -/* Name of log file (in Services directory) */ -#define LOG_FILENAME "services.log" + /* NickServ Name */ + char *s_NickServ; + /* ChanServ Name */ + char *s_ChanServ; + /* MemoServ Name */ + char *s_MemoServ; + /* BotServ Name */ + char *s_BotServ; + /* OperServ name */ + char *s_OperServ; + /* Global name */ + char *s_GlobalNoticer; + /* NickServs realname */ + char *desc_NickServ; + /* ChanServ realname */ + char *desc_ChanServ; + /* MemoServ relname */ + char *desc_MemoServ; + /* BotServ realname */ + char *desc_BotServ; + /* OperServ realname */ + char *desc_OperServ; + /* Global realname */ + char *desc_GlobalNoticer; -/******************* END OF USER-CONFIGURABLE SECTION ********************/ + /* HostServ Name */ + char *s_HostServ; + /* HostServ realname */ + char *desc_HostServ; -/* Size of input buffer (note: this is different from BUFSIZ) - * This must be big enough to hold at least one full IRC message, or messy - * things will happen. */ -#define BUFSIZE 1024 + /* Filename for the PID file */ + char *PIDFilename; + /* MOTD filename */ + char *MOTDFilename; -/* Maximum amount of data from/to the network to buffer (bytes). */ -#define NET_BUFSIZE 65536 + /* True if its ok to not be able to save backs */ + bool NoBackupOkay; + /* Do password checking when new people register */ + bool StrictPasswords; + /* How many times you're allowed to give a bad password before being killed */ + unsigned BadPassLimit; + /* How long before bad passwords are forgotten */ + time_t BadPassTimeout; + /* Delay between automatic database updates */ + time_t UpdateTimeout; + /* Delay between checks for expired nicks and channels */ + time_t ExpireTimeout; + /* How long to wait for something from the uplink, this is passed to select() */ + time_t ReadTimeout; + /* How often to send program errors */ + time_t WarningTimeout; + /* How long to process things such as timers to see if there is anything to calll */ + time_t TimeoutCheck; + /* Num of days logfiles are kept */ + int KeepLogs; + /* Number of days backups are kept */ + int KeepBackups; + /* Forbidding requires a reason */ + bool ForceForbidReason; + /* Services should use privmsgs instead of notices */ + bool UsePrivmsg; + /* Services only respond to full PRIVMSG client@services.server.name messages */ + bool UseStrictPrivMsg; + /* Dump a core file if we crash */ + bool DumpCore; + /* Log users connecting/existing/changing nicks */ + bool LogUsers; + /* Number of seconds between consecutive uses of the REGISTER command + * Not to be confused with NSRegDelay */ + unsigned NickRegDelay; + /* Max number if news items allowed in the list */ + unsigned NewsCount; + /* Default mlock modes */ + std::string MLock; + /* Default botmodes on channels, defaults to ao */ + std::string BotModes; + /* How many times to try and reconnect to the uplink before giving up */ + unsigned MaxRetries; + /* How long to wait between connection attempts */ + int RetryWait; -/**************************************************************************/ + /* Services can use email */ + bool UseMail; + /* Path to the sendmail executable */ + char *SendMailPath; + /* Address to send from */ + char *SendFrom; + /* Only opers can have services send mail */ + bool RestrictMail; + /* Delay between sending mail */ + time_t MailDelay; + /* Don't quote the To: address */ + bool DontQuoteAddresses; + + /* Prefix of guest nicks when a user gets forced off of a nick */ + char *NSGuestNickPrefix; + /* Allow users to set kill immed on */ + bool NSAllowKillImmed; + /* Don't allow nicks to use /ns group to regroup nicks */ + bool NSNoGroupChange; + /* Default flags for newly registered nicks */ + Flags NSDefFlags; + /* Default language used by services */ + unsigned NSDefLanguage; + /* Users must be connected this long before they can register + * Not to be confused with NickRegDelay */ + time_t NSRegDelay; + /* Time before the registering mail will be resent */ + time_t NSResendDelay; + /* How long before nicks expir */ + time_t NSExpire; + /* Time before NickRequests expire */ + time_t NSRExpire; + /* Force email when registering */ + bool NSForceEmail; + /* Max number of nicks in a group */ + int NSMaxAliases; + /* Max number of allowed strings on the access list */ + unsigned NSAccessMax; + /* Enforcer client user name */ + char *NSEnforcerUser; + /* Enforcer client hostname */ + char *NSEnforcerHost; + /* How long before recovered nicks are released */ + time_t NSReleaseTimeout; + /* /nickserv list is oper only */ + bool NSListOpersOnly; + /* Max number of entries that can be returned from the list command */ + unsigned NSListMax; + /* Only allow usermode +a etc on real services admins */ + bool NSSecureAdmins; + /* Services opers must be /operd on the ircd aswell */ + bool NSStrictPrivileges; + /* Use email to verify new users registering */ + bool NSEmailReg; + /* Set the proper channel modes on users when they identify */ + bool NSModeOnID; + /* Add the users hostnask their access list when they register */ + bool NSAddAccessOnReg; + + /* Default flags for newly registered channels */ + Flags CSDefFlags; + /* Max number of channels a user can own */ + unsigned CSMaxReg; + /* Time before a channel expires */ + time_t CSExpire; + /* Default ban type to use for channels */ + int CSDefBantype; + /* Max number of entries allowed on channel access lists */ + unsigned CSAccessMax; + /* Max number of entries allowed on autokick lists */ + unsigned CSAutokickMax; + /* Default autokick reason */ + char *CSAutokickReason; + /* Time ChanServ should stay in the channel to hold it to keep users from getting in */ + time_t CSInhabit; + /* ChanServ's LIST command is oper only */ + bool CSListOpersOnly; + /* Max number of entries allowed to be returned from the LIST command */ + unsigned CSListMax; + /* true to make ChanServ oper only */ + bool CSOpersOnly; + + /* Max number of memos allowed */ + unsigned MSMaxMemos; + /* Time you must wait between sending memos */ + time_t MSSendDelay; + /* Notify all of the aliases of the core the memo was sent to */ + bool MSNotifyAll; + /* Who can use memos reciepts */ + unsigned MSMemoReceipt; + + /* Defai;t BotServ flags */ + Flags BSDefFlags; + /* How long before botserv forgets a user. This is used for flood kickers etc */ + time_t BSKeepData; + /* Min number of users to have in the channel before the service bot joins */ + unsigned BSMinUsers; + /* Max number of words allowed on the badwordslist */ + unsigned BSBadWordsMax; + /* BotServ bot only joins if it would normally allowed to, abides by bans etc */ + bool BSSmartJoin; + /* Dont tell users what badword they used */ + bool BSGentleBWReason; + /* Case sensitive badwords matching */ + bool BSCaseSensitive; + /* Char to use for the fantasy char, eg ! */ + char *BSFantasyCharacter; + + /* Only show /stats o to opers */ + bool HideStatsO; + /* Send out a global when services shut down or restart */ + bool GlobalOnCycle; + /* Don't include the opers name in globals */ + bool AnonymousGlobal; + /* Dont allow users to register nicks with oper names in them */ + bool RestrictOperNicks; + /* Message to send when shutting down */ + char *GlobalOnCycleMessage; + /* Message to send when starting up */ + char *GlobalOnCycleUP; + /* Super admin is allowed */ + bool SuperAdmin; + /* Log things said through ACT/SAY */ + bool LogBot; + /* Log when new user max is reached */ + bool LogMaxUsers; + /* Default expiry time for akills */ + time_t AutokillExpiry; + /* Default expiry time for chan kills */ + time_t ChankillExpiry; + /* Default expiry time for SGLine Expire */ + time_t SGLineExpiry; + /* Default expiry time for SQLines */ + time_t SQLineExpiry; + /* Default expiry time for SZLine */ + time_t SZLineExpiry; + /* Actually akill the user when the akill is added */ + bool AkillOnAdd; + /* Kill users on SGline */ + bool KillonSGline; + /* Kill users on SQline */ + bool KillonSQline; + /* Send a WALLOPS/GLOBOPS when a user opers */ + bool WallOper; + /* Send a WALLOPS/GLOBOPS when a nonoper tries to use OperServ */ + bool WallBadOS; + /* Send a WALLOPS/GLOBOPS when someone uses the GLOBAL command */ + bool WallOSGlobal; + /* Send a WALLOPS/GLOBOPS when someone uses the MODE command */ + bool WallOSMode; + /* Send a WALLOPS/GLOBOPS when someone uses the CLEARMODES command */ + bool WallOSClearmodes; + /* Send a WALLOPS/GLOBOPS when someone uses the KICK command */ + bool WallOSKick; + /* Send a WALLOPS/GLOBOPS when someone uses the AKILL command */ + bool WallOSAkill; + /* Send a WALLOPS/GLOBOPS when someone uses the SGLINE command */ + bool WallOSSGLine; + /* Send a WALLOPS/GLOBOPS when someone uses the SQLINE command */ + bool WallOSSQLine; + /* Send a WALLOPS/GLOBOPS when someone uses the SZLINE command */ + bool WallOSSZLine; + /* Send a WALLOPS/GLOBOPS when someone uses the NOOP command */ + bool WallOSNoOp; + /* Send a WALLOPS/GLOBOPS when when someone uses the JUPE command */ + bool WallOSJupe; + /* Send a WALLOPS/GLOBOPS when an akill expires */ + bool WallAkillExpire; + /* Send a WALLOPS/GLOBOPS when SGLines expire */ + bool WallSGLineExpire; + /* Send a WALLOPS/GLOBOPS when SQLines expire */ + bool WallSQLineExpire; + /* Send a WALLOPS/GLOBOPS when SZLines expire */ + bool WallSZLineExpire; + /* Send a WALLOPS/GLOBOPS when exceptions expire */ + bool WallExceptionExpire; + /* Send a WALLOPS/GLOBOPS when DROP is used */ + bool WallDrop; + /* Send a WALLOPS/GLOBOPS when FORBID is used */ + bool WallForbid; + /* Send a WALLOPS/GLOBOPS when GETPASS is used */ + bool WallGetpass; + /* Send a WALLOPS/GLOBOPS when SETPASS is used */ + bool WallSetpass; + /* Add the akillers nick to the akill reason */ + bool AddAkiller; + + /* Limit sessions */ + bool LimitSessions; + /* The default session limit */ + unsigned DefSessionLimit; + /* How long before exceptions expire */ + time_t ExceptionExpiry; + /* How many times to kill before adding an KILL */ + int MaxSessionKill; + /* Max limit that can be used for exceptions */ + unsigned MaxSessionLimit; + /* How long session akills should last */ + time_t SessionAutoKillExpiry; + /* Reason to use for session kills */ + char *SessionLimitExceeded; + /* Optional second reason */ + char *SessionLimitDetailsLoc; + /* OperServ requires you to be an operator */ + bool OSOpersOnly; + + /* List of modules to autoload */ + std::list ModulesAutoLoad; + /* Encryption modules */ + std::list EncModuleList; + /* Database modules */ + std::list DBModuleList; + /* HostServ Core Modules */ + std::list HostServCoreModules; + /* MemoServ Core Modules */ + std::list MemoServCoreModules; + /* BotServ Core Modules */ + std::list BotServCoreModules; + /* OperServ Core Modules */ + std::list OperServCoreModules; + /* NickServ Core Modules */ + std::list NickServCoreModules; + /* ChanServ Core Modules */ + std::list ChanServCoreModules; + + /* Default defcon level */ + int DefConLevel; + /* Timeout before defcon is reset */ + time_t DefConTimeOut; + /* Session limiit to use when using defcon */ + int DefConSessionLimit; + /* How long to add akills for defcon */ + time_t DefConAKILL; + /* Chan modes for defcon */ + char *DefConChanModes; + /* Should we global on defcon */ + bool GlobalOnDefcon; + /* Should we send DefconMessage aswell? */ + bool GlobalOnDefconMore; + /* Message to send when defcon is off */ + char *DefConOffMessage; + /* Message to send when defcon is on*/ + char *DefconMessage; + /* Reason to akill clients for defcon */ + char *DefConAkillReason; + + /* User keys to use for generating random hashes for pass codes etc */ + long unsigned int UserKey1; + long unsigned int UserKey2; + long unsigned int UserKey3; + + /* Numeric */ + char *Numeric; + /* Array of ulined servers */ + char **Ulines; + /* Number of ulines */ + int NumUlines; + + /* List of available opertypes */ + std::list MyOperTypes; + /* List of pairs of opers and their opertype from the config */ + std::list > Opers; +}; + +/** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. + * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or + * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not + * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user + * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time. + */ +class ConfigException : public CoreException +{ + public: + /** Default constructor, just uses the error mesage 'Config threw an exception'. + */ + ConfigException() : CoreException("Config threw an exception", "Config Parser") {} + /** This constructor can be used to specify an error message before throwing. + */ + ConfigException(const std::string &message) : CoreException(message, "Config Parser") {} + /** This destructor solves world hunger, cancels the world debt, and causes the world to end. + * Actually no, it does nothing. Never mind. + * @throws Nothing! + */ + virtual ~ConfigException() throw() { }; +}; + +#define CONF_NO_ERROR 0x000000 +#define CONF_NOT_A_NUMBER 0x000010 +#define CONF_INT_NEGATIVE 0x000080 +#define CONF_VALUE_NOT_FOUND 0x000100 +#define CONF_FILE_NOT_FOUND 0x000200 + +/** Allows reading of values from configuration files + * This class allows a module to read from either the main configuration file (inspircd.conf) or from + * a module-specified configuration file. It may either be instantiated with one parameter or none. + * Constructing the class using one parameter allows you to specify a path to your own configuration + * file, otherwise, inspircd.conf is read. + */ +class CoreExport ConfigReader +{ + protected: + /** The contents of the configuration file + * This protected member should never be accessed by a module (and cannot be accessed unless the + * core is changed). It will contain a pointer to the configuration file data with unneeded data + * (such as comments) stripped from it. + */ + ConfigDataHash *data; + /** Used to store errors + */ + std::ostringstream *errorlog; + /** If we're using our own config data hash or not + */ + bool privatehash; + /** True if an error occured reading the config file + */ + bool readerror; + /** Error code + */ + long error; + public: + /** Default constructor. + * This constructor initialises the ConfigReader class to read services.conf. + */ + ConfigReader(); + /** Overloaded constructor. + * This constructor initialises the ConfigReader class to read a user-specified config file + */ + ConfigReader(const std::string &); + /** Default destructor. + * This method destroys the ConfigReader class. + */ + ~ConfigReader(); + /** Retrieves a value from the config file. + * This method retrieves a value from the config file. Where multiple copies of the tag + * exist in the config file, index indicates which of the values to retrieve. + */ + std::string ReadValue(const std::string &, const std::string &, int, bool = false); + /** Retrieves a value from the config file. + * This method retrieves a value from the config file. Where multiple copies of the tag + * exist in the config file, index indicates which of the values to retrieve. If the + * tag is not found the default value is returned instead. + */ + std::string ReadValue(const std::string &, const std::string &, const std::string &, int, bool = false); + /** Retrieves a boolean value from the config file. + * This method retrieves a boolean value from the config file. Where multiple copies of the tag + * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" + * and "true" in the config file count as true to ReadFlag, and any other value counts as false. + */ + bool ReadFlag(const std::string &, const std::string &, int); + /** Retrieves a boolean value from the config file. + * This method retrieves a boolean value from the config file. Where multiple copies of the tag + * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" + * and "true" in the config file count as true to ReadFlag, and any other value counts as false. + * If the tag is not found, the default value is used instead. + */ + bool ReadFlag(const std::string &, const std::string &, const std::string &, int); + /** Retrieves an integer value from the config file. + * This method retrieves an integer value from the conf