mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:45:11 +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
116
src/XMPPThread/PEPs/VCard.c
Normal file
116
src/XMPPThread/PEPs/VCard.c
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#include "XMPPThread/internal.h"
|
||||
|
||||
#include <Parsee.h>
|
||||
#include <XMPP.h>
|
||||
#include <XML.h>
|
||||
#include <AS.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define AddFieldBase(type) \
|
||||
XMLElement *field, *text, *text_data; \
|
||||
field = XMLCreateTag(name); \
|
||||
text = XMLCreateTag(type); \
|
||||
text_data = XMLCreateText(value); \
|
||||
\
|
||||
XMLAddChild(vcard, field); \
|
||||
XMLAddChild(field, text); \
|
||||
XMLAddChild(text, text_data)
|
||||
static void
|
||||
AddTextField(XMLElement *vcard, char *name, char *value)
|
||||
{
|
||||
AddFieldBase("text");
|
||||
}
|
||||
static void
|
||||
AddURIField(XMLElement *vcard, char *name, char *value)
|
||||
{
|
||||
AddFieldBase("uri");
|
||||
}
|
||||
#undef AddFieldBase
|
||||
|
||||
void
|
||||
PEPVCardEvent(PEPManager *m, XMLElement *stanza, XMLElement *item)
|
||||
{
|
||||
XMPPThreadInfo *info = PEPManagerCookie(m);
|
||||
XMPPComponent *jabber = info->jabber;
|
||||
ParseeData *data = info->args;
|
||||
char *from = HashMapGet(stanza->attrs, "from");
|
||||
char *to = HashMapGet(stanza->attrs, "to");
|
||||
char *id = HashMapGet(stanza->attrs, "id");
|
||||
XMLElement *reply;
|
||||
|
||||
reply = XMLCreateTag("iq");
|
||||
XMLAddAttr(reply, "type", "result");
|
||||
XMLAddAttr(reply, "id", id);
|
||||
XMLAddAttr(reply, "from", to);
|
||||
XMLAddAttr(reply, "to", from);
|
||||
{
|
||||
XMLElement *pubsub, *items, *item;
|
||||
pubsub = XMLCreateTag("pubsub");
|
||||
items = XMLCreateTag("items");
|
||||
item = XMLCreateTag("item");
|
||||
XMLAddChild(reply, pubsub);
|
||||
XMLAddChild(pubsub, items);
|
||||
XMLAddChild(items, item);
|
||||
XMLAddAttr(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
|
||||
XMLAddAttr(items, "node", "urn:xmpp:vcard4");
|
||||
{
|
||||
XMLElement *vcard = XMLCreateTag("vcard");
|
||||
XMLAddAttr(vcard, "xmlns", "urn:ietf:params:xml:ns:vcard-4.0");
|
||||
|
||||
if (!strncmp(to, "parsee", 6))
|
||||
{
|
||||
AddTextField(vcard, "title", "System user");
|
||||
|
||||
AddTextField(vcard, "fn", "Parsee Mizuhashi");
|
||||
AddTextField(vcard, "nickname", "parsee");
|
||||
AddTextField(vcard, "nickname", "that annoying bridge");
|
||||
AddTextField(vcard, "nickname", "green-eyed monster");
|
||||
|
||||
AddURIField(vcard, "url", REPOSITORY);
|
||||
AddURIField(vcard, "url", "https://kappach.at/parsee");
|
||||
|
||||
AddTextField(vcard, "note", "This is the Parsee user account.");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: Get the user's info(over the Matrix profile API if
|
||||
* the server shows support for it.) */
|
||||
char *mxid = ParseeDecodeMXID(to);
|
||||
char *name = ASGetName(data->config, NULL, mxid);
|
||||
char *m_to = ParseeGenerateMTO(mxid);
|
||||
|
||||
AddTextField(vcard, "title", "Matrix user");
|
||||
|
||||
AddTextField(vcard, "fn", name);
|
||||
AddTextField(vcard, "nickname", mxid);
|
||||
|
||||
AddURIField(vcard, "url", REPOSITORY);
|
||||
AddURIField(vcard, "url", "https://kappach.at/parsee");
|
||||
AddURIField(vcard, "url", "https://matrix.org");
|
||||
AddURIField(vcard, "url", m_to);
|
||||
|
||||
AddTextField(
|
||||
vcard,
|
||||
"note",
|
||||
"This is a bridged Matrix user, from Parsee."
|
||||
);
|
||||
Free(mxid);
|
||||
Free(name);
|
||||
Free(m_to);
|
||||
}
|
||||
|
||||
XMLAddChild(item, vcard);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&jabber->write_lock);
|
||||
XMLEncode(jabber->stream, reply);
|
||||
StreamFlush(jabber->stream);
|
||||
pthread_mutex_unlock(&jabber->write_lock);
|
||||
XMLFreeElement(reply);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue