summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-07-19 13:40:07 +0200
committerattilamolnar <attilamolnar@hush.com>2013-08-22 13:42:20 +0200
commit7264a6a8d4360989ca2f64230da07c562d0f34f1 (patch)
treec2916ac67c8b547f234eb67206ccb7ced14e8860
parent67de413cad88194972d55a8ff88464370890c5a9 (diff)
m_spanningtree Add TreeServer::GetChildren() that replaces ChildCount() and GetChild()
-rw-r--r--src/modules/m_spanningtree/main.cpp19
-rw-r--r--src/modules/m_spanningtree/netburst.cpp5
-rw-r--r--src/modules/m_spanningtree/override_map.cpp6
-rw-r--r--src/modules/m_spanningtree/treeserver.cpp26
-rw-r--r--src/modules/m_spanningtree/treeserver.h9
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp5
-rw-r--r--src/modules/m_spanningtree/utils.cpp17
7 files changed, 33 insertions, 54 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 316ed6e96..169a5cd90 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -78,18 +78,21 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
{
Parent = Current->GetParent()->GetName();
}
- for (unsigned int q = 0; q < Current->ChildCount(); q++)
+
+ const TreeServer::ChildServers& children = Current->GetChildren();
+ for (TreeServer::ChildServers::const_iterator i = children.begin(); i != children.end(); ++i)
{
- if ((Current->GetChild(q)->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(Current->GetChild(q)->GetName()))))
+ TreeServer* server = *i;
+ if ((server->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(server->GetName()))))
{
if (user->IsOper())
{
- ShowLinks(Current->GetChild(q),user,hops+1);
+ ShowLinks(server, user, hops+1);
}
}
else
{
- ShowLinks(Current->GetChild(q),user,hops+1);
+ ShowLinks(server, user, hops+1);
}
}
/* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */
@@ -685,11 +688,11 @@ void ModuleSpanningTree::OnUnloadModule(Module* mod)
return;
ServerInstance->PI->SendMetaData(NULL, "modules", "-" + mod->ModuleSourceFile);
- unsigned int items = Utils->TreeRoot->ChildCount();
- for(unsigned int x = 0; x < items; x++)
+ // Close all connections which use an IO hook provided by this module
+ const TreeServer::ChildServers& list = Utils->TreeRoot->GetChildren();
+ for (TreeServer::ChildServers::const_iterator i = list.begin(); i != list.end(); ++i)
{
- TreeServer* srv = Utils->TreeRoot->GetChild(x);
- TreeSocket* sock = srv->GetSocket();
+ TreeSocket* sock = (*i)->GetSocket();
if (sock && sock->GetIOHook() && sock->GetIOHook()->creator == mod)
{
sock->SendError("SSL module unloaded");
diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp
index d86115cce..938585c84 100644
--- a/src/modules/m_spanningtree/netburst.cpp
+++ b/src/modules/m_spanningtree/netburst.cpp
@@ -65,9 +65,10 @@ void TreeSocket::DoBurst(TreeServer* s)
*/
void TreeSocket::SendServers(TreeServer* Current, TreeServer* s)
{
- for (unsigned int q = 0; q < Current->ChildCount(); q++)
+ const TreeServer::ChildServers& children = Current->GetChildren();
+ for (TreeServer::ChildServers::const_iterator i = children.begin(); i != children.end(); ++i)
{
- TreeServer* recursive_server = Current->GetChild(q);
+ TreeServer* recursive_server = *i;
if (recursive_server != s)
{
this->WriteLine(InspIRCd::Format(":%s SERVER %s * 0 %s :%s", Current->GetID().c_str(),
diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp
index 14d0a3b4f..b5da11280 100644
--- a/src/modules/m_spanningtree/override_map.cpp
+++ b/src/modules/m_spanningtree/override_map.cpp
@@ -77,9 +77,11 @@ void CommandMap::ShowMap(TreeServer* Current, User* user, int depth, int &line,
if (user->IsOper() || !Utils->FlatLinks)
depth = depth + 2;
- for (unsigned int q = 0; q < Current->ChildCount(); q++)
+
+ const TreeServer::ChildServers& servers = Current->GetChildren();
+ for (TreeServer::ChildServers::const_iterator i = servers.begin(); i != servers.end(); ++i)
{
- TreeServer* child = Current->GetChild(q);
+ TreeServer* child = *i;
if (!user->IsOper()) {
if (child->Hidden)
continue;
diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp
index 54ea5922f..8af3e777d 100644
--- a/src/modules/m_spanningtree/treeserver.cpp
+++ b/src/modules/m_spanningtree/treeserver.cpp
@@ -119,9 +119,9 @@ void TreeServer::FinishBurstInternal()
this->bursting = false;
SetNextPingTime(ServerInstance->Time() + Utils->PingFreq);
SetPingFlag();
- for(unsigned int q=0; q < ChildCount(); q++)
+ for (ChildServers::const_iterator i = Children.begin(); i != Children.end(); ++i)
{
- TreeServer* child = GetChild(q);
+ TreeServer* child = *i;
child->FinishBurstInternal();
}
}
@@ -229,28 +229,6 @@ void TreeServer::SetVersion(const std::string &Version)
VersionString = Version;
}
-unsigned int TreeServer::ChildCount()
-{
- return Children.size();
-}
-
-TreeServer* TreeServer::GetChild(unsigned int n)
-{
- if (n < Children.size())
- {
- /* Make sure they cant request
- * an out-of-range object. After
- * all we know what these programmer
- * types are like *grin*.
- */
- return Children[n];
- }
- else
- {
- return NULL;
- }
-}
-
void TreeServer::AddChild(TreeServer* Child)
{
Children.push_back(Child);
diff --git a/src/modules/m_spanningtree/treeserver.h b/src/modules/m_spanningtree/treeserver.h
index 9f2e24172..8178c87fa 100644
--- a/src/modules/m_spanningtree/treeserver.h
+++ b/src/modules/m_spanningtree/treeserver.h
@@ -56,6 +56,7 @@ class TreeServer : public classbase
void AddHashEntry();
public:
+ typedef std::vector<TreeServer*> ChildServers;
FakeUser* const ServerUser; /* User representing this server */
const time_t age;
@@ -151,13 +152,9 @@ class TreeServer : public classbase
*/
void SetVersion(const std::string &Version);
- /** Return number of child servers
+ /** Return all child servers
*/
- unsigned int ChildCount();
-
- /** Return a child server indexed 0..n
- */
- TreeServer* GetChild(unsigned int n);
+ const ChildServers& GetChildren() const { return Children; }
/** Add a child server
*/
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 9e0acdd12..ad3a6390d 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -150,9 +150,10 @@ void TreeSocket::SquitServer(std::string &from, TreeServer* Current, int& num_lo
* We're going backwards so we don't remove users
* while we still need them ;)
*/
- for (unsigned int q = 0; q < Current->ChildCount(); q++)
+ const TreeServer::ChildServers& children = Current->GetChildren();
+ for (TreeServer::ChildServers::const_iterator i = children.begin(); i != children.end(); ++i)
{
- TreeServer* recursive_server = Current->GetChild(q);
+ TreeServer* recursive_server = *i;
this->SquitServer(from,recursive_server, num_lost_servers, num_lost_users);
}
/* Now we've whacked the kids, whack self */
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index bd87f2028..f71a9f0d5 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -136,14 +136,11 @@ SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C)
CullResult SpanningTreeUtilities::cull()
{
- while (TreeRoot->ChildCount())
+ const TreeServer::ChildServers& children = TreeRoot->GetChildren();
+ while (!children.empty())
{
- TreeServer* child_server = TreeRoot->GetChild(0);
- if (child_server)
- {
- TreeSocket* sock = child_server->GetSocket();
- sock->Close();
- }
+ TreeSocket* sock = children.front()->GetSocket();
+ sock->Close();
}
for(std::map<TreeSocket*, std::pair<std::string, int> >::iterator i = timeoutlist.begin(); i != timeoutlist.end(); ++i)
@@ -209,10 +206,10 @@ void SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const
{
std::string FullLine = ConstructLine(prefix, command, params);
- unsigned int items = this->TreeRoot->ChildCount();
- for (unsigned int x = 0; x < items; x++)
+ const TreeServer::ChildServers& children = TreeRoot->GetChildren();
+ for (TreeServer::ChildServers::const_iterator i = children.begin(); i != children.end(); ++i)
{
- TreeServer* Route = this->TreeRoot->GetChild(x);
+ TreeServer* Route = *i;
// Send the line if the route isn't the path to the one to be omitted
if (Route != omitroute)
{