+ GoodChannels goodchans;
+ ConfigTagList tags = ServerInstance->Config->ConfTags("goodchan");
+ for (ConfigIter iter = tags.first; iter != tags.second; ++iter)
+ {
+ ConfigTag* tag = iter->second;
+
+ // Ensure that we have the <goodchan:name> parameter.
+ const std::string name = tag->getString("name");
+ if (name.empty())
+ throw ModuleException("<goodchan:name> is a mandatory field, at " + tag->getTagLocation());
+
+ goodchans.push_back(name);
+ }
+
+ BadChannels badchans;
+ tags = ServerInstance->Config->ConfTags("badchan");
+ for (ConfigIter i = tags.first; i != tags.second; ++i)
+ {
+ ConfigTag* tag = i->second;
+
+ // Ensure that we have the <badchan:name> parameter.
+ const std::string name = tag->getString("name");
+ if (name.empty())
+ throw ModuleException("<badchan:name> is a mandatory field, at " + tag->getTagLocation());
+
+ // Ensure that we have the <badchan:reason> parameter.
+ const std::string reason = tag->getString("reason");
+ if (reason.empty())
+ throw ModuleException("<badchan:reason> is a mandatory field, at " + tag->getTagLocation());
+
+ const std::string redirect = tag->getString("redirect");
+ if (!redirect.empty())
+ {
+ // Ensure that <badchan:redirect> contains a channel name.
+ if (!ServerInstance->IsChannel(redirect))
+ throw ModuleException("<badchan:redirect> is not a valid channel name, at " + tag->getTagLocation());
+
+ // We defer the rest of the validation of the redirect channel until we have
+ // finished parsing all of the badchans.
+ }
+
+ badchans.push_back(BadChannel(name, redirect, reason, tag->getBool("allowopers")));
+ }
+
+ // Now we have all of the badchan information recorded we can check that all redirect
+ // channels can actually be redirected to.
+ for (BadChannels::const_iterator i = badchans.begin(); i != badchans.end(); ++i)
+ {
+ const BadChannel& badchan = *i;
+
+ // If there is no redirect channel we have nothing to do.
+ if (badchan.redirect.empty())
+ continue;
+
+ // If the redirect channel is whitelisted then it is okay.
+ for (GoodChannels::const_iterator j = goodchans.begin(); j != goodchans.end(); ++j)
+ if (InspIRCd::Match(badchan.redirect, *j))
+ continue;
+
+ // If the redirect channel is not blacklisted then it is okay.
+ for (BadChannels::const_iterator j = badchans.begin(); j != badchans.end(); ++j)
+ if (InspIRCd::Match(badchan.redirect, j->name))
+ throw ModuleException("<badchan:redirect> cannot be a blacklisted channel name");
+ }
+
+ // The config file contained no errors so we can apply the new configuration.
+ badchannels.swap(badchans);
+ goodchannels.swap(goodchans);