- std::string mask = Conf.ReadValue("hostchange", "mask", index);
- std::string ports = Conf.ReadValue("hosthange", "ports", index);
- std::string action = Conf.ReadValue("hostchange", "action", index);
- std::string newhost = Conf.ReadValue("hostchange", "value", index);
- Host* x = new Host;
- x->action = action;
- x->ports = ports;
- x->newhost = newhost;
- hostchanges[mask] = x;
+ 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());
+ }