inspircd/include/configreader.h

1 line
22 KiB
C
Raw Normal View History

/* +------------------------------------+ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * * InspIRCd: (C) 2002-2007 InspIRCd Development Team * See: http://www.inspircd.org/wiki/index.php/Credits * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ #ifndef INSPIRCD_CONFIGREADER #define INSPIRCD_CONFIGREADER /* handy defines */ /** Determines if a channel op is exempt from given mode m, * in config of server instance s. */ #define CHANOPS_EXEMPT(s, m) (s->Config->ExemptChanOps[(unsigned char)m]) #include <sstream> #include <string> #include <vector> #include <map> #include "inspircd.h" #include "globals.h" #include "modules.h" #include "socketengine.h" #include "socket.h" /* Required forward definitions */ class ServerConfig; class InspIRCd; class InspSocket; /** Types of data in the core config */ enum ConfigDataType { DT_NOTHING = 0, /* No data */ DT_INTEGER = 1, /* Integer */ DT_CHARPTR = 2, /* Char pointer */ DT_BOOLEAN = 3, /* Boolean */ DT_ALLOW_NEWLINE = 128 /* New line characters allowed */ }; /** Holds a config value, either string, integer or boolean. * Callback functions receive one or more of these, either on * their own as a reference, or in a reference to a deque of them. * The callback function can then alter the values of the ValueItem * classes to validate the settings. */ class ValueItem { /** Actual data */ std::string v; public: /** Initialize with an int */ ValueItem(int value); /** Initialize with a bool */ ValueItem(bool value); /** Initialize with a char pointer */ ValueItem(char* value); /** Change value to a char pointer */ void Set(char* value); /** Change value to a const char pointer */ void Set(const char* val); /** Change value to an int */ void Set(int value); /** Get value as an int */ int GetInteger(); /** Get value as a string */ char* GetString(); /** Get value as a bool */ bool GetBool(); }; /** The base class of the container 'ValueContainer' * used internally by the core to hold core values. */ class ValueContainerBase { public: /** Constructor */ ValueContainerBase() { } /** Destructor */ virtual ~ValueContainerBase() { } }; /** ValueContainer is used to contain pointers to different * core values such as the server name, maximum number of * clients etc. * It is specialized to hold a data type, then pointed at * a value in the ServerConfig class. When the value has been * read and validated, the Set method is called to write the * value safely in a type-safe manner. */ template<typename T> class ValueContainer : public ValueContainerBase { /** Contained item */ T val; public: /** Initialize with nothing */ ValueContainer() { val = NULL; } /** Initialize with a value of type T */ ValueContainer(T Val) { val = Val; } /** Change value to type T of size s */ void Set(T newval, size_t s) { memcpy(val, newval, s); } }; /** A specialization of ValueContainer to hold a pointer to a bool */ typedef ValueContainer<bool*> ValueContainerBool; /** A specialization of ValueContainer to hold a pointer to * an unsigned int */ typedef ValueContainer<unsigned int*> ValueContainerUInt; /** A specialization of ValueContainer to hold a pointer to * a char array. */ typedef ValueContainer<char*> ValueContainerChar; /** A specialization of ValueContainer to hold a pointer to * an int */ typedef ValueContainer<int*> ValueContainerInt; /** A set of ValueItems used by multi-value validator functions */ typedef std::deque<ValueItem> ValueList; /** A callback for validating a single value */ typedef bool (*Validator)(ServerConfig* conf, const char*, const char*, ValueItem&); /** A callback for validating multiple value entries */ typedef bool (*MultiValidator)(ServerConfig* conf, const char*, char**, ValueList&, int*); /** A callback indicating the end of a group of entries */ typedef bool (*MultiNotify)(ServerConfig