X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fconfigreader.h;h=a46f9cf95ce2bb5b370f0b85062bb2fa7538d069;hb=02830985a18950497003f3392cf8d6cc30c15c50;hp=51ced2ec7ddce5b09ffe86dd5ef9b041305232d4;hpb=3ae91bafe711b26ffae1aa27cfd4f5fe7bfc2347;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/configreader.h b/include/configreader.h index 51ced2ec7..a46f9cf95 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -44,12 +44,22 @@ class CoreExport ConfigTag : public refcountbase /** 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); + long getInt(const std::string& key, long def = 0, long min = LONG_MIN, long max = LONG_MAX); /** 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 in seconds of a duration that is in the user-friendly "1h2m3s" format, + * using a default value if it does not exist or is out of bounds. + * @param key The config key name + * @param def Default value (optional) + * @param min Minimum acceptable value (optional) + * @param max Maximum acceptable value (optional) + * @return The duration in seconds + */ + long getDuration(const std::string& key, long def = 0, long min = LONG_MIN, long max = LONG_MAX); + /** 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) @@ -58,6 +68,16 @@ class CoreExport ConfigTag : public refcountbase */ bool readString(const std::string& key, std::string& value, bool allow_newline = false); + /** Check for an out of range value. If the value falls outside the boundaries a warning is + * logged and the value is corrected (set to def). + * @param key The key name, used in the warning message + * @param res The value to verify and modify if needed + * @param def The default value, res will be set to this if (min <= res <= max) doesn't hold true + * @param min Minimum accepted value for res + * @param max Maximum accepted value for res + */ + void CheckRange(const std::string& key, long& res, long def, long min, long max); + std::string getTagLocation(); inline const std::vector& getItems() const { return items; } @@ -184,6 +204,32 @@ class CoreExport ServerConfig void CrossCheckConnectBlocks(ServerConfig* current); public: + class ServerPaths + { + public: + /** Config path */ + std::string Config; + + /** Data path */ + std::string Data; + + /** Log path */ + std::string Log; + + /** Module path */ + std::string Module; + + ServerPaths() + : Config(CONFIG_PATH) + , Data(DATA_PATH) + , Log(LOG_PATH) + , Module(MOD_PATH) { } + + std::string PrependConfig(const std::string& fn) const { return FileSystem::ExpandPath(Config, fn); } + std::string PrependData(const std::string& fn) const { return FileSystem::ExpandPath(Data, fn); } + std::string PrependLog(const std::string& fn) const { return FileSystem::ExpandPath(Log, fn); } + std::string PrependModule(const std::string& fn) const { return FileSystem::ExpandPath(Module, fn); } + }; /** Get a configuration tag * @param tag The name of the tag to get @@ -220,6 +266,9 @@ class CoreExport ServerConfig */ ServerLimits Limits; + /** Locations of various types of file (config, module, etc). */ + ServerPaths Paths; + /** Configuration parsed from the command line. */ CommandLineConf cmdline; @@ -239,9 +288,9 @@ class CoreExport ServerConfig */ std::string ServerName; - /** Notice to give to users when they are Xlined + /** Notice to give to users when they are banned by an XLine */ - std::string MoronBanner; + std::string XLineMessage; /* Holds the network name the local server * belongs to. This is an arbitary field defined @@ -333,13 +382,6 @@ class CoreExport ServerConfig */ char DisabledCModes[64]; - /** The full path to the modules directory. - * This is either set at compile time, or - * overridden in the configuration file via - * the \ tag. - */ - std::string ModPath; - /** 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. @@ -450,11 +492,6 @@ class CoreExport ServerConfig */ bool SyntaxHints; - /** If set to true, users appear to quit then rejoin when their hosts change. - * This keeps clients synchronized properly. - */ - bool CycleHosts; - /** If set to true, the CycleHosts mode change will be sourced from the user, * rather than the server */ @@ -470,11 +507,14 @@ class CoreExport ServerConfig */ bool FullHostInTopic; - /** Oper block and type index. - * For anonymous oper blocks (type only), prefix with a space. + /** Oper blocks keyed by their name */ OperIndex oper_blocks; + /** Oper types keyed by their name + */ + OperIndex OperTypes; + /** Max channels per user */ unsigned int MaxChans; @@ -511,24 +551,8 @@ class CoreExport ServerConfig void Fill(); - /** Returns true if the given string starts with a windows drive letter - */ - bool StartsWithWindowsDriveLetter(const std::string &path); - bool ApplyDisabledCommands(const std::string& data); - /** Clean a filename, stripping the directories (and drives) from string. - * @param name Directory to tidy - * @return The cleaned filename - */ - static const char* CleanFilename(const char* name); - - /** Check if a file exists. - * @param file The full path to a file - * @return True if the file exists and is readable. - */ - static bool FileExists(const char* file); - /** Escapes a value for storage in a configuration key. * @param str The string to escape. * @param xml Are we using the XML config format? @@ -568,3 +592,14 @@ class CoreExport ConfigReaderThread : public Thread void Finish(); bool IsDone() { return done; } }; + +class CoreExport ConfigStatus +{ + public: + User* const srcuser; + + ConfigStatus(User* user = NULL) + : srcuser(user) + { + } +};