X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_cap.cpp;h=6b4387fdd96ccec55db075d0391be07a6478c02f;hb=d8c72fd7af539cf0a2759740126e020b9ea2eb86;hp=b8abd1b02116d0d5a2e2307ec772ac7953bd460b;hpb=43847ec9c7e1a195163eb4c529f1c92fd1ace0a4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index b8abd1b02..6b4387fdd 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -1,16 +1,23 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2008 Craig Edwards * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. * - * This program is free but copyrighted software; see - * the file COPYING for details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * --------------------------------------------------- + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + #include "inspircd.h" #include "m_cap.h" @@ -34,11 +41,12 @@ CAP END */ class CommandCAP : public Command { - Module* Creator; public: - CommandCAP (InspIRCd* Instance, Module* mod) : Command(Instance,"CAP", 0, 1, true), Creator(mod) + LocalIntExt reghold; + CommandCAP (Module* mod) : Command(mod, "CAP", 1), + reghold("CAP_REGHOLD", mod) { - this->source = "m_cap.so"; + works_before_reg = true; } CmdResult Handle (const std::vector ¶meters, User *user) @@ -47,120 +55,113 @@ class CommandCAP : public Command if (subcommand == "REQ") { - CapData Data; - - Data.type = subcommand; - Data.user = user; - Data.creator = this->Creator; - if (parameters.size() < 2) return CMD_FAILURE; + CapEvent Data(creator, user, CapEvent::CAPEVENT_REQ); + // tokenize the input into a nice list of requested caps - std::string param = parameters[1]; std::string cap_; - irc::spacesepstream cap_stream(param); + irc::spacesepstream cap_stream(parameters[1]); while (cap_stream.GetToken(cap_)) { - Data.wanted.push_back(cap_); + // Whilst the handling of extraneous spaces is not currently defined in the CAP specification + // every single other implementation ignores extraneous spaces. Lets copy them for + // compatibility purposes. + trim(cap_); + if (!cap_.empty()) + Data.wanted.push_back(cap_); } - user->Extend("CAP_REGHOLD"); - Event event((char*) &Data, (Module*)this->Creator, "cap_req"); - event.Send(this->ServerInstance); + reghold.set(user, 1); + Data.Send(); - if (Data.ack.size() > 0) + if (Data.wanted.empty()) { - std::string AckResult = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined(); - user->WriteServ("CAP * ACK :%s", AckResult.c_str()); + user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), parameters[1].c_str()); + return CMD_SUCCESS; } - if (Data.wanted.size() > 0) - { - std::string NakResult = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined(); - user->WriteServ("CAP * NAK :%s", NakResult.c_str()); - } + // HACK: reset all of the caps which were enabled on this user because a cap request is atomic. + for (std::vector >::iterator iter = Data.changed.begin(); iter != Data.changed.end(); ++iter) + iter->first->ext.set(user, iter->second); + + user->WriteServ("CAP %s NAK :%s", user->nick.c_str(), parameters[1].c_str()); } else if (subcommand == "END") { - user->Shrink("CAP_REGHOLD"); + reghold.set(user, 0); } else if ((subcommand == "LS") || (subcommand == "LIST")) { - CapData Data; + CapEvent Data(creator, user, subcommand == "LS" ? CapEvent::CAPEVENT_LS : CapEvent::CAPEVENT_LIST); - Data.type = subcommand; - Data.user = user; - Data.creator = this->Creator; - - user->Extend("CAP_REGHOLD"); - Event event((char*) &Data, (Module*)this->Creator, subcommand == "LS" ? "cap_ls" : "cap_list"); - event.Send(this->ServerInstance); + reghold.set(user, 1); + Data.Send(); std::string Result; if (Data.wanted.size() > 0) Result = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined(); - else - Result = ""; - user->WriteServ("CAP * %s :%s", subcommand.c_str(), Result.c_str()); + user->WriteServ("CAP %s %s :%s", user->nick.c_str(), subcommand.c_str(), Result.c_str()); } else if (subcommand == "CLEAR") { - CapData Data; - - Data.type = subcommand; - Data.user = user; - Data.creator = this->Creator; + CapEvent Data(creator, user, CapEvent::CAPEVENT_CLEAR); - user->Extend("CAP_REGHOLD"); - Event event((char*) &Data, (Module*)this->Creator, "cap_clear"); - event.Send(this->ServerInstance); + reghold.set(user, 1); + Data.Send(); - std::string Result = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined(); - user->WriteServ("CAP * ACK :%s", Result.c_str()); + std::string Result; + if (!Data.ack.empty()) + Result = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined(); + user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), Result.c_str()); } else { - user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "* %s :Invalid CAP subcommand", subcommand.c_str()); + user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "%s %s :Invalid CAP subcommand", user->nick.c_str(), subcommand.c_str()); + return CMD_FAILURE; } - return CMD_FAILURE; + return CMD_SUCCESS; } }; class ModuleCAP : public Module { - CommandCAP* newcommand; + CommandCAP cmd; public: - ModuleCAP(InspIRCd* Me) - : Module(Me) + ModuleCAP() + : cmd(this) + { + } + + void init() { - // Create a new command - newcommand = new CommandCAP(ServerInstance, this); - ServerInstance->AddCommand(newcommand); + ServerInstance->Modules->AddService(cmd); + ServerInstance->Modules->AddService(cmd.reghold); Implementation eventlist[] = { I_OnCheckReady }; - ServerInstance->Modules->Attach(eventlist, this, 1); + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } - virtual bool OnCheckReady(User* user) + ModResult OnCheckReady(LocalUser* user) { /* Users in CAP state get held until CAP END */ - if (user->GetExt("CAP_REGHOLD")) - return false; + if (cmd.reghold.get(user)) + return MOD_RES_DENY; - return true; + return MOD_RES_PASSTHRU; } - virtual ~ModuleCAP() + ~ModuleCAP() { } - virtual Version GetVersion() + Version GetVersion() { - return Version("$Id$", VF_VENDOR, API_VERSION); + return Version("Client CAP extension support", VF_VENDOR); } };