diff options
58 files changed, 818 insertions, 2056 deletions
diff --git a/.Makefile.inc b/.Makefile.inc index c0797463c..ca85da062 100644 --- a/.Makefile.inc +++ b/.Makefile.inc @@ -43,12 +43,13 @@ install: all @-install -v -m 0700 src/libIRCDchannels.so $(LIBPATH) @-install -v -m 0700 src/libIRCDcommand_parse.so $(LIBPATH) @-install -v -m 0700 src/libIRCDcommands.so $(LIBPATH) + @-install -v -m 0700 src/libIRCDconfigreader.so $(LIBPATH) @-install -v -m 0700 src/libIRCDcull_list.so $(LIBPATH) @-install -v -m 0700 src/libIRCDdnsqueue.so $(LIBPATH) @-install -v -m 0700 src/libIRCDdynamic.so $(LIBPATH) @-install -v -m 0700 src/libIRCDhash.so $(LIBPATH) @-install -v -m 0700 src/libIRCDhelper.so $(LIBPATH) - @-install -v -m 0700 src/libIRCDio.so $(LIBPATH) + @-install -v -m 0700 src/libIRCDinspsocket.so $(LIBPATH) @-install -v -m 0700 src/libIRCDmessage.so $(LIBPATH) @-install -v -m 0700 src/libIRCDmode.so $(LIBPATH) @-install -v -m 0700 src/libIRCDmodules.so $(LIBPATH) @@ -1323,20 +1323,20 @@ EOM if ($config{OSNAME} =~ /CYGWIN/) { print FH <<EOM; -all: timer.o aes.o command_parse.o cull_list.o userprocess.o socketengine.o socket.o hashcomp.o channels.o mode.o xline.o inspstring.o dns.o base.o inspircd_io.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o inspircd.exe +all: timer.o aes.o command_parse.o cull_list.o userprocess.o socketengine.o socket.o hashcomp.o channels.o mode.o xline.o inspstring.o dns.o base.o configreader.o inspsocket.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o inspircd.exe inspircd.exe: inspircd.dll.a \$(CC) -o \$@ \$^ -inspircd.dll inspircd.dll.a: inspircd.o channels.o mode.o xline.o inspstring.o dns.o base.o inspircd_io.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o hashcomp.o socket.o socketengine.o userprocess.o cull_list.o command_parse.o aes.o timer.o +inspircd.dll inspircd.dll.a: inspircd.o channels.o mode.o xline.o inspstring.o dns.o base.o configreader.o inspsocket.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o hashcomp.o socket.o socketengine.o userprocess.o cull_list.o command_parse.o aes.o timer.o \$(CC) -shared -Wl,--out-implib=inspircd.dll.a -o inspircd.dll \$^ EOM } else { print FH <<EOM; -all: timer.o aes.o command_parse.o cull_list.o userprocess.o socketengine.o socket.o hashcomp.o channels.o mode.o xline.o inspstring.o dns.o base.o inspircd_io.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o \$(MODULES) inspircd.exe +all: timer.o aes.o command_parse.o cull_list.o userprocess.o socketengine.o socket.o hashcomp.o channels.o mode.o xline.o inspstring.o dns.o base.o configreader.o inspsocket.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o \$(MODULES) inspircd.exe inspircd.exe: inspircd.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/channels.h ../include/globals.h ../include/inspircd_config.h ../include/base.h - \$(CC) -I../include \$(FLAGS) inspircd.cpp -o inspircd.exe \$(LDLIBS) channels.o mode.o xline.o inspstring.o dns.o base.o inspircd_io.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o hashcomp.o socket.o socketengine.o userprocess.o cull_list.o command_parse.o aes.o timer.o \$(MODULES) + \$(CC) -I../include \$(FLAGS) inspircd.cpp -o inspircd.exe \$(LDLIBS) channels.o mode.o xline.o inspstring.o dns.o base.o inspsocket.o configreader.o message.o $cmdobjs commands.o dnsqueue.o dynamic.o users.o modules.o wildcard.o helperfuncs.o hashcomp.o socket.o socketengine.o userprocess.o cull_list.o command_parse.o aes.o timer.o \$(MODULES) EOM } @@ -1378,8 +1378,8 @@ dns.o: dns.cpp ../include/base.h ../include/dns.h ../include/inspircd.h ../inclu base.o: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp -inspircd_io.o: inspircd_io.cpp ../include/base.h ../include/inspircd_io.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h - \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspircd_io.cpp +configreader.o: configreader.cpp ../include/base.h ../include/configreader.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h + \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c configreader.cpp message.o: message.cpp ../include/base.h ../include/message.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c message.cpp @@ -1404,6 +1404,9 @@ wildcard.o: wildcard.cpp ../include/base.h ../include/wildcard.h ../include/insp socket.o: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp + +inspsocket.o: inspsocket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h + \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspsocket.cpp aes.o: aes.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c aes.cpp @@ -1453,10 +1456,10 @@ CC = im a cheezeball CXXFLAGS = -I../include \${FLAGS} -all: libIRCDtimer.so libIRCDaes.so libIRCDcull_list.so libIRCDuserprocess.so libIRCDsocketengine.so libIRCDsocket.so libIRCDhash.so libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDio.so libIRCDmessage.so $cmdobjs libIRCDcommands.so libIRCDdnsqueue.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDcommand_parse.so inspircd +all: libIRCDtimer.so libIRCDaes.so libIRCDcull_list.so libIRCDuserprocess.so libIRCDsocketengine.so libIRCDsocket.so libIRCDhash.so libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDconfigreader.so libIRCDinspsocket.so libIRCDmessage.so $cmdobjs libIRCDcommands.so libIRCDdnsqueue.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDcommand_parse.so inspircd inspircd: inspircd.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/channels.h ../include/globals.h ../include/inspircd_config.h ../include/socket.h - \$(CC) -I../include -Wl,--rpath -Wl,$config{LIBRARY_DIR} \$(FLAGS) -rdynamic -L. inspircd.cpp -o inspircd \$(LDLIBS) libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDio.so libIRCDmessage.so libIRCDcommands.so libIRCDdnsqueue.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDhash.so libIRCDsocket.so libIRCDsocketengine.so libIRCDuserprocess.so libIRCDcull_list.so libIRCDcommand_parse.so libIRCDaes.so libIRCDtimer.so + \$(CC) -I../include -Wl,--rpath -Wl,$config{LIBRARY_DIR} \$(FLAGS) -rdynamic -L. inspircd.cpp -o inspircd \$(LDLIBS) libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDconfigreader.so libIRCDinspsocket.so libIRCDmessage.so libIRCDcommands.so libIRCDdnsqueue.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDhash.so libIRCDsocket.so libIRCDsocketengine.so libIRCDuserprocess.so libIRCDcull_list.so libIRCDcommand_parse.so libIRCDaes.so libIRCDtimer.so libIRCDsocketengine.so: socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp @@ -1506,9 +1509,9 @@ libIRCDbase.so: base.cpp ../include/base.h ../include/globals.h ../include/inspi \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDbase.so base.o -libIRCDio.so: inspircd_io.cpp ../include/base.h ../include/inspircd_io.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h - \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspircd_io.cpp - \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDio.so inspircd_io.o +libIRCDconfigreader.so: configreader.cpp ../include/base.h ../include/configreader.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h + \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c configreader.cpp + \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDconfigreader.so configreader.o libIRCDmessage.so: message.cpp ../include/base.h ../include/message.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c message.cpp @@ -1542,6 +1545,10 @@ libIRCDsocket.so: socket.cpp ../include/base.h ../include/inspircd.h ../include/ \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsocket.so socket.o +libIRCDinspsocket.so: inspsocket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h + \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspsocket.cpp + \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDinspsocket.so inspsocket.o + libIRCDaes.so: aes.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c aes.cpp \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDaes.so aes.o diff --git a/include/ctables.h b/include/ctables.h index d98e1701d..c4b5aa335 100644 --- a/include/ctables.h +++ b/include/ctables.h @@ -18,18 +18,7 @@ #define __CTABLES_H__ #include "inspircd_config.h" - -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif - -#ifdef GCC3 -#define nspace __gnu_cxx -#else -#define nspace std -#endif +#include "hash_map.h" class userrec; @@ -73,4 +62,3 @@ class command_t typedef nspace::hash_map<std::string,command_t*> command_table; #endif - diff --git a/include/helperfuncs.h b/include/helperfuncs.h index ee434fd08..c9645144f 100644 --- a/include/helperfuncs.h +++ b/include/helperfuncs.h @@ -27,6 +27,14 @@ #include <deque> #include <sstream> +/** Flags for use with log() + */ +#define DEBUG 10 +#define VERBOSE 20 +#define DEFAULT 30 +#define SPARSE 40 +#define NONE 50 + void log(int level,char *text, ...); void readfile(file_cache &F, const char* fname); @@ -84,6 +92,8 @@ void ShowMOTD(userrec *user); void ShowRULES(userrec *user); bool AllModulesReportReady(userrec* user); bool DirValid(char* dirandfile); +bool FileExists(const char* file); +char* CleanFilename(char* name); std::string GetFullProgDir(char** argv, int argc); int InsertMode(std::string &output, const char* modes, unsigned short section); bool IsValidChannelName(const char *); diff --git a/include/inspircd.h b/include/inspircd.h index 822be147e..a9873ff76 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -127,6 +127,13 @@ class InspIRCd }; +/* Miscellaneous stuff here, moved from inspircd_io.h */ +void Exit(int status); +void Start(); +void SetSignals(); +bool DaemonSeed(); +void WritePID(const std::string &filename); + /* userrec optimization stuff */ void AddServerName(std::string servername); const char* FindServerNamePtr(std::string servername); diff --git a/include/inspircd_io.h b/include/inspircd_io.h index 158acfa79..e69de29bb 100644 --- a/include/inspircd_io.h +++ b/include/inspircd_io.h @@ -1,406 +0,0 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ - * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * <brain@chatspike.net> - * <Craig@chatspike.net> - * - * Written by Craig Edwards, Craig McLure, and others. - * This program is free but copyrighted software; see - * the file COPYING for details. - * - * --------------------------------------------------- - */ - -#ifndef __INSPIRCD_IO_H__ -#define __INSPIRCD_IO_H__ - -#include <sstream> -#include <string> -#include <vector> -#include <map> -#include "inspircd.h" -#include "globals.h" -#include "modules.h" - -/** Flags for use with log() - */ -#define DEBUG 10 -#define VERBOSE 20 -#define DEFAULT 30 -#define SPARSE 40 -#define NONE 50 - -typedef bool (*Validator)(const char*, const char*, void*); -typedef bool (*MultiValidator)(const char*, char**, void**, int*); -typedef bool (*MultiNotify)(const char*); - -enum ConfigDataType { DT_NOTHING, DT_INTEGER, DT_CHARPTR, DT_BOOLEAN }; - -struct InitialConfig { - char* tag; - char* value; - void* val; - ConfigDataType datatype; - Validator validation_function; -}; - -struct MultiConfig { - const char* tag; - char* items[12]; - int datatype[12]; - MultiNotify init_function; - MultiValidator validation_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 : public classbase -{ - 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<std::string> include_stack; - - /** This private method processes one line of - * configutation, appending errors to errorstream - * and setting error if an error has occured. - */ - bool ParseLine(ConfigDataHash &target, std::string &line, long linenumber, std::ostringstream &errorstream); - - bool DoInclude(ConfigDataHash &target, const std::string &file, std::ostringstream &errorstream); - - /** Check that there is only one of each configuration item - */ - bool CheckOnce(char* tag, bool bail, userrec* user); - - public: - - /** This holds all the information in the config file, - * it's indexed by tag name to a vector of key/values. - */ - ConfigDataHash config_data; - - /** Holds the server name of the local server - * as defined by the administrator. - */ - char ServerName[MAXBUF]; - - /* Holds the network name the local server - * belongs to. This is an arbitary field defined - * by the administrator. - */ - char Network[MAXBUF]; - - /** Holds the description of the local server - * as defined by the administrator. - */ - char ServerDesc[MAXBUF]; - - /** Holds the admin's name, for output in - * the /ADMIN command. - */ - char AdminName[MAXBUF]; - - /** Holds the email address of the admin, - * for output in the /ADMIN command. - */ - char AdminEmail[MAXBUF]; - - /** Holds the admin's nickname, for output - * in the /ADMIN command - */ - char AdminNick[MAXBUF]; - - /** The admin-configured /DIE password - */ - char diepass[MAXBUF]; - - /** The admin-configured /RESTART password - */ - char restartpass[MAXBUF]; - - /** The pathname and filename of the message of the - * day file, as defined by the administrator. - */ - char motd[MAXBUF]; - - /** The pathname and filename of the rules file, - * as defined by the administrator. - */ - char rules[MAXBUF]; - - /** The quit prefix in use, or an empty string - */ - char PrefixQuit[MAXBUF]; - - /** The last string found within a <die> tag, or - * an empty string. - */ - char DieValue[MAXBUF]; - - /** The DNS server to use for DNS queries - */ - char DNSServer[MAXBUF]; - - /** This variable contains a space-seperated list - * of commands which are disabled by the - * administrator of the server for non-opers. - */ - char DisabledCommands[MAXBUF]; - - /** The full path to the modules directory. - * This is either set at compile time, or - * overridden in the configuration file via - * the <options> tag. - */ - char ModPath[1024]; - - /** The temporary directory where modules are copied - */ - char TempDir[1024]; - - /** The full pathname to the executable, as - * given in argv[0] when the program starts. - */ - char MyExecutable[1024]; - - /** The file handle of the logfile. If this - * value is NULL, the log file is not open, - * probably due to a permissions error on - * startup (this should not happen in normal - * operation!). - */ - FILE *log_file; - - /** If this value is true, the owner of the - * server specified -nofork on the command - * line, causing the daemon to stay in the - * foreground. - */ - bool nofork; - - /** If this value if true then all log - * messages will be output, regardless of - * the level given in the config file. - * This is set with the -debug commandline - * option. - */ - bool forcedebug; - - /** If this is true then log output will be - * written to the logfile. This is the default. - * If you put -nolog on the commandline then - * the logfile will not be written. - * This is meant to be used in conjunction with - * -debug for debugging without filling up the - * hard disk. - */ - bool writelog; - - /** If this value is true, halfops have been - * enabled in the configuration file. - */ - bool AllowHalfop; - - /** The number of seconds the DNS subsystem - * will wait before timing out any request. - */ - int dns_timeout; - - /** The size of the read() buffer in the user - * handling code, used to read data into a user's - * recvQ. - */ - int NetBufferSize; - - /** The value to be used for listen() backlogs - * as default. - */ - int MaxConn; - - /** The soft limit value assigned to the irc server. - * The IRC server will not allow more than this - * number of local users. - */ - unsigned int SoftLimit; - - /** Maximum number of targets for a multi target command - * such as PRIVMSG or KICK - */ - unsigned int MaxTargets; - - /** The maximum number of /WHO results allowed - * in any single /WHO command. - */ - int MaxWhoResults; - - /** True if the DEBUG loglevel is selected. - */ - int debugging; - - /** The loglevel in use by the IRC server - */ - int LogLevel; - - /** How many seconds to wait before exiting - * the program when /DIE is correctly issued. - */ - int DieDelay; - - /** True if we're going to hide netsplits as *.net *.split for non-opers - */ - bool HideSplits; - - /** True if we're going to hide ban reasons for non-opers (e.g. G-Lines, - * K-Lines, Z-Lines) - */ - bool HideBans; - - /** If this is enabled then operators will - * see invisible (+i) channels in /whois. - */ - bool OperSpyWhois; - - /** Set to a non-empty string to obfuscate the server name of users in WHOIS - */ - char HideWhoisServer[MAXBUF]; - - /** A list of IP addresses the server is listening - * on. - */ - char addrs[MAXBUF][255]; - - /** The MOTD file, cached in a file_cache type. - */ - file_cache MOTD; - - /** The RULES file, cached in a file_cache type. - */ - file_cache RULES; - - /** The full pathname and filename of the PID - * file as defined in the configuration. - */ - char PID[1024]; - - /** The connect classes in use by the IRC server. - */ - ClassVector Classes; - - /** A list of module names (names only, no paths) - * which are currently loaded by the server. - */ - std::vector<std::string> module_names; - - /** A list of ports which the server is listening on - */ - int ports[255]; - - /** Boolean sets of which modules implement which functions - */ - char implement_lists[255][255]; - - /** Global implementation list - */ - char global_implementation[255]; - - /** A list of ports claimed by IO Modules - */ - std::map<int,Module*> IOHookModule; - - /** The 005 tokens of this server (ISUPPORT) - * populated/repopulated upon loading or unloading - * modules. - */ - std::string data005; - - /** STATS characters in this list are available - * only to operators. - */ - char OperOnlyStats[MAXBUF]; - - /** The path and filename of the ircd.log file - */ - std::string logpath; - - /** Custom version string, which if defined can replace the system info in VERSION. - */ - char CustomVersion[MAXBUF]; - - /** List of u-lined servers - */ - std::vector<irc::string> ulines; - - /** Max banlist sizes for channels (the std::string is a glob) - */ - std::map<std::string,int> maxbans; - - 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. - */ - void Read(bool bail, userrec* user); - - /** 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 &target, const char* filename, std::ostringstream &errorstream); - bool LoadConf(ConfigDataHash &target, const std::string &filename, std::ostringstream &errorstream); - - /* Both these return true if the value existed or false otherwise */ - - /* Writes 'length' chars into 'result' as a string */ - bool ConfValue(ConfigDataHash &target, const char* tag, const char* var, int index, char* result, int length); - bool ConfValue(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, std::string &result); - - /* Tries to convert the value to an integer and write it to 'result' */ - bool ConfValueInteger(ConfigDataHash &target, const char* tag, const char* var, int index, int &result); - bool ConfValueInteger(ConfigDataHash &target, const std::string &tag, const std::string &var, int index, int &result); - - /* Returns true if the value exists and has a true value, false otherwise */ - bool ConfValueBool(ConfigDataHash &target, const char* tag, const char* var, int index); - bool ConfValueBool(ConfigDataHash &target, const std::string &tag, const std::string &var, int index); - - /* Returns the number of occurences of tag in the config file */ - int ConfValueEnum(ConfigDataHash &target, const char* tag); - int ConfValueEnum(ConfigDataHash &target, const std::string &tag); - - /* Returns the numbers of vars inside the index'th 'tag in the config file */ - int ConfVarEnum(ConfigDataHash &target, const char* tag, int index); - int ConfVarEnum(ConfigDataHash &target, const std::string &tag, int index); - - Module* GetIOHook(int port); - bool AddIOHook(int port, Module* iomod); - bool DelIOHook(int port); -}; - - -void Exit(int status); -void Start(); -void SetSignals(); -bool DaemonSeed(); -bool FileExists(const char* file); -int OpenTCPSocket(); -bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr); -void WritePID(const std::string &filename); -int BindPorts(bool bail); -char* CleanFilename(char* name); - -#endif diff --git a/include/inspsocket.h b/include/inspsocket.h new file mode 100644 index 000000000..caa1490b5 --- /dev/null +++ b/include/inspsocket.h @@ -0,0 +1,374 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. + * E-mail: + * <brain@chatspike.net> + * <Craig@chatspike.net> + * + * Written by Craig Edwards, Craig McLure, and others. + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#ifndef __INSP_SOCKET_H__ +#define __INSP_SOCKET_H__ + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <sstream> +#include <string> +#include <deque> +#include "dns.h" +#include "inspircd_config.h" + +/* macros to the relevant system address description structs */ +#ifdef IPV6 + +typedef struct sockaddr_in6 insp_sockaddr; +typedef struct in6_addr insp_inaddr; + +#else + +typedef struct sockaddr_in insp_sockaddr; +typedef struct in_addr insp_inaddr; + +#endif + +/** + * States which a socket may be in + */ +enum InspSocketState { I_DISCONNECTED, I_RESOLVING, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR }; + +/** + * Error types which a socket may exhibit + */ +enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT, I_ERR_BIND, I_ERR_RESOLVE, I_ERR_WRITE }; + +/** + * InspSocket is an extendable socket class which modules + * can use for TCP socket support. It is fully integrated + * into InspIRCds socket loop and attaches its sockets to + * the core's instance of the SocketEngine class, meaning + * that any sockets you create have the same power and + * abilities as a socket created by the core itself. + * To use InspSocket, you must inherit a class from it, + * and use the InspSocket constructors to establish connections + * and bindings. + */ +class InspSocket +{ +private: + + std::deque<std::string> outbuffer; + + /** + * The file descriptor of this socket + */ + int fd; + + /** + * The resolver for this socket + */ + DNS dns; + + /** + * The hostname connected to + */ + char host[MAXBUF]; + + /** + * The port connected to, or the port + * this socket is listening on + */ + int port; + + /** + * The state for this socket, either + * listening, connecting, connected + * or error. + */ + InspSocketState state; + + /** + * The host being connected to, + * in sockaddr form + */ + insp_sockaddr addr; + + /** + * The host being connected to, + * in in_addr form + */ + insp_inaddr addy; + + /** + * When this time is reached, + * the socket times out if it is + * in the CONNECTING state + */ + time_t timeout_end; + + /** + * This value is true if the + * socket has timed out. + */ + bool timeout; + + /** + * Socket input buffer, used by read(). The class which + * extends InspSocket is expected to implement an extendable + * buffer which can grow much larger than 64k, + * this buffer is just designed to be temporary storage. + * space. + */ + char ibuf[65535]; + + /** + * The IP address being connected + * to stored in string form for + * easy retrieval by accessors. + */ + char IP[MAXBUF]; + + /** + * Client sockaddr structure used + * by accept() + */ + insp_sockaddr client; + + /** + * Server sockaddr structure used + * by accept() + */ + insp_sockaddr server; + + /** + * Used by accept() to indicate the + * sizes of the sockaddr_in structures + */ + socklen_t length; + + /** Flushes the write buffer + */ + bool FlushWriteBuffer(); + + /** Set the queue sizes + * This private method sets the operating system queue + * sizes for this socket to 65535 so that it can queue + * more information without application-level queueing + * which was required in older software. + */ + void SetQueues(int nfd); + + /** When the socket has been marked as closing, this flag + * will be set to true, then the next time the socket is + * examined, the socket is deleted and closed. + */ + bool ClosePending; + +public: + + /** + * The default constructor does nothing + * and should not be used. + */ + InspSocket(); + + /** + * This constructor is used to associate + * an existing connecting with an InspSocket + * class. The given file descriptor must be + * valid, and when initialized, the InspSocket + * will be set with the given IP address + * and placed in CONNECTED state. + */ + InspSocket(int newfd, char* ip); + + /** + * This constructor is used to create a new + * socket, either listening for connections, or an outbound connection to another host. + * Note that if you specify a hostname in the 'host' parameter, then there will be an extra + * step involved (a nonblocking DNS lookup) which will cause your connection to be established + * slower than if it was an IP. Therefore, use an IP address where it is available instead. + * @param host The hostname to connect to, or bind to + * @param port The port number to connect to, or bind to + * @param listening true to listen on the given host:port pair, or false to connect to them + * @param maxtime Number of seconds to wait, if connecting, before the connection times out and an OnTimeout() event is generated + */ + InspSocket(const std::string &host, int port, bool listening, unsigned long maxtime); + + /** + * This method is called when an outbound + * connection on your socket is completed. + * @return false to abort the connection, true to continue + */ + virtual bool OnConnected(); + + /** + * This method is called when an error occurs. + * A closed socket in itself is not an error, + * however errors also generate close events. + * @param e The error type which occured + */ + virtual void OnError(InspSocketError e); + + /** + * When an established connection is terminated, + * the OnDisconnect method is triggered. + */ + virtual int OnDisconnect(); + + /** + * When there is data waiting to be read on a + * socket, the OnDataReady() method is called. + * Within this method, you *MUST* call the Read() + * method to read any pending data. At its lowest + * level, this event is signalled by the core via + * the socket engine. If you return false from this + * function, the core removes your socket from its + * list and erases it from the socket engine, then + * calls InspSocket::Close() and deletes it. + * @return false to close the socket + */ + virtual bool OnDataReady(); + + /** + * When an outbound connection fails, and the + * attempt times out, you will receive this event. + * The method will trigger once maxtime seconds are + * reached (as given in the constructor) just + * before the socket's descriptor is closed. + * A failed DNS lookup may cause this event if + * the DNS server is not responding, as well as + * a failed connect() call, because DNS lookups are + * nonblocking as implemented by this class. + */ + virtual void OnTimeout(); + + /** + * Whenever close() is called, OnClose() will be + * called first. Please note that this means + * OnClose will be called alongside OnError(), + * OnTimeout(), and Close(), and also when + * cancelling a listening socket by calling + * the destructor indirectly. + */ + virtual void OnClose(); + + /** + * Reads all pending bytes from the socket + * into a char* array which can be up to + * 16 kilobytes in length. + */ + virtual char* Read(); + + /** + * Returns the IP address associated with + * this connection, or an empty string if + * no IP address exists. + */ + std::string GetIP(); + + /** + * This function checks if the socket has + * timed out yet, given the current time + * in the parameter. + * @return true if timed out, false if not timed out + */ + bool Timeout(time_t current); + + /** + * Writes a std::string to the socket. No carriage + * returns or linefeeds are appended to the string. + * @param data The data to send + */ + virtual int Write(const std::string &data); + + /** + * If your socket is a listening socket, when a new + * connection comes in on the socket this method will + * be called. Given the new file descriptor in the + * parameters, and the IP, it is recommended you copy + * them to a new instance of your socket class, + * e.g.: + * + * MySocket* newsocket = new MySocket(newfd,ip); + * + * Once you have done this, you can then associate the + * new socket with the core using Server::AddSocket(). + */ + virtual int OnIncomingConnection(int newfd, char* ip); + + /** + * Changes the socket's state. The core uses this + * to change socket states, and you should not call + * it directly. + */ + void SetState(InspSocketState s); + + /** + * Returns the current socket state. + */ + InspSocketState GetState(); + + /** + * Only the core should call this function. + * When called, it is assumed the socket is ready + * to read data, and the method call routes the + * event to the various methods of InspSocket + * for you to handle. This can also cause the + * socket's state to change. + */ + bool Poll(); + + /** + * This method returns the socket's file descriptor + * as assigned by the operating system, or -1 + * if no descriptor has been assigned. + */ + int GetFd(); + + /** + * This method causes the socket to close, and may + * also be triggered by other methods such as OnTimeout + * and OnError. + */ + virtual void Close(); + + /** + * The destructor may implicitly call OnClose(), and + * will close() and shutdown() the file descriptor + * used for this socket. + */ + virtual ~InspSocket(); + + /** + * This method attempts to resolve the hostname, + * if a hostname is given and not an IP, + * before a connection can occur. This method is + * asyncronous. + */ + virtual bool DoResolve(); + + /** + * This method attempts to connect to a hostname. + * This only occurs on a non-listening socket. This + * method is asyncronous. + */ + virtual bool DoConnect(); + + /** + * This method marks the socket closed. + * The next time the core examines a socket marked + * as closed, the socket will be closed and the + * memory reclaimed. + */ + void MarkAsClosed(); +}; + +#endif diff --git a/include/modules.h b/include/modules.h index a57fbef1a..f15341e01 100644 --- a/include/modules.h +++ b/include/modules.h @@ -68,7 +68,7 @@ enum TargetTypeFlags { #include "dynamic.h" #include "base.h" #include "ctables.h" -#include "socket.h" +#include "inspsocket.h" #include <string> #include <deque> #include <sstream> @@ -102,7 +102,7 @@ typedef std::deque<userrec*> chanuserlist; } \ catch (ModuleException& modexcept) \ { \ - log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ + log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \ } \ } \ } @@ -1932,6 +1932,8 @@ class ModuleFactory : public classbase typedef DLLFactory<ModuleFactory> ircd_module; +typedef std::vector<Module*> ModuleList; +typedef std::vector<ircd_module*> FactoryList; bool ModeDefined(char c, int i); bool ModeDefinedOper(char c, int i); diff --git a/include/socket.h b/include/socket.h index caa1490b5..b7b2b3d40 100644 --- a/include/socket.h +++ b/include/socket.h @@ -14,16 +14,20 @@ * --------------------------------------------------- */ -#ifndef __INSP_SOCKET_H__ -#define __INSP_SOCKET_H__ +#ifndef INSPIRCD_SOCKET_H +#define INSPIRCD_SOCKET_H +/* This is where we'll define wrappers for socket IO stuff, for neat winsock compatability */ + +#include <sys/time.h> +#include <sys/resource.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> -#include <sstream> -#include <string> -#include <deque> -#include "dns.h" +#include <unistd.h> +#include <fcntl.h> +#include <poll.h> + #include "inspircd_config.h" /* macros to the relevant system address description structs */ @@ -39,336 +43,8 @@ typedef struct in_addr insp_inaddr; #endif -/** - * States which a socket may be in - */ -enum InspSocketState { I_DISCONNECTED, I_RESOLVING, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR }; - -/** - * Error types which a socket may exhibit - */ -enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT, I_ERR_BIND, I_ERR_RESOLVE, I_ERR_WRITE }; - -/** - * InspSocket is an extendable socket class which modules - * can use for TCP socket support. It is fully integrated - * into InspIRCds socket loop and attaches its sockets to - * the core's instance of the SocketEngine class, meaning - * that any sockets you create have the same power and - * abilities as a socket created by the core itself. - * To use InspSocket, you must inherit a class from it, - * and use the InspSocket constructors to establish connections - * and bindings. - */ -class InspSocket -{ -private: - - std::deque<std::string> outbuffer; - - /** - * The file descriptor of this socket - */ - int fd; - - /** - * The resolver for this socket - */ - DNS dns; - - /** - * The hostname connected to - */ - char host[MAXBUF]; - - /** - * The port connected to, or the port - * this socket is listening on - */ - int port; - - /** - * The state for this socket, either - * listening, connecting, connected - * or error. - */ - InspSocketState state; - - /** - * The host being connected to, - * in sockaddr form - */ - insp_sockaddr addr; - - /** - * The host being connected to, - * in in_addr form - */ - insp_inaddr addy; - - /** - * When this time is reached, - * the socket times out if it is - * in the CONNECTING state - */ - time_t timeout_end; - - /** - * This value is true if the - * socket has timed out. - */ - bool timeout; - - /** - * Socket input buffer, used by read(). The class which - * extends InspSocket is expected to implement an extendable - * buffer which can grow much larger than 64k, - * this buffer is just designed to be temporary storage. - * space. - */ - char ibuf[65535]; - - /** - * The IP address being connected - * to stored in string form for - * easy retrieval by accessors. - */ - char IP[MAXBUF]; - - /** - * Client sockaddr structure used - * by accept() - */ - insp_sockaddr client; - - /** - * Server sockaddr structure used - * by accept() - */ - insp_sockaddr server; - - /** - * Used by accept() to indicate the - * sizes of the sockaddr_in structures - */ - socklen_t length; - - /** Flushes the write buffer - */ - bool FlushWriteBuffer(); - - /** Set the queue sizes - * This private method sets the operating system queue - * sizes for this socket to 65535 so that it can queue - * more information without application-level queueing - * which was required in older software. - */ - void SetQueues(int nfd); - - /** When the socket has been marked as closing, this flag - * will be set to true, then the next time the socket is - * examined, the socket is deleted and closed. - */ - bool ClosePending; - -public: - - /** - * The default constructor does nothing - * and should not be used. - */ - InspSocket(); - - /** - * This constructor is used to associate - * an existing connecting with an InspSocket - * class. The given file descriptor must be - * valid, and when initialized, the InspSocket - * will be set with the given IP address - * and placed in CONNECTED state. - */ - InspSocket(int newfd, char* ip); - - /** - * This constructor is used to create a new - * socket, either listening for connections, or an outbound connection to another host. - * Note that if you specify a hostname in the 'host' parameter, then there will be an extra - * step involved (a nonblocking DNS lookup) which will cause your connection to be established - * slower than if it was an IP. Therefore, use an IP address where it is available instead. - * @param host The hostname to connect to, or bind to - * @param port The port number to connect to, or bind to - * @param listening true to listen on the given host:port pair, or false to connect to them - * @param maxtime Number of seconds to wait, if connecting, before the connection times out and an OnTimeout() event is generated - */ - InspSocket(const std::string &host, int port, bool listening, unsigned long maxtime); - - /** - * This method is called when an outbound - * connection on your socket is completed. - * @return false to abort the connection, true to continue - */ - virtual bool OnConnected(); - - /** - * This method is called when an error occurs. - * A closed socket in itself is not an error, - * however errors also generate close events. - * @param e The error type which occured - */ - virtual void OnError(InspSocketError e); - - /** - * When an established connection is terminated, - * the OnDisconnect method is triggered. - */ - virtual int OnDisconnect(); - - /** - * When there is data waiting to be read on a - * socket, the OnDataReady() method is called. - * Within this method, you *MUST* call the Read() - * method to read any pending data. At its lowest - * level, this event is signalled by the core via - * the socket engine. If you return false from this - * function, the core removes your socket from its - * list and erases it from the socket engine, then - * calls InspSocket::Close() and deletes it. - * @return false to close the socket - */ - virtual bool OnDataReady(); - - /** - * When an outbound connection fails, and the - * attempt times out, you will receive this event. - * The method will trigger once maxtime seconds are - * reached (as given in the constructor) just - * before the socket's descriptor is closed. - * A failed DNS lookup may cause this event if - * the DNS server is not responding, as well as - * a failed connect() call, because DNS lookups are - * nonblocking as implemented by this class. - */ - virtual void OnTimeout(); - - /** - * Whenever close() is called, OnClose() will be - * called first. Please note that this means - * OnClose will be called alongside OnError(), - * OnTimeout(), and Close(), and also when - * cancelling a listening socket by calling - * the destructor indirectly. - */ - virtual void OnClose(); - - /** - * Reads all pending bytes from the socket - * into a char* array which can be up to - * 16 kilobytes in length. - */ - virtual char* Read(); - - /** - * Returns the IP address associated with - * this connection, or an empty string if - * no IP address exists. - */ - std::string GetIP(); - - /** - * This function checks if the socket has - * timed out yet, given the current time - * in the parameter. - * @return true if timed out, false if not timed out - */ - bool Timeout(time_t current); - - /** - * Writes a std::string to the socket. No carriage - * returns or linefeeds are appended to the string. - * @param data The data to send - */ - virtual int Write(const std::string &data); - - /** - * If your socket is a listening socket, when a new - * connection comes in on the socket this method will - * be called. Given the new file descriptor in the - * parameters, and the IP, it is recommended you copy - * them to a new instance of your socket class, - * e.g.: - * - * MySocket* newsocket = new MySocket(newfd,ip); - * - * Once you have done this, you can then associate the - * new socket with the core using Server::AddSocket(). - */ - virtual int OnIncomingConnection(int newfd, char* ip); - - /** - * Changes the socket's state. The core uses this - * to change socket states, and you should not call - * it directly. - */ - void SetState(InspSocketState s); - - /** - * Returns the current socket state. - */ - InspSocketState GetState(); - - /** - * Only the core should call this function. - * When called, it is assumed the socket is ready - * to read data, and the method call routes the - * event to the various methods of InspSocket - * for you to handle. This can also cause the - * socket's state to change. - */ - bool Poll(); - - /** - * This method returns the socket's file descriptor - * as assigned by the operating system, or -1 - * if no descriptor has been assigned. - */ - int GetFd(); - - /** - * This method causes the socket to close, and may - * also be triggered by other methods such as OnTimeout - * and OnError. - */ - virtual void Close(); - - /** - * The destructor may implicitly call OnClose(), and - * will close() and shutdown() the file descriptor - * used for this socket. - */ - virtual ~InspSocket(); - - /** - * This method attempts to resolve the hostname, - * if a hostname is given and not an IP, - * before a connection can occur. This method is - * asyncronous. - */ - virtual bool DoResolve(); - - /** - * This method attempts to connect to a hostname. - * This only occurs on a non-listening socket. This - * method is asyncronous. - */ - virtual bool DoConnect(); - - /** - * This method marks the socket closed. - * The next time the core examines a socket marked - * as closed, the socket will be closed and the - * memory reclaimed. - */ - void MarkAsClosed(); -}; +int OpenTCPSocket(); +bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr); +int BindPorts(bool bail); #endif diff --git a/src/channels.cpp b/src/channels.cpp index 164525abe..4eba586ab 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -16,7 +16,7 @@ using namespace std; -#include "inspircd_config.h" +#include "configreader.h" #include "inspircd.h" #include "inspircd_io.h" #include <unistd.h> @@ -672,5 +672,3 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason) } } } - - diff --git a/src/cmd_admin.cpp b/src/cmd_admin.cpp index 0bb4b07fe..735e593c7 100644 --- a/src/cmd_admin.cpp +++ b/src/cmd_admin.cpp @@ -14,23 +14,10 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <string> -#include <vector> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" #include "cmd_admin.h" extern ServerConfig* Config; @@ -42,5 +29,3 @@ void cmd_admin::Handle (char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"258 %s :Nickname - %s",user->nick,Config->AdminNick); WriteServ(user->fd,"258 %s :E-Mail - %s",user->nick,Config->AdminEmail); } - - diff --git a/src/cmd_away.cpp b/src/cmd_away.cpp index 65e613acb..732cf9d91 100644 --- a/src/cmd_away.cpp +++ b/src/cmd_away.cpp @@ -14,27 +14,13 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <string> -#include <map> -#include <sstream> #include <vector> -#include <deque> +#include "inspircd_config.h" +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "message.h" #include "commands.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" #include "cmd_away.h" extern ServerConfig* Config; @@ -59,5 +45,3 @@ void cmd_away::Handle (char **parameters, int pcnt, userrec *user) FOREACH_MOD(I_OnCancelAway,OnCancelAway(user)); } } - - diff --git a/src/cmd_die.cpp b/src/cmd_die.cpp index bc8f58099..a8d3f14e6 100644 --- a/src/cmd_die.cpp +++ b/src/cmd_die.cpp @@ -14,23 +14,13 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> +#include <unistd.h> #include <string> +#include <vector> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" #include "cmd_die.h" extern ServerConfig* Config; diff --git a/src/cmd_eline.cpp b/src/cmd_eline.cpp index b7b49472c..e25f2b7fe 100644 --- a/src/cmd_eline.cpp +++ b/src/cmd_eline.cpp @@ -14,31 +14,14 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> #include <string> -#include <map> -#include <sstream> #include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" #include "xline.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_eline.h" extern int MODCOUNT; @@ -80,5 +63,3 @@ void cmd_eline::Handle (char **parameters, int pcnt, userrec *user) // no need to apply the lines for an eline } - - diff --git a/src/cmd_gline.cpp b/src/cmd_gline.cpp index 5285383cc..0d01c0875 100644 --- a/src/cmd_gline.cpp +++ b/src/cmd_gline.cpp @@ -14,31 +14,14 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> #include <string> -#include <map> -#include <sstream> #include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" #include "xline.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_eline.h" extern ServerConfig* Config; @@ -80,5 +63,3 @@ void cmd_gline::Handle (char **parameters, int pcnt, userrec *user) } } } - - diff --git a/src/cmd_info.cpp b/src/cmd_info.cpp index 692fa0e07..1f3e3182f 100644 --- a/src/cmd_info.cpp +++ b/src/cmd_info.cpp @@ -14,23 +14,11 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <string> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "message.h" #include "commands.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" #include "cmd_info.h" extern ServerConfig* Config; @@ -82,5 +70,3 @@ void cmd_info::Handle (char **parameters, int pcnt, userrec *user) FOREACH_MOD(I_OnInfo,OnInfo(user)); WriteServ(user->fd, "374 %s :End of /INFO list", user->nick); } - - diff --git a/src/cmd_invite.cpp b/src/cmd_invite.cpp index 33e61189d..8baeb30b0 100644 --- a/src/cmd_invite.cpp +++ b/src/cmd_invite.cpp @@ -14,26 +14,13 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <string> #include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "message.h" #include "commands.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" -#include "command_parse.h" +#include "message.h" #include "cmd_invite.h" extern ServerConfig* Config; diff --git a/src/cmd_kill.cpp b/src/cmd_kill.cpp index f90347e95..44594a0e1 100644 --- a/src/cmd_kill.cpp +++ b/src/cmd_kill.cpp @@ -14,30 +14,14 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif #include <vector> -#include <deque> +#include "inspircd_config.h" +#include "hash_map.h" +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "message.h" #include "commands.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" #include "cmd_kill.h" extern ServerConfig* Config; @@ -103,5 +87,3 @@ void cmd_kill::Handle (char **parameters, int pcnt, userrec *user) WriteServ(user->fd, "401 %s %s :No such nick/channel", user->nick, parameters[0]); } } - - diff --git a/src/cmd_kline.cpp b/src/cmd_kline.cpp index 9c840b469..d6805c4d5 100644 --- a/src/cmd_kline.cpp +++ b/src/cmd_kline.cpp @@ -14,53 +14,28 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" #include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif #include <map> #include <sstream> #include <vector> #include <deque> + +#include "inspircd_config.h" +#include "configreader.h" +#include "hash_map.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" #include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_kline.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; extern int MODCOUNT; extern std::vector<Module*> modules; extern std::vector<ircd_module*> factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; - -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_kline::Handle (char **parameters, int pcnt, userrec *user) { @@ -96,5 +71,3 @@ void cmd_kline::Handle (char **parameters, int pcnt, userrec *user) } } } - - diff --git a/src/cmd_links.cpp b/src/cmd_links.cpp index 9b1061a03..e94a04edc 100644 --- a/src/cmd_links.cpp +++ b/src/cmd_links.cpp @@ -14,23 +14,12 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <string> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "message.h" #include "commands.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" #include "cmd_links.h" extern ServerConfig* Config; @@ -40,5 +29,3 @@ void cmd_links::Handle (char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"364 %s %s %s :0 %s",user->nick,Config->ServerName,Config->ServerName,Config->ServerDesc); WriteServ(user->fd,"365 %s * :End of /LINKS list.",user->nick); } - - diff --git a/src/cmd_map.cpp b/src/cmd_map.cpp index 5949420aa..07173eb2a 100644 --- a/src/cmd_map.cpp +++ b/src/cmd_map.cpp @@ -14,21 +14,11 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "message.h" #include "commands.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_map.h" extern ServerConfig* Config; @@ -41,4 +31,3 @@ void cmd_map::Handle (char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"006 %s :%s",user->nick,Config->ServerName); WriteServ(user->fd,"007 %s :End of /MAP",user->nick); } - diff --git a/src/cmd_modules.cpp b/src/cmd_modules.cpp index 0e5b12672..e4e208f7d 100644 --- a/src/cmd_modules.cpp +++ b/src/cmd_modules.cpp @@ -14,53 +14,27 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" #include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif #include <map> #include <sstream> #include <vector> #include <deque> +#include "inspircd_config.h" +#include "inspircd.h" +#include "configreader.h" +#include "hash_map.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" +#include "wildcard.h" #include "cmd_modules.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; extern int MODCOUNT; extern std::vector<Module*> modules; extern std::vector<ircd_module*> factory; -extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; - -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; char* itab[] = { "OnUserConnect", "OnUserQuit", "OnUserDisconnect", "OnUserJoin", "OnUserPart", "OnRehash", "OnServerRaw", @@ -143,5 +117,3 @@ void cmd_modules::Handle (char **parameters, int pcnt, userrec *user) } WriteServ(user->fd,"901 %s :End of MODULES list",user->nick); } - - diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp index 26a603867..16b3d2b94 100644 --- a/src/cmd_nick.cpp +++ b/src/cmd_nick.cpp @@ -14,53 +14,26 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> #include <vector> -#include <deque> +#include "inspircd_config.h" +#include "configreader.h" +#include "hash_map.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" #include "xline.h" -#include "inspstring.h" #include "dnsqueue.h" #include "dns.h" #include "helperfuncs.h" #include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_nick.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; extern int MODCOUNT; extern std::vector<Module*> modules; extern std::vector<ircd_module*> factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_nick::Handle (char **parameters, int pcnt, userrec *user) { @@ -194,4 +167,3 @@ void cmd_nick::Handle (char **parameters, int pcnt, userrec *user) FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick)); } } - diff --git a/src/cmd_notice.cpp b/src/cmd_notice.cpp index 784f1e185..6a9af4a40 100644 --- a/src/cmd_notice.cpp +++ b/src/cmd_notice.cpp @@ -14,39 +14,19 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif #include <map> #include <sstream> #include <vector> #include <deque> +#include "configreader.h" +#include "hash_map.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" #include "message.h" +#include "wildcard.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" #include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_notice.h" extern ServerConfig* Config; @@ -55,11 +35,6 @@ extern int MODCOUNT; extern std::vector<Module*> modules; extern std::vector<ircd_module*> factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_notice::Handle (char **parameters, int pcnt, userrec *user) { @@ -159,5 +134,3 @@ void cmd_notice::Handle (char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } - - diff --git a/src/cmd_oper.cpp b/src/cmd_oper.cpp index 2681da13e..718465e9f 100644 --- a/src/cmd_oper.cpp +++ b/src/cmd_oper.cpp @@ -14,24 +14,13 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> #include <sstream> #include <vector> -#include <deque> +#include "inspircd_config.h" +#include "configreader.h" +#include "typedefs.h" #include "users.h" -#include "ctables.h" #include "globals.h" #include "modules.h" #include "dynamic.h" @@ -45,21 +34,15 @@ using namespace std; #include "helperfuncs.h" #include "hashcomp.h" #include "socketengine.h" -#include "typedefs.h" + #include "command_parse.h" #include "cmd_oper.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; bool OneOfMatches(const char* host, const char* hostlist) { diff --git a/src/cmd_ping.cpp b/src/cmd_ping.cpp index ee43c0cb8..2ac09e6c4 100644 --- a/src/cmd_ping.cpp +++ b/src/cmd_ping.cpp @@ -14,56 +14,15 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_ping.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; -extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; -extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_ping::Handle (char **parameters, int pcnt, userrec *user) { WriteServ(user->fd,"PONG %s :%s",Config->ServerName,parameters[0]); } - - diff --git a/src/cmd_privmsg.cpp b/src/cmd_privmsg.cpp index 85bb4d6d2..0814c08c4 100644 --- a/src/cmd_privmsg.cpp +++ b/src/cmd_privmsg.cpp @@ -14,52 +14,24 @@ * --------------------------------------------------- */ -using namespace std; - +#include <string> #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" #include "message.h" +#include "wildcard.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_privmsg.h" extern ServerConfig* Config; extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_privmsg::Handle (char **parameters, int pcnt, userrec *user) { @@ -163,5 +135,3 @@ void cmd_privmsg::Handle (char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]); } } - - diff --git a/src/cmd_qline.cpp b/src/cmd_qline.cpp index 76e9a7b80..e86c23a09 100644 --- a/src/cmd_qline.cpp +++ b/src/cmd_qline.cpp @@ -14,37 +14,19 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" #include "xline.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_eline.h" extern ServerConfig* Config; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; void cmd_qline::Handle (char **parameters, int pcnt, userrec *user) { @@ -77,5 +59,3 @@ void cmd_qline::Handle (char **parameters, int pcnt, userrec *user) } } } - - diff --git a/src/cmd_quit.cpp b/src/cmd_quit.cpp index 4863d6333..e3529278c 100644 --- a/src/cmd_quit.cpp +++ b/src/cmd_quit.cpp @@ -14,22 +14,11 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> +#include "configreader.h" #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> #include <vector> -#include <deque> #include "users.h" #include "ctables.h" #include "globals.h" @@ -45,19 +34,16 @@ using namespace std; #include "helperfuncs.h" #include "hashcomp.h" #include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_quit.h" extern ServerConfig* Config; extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; extern time_t TIME; extern user_hash clientlist; extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; extern std::vector<userrec*> local_users; extern userrec* fd_ref_table[MAX_DESCRIPTORS]; @@ -133,5 +119,3 @@ void cmd_quit::Handle (char **parameters, int pcnt, userrec *user) fd_ref_table[user->fd] = NULL; delete user; } - - diff --git a/src/cmd_rehash.cpp b/src/cmd_rehash.cpp index 421ad9b13..8c219ad90 100644 --- a/src/cmd_rehash.cpp +++ b/src/cmd_rehash.cpp @@ -14,52 +14,18 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_rehash.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; -extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; +extern ModuleList modules; +extern FactoryList factory; void cmd_rehash::Handle (char **parameters, int pcnt, userrec *user) { @@ -76,5 +42,3 @@ void cmd_rehash::Handle (char **parameters, int pcnt, userrec *user) } FOREACH_MOD(I_OnRehash,OnRehash(parameter)); } - - diff --git a/src/cmd_restart.cpp b/src/cmd_restart.cpp index c16570a74..01cf650db 100644 --- a/src/cmd_restart.cpp +++ b/src/cmd_restart.cpp @@ -14,52 +14,13 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_restart.h" -extern ServerConfig* Config; -extern InspIRCd* ServerInstance; -extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; -extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; +extern ServerConfig* Config;; void cmd_restart::Handle (char **parameters, int pcnt, userrec *user) { @@ -100,5 +61,3 @@ void cmd_restart::Handle (char **parameters, int pcnt, userrec *user) WriteOpers("*** Failed RESTART Command from %s!%s@%s.",user->nick,user->ident,user->host); } } - - diff --git a/src/cmd_stats.cpp b/src/cmd_stats.cpp index 4f2de6dfe..c83974ec4 100644 --- a/src/cmd_stats.cpp +++ b/src/cmd_stats.cpp @@ -14,18 +14,10 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif +#include "configreader.h" +#include "hash_map.h" #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> @@ -36,10 +28,7 @@ using namespace std; #define RUSAGE_SELF 0 #define RUSAGE_CHILDREN -1 #endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> + #include "users.h" #include "ctables.h" #include "globals.h" @@ -55,21 +44,17 @@ using namespace std; #include "helperfuncs.h" #include "hashcomp.h" #include "socketengine.h" -#include "typedefs.h" #include "command_parse.h" #include "cmd_stats.h" extern ServerConfig* Config; extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; extern time_t TIME; extern user_hash clientlist; extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_stats::Handle (char **parameters, int pcnt, userrec *user) { @@ -205,12 +190,12 @@ void cmd_stats::Handle (char **parameters, int pcnt, userrec *user) if (*parameters[0] == 'T') { - WriteServ(user->fd,"249 Brain :accepts %d refused %d",ServerInstance->stats->statsAccept,ServerInstance->stats->statsRefused); - WriteServ(user->fd,"249 Brain :unknown commands %d",ServerInstance->stats->statsUnknown); - WriteServ(user->fd,"249 Brain :nick collisions %d",ServerInstance->stats->statsCollisions); - WriteServ(user->fd,"249 Brain :dns requests %d succeeded %d failed %d",ServerInstance->stats->statsDns,ServerInstance->stats->statsDnsGood,ServerInstance->stats->statsDnsBad); - WriteServ(user->fd,"249 Brain :connections %d",ServerInstance->stats->statsConnects); - WriteServ(user->fd,"249 Brain :bytes sent %dK recv %dK",(ServerInstance->stats->statsSent / 1024),(ServerInstance->stats->statsRecv / 1024)); + WriteServ(user->fd,"249 %s :accepts %d refused %d",user->nick,ServerInstance->stats->statsAccept,ServerInstance->stats->statsRefused); + WriteServ(user->fd,"249 %s :unknown commands %d",user->nick,ServerInstance->stats->statsUnknown); + WriteServ(user->fd,"249 %s :nick collisions %d",user->nick,ServerInstance->stats->statsCollisions); + WriteServ(user->fd,"249 %s :dns requests %d succeeded %d failed %d",user->nick,ServerInstance->stats->statsDns,ServerInstance->stats->statsDnsGood,ServerInstance->stats->statsDnsBad); + WriteServ(user->fd,"249 %s :connections %d",user->nick,ServerInstance->stats->statsConnects); + WriteServ(user->fd,"249 %s :bytes sent %dK recv %dK",user->nick,(ServerInstance->stats->statsSent / 1024),(ServerInstance->stats->statsRecv / 1024)); } /* stats o */ diff --git a/src/cmd_time.cpp b/src/cmd_time.cpp index f914add49..cabb260c6 100644 --- a/src/cmd_time.cpp +++ b/src/cmd_time.cpp @@ -14,60 +14,21 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" #include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_time.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; -extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_time::Handle (char **parameters, int pcnt, userrec *user) { - time_t rawtime; - struct tm * timeinfo; + struct tm* timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); + timeinfo = localtime(&TIME); char tms[26]; snprintf(tms,26,"%s",asctime(timeinfo)); @@ -76,5 +37,3 @@ void cmd_time::Handle (char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"391 %s %s :%s",user->nick,Config->ServerName,tms); } - - diff --git a/src/cmd_topic.cpp b/src/cmd_topic.cpp index 0b94eb53b..b9051ea6f 100644 --- a/src/cmd_topic.cpp +++ b/src/cmd_topic.cpp @@ -14,52 +14,19 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" #include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" -#include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_topic.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; +extern ModuleList modules; +extern FactoryList factory; void cmd_topic::Handle (char **parameters, int pcnt, userrec *user) { @@ -135,5 +102,3 @@ void cmd_topic::Handle (char **parameters, int pcnt, userrec *user) } } } - - diff --git a/src/cmd_user.cpp b/src/cmd_user.cpp index d088a80f0..f606751d7 100644 --- a/src/cmd_user.cpp +++ b/src/cmd_user.cpp @@ -14,52 +14,18 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" #include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_user.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; -extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; +extern ModuleList modules; +extern FactoryList factory; void cmd_user::Handle (char **parameters, int pcnt, userrec *user) { @@ -93,5 +59,3 @@ void cmd_user::Handle (char **parameters, int pcnt, userrec *user) //ConnectUser(user,NULL); } } - - diff --git a/src/cmd_version.cpp b/src/cmd_version.cpp index 8e80e3778..bdb8a8b23 100644 --- a/src/cmd_version.cpp +++ b/src/cmd_version.cpp @@ -14,39 +14,11 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_version.h" extern ServerConfig* Config; @@ -75,5 +47,3 @@ void cmd_version::Handle (char **parameters, int pcnt, userrec *user) } } } - - diff --git a/src/cmd_wallops.cpp b/src/cmd_wallops.cpp index 077ead78e..bad638815 100644 --- a/src/cmd_wallops.cpp +++ b/src/cmd_wallops.cpp @@ -14,39 +14,10 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> -#include "users.h" -#include "ctables.h" -#include "globals.h" +#include "configreader.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_wallops.h" extern int MODCOUNT; @@ -59,5 +30,3 @@ void cmd_wallops::Handle (char **parameters, int pcnt, userrec *user) WriteWallOps(user,false,"%s",parameters[0]); FOREACH_MOD(I_OnWallops,OnWallops(user,parameters[0])); } - - diff --git a/src/cmd_who.cpp b/src/cmd_who.cpp index f5a376e39..49c44765c 100644 --- a/src/cmd_who.cpp +++ b/src/cmd_who.cpp @@ -14,59 +14,24 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" #include "message.h" +#include "modules.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" -#include "inspircd.h" #include "cmd_who.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; -extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; -extern time_t TIME; extern user_hash clientlist; extern chan_hash chanlist; extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void cmd_who::Handle (char **parameters, int pcnt, userrec *user) { chanrec* Ptr = NULL; char tmp[10]; - /* theres more to do here, but for now just close the socket */ if (pcnt == 1) { if ((IS_SINGLE(parameters[0],'0')) || (IS_SINGLE(parameters[0],'*'))) @@ -185,4 +150,3 @@ void cmd_who::Handle (char **parameters, int pcnt, userrec *user) } } } - diff --git a/src/cmd_whois.cpp b/src/cmd_whois.cpp index 37283784b..75e469f92 100644 --- a/src/cmd_whois.cpp +++ b/src/cmd_whois.cpp @@ -14,52 +14,21 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "message.h" +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_whois.h" extern ServerConfig* Config; extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; void do_whois(userrec* user, userrec* dest,unsigned long signon, unsigned long idle, char* nick) { diff --git a/src/cmd_whowas.cpp b/src/cmd_whowas.cpp index 143877219..bb8866239 100644 --- a/src/cmd_whowas.cpp +++ b/src/cmd_whowas.cpp @@ -14,53 +14,14 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" -#include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" -#include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" -#include "mode.h" -#include "xline.h" -#include "inspstring.h" -#include "dnsqueue.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "socketengine.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_whowas.h" extern ServerConfig* Config; -extern InspIRCd* ServerInstance; -extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; -extern time_t TIME; -extern user_hash clientlist; -extern chan_hash chanlist; -extern std::vector<userrec*> all_opers; -extern std::vector<userrec*> local_users; -extern userrec* fd_ref_table[MAX_DESCRIPTORS]; - extern whowas_users whowas; void cmd_whowas::Handle (char **parameters, int pcnt, userrec* user) diff --git a/src/cmd_zline.cpp b/src/cmd_zline.cpp index 7ffe5cd73..a040787ba 100644 --- a/src/cmd_zline.cpp +++ b/src/cmd_zline.cpp @@ -14,37 +14,20 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" -#include <time.h> -#include <string> -#include <map> -#include <sstream> -#include <vector> -#include <deque> +#include "configreader.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" -#include "message.h" #include "commands.h" #include "xline.h" -#include "inspstring.h" #include "helperfuncs.h" -#include "hashcomp.h" -#include "typedefs.h" -#include "command_parse.h" #include "cmd_eline.h" extern ServerConfig* Config; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; void cmd_zline::Handle (char **parameters, int pcnt, userrec *user) { @@ -82,5 +65,3 @@ void cmd_zline::Handle (char **parameters, int pcnt, userrec *user) } } } - - diff --git a/src/command_parse.cpp b/src/command_parse.cpp index e81595ac4..7a26f209b 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -14,11 +14,9 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <fcntl.h> #include <sys/errno.h> @@ -26,15 +24,8 @@ using namespace std; #include <sys/utsname.h> #include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> #include <sstream> #include <vector> -#include <deque> #include <sched.h> #ifdef THREADED_DNS #include <pthread.h> @@ -838,4 +829,3 @@ void CommandParser::SetupCommandTable() this->CreateCommand(new cmd_server); this->CreateCommand(new cmd_commands); } - diff --git a/src/commands.cpp b/src/commands.cpp index e5d58bfba..e4fc939ea 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -14,11 +14,9 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <sys/errno.h> #include <sys/ioctl.h> @@ -26,15 +24,8 @@ using namespace std; #include <cstdio> #include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> #include <sstream> #include <vector> -#include <deque> #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> @@ -67,8 +58,8 @@ extern ServerConfig* Config; extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; extern time_t TIME; const long duration_m = 60; diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 20118038b..73d80d11d 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -14,41 +14,23 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/utsname.h> -#include <cstdio> -#include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif -#include <map> -#include <sstream> -#include <vector> -#include <deque> #include "users.h" #include "globals.h" #include "inspstring.h" #include "dnsqueue.h" -#include <time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <netinet/in.h> -#include <string.h> #include "dns.h" #include "helperfuncs.h" #include "hashcomp.h" #include "socketengine.h" +#include "socket.h" extern ServerConfig* Config; extern InspIRCd* ServerInstance; @@ -288,4 +270,3 @@ void dns_poll(int fdcheck) if (ServerInstance && ServerInstance->SE) ServerInstance->SE->DelFd(fdcheck); } - diff --git a/src/dynamic.cpp b/src/dynamic.cpp index 8e63b7d03..d9ace43e0 100644 --- a/src/dynamic.cpp +++ b/src/dynamic.cpp @@ -17,7 +17,7 @@ using namespace std; #include "inspircd_config.h" -#include "inspircd_io.h" +#include "configreader.h" #include "globals.h" #include "dynamic.h" diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index c467172d8..3a0f39c6d 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -14,25 +14,16 @@ * --------------------------------------------------- */ -using namespace std; - +#include <stdarg.h> #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <fcntl.h> #include <sys/errno.h> #include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif #include <sstream> -#include <vector> -#include <deque> -#include <stdarg.h> #include "connection.h" #include "users.h" #include "ctables.h" @@ -50,7 +41,7 @@ using namespace std; #include "typedefs.h" extern int MODCOUNT; -extern std::vector<Module*> modules; +extern ModuleList modules; extern ServerConfig *Config; extern InspIRCd* ServerInstance; extern time_t TIME; @@ -278,8 +269,6 @@ void WriteServ(int sock, char* text, ...) { va_list argsPtr; char textbuffer[MAXBUF]; - char tb[MAXBUF]; - int bytes; if ((sock < 0) || (sock > MAX_DESCRIPTORS)) return; @@ -1603,6 +1592,34 @@ bool AllModulesReportReady(userrec* user) return true; } +/* Make Sure Modules Are Avaliable! + * (BugFix By Craig.. See? I do work! :p) + * Modified by brain, requires const char* + * to work with other API functions + */ + +/* XXX - Needed? */ +bool FileExists (const char* file) +{ + FILE *input; + if ((input = fopen (file, "r")) == NULL) + { + return(false); + } + else + { + fclose (input); + return(true); + } +} + +char* CleanFilename(char* name) +{ + char* p = name + strlen(name); + while ((p != name) && (*p != '/')) p--; + return (p != name ? ++p : p); +} + bool DirValid(char* dirandfile) { char work[MAXBUF]; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index bdb1812c3..fd164000a 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -16,11 +16,9 @@ /* Now with added unF! ;) */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <fcntl.h> #include <sys/errno.h> #include <sys/ioctl.h> @@ -29,13 +27,9 @@ using namespace std; #include <exception> #include <stdexcept> #include <new> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif #include <map> #include <sstream> +#include <fstream> #include <vector> #include <deque> #ifdef THREADED_DNS @@ -132,6 +126,96 @@ bool FindServerName(std::string servername) return false; } +void Exit(int status) +{ + if (Config->log_file) + fclose(Config->log_file); + send_error("Server shutdown."); + exit (status); +} + +void Start() +{ + printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__); + printf("(C) ChatSpike Development team.\033[0m\n\n"); + printf("Developers:\t\t\033[1;32mBrain, FrostyCoolSlug, w00t, Om\033[0m\n"); + printf("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n"); + printf("Name concept:\t\t\033[1;32mLord_Zathras\033[0m\n\n"); +} + +void Killed(int status) +{ + if (Config->log_file) + fclose(Config->log_file); + send_error("Server terminated."); + exit(status); +} + +void Rehash(int status) +{ + WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE)); + fclose(Config->log_file); + OpenLog(NULL,0); + Config->Read(false,NULL); + FOREACH_MOD(I_OnRehash,OnRehash("")); +} + +void SetSignals() +{ + signal (SIGALRM, SIG_IGN); + signal (SIGHUP, Rehash); + signal (SIGPIPE, SIG_IGN); + signal (SIGTERM, Exit); + signal (SIGSEGV, Error); +} + +bool DaemonSeed() +{ + int childpid; + if ((childpid = fork ()) < 0) + return (ERROR); + else if (childpid > 0) + { + /* We wait a few seconds here, so that the shell prompt doesnt come back over the output */ + sleep(6); + exit (0); + } + setsid (); + umask (007); + printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid()); + + rlimit rl; + if (getrlimit(RLIMIT_CORE, &rl) == -1) + { + log(DEFAULT,"Failed to getrlimit()!"); + return false; + } + else + { + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_CORE, &rl) == -1) + log(DEFAULT,"setrlimit() failed, cannot increase coredump size."); + } + + return true; +} + +void WritePID(const std::string &filename) +{ + std::ofstream outfile(filename.c_str()); + if (outfile.is_open()) + { + outfile << getpid(); + outfile.close(); + } + else + { + printf("Failed to write PID-file '%s', exiting.\n",filename.c_str()); + log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str()); + Exit(0); + } +} + std::string InspIRCd::GetRevision() { return REVISION; diff --git a/src/message.cpp b/src/message.cpp index 1cc97743b..28a11fda9 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -18,7 +18,7 @@ using namespace std; #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <fcntl.h> #include <sys/errno.h> diff --git a/src/mode.cpp b/src/mode.cpp index cdf73350f..b6905df9e 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -18,7 +18,7 @@ using namespace std; #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <sys/errno.h> #include <time.h> diff --git a/src/modules.cpp b/src/modules.cpp index 2a7b2696f..223b1fe30 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -14,20 +14,13 @@ * --------------------------------------------------- */ -using namespace std; - #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <sys/errno.h> #include <time.h> #include <string> -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif #include <map> #include <sstream> #include <vector> @@ -54,17 +47,18 @@ using namespace std; extern ServerConfig *Config; extern InspIRCd* ServerInstance; extern int MODCOUNT; -extern std::vector<Module*> modules; -extern std::vector<ircd_module*> factory; +extern ModuleList modules; +extern FactoryList factory; extern std::vector<InspSocket*> module_sockets; extern std::vector<userrec*> local_users; extern time_t TIME; -class Server; extern userrec* fd_ref_table[MAX_DESCRIPTORS]; - extern user_hash clientlist; extern chan_hash chanlist; extern command_table cmdlist; + +class Server; + ExtModeList EMode; // returns true if an extended mode character is in use diff --git a/src/modules/extra/m_sqloper.cpp b/src/modules/extra/m_sqloper.cpp index a5b79dc54..64f9f497f 100644 --- a/src/modules/extra/m_sqloper.cpp +++ b/src/modules/extra/m_sqloper.cpp @@ -32,6 +32,7 @@ using namespace std; #include "channels.h" #include "modules.h" #include "inspircd.h" +#include "configreader.h" #include "helperfuncs.h" #include "m_sql.h" #include "cmd_oper.h" @@ -244,4 +245,3 @@ extern "C" void * init_module( void ) { return new ModuleSQLOperFactory; } - diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 33f15e376..52209d44c 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -4,6 +4,7 @@ #include <gnutls/gnutls.h> #include "inspircd_config.h" +#include "configreader.h" #include "users.h" #include "channels.h" #include "modules.h" diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index 27e6e3f02..1e20b1ccf 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -5,6 +5,7 @@ #include <openssl/err.h> #include "inspircd_config.h" +#include "configreader.h" #include "users.h" #include "channels.h" #include "modules.h" diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index 0005f0683..3394044a3 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -23,11 +23,8 @@ using namespace std; #include <deque> #include "globals.h" #include "inspircd_config.h" -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif +#include "hash_map.h" +#include "configreader.h" #include "users.h" #include "channels.h" #include "modules.h" diff --git a/src/modules/m_spanningtree_ng.cpp b/src/modules/m_spanningtree_ng.cpp index 0005f0683..3394044a3 100644 --- a/src/modules/m_spanningtree_ng.cpp +++ b/src/modules/m_spanningtree_ng.cpp @@ -23,11 +23,8 @@ using namespace std; #include <deque> #include "globals.h" #include "inspircd_config.h" -#ifdef GCC3 -#include <ext/hash_map> -#else -#include <hash_map> -#endif +#include "hash_map.h" +#include "configreader.h" #include "users.h" #include "channels.h" #include "modules.h" diff --git a/src/socket.cpp b/src/socket.cpp index 1b657e568..f9b605d3b 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -14,410 +14,236 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" -#include <sys/time.h> -#include <sys/resource.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> #include <string> -#include <unistd.h> -#include <fcntl.h> -#include <poll.h> -#include <sstream> -#include <iostream> -#include <fstream> -#include <stdexcept> +#include "configreader.h" #include "socket.h" #include "inspircd.h" -#include "inspircd_io.h" #include "inspstring.h" #include "helperfuncs.h" #include "socketengine.h" - +#include "message.h" extern InspIRCd* ServerInstance; extern ServerConfig* Config; extern time_t TIME; +extern int openSockfd[MAX_DESCRIPTORS]; InspSocket* socket_ref[MAX_DESCRIPTORS]; -InspSocket::InspSocket() +/** This will bind a socket to a port. It works for UDP/TCP. + * If a hostname is given to bind to, the function will first + * attempt to resolve the hostname, then bind to the IP the + * hostname resolves to. This is a blocking lookup blocking for + * a maximum of one second before it times out, using the DNS + * server specified in the configuration file. + */ +bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr) { - this->state = I_DISCONNECTED; - this->fd = -1; - this->ClosePending = false; -} + memset(&server,0,sizeof(server)); + insp_inaddr addy; + bool resolved = false; + char resolved_addr[128]; -InspSocket::InspSocket(int newfd, char* ip) -{ - this->fd = newfd; - this->state = I_CONNECTED; - strlcpy(this->IP,ip,MAXBUF); - this->ClosePending = false; - ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE); - socket_ref[this->fd] = this; -} + if (*addr == '*') + *addr = 0; -InspSocket::InspSocket(const std::string &ahost, int aport, bool listening, unsigned long maxtime) : fd(-1) -{ - strlcpy(host,ahost.c_str(),MAXBUF); - this->ClosePending = false; - if (listening) { - if ((this->fd = OpenTCPSocket()) == ERROR) - { - this->fd = -1; - this->state = I_ERROR; - this->OnError(I_ERR_SOCKET); - this->ClosePending = true; - log(DEBUG,"OpenTCPSocket() error"); - return; - } - else - { - if (!BindSocket(this->fd,this->client,this->server,aport,(char*)ahost.c_str())) - { - this->Close(); - this->fd = -1; - this->state = I_ERROR; - this->OnError(I_ERR_BIND); - this->ClosePending = true; - log(DEBUG,"BindSocket() error %s",strerror(errno)); - return; - } - else - { - this->state = I_LISTENING; - ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE); - socket_ref[this->fd] = this; - log(DEBUG,"New socket now in I_LISTENING state"); - return; - } - } - } - else + if (*addr && !inet_aton(addr,&addy)) { - strlcpy(this->host,ahost.c_str(),MAXBUF); - this->port = aport; - - if (!inet_aton(host,&addy)) + /* If they gave a hostname, bind to the IP it resolves to */ + if (CleanAndResolve(resolved_addr, addr, true)) { - log(DEBUG,"Attempting to resolve %s",this->host); - /* Its not an ip, spawn the resolver */ - this->dns.SetNS(std::string(Config->DNSServer)); - this->dns.ForwardLookupWithFD(host,fd); - timeout_end = time(NULL) + maxtime; - timeout = false; - this->state = I_RESOLVING; - socket_ref[this->fd] = this; + inet_aton(resolved_addr,&addy); + log(DEFAULT,"Resolved binding '%s' -> '%s'",addr,resolved_addr); + server.sin_addr = addy; + resolved = true; } else { - log(DEBUG,"No need to resolve %s",this->host); - strlcpy(this->IP,host,MAXBUF); - timeout_end = time(NULL) + maxtime; - this->DoConnect(); + log(DEFAULT,"WARNING: Could not resolve '%s' to an IP for binding to on port %d",addr,port); + return false; } } -} - -void InspSocket::SetQueues(int nfd) -{ - // attempt to increase socket sendq and recvq as high as its possible - int sendbuf = 32768; - int recvbuf = 32768; - setsockopt(nfd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf)); - setsockopt(nfd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf)); -} - -bool InspSocket::DoResolve() -{ - log(DEBUG,"In DoResolve(), trying to resolve IP"); - if (this->dns.HasResult()) + server.sin_family = AF_INET; + if (!resolved) { - log(DEBUG,"Socket has result"); - std::string res_ip = dns.GetResultIP(); - if (res_ip != "") + if (!*addr) { - log(DEBUG,"Socket result set to %s",res_ip.c_str()); - strlcpy(this->IP,res_ip.c_str(),MAXBUF); - socket_ref[this->fd] = NULL; + server.sin_addr.s_addr = htonl(INADDR_ANY); } else { - log(DEBUG,"Socket DNS failure"); - this->Close(); - this->state = I_ERROR; - this->OnError(I_ERR_RESOLVE); - this->fd = -1; - this->ClosePending = true; - return false; + server.sin_addr = addy; } - return this->DoConnect(); } - log(DEBUG,"No result for socket yet!"); - return true; -} - -bool InspSocket::DoConnect() -{ - log(DEBUG,"In DoConnect()"); - if ((this->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) + server.sin_port = htons(port); + if (bind(sockfd,(struct sockaddr*)&server,sizeof(server)) < 0) { - log(DEBUG,"Cant socket()"); - this->state = I_ERROR; - this->OnError(I_ERR_SOCKET); - this->fd = -1; return false; } - - log(DEBUG,"Part 2 DoConnect() %s",this->IP); - inet_aton(this->IP,&addy); - addr.sin_family = AF_INET; - addr.sin_addr = addy; - addr.sin_port = htons(this->port); - - int flags; - flags = fcntl(this->fd, F_GETFL, 0); - fcntl(this->fd, F_SETFL, flags | O_NONBLOCK); - - if (connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr)) == -1) + else { - if (errno != EINPROGRESS) + log(DEBUG,"Bound port %s:%d",*addr ? addr : "*",port); + if (listen(sockfd, Config->MaxConn) == -1) { - log(DEBUG,"Error connect() %d: %s",this->fd,strerror(errno)); - this->OnError(I_ERR_CONNECT); - this->Close(); - this->state = I_ERROR; - this->fd = -1; - this->ClosePending = true; + log(DEFAULT,"ERROR in listen(): %s",strerror(errno)); return false; } + else + { + NonBlocking(sockfd); + return true; + } } - this->state = I_CONNECTING; - ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE); - socket_ref[this->fd] = this; - this->SetQueues(this->fd); - log(DEBUG,"Returning true from InspSocket::DoConnect"); - return true; } -void InspSocket::Close() +// Open a TCP Socket +int OpenTCPSocket() { - if (this->fd != -1) + int sockfd; + int on = 1; + struct linger linger = { 0 }; + + if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { - this->OnClose(); - shutdown(this->fd,2); - close(this->fd); - socket_ref[this->fd] = NULL; - this->ClosePending = true; - this->fd = -1; + log(DEFAULT,"Error creating TCP socket: %s",strerror(errno)); + return (ERROR); + } + else + { + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + /* This is BSD compatible, setting l_onoff to 0 is *NOT* http://web.irc.org/mla/ircd-dev/msg02259.html */ + linger.l_onoff = 1; + linger.l_linger = 1; + setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &linger,sizeof(linger)); + return (sockfd); } } -std::string InspSocket::GetIP() -{ - return this->IP; -} - -char* InspSocket::Read() +bool HasPort(int port, char* addr) { - if ((fd < 0) || (fd > MAX_DESCRIPTORS)) - return NULL; - int n = recv(this->fd,this->ibuf,sizeof(this->ibuf),0); - if ((n > 0) && (n <= (int)sizeof(this->ibuf))) + for (int count = 0; count < ServerInstance->stats->BoundPortCount; count++) { - ibuf[n] = 0; - return ibuf; - } - else - { - if (errno == EAGAIN) + if ((port == Config->ports[count]) && (!strcasecmp(Config->addrs[count],addr))) { - return ""; - } - else - { - log(DEBUG,"EOF or error on socket: %s",strerror(errno)); - return NULL; + return true; } } + return false; } -void InspSocket::MarkAsClosed() -{ - log(DEBUG,"Marked as closed"); - this->ClosePending = true; -} - -// There are two possible outcomes to this function. -// It will either write all of the data, or an undefined amount. -// If an undefined amount is written the connection has failed -// and should be aborted. -int InspSocket::Write(const std::string &data) +int BindPorts(bool bail) { - if (this->ClosePending) - return false; + char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF]; + insp_sockaddr client, server; + int clientportcount = 0; + int BoundPortCount = 0; - /*int result = write(this->fd,data.c_str(),data.length()); - if (result < 1) - return false; - return true;*/ - - /* Try and append the data to the back of the queue, and send it on its way - */ - outbuffer.push_back(data); - return (!this->FlushWriteBuffer()); -} + if (!bail) + { + int InitialPortCount = ServerInstance->stats->BoundPortCount; + log(DEBUG,"Initial port count: %d",InitialPortCount); -bool InspSocket::FlushWriteBuffer() -{ - if (this->ClosePending) - return true; + for (int count = 0; count < Config->ConfValueEnum(Config->config_data, "bind"); count++) + { + Config->ConfValue(Config->config_data, "bind", "port", count, configToken, MAXBUF); + Config->ConfValue(Config->config_data, "bind", "address", count, Addr, MAXBUF); + Config->ConfValue(Config->config_data, "bind", "type", count, Type, MAXBUF); - if ((this->fd > -1) && (this->state == I_CONNECTED)) - { - if (outbuffer.size()) + if (((!*Type) || (!strcmp(Type,"clients"))) && (!HasPort(atoi(configToken),Addr))) + { + // modules handle server bind types now + Config->ports[clientportcount+InitialPortCount] = atoi(configToken); + if (*Addr == '*') + *Addr = 0; + + strlcpy(Config->addrs[clientportcount+InitialPortCount],Addr,256); + clientportcount++; + log(DEBUG,"NEW binding %s:%s [%s] from config",Addr,configToken, Type); + } + } + int PortCount = clientportcount; + if (PortCount) { - int result = write(this->fd,outbuffer[0].c_str(),outbuffer[0].length()); - if (result > 0) + for (int count = InitialPortCount; count < InitialPortCount + PortCount; count++) { - if ((unsigned int)result == outbuffer[0].length()) + if ((openSockfd[count] = OpenTCPSocket()) == ERROR) { - /* The whole block was written (usually a line) - * Pop the block off the front of the queue - */ - outbuffer.pop_front(); + log(DEBUG,"Bad fd %d binding port [%s:%d]",openSockfd[count],Config->addrs[count],Config->ports[count]); + return ERROR; + } + if (!BindSocket(openSockfd[count],client,server,Config->ports[count],Config->addrs[count])) + { + log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno)); } else { - std::string temp = outbuffer[0].substr(result); - outbuffer[0] = temp; + /* Associate the new open port with a slot in the socket engine */ + ServerInstance->SE->AddFd(openSockfd[count],true,X_LISTEN); + BoundPortCount++; } } - else if ((result == -1) && (errno != EAGAIN)) - { - log(DEBUG,"Write error on socket: %s",strerror(errno)); - this->OnError(I_ERR_WRITE); - this->state = I_ERROR; - this->ClosePending = true; - return true; - } + return InitialPortCount + BoundPortCount; } + else + { + log(DEBUG,"There is nothing new to bind!"); + } + return InitialPortCount; } - return (fd < 0); -} -bool InspSocket::Timeout(time_t current) -{ - if (!socket_ref[this->fd] || !ServerInstance->SE->HasFd(this->fd)) + for (int count = 0; count < Config->ConfValueEnum(Config->config_data, "bind"); count++) { - log(DEBUG,"No FD or socket ref"); - return false; - } + Config->ConfValue(Config->config_data, "bind", "port", count, configToken, MAXBUF); + Config->ConfValue(Config->config_data, "bind", "address", count, Addr, MAXBUF); + Config->ConfValue(Config->config_data, "bind", "type", count, Type, MAXBUF); - if (this->ClosePending) - { - log(DEBUG,"Close is pending"); - return true; + if ((!*Type) || (!strcmp(Type,"clients"))) + { + // modules handle server bind types now + Config->ports[clientportcount] = atoi(configToken); + + // If the client put bind "*", this is an unrealism. + // We don't actually support this as documented, but + // i got fed up of people trying it, so now it converts + // it to an empty string meaning the same 'bind to all'. + if (*Addr == '*') + *Addr = 0; + + strlcpy(Config->addrs[clientportcount],Addr,256); + clientportcount++; + log(DEBUG,"Binding %s:%s [%s] from config",Addr,configToken, Type); + } } - if (((this->state == I_RESOLVING) || (this->state == I_CONNECTING)) && (current > timeout_end)) - { - log(DEBUG,"Timed out, current=%lu timeout_end=%lu"); - // for non-listening sockets, the timeout can occur - // which causes termination of the connection after - // the given number of seconds without a successful - // connection. - this->OnTimeout(); - this->OnError(I_ERR_TIMEOUT); - timeout = true; - this->state = I_ERROR; - this->ClosePending = true; - return true; - } - return this->FlushWriteBuffer(); -} + int PortCount = clientportcount; -bool InspSocket::Poll() -{ - if (!socket_ref[this->fd] || !ServerInstance->SE->HasFd(this->fd)) - return false; - - int incoming = -1; - bool n = true; + for (int count = 0; count < PortCount; count++) + { + if ((openSockfd[BoundPortCount] = OpenTCPSocket()) == ERROR) + { + log(DEBUG,"Bad fd %d binding port [%s:%d]",openSockfd[BoundPortCount],Config->addrs[count],Config->ports[count]); + return ERROR; + } - if ((fd < 0) || (fd > MAX_DESCRIPTORS) || (this->ClosePending)) - return false; + if (!BindSocket(openSockfd[BoundPortCount],client,server,Config->ports[count],Config->addrs[count])) + { + log(DEFAULT,"Failed to bind port [%s:%d]: %s",Config->addrs[count],Config->ports[count],strerror(errno)); + } + else + { + /* well we at least bound to one socket so we'll continue */ + BoundPortCount++; + } + } - switch (this->state) + /* if we didn't bind to anything then abort */ + if (!BoundPortCount) { - case I_RESOLVING: - log(DEBUG,"State = I_RESOLVING, calling DoResolve()"); - return this->DoResolve(); - break; - case I_CONNECTING: - log(DEBUG,"State = I_CONNECTING"); - this->SetState(I_CONNECTED); - /* Our socket was in write-state, so delete it and re-add it - * in read-state. - */ - ServerInstance->SE->DelFd(this->fd); - ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE); - return this->OnConnected(); - break; - case I_LISTENING: - length = sizeof (client); - incoming = accept (this->fd, (sockaddr*)&client,&length); - this->SetQueues(incoming); - this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr)); - return true; - break; - case I_CONNECTED: - n = this->OnDataReady(); - /* Flush any pending, but not till after theyre done with the event - * so there are less write calls involved. - * Both FlushWriteBuffer AND the return result of OnDataReady must - * return true for this to be ok. - */ - if (this->FlushWriteBuffer()) - return false; - return n; - break; - default: - break; + log(DEFAULT,"No ports bound, bailing!"); + printf("\nERROR: Could not bind any of %d ports! Please check your configuration.\n\n", PortCount); + return ERROR; } - return true; -} -void InspSocket::SetState(InspSocketState s) -{ - log(DEBUG,"Socket state change"); - this->state = s; -} - -InspSocketState InspSocket::GetState() -{ - return this->state; -} - -int InspSocket::GetFd() -{ - return this->fd; -} - -bool InspSocket::OnConnected() { return true; } -void InspSocket::OnError(InspSocketError e) { return; } -int InspSocket::OnDisconnect() { return 0; } -int InspSocket::OnIncomingConnection(int newfd, char* ip) { return 0; } -bool InspSocket::OnDataReady() { return true; } -void InspSocket::OnTimeout() { return; } -void InspSocket::OnClose() { return; } - -InspSocket::~InspSocket() -{ - this->Close(); + return BoundPortCount; } diff --git a/src/userprocess.cpp b/src/userprocess.cpp index 956ddb61b..2adccc36e 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -20,7 +20,7 @@ using namespace std; #include "inspircd_config.h" #include "inspircd.h" -#include "inspircd_io.h" +#include "configreader.h" #include <unistd.h> #include <fcntl.h> #include <sys/errno.h> @@ -417,4 +417,3 @@ void DoBackgroundUserStuff(time_t TIME) /* Remove all the queued users who are due to be quit, free memory used. */ GlobalGoners.Apply(); } - diff --git a/src/users.cpp b/src/users.cpp index d6ee1d3bd..d4919af06 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -14,9 +14,8 @@ * --------------------------------------------------- */ -using namespace std; - -#include "inspircd_config.h" +#include "inspircd_config.h" +#include "configreader.h" #include "channels.h" #include "connection.h" #include "users.h" |