mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:35:11 +00:00
[MOD] Actually start noting down presence requests
This commit is contained in:
parent
f666f39b7c
commit
7ee5c055f4
6 changed files with 81 additions and 1 deletions
|
|
@ -6,3 +6,4 @@ SOURCE=src
|
||||||
INCLUDES=src/include
|
INCLUDES=src/include
|
||||||
OBJECT=build
|
OBJECT=build
|
||||||
CC=cc
|
CC=cc
|
||||||
|
CFLAGS=-O3
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@ SignalHandler(int signal)
|
||||||
HttpServerStop(server);
|
HttpServerStop(server);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (signal == SIGPIPE)
|
||||||
|
{
|
||||||
|
Log(LOG_DEBUG, "Caught a SIGPIPE...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ IsPubsubRequest(XMLElement *stanza)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log(LOG_INFO, "WOAH");
|
||||||
return XMLookForUnique(pubsub, "subscribe");
|
return XMLookForUnique(pubsub, "subscribe");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
62
src/XMPPThread/PresenceSub.c
Normal file
62
src/XMPPThread/PresenceSub.c
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include "XMPPThread/internal.h"
|
||||||
|
|
||||||
|
static char *
|
||||||
|
SubscriptionHash(ParseeData *data, char *from, char *to)
|
||||||
|
{
|
||||||
|
uint8_t *sum;
|
||||||
|
char *hash;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = strlen(from) + 1 + strlen(to);
|
||||||
|
sum = Malloc(len);
|
||||||
|
memset(sum, 0x00, len);
|
||||||
|
memcpy(sum[0], from, strlen(from)):
|
||||||
|
memcpy(sum[strlen(from) + 1], to, strlen(to));
|
||||||
|
|
||||||
|
hash = ParseeHMAC(data->id, sum, len);
|
||||||
|
Free(sum);
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AddPresenceSubscriber(ParseeData *data, char *from, char *to)
|
||||||
|
{
|
||||||
|
Db *database;
|
||||||
|
DbRef *ref;
|
||||||
|
char *hash;
|
||||||
|
if (!data || !from || !to)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
database = data->db;
|
||||||
|
hash = SubscriptionHash(data, from, to);
|
||||||
|
ref = DbCreate(database, 2, "subscriptions", hash);
|
||||||
|
|
||||||
|
HashMapSet(DbRef(ref), "from", JsonValueString(from));
|
||||||
|
HashMapSet(DbRef(ref), "to", JsonValueString(to));
|
||||||
|
/* I don't think we need more information right now */
|
||||||
|
|
||||||
|
DbClose(database, ref);
|
||||||
|
Free(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
IsSubscribed(ParseeData *data, char *user, char *to)
|
||||||
|
{
|
||||||
|
Db *database;
|
||||||
|
char *hash;
|
||||||
|
bool ret;
|
||||||
|
if (!data || !from || !to)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
database = data->db;
|
||||||
|
hash = SubscriptionHash(data, from, to);
|
||||||
|
ret = DbExists(database, 2, "subscriptions", hash);
|
||||||
|
Free(hash);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
@ -65,6 +65,15 @@ PresenceStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
XMLElement *status = XMLookForUnique(stanza, "status");
|
XMLElement *status = XMLookForUnique(stanza, "status");
|
||||||
|
|
||||||
char *oid = HashMapGet(stanza->attrs, "from");
|
char *oid = HashMapGet(stanza->attrs, "from");
|
||||||
|
char *dst = HashMapGet(stanza->attrs, "to");
|
||||||
|
char *type = HashMapGet(stanza->attrs, "type");
|
||||||
|
|
||||||
|
if (StrEquals(type, "subscribe"))
|
||||||
|
{
|
||||||
|
Log(LOG_WARNING, "!PRESENCE SUBSCRIPTION REQUEST! (%s:%s)", oid, dst);
|
||||||
|
AddPresenceSubscriber(args, oid, dst); /* TODO: Send presence updates
|
||||||
|
* whenever possible. */
|
||||||
|
}
|
||||||
|
|
||||||
if (PEPManagerHandle(thr->info->pep_manager, stanza))
|
if (PEPManagerHandle(thr->info->pep_manager, stanza))
|
||||||
{
|
{
|
||||||
|
|
@ -97,7 +106,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
char *jid = item ? HashMapGet(item->attrs, "jid") : NULL;
|
char *jid = item ? HashMapGet(item->attrs, "jid") : NULL;
|
||||||
char *trim = ParseeTrimJID(jid);
|
char *trim = ParseeTrimJID(jid);
|
||||||
char *from = NULL;
|
char *from = NULL;
|
||||||
char *type = HashMapGet(stanza->attrs, "type");
|
|
||||||
char *room = ParseeGetBridgedRoom(args, stanza);
|
char *room = ParseeGetBridgedRoom(args, stanza);
|
||||||
char *decode_from, *real_matrix;
|
char *decode_from, *real_matrix;
|
||||||
char *matrix_user_pl = ParseeEncodeJID(args->config, trim, false);
|
char *matrix_user_pl = ParseeEncodeJID(args->config, trim, false);
|
||||||
|
|
|
||||||
|
|
@ -97,3 +97,7 @@ void PEPAvatarEvent(PEPManager *m, XMLElement *stanza, XMLElement *item);
|
||||||
void PEPVCardEvent(PEPManager *m, XMLElement *stanza, XMLElement *item);
|
void PEPVCardEvent(PEPManager *m, XMLElement *stanza, XMLElement *item);
|
||||||
|
|
||||||
char * ScrambleOID(ParseeData *data, char *opaque_oid);
|
char * ScrambleOID(ParseeData *data, char *opaque_oid);
|
||||||
|
|
||||||
|
/* Presence management */
|
||||||
|
void AddPresenceSubscriber(ParseeData *data, char *from, char *to);
|
||||||
|
bool IsSubscribed(ParseeData *data, char *user, char *to);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue