[ADD/WIP] Continue MUCwerk

oh man this is gonna be painful to do... xmpp is fine iff youre doing
DMs isnt it?
This commit is contained in:
LDA 2024-06-21 00:48:27 +02:00
commit d3b7f2fee0
19 changed files with 707 additions and 44 deletions

109
src/XMPP/MUC.c Normal file
View file

@ -0,0 +1,109 @@
#include <XMPP.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Util.h>
#include <Cytoplasm/Str.h>
#include <Cytoplasm/Log.h>
#include <Parsee.h>
#include <XML.h>
bool
XMPPQueryMUC(XMPPComponent *jabber, char *muc, MUCInfo *out)
{
XMLElement *iq_query, *query;
char *uuid, *from;
if (!jabber || !muc)
{
return false;
}
iq_query = XMLCreateTag("iq");
query = XMLCreateTag("query");
XMLAddAttr(iq_query, "from",(from = StrConcat(2,"parsee@",jabber->host)));
XMLAddAttr(iq_query, "to", muc);
XMLAddAttr(iq_query, "id", (uuid = StrRandom(8)));
XMLAddAttr(iq_query, "type", "get");
XMLAddAttr(query, "xmlns", "http://jabber.org/protocol/disco#info");
XMLAddChild(iq_query, query);
Free(from);
Free(uuid);
/* Pause the XMPP thread */
XMPPKillThread(jabber, "suspend");
UtilSleepMillis(500);
{
XMLElement *identity;
/* -- WE ARE ON OUR OWN HERE WITH STANZAS -- */
XMLEncode(jabber->stream, iq_query);
StreamFlush(jabber->stream);
XMLFreeElement(iq_query);
/* Except an IQ reply */
iq_query = XMLDecode(jabber->stream, false);
if (!iq_query || !StrEquals(iq_query->name, "iq"))
{
XMLFreeElement(iq_query);
ParseeWakeupThread();
return false;
}
query = XMLookForUnique(iq_query, "query");
identity = XMLookForUnique(query, "identity");
if (!identity ||
!StrEquals(HashMapGet(identity->attrs, "category"),
"conference"))
{
XMLFreeElement(iq_query);
ParseeWakeupThread();
return false;
}
/* We found a MUC! */
if (out)
{
out->exists = true;
out->jabber = jabber;
out->iq_reply = iq_query;
}
else
{
XMLFreeElement(iq_query);
}
}
/* Wake it up once we're done */
ParseeWakeupThread();
return true;
}
void
XMPPFreeMUCInfo(MUCInfo info)
{
if (!info.exists)
{
return;
}
XMLFreeElement(info.iq_reply);
info.exists = false;
}
char *
XMPPGetMUCName(MUCInfo info)
{
XMLElement *query, *identity;
char *name;
if (!info.exists)
{
return NULL;
}
query = XMLookForUnique(info.iq_reply, "query");
identity = XMLookForUnique(query, "identity");
name = StrDuplicate(HashMapGet(identity->attrs, "name"));
return name;
}