+ if (c.threshold == 0)
+ {
+ c.threshold = 1;
+ c.flood = 999;
+ log(DEFAULT,"Warning: Connect allow line '%s' has no flood/threshold settings. Setting this tag to 999 lines in 1 second.",c.host.c_str());
+ }
+ if (c.sendqmax == 0)
+ c.sendqmax = 262114;
+ if (c.recvqmax == 0)
+ c.recvqmax = 4096;
+ if (c.registration_timeout == 0)
+ c.registration_timeout = 90;
+ if (c.pingtime == 0)
+ c.pingtime = 120;
+ Config->Classes.push_back(c);
+ }
+ else
+ {
+ c.host = deny;
+ c.type = CC_DENY;
+ Config->Classes.push_back(c);
+ log(DEBUG,"Read connect class type DENY, host=%s",deny);
+ }
+
+ return true;
+}
+
+/* Callback called when there are no more <connect> tags
+ */
+bool DoneConnect(const char* tag)
+{
+ log(DEBUG,"DoneConnect called for tag: %s",tag);
+ return true;
+}
+
+/* Callback called before processing the first <uline> tag
+ */
+bool InitULine(const char* tag)
+{
+ Config->ulines.clear();
+ return true;
+}
+
+/* Callback called to process a single <uline> tag
+ */
+bool DoULine(const char* tag, char** entries, void** values, int* types)
+{
+ char* server = (char*)values[0];
+ log(DEBUG,"Read ULINE '%s'",server);
+ Config->ulines.push_back(server);
+ return true;
+}
+
+/* Callback called when there are no more <uline> tags
+ */
+bool DoneULine(const char* tag)
+{
+ return true;
+}
+
+/* Callback called before processing the first <module> tag
+ */
+bool InitModule(const char* tag)
+{
+ old_module_names.clear();
+ new_module_names.clear();
+ added_modules.clear();
+ removed_modules.clear();
+ for (std::vector<std::string>::iterator t = Config->module_names.begin(); t != Config->module_names.end(); t++)
+ {
+ old_module_names.push_back(*t);
+ }
+ return true;
+}
+
+/* Callback called to process a single <module> tag
+ */
+bool DoModule(const char* tag, char** entries, void** values, int* types)
+{
+ char* modname = (char*)values[0];
+ new_module_names.push_back(modname);
+ return true;
+}
+
+/* Callback called when there are no more <module> tags
+ */
+bool DoneModule(const char* tag)
+{
+ // now create a list of new modules that are due to be loaded
+ // and a seperate list of modules which are due to be unloaded
+ for (std::vector<std::string>::iterator _new = new_module_names.begin(); _new != new_module_names.end(); _new++)
+ {
+ bool added = true;
+
+ for (std::vector<std::string>::iterator old = old_module_names.begin(); old != old_module_names.end(); old++)
+ {
+ if (*old == *_new)
+ added = false;
+ }
+
+ if (added)
+ added_modules.push_back(*_new);
+ }
+
+ for (std::vector<std::string>::iterator oldm = old_module_names.begin(); oldm != old_module_names.end(); oldm++)
+ {
+ bool removed = true;
+ for (std::vector<std::string>::iterator newm = new_module_names.begin(); newm != new_module_names.end(); newm++)
+ {
+ if (*newm == *oldm)
+ removed = false;
+ }
+
+ if (removed)
+ removed_modules.push_back(*oldm);
+ }
+ return true;
+}
+
+/* Callback called before processing the first <banlist> tag
+ */
+bool InitMaxBans(const char* tag)
+{
+ Config->maxbans.clear();
+ return true;
+}
+
+/* Callback called to process a single <banlist> tag
+ */
+bool DoMaxBans(const char* tag, char** entries, void** values, int* types)
+{
+ char* channel = (char*)values[0];
+ int* limit = (int*)values[1];
+ Config->maxbans[channel] = *limit;
+ return true;
+}
+
+/* Callback called when there are no more <banlist> tags.
+ */
+bool DoneMaxBans(const char* tag)
+{
+ return true;
+}
+
+void ServerConfig::Read(bool bail, userrec* user)
+{
+ char debug[MAXBUF]; /* Temporary buffer for debugging value */
+ char* data[12]; /* Temporary buffers for reading multiple occurance tags into */
+ void* ptr[12]; /* Temporary pointers for passing to callbacks */
+ int r_i[12]; /* Temporary array for casting */
+ int rem = 0, add = 0; /* Number of modules added, number of modules removed */
+ std::ostringstream errstr; /* String stream containing the error output */
+
+ /* These tags MUST occur and must ONLY occur once in the config file */
+ static char* Once[] = { "server", "admin", "files", "power", "options", "pid", NULL };
+
+ /* These tags can occur ONCE or not at all */
+ static InitialConfig Values[] = {
+ {"options", "softlimit", &this->SoftLimit, DT_INTEGER, ValidateSoftLimit},
+ {"options", "somaxconn", &this->MaxConn, DT_INTEGER, ValidateMaxConn},
+ {"server", "name", &this->ServerName, DT_CHARPTR, ValidateServerName},
+ {"server", "description", &this->ServerDesc, DT_CHARPTR, ValidateServerDesc},
+ {"server", "network", &this->Network, DT_CHARPTR, ValidateNetworkName},
+ {"admin", "name", &this->AdminName, DT_CHARPTR, NoValidation},
+ {"admin", "email", &this->AdminEmail, DT_CHARPTR, NoValidation},
+ {"admin", "nick", &this->AdminNick, DT_CHARPTR, NoValidation},
+ {"files", "motd", &this->motd, DT_CHARPTR, ValidateMotd},
+ {"files", "rules", &this->rules, DT_CHARPTR, ValidateRules},
+ {"power", "diepass", &this->diepass, DT_CHARPTR, NoValidation},
+ {"power", "pauseval", &this->DieDelay, DT_INTEGER, NoValidation},
+ {"power", "restartpass", &this->restartpass, DT_CHARPTR, NoValidation},
+ {"options", "prefixquit", &this->PrefixQuit, DT_CHARPTR, NoValidation},
+ {"die", "value", &this->DieValue, DT_CHARPTR, NoValidation},
+ {"options", "loglevel", &debug, DT_CHARPTR, ValidateLogLevel},
+ {"options", "netbuffersize", &this->NetBufferSize, DT_INTEGER, ValidateNetBufferSize},
+ {"options", "maxwho", &this->MaxWhoResults, DT_INTEGER, ValidateMaxWho},
+ {"options", "allowhalfop", &this->AllowHalfop, DT_BOOLEAN, NoValidation},
+ {"dns", "server", &this->DNSServer, DT_CHARPTR, ValidateDnsServer},
+ {"dns", "timeout", &this->dns_timeout, DT_INTEGER, ValidateDnsTimeout},
+ {"options", "moduledir", &this->ModPath, DT_CHARPTR, ValidateModPath},
+ {"disabled", "commands", &this->DisabledCommands, DT_CHARPTR, NoValidation},
+ {"options", "operonlystats", &this->OperOnlyStats, DT_CHARPTR, NoValidation},
+ {"options", "customversion", &this->CustomVersion, DT_CHARPTR, NoValidation},
+ {"options", "hidesplits", &this->HideSplits, DT_BOOLEAN, NoValidation},
+ {"options", "hidebans", &this->HideBans, DT_BOOLEAN, NoValidation},
+ {"options", "hidewhois", &this->HideWhoisServer, DT_CHARPTR, NoValidation},
+ {"options", "operspywhois", &this->OperSpyWhois, DT_BOOLEAN, NoValidation},
+ {"options", "tempdir", &this->TempDir, DT_CHARPTR, ValidateTempDir},
+ {"pid", "file", &this->PID, DT_CHARPTR, NoValidation},
+ {NULL}
+ };
+
+ /* These tags can occur multiple times, and therefore they have special code to read them
+ * which is different to the code for reading the singular tags listed above.
+ */
+ static MultiConfig MultiValues[] = {
+
+ {"connect",
+ {"allow", "deny", "password", "timeout", "pingfreq", "flood",
+ "threshold", "sendq", "recvq", "localmax", "globalmax", NULL},
+ {DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_INTEGER, DT_INTEGER, DT_INTEGER,
+ DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER, DT_INTEGER},
+ InitConnect, DoConnect, DoneConnect},
+
+ {"uline",
+ {"server", NULL},
+ {DT_CHARPTR},
+ InitULine,DoULine,DoneULine},
+
+ {"banlist",
+ {"chan", "limit", NULL},
+ {DT_CHARPTR, DT_INTEGER},
+ InitMaxBans, DoMaxBans, DoneMaxBans},
+
+ {"module",
+ {"name", NULL},
+ {DT_CHARPTR},
+ InitModule, DoModule, DoneModule},
+
+ {"badip",
+ {"reason", "ipmask", NULL},
+ {DT_CHARPTR, DT_CHARPTR},
+ InitXLine, DoZLine, DoneXLine},
+
+ {"badnick",
+ {"reason", "nick", NULL},
+ {DT_CHARPTR, DT_CHARPTR},
+ InitXLine, DoQLine, DoneXLine},
+
+ {"badhost",
+ {"reason", "host", NULL},
+ {DT_CHARPTR, DT_CHARPTR},
+ InitXLine, DoKLine, DoneXLine},
+
+ {"exception",
+ {"reason", "host", NULL},
+ {DT_CHARPTR, DT_CHARPTR},
+ InitXLine, DoELine, DoneXLine},
+
+ {"type",
+ {"name", "classes", NULL},
+ {DT_CHARPTR, DT_CHARPTR},
+ InitTypes, DoType, DoneClassesAndTypes},
+
+ {"class",
+ {"name", "commands", NULL},
+ {DT_CHARPTR, DT_CHARPTR},
+ InitClasses, DoClass, DoneClassesAndTypes},
+
+ {NULL}
+ };
+
+ include_stack.clear();
+
+ /* Load and parse the config file, if there are any errors then explode */
+
+ /* Make a copy here so if it fails then we can carry on running with an unaffected config */
+ ConfigDataHash newconfig;
+
+ if (this->LoadConf(newconfig, CONFIG_FILE, errstr))
+ {
+ /* If we succeeded, set the ircd config to the new one */
+ Config->config_data = newconfig;
+
+/* int c = 1;
+ std::string last;
+
+ for(ConfigDataHash::const_iterator i = this->config_data.begin(); i != this->config_data.end(); i++)
+ {
+ c = (i->first != last) ? 1 : c+1;
+ last = i->first;
+
+ std::cout << "[" << i->first << " " << c << "/" << this->config_data.count(i->first) << "]" << std::endl;
+
+ for(KeyValList::const_iterator j = i->second.begin(); j != i->second.end(); j++)
+ std::cout << "\t" << j->first << " = " << j->second << std::endl;
+
+ std::cout << "[/" << i->first << " " << c << "/" << this->config_data.count(i->first) << "]" << std::endl;
+ }
+ */ }
+ else
+ {
+ log(DEFAULT, "There were errors in your configuration:\n%s", errstr.str().c_str());
+
+ if (bail)
+ {
+ /* Unneeded because of the log() aboive? */
+ printf("There were errors in your configuration:\n%s",errstr.str().c_str());
+ Exit(0);
+ }
+ else
+ {
+ std::string errors = errstr.str();
+ std::string::size_type start;
+ unsigned int prefixlen;
+
+ start = 0;
+ /* ":Config->ServerName NOTICE user->nick :" */
+ prefixlen = strlen(Config->ServerName) + strlen(user->nick) + 11;
+
+ if (user)