]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/inspircd.h
Strip all control codes except \001 in InspIRCd::StripColor()
[user/henk/code/inspircd.git] / include / inspircd.h
index 17dca94d56a2db489c3b8a11d0a7b4cfe485fe5d..91b70fbd8bbffe7bf80fbda14d2d907af1418fd4 100644 (file)
 #include <vector>
 
 #include "intrusive_list.h"
+#include "flat_map.h"
 #include "compat.h"
+#include "aligned_storage.h"
 #include "typedefs.h"
 #include "stdalgo.h"
 
 CoreExport extern InspIRCd* ServerInstance;
 
+/** Base class for manager classes that are still accessed using -> but are no longer pointers
+ */
+template <typename T>
+struct fakederef
+{
+       T* operator->()
+       {
+               return static_cast<T*>(this);
+       }
+};
+
 #include "config.h"
 #include "dynref.h"
 #include "consolecolors.h"
@@ -79,10 +92,7 @@ CoreExport extern InspIRCd* ServerInstance;
 #include "inspstring.h"
 #include "protocol.h"
 #include "bancache.h"
-
-/** Returned by some functions to indicate failure.
- */
-#define ERROR -1
+#include "isupportmanager.h"
 
 /** Template function to convert any input type to std::string
  */
@@ -234,27 +244,6 @@ class serverstats
        }
 };
 
-/** This class manages the generation and transmission of ISUPPORT. */
-class CoreExport ISupportManager
-{
-private:
-       /** The generated lines which are sent to clients. */
-       std::vector<std::string> Lines;
-
-public:
-       /** (Re)build the ISUPPORT vector. */
-       void Build();
-
-       /** Returns the std::vector of ISUPPORT lines. */
-       const std::vector<std::string>& GetLines()
-       {
-               return this->Lines;
-       }
-
-       /** Send the 005 numerics (ISUPPORT) to a user. */
-       void SendTo(LocalUser* user);
-};
-
 DEFINE_HANDLER1(IsNickHandler, bool, const std::string&);
 DEFINE_HANDLER2(GenRandomHandler, void, char*, size_t);
 DEFINE_HANDLER1(IsIdentHandler, bool, const std::string&);
@@ -339,7 +328,7 @@ class CoreExport InspIRCd
 
        /** Mode handler, handles mode setting and removal
         */
-       ModeParser* Modes;
+       ModeParser Modes;
 
        /** Command parser, handles client to server commands
         */
@@ -355,12 +344,12 @@ class CoreExport InspIRCd
 
        /** LogManager handles logging.
         */
-       LogManager *Logs;
+       LogManager Logs;
 
        /** ModuleManager contains everything related to loading/unloading
         * modules.
         */
-       ModuleManager* Modules;
+       ModuleManager Modules;
 
        /** BanCacheManager is used to speed up checking of restrictions on connection
         * to the IRCd.
@@ -378,7 +367,7 @@ class CoreExport InspIRCd
        /** Snomask manager - handles routing of snomask messages
         * to opers.
         */
-       SnomaskManager* SNO;
+       SnomaskManager SNO;
 
        /** Timer manager class, triggers Timer timer events
         */
@@ -390,7 +379,7 @@ class CoreExport InspIRCd
 
        /** User manager. Various methods and data associated with users.
         */
-       UserManager *Users;
+       UserManager Users;
 
        /** Channel list, a hash_map containing all channels XXX move to channel manager class
         */
@@ -408,6 +397,10 @@ class CoreExport InspIRCd
         */
        ProtocolInterface* PI;
 
+       /** Default implementation of the ProtocolInterface, does nothing
+        */
+       ProtocolInterface DefaultProtocolInterface;
+
        /** Holds extensible for user operquit
         */
        StringExtItem OperQuit;
@@ -445,15 +438,6 @@ class CoreExport InspIRCd
         */
        int BindPorts(FailedPortList &failed_ports);
 
-       /** Binds a socket on an already open file descriptor
-        * @param sockfd A valid file descriptor of an open socket
-        * @param port The port number to bind to
-        * @param addr The address to bind to (IP only)
-        * @param dolisten Should this port be listened on?
-        * @return True if the port was bound successfully
-        */
-       bool BindSocket(int sockfd, int port, const char* addr, bool dolisten = true);
-
        /** Find a user in the nick hash.
         * If the user cant be found in the nick hash check the uuid hash
         * @param nick The nickname to find
@@ -518,11 +502,6 @@ class CoreExport InspIRCd
        static const char* Format(const char* formatString, ...) CUSTOM_PRINTF(1, 2);
        static const char* Format(va_list &vaList, const char* formatString) CUSTOM_PRINTF(2, 0);
 
-       /** Send an error notice to all local users, opered and unopered
-        * @param s The error string to send
-        */
-       void SendError(const std::string &s);
-
        /** Return true if a nickname is valid
         * @param n A nickname to verify
         * @return True if the nick is valid
@@ -567,7 +546,7 @@ class CoreExport InspIRCd
         */
        static bool IsValidMask(const std::string& mask);
 
-       /** Strips all color codes from the given string
+       /** Strips all color and control codes except 001 from the given string
         * @param sentence The string to strip from
         */
        static void StripColor(std::string &sentence);
@@ -620,23 +599,6 @@ class CoreExport InspIRCd
         */
        InspIRCd(int argc, char** argv);
 
-       /** Send a line of WHOIS data to a user.
-        * @param user user to send the line to
-        * @param dest user being WHOISed
-        * @param numeric Numeric to send
-        * @param text Text of the numeric
-        */
-       void SendWhoisLine(User* user, User* dest, int numeric, const std::string &text);
-
-       /** Send a line of WHOIS data to a user.
-        * @param user user to send the line to
-        * @param dest user being WHOISed
-        * @param numeric Numeric to send
-        * @param format Format string for the numeric
-        * @param ... Parameters for the format string
-        */
-       void SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...) CUSTOM_PRINTF(5, 6);
-
        /** Called to check whether a channel restriction mode applies to a user
         * @param User that is attempting some action
         * @param Channel that the action is being performed on
@@ -651,8 +613,21 @@ class CoreExport InspIRCd
        void Cleanup();
 
        /** Return a time_t as a human-readable string.
+        * @param format The format to retrieve the date/time in. See `man 3 strftime`
+        * for more information. If NULL, "%a %b %d %T %Y" is assumed.
+        * @param utc True to convert the time to string as-is, false to convert it to local time first.
+        * @return A string representing the given date/time.
         */
-       static std::string TimeString(time_t curtime);
+       static std::string TimeString(time_t curtime, const char* format = NULL, bool utc = false);
+
+       /** Compare two strings in a timing-safe way. If the lengths of the strings differ, the function
+        * returns false immediately (leaking information about the length), otherwise it compares each
+        * character and only returns after all characters have been compared.
+        * @param one First string
+        * @param two Second string
+        * @return True if the strings match, false if they don't
+        */
+       static bool TimingSafeCompare(const std::string& one, const std::string& two);
 
        /** Begin execution of the server.
         * NOTE: this function NEVER returns. Internally,
@@ -688,3 +663,5 @@ inline void stdalgo::culldeleter::operator()(classbase* item)
        if (item)
                ServerInstance->GlobalCulls.AddItem(item);
 }
+
+#include "modules/whois.h"