11 #include "../contrib/libdazeus-irc/src/utils.h"
55 std::vector<NetworkConfig*>::iterator it;
56 for(it = networks.begin(); it != networks.end(); ++it) {
57 std::vector<ServerConfig*>::iterator sit;
58 for(sit = (*it)->servers.begin(); sit != (*it)->servers.end(); ++sit) {
61 (*it)->servers.clear();
65 std::vector<SocketConfig*>::iterator sockit;
66 for(sockit = sockets.begin(); sockit != sockets.end(); ++sockit) {
70 std::vector<PluginConfig*>::iterator pit;
71 for(pit = plugins.begin(); pit != plugins.end(); ++pit) {
84 {
"<socket>", ARG_NONE, sect_open, NULL, CTX_ALL},
85 {
"</socket>", ARG_NONE, sect_close, NULL, CTX_ALL},
86 {
"<database>", ARG_NONE, sect_open, NULL, CTX_ALL},
87 {
"</database>", ARG_NONE, sect_close, NULL, CTX_ALL},
88 {
"<network", ARG_STR, sect_open, NULL, CTX_ALL},
89 {
"</network>", ARG_NONE, sect_close, NULL, CTX_ALL},
90 {
"<server>", ARG_NONE, sect_open, NULL, CTX_ALL},
91 {
"</server>", ARG_NONE, sect_close, NULL, CTX_ALL},
92 {
"<plugin", ARG_STR, sect_open, NULL, CTX_ALL},
93 {
"</plugin>", ARG_NONE, sect_close, NULL, CTX_ALL},
94 {
"nickname", ARG_RAW, option, NULL, CTX_ALL},
95 {
"username", ARG_RAW, option, NULL, CTX_ALL},
96 {
"fullname", ARG_RAW, option, NULL, CTX_ALL},
97 {
"plugindirectory", ARG_RAW, option, NULL, CTX_ALL},
98 {
"highlight", ARG_RAW, option, NULL, CTX_ALL},
99 {
"type", ARG_RAW, option, NULL, CTX_ALL},
100 {
"path", ARG_RAW, option, NULL, CTX_ALL},
101 {
"host", ARG_RAW, option, NULL, CTX_ALL},
102 {
"port", ARG_INT, option, NULL, CTX_ALL},
103 {
"password", ARG_RAW, option, NULL, CTX_ALL},
104 {
"database", ARG_RAW, option, NULL, CTX_ALL},
105 {
"options", ARG_RAW, option, NULL, CTX_ALL},
106 {
"autoconnect", ARG_RAW, option, NULL, CTX_ALL},
107 {
"priority", ARG_INT, option, NULL, CTX_ALL},
108 {
"ssl", ARG_RAW, option, NULL, CTX_ALL},
109 {
"sslverify", ARG_RAW, option, NULL, CTX_ALL},
110 {
"executable", ARG_RAW, option, NULL, CTX_ALL},
111 {
"scope", ARG_RAW, option, NULL, CTX_ALL},
112 {
"parameters", ARG_RAW, option, NULL, CTX_ALL},
113 {
"var", ARG_RAW, option, NULL, CTX_ALL},
121 return s ==
"true" || s ==
"yes" || s ==
"1";
127 configfile_t *configfile = dotconf_create(
128 const_cast<char*>(file.c_str()),
options,
129 this, CASE_INSENSITIVE);
131 throw exception(state->error =
"Error opening config file.");
134 configfile->errorhandler = (dotconf_errorhandler_t) error_handler;
139 if(dotconf_command_loop(configfile) == 0 || state->error.length() > 0) {
140 dotconf_cleanup(configfile);
141 if(state->error.size() == 0)
142 state->error =
"Error reading config file.";
146 if(state->database_progress == 0) {
147 throw exception(
"No Database block defined in config file.");
150 assert(state->socket_progress == 0);
151 assert(state->network_progress == 0);
152 assert(state->server_progress == 0);
153 assert(state->plugin_progress == 0);
155 sockets = state->sockets;
156 networks = state->networks;
157 plugins = state->plugins;
158 global = state->global_progress;
159 database = state->database_progress;
161 state->sockets.clear();
162 state->networks.clear();
163 state->plugins.clear();
165 dotconf_cleanup(configfile);
175 if(s->
error.length() == 0) {
178 s->
error.append(
"\n" + std::string(msg));
188 std::string name(cmd->name);
196 if(name ==
"<socket>") {
199 }
else if(name ==
"<database>") {
201 return "More than one Database block defined in configuration file.";
205 }
else if(name ==
"<network") {
206 std::string networkname = cmd->data.str;
207 networkname.resize(networkname.length() - 1);
213 default_nick, default_user, default_full);
214 }
else if(name ==
"<plugin") {
215 std::string pluginname = cmd->data.str;
216 pluginname.resize(pluginname.length() - 1);
217 if(pluginname.length() == 0) {
218 return "All plugins must have a name in their <Plugin> tag.";
223 return "Logic error";
229 if(name ==
"<server>") {
235 return "Logic error";
246 std::string name(cmd->name);
249 case S_ROOT:
return "Logic error";
251 if(name ==
"</socket>") {
256 return "Logic error";
260 if(name ==
"</database>") {
263 return "Logic error";
267 if(name ==
"</network>") {
272 return "Logic error";
276 if(name ==
"</server>") {
281 return "Logic error";
285 if(name ==
"</plugin>") {
290 return "Logic error";
294 return "Logic error";
304 std::string name(cmd->name);
309 if(name ==
"nickname") {
311 }
else if(name ==
"username") {
313 }
else if(name ==
"fullname") {
315 }
else if(name ==
"plugindirectory") {
317 }
else if(name ==
"highlight") {
320 s->
error =
"Invalid option name in root context: " + name;
321 return "Configuration file contains errors";
330 }
else if(name ==
"path") {
332 }
else if(name ==
"host") {
334 }
else if(name ==
"port") {
335 if(cmd->data.value > std::numeric_limits<uint16_t>::max() || cmd->data.value < 0) {
336 return "Invalid value for 'port'";
338 sc->
port = cmd->data.value;
340 s->
error =
"Invalid option name in socket context: " + name;
341 return "Configuration file contains errors";
350 }
else if(name ==
"host") {
352 }
else if(name ==
"port") {
353 dc->
port = cmd->data.value;
354 }
else if(name ==
"username") {
356 }
else if(name ==
"password") {
358 }
else if(name ==
"database") {
360 }
else if(name ==
"options") {
363 s->
error =
"Invalid option name in database context: " + name;
364 return "Configuration file contains errors";
371 if(name ==
"autoconnect") {
373 }
else if(name ==
"nickname") {
375 }
else if(name ==
"username") {
377 }
else if(name ==
"fullname") {
379 }
else if(name ==
"password") {
382 s->
error =
"Invalid option name in network context: " + name;
383 return "Configuration file contains errors";
392 }
else if(name ==
"port") {
393 sc->
port = cmd->data.value;
394 }
else if(name ==
"priority") {
396 }
else if(name ==
"ssl") {
398 }
else if(name ==
"sslverify") {
401 s->
error =
"Invalid option name in server context: " + name;
402 return "Configuration file contains errors";
411 }
else if(name ==
"executable") {
413 }
else if(name ==
"scope") {
415 if(scope ==
"network") {
417 }
else if(scope !=
"global") {
418 s->
error =
"Invalid value for Scope for plugin " + pc->
name;
419 return "Configuration file contains errors";
421 }
else if(name ==
"parameters") {
423 }
else if(name ==
"var") {
424 if(cmd->arg_count != 2) {
425 s->
error =
"Invalid amount of parameters to Var in plugin context";
426 return "Configuration file contains errors";
430 s->
error =
"Invalid option name in plugin context: " + name;
431 return "Configuration file contains errors";
436 return "Logic error";