/*
* InspIRCd -- Internet Relay Chat Daemon
*
- * Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
+ * Copyright (C) 2018-2020 Sadie Powell <sadie@witchery.services>
* Copyright (C) 2015-2016, 2018 Attila Molnar <attilamolnar@hush.com>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
used |= cap->GetMask();
}
- for (unsigned int i = 0; i < MAX_CAPS; i++)
+ for (size_t i = 0; i < MAX_CAPS; i++)
{
- Capability::Bit bit = (1 << i);
+ Capability::Bit bit = (static_cast<Capability::Bit>(1) << i);
if (!(used & bit))
return bit;
}
return true;
}
- void HandleList(std::string& out, LocalUser* user, bool show_all, bool show_values, bool minus_prefix = false) const
+ void HandleList(std::vector<std::string>& out, LocalUser* user, bool show_all, bool show_values, bool minus_prefix = false) const
{
Ext show_caps = (show_all ? ~0 : capext.get(user));
if ((show_all) && (!cap->OnList(user)))
continue;
+ std::string token;
if (minus_prefix)
- out.push_back('-');
- out.append(cap->GetName());
+ token.push_back('-');
+ token.append(cap->GetName());
if (show_values)
{
const std::string* capvalue = cap->GetValue(user);
if ((capvalue) && (!capvalue->empty()) && (capvalue->find(' ') == std::string::npos))
{
- out.push_back('=');
- out.append(*capvalue, 0, MAX_VALUE_LENGTH);
+ token.push_back('=');
+ token.append(*capvalue, 0, MAX_VALUE_LENGTH);
}
}
- out.push_back(' ');
+ out.push_back(token);
}
}
- void HandleClear(LocalUser* user, std::string& result)
+ void HandleClear(LocalUser* user, std::vector<std::string>& result)
{
HandleList(result, user, false, false, true);
capext.unset(user);
return std::string();
// List requested caps
- std::string ret;
- managerimpl->HandleList(ret, user, false, false);
+ std::vector<std::string> result;
+ managerimpl->HandleList(result, user, false, false);
- // Serialize cap protocol version. If building a human-readable string append a new token, otherwise append only a single character indicating the version.
- Cap::Protocol protocol = managerimpl->GetProtocol(user);
+ // Serialize cap protocol version. If building a human-readable string append a
+ // new token, otherwise append only a single character indicating the version.
+ std::string version;
if (human)
- ret.append("capversion=3.");
- else if (!ret.empty())
- ret.erase(ret.length()-1);
-
- if (protocol == Cap::CAP_302)
- ret.push_back('2');
- else
- ret.push_back('1');
+ version.append("capversion=3.");
+ switch (managerimpl->GetProtocol(user))
+ {
+ case Cap::CAP_302:
+ version.push_back('2');
+ break;
+ default:
+ version.push_back('1');
+ break;
+ }
+ result.push_back(version);
- return ret;
+ return stdalgo::string::join(result, ' ');
}
}
class CapMessage : public Cap::MessageBase
{
public:
- CapMessage(LocalUser* user, const std::string& subcmd, const std::string& result)
+ CapMessage(LocalUser* user, const std::string& subcmd, const std::string& result, bool asterisk)
: Cap::MessageBase(subcmd)
{
SetUser(user);
+ if (asterisk)
+ PushParam("*");
PushParamRef(result);
}
};
class CommandCap : public SplitCommand
{
+ private:
Events::ModuleEventProvider evprov;
Cap::ManagerImpl manager;
ClientProtocol::EventProvider protoevprov;
- void DisplayResult(LocalUser* user, const std::string& subcmd, std::string& result)
+ void DisplayResult(LocalUser* user, const std::string& subcmd, std::vector<std::string> result, bool asterisk)
{
- if (*result.rbegin() == ' ')
- result.erase(result.end()-1);
- DisplayResult2(user, subcmd, result);
+ size_t maxline = ServerInstance->Config->Limits.MaxLine - ServerInstance->Config->ServerName.size() - user->nick.length() - subcmd.length() - 11;
+ std::string line;
+ for (std::vector<std::string>::const_iterator iter = result.begin(); iter != result.end(); ++iter)
+ {
+ if (line.length() + iter->length() < maxline)
+ {
+ line.append(*iter);
+ line.push_back(' ');
+ }
+ else
+ {
+ DisplaySingleResult(user, subcmd, line, asterisk);
+ line.clear();
+ }
+ }
+ DisplaySingleResult(user, subcmd, line, false);
}
- void DisplayResult2(LocalUser* user, const std::string& subcmd, const std::string& result)
+ void DisplaySingleResult(LocalUser* user, const std::string& subcmd, const std::string& result, bool asterisk)
{
- CapMessage msg(user, subcmd, result);
+ CapMessage msg(user, subcmd, result, asterisk);
ClientProtocol::Event ev(protoevprov, msg);
user->Send(ev);
}
return CMD_FAILURE;
const std::string replysubcmd = (manager.HandleReq(user, parameters[1]) ? "ACK" : "NAK");
- DisplayResult2(user, replysubcmd, parameters[1]);
+ DisplaySingleResult(user, replysubcmd, parameters[1], false);
}
else if (irc::equals(subcommand, "END"))
{
}
}
- std::string result;
+ std::vector<std::string> result;
// Show values only if supports v3.2 and doing LS
manager.HandleList(result, user, is_ls, ((is_ls) && (capversion != Cap::CAP_LEGACY)));
- DisplayResult(user, subcommand, result);
+ DisplayResult(user, subcommand, result, (capversion != Cap::CAP_LEGACY));
}
else if (irc::equals(subcommand, "CLEAR") && (manager.GetProtocol(user) == Cap::CAP_LEGACY))
{
- std::string result;
+ std::vector<std::string> result;
manager.HandleClear(user, result);
- DisplayResult(user, "ACK", result);
+ DisplayResult(user, "ACK", result, false);
}
else
{
{
private:
CommandCap cmd;
- PoisonCap cap;
+ PoisonCap poisoncap;
+ Cap::Capability stdrplcap;
public:
ModuleCap()
: cmd(this)
- , cap(this)
+ , poisoncap(this)
+ , stdrplcap(this, "inspircd.org/standard-replies")
{
}
Version GetVersion() CXX11_OVERRIDE
{
- return Version("Provides support for CAP capability negotiation", VF_VENDOR);
+ return Version("Implements support for the IRCv3 Client Capability Negotiation extension.", VF_VENDOR);
}
};