[MOD] Actually start noting down presence requests

This commit is contained in:
LDA 2024-09-18 15:39:52 +02:00
commit 7ee5c055f4
6 changed files with 81 additions and 1 deletions

View 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;
}