X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=include%2Fconfigreader.h;h=f5ce4b57abceb3e240ec6e3ed0e8344433b491e2;hb=19487dbebc520450e457472b97d9e7bcd5160c00;hp=d4bc4b71bef2a0c2df7f3b3707889ef88738aed8;hpb=a30abe26fc803900eaf5dc4c08a31aa1d3c9c89f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/configreader.h b/include/configreader.h index d4bc4b71b..f5ce4b57a 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -23,43 +23,42 @@ #include "socketengine.h" #include "socket.h" -/* Required forward definitions */ -class ServerConfig; -class ServerLimits; -class InspIRCd; -class BufferedSocket; - -/** A cached text file stored with its contents as lines - */ -typedef std::vector file_cache; - -/** A configuration key and value pair - */ -typedef std::pair KeyVal; - -struct CoreExport ConfigTag : public refcountbase +/** Structure representing a single in config */ +class CoreExport ConfigTag : public refcountbase { + std::vector items; + public: const std::string tag; const std::string src_name; const int src_line; - std::vector items; - - ConfigTag(const std::string& Tag, const std::string& file, int line) - : tag(Tag), src_name(file), src_line(line) {} + /** Get the value of an option, using def if it does not exist */ std::string getString(const std::string& key, const std::string& def = ""); + /** Get the value of an option, using def if it does not exist */ long getInt(const std::string& key, long def = 0); + /** Get the value of an option, using def if it does not exist */ double getFloat(const std::string& key, double def = 0); + /** Get the value of an option, using def if it does not exist */ bool getBool(const std::string& key, bool def = false); + /** Get the value of an option + * @param key The option to get + * @param value The location to store the value (unmodified if does not exist) + * @param allow_newline Allow newlines in the option (normally replaced with spaces) + * @return true if the option exists + */ bool readString(const std::string& key, std::string& value, bool allow_newline = false); std::string getTagLocation(); -}; -/** An entire config file, built up of KeyValLists - */ -typedef std::multimap > ConfigDataHash; + inline const std::vector& getItems() const { return items; } + + /** Create a new ConfigTag, giving access to the private KeyVal item list */ + static ConfigTag* create(const std::string& Tag, const std::string& file, int line, + std::vector*&items); + private: + ConfigTag(const std::string& Tag, const std::string& file, int line); +}; /** Defines the server's length limits on various length-limited * items such as topics, nicknames, channel names etc. @@ -110,9 +109,61 @@ class ServerLimits } }; +struct CommandLineConf +{ + /** 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; + + /** True if we have been told to run the testsuite from the commandline, + * rather than entering the mainloop. + */ + bool TestSuite; + + /** Saved argc from startup + */ + int argc; + + /** Saved argv from startup + */ + char** argv; + + std::string startup_log; +}; + class CoreExport OperInfo : public refcountbase { public: + std::set AllowedOperCommands; + std::set AllowedPrivs; + + /** Allowed user modes from oper classes. */ + std::bitset<64> AllowedUserModes; + + /** Allowed channel modes from oper classes. */ + std::bitset<64> AllowedChanModes; + /** block used for this oper-up. May be NULL. */ reference oper_block; /** block used for this oper-up. Valid for local users, may be NULL on remote */ @@ -124,6 +175,7 @@ class CoreExport OperInfo : public refcountbase /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */ std::string getConfig(const std::string& key); + void init(); inline const char* NameStr() { @@ -131,9 +183,6 @@ class CoreExport OperInfo : public refcountbase } }; -typedef std::map > TagIndex; -typedef std::map > OperIndex; - /** 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 @@ -151,7 +200,9 @@ class CoreExport ServerConfig * @param tag The name of the tag to get * @param offset get the Nth occurance of the tag */ - ConfigTag* ConfValue(const std::string& tag, int offset = 0); + ConfigTag* ConfValue(const std::string& tag); + + ConfigTagList ConfTags(const std::string& tag); /** Error stream, contains error output from any failed configuration parsing. */ @@ -172,6 +223,10 @@ class CoreExport ServerConfig */ ServerLimits Limits; + /** Configuration parsed from the command line. + */ + CommandLineConf cmdline; + /** Clones CIDR range for ipv4 (0-32) * Defaults to 32 (checks clones on all IPs seperately) */ @@ -195,11 +250,6 @@ class CoreExport ServerConfig */ int WhoWasMaxKeep; - /** Both for set(g|u)id. - */ - std::string SetUser; - std::string SetGroup; - /** Holds the server name of the local server * as defined by the administrator. */ @@ -302,7 +352,6 @@ class CoreExport ServerConfig /** This variable identifies which usermodes have been diabled. */ - char DisabledUModes[64]; /** This variable identifies which chanmodes have been disabled. @@ -312,43 +361,10 @@ class CoreExport ServerConfig /** The full path to the modules directory. * This is either set at compile time, or * overridden in the configuration file via - * the tag. + * the tag. */ std::string ModPath; - /** 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 set to true, then all opers on this server are * shown with a generic 'is an IRC operator' line rather * than the oper type. Oper types are still used internally. @@ -360,11 +376,6 @@ class CoreExport ServerConfig */ bool RestrictBannedUsers; - /** If this value is true, halfops have been - * enabled in the configuration file. - */ - bool AllowHalfop; - /** If this is set to true, then mode lists (e.g * MODE #chan b) are hidden from unprivileged * users. @@ -403,10 +414,6 @@ class CoreExport ServerConfig */ int MaxWhoResults; - /** True if the DEBUG loglevel is selected. - */ - int debugging; - /** How many seconds to wait before exiting * the program when /DIE is correctly issued. */ @@ -470,10 +477,6 @@ class CoreExport ServerConfig */ std::string UserStats; - /** The path and filename of the ircd.log file - */ - std::string logpath; - /** Default channel modes */ std::string DefaultModes; @@ -490,10 +493,6 @@ class CoreExport ServerConfig */ std::map maxbans; - /** Directory where the inspircd binary resides - */ - std::string MyDir; - /** If set to true, no user DNS lookups are to be performed */ bool NoUserDns; @@ -522,14 +521,6 @@ class CoreExport ServerConfig */ OperIndex oper_blocks; - /** Saved argv from startup - */ - char** argv; - - /** Saved argc from startup - */ - int argc; - /** Max channels per user */ unsigned int MaxChans; @@ -545,11 +536,6 @@ class CoreExport ServerConfig */ std::string sid; - /** True if we have been told to run the testsuite from the commandline, - * rather than entering the mainloop. - */ - bool TestSuite; - /** Construct a new ServerConfig */ ServerConfig(); @@ -606,4 +592,30 @@ class CoreExport ServerConfig bool InvBypassModes; }; + +/** The background thread for config reading, so that reading from executable includes + * does not block. + */ +class CoreExport ConfigReaderThread : public Thread +{ + ServerConfig* Config; + volatile bool done; + public: + const std::string TheUserUID; + ConfigReaderThread(const std::string &useruid) + : Config(new ServerConfig), done(false), TheUserUID(useruid) + { + } + + virtual ~ConfigReaderThread() + { + delete Config; + } + + void Run(); + /** Run in the main thread to apply the configuration */ + void Finish(); + bool IsDone() { return done; } +}; + #endif