[ADD] Add a few basic MUC commands

This commit is contained in:
LDA 2024-10-28 08:57:17 +01:00
commit 7f7ab41afa
5 changed files with 70 additions and 14 deletions

View file

@ -387,6 +387,16 @@ IQIsCommandList(ParseeData *args, XMLElement *stanza)
return ret;
}
static bool
IsInMUC(ParseeData *data, char *jid)
{
char *trimmed = ParseeTrimJID(jid);
char *chat_id = ParseeGetFromMUCID(data, trimmed);
Free(trimmed);
Free(chat_id);
return !!chat_id;
}
void
IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
{
@ -401,19 +411,27 @@ IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
if (IQIsCommandList(args, stanza))
{
XMLElement *iq_reply = XMLCreateTag("iq");
char *trimmed = ParseeTrimJID(from);
XMLAddAttr(iq_reply, "type", "result");
XMLAddAttr(iq_reply, "from", to);
XMLAddAttr(iq_reply, "to", from);
XMLAddAttr(iq_reply, "id", id);
{
XMLElement *q = XMLCreateTag("query");
char *parsee_muc_jid = StrConcat(3, trimmed, "/", "parsee");
XMLAddAttr(q, "xmlns", "http://jabber.org/protocol/disco#items");
XMLAddAttr(q, "node", "http://jabber.org/protocol/commands");
XMPPShoveCommandList(thr->info->m, to, q, stanza);
XMPPShoveCommandList(thr->info->m,
IsInMUC(args, from) ? parsee_muc_jid : to,
q, stanza
);
XMLAddChild(iq_reply, q);
Free(parsee_muc_jid);
}
XMPPSendStanza(jabber, iq_reply, args->config->max_stanza_size);
XMLFreeElement(iq_reply);
Free(trimmed);
}
else if (XMLookForTKV(stanza, "vCard", "xmlns", "vcard-temp"))
{