mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-14 01:55:16 +00:00
[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:
parent
3a60b773c9
commit
692cb8aa6f
19 changed files with 190 additions and 111 deletions
|
|
@ -118,7 +118,6 @@ ParseeVerifyAllStanza(ParseeData *args, XMLElement *stanza)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* TODO: Cache this information. */
|
||||
bool
|
||||
ServerHasXEP421(ParseeData *data, char *from)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,33 @@
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <XMPP.h>
|
||||
#include <XML.h>
|
||||
|
||||
XMLElement *
|
||||
CreatePubsubRequest(char *from, char *to, char *node)
|
||||
{
|
||||
XMLElement *iq_req, *pubsub, *sub;
|
||||
char *id;
|
||||
iq_req = XMLCreateTag("iq");
|
||||
XMLAddAttr(iq_req, "from", from);
|
||||
XMLAddAttr(iq_req, "to", to);
|
||||
XMLAddAttr(iq_req, "id", (id = StrRandom(16)));
|
||||
XMLAddAttr(iq_req, "type", "set");
|
||||
|
||||
pubsub = XMLCreateTag("pubsub");
|
||||
XMLAddAttr(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
|
||||
XMLAddChild(iq_req, pubsub);
|
||||
|
||||
sub = XMLCreateTag("subscribe");
|
||||
XMLAddAttr(sub, "node", node);
|
||||
XMLAddAttr(sub, "jid", from);
|
||||
XMLAddChild(pubsub, sub);
|
||||
|
||||
Free(id);
|
||||
return iq_req;
|
||||
}
|
||||
|
||||
struct PEPManager {
|
||||
pthread_mutex_t lock;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
#include "XMPPThread/internal.h"
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <XMPP.h>
|
||||
#include <XML.h>
|
||||
|
||||
/* TODO: This should be in PEP.c */
|
||||
XMLElement *
|
||||
CreatePubsubRequest(char *from, char *to, char *node)
|
||||
{
|
||||
XMLElement *iq_req, *pubsub, *sub;
|
||||
char *id;
|
||||
iq_req = XMLCreateTag("iq");
|
||||
XMLAddAttr(iq_req, "from", from);
|
||||
XMLAddAttr(iq_req, "to", to);
|
||||
XMLAddAttr(iq_req, "id", (id = StrRandom(16)));
|
||||
XMLAddAttr(iq_req, "type", "set");
|
||||
|
||||
pubsub = XMLCreateTag("pubsub");
|
||||
XMLAddAttr(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
|
||||
XMLAddChild(iq_req, pubsub);
|
||||
|
||||
sub = XMLCreateTag("subscribe");
|
||||
XMLAddAttr(sub, "node", node);
|
||||
XMLAddAttr(sub, "jid", from);
|
||||
XMLAddChild(pubsub, sub);
|
||||
|
||||
Free(id);
|
||||
return iq_req;
|
||||
}
|
||||
|
|
@ -58,6 +58,11 @@ XMPPDispatcher(void *argp)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
|
||||
{
|
||||
Log(LOG_DEBUG, "Received stanza='%s'.", stanza->name);
|
||||
}
|
||||
|
||||
if (StrEquals(stanza->name, "presence"))
|
||||
{
|
||||
PresenceStanza(args, stanza);
|
||||
|
|
@ -68,6 +73,10 @@ XMPPDispatcher(void *argp)
|
|||
{
|
||||
if (!MessageStanza(args, stanza, thread))
|
||||
{
|
||||
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
|
||||
{
|
||||
Log(LOG_DEBUG, "Done receiving message with an error");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -82,6 +91,11 @@ XMPPDispatcher(void *argp)
|
|||
StreamPrintf(StreamStdout(), "\n");
|
||||
StreamFlush(StreamStdout());
|
||||
}
|
||||
|
||||
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
|
||||
{
|
||||
Log(LOG_DEBUG, "Done receiving stanza='%s'.", stanza->name);
|
||||
}
|
||||
XMLFreeElement(stanza);
|
||||
}
|
||||
|
||||
|
|
@ -180,9 +194,22 @@ ParseeXMPPThread(void *argp)
|
|||
stanza = XMLDecode(jabber->stream, false);
|
||||
if (!stanza)
|
||||
{
|
||||
if (args->verbosity >= PARSEE_VERBOSE_COMICAL)
|
||||
{
|
||||
Log(LOG_DEBUG, "RECEIVED EOF.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (args->verbosity >= PARSEE_VERBOSE_STANZA)
|
||||
{
|
||||
Stream *output = StreamStderr();
|
||||
StreamPrintf(output, "-------STANZA BEGIN-------" "\n");
|
||||
XMLEncode(output, stanza);
|
||||
StreamPrintf(output, "\n--------STANZA END--------" "\n");
|
||||
StreamFlush(output);
|
||||
}
|
||||
|
||||
id = HashMapGet(stanza->attrs, "id");
|
||||
if (id)
|
||||
{
|
||||
|
|
@ -271,7 +298,7 @@ ParseeAwaitStanza(char *identifier, int64_t timeout)
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
pthread_mutex_lock(&await_lock);
|
||||
if (HashMapGet(await_table, identifier))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue