From 11a2e3c46afca0ad74c02872eb398df30d8bdbb9 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 12:45:02 +0200 Subject: m_spanningtree Remove unused CommandBuilder::Unicast() overload accepting a string --- src/modules/m_spanningtree/commandbuilder.h | 5 ----- 1 file changed, 5 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); -- cgit v1.2.3 From 6c5ac89f35d49833d7075c1449b2d82ddf7926dc Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 12:45:37 +0200 Subject: m_spanningtree Remove unused SpanningTreeUtilities::DoOneToOne() overload accepting a string --- src/modules/m_spanningtree/utils.cpp | 10 ---------- src/modules/m_spanningtree/utils.h | 1 - 2 files changed, 11 deletions(-) diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index bbda2634d..71855305e 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -191,16 +191,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(server); diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 84637bf01..3c54e93ac 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 -- cgit v1.2.3 From 610a74ecea1d4b70f0c7eb3de04b8f7ff27e1fed Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 12:46:12 +0200 Subject: m_spanningtree Remove unused SpanningTreeUtilities::BestRouteTo() --- src/modules/m_spanningtree/utils.cpp | 26 -------------------------- src/modules/m_spanningtree/utils.h | 4 ---- 2 files changed, 30 deletions(-) diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 71855305e..05b77bb62 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. */ diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 3c54e93ac..6d0d094e7 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -148,10 +148,6 @@ class SpanningTreeUtilities : public classbase */ TreeServer* FindServerID(const std::string &id); - /** Find a route to a server by name - */ - TreeServer* BestRouteTo(const std::string &ServerName); - /** Find a server by glob mask */ TreeServer* FindServerMask(const std::string &ServerName); -- cgit v1.2.3 From ea258053f694ff17980e2f39ea182f3a2de9ba5b Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 12:49:25 +0200 Subject: m_spanningtree Add SpanningTreeUtilities::FindRouteTarget() --- src/modules/m_spanningtree/utils.cpp | 13 +++++++++++++ src/modules/m_spanningtree/utils.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 05b77bb62..6de47de94 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -89,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 diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 6d0d094e7..a2f7212f6 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -148,6 +148,11 @@ class SpanningTreeUtilities : public classbase */ TreeServer* FindServerID(const std::string &id); + /** 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* FindRouteTarget(const std::string& target); + /** Find a server by glob mask */ TreeServer* FindServerMask(const std::string &ServerName); -- cgit v1.2.3 From da2b0ee6cad139804442a1ebcd0448755714f22a Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 12:50:00 +0200 Subject: m_spanningtree Use SpanningTreeUtilities::FindRouteTarget() in RouteCommand() This makes ROUTE_UNICAST() accept nicks and uuids --- src/modules/m_spanningtree/postcommand.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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(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()); -- cgit v1.2.3 From 4aed5846f17b15939aaf620ee4c4ca95a10609fc Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Tue, 29 Mar 2016 12:54:02 +0200 Subject: Simplify GetRouting() methods doing unicast --- src/modules/m_chghost.cpp | 5 +---- src/modules/m_chgident.cpp | 5 +---- src/modules/m_chgname.cpp | 5 +---- src/modules/m_nicklock.cpp | 10 ++-------- src/modules/m_sajoin.cpp | 5 +---- src/modules/m_sakick.cpp | 5 +---- src/modules/m_sanick.cpp | 5 +---- src/modules/m_sapart.cpp | 5 +---- src/modules/m_saquit.cpp | 5 +---- src/modules/m_silence.cpp | 5 +---- src/modules/m_spanningtree/svsjoin.cpp | 5 +---- src/modules/m_spanningtree/svsnick.cpp | 5 +---- src/modules/m_spanningtree/svspart.cpp | 5 +---- src/modules/m_uninvite.cpp | 3 +-- 14 files changed, 15 insertions(+), 58 deletions(-) diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp index 163f1f2eb..60146c78b 100644 --- a/src/modules/m_chghost.cpp +++ b/src/modules/m_chghost.cpp @@ -77,10 +77,7 @@ class CommandChghost : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_chgident.cpp b/src/modules/m_chgident.cpp index 0b4e78f12..8ba5b4a5b 100644 --- a/src/modules/m_chgident.cpp +++ b/src/modules/m_chgident.cpp @@ -70,10 +70,7 @@ class CommandChgident : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_chgname.cpp b/src/modules/m_chgname.cpp index 3ad9cede9..2582ef652 100644 --- a/src/modules/m_chgname.cpp +++ b/src/modules/m_chgname.cpp @@ -66,10 +66,7 @@ class CommandChgname : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp index a517e95ac..35845c8d8 100644 --- a/src/modules/m_nicklock.cpp +++ b/src/modules/m_nicklock.cpp @@ -78,10 +78,7 @@ class CommandNicklock : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; @@ -128,10 +125,7 @@ class CommandNickunlock : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_sajoin.cpp b/src/modules/m_sajoin.cpp index cc97c7308..9d87360ec 100644 --- a/src/modules/m_sajoin.cpp +++ b/src/modules/m_sajoin.cpp @@ -103,10 +103,7 @@ class CommandSajoin : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_sakick.cpp b/src/modules/m_sakick.cpp index 8fc6e741b..ab168ca68 100644 --- a/src/modules/m_sakick.cpp +++ b/src/modules/m_sakick.cpp @@ -75,10 +75,7 @@ class CommandSakick : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[1]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[1]); } }; diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp index fd9a825dd..3dc89b4f6 100644 --- a/src/modules/m_sanick.cpp +++ b/src/modules/m_sanick.cpp @@ -79,10 +79,7 @@ class CommandSanick : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_sapart.cpp b/src/modules/m_sapart.cpp index 65c32cd8a..db1e6fdee 100644 --- a/src/modules/m_sapart.cpp +++ b/src/modules/m_sapart.cpp @@ -80,10 +80,7 @@ class CommandSapart : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_saquit.cpp b/src/modules/m_saquit.cpp index 4d5ac6e22..c3895ec12 100644 --- a/src/modules/m_saquit.cpp +++ b/src/modules/m_saquit.cpp @@ -61,10 +61,7 @@ class CommandSaquit : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* dest = ServerInstance->FindNick(parameters[0]); - if (dest) - return ROUTE_OPT_UCAST(dest->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index 7d3b3f90c..0ec40a92f 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -93,10 +93,7 @@ class CommandSVSSilence : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* target = ServerInstance->FindNick(parameters[0]); - if (target) - return ROUTE_OPT_UCAST(target->server); - return ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; 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& parameter RouteDescriptor CommandSVSJoin::GetRouting(User* user, const std::vector& 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& parameter RouteDescriptor CommandSVSNick::GetRouting(User* user, const std::vector& 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& parameter RouteDescriptor CommandSVSPart::GetRouting(User* user, const std::vector& 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_uninvite.cpp b/src/modules/m_uninvite.cpp index 19184751d..d3a424dff 100644 --- a/src/modules/m_uninvite.cpp +++ b/src/modules/m_uninvite.cpp @@ -105,8 +105,7 @@ class CommandUninvite : public Command RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - User* u = ServerInstance->FindNick(parameters[0]); - return u ? ROUTE_OPT_UCAST(u->server) : ROUTE_LOCALONLY; + return ROUTE_OPT_UCAST(parameters[0]); } }; -- cgit v1.2.3