[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

View file

@ -56,7 +56,6 @@ XMPPInitialiseCompStream(char *host, int port)
sd = -1;
continue;
}
Log(LOG_INFO, "Connected to port %s", serv);
break;
}
@ -68,7 +67,6 @@ XMPPInitialiseCompStream(char *host, int port)
freeaddrinfo(res0);
stream = StreamFd(sd);
Log(LOG_INFO, "Got %d via %p", sd, stream);
if (!stream)
{
close(sd);
@ -143,7 +141,7 @@ XMPPAuthenticateCompStream(XMPPComponent *comp, char *shared)
stream_id = StrDuplicate(HashMapGet(ev->attrs, "id"));
handshake = ComputeHandshake(shared, stream_id);
/* y no stream id */
Log(LOG_NOTICE, "- sID='%s'", stream_id);
StreamPrintf(stream, "<handshake>%s</handshake>", handshake);
StreamFlush(stream);

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;
}

View file

@ -2,6 +2,7 @@
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <Cytoplasm/Log.h>
#include <XML.h>
@ -32,11 +33,11 @@ XMPPSendPlain(XMPPComponent *comp, char *fr, char *to, char *msg, char *type)
Free(from);
}
void
XMPPSendPresence(XMPPComponent *comp, char *fr, char *to)
XMPPJoinMUC(XMPPComponent *comp, char *fr, char *muc)
{
XMLElement *presence, *x;
char *from;
if (!comp || !fr || !to)
if (!comp || !fr || !muc)
{
return;
}
@ -44,28 +45,33 @@ XMPPSendPresence(XMPPComponent *comp, char *fr, char *to)
presence = XMLCreateTag("presence");
x = XMLCreateTag("x");
XMLAddAttr(presence, "from", (from = StrConcat(3, fr, "@", comp->host)));
XMLAddAttr(presence, "to", to);
XMLAddAttr(presence, "to", muc);
XMLAddAttr(x, "xmlns", "http://jabber.org/protocol/muc");
XMLAddChild(presence, x);
/* A*/
XMLEncode(comp->stream, presence);
Log(LOG_INFO, "Flushing...");
/* B */
StreamFlush(comp->stream);
XMLFreeElement(presence);
Free(from);
/* How is that leaking */
}
void
XMPPKillThread(XMPPComponent *jabber)
XMPPKillThread(XMPPComponent *jabber, char *killer)
{
XMLElement *message, *body, *data;
char *from;
if (!jabber)
if (!jabber || !killer)
{
return;
}
from = StrConcat(2, "jabber_die@", jabber->host);
from = StrConcat(3, killer, "@", jabber->host);
message = XMLCreateTag("message");
XMLAddAttr(message, "from", from);
XMLAddAttr(message, "to", from);