summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-03-29 16:17:37 +0200
committerAttila Molnar <attilamolnar@hush.com>2016-03-29 16:17:37 +0200
commitc0514526561e5fde6db765e294c19e0aaee15e1e (patch)
tree6f7031cee8f956a15f2749628c5f166830058cc4 /src/modules/m_spanningtree
parent5d3b755cab8e436bf7ffebaa051cde9d6e2a0997 (diff)
parent4aed5846f17b15939aaf620ee4c4ca95a10609fc (diff)
Merge branch 'master+stroute'
Diffstat (limited to 'src/modules/m_spanningtree')
-rw-r--r--src/modules/m_spanningtree/commandbuilder.h5
-rw-r--r--src/modules/m_spanningtree/postcommand.cpp4
-rw-r--r--src/modules/m_spanningtree/svsjoin.cpp5
-rw-r--r--src/modules/m_spanningtree/svsnick.cpp5
-rw-r--r--src/modules/m_spanningtree/svspart.cpp5
-rw-r--r--src/modules/m_spanningtree/utils.cpp49
-rw-r--r--src/modules/m_spanningtree/utils.h6
7 files changed, 22 insertions, 57 deletions
diff --git a/src/modules/m_spanningtree/commandbuilder.h b/src/modules/m_spanningtree/commandbuilder.h
index 26eb4587f..59de84052 100644
--- a/src/modules/m_spanningtree/commandbuilder.h
+++ b/src/modules/m_spanningtree/commandbuilder.h
@@ -142,11 +142,6 @@ class CmdBuilder
Utils->DoOneToAllButSender(*this, omit);
}
- bool Unicast(const std::string& target) const
- {
- return Utils->DoOneToOne(*this, target);
- }
-
void Unicast(User* target) const
{
Utils->DoOneToOne(*this, target->server);
diff --git a/src/modules/m_spanningtree/postcommand.cpp b/src/modules/m_spanningtree/postcommand.cpp
index ae98be946..7b0478229 100644
--- a/src/modules/m_spanningtree/postcommand.cpp
+++ b/src/modules/m_spanningtree/postcommand.cpp
@@ -51,7 +51,9 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
sdest = static_cast<TreeServer*>(routing.server);
if (!sdest)
{
- sdest = FindServer(routing.serverdest);
+ // Assume the command handler already validated routing.serverdest and have only returned success if the target is something that the
+ // user executing the command is allowed to look up e.g. target is not an uuid if user is local.
+ sdest = FindRouteTarget(routing.serverdest);
if (!sdest)
{
ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Trying to route %s%s to nonexistant server %s", (encap ? "ENCAP " : ""), command.c_str(), routing.serverdest.c_str());
diff --git a/src/modules/m_spanningtree/svsjoin.cpp b/src/modules/m_spanningtree/svsjoin.cpp
index 98443409a..c85e4f412 100644
--- a/src/modules/m_spanningtree/svsjoin.cpp
+++ b/src/modules/m_spanningtree/svsjoin.cpp
@@ -54,8 +54,5 @@ CmdResult CommandSVSJoin::Handle(User* user, std::vector<std::string>& parameter
RouteDescriptor CommandSVSJoin::GetRouting(User* user, const std::vector<std::string>& parameters)
{
- User* u = ServerInstance->FindUUID(parameters[0]);
- if (u)
- return ROUTE_OPT_UCAST(u->server);
- return ROUTE_LOCALONLY;
+ return ROUTE_OPT_UCAST(parameters[0]);
}
diff --git a/src/modules/m_spanningtree/svsnick.cpp b/src/modules/m_spanningtree/svsnick.cpp
index b3a612ca3..84cf8558c 100644
--- a/src/modules/m_spanningtree/svsnick.cpp
+++ b/src/modules/m_spanningtree/svsnick.cpp
@@ -72,8 +72,5 @@ CmdResult CommandSVSNick::Handle(User* user, std::vector<std::string>& parameter
RouteDescriptor CommandSVSNick::GetRouting(User* user, const std::vector<std::string>& parameters)
{
- User* u = ServerInstance->FindNick(parameters[0]);
- if (u)
- return ROUTE_OPT_UCAST(u->server);
- return ROUTE_LOCALONLY;
+ return ROUTE_OPT_UCAST(parameters[0]);
}
diff --git a/src/modules/m_spanningtree/svspart.cpp b/src/modules/m_spanningtree/svspart.cpp
index f86afa367..c4163ef3d 100644
--- a/src/modules/m_spanningtree/svspart.cpp
+++ b/src/modules/m_spanningtree/svspart.cpp
@@ -42,8 +42,5 @@ CmdResult CommandSVSPart::Handle(User* user, std::vector<std::string>& parameter
RouteDescriptor CommandSVSPart::GetRouting(User* user, const std::vector<std::string>& parameters)
{
- User* u = ServerInstance->FindUUID(parameters[0]);
- if (u)
- return ROUTE_OPT_UCAST(u->server);
- return ROUTE_LOCALONLY;
+ return ROUTE_OPT_UCAST(parameters[0]);
}
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index bbda2634d..6de47de94 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -67,32 +67,6 @@ TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
}
}
-/** Returns the locally connected server we must route a
- * message through to reach server 'ServerName'. This
- * only applies to one-to-one and not one-to-many routing.
- * See the comments for the constructor of TreeServer
- * for more details.
- */
-TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
-{
- TreeServer* Found = FindServer(ServerName);
- if (Found)
- {
- return Found->GetRoute();
- }
- else
- {
- // Cheat a bit. This allows for (better) working versions of routing commands with nick based prefixes, without hassle
- User *u = ServerInstance->FindNick(ServerName);
- if (u)
- {
- return TreeServer::Get(u)->GetRoute();
- }
-
- return NULL;
- }
-}
-
/** Find the first server matching a given glob mask.
* We iterate over the list and match each one until we get a hit.
*/
@@ -115,6 +89,19 @@ TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id)
return NULL;
}
+TreeServer* SpanningTreeUtilities::FindRouteTarget(const std::string& target)
+{
+ TreeServer* const server = FindServer(target);
+ if (server)
+ return server;
+
+ User* const user = ServerInstance->FindNick(target);
+ if (user)
+ return TreeServer::Get(user);
+
+ return NULL;
+}
+
SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C)
: Creator(C), TreeRoot(NULL)
, PingFreq(60) // XXX: TreeServer constructor reads this and TreeRoot is created before the config is read, so init it to something (value doesn't matter) to avoid a valgrind warning in TimerManager on unload
@@ -191,16 +178,6 @@ void SpanningTreeUtilities::DoOneToAllButSender(const CmdBuilder& params, TreeSe
}
}
-bool SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, const std::string& target)
-{
- TreeServer* Route = this->BestRouteTo(target);
- if (!Route)
- return false;
-
- DoOneToOne(params, Route);
- return true;
-}
-
void SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, Server* server)
{
TreeServer* ts = static_cast<TreeServer*>(server);
diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h
index 84637bf01..a2f7212f6 100644
--- a/src/modules/m_spanningtree/utils.h
+++ b/src/modules/m_spanningtree/utils.h
@@ -118,7 +118,6 @@ class SpanningTreeUtilities : public classbase
/** Send a message from this server to one other local or remote
*/
- bool DoOneToOne(const CmdBuilder& params, const std::string& target);
void DoOneToOne(const CmdBuilder& params, Server* target);
/** Send a message from this server to all but one other, local or remote
@@ -149,9 +148,10 @@ class SpanningTreeUtilities : public classbase
*/
TreeServer* FindServerID(const std::string &id);
- /** Find a route to a server by name
+ /** Find a server based on a target string.
+ * @param target Target string where a command should be routed to. May be a server name, a sid, a nickname or a uuid.
*/
- TreeServer* BestRouteTo(const std::string &ServerName);
+ TreeServer* FindRouteTarget(const std::string& target);
/** Find a server by glob mask
*/