Make it possible for modules to send values in CAP LS

This commit is contained in:
Alexey Sokolov
2023-01-08 15:46:21 +00:00
parent b57d794aaf
commit d49168b93f
3 changed files with 39 additions and 5 deletions
+4 -2
View File
@@ -103,7 +103,7 @@ class CClient : public CIRCSocket {
m_bGotPass(false),
m_bGotNick(false),
m_bGotUser(false),
m_bCap302(false),
m_uCapVersion(0),
m_bInCap(false),
m_bCapNotify(false),
m_bAwayNotify(false),
@@ -182,6 +182,8 @@ class CClient : public CIRCSocket {
CString GetNick(bool bAllowIRCNick = true) const;
CString GetNickMask() const;
CString GetIdentifier() const { return m_sIdentifier; }
unsigned short int CapVersion() const { return m_uCapVersion; }
bool HasCap302() const { return CapVersion() >= 302; }
bool HasCapNotify() const { return m_bCapNotify; }
bool HasAwayNotify() const { return m_bAwayNotify; }
bool HasAccountNotify() const { return m_bAccountNotify; }
@@ -350,7 +352,7 @@ class CClient : public CIRCSocket {
bool m_bGotPass;
bool m_bGotNick;
bool m_bGotUser;
bool m_bCap302;
unsigned short int m_uCapVersion;
bool m_bInCap;
bool m_bCapNotify;
bool m_bAwayNotify;
+3 -3
View File
@@ -706,6 +706,7 @@ void CClient::HandleCap(const CMessage& Message) {
CString sSubCmd = Message.GetParam(0);
if (sSubCmd.Equals("LS")) {
m_uCapVersion = Message.GetParam(1).ToInt();
SCString ssOfferCaps;
for (const auto& it : m_mCoreCaps) {
bool bServerDependent = std::get<0>(it.second);
@@ -716,8 +717,7 @@ void CClient::HandleCap(const CMessage& Message) {
GLOBALMODULECALL(OnClientCapLs(this, ssOfferCaps), NOTHING);
VCString vsCaps = MultiLine(ssOfferCaps);
m_bInCap = true;
if (Message.GetParam(1).ToInt() >= 302) {
m_bCap302 = true;
if (HasCap302()) {
m_bCapNotify = true;
for (int i = 0; i < vsCaps.size() - 1; ++i) {
RespondCap("LS * :" + vsCaps[i]);
@@ -785,7 +785,7 @@ void CClient::HandleCap(const CMessage& Message) {
RespondCap("ACK :" + Message.GetParam(1));
} else if (sSubCmd.Equals("LIST")) {
VCString vsCaps = MultiLine(m_ssAcceptedCaps);
if (m_bCap302) {
if (HasCap302()) {
for (int i = 0; i < vsCaps.size() - 1; ++i) {
RespondCap("LIST * :" + vsCaps[i]);
}
+32
View File
@@ -472,5 +472,37 @@ TEST_F(ZNCTest, CAP302MultiLS) {
ASSERT_GT(rem.indexOf("LS :", w), 1);
}
TEST_F(ZNCTest, CAP302LSValue) {
auto znc = Run();
auto ircd = ConnectIRCd();
auto client = LoginClient();
InstallModule("testmod.cpp", R"(
#include <znc/Client.h>
#include <znc/Modules.h>
class TestModule : public CModule {
public:
MODCONSTRUCTOR(TestModule) {}
void OnClientCapLs(CClient* pClient, SCString& ssCaps) override {
if (pClient->HasCap302()) {
ssCaps.insert("testcap=blah");
} else {
ssCaps.insert("testcap");
}
}
};
GLOBALMODULEDEFS(TestModule, "Test")
)");
client.Write("znc loadmod testmod");
client.ReadUntil("Loaded module testmod");
auto client2 = ConnectClient();
client2.Write("CAP LS");
client2.ReadUntil("testcap ");
client2 = ConnectClient();
client2.Write("CAP LS 302");
client2.ReadUntil("testcap=");
}
} // namespace
} // namespace znc_inttest