+ HostRules rules;
+
+ ConfigTagList tags = ServerInstance->Config->ConfTags("hostchange");
+ for (ConfigIter i = tags.first; i != tags.second; ++i)
+ {
+ ConfigTag* tag = i->second;
+
+ // Ensure that we have the <hostchange:mask> parameter.
+ const std::string mask = tag->getString("mask");
+ if (mask.empty())
+ throw ModuleException("<hostchange:mask> is a mandatory field, at " + tag->getTagLocation());
+
+ insp::flat_set<int> ports;
+ const std::string portlist = tag->getString("ports");
+ if (!ports.empty())
+ {
+ irc::portparser portrange(portlist, false);
+ while (int port = portrange.GetToken())
+ ports.insert(port);
+ }
+
+ // Determine what type of host rule this is.
+ const std::string action = tag->getString("action");
+ if (stdalgo::string::equalsci(action, "addaccount"))
+ {
+ // The hostname is in the format [prefix]<account>[suffix].
+ rules.push_back(HostRule(HostRule::HCA_ADDACCOUNT, mask, ports, tag->getString("prefix"), tag->getString("suffix")));
+ }
+ else if (stdalgo::string::equalsci(action, "addnick"))
+ {
+ // The hostname is in the format [prefix]<nick>[suffix].
+ rules.push_back(HostRule(HostRule::HCA_ADDNICK, mask, ports, tag->getString("prefix"), tag->getString("suffix")));
+ }
+ else if (stdalgo::string::equalsci(action, "set"))
+ {
+ // Ensure that we have the <hostchange:value> parameter.
+ const std::string value = tag->getString("value");
+ if (value.empty())
+ throw ModuleException("<hostchange:value> is a mandatory field when using the 'set' action, at " + tag->getTagLocation());
+
+ // The hostname is in the format <value>.
+ rules.push_back(HostRule(mask, value, ports));
+ continue;
+ }
+ else
+ {
+ throw ModuleException(action + " is an invalid <hostchange:action> type, at " + tag->getTagLocation());
+ }
+ }
+
+ const std::string hmap = ServerInstance->Config->ConfValue("hostname")->getString("charmap", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789");
+ hostmap.reset();
+ for (std::string::const_iterator iter = hmap.begin(); iter != hmap.end(); ++iter)
+ hostmap.set(static_cast<unsigned char>(*iter));
+ hostrules.swap(rules);