From 2df0ebf2dfed1dcbf80c92bff8361e2a04581bec Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 25 Feb 2015 18:35:30 +0100 Subject: Add support for a fixed_irc_server configuration This option lets the administrator choose a specific IRC server, and only that server can be used with this biboumi instance. In this mode, JIDs to use are changed like this: - #chan%irc.example.com@biboumi.example.com -> #chan@biboumi.example.com - user!irc.example.com@biboumi.example.com -> user!@biboumi.example.com - #chan%irc.example.com@biboumi.example.com/Nick -> #chan@biboumi.example.com/Nick - %irc.example.com@biboumi.example.com -> no equivalent - irc.example.com@biboumi.example.com -> no equivalent --- src/irc/iid.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src/irc/iid.cpp') diff --git a/src/irc/iid.cpp b/src/irc/iid.cpp index 0bb991f..d4dc8ce 100644 --- a/src/irc/iid.cpp +++ b/src/irc/iid.cpp @@ -1,10 +1,21 @@ #include +#include #include Iid::Iid(const std::string& iid): is_channel(false), is_user(false) +{ + const std::string fixed_irc_server = Config::get("fixed_irc_server", ""); + if (fixed_irc_server.empty()) + this->init(iid); + else + this->init_with_fixed_server(iid, fixed_irc_server); +} + + +void Iid::init(const std::string& iid) { const std::string::size_type sep = iid.find_first_of("%!"); if (sep != std::string::npos) @@ -20,6 +31,29 @@ Iid::Iid(const std::string& iid): this->set_server(iid); } +void Iid::init_with_fixed_server(const std::string& iid, const std::string& hostname) +{ + this->set_server(hostname); + + const std::string::size_type sep = iid.find_first_of("%!"); + + // Without any separator, we consider that it's a channel + if (sep == std::string::npos) + { + this->is_channel = true; + this->set_local(iid); + } + else // A separator can be present to differenciate a channel from a user, + // but the part behind it (the hostname) is ignored + { + this->set_local(iid.substr(0, sep)); + if (iid[sep] == '%') + this->is_channel = true; + else + this->is_user = true; + } +} + Iid::Iid(const Iid& other): is_channel(other.is_channel), is_user(other.is_user), @@ -66,6 +100,14 @@ std::string Iid::get_sep() const namespace std { const std::string to_string(const Iid& iid) { - return iid.get_local() + iid.get_sep() + iid.get_server(); + if (Config::get("fixed_irc_server", "").empty()) + return iid.get_local() + iid.get_sep() + iid.get_server(); + else + { + if (iid.get_sep() == "!") + return iid.get_local() + iid.get_sep(); + else + return iid.get_local(); + } } } -- cgit v1.2.3