[ADD] Bare JIDs, use room nicks

This commit is contained in:
LDA 2024-06-28 11:09:21 +02:00
commit e21785afcb
8 changed files with 151 additions and 16 deletions

View file

@ -42,7 +42,7 @@ MessageStanza(ParseeData *args, XMLElement *stanza)
XMLElement *body = NULL;
XMLElement *data = NULL;
char *to, *room, *from, *from_matrix;
char *to, *room, *from, *from_matrix, *decode_from;
char *chat_id, *mroom_id;
size_t i;
body = XMLookForUnique(stanza, "body");
@ -54,7 +54,8 @@ MessageStanza(ParseeData *args, XMLElement *stanza)
to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
from = HashMapGet(stanza->attrs, "from");
from_matrix = ParseeEncodeJID(args->config, from, true);
decode_from = ParseeLookupJID(from);
from_matrix = ParseeEncodeJID(args->config, decode_from, true);
room = ParseeFindDMRoom(args, to, from);
data = ArrayGet(body->children, 0);
@ -68,7 +69,7 @@ MessageStanza(ParseeData *args, XMLElement *stanza)
if (mroom_id && !XMPPIsParseeStanza(stanza))
{
char *res = ParseeGetResource(from);
char *encoded = ParseeEncodeJID(args->config, from, false);
char *encoded = ParseeEncodeJID(args->config, decode_from, false);
char *s_id_str = XMPPGetStanzaID(stanza);
char *o_id_str = XMPPGetOriginID(stanza);
char *id_str = HashMapGet(stanza->attrs, "id");
@ -167,6 +168,7 @@ MessageStanza(ParseeData *args, XMLElement *stanza)
Free(chat_id);
Free(mroom_id);
Free(from_matrix);
Free(decode_from);
Free(room);
Free(to);
@ -254,6 +256,29 @@ IQStanza(ParseeData *args, XMLElement *stanza)
#undef OnType
}
static void
PresenceStanza(ParseeData *args, XMLElement *stanza)
{
#define MUC_USER_NS "http://jabber.org/protocol/muc#user"
XMLElement *user_info;
if ((user_info = XMLookForTKV(stanza, "x", "xmlns", MUC_USER_NS)))
{
XMLElement *item = XMLookForUnique(user_info, "item");
char *jid = item ? HashMapGet(item->attrs, "jid") : NULL;
char *oid = HashMapGet(stanza->attrs, "from");
if (jid)
{
ParseePushJIDTable(oid, jid);
}
/* TODO: Make proper mapping in some sort of soft-DB.
* I am saying soft-DB, because this does not need to be
* stored inside the actual database, as we retrieve it at
* startup everytime from the service anyways. */
}
#undef MUC_USER_NS
}
void *
ParseeXMPPThread(void *argp)
{
@ -274,6 +299,7 @@ ParseeXMPPThread(void *argp)
if (StrEquals(stanza->name, "presence"))
{
/* TODO: Manage presence */
PresenceStanza(args, stanza);
XMLFreeElement(stanza);
continue;
}