anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

config.h (5400B)

      1 /*
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #ifndef CONFIG_H
     13 #define CONFIG_H
     14 
     15 #include "account.h"
     16 #include "regchannel.h"
     17 #include "users.h"
     18 #include "opertype.h"
     19 #include <stack>
     20 
     21 namespace Configuration
     22 {
     23 	class CoreExport Block
     24 	{
     25 		friend struct Conf;
     26 
     27 	 public:
     28 		typedef Anope::map<Anope::string> item_map;
     29 		typedef Anope::multimap<Block> block_map;
     30 
     31 	 private:
     32 		Anope::string name;
     33 		item_map items;
     34 		block_map blocks;
     35 		int linenum;
     36 
     37 	 public:
     38 		Block(const Anope::string &);
     39 		const Anope::string &GetName() const;
     40 		int CountBlock(const Anope::string &name);
     41 		Block* GetBlock(const Anope::string &name, int num = 0);
     42 
     43 		template<typename T> inline T Get(const Anope::string &tag)
     44 		{
     45 			return this->Get<T>(tag, "");
     46 		}
     47 		/* VS 2008 has an issue with having a default argument here (def = ""), which is why the above
     48 		 * function exists.
     49 		 */
     50 		template<typename T> T Get(const Anope::string &tag, const Anope::string &def) const
     51 		{
     52 			const Anope::string &value = this->Get<const Anope::string>(tag, def);
     53 			if (!value.empty())
     54 				try
     55 				{
     56 					return convertTo<T>(value);
     57 				}
     58 				catch (const ConvertException &) { }
     59 			return T();
     60 		}
     61 
     62 		bool Set(const Anope::string &tag, const Anope::string &value);
     63 		const item_map* GetItems() const;
     64 	};
     65 
     66 	template<> CoreExport const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const;
     67 	template<> CoreExport time_t Block::Get(const Anope::string &tag, const Anope::string &def) const;
     68 	template<> CoreExport bool Block::Get(const Anope::string &tag, const Anope::string &def) const;
     69 
     70 	/** Represents a configuration file
     71 	 */
     72 	class File
     73 	{
     74 		Anope::string name;
     75 		bool executable;
     76 		FILE *fp;
     77 	 public:
     78 		File(const Anope::string &, bool);
     79 		~File();
     80 		const Anope::string &GetName() const;
     81 		Anope::string GetPath() const;
     82 
     83 		bool IsOpen() const;
     84 		bool Open();
     85 		void Close();
     86 		bool End() const;
     87 		Anope::string Read();
     88 	};
     89 
     90 	struct Uplink;
     91 
     92 	struct CoreExport Conf : Block
     93 	{
     94 		/* options:readtimeout */
     95 		time_t ReadTimeout;
     96 		/* options:useprivmsg */
     97 		bool UsePrivmsg;
     98 		/* If we should default to privmsging clients */
     99 		bool DefPrivmsg;
    100 		/* Default language */
    101 		Anope::string DefLanguage;
    102 		/* options:timeoutcheck */
    103 		time_t TimeoutCheck;
    104 		/* options:usestrictprivmsg */
    105 		bool UseStrictPrivmsg;
    106 		/* networkinfo:nickchars */
    107 		Anope::string NickChars;
    108 
    109 		/* either "/msg " or "/" */
    110 		Anope::string StrictPrivmsg;
    111 		/* List of uplink servers to try and connect to */
    112 		std::vector<Uplink> Uplinks;
    113 		/* A vector of our logfile options */
    114 		std::vector<LogInfo> LogInfos;
    115 		/* Array of ulined servers */
    116 		std::vector<Anope::string> Ulines;
    117 		/* List of available opertypes */
    118 		std::vector<OperType *> MyOperTypes;
    119 		/* List of pairs of opers and their opertype from the config */
    120 		std::vector<Oper *> Opers;
    121 		/* Map of fantasy commands */
    122 		CommandInfo::map Fantasy;
    123 		/* Command groups */
    124 		std::vector<CommandGroup> CommandGroups;
    125 		/* List of modules to autoload */
    126 		std::vector<Anope::string> ModulesAutoLoad;
    127 
    128 		/* module configuration blocks */
    129 		std::map<Anope::string, Block *> modules;
    130 		Anope::map<Anope::string> bots;
    131 
    132 		Conf();
    133 		~Conf();
    134 
    135 		void LoadConf(File &file);
    136 		void Post(Conf *old);
    137 
    138 		Block *GetModule(Module *);
    139 		Block *GetModule(const Anope::string &name);
    140 
    141 		BotInfo *GetClient(const Anope::string &name);
    142 
    143 		Block *GetCommand(CommandSource &);
    144 	};
    145 
    146 	struct Uplink
    147 	{
    148 		Anope::string host;
    149 		unsigned port;
    150 		Anope::string password;
    151 		bool ipv6;
    152 
    153 		Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { }
    154 		inline bool operator==(const Uplink &other) const { return host == other.host && port == other.port && password == other.password && ipv6 == other.ipv6; }
    155 		inline bool operator!=(const Uplink &other) const { return !(*this == other); }
    156 	};
    157 }
    158 
    159 /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
    160  * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or
    161  * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not
    162  * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
    163  * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
    164  */
    165 class ConfigException : public CoreException
    166 {
    167  public:
    168 	/** Default constructor, just uses the error message 'Config threw an exception'.
    169 	 */
    170 	ConfigException() : CoreException("Config threw an exception", "Config Parser") { }
    171 	/** This constructor can be used to specify an error message before throwing.
    172 	 */
    173 	ConfigException(const Anope::string &message) : CoreException(message, "Config Parser") { }
    174 	/** This destructor solves world hunger, cancels the world debt, and causes the world to end.
    175 	 * Actually no, it does nothing. Never mind.
    176 	 * @throws Nothing!
    177 	 */
    178 	virtual ~ConfigException() throw() { }
    179 };
    180 
    181 extern Configuration::File ServicesConf;
    182 extern CoreExport Configuration::Conf *Config;
    183 
    184 #endif // CONFIG_H