mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:55:10 +00:00
[ADD/WIP] VCard4, slightly more PEPwerk
This commit is contained in:
parent
3c495a8a81
commit
ee004ca9c0
10 changed files with 313 additions and 32 deletions
87
src/XMPPThread/PEPs/Avatar.c
Normal file
87
src/XMPPThread/PEPs/Avatar.c
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include "XMPPThread/internal.h"
|
||||
|
||||
#include <Parsee.h>
|
||||
#include <XMPP.h>
|
||||
#include <XML.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Json.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Db.h>
|
||||
|
||||
static XMLElement *
|
||||
CreateAvatarRequest(char *from, char *to, char *avatar_id)
|
||||
{
|
||||
XMLElement *iq_req, *pubsub, *items, *item;
|
||||
char *id;
|
||||
iq_req = XMLCreateTag("iq");
|
||||
XMLAddAttr(iq_req, "from", from);
|
||||
XMLAddAttr(iq_req, "to", to);
|
||||
XMLAddAttr(iq_req, "id", (id = StrRandom(16)));
|
||||
XMLAddAttr(iq_req, "type", "get");
|
||||
|
||||
pubsub = XMLCreateTag("pubsub");
|
||||
XMLAddAttr(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
|
||||
XMLAddChild(iq_req, pubsub);
|
||||
|
||||
items = XMLCreateTag("items");
|
||||
XMLAddAttr(items, "node", "urn:xmpp:avatar:data");
|
||||
XMLAddChild(pubsub, items);
|
||||
|
||||
item = XMLCreateTag("item");
|
||||
XMLAddAttr(item, "id", avatar_id);
|
||||
XMLAddChild(items, item);
|
||||
|
||||
Free(id);
|
||||
return iq_req;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PEPAvatarEvent(PEPManager *m, XMLElement *stanza, XMLElement *item)
|
||||
{
|
||||
XMPPThreadInfo *info = PEPManagerCookie(m);
|
||||
XMPPComponent *jabber = info->jabber;
|
||||
ParseeData *args = info->args;
|
||||
DbRef *avatars;
|
||||
HashMap *json;
|
||||
|
||||
char *publisher = HashMapGet(item->attrs, "publisher");
|
||||
char *id = HashMapGet(item->attrs, "id");
|
||||
char *mxid;
|
||||
|
||||
avatars = DbLock(args->db, 1, "avatars");
|
||||
if (!avatars)
|
||||
{
|
||||
avatars = DbCreate(args->db, 1, "avatars");
|
||||
}
|
||||
json = DbJson(avatars);
|
||||
|
||||
mxid = GrabString(json, 1, publisher);
|
||||
if (mxid && StrEquals(mxid, id))
|
||||
{
|
||||
/* We have nothing to do. */
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* We need to download the media to push it. Let's submit a pubsub request. */
|
||||
{
|
||||
char *from = HashMapGet(stanza->attrs, "to");
|
||||
char *to = HashMapGet(stanza->attrs, "from");
|
||||
char *url = HashMapGet(item->attrs, "url");
|
||||
XMLElement *request = CreateAvatarRequest(from, to, id);
|
||||
|
||||
pthread_mutex_lock(&jabber->write_lock);
|
||||
XMLEncode(jabber->stream, request);
|
||||
StreamFlush(jabber->stream);
|
||||
pthread_mutex_unlock(&jabber->write_lock);
|
||||
|
||||
XMLFreeElement(request);
|
||||
|
||||
(void) url; /* TODO */
|
||||
}
|
||||
|
||||
end:
|
||||
DbUnlock(args->db, avatars);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue