diff --git a/src/XMPPCommands/Admins.c b/src/XMPPCommands/Admins.c index 1baf789..f126fc4 100644 --- a/src/XMPPCommands/Admins.c +++ b/src/XMPPCommands/Admins.c @@ -21,12 +21,6 @@ AdminsCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement * XMLElement *title; XMLElement *reported, *item, *field, *value, *txt; - if (!ParseeIsAdmin(data, trimmed)) - { - SetNote("error", "User is not authorised to execute command."); - Free(trimmed); - return; - } Free(trimmed); x = XMLCreateTag("x"); title = XMLCreateTag("title"); diff --git a/src/XMPPCommands/MUCInformation.c b/src/XMPPCommands/MUCInformation.c new file mode 100644 index 0000000..53dc684 --- /dev/null +++ b/src/XMPPCommands/MUCInformation.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +void +MUCInformationID(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out) +{ + ParseeData *data = XMPPGetManagerCookie(m); + char *muc = ParseeTrimJID(from); + char *chat_id = ParseeGetFromMUCID(data, muc); + char *room_id = ParseeGetRoomID(data, chat_id); + char *msg = StrConcat(5, + "The MUC ", muc, " is bridged to ", room_id, "." + ); + + SetNote("info", msg); + + Free(muc); + Free(msg); + Free(room_id); + Free(chat_id); + (void) form; +} +void +MUCInformationCID(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out) +{ + ParseeData *data = XMPPGetManagerCookie(m); + char *muc = ParseeTrimJID(from); + char *chat_id = ParseeGetFromMUCID(data, muc); + char *msg = StrConcat(5, + "The MUC ", muc, "'s internal ID is ", chat_id, "." + ); + + SetNote("info", msg); + + Free(muc); + Free(msg); + Free(chat_id); + (void) form; +} diff --git a/src/XMPPCommands/Status.c b/src/XMPPCommands/Status.c index f1a0b73..8e72c98 100644 --- a/src/XMPPCommands/Status.c +++ b/src/XMPPCommands/Status.c @@ -26,13 +26,6 @@ StatusCallback(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement * XMLElement *x; XMLElement *title, *txt; - if (!ParseeIsAdmin(data, trimmed)) - { - SetNote("error", "User is not authorised to execute command."); - - Free(trimmed); - return; - } Free(trimmed); x = XMLCreateTag("x"); title = XMLCreateTag("title"); diff --git a/src/XMPPThread/Stanzas/IQ.c b/src/XMPPThread/Stanzas/IQ.c index e944168..562fc22 100644 --- a/src/XMPPThread/Stanzas/IQ.c +++ b/src/XMPPThread/Stanzas/IQ.c @@ -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")) { diff --git a/src/include/XMPPCommands.x.h b/src/include/XMPPCommands.x.h index 5000a2f..01b27fb 100644 --- a/src/include/XMPPCommands.x.h +++ b/src/include/XMPPCommands.x.h @@ -43,5 +43,7 @@ typedef enum XMPPCommandFlags { XMPPSetFormInstruction(cmd, "Add a server to whitelist"); \ }) \ XMPP_COMMAND(WhitelistCallback, XMPPCMD_ADMINS, "wl", "Get Parsee's chat whitelist", {}) \ + XMPP_COMMAND(MUCInformationID, XMPPCMD_MUC, "muc-info-id", "Get bridged Matrix room ID", {}) \ + XMPP_COMMAND(MUCInformationCID, XMPPCMD_MUC, "muc-info-cid", "Get MUC's internal ID", {}) \ XMPPCOMMANDS