mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 17:05:11 +00:00
[FIX/WIP] Start making Parsee go vroom
This commit is contained in:
parent
c2ea3807ec
commit
dec0d1f3d9
5 changed files with 113 additions and 46 deletions
|
|
@ -28,6 +28,8 @@ system of Parsee.
|
||||||
- Allows MbedTLS through a specific Cytoplasm patch.
|
- Allows MbedTLS through a specific Cytoplasm patch.
|
||||||
- "Lone" XMPP messages no longer render weirdly on Element Android's
|
- "Lone" XMPP messages no longer render weirdly on Element Android's
|
||||||
weird rendering.
|
weird rendering.
|
||||||
|
- Start fixing bug where Parsee takes several seconds to send a
|
||||||
|
message coming from XMPP
|
||||||
#### Deprecated features
|
#### Deprecated features
|
||||||
- The old `build.c` and `Makefile`s used for building are removed,
|
- The old `build.c` and `Makefile`s used for building are removed,
|
||||||
and replaced by the `configure.c` C file(/script via TCC).
|
and replaced by the `configure.c` C file(/script via TCC).
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,8 @@ ParseeCleanup(void *datp)
|
||||||
CleanupField(stanza, 30 MINUTES, 500);
|
CleanupField(stanza, 30 MINUTES, 500);
|
||||||
CleanupField(event, 30 MINUTES, 500);
|
CleanupField(event, 30 MINUTES, 500);
|
||||||
CleanupField(id, 30 MINUTES, 500);
|
CleanupField(id, 30 MINUTES, 500);
|
||||||
|
|
||||||
|
/* TODO: Also cleanup user cache information */
|
||||||
#undef CleanupField
|
#undef CleanupField
|
||||||
}
|
}
|
||||||
DbListFree(chats);
|
DbListFree(chats);
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,6 @@ ParseeGetBridgedUserI(ParseeData *data, XMLElement *stanza, char *force)
|
||||||
{
|
{
|
||||||
ParseePushOIDTable(xmpp_from, occ_id);
|
ParseePushOIDTable(xmpp_from, occ_id);
|
||||||
}
|
}
|
||||||
Log(LOG_DEBUG, "Trying Occ ID for %s{%s}", xmpp_from, occ_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!occ_id)
|
if (!occ_id)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "XMPPThread/internal.h"
|
#include "XMPPThread/internal.h"
|
||||||
|
|
||||||
#include <Cytoplasm/Memory.h>
|
#include <Cytoplasm/Memory.h>
|
||||||
|
#include <Cytoplasm/Util.h>
|
||||||
#include <Cytoplasm/Str.h>
|
#include <Cytoplasm/Str.h>
|
||||||
#include <Cytoplasm/Log.h>
|
#include <Cytoplasm/Log.h>
|
||||||
|
|
||||||
|
|
@ -12,15 +13,58 @@
|
||||||
static void
|
static void
|
||||||
LazyRegister(ParseeData *data, char *mxid, char *name)
|
LazyRegister(ParseeData *data, char *mxid, char *name)
|
||||||
{
|
{
|
||||||
if (!DbExists(data->db, 2, "users", mxid))
|
DbRef *ref;
|
||||||
|
char *hash = ParseeHMACS(data->id, mxid);
|
||||||
|
char *dbname;
|
||||||
|
if (!(ref = DbLock(data->db, 2, "users", hash)))
|
||||||
{
|
{
|
||||||
ASRegisterUser(data->config, mxid);
|
ASRegisterUser(data->config, mxid);
|
||||||
DbUnlock(data->db, DbCreate(data->db, 2, "users", mxid));
|
ref = DbCreate(data->db, 2, "users", hash);
|
||||||
|
HashMapSet(DbJson(ref), "mxid", JsonValueString(mxid));
|
||||||
|
HashMapSet(DbJson(ref), "ts", JsonValueInteger(UtilTsMillis()));
|
||||||
}
|
}
|
||||||
if (name)
|
dbname = GrabString(DbJson(ref), 1, "name");
|
||||||
|
if (name && !StrEquals(dbname, name))
|
||||||
{
|
{
|
||||||
ASSetName(data->config, mxid, name);
|
ASSetName(data->config, mxid, name);
|
||||||
|
HashMapSet(DbJson(ref), "name", JsonValueString(name));
|
||||||
}
|
}
|
||||||
|
DbUnlock(data->db, ref);
|
||||||
|
Free(hash);
|
||||||
|
}
|
||||||
|
static char *
|
||||||
|
LazySend(ParseeData *args, char *mxid, char *mroom_id, char *type, HashMap *ev)
|
||||||
|
{
|
||||||
|
HashMap *duplicate;
|
||||||
|
char *event;
|
||||||
|
if (!args || !mxid || !mroom_id || !ev)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!mroom_id)
|
||||||
|
{
|
||||||
|
mroom_id = "m.room.message";
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicate = JsonDuplicate(ev);
|
||||||
|
event = ASSend(
|
||||||
|
args->config, mroom_id, mxid,
|
||||||
|
"m.room.message",
|
||||||
|
ev
|
||||||
|
);
|
||||||
|
if (event)
|
||||||
|
{
|
||||||
|
JsonFree(duplicate);
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASInvite(args->config, mroom_id, mxid);
|
||||||
|
Free(ASJoin(args->config, mroom_id, mxid));
|
||||||
|
|
||||||
|
return ASSend(
|
||||||
|
args->config, mroom_id, mxid,
|
||||||
|
"m.room.message", duplicate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -79,6 +123,15 @@ ProcessChatstates(ParseeData *args, XMLElement *stanza)
|
||||||
}
|
}
|
||||||
#undef CHAT_STATES
|
#undef CHAT_STATES
|
||||||
}
|
}
|
||||||
|
static float
|
||||||
|
TimeElapsed(uint64_t *rectime, uint64_t v)
|
||||||
|
{
|
||||||
|
uint64_t time = UtilTsMillis();
|
||||||
|
float t = ((time-v)/1000.f);
|
||||||
|
*rectime = time;
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
bool
|
bool
|
||||||
MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
{
|
{
|
||||||
|
|
@ -97,30 +150,30 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
char *type = HashMapGet(stanza->attrs, "type");
|
char *type = HashMapGet(stanza->attrs, "type");
|
||||||
bool chat = StrEquals(type, "chat");
|
bool chat = StrEquals(type, "chat");
|
||||||
size_t i;
|
size_t i;
|
||||||
|
uint64_t time, rectime;
|
||||||
|
#define Elapsed(v) (TimeElapsed(&rectime, v))
|
||||||
|
|
||||||
|
|
||||||
to = NULL;
|
to = NULL;
|
||||||
from = NULL;
|
from = NULL;
|
||||||
decode_from = NULL;
|
decode_from = NULL;
|
||||||
from_matrix = NULL;
|
from_matrix = NULL;
|
||||||
Log(LOG_DEBUG, "<message> usage=%d", MemoryAllocated());
|
Log(LOG_DEBUG, "<message> usage=%d", MemoryAllocated());
|
||||||
|
time = UtilTsMillis();
|
||||||
|
rectime = time;
|
||||||
|
|
||||||
from = HashMapGet(stanza->attrs, "from");
|
from = HashMapGet(stanza->attrs, "from");
|
||||||
if (ParseeManageBan(args, from, NULL))
|
if (ParseeManageBan(args, from, NULL))
|
||||||
{
|
{
|
||||||
XMLFreeElement(stanza);
|
XMLFreeElement(stanza);
|
||||||
Log(LOG_DEBUG, "<message/> usage=%d (%s:%d)", MemoryAllocated(), __FILE__, __LINE__);
|
Log(LOG_DEBUG,
|
||||||
|
"<message/> time=%f "
|
||||||
|
"usage=%d (%s:%d)",
|
||||||
|
Elapsed(time),
|
||||||
|
MemoryAllocated(), __FILE__, __LINE__
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/*{
|
|
||||||
XMLElement *foo = XMLCreateTag("message");
|
|
||||||
XMLElement *body = XMLCreateTag("body");
|
|
||||||
XMLAddAttr(foo, "type", "chat");
|
|
||||||
XMLAddChild(foo, body);
|
|
||||||
XMLAddChild(body, XMLCreateText("Storm on Mt. Ooe (sorry if you see this)"));
|
|
||||||
|
|
||||||
BroadcastStanza(args, HashMapGet(stanza->attrs, "to"), foo);
|
|
||||||
XMLFreeElement(foo);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
if (ServerHasXEP421(args, from))
|
if (ServerHasXEP421(args, from))
|
||||||
|
|
@ -131,14 +184,18 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
);
|
);
|
||||||
char *occ_id = occupant ? HashMapGet(occupant->attrs, "id") : NULL;
|
char *occ_id = occupant ? HashMapGet(occupant->attrs, "id") : NULL;
|
||||||
if (occ_id)
|
if (occ_id)
|
||||||
|
{
|
||||||
|
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
|
||||||
{
|
{
|
||||||
Log(LOG_DEBUG,
|
Log(LOG_DEBUG,
|
||||||
"'%s' has support for XEP-421, fetching OID=%s",
|
"'%s' has support for XEP-421, fetching OID=%s",
|
||||||
from, occ_id
|
from, occ_id
|
||||||
);
|
);
|
||||||
|
}
|
||||||
ParseePushOIDTable(from, occ_id);
|
ParseePushOIDTable(from, occ_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log(LOG_DEBUG, "XEP-421: %fs", Elapsed(rectime));
|
||||||
|
|
||||||
if (StrEquals(type, "error"))
|
if (StrEquals(type, "error"))
|
||||||
{
|
{
|
||||||
|
|
@ -164,9 +221,8 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
|
|
||||||
message = StrConcat(3, type, ": ", text);
|
message = StrConcat(3, type, ": ", text);
|
||||||
room = ParseeGetBridgedRoom(args, stanza);
|
room = ParseeGetBridgedRoom(args, stanza);
|
||||||
Free(ASSend(
|
Free(LazySend(
|
||||||
args->config, room, parsee,
|
args, parsee, room, NULL,
|
||||||
"m.room.message",
|
|
||||||
MatrixCreateNotice(message)
|
MatrixCreateNotice(message)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
@ -176,9 +232,15 @@ end_error:
|
||||||
Free(parsee);
|
Free(parsee);
|
||||||
Free(room);
|
Free(room);
|
||||||
Free(user);
|
Free(user);
|
||||||
Log(LOG_DEBUG, "<message/> usage=%d (%s:%d)", MemoryAllocated(), __FILE__, __LINE__);
|
Log(LOG_DEBUG,
|
||||||
|
"<message/> time=%f "
|
||||||
|
"usage=%d (%s:%d)",
|
||||||
|
Elapsed(time),
|
||||||
|
MemoryAllocated(), __FILE__, __LINE__
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Log(LOG_DEBUG, "Error management: %fs", Elapsed(rectime));
|
||||||
|
|
||||||
if (moderated)
|
if (moderated)
|
||||||
{
|
{
|
||||||
|
|
@ -206,18 +268,22 @@ end_error:
|
||||||
body = XMLookForUnique(stanza, "body");
|
body = XMLookForUnique(stanza, "body");
|
||||||
|
|
||||||
PEPManagerHandle(thr->info->pep_manager, stanza);
|
PEPManagerHandle(thr->info->pep_manager, stanza);
|
||||||
|
Log(LOG_DEBUG, "PEP management: %fs", Elapsed(rectime));
|
||||||
|
|
||||||
ProcessChatstates(args, stanza);
|
ProcessChatstates(args, stanza);
|
||||||
|
Log(LOG_DEBUG, "Chatstate management: %fs", Elapsed(rectime));
|
||||||
|
|
||||||
to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
|
to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
|
||||||
decode_from = ParseeLookupJID(from);
|
decode_from = ParseeLookupJID(from);
|
||||||
from_matrix = ParseeEncodeJID(args->config, decode_from, true);
|
from_matrix = ParseeEncodeJID(args->config, decode_from, true);
|
||||||
room = ParseeFindDMRoom(args, to, from);
|
room = ParseeFindDMRoom(args, to, from);
|
||||||
data = body ? ArrayGet(body->children, 0) : NULL;
|
data = body ? ArrayGet(body->children, 0) : NULL;
|
||||||
|
Log(LOG_DEBUG, "Fetching user info: %fs", Elapsed(rectime));
|
||||||
|
|
||||||
/* TODO: CLEAN THAT UP INTO A CREATEDM FUNCTION */
|
/* TODO: CLEAN THAT UP INTO A CREATEDM FUNCTION */
|
||||||
mroom_id = ParseeGetBridgedRoom(args, stanza);
|
mroom_id = ParseeGetBridgedRoom(args, stanza);
|
||||||
Log(LOG_DEBUG, "Bridging event to '%s'...", mroom_id);
|
Log(LOG_DEBUG, "Bridging event to '%s'...", mroom_id);
|
||||||
|
Log(LOG_DEBUG, "Fetching bridge: %fs", Elapsed(rectime));
|
||||||
if (!mroom_id && !room && !XMPPIsParseeStanza(stanza) &&
|
if (!mroom_id && !room && !XMPPIsParseeStanza(stanza) &&
|
||||||
to && *to == '@')
|
to && *to == '@')
|
||||||
{
|
{
|
||||||
|
|
@ -228,7 +294,7 @@ end_error:
|
||||||
LazyRegister(args, from_matrix, NULL);
|
LazyRegister(args, from_matrix, NULL);
|
||||||
room = ASCreateDM(args->config, from_matrix, to);
|
room = ASCreateDM(args->config, from_matrix, to);
|
||||||
mroom_id = StrDuplicate(room);
|
mroom_id = StrDuplicate(room);
|
||||||
Log(LOG_INFO, "Creating a DM to '%s'(%s)...", to, mroom_id);
|
Log(LOG_DEBUG, "Creating a DM to '%s'(%s)...", to, mroom_id);
|
||||||
if (room)
|
if (room)
|
||||||
{
|
{
|
||||||
room_ref = DbCreate(args->db, 3, "rooms", room, "data");
|
room_ref = DbCreate(args->db, 3, "rooms", room, "data");
|
||||||
|
|
@ -277,6 +343,7 @@ end_error:
|
||||||
StreamFlush(jabber->stream);
|
StreamFlush(jabber->stream);
|
||||||
pthread_mutex_unlock(&jabber->write_lock);
|
pthread_mutex_unlock(&jabber->write_lock);
|
||||||
XMLFreeElement(ps);
|
XMLFreeElement(ps);
|
||||||
|
Log(LOG_DEBUG, "Subscription to XEP-0084: %fs", Elapsed(rectime));
|
||||||
|
|
||||||
Free(parsee);
|
Free(parsee);
|
||||||
Free(trim);
|
Free(trim);
|
||||||
|
|
@ -289,10 +356,7 @@ end_error:
|
||||||
pthread_mutex_unlock(&thr->info->chk_lock);
|
pthread_mutex_unlock(&thr->info->chk_lock);
|
||||||
|
|
||||||
LazyRegister(args, encoded, !chat ? res : NULL);
|
LazyRegister(args, encoded, !chat ? res : NULL);
|
||||||
/* TODO: I don't think we can quite remove that. Maybe
|
Log(LOG_DEBUG, "Matrix registration: %fs", Elapsed(rectime));
|
||||||
* the user was kicked and the bridge is unaware? */
|
|
||||||
ASInvite(args->config, mroom_id, encoded);
|
|
||||||
Free(ASJoin(args->config, mroom_id, encoded));
|
|
||||||
|
|
||||||
reactions = XMLookForTKV(stanza,
|
reactions = XMLookForTKV(stanza,
|
||||||
"reactions", "xmlns", "urn:xmpp:reactions:0"
|
"reactions", "xmlns", "urn:xmpp:reactions:0"
|
||||||
|
|
@ -322,9 +386,9 @@ end_error:
|
||||||
);
|
);
|
||||||
ShoveStanza(content, stanza);
|
ShoveStanza(content, stanza);
|
||||||
|
|
||||||
event_id = ASSend(
|
event_id = LazySend(
|
||||||
args->config, mroom_id, encoded,
|
args, encoded, mroom_id, NULL,
|
||||||
"m.room.message", content
|
content
|
||||||
);
|
);
|
||||||
Free(mxc);
|
Free(mxc);
|
||||||
}
|
}
|
||||||
|
|
@ -364,14 +428,13 @@ end_error:
|
||||||
reaction = ArrayGet(react_child, i);
|
reaction = ArrayGet(react_child, i);
|
||||||
react_data = ArrayGet(reaction->children, 0);
|
react_data = ArrayGet(reaction->children, 0);
|
||||||
|
|
||||||
Free(ASSend(
|
event_id = LazySend(
|
||||||
args->config, mroom_id, encoded,
|
args, encoded, mroom_id, "m.reaction",
|
||||||
"m.reaction",
|
|
||||||
ShoveStanza(
|
ShoveStanza(
|
||||||
MatrixCreateReact(event_id, react_data->data),
|
MatrixCreateReact(event_id, react_data->data),
|
||||||
stanza
|
stanza
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
Free(event_id);
|
Free(event_id);
|
||||||
event_id = NULL;
|
event_id = NULL;
|
||||||
|
|
@ -401,9 +464,9 @@ end_error:
|
||||||
Free(reply_id);
|
Free(reply_id);
|
||||||
}
|
}
|
||||||
ShoveStanza(ev, stanza);
|
ShoveStanza(ev, stanza);
|
||||||
event_id = ASSend(
|
event_id = LazySend(
|
||||||
args->config, mroom_id, encoded,
|
args, encoded, mroom_id, NULL,
|
||||||
"m.room.message", ev
|
ev
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
pthread_mutex_lock(&thr->info->chk_lock);
|
pthread_mutex_lock(&thr->info->chk_lock);
|
||||||
|
|
@ -424,9 +487,9 @@ end_error:
|
||||||
);
|
);
|
||||||
|
|
||||||
Log(LOG_DEBUG, "Replacing events in %s(%s)", mroom_id, event_id);
|
Log(LOG_DEBUG, "Replacing events in %s(%s)", mroom_id, event_id);
|
||||||
Free(ASSend(
|
Free(LazySend(
|
||||||
args->config, mroom_id, encoded,
|
args, encoded, mroom_id, NULL,
|
||||||
"m.room.message", ev
|
ev
|
||||||
));
|
));
|
||||||
ParseePushAllStanza(args, stanza, event_id);
|
ParseePushAllStanza(args, stanza, event_id);
|
||||||
pthread_mutex_unlock(&thr->info->chk_lock);
|
pthread_mutex_unlock(&thr->info->chk_lock);
|
||||||
|
|
@ -459,7 +522,12 @@ end:
|
||||||
Free(decode_from);
|
Free(decode_from);
|
||||||
Free(room);
|
Free(room);
|
||||||
Free(to);
|
Free(to);
|
||||||
Log(LOG_DEBUG, "<message/> usage=%d (%s:%d)", MemoryAllocated(), __FILE__, __LINE__);
|
Log(LOG_DEBUG,
|
||||||
|
"<message/> time=%f "
|
||||||
|
"usage=%d (%s:%d)",
|
||||||
|
(UtilTsMillis()-time)/1000.f,
|
||||||
|
MemoryAllocated(), __FILE__, __LINE__
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,10 +89,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||||
char *occ_id = occupant ? HashMapGet(occupant->attrs, "id") : NULL;
|
char *occ_id = occupant ? HashMapGet(occupant->attrs, "id") : NULL;
|
||||||
if (occ_id)
|
if (occ_id)
|
||||||
{
|
{
|
||||||
Log(LOG_DEBUG,
|
|
||||||
"'%s' has support for XEP-421, fetching OID=%s",
|
|
||||||
oid, occ_id
|
|
||||||
);
|
|
||||||
ParseePushOIDTable(oid, occ_id);
|
ParseePushOIDTable(oid, occ_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue