mirror of
https://github.com/anope/anope.git
synced 2026-06-12 17:24:49 +02:00
Add Block::GetBlocks which returns an iterable list of blocks.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include "regchannel.h"
|
#include "regchannel.h"
|
||||||
#include "users.h"
|
#include "users.h"
|
||||||
#include "opertype.h"
|
#include "opertype.h"
|
||||||
|
#include "miscutils.h"
|
||||||
|
|
||||||
namespace Configuration
|
namespace Configuration
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,7 @@ namespace Configuration
|
|||||||
public:
|
public:
|
||||||
typedef Anope::map<Anope::string> ItemMap;
|
typedef Anope::map<Anope::string> ItemMap;
|
||||||
typedef Anope::multimap<Block> BlockMap;
|
typedef Anope::multimap<Block> BlockMap;
|
||||||
|
typedef Anope::iterator_range<BlockMap::const_iterator> BlockList;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Anope::string name;
|
Anope::string name;
|
||||||
@@ -42,6 +44,7 @@ namespace Configuration
|
|||||||
Block(const Anope::string &);
|
Block(const Anope::string &);
|
||||||
const Anope::string &GetName() const;
|
const Anope::string &GetName() const;
|
||||||
int CountBlock(const Anope::string &name) const;
|
int CountBlock(const Anope::string &name) const;
|
||||||
|
BlockList GetBlocks(const Anope::string &name) const;
|
||||||
const Block &GetBlock(const Anope::string &name, int num = 0) const;
|
const Block &GetBlock(const Anope::string &name, int num = 0) const;
|
||||||
Block *GetMutableBlock(const Anope::string &name, int num = 0);
|
Block *GetMutableBlock(const Anope::string &name, int num = 0);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
// Anope IRC Services <https://www.anope.org/>
|
||||||
|
//
|
||||||
|
// Copyright (C) 2003-2026 Anope Contributors
|
||||||
|
//
|
||||||
|
// Anope is free software. You can use, modify, and/or distribute it under the
|
||||||
|
// terms of version 2 of the GNU General Public License. See docs/LICENSE.txt
|
||||||
|
// for the complete terms of this license and docs/AUTHORS.txt for a list of
|
||||||
|
// contributors.
|
||||||
|
//
|
||||||
|
// Based on the original code of Epona by Lara
|
||||||
|
// Based on the original code of Services by Andy Church
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace Anope
|
||||||
|
{
|
||||||
|
template <typename Iterator>
|
||||||
|
class iterator_range;
|
||||||
|
|
||||||
|
/** Returns a range containing all elements equivalent to \p value.
|
||||||
|
* @param collection The collection to search within.
|
||||||
|
* @param value The value to search for.
|
||||||
|
*/
|
||||||
|
template <typename Collection, typename Value>
|
||||||
|
auto equal_range(const Collection& collection, const Value& value)
|
||||||
|
{
|
||||||
|
return iterator_range(collection.equal_range(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a range representing a reverse iterator for the specified colleciton.
|
||||||
|
* @param collection The collection to create a reverse iterator for.
|
||||||
|
*/
|
||||||
|
template <typename Collection>
|
||||||
|
auto reverse_range(const Collection& collection)
|
||||||
|
{
|
||||||
|
return iterator_range(collection.rbegin(), collection.rend());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Represents a range of iterators. */
|
||||||
|
template <typename Iterator>
|
||||||
|
class Anope::iterator_range final
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/** An iterator which points to the start of the range. */
|
||||||
|
const Iterator begini;
|
||||||
|
|
||||||
|
/* An iterator which points to one past the end of the range. */
|
||||||
|
const Iterator endi;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** Initialises a new iterator range with the specified iterators.
|
||||||
|
* @param begin An iterator which points to the start of the range.
|
||||||
|
* @param end An iterator which points to one past the end of the range.
|
||||||
|
*/
|
||||||
|
explicit iterator_range(Iterator begin, Iterator end)
|
||||||
|
: begini(begin)
|
||||||
|
, endi(end)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Initialises a new iterator range from a pair of iterators.
|
||||||
|
* @param range A pair of iterators in the format [first, last).
|
||||||
|
*/
|
||||||
|
explicit iterator_range(std::pair<Iterator, Iterator> range)
|
||||||
|
: begini(range.first)
|
||||||
|
, endi(range.second)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Determines whether the iterator range is empty. */
|
||||||
|
bool empty() const { return begini == endi; }
|
||||||
|
|
||||||
|
/** Retrieves an iterator which points to the start of the range. */
|
||||||
|
const Iterator& begin() const { return begini; }
|
||||||
|
|
||||||
|
/** Retrieves an iterator which points to one past the end of the range. */
|
||||||
|
const Iterator& end() const { return endi; }
|
||||||
|
|
||||||
|
/** Retrieves the number of hops within the iterator range. */
|
||||||
|
typename std::iterator_traits<Iterator>::difference_type count() const { return std::distance(begini, endi); }
|
||||||
|
};
|
||||||
@@ -963,10 +963,8 @@ public:
|
|||||||
{
|
{
|
||||||
defaultLevels.clear();
|
defaultLevels.clear();
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("privilege"); ++i)
|
for (const auto &[_, priv] : conf.GetBlocks("privilege"))
|
||||||
{
|
{
|
||||||
const auto &priv = conf.GetBlock("privilege", i);
|
|
||||||
|
|
||||||
const Anope::string &pname = priv.Get<const Anope::string>("name");
|
const Anope::string &pname = priv.Get<const Anope::string>("name");
|
||||||
|
|
||||||
Privilege *p = PrivilegeManager::FindPrivilege(pname);
|
Privilege *p = PrivilegeManager::FindPrivilege(pname);
|
||||||
|
|||||||
@@ -661,10 +661,8 @@ public:
|
|||||||
{
|
{
|
||||||
defaultFlags.clear();
|
defaultFlags.clear();
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("privilege"); ++i)
|
for (const auto &[_, priv] : conf.GetBlocks("privilege"))
|
||||||
{
|
{
|
||||||
const auto &priv = conf.GetBlock("privilege", i);
|
|
||||||
|
|
||||||
const Anope::string &pname = priv.Get<const Anope::string>("name");
|
const Anope::string &pname = priv.Get<const Anope::string>("name");
|
||||||
|
|
||||||
Privilege *p = PrivilegeManager::FindPrivilege(pname);
|
Privilege *p = PrivilegeManager::FindPrivilege(pname);
|
||||||
|
|||||||
@@ -331,10 +331,8 @@ public:
|
|||||||
const auto &block = conf.GetModule(this);
|
const auto &block = conf.GetModule(this);
|
||||||
defaults.clear();
|
defaults.clear();
|
||||||
|
|
||||||
for (int i = 0; i < block.CountBlock("default"); ++i)
|
for (const auto &[_, def] : block.GetBlocks("default"))
|
||||||
{
|
{
|
||||||
const auto &def = block.GetBlock("default", i);
|
|
||||||
|
|
||||||
LogDefault ld;
|
LogDefault ld;
|
||||||
|
|
||||||
ld.service = def.Get<const Anope::string>("service");
|
ld.service = def.Get<const Anope::string>("service");
|
||||||
|
|||||||
@@ -999,10 +999,8 @@ public:
|
|||||||
{
|
{
|
||||||
modes.clear();
|
modes.clear();
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("command"); ++i)
|
for (const auto &[_, block] : conf.GetBlocks("command"))
|
||||||
{
|
{
|
||||||
const auto &block = conf.GetBlock("command", i);
|
|
||||||
|
|
||||||
const Anope::string &cname = block.Get<const Anope::string>("name"),
|
const Anope::string &cname = block.Get<const Anope::string>("name"),
|
||||||
&cmd = block.Get<const Anope::string>("command");
|
&cmd = block.Get<const Anope::string>("command");
|
||||||
|
|
||||||
|
|||||||
@@ -268,9 +268,9 @@ public:
|
|||||||
void OnReload(Configuration::Conf &conf) override
|
void OnReload(Configuration::Conf &conf) override
|
||||||
{
|
{
|
||||||
command_data.clear();
|
command_data.clear();
|
||||||
for (int i = 0; i < conf.CountBlock("command"); ++i)
|
|
||||||
|
for (const auto &[_, block] : conf.GetBlocks("command"))
|
||||||
{
|
{
|
||||||
const auto &block = conf.GetBlock("command", i);
|
|
||||||
if (block.Get<const Anope::string>("command") != "chanserv/set/misc")
|
if (block.Get<const Anope::string>("command") != "chanserv/set/misc")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -688,9 +688,8 @@ public:
|
|||||||
order.clear();
|
order.clear();
|
||||||
permissions.clear();
|
permissions.clear();
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("privilege"); ++i)
|
for (const auto &[_, block] : conf.GetBlocks("privilege"))
|
||||||
{
|
{
|
||||||
const auto &block = conf.GetBlock("privilege", i);
|
|
||||||
const Anope::string &pname = block.Get<const Anope::string>("name");
|
const Anope::string &pname = block.Get<const Anope::string>("name");
|
||||||
|
|
||||||
Privilege *p = PrivilegeManager::FindPrivilege(pname);
|
Privilege *p = PrivilegeManager::FindPrivilege(pname);
|
||||||
@@ -704,9 +703,8 @@ public:
|
|||||||
permissions[xop].push_back(pname);
|
permissions[xop].push_back(pname);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("command"); ++i)
|
for (const auto &[_, block] : conf.GetBlocks("command"))
|
||||||
{
|
{
|
||||||
const auto &block = conf.GetBlock("command", i);
|
|
||||||
const Anope::string &cname = block.Get<const Anope::string>("name"),
|
const Anope::string &cname = block.Get<const Anope::string>("name"),
|
||||||
&cserv = block.Get<const Anope::string>("command");
|
&cserv = block.Get<const Anope::string>("command");
|
||||||
if (cname.empty() || cserv != "chanserv/xop")
|
if (cname.empty() || cserv != "chanserv/xop")
|
||||||
|
|||||||
@@ -1584,9 +1584,8 @@ public:
|
|||||||
const auto &modconf = conf.GetModule(this);
|
const auto &modconf = conf.GetModule(this);
|
||||||
|
|
||||||
csmiscdata.clear();
|
csmiscdata.clear();
|
||||||
for (auto idx = 0; idx < modconf.CountBlock("cs_set_misc"); ++idx)
|
for (const auto &[_, data] : modconf.GetBlocks("cs_set_misc"))
|
||||||
{
|
{
|
||||||
const auto &data = modconf.GetBlock("cs_set_misc", idx);
|
|
||||||
const auto &anope = data.Get<const Anope::string>("anope");
|
const auto &anope = data.Get<const Anope::string>("anope");
|
||||||
const auto &atheme = data.Get<const Anope::string>("atheme");
|
const auto &atheme = data.Get<const Anope::string>("atheme");
|
||||||
if (!anope.empty() && !atheme.empty())
|
if (!anope.empty() && !atheme.empty())
|
||||||
@@ -1594,9 +1593,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsmiscdata.clear();
|
nsmiscdata.clear();
|
||||||
for (auto idx = 0; idx < modconf.CountBlock("ns_set_misc"); ++idx)
|
for (const auto &[_, data] : modconf.GetBlocks("ns_set_misc"))
|
||||||
{
|
{
|
||||||
const auto &data = modconf.GetBlock("ns_set_misc", idx);
|
|
||||||
const auto &anope = data.Get<const Anope::string>("anope");
|
const auto &anope = data.Get<const Anope::string>("anope");
|
||||||
const auto &atheme = data.Get<const Anope::string>("atheme");
|
const auto &atheme = data.Get<const Anope::string>("atheme");
|
||||||
if (!anope.empty() && !atheme.empty())
|
if (!anope.empty() && !atheme.empty())
|
||||||
@@ -1604,9 +1602,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags.clear();
|
flags.clear();
|
||||||
for (int i = 0; i < Config->CountBlock("privilege"); ++i)
|
for (const auto &[_, priv] : conf.GetBlocks("privilege"))
|
||||||
{
|
{
|
||||||
const auto &priv = Config->GetBlock("privilege", i);
|
|
||||||
const Anope::string &name = priv.Get<const Anope::string>("name");
|
const Anope::string &name = priv.Get<const Anope::string>("name");
|
||||||
const Anope::string &value = priv.Get<const Anope::string>("flag");
|
const Anope::string &value = priv.Get<const Anope::string>("flag");
|
||||||
if (!name.empty() && !value.empty())
|
if (!name.empty() && !value.empty())
|
||||||
|
|||||||
+1
-2
@@ -1095,9 +1095,8 @@ public:
|
|||||||
refresh = block.Get<int>("refresh", "3600");
|
refresh = block.Get<int>("refresh", "3600");
|
||||||
|
|
||||||
std::vector<std::pair<Anope::string, short> > notify;
|
std::vector<std::pair<Anope::string, short> > notify;
|
||||||
for (int i = 0; i < block.CountBlock("notify"); ++i)
|
for (const auto &[_, n] : block.GetBlocks("notify"))
|
||||||
{
|
{
|
||||||
const auto &n = block.GetBlock("notify", i);
|
|
||||||
auto nip = n.Get<Anope::string>("ip");
|
auto nip = n.Get<Anope::string>("ip");
|
||||||
auto nport = n.Get<short>("port");
|
auto nport = n.Get<short>("port");
|
||||||
|
|
||||||
|
|||||||
+3
-6
@@ -126,9 +126,8 @@ public:
|
|||||||
this->add_to_akill = block.Get<bool>("add_to_akill", "yes");
|
this->add_to_akill = block.Get<bool>("add_to_akill", "yes");
|
||||||
|
|
||||||
this->blacklists.clear();
|
this->blacklists.clear();
|
||||||
for (int i = 0; i < block.CountBlock("blacklist"); ++i)
|
for (const auto &[_, bl] : block.GetBlocks("blacklist"))
|
||||||
{
|
{
|
||||||
const auto &bl = block.GetBlock("blacklist", i);
|
|
||||||
Blacklist blacklist;
|
Blacklist blacklist;
|
||||||
|
|
||||||
blacklist.name = bl.Get<Anope::string>("name");
|
blacklist.name = bl.Get<Anope::string>("name");
|
||||||
@@ -137,9 +136,8 @@ public:
|
|||||||
blacklist.bantime = bl.Get<time_t>("time", "4h");
|
blacklist.bantime = bl.Get<time_t>("time", "4h");
|
||||||
blacklist.reason = bl.Get<Anope::string>("reason");
|
blacklist.reason = bl.Get<Anope::string>("reason");
|
||||||
|
|
||||||
for (int j = 0; j < bl.CountBlock("reply"); ++j)
|
for (const auto &[_, reply] : block.GetBlocks("reply"))
|
||||||
{
|
{
|
||||||
const auto &reply = bl.GetBlock("reply", j);
|
|
||||||
Blacklist::Reply r;
|
Blacklist::Reply r;
|
||||||
|
|
||||||
r.code = reply.Get<int>("code");
|
r.code = reply.Get<int>("code");
|
||||||
@@ -153,9 +151,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->exempts.clear();
|
this->exempts.clear();
|
||||||
for (int i = 0; i < block.CountBlock("exempt"); ++i)
|
for (const auto &[_, bl] : block.GetBlocks("exempt"))
|
||||||
{
|
{
|
||||||
const auto &bl = block.GetBlock("exempt", i);
|
|
||||||
this->exempts.insert(bl.Get<Anope::string>("ip"));
|
this->exempts.insert(bl.Get<Anope::string>("ip"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -654,10 +654,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("ldap"); ++i)
|
for (const auto &[_, ldap] : conf.GetBlocks("ldap"))
|
||||||
{
|
{
|
||||||
const auto &ldap = conf.GetBlock("ldap", i);
|
|
||||||
|
|
||||||
const Anope::string &connname = ldap.Get<const Anope::string>("name", "ldap/main");
|
const Anope::string &connname = ldap.Get<const Anope::string>("name", "ldap/main");
|
||||||
|
|
||||||
if (this->LDAPServices.find(connname) == this->LDAPServices.end())
|
if (this->LDAPServices.find(connname) == this->LDAPServices.end())
|
||||||
|
|||||||
@@ -298,9 +298,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < config.CountBlock("mysql"); ++i)
|
for (const auto &[_, block] : config.GetBlocks("mysql"))
|
||||||
{
|
{
|
||||||
const auto &block = config.GetBlock("mysql", i);
|
|
||||||
const Anope::string &connname = block.Get<const Anope::string>("name", "mysql/main");
|
const Anope::string &connname = block.Get<const Anope::string>("name", "mysql/main");
|
||||||
|
|
||||||
if (this->MySQLServices.find(connname) == this->MySQLServices.end())
|
if (this->MySQLServices.find(connname) == this->MySQLServices.end())
|
||||||
|
|||||||
@@ -145,9 +145,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < config.CountBlock("sqlite"); ++i)
|
for (const auto &[_, block] : config.GetBlocks("sqlite"))
|
||||||
{
|
{
|
||||||
const auto &block = config.GetBlock("sqlite", i);
|
|
||||||
Anope::string connname = block.Get<const Anope::string>("name", "sqlite/main");
|
Anope::string connname = block.Get<const Anope::string>("name", "sqlite/main");
|
||||||
|
|
||||||
if (this->SQLiteServices.find(connname) == this->SQLiteServices.end())
|
if (this->SQLiteServices.find(connname) == this->SQLiteServices.end())
|
||||||
|
|||||||
@@ -331,10 +331,8 @@ public:
|
|||||||
throw ConfigException("Unable to find http reference, is httpd loaded?");
|
throw ConfigException("Unable to find http reference, is httpd loaded?");
|
||||||
|
|
||||||
xmlrpcinterface.tokens.clear();
|
xmlrpcinterface.tokens.clear();
|
||||||
for (int i = 0; i < modconf.CountBlock("token"); ++i)
|
for (const auto &[_, block] : modconf.GetBlocks("token"))
|
||||||
{
|
{
|
||||||
const auto &block = modconf.GetBlock("token", i);
|
|
||||||
|
|
||||||
RPC::Token token;
|
RPC::Token token;
|
||||||
token.token = block.Get<const Anope::string>("token");
|
token.token = block.Get<const Anope::string>("token");
|
||||||
if (!token.token.empty())
|
if (!token.token.empty())
|
||||||
|
|||||||
+1
-4
@@ -372,11 +372,8 @@ public:
|
|||||||
const auto &conf = config.GetModule(this);
|
const auto &conf = config.GetModule(this);
|
||||||
std::set<Anope::string> existing;
|
std::set<Anope::string> existing;
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("httpd"); ++i)
|
for (const auto &[_, block] : conf.GetBlocks("httpd"))
|
||||||
{
|
{
|
||||||
const auto &block = conf.GetBlock("httpd", i);
|
|
||||||
|
|
||||||
|
|
||||||
const Anope::string &hname = block.Get<const Anope::string>("name", "httpd/main");
|
const Anope::string &hname = block.Get<const Anope::string>("name", "httpd/main");
|
||||||
existing.insert(hname);
|
existing.insert(hname);
|
||||||
|
|
||||||
|
|||||||
@@ -330,9 +330,9 @@ public:
|
|||||||
command_data.clear();
|
command_data.clear();
|
||||||
items_by_priority.clear();
|
items_by_priority.clear();
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("command"); ++i)
|
time_t default_priority = 0;
|
||||||
|
for (const auto &[_, block] : conf.GetBlocks("command"))
|
||||||
{
|
{
|
||||||
const auto &block = conf.GetBlock("command", i);
|
|
||||||
const Anope::string &cmd = block.Get<const Anope::string>("command");
|
const Anope::string &cmd = block.Get<const Anope::string>("command");
|
||||||
if (cmd != "nickserv/set/misc" && cmd != "nickserv/saset/misc")
|
if (cmd != "nickserv/set/misc" && cmd != "nickserv/saset/misc")
|
||||||
continue;
|
continue;
|
||||||
@@ -353,6 +353,8 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default_priority += 1000;
|
||||||
|
|
||||||
data.set_description = desc;
|
data.set_description = desc;
|
||||||
data.pattern = block.Get<const Anope::string>("misc_pattern");
|
data.pattern = block.Get<const Anope::string>("misc_pattern");
|
||||||
data.syntax = block.Get<const Anope::string>("misc_syntax");
|
data.syntax = block.Get<const Anope::string>("misc_syntax");
|
||||||
@@ -361,7 +363,7 @@ public:
|
|||||||
if (data.priority <= 0)
|
if (data.priority <= 0)
|
||||||
{
|
{
|
||||||
// If no priority is specified, go by order processed
|
// If no priority is specified, go by order processed
|
||||||
data.priority = i * 1000;
|
data.priority = default_priority;
|
||||||
}
|
}
|
||||||
data.swhois = block.Get<bool>("misc_swhois");
|
data.swhois = block.Get<bool>("misc_swhois");
|
||||||
items_by_priority.emplace_back(data.priority, item);
|
items_by_priority.emplace_back(data.priority, item);
|
||||||
|
|||||||
@@ -84,9 +84,8 @@ public:
|
|||||||
lflist.AddColumn(_("Module Name")).AddColumn(_("Name")).AddColumn(_("Value"));
|
lflist.AddColumn(_("Module Name")).AddColumn(_("Name")).AddColumn(_("Value"));
|
||||||
lflist.SetFlexible(_("\002{}{module_name}}:{name}\002 = {value}"));
|
lflist.SetFlexible(_("\002{}{module_name}}:{name}\002 = {value}"));
|
||||||
|
|
||||||
for (int i = 0; i < Config->CountBlock("module"); ++i)
|
for (const auto &[_, block] : Config->GetBlocks("module"))
|
||||||
{
|
{
|
||||||
const auto &block = Config->GetBlock("module", i);
|
|
||||||
const auto &items = block.GetItems();
|
const auto &items = block.GetItems();
|
||||||
|
|
||||||
if (items.size() <= 1)
|
if (items.size() <= 1)
|
||||||
|
|||||||
@@ -529,10 +529,8 @@ public:
|
|||||||
fileforbids.clear();
|
fileforbids.clear();
|
||||||
|
|
||||||
const auto &modconf = conf.GetModule(this);
|
const auto &modconf = conf.GetModule(this);
|
||||||
for (auto i = 0; i < modconf.CountBlock("file"); ++i)
|
for (const auto &[_, fileblock] : modconf.GetBlocks("file"))
|
||||||
{
|
{
|
||||||
const auto &fileblock = modconf.GetBlock("file", i);
|
|
||||||
|
|
||||||
const auto reasonstr = fileblock.Get<const Anope::string>("reason");
|
const auto reasonstr = fileblock.Get<const Anope::string>("reason");
|
||||||
|
|
||||||
const auto typestr = fileblock.Get<const Anope::string>("type");
|
const auto typestr = fileblock.Get<const Anope::string>("type");
|
||||||
|
|||||||
@@ -309,9 +309,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->proxyscans.clear();
|
this->proxyscans.clear();
|
||||||
for (int i = 0; i < config.CountBlock("proxyscan"); ++i)
|
|
||||||
|
for (const auto &[_, block] : config.GetBlocks("proxyscan"))
|
||||||
{
|
{
|
||||||
const auto &block = config.GetBlock("proxyscan", i);
|
|
||||||
ProxyCheck p;
|
ProxyCheck p;
|
||||||
Anope::string token;
|
Anope::string token;
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -173,10 +173,8 @@ public:
|
|||||||
{
|
{
|
||||||
Rewrite::rewrites.clear();
|
Rewrite::rewrites.clear();
|
||||||
|
|
||||||
for (int i = 0; i < conf.CountBlock("command"); ++i)
|
for (const auto &[_, block] : conf.GetBlocks("command"))
|
||||||
{
|
{
|
||||||
const auto &block = conf.GetBlock("command", i);
|
|
||||||
|
|
||||||
if (!block.Get<bool>("rewrite"))
|
if (!block.Get<bool>("rewrite"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -313,10 +313,9 @@ public:
|
|||||||
throw ConfigException("Unable to find http reference, is httpd loaded?");
|
throw ConfigException("Unable to find http reference, is httpd loaded?");
|
||||||
|
|
||||||
jsonrpcinterface.tokens.clear();
|
jsonrpcinterface.tokens.clear();
|
||||||
for (int i = 0; i < modconf.CountBlock("token"); ++i)
|
|
||||||
{
|
|
||||||
const auto &block = modconf.GetBlock("token", i);
|
|
||||||
|
|
||||||
|
for (const auto &[_, block] : modconf.GetBlocks("token"))
|
||||||
|
{
|
||||||
RPC::Token token;
|
RPC::Token token;
|
||||||
token.token = block.Get<const Anope::string>("token");
|
token.token = block.Get<const Anope::string>("token");
|
||||||
if (!token.token.empty())
|
if (!token.token.empty())
|
||||||
|
|||||||
+18
-35
@@ -43,6 +43,11 @@ int Configuration::Block::CountBlock(const Anope::string &bname) const
|
|||||||
return blocks.count(bname);
|
return blocks.count(bname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Configuration::Block::BlockList Configuration::Block::GetBlocks(const Anope::string &bname) const
|
||||||
|
{
|
||||||
|
return Anope::equal_range(blocks, bname);
|
||||||
|
}
|
||||||
|
|
||||||
const Configuration::Block &Configuration::Block::GetBlock(const Anope::string &bname, int num) const
|
const Configuration::Block &Configuration::Block::GetBlock(const Anope::string &bname, int num) const
|
||||||
{
|
{
|
||||||
auto it = blocks.equal_range(bname);
|
auto it = blocks.equal_range(bname);
|
||||||
@@ -125,10 +130,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
|
|
||||||
this->LoadConf(ServicesConf);
|
this->LoadConf(ServicesConf);
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("include"); ++i)
|
for (const auto &[_, include] : this->GetBlocks("include"))
|
||||||
{
|
{
|
||||||
const auto &include = this->GetBlock("include", i);
|
|
||||||
|
|
||||||
const Anope::string &type = include.Get<const Anope::string>("type"),
|
const Anope::string &type = include.Get<const Anope::string>("type"),
|
||||||
&file = include.Get<const Anope::string>("name");
|
&file = include.Get<const Anope::string>("name");
|
||||||
|
|
||||||
@@ -205,10 +208,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
this->TimeoutCheck = options.Get<time_t>("timeoutcheck");
|
this->TimeoutCheck = options.Get<time_t>("timeoutcheck");
|
||||||
this->NickChars = networkinfo.Get<Anope::string>("nick_chars");
|
this->NickChars = networkinfo.Get<Anope::string>("nick_chars");
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("uplink"); ++i)
|
for (const auto &[_, uplink] : this->GetBlocks("uplink"))
|
||||||
{
|
{
|
||||||
const auto &uplink = this->GetBlock("uplink", i);
|
|
||||||
|
|
||||||
int protocol;
|
int protocol;
|
||||||
const Anope::string &protocolstr = uplink.Get<const Anope::string>("protocol", "ipv4");
|
const Anope::string &protocolstr = uplink.Get<const Anope::string>("protocol", "ipv4");
|
||||||
if (protocolstr == "ipv4")
|
if (protocolstr == "ipv4")
|
||||||
@@ -238,10 +239,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
this->Uplinks.emplace_back(host, port, password, protocol);
|
this->Uplinks.emplace_back(host, port, password, protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("module"); ++i)
|
for (const auto &[_, module] : this->GetBlocks("module"))
|
||||||
{
|
{
|
||||||
const auto &module = this->GetBlock("module", i);
|
|
||||||
|
|
||||||
const Anope::string &modname = module.Get<const Anope::string>("name");
|
const Anope::string &modname = module.Get<const Anope::string>("name");
|
||||||
|
|
||||||
ValidateNotEmptyOrSpaces("module", "name", modname);
|
ValidateNotEmptyOrSpaces("module", "name", modname);
|
||||||
@@ -249,10 +248,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
this->ModulesAutoLoad.push_back(modname);
|
this->ModulesAutoLoad.push_back(modname);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("opertype"); ++i)
|
for (const auto &[_, opertype] : this->GetBlocks("opertype"))
|
||||||
{
|
{
|
||||||
const auto &opertype = this->GetBlock("opertype", i);
|
|
||||||
|
|
||||||
const Anope::string &oname = opertype.Get<const Anope::string>("name"),
|
const Anope::string &oname = opertype.Get<const Anope::string>("name"),
|
||||||
&modes = opertype.Get<const Anope::string>("modes"),
|
&modes = opertype.Get<const Anope::string>("modes"),
|
||||||
&inherits = opertype.Get<const Anope::string>("inherits"),
|
&inherits = opertype.Get<const Anope::string>("inherits"),
|
||||||
@@ -292,10 +289,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
this->MyOperTypes.push_back(ot);
|
this->MyOperTypes.push_back(ot);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("oper"); ++i)
|
for (const auto &[_, oper] : this->GetBlocks("oper"))
|
||||||
{
|
{
|
||||||
const auto &oper = this->GetBlock("oper", i);
|
|
||||||
|
|
||||||
const Anope::string &nname = oper.Get<const Anope::string>("name"),
|
const Anope::string &nname = oper.Get<const Anope::string>("name"),
|
||||||
&type = oper.Get<const Anope::string>("type"),
|
&type = oper.Get<const Anope::string>("type"),
|
||||||
&password = oper.Get<const Anope::string>("password"),
|
&password = oper.Get<const Anope::string>("password"),
|
||||||
@@ -330,10 +325,9 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
|
|
||||||
for (const auto &[_, bi] : *BotListByNick)
|
for (const auto &[_, bi] : *BotListByNick)
|
||||||
bi->conf = false;
|
bi->conf = false;
|
||||||
for (int i = 0; i < this->CountBlock("service"); ++i)
|
|
||||||
{
|
|
||||||
const auto &service = this->GetBlock("service", i);
|
|
||||||
|
|
||||||
|
for (const auto &[_, service] : this->GetBlocks("service"))
|
||||||
|
{
|
||||||
const Anope::string &nick = service.Get<const Anope::string>("nick"),
|
const Anope::string &nick = service.Get<const Anope::string>("nick"),
|
||||||
&user = service.Get<const Anope::string>("user", nick.lower()),
|
&user = service.Get<const Anope::string>("user", nick.lower()),
|
||||||
&host = service.Get<const Anope::string>("host", servername),
|
&host = service.Get<const Anope::string>("host", servername),
|
||||||
@@ -421,10 +415,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("log"); ++i)
|
for (const auto &[_, log] : this->GetBlocks("log"))
|
||||||
{
|
{
|
||||||
const auto &log = this->GetBlock("log", i);
|
|
||||||
|
|
||||||
int logage = log.Get<int>("logage");
|
int logage = log.Get<int>("logage");
|
||||||
bool rawio = log.Get<bool>("rawio");
|
bool rawio = log.Get<bool>("rawio");
|
||||||
bool debug = log.Get<bool>("debug");
|
bool debug = log.Get<bool>("debug");
|
||||||
@@ -447,10 +439,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
|
|
||||||
for (const auto &[_, bi] : *BotListByNick)
|
for (const auto &[_, bi] : *BotListByNick)
|
||||||
bi->commands.clear();
|
bi->commands.clear();
|
||||||
for (int i = 0; i < this->CountBlock("command"); ++i)
|
for (const auto &[_, command] : this->GetBlocks("command"))
|
||||||
{
|
{
|
||||||
const auto &command = this->GetBlock("command", i);
|
|
||||||
|
|
||||||
const Anope::string &service = command.Get<const Anope::string>("service"),
|
const Anope::string &service = command.Get<const Anope::string>("service"),
|
||||||
&nname = command.Get<const Anope::string>("name"),
|
&nname = command.Get<const Anope::string>("name"),
|
||||||
&cmd = command.Get<const Anope::string>("command"),
|
&cmd = command.Get<const Anope::string>("command"),
|
||||||
@@ -472,10 +462,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
}
|
}
|
||||||
|
|
||||||
PrivilegeManager::ClearPrivileges();
|
PrivilegeManager::ClearPrivileges();
|
||||||
for (int i = 0; i < this->CountBlock("privilege"); ++i)
|
for (const auto &[_, privilege] : this->GetBlocks("privilege"))
|
||||||
{
|
{
|
||||||
const auto &privilege = this->GetBlock("privilege", i);
|
|
||||||
|
|
||||||
const Anope::string &nname = privilege.Get<const Anope::string>("name"),
|
const Anope::string &nname = privilege.Get<const Anope::string>("name"),
|
||||||
&desc = privilege.Get<const Anope::string>("desc");
|
&desc = privilege.Get<const Anope::string>("desc");
|
||||||
int rank = privilege.Get<int>("rank");
|
int rank = privilege.Get<int>("rank");
|
||||||
@@ -483,10 +471,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
PrivilegeManager::AddPrivilege(Privilege(nname, desc, rank));
|
PrivilegeManager::AddPrivilege(Privilege(nname, desc, rank));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("fantasy"); ++i)
|
for (const auto &[_, fantasy] : this->GetBlocks("fantasy"))
|
||||||
{
|
{
|
||||||
const auto &fantasy = this->GetBlock("fantasy", i);
|
|
||||||
|
|
||||||
const Anope::string &nname = fantasy.Get<const Anope::string>("name"),
|
const Anope::string &nname = fantasy.Get<const Anope::string>("name"),
|
||||||
&service = fantasy.Get<const Anope::string>("command"),
|
&service = fantasy.Get<const Anope::string>("command"),
|
||||||
&permission = fantasy.Get<const Anope::string>("permission"),
|
&permission = fantasy.Get<const Anope::string>("permission"),
|
||||||
@@ -504,10 +490,8 @@ Configuration::Conf::Conf() : Configuration::Block("")
|
|||||||
c.require_privilege = fantasy.Get<bool>("require_privilege", "yes");
|
c.require_privilege = fantasy.Get<bool>("require_privilege", "yes");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < this->CountBlock("command_group"); ++i)
|
for (const auto &[_, command_group] : this->GetBlocks("command_group"))
|
||||||
{
|
{
|
||||||
const auto &command_group = this->GetBlock("command_group", i);
|
|
||||||
|
|
||||||
const Anope::string &nname = command_group.Get<const Anope::string>("name"),
|
const Anope::string &nname = command_group.Get<const Anope::string>("name"),
|
||||||
&description = command_group.Get<const Anope::string>("description");
|
&description = command_group.Get<const Anope::string>("description");
|
||||||
|
|
||||||
@@ -1020,9 +1004,8 @@ Anope::string Configuration::Conf::ReplaceVars(const Anope::string &str, const C
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto found = false;
|
auto found = false;
|
||||||
for (int i = 0; i < this->CountBlock("define"); ++i)
|
for (const auto &[_, define] : this->GetBlocks("define"))
|
||||||
{
|
{
|
||||||
const auto &define = this->GetBlock("define", i);
|
|
||||||
const auto defname = define.Get<const Anope::string>("name");
|
const auto defname = define.Get<const Anope::string>("name");
|
||||||
if (defname == var)
|
if (defname == var)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -537,8 +537,8 @@ bool Anope::Init(int ac, char **av)
|
|||||||
|
|
||||||
/* load modules */
|
/* load modules */
|
||||||
Log() << "Loading modules...";
|
Log() << "Loading modules...";
|
||||||
for (int i = 0; i < Config->CountBlock("module"); ++i)
|
for (const auto &[_, block] : Config->GetBlocks("module"))
|
||||||
ModuleManager::LoadModule(Config->GetBlock("module", i).Get<const Anope::string>("name"), NULL);
|
ModuleManager::LoadModule(block.Get<const Anope::string>("name"), NULL);
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
/* If we're root, issue a warning now */
|
/* If we're root, issue a warning now */
|
||||||
|
|||||||
Reference in New Issue
Block a user