[MOD] Verbosity levels, avatar cleanser

I have a weird bug where Parsee seems to hang on a Db request, been
tryign to figure that otu since a while but can't quite put my finger on
where.
You can have this commit, as a treat.
This commit is contained in:
LDA 2024-08-24 19:36:37 +02:00
commit 692cb8aa6f
19 changed files with 190 additions and 111 deletions

View file

@ -120,7 +120,6 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
{
XMLElement *vcard = XMLookForTKV(stanza, "vCard", "xmlns", "vcard-temp");
/* TODO: Move this to PEP */
XMLElement *event = XMLookForTKV(stanza, "pubsub",
"xmlns", "http://jabber.org/protocol/pubsub"
@ -169,12 +168,16 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
DbUnlock(args->db, avatars);
return;
}
JsonValueFree(JsonSet(
json, JsonValueString(id),
1, from
));
DbUnlock(args->db, avatars);
base64 = TrimBase64(data->data);
b64len = base64 ? strlen(base64) : 0;
length = Base64DecodedSize(base64, b64len);
/* TODO: Bound checks for a size limit. */
bdata = (char *) Base64Decode(base64, b64len);
datastream = StrStreamReaderN(bdata, length);
@ -185,12 +188,6 @@ IQResult(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
from_matrix = ParseeGetBridgedUser(args, stanza);
ASSetAvatar(args->config, from_matrix, mxc);
JsonValueFree(JsonSet(
json, JsonValueString(id),
1, from
));
DbUnlock(args->db, avatars);
Free(mxc);
Free(jid);
Free(bdata);

View file

@ -95,7 +95,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
if (!real_matrix || *real_matrix != '@')
{
Free(real_matrix);
/*real_matrix = ParseeEncodeJID(args->config, decode_from, false);*/
real_matrix = ParseeGetBridgedUser(args, stanza);
}
@ -109,8 +108,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
}
else if (StrEquals(affiliation, "member"))
{
/* TODO: Reconsider setting the PL if a member, as there's no
* clear reason to do this in some cases. */
power_level = 0;
}
else if (StrEquals(affiliation, "outcast"))
@ -139,7 +136,7 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
}
/* Set the user's PL
* TODO: Do NOT change the PL of *real* people nilly-willy.
* NOTE: Do NOT change the PL of *real* people nilly-willy.
* In some scenarios, this is really bad behaviour. */
if (room)
{
@ -151,7 +148,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
* lacking any checking. (--gen) */
if (StrEquals(parsee, matrix_user_pl))
{
/* TODO: Give the user an achievement, this is goofy. */
Log(LOG_ERR, "BAD PL DOWNGRADE (%d->%d)", level, power_level);
}
if (users && level != power_level &&
@ -239,6 +235,13 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
{
return;
}
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
{
Log(LOG_DEBUG,
"Looking at VCard in presence from %s",
oid
);
}
avatars = DbLock(args->db, 1, "avatars");
if (!avatars)
@ -246,18 +249,32 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
avatars = DbCreate(args->db, 1, "avatars");
}
json = DbJson(avatars);
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
{
Log(LOG_DEBUG, "VCard: Locked the database!");
}
avatar_id = GrabString(json, 1, oid);
if (avatar_id && StrEquals(avatar_id, p_dat->data))
{
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
{
Log(LOG_DEBUG,
"VCard: %s is already cached for %s", avatar_id, oid
);
}
DbUnlock(args->db, avatars);
return;
}
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
{
Log(LOG_DEBUG, "VCard: %s for %s", p_dat->data, oid);
}
JsonValueFree(JsonSet(
json, JsonValueString(p_dat->data),
1, oid)
);
DbUnlock(args->db, avatars);
from = ParseeJID(args);
@ -273,8 +290,6 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
XMLFreeElement(vcard_request);
Free(from);
}
/* TODO: Sending VCard on presence is slow and stalls the thread */
#undef MUC_USER_NS
}