mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 01:55:16 +00:00
[ADD/WIP] Baisic VCards, worst XEP-0393 parser
Blocks coming soon. Took me a day to get a system I remotely liked, and now I feel ashamed of that a bit. It's truly over...
This commit is contained in:
parent
c349b37f60
commit
4007232716
6 changed files with 409 additions and 12 deletions
|
|
@ -17,8 +17,6 @@
|
|||
#include <XML.h>
|
||||
#include <AS.h>
|
||||
|
||||
/* TODO: Rewrite this avatar code.
|
||||
* XEP-0084 sucks. */
|
||||
#define IQ_ADVERT \
|
||||
AdvertiseSimple("http://jabber.org/protocol/chatstates") \
|
||||
AdvertiseSimple("http://jabber.org/protocol/caps") \
|
||||
|
|
@ -42,7 +40,6 @@
|
|||
AdvertiseSimple("urn:parsee:x-parsee:0") \
|
||||
AdvertiseSimple("urn:parsee:jealousy:0")
|
||||
|
||||
/* TODO: More identities */
|
||||
#define IQ_IDENTITY \
|
||||
IdentitySimple("gateway", "matrix", "Parsee Matrix Gateway") \
|
||||
IdentitySimple("client", "pc", NAME " v" VERSION " bridge") \
|
||||
|
|
@ -286,7 +283,11 @@ ParseeVerifyAllStanza(ParseeData *args, XMLElement *stanza)
|
|||
}
|
||||
struct XMPPThread;
|
||||
typedef struct XMPPThreadInfo {
|
||||
/* A FIFO of stanzas */
|
||||
/* A FIFO of stanzas inbound, to be read by dispatcher
|
||||
* threads.
|
||||
*
|
||||
* TODO: Using it's length in !stats can be useful
|
||||
* for having a "congestion" metric for Parsee admins... */
|
||||
Array *stanzas;
|
||||
pthread_mutex_t lock;
|
||||
|
||||
|
|
@ -1022,6 +1023,16 @@ IQResult(ParseeData *args, XMLElement *stanza)
|
|||
}
|
||||
}
|
||||
}
|
||||
static XMLElement *
|
||||
CreateTagWithText(const char *tn, char *text)
|
||||
{
|
||||
XMLElement *tag = XMLCreateTag((char *) tn);
|
||||
XMLElement *tex = XMLCreateText(text);
|
||||
|
||||
XMLAddChild(tag, tex);
|
||||
|
||||
return tag;
|
||||
}
|
||||
static void
|
||||
IQGet(ParseeData *args, XMLElement *stanza)
|
||||
{
|
||||
|
|
@ -1033,6 +1044,44 @@ IQGet(ParseeData *args, XMLElement *stanza)
|
|||
if (XMLookForTKV(stanza, "vCard", "xmlns", "vcard-temp"))
|
||||
{
|
||||
Log(LOG_INFO, "vCard information GET for %s", to);
|
||||
|
||||
/* TODO: "a compliant server MUST respond on behalf of the
|
||||
* requestor and not forward the IQ to the requestee's
|
||||
* connected resource". */
|
||||
if (!strncmp(to, "parsee@", 7))
|
||||
{
|
||||
XMLElement *iqVCard = XMLCreateTag("iq");
|
||||
XMLAddAttr(iqVCard, "from", to);
|
||||
XMLAddAttr(iqVCard, "to", from);
|
||||
XMLAddAttr(iqVCard, "id", id);
|
||||
XMLAddAttr(iqVCard, "type", "result");
|
||||
{
|
||||
XMLElement *vCard = XMLCreateTag("vCard");
|
||||
XMLAddAttr(vCard, "xmlns", "vcard-temp");
|
||||
{
|
||||
XMLElement *fn = CreateTagWithText(
|
||||
"FN", "Parsee Mizuhashi"
|
||||
);
|
||||
XMLElement *nick = CreateTagWithText(
|
||||
"NICKNAME", "Parsee"
|
||||
);
|
||||
XMLElement *url = CreateTagWithText(
|
||||
"URL", REPOSITORY
|
||||
);
|
||||
/* TODO: Maybe abstract the vCard code. */
|
||||
XMLAddChild(vCard, nick);
|
||||
XMLAddChild(vCard, url);
|
||||
XMLAddChild(vCard, fn);
|
||||
}
|
||||
XMLAddChild(iqVCard, vCard);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&jabber->write_lock);
|
||||
XMLEncode(jabber->stream, iqVCard);
|
||||
StreamFlush(jabber->stream);
|
||||
pthread_mutex_unlock(&jabber->write_lock);
|
||||
XMLFreeElement(iqVCard);
|
||||
}
|
||||
}
|
||||
else if (XMLookForTKV(stanza, "query", "xmlns", DISCO))
|
||||
{
|
||||
|
|
@ -1228,7 +1277,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
|
|||
JsonValue *val = JsonValueInteger(power_level);
|
||||
JsonValueFree(JsonSet(users, val, 1, matrix_user_pl));
|
||||
ASSetPL(args->config, room, powers);
|
||||
JsonValueFree(val);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1283,8 +1331,11 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
|
|||
status_str = status_data->data;
|
||||
}
|
||||
|
||||
/* TODO: Verify whenever this code works as soon as I can get
|
||||
* my own instance (kappach.at) with presence enabled. */
|
||||
/* TODO: "The server will automatically set a user's presence to
|
||||
* unavailable if their last active time was over a threshold value
|
||||
* (e.g. 5 minutes)."
|
||||
* We _will_ need to manage those cases properly(cronjob?) if we want
|
||||
* XMPP presences to sync properly */
|
||||
ASSetStatus(
|
||||
args->config, from_matrix,
|
||||
GuessStatus(stanza), status_str
|
||||
|
|
@ -1547,6 +1598,7 @@ ParseeAwaitStanza(char *identifier, int64_t timeout)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Convert into an absolute timeout */
|
||||
if (timeout > 0)
|
||||
{
|
||||
int64_t seconds = timeout / (1 SECONDS);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue