diff options
author | Adam <Adam@anope.org> | 2013-05-05 01:55:04 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-05-05 01:55:04 -0400 |
commit | 1d0bb9b26b7ad58ab0bf979ac046f4511b3bf12b (patch) | |
tree | 4486f0784bdf050fd7eb225c0cb9df352ce1f45a /modules/commands/os_config.cpp | |
parent | 781defb7076ddfddf723ca08cd0a518b6657b64f (diff) |
Rework the config file reader to be much more flexible and move many configuration directives to the actual modules they are used in.
Diffstat (limited to 'modules/commands/os_config.cpp')
-rw-r--r-- | modules/commands/os_config.cpp | 154 |
1 files changed, 19 insertions, 135 deletions
diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp index 0517f28d7..391d36157 100644 --- a/modules/commands/os_config.cpp +++ b/modules/commands/os_config.cpp @@ -15,22 +15,6 @@ class CommandOSConfig : public Command { - void ChangeHash(ConfigDataHash &hash, const Anope::string &block, const Anope::string &iname, const Anope::string &value) - { - ConfigDataHash::iterator it = hash.find(block); - - KeyValList &list = it->second; - for (unsigned i = 0; i < list.size(); ++i) - { - const Anope::string &item = list[i].first; - if (item == iname) - { - list[i] = std::make_pair(item, value); - break; - } - } - } - public: CommandOSConfig(Module *creator) : Command(creator, "operserv/config", 1, 4) { @@ -44,110 +28,17 @@ class CommandOSConfig : public Command if (what.equals_ci("MODIFY") && params.size() > 3) { - ConfigItems configitems(Config); - - for (unsigned i = 0; !configitems.Values[i].tag.empty(); ++i) + Configuration::Block *block = Config->GetBlock(params[1]); + if (!block) { - ConfigItems::Item *v = &configitems.Values[i]; - if (v->tag.equals_cs(params[1]) && v->value.equals_cs(params[2])) - { - try - { - ValueItem vi(params[3]); - if (!v->validation_function(Config, v->tag, v->value, vi)) - throw ConfigException("Parameter failed to validate."); - - int dt = v->datatype; - - if (dt & DT_NORELOAD) - throw ConfigException("This item can not be changed while Anope is running."); - bool allow_wild = dt & DT_ALLOW_WILD; - dt &= ~(DT_ALLOW_NEWLINE | DT_ALLOW_WILD); - - /* Yay for *massive* copypaste from reader.cpp */ - switch (dt) - { - case DT_NOSPACES: - { - ValueContainerString *vcs = anope_dynamic_static_cast<ValueContainerString *>(v->val); - Config->ValidateNoSpaces(vi.GetValue(), v->tag, v->value); - vcs->Set(vi.GetValue()); - break; - } - case DT_HOSTNAME: - { - ValueContainerString *vcs = anope_dynamic_static_cast<ValueContainerString *>(v->val); - Config->ValidateHostname(vi.GetValue(), v->tag, v->value); - vcs->Set(vi.GetValue()); - break; - } - case DT_IPADDRESS: - { - ValueContainerString *vcs = anope_dynamic_static_cast<ValueContainerString *>(v->val); - Config->ValidateIP(vi.GetValue(), v->tag, v->value, allow_wild); - vcs->Set(vi.GetValue()); - break; - } - case DT_STRING: - { - ValueContainerString *vcs = anope_dynamic_static_cast<ValueContainerString *>(v->val); - vcs->Set(vi.GetValue()); - break; - } - case DT_INTEGER: - { - int val = vi.GetInteger(); - ValueContainerInt *vci = anope_dynamic_static_cast<ValueContainerInt *>(v->val); - vci->Set(&val, sizeof(int)); - break; - } - case DT_UINTEGER: - { - unsigned val = vi.GetInteger(); - ValueContainerUInt *vci = anope_dynamic_static_cast<ValueContainerUInt *>(v->val); - vci->Set(&val, sizeof(unsigned)); - break; - } - case DT_LUINTEGER: - { - unsigned long val = vi.GetInteger(); - ValueContainerLUInt *vci = anope_dynamic_static_cast<ValueContainerLUInt *>(v->val); - vci->Set(&val, sizeof(unsigned long)); - break; - } - case DT_TIME: - { - time_t time = Anope::DoTime(vi.GetValue()); - ValueContainerTime *vci = anope_dynamic_static_cast<ValueContainerTime *>(v->val); - vci->Set(&time, sizeof(time_t)); - break; - } - case DT_BOOLEAN: - { - bool val = vi.GetBool(); - ValueContainerBool *vcb = anope_dynamic_static_cast<ValueContainerBool *>(v->val); - vcb->Set(&val, sizeof(bool)); - break; - } - default: - break; - } - } - catch (const ConfigException &ex) - { - source.Reply(_("Error changing configuration value: ") + ex.GetReason()); - return; - } - - ChangeHash(Config->config_data, params[1], params[2], params[3]); - - Log(LOG_ADMIN, source, this) << "to change the configuration value of " << params[1] << ":" << params[2] << " to " << params[3]; - source.Reply(_("Value of %s:%s changed to %s"), params[1].c_str(), params[2].c_str(), params[3].c_str()); - return; - } + source.Reply(_("There is no such configuration block %s."), params[1].c_str()); + return; } - source.Reply("There is no configuration value named %s:%s", params[1].c_str(), params[2].c_str()); + block->Set(params[2], params[3]); + + Log(LOG_ADMIN, source, this) << "to change the configuration value of " << params[1] << ":" << params[2] << " to " << params[3]; + source.Reply(_("Value of %s:%s changed to %s"), params[1].c_str(), params[2].c_str(), params[3].c_str()); } else if (what.equals_ci("VIEW")) { @@ -155,35 +46,30 @@ class CommandOSConfig : public Command const Anope::string show_blocks[] = { "botserv", "chanserv", "defcon", "global", "memoserv", "nickserv", "networkinfo", "operserv", "options", "" }; Log(LOG_ADMIN, source, this) << "VIEW"; - - for (ConfigDataHash::const_iterator it = Config->config_data.begin(), it_end = Config->config_data.end(); it != it_end; ++it) + + for (unsigned i = 0; !show_blocks[i].empty(); ++i) { - const Anope::string &bname = it->first; - const KeyValList &list = it->second; - - bool ok = false; - for (unsigned i = 0; !show_blocks[i].empty(); ++i) - if (bname == show_blocks[i]) - ok = true; - if (ok == false) + Configuration::Block *block = Config->GetBlock(show_blocks[i]); + const Configuration::Block::item_map *items = block->GetItems(); + + if (!items) continue; ListFormatter lflist; lflist.AddColumn("Name").AddColumn("Value"); - for (unsigned i = 0; i < list.size(); ++i) - { - const Anope::string &first = list[i].first, second = list[i].second; + for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it) + { ListFormatter::ListEntry entry; - entry["Name"] = first; - entry["Value"] = second; + entry["Name"] = it->first; + entry["Value"] = it->second; lflist.AddEntry(entry); } std::vector<Anope::string> replies; lflist.Process(replies); - source.Reply(_("%s settings:"), bname.c_str()); + source.Reply(_("%s settings:"), block->GetName().c_str()); for (unsigned i = 0; i < replies.size(); ++i) source.Reply(replies[i]); @@ -193,8 +79,6 @@ class CommandOSConfig : public Command } else this->OnSyntaxError(source, what); - - return; } bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override |