Anope IRC Services  Version 2.0
config.h
Go to the documentation of this file.
1 /*
2  *
3  * (C) 2003-2014 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 
13 #ifndef CONFIG_H
14 #define CONFIG_H
15 
16 #include "account.h"
17 #include "regchannel.h"
18 #include "users.h"
19 #include "opertype.h"
20 #include <stack>
21 
22 namespace Configuration
23 {
25  {
26  friend struct Conf;
27 
28  public:
31 
32  private:
34  item_map items;
35  block_map blocks;
36  int linenum;
37 
38  public:
39  Block(const Anope::string &);
40  const Anope::string &GetName() const;
41  int CountBlock(const Anope::string &name);
42  Block* GetBlock(const Anope::string &name, int num = 0);
43 
44  template<typename T> inline T Get(const Anope::string &tag)
45  {
46  return this->Get<T>(tag, "");
47  }
48  /* VS 2008 has an issue with having a default argument here (def = ""), which is why the above
49  * function exists.
50  */
51  template<typename T> T Get(const Anope::string &tag, const Anope::string &def) const
52  {
53  const Anope::string &value = this->Get<const Anope::string>(tag, def);
54  if (!value.empty())
55  try
56  {
57  return convertTo<T>(value);
58  }
59  catch (const ConvertException &) { }
60  return T();
61  }
62 
63  bool Set(const Anope::string &tag, const Anope::string &value);
64  const item_map* GetItems() const;
65  };
66 
67  template<> CoreExport const Anope::string Block::Get(const Anope::string &tag, const Anope::string& def) const;
68  template<> CoreExport time_t Block::Get(const Anope::string &tag, const Anope::string &def) const;
69  template<> CoreExport bool Block::Get(const Anope::string &tag, const Anope::string &def) const;
70 
73  class File
74  {
76  bool executable;
77  FILE *fp;
78  public:
79  File(const Anope::string &, bool);
80  ~File();
81  const Anope::string &GetName() const;
82 
83  bool IsOpen() const;
84  bool Open();
85  void Close();
86  bool End() const;
88  };
89 
90  struct Uplink;
91 
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 */
102  /* options:timeoutcheck */
103  time_t TimeoutCheck;
104  /* options:usestrictprivmsg */
106 
107  /* either "/msg " or "/" */
109  /* List of uplink servers to try and connect to */
110  std::vector<Uplink> Uplinks;
111  /* A vector of our logfile options */
112  std::vector<LogInfo> LogInfos;
113  /* Array of ulined servers */
114  std::vector<Anope::string> Ulines;
115  /* List of available opertypes */
116  std::vector<OperType *> MyOperTypes;
117  /* List of pairs of opers and their opertype from the config */
118  std::vector<Oper *> Opers;
119  /* Map of fantasy commands */
121  /* Command groups */
122  std::vector<CommandGroup> CommandGroups;
123  /* List of modules to autoload */
124  std::vector<Anope::string> ModulesAutoLoad;
125 
126  /* module configuration blocks */
127  std::map<Anope::string, Block *> modules;
129 
130  Conf();
131  ~Conf();
132 
133  void LoadConf(File &file);
134  void Post(Conf *old);
135 
136  Block *GetModule(Module *);
137  Block *GetModule(const Anope::string &name);
138 
139  BotInfo *GetClient(const Anope::string &name);
140 
141  Block *GetCommand(CommandSource &);
142  };
143 
144  struct Uplink
145  {
147  unsigned port;
149  bool ipv6;
150 
151  Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { }
152  inline bool operator==(const Uplink &other) const { return host == other.host && port == other.port && password == other.password && ipv6 == other.ipv6; }
153  inline bool operator!=(const Uplink &other) const { return !(*this == other); }
154  };
155 }
156 
164 {
165  public:
168  ConfigException() : CoreException("Config threw an exception", "Config Parser") { }
171  ConfigException(const Anope::string &message) : CoreException(message, "Config Parser") { }
176  virtual ~ConfigException() throw() { }
177 };
178 
181 
182 #endif // CONFIG_H
Definition: bots.h:24
std::vector< CommandGroup > CommandGroups
Definition: config.h:122
std::vector< Anope::string > ModulesAutoLoad
Definition: config.h:124
bool UseStrictPrivmsg
Definition: config.h:105
time_t ReadTimeout
Definition: config.h:95
item_map items
Definition: config.h:34
Anope::string name
Definition: config.h:33
std::vector< OperType * > MyOperTypes
Definition: config.h:116
std::vector< LogInfo > LogInfos
Definition: config.h:112
CommandInfo::map Fantasy
Definition: config.h:120
Anope::map< Anope::string > item_map
Definition: config.h:29
const Anope::string & GetName() const
Definition: config.cpp:647
Anope::string Read()
Definition: config.cpp:681
std::vector< Oper * > Opers
Definition: config.h:118
bool empty() const
Definition: anope.h:126
std::vector< Anope::string > Ulines
Definition: config.h:114
time_t TimeoutCheck
Definition: config.h:103
#define CoreExport
Definition: services.h:62
virtual ~ConfigException()
Definition: config.h:176
Configuration::File ServicesConf
Anope::multimap< Block > block_map
Definition: config.h:30
T Get(const Anope::string &tag, const Anope::string &def) const
Definition: config.h:51
std::map< Anope::string, Block * > modules
Definition: config.h:127
Anope::string name
Definition: access.cpp:22
Anope::map< Anope::string > bots
Definition: config.h:128
T Get(const Anope::string &tag)
Definition: config.h:44
CoreExport Configuration::Conf * Config
Definition: config.cpp:24
File(const Anope::string &, bool)
Definition: config.cpp:638
Anope::string name
Definition: config.h:75
Anope::string StrictPrivmsg
Definition: config.h:108
bool IsOpen() const
Definition: config.cpp:652
block_map blocks
Definition: config.h:35
std::vector< Uplink > Uplinks
Definition: config.h:110
ConfigException(const Anope::string &message)
Definition: config.h:171
Anope::string DefLanguage
Definition: config.h:101
bool End() const
Definition: config.cpp:676