]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/inspircd.h
Reduce size of max number of bytes in a bitfield from a 4 or 8 byte field to a 1...
[user/henk/code/inspircd.git] / include / inspircd.h
index cf884f9150363e565e18ea585d42031cef1da90c..7fecf22ae9fd7f5dae85ca533f01d814d2433cae 100644 (file)
@@ -25,9 +25,9 @@
 #include "channels.h"
 #include "socket.h"
 #include "mode.h"
-#include "helperfuncs.h"
 #include "socketengine.h"
 #include "command_parse.h"
+#include "snomasks.h"
 
 /** Returned by some functions to indicate failure,
  * and the exit code of the program if it terminates.
@@ -59,7 +59,11 @@ enum DebugLevel
 
 /** Delete a pointer, and NULL its value
  */
-#define DELETE(x) {if (x) { delete x; x = NULL; }}
+template<typename T> inline void DELETE(T* x)
+{
+       delete x;
+       x = NULL;
+}
 
 /** Template function to convert any input type to std::string
  */
@@ -125,9 +129,73 @@ class serverstats : public classbase
        }
 };
 
+class InspIRCd;
+
+/** This class implements a nonblocking log-writer.
+ * Most people writing an ircd give little thought to their disk
+ * i/o. On a congested system, disk writes can block for long
+ * periods of time (e.g. if the system is busy and/or swapping
+ * a lot). If we just use a blocking fprintf() call, this could
+ * block for undesirable amounts of time (half of a second through
+ * to whole seconds). We DO NOT want this, so we make our logfile
+ * nonblocking and hook it into the SocketEngine.
+ * NB: If the operating system does not support nonblocking file
+ * I/O (linux seems to, as does freebsd) this will default to
+ * blocking behaviour.
+ */
+class FileLogger : public EventHandler
+{
+ protected:
+       /** The creator/owner of this object
+        */
+       InspIRCd* ServerInstance;
+       /** The log file (fd is inside this somewhere,
+        * we get it out with fileno())
+        */
+       FILE* log;
+       /** Buffer of pending log lines to be written
+        */
+       std::string buffer;
+       /** Number of write operations that have occured
+        */
+       int writeops;
+ public:
+       /** The constructor takes an already opened logfile.
+        */
+       FileLogger(InspIRCd* Instance, FILE* logfile);
+       /** This returns false, logfiles are writeable.
+        */
+       virtual bool Readable();
+       /** Handle pending write events.
+        * This will flush any waiting data to disk.
+        * If any data remains after the fprintf call,
+        * another write event is scheduled to write
+        * the rest of the data when possible.
+        */
+       virtual void HandleEvent(EventType et, int errornum = 0);
+       /** Write one or more preformatted log lines.
+        * If the data cannot be written immediately,
+        * this class will insert itself into the
+        * SocketEngine, and register a write event,
+        * and when the write event occurs it will
+        * attempt again to write the data.
+        */
+       void WriteLogLine(const std::string &line);
+       /** Close the log file and cancel any events.
+        */
+       virtual void Close();
+       /** Close the log file and cancel any events.
+        * (indirectly call Close()
+        */
+       virtual ~FileLogger();
+};
+
+/** A list of failed port bindings, used for informational purposes on startup */
+typedef std::vector<std::pair<std::string, long> > FailedPortList;
+
 class XLineManager;
 
-/** The main singleton class of the irc server.
+/** The main class of the irc server.
  * This class contains instances of all the other classes
  * in this software, with the exception of the base class,
  * classbase. Amongst other things, it contains a ModeParser,
@@ -146,14 +214,6 @@ class InspIRCd : public classbase
        /** Holds a string describing the last module error to occur
         */
        char MODERR[MAXBUF];
-
-       /** This is an internal flag used by the mainloop
-        */
-       bool expire_run;
-
-       /** List of server names we've seen.
-        */
-       servernamelist servernames;
  
        /** Remove a ModuleFactory pointer
         * @param j Index number of the ModuleFactory to remove
@@ -180,19 +240,14 @@ class InspIRCd : public classbase
        void Start();
 
        /** Set up the signal handlers
-        * @param SEGVHandler create a handler for segfaults (deprecated)
         */
-       void SetSignals(bool SEGVHandler);
+       void SetSignals();
 
        /** Daemonize the ircd and close standard input/output streams
         * @return True if the program daemonized succesfully
         */
        bool DaemonSeed();
 
-       /** Build the upper/lowercase comparison table
-        */
-       void MakeLowerMap();
-
        /** Moves the given module to the last slot in the list
         * @param modulename The module name to relocate
         */
@@ -215,12 +270,6 @@ class InspIRCd : public classbase
         */
        void MoveBefore(std::string modulename, std::string before);
 
-       /** Process a user whos socket has been flagged as active
-        * @param cu The user to process
-        * @return There is no actual return value, however upon exit, the user 'cu' may have been deleted
-        */
-       void ProcessUser(userrec* cu);
-
        /** Iterate the list of InspSocket objects, removing ones which have timed out
         * @param TIME the current time
         */
@@ -281,7 +330,28 @@ class InspIRCd : public classbase
         */
        const long duration_y;
 
+       /** Used when connecting clients
+        */
+       insp_sockaddr client, server;
+
+       /** Used when connecting clients
+        */
+       socklen_t length;
+
+       /** Nonblocking file writer
+        */
+       FileLogger* Logger;
+
+       /** Time offset in seconds
+        * This offset is added to all calls to Time(). Use SetTimeDelta() to update
+        */
+       int time_delta;
+
  public:
+        /** List of server names we've seen.
+        */
+       servernamelist servernames;
+
        /** Time this ircd was booted
         */
        time_t startup_time;
@@ -306,17 +376,10 @@ class InspIRCd : public classbase
         */
        ServerConfig* Config;
 
-       /** Module sockets list, holds the active set of InspSocket classes
-        */
-       std::vector<InspSocket*> module_sockets;
-
-       /** Socket reference table, provides fast lookup of fd to InspSocket*
-        */
-       InspSocket* socket_ref[MAX_DESCRIPTORS];
-
-       /** user reference table, provides fast lookup of fd to userrec*
+       /** Snomask manager - handles routing of snomask messages
+        * to opers.
         */
-       userrec* fd_ref_table[MAX_DESCRIPTORS];
+       SnomaskManager* SNO;
 
        /** Client list, a hash_map containing all clients, local and remote
         */
@@ -338,6 +401,10 @@ class InspIRCd : public classbase
         */
        irc::whowas::whowas_users whowas;
 
+       /** Whowas container, contains a map of time_t to users tracked by WHOWAS
+        */
+       irc::whowas::whowas_users_fifo whowas_fifo;
+
        /** DNS class, provides resolver facilities to the core and modules
         */
        DNS* Res;
@@ -346,10 +413,6 @@ class InspIRCd : public classbase
         */
        TimerManager* Timers;
 
-       /** Command list, a hash_map of command names to command_t*
-        */
-       command_table cmdlist;
-
        /** X-Line manager. Handles G/K/Q/E line setting, removal and matching
         */
        XLineManager* XLines;
@@ -366,12 +429,31 @@ class InspIRCd : public classbase
         */
        FactoryList factory;
 
+       /** The time we next call our ping timeout and reg timeout checks
+        */
+       time_t next_call;
+
        /** Get the current time
         * Because this only calls time() once every time around the mainloop,
         * it is much faster than calling time() directly.
+        * @param delta True to use the delta as an offset, false otherwise
         * @return The current time as an epoch value (time_t)
         */
-       time_t Time();
+       time_t Time(bool delta = false);
+
+       /** Set the time offset in seconds
+        * This offset is added to Time() to offset the system time by the specified
+        * number of seconds.
+        * @param delta The number of seconds to offset
+        * @return The old time delta
+        */
+       int SetTimeDelta(int delta);
+
+       /** Process a user whos socket has been flagged as active
+        * @param cu The user to process
+        * @return There is no actual return value, however upon exit, the user 'cu' may have been deleted
+        */
+       void ProcessUser(userrec* cu);
 
        /** Get the total number of currently loaded modules
         * @return The number of loaded modules
@@ -387,9 +469,10 @@ class InspIRCd : public classbase
 
        /** Bind all ports specified in the configuration file.
         * @param bail True if the function should bail back to the shell on failure
+        * @param found_ports The actual number of ports found in the config, as opposed to the number actually bound
         * @return The number of ports actually bound without error
         */
-       int BindPorts(bool bail);
+       int BindPorts(bool bail, int &found_ports, FailedPortList &failed_ports);
 
        /** Returns true if this server has the given port bound to the given address
         * @param port The port number
@@ -807,21 +890,6 @@ class InspIRCd : public classbase
         */
         bool IsValidMask(const std::string &mask);
 
-       /** Add an InspSocket class to the active set
-        * @param sock A socket to add to the active set
-        */
-        void AddSocket(InspSocket* sock);
-
-       /** Remove an InspSocket class from the active set at next time around the loop
-        * @param sock A socket to remove from the active set
-        */
-        void RemoveSocket(InspSocket* sock);
-
-       /** Delete a socket immediately without waiting for the next iteration of the mainloop
-        * @param sock A socket to delete from the active set
-        */
-        void DelSocket(InspSocket* sock);
-
        /** Rehash the local server
         */
         void RehashServer();
@@ -948,6 +1016,10 @@ class InspIRCd : public classbase
         */
        void Log(int level, const std::string &text);
 
+       void SendWhoisLine(userrec* user, userrec* dest, int numeric, const std::string &text);
+
+       void SendWhoisLine(userrec* user, userrec* dest, int numeric, const char* format, ...);
+
        /** Begin execution of the server.
         * NOTE: this function NEVER returns. Internally,
         * after performing some initialisation routines,