[MOD] Notify MUCs about errors

This commit is contained in:
LDA 2025-01-03 15:01:35 +01:00
commit c365681fcb
7 changed files with 37 additions and 27 deletions

View file

@ -13,7 +13,7 @@
#include <signal.h>
#include <stdlib.h>
#include <Unistring.h>
#include <StanzaBuilder.h>
#include <Parsee.h>
#include <XMPP.h>
#include <AS.h>
@ -66,21 +66,36 @@ ParseeCheckMatrix(void *datp)
if (!ASPing(data->config))
{
Log(LOG_ERR, "Cannot reach '%s' properly...", data->config->homeserver_host);
if (++streak >= 5)
if (++streak == 10)
{
Log(LOG_ERR, "This has been at least the fifth time in a row.");
Log(LOG_ERR, "Please check if your homeserver is active.");
Log(LOG_ERR, "%s shall now exit...", NAME);
DbRef *ref = DbLockIntent(data->db, DB_HINT_READONLY, 1, "chats");
HashMap *json = DbJson(ref);
HashMap *mucs = GrabObject(json, 1, "mucs");
char *muc;
void *ignored;
/* TODO: SEGV! */
pthread_mutex_lock(&data->halt_lock);
data->halted = true;
pthread_mutex_unlock(&data->halt_lock);
XMPPFinishCompStream(data->jabber);
//pthread_join(xmpp_thr, NULL);
Log(LOG_INFO, "Stopping server...");
HttpServerStop(data->server);
/* Notify any potential MUCs about this */
while (HashMapIterate(mucs, &muc, &ignored))
{
char *id = StrRandom(32);
char *sender = StrConcat(3, "parsee@", data->jabber->host, "/parsee");
StanzaBuilder *b = CreateStanzaBuilder(sender, muc, id);
SetStanzaType(b, "groupchat");
SetStanzaBody(b,
"This bridge hasn't been able to reach the Matrix host, and "
"as such, some messages may not have been sent over."
);
WriteoutStanza(b, data->jabber, 0);
DestroyStanzaBuilder(b);
Free(sender);
Free(id);
}
(void) ignored;
DbUnlock(data->db, ref);
}
return;
}
@ -109,7 +124,7 @@ Main(Array *args, HashMap *env)
);
ParseePrintASCII();
Log(LOG_INFO, "=======================");
Log(LOG_INFO, "(C)opyright 2024 LDA and other contributors");
Log(LOG_INFO, "(C)opyright 2024-2025 LDA and other contributors");
Log(LOG_INFO, "(This program is free software, see LICENSE.)");
#ifdef PLATFORM_IPHONE

View file

@ -132,7 +132,6 @@ ParseeCleanup(void *datp)
char *chat;
size_t i;
uint64_t ts = UtilTsMillis();
size_t entries = 0;
chats = DbList(data->db, 1, "chats");
@ -176,7 +175,6 @@ ParseeCleanup(void *datp)
if (cleaned > threshold) \
{ \
DbDelete(data->db, 4, "chats", chat, #field"s", field); \
entries++; \
} \
Free(field); \
} \
@ -233,7 +231,6 @@ ParseeCleanup(void *datp)
if (cleaned > threshold) \
{ \
JsonValueFree(HashMapDelete(field##s, field)); \
entries++; \
} \
Free(field); \
} \

View file

@ -538,7 +538,6 @@ ParseeGetMUCID(ParseeData *data, char *chat_id)
return ret;
}
void
ParseeSendPresence(ParseeData *data)
{
@ -562,7 +561,7 @@ ParseeSendPresence(ParseeData *data)
uint64_t ts = GrabInteger(DbJson(chat), 1, "ts");
int diff = ts ? (int) ((UtilTsMillis() - ts) / 1000) : -1;
/* Make a fake user join the MUC */
Log(LOG_NOTICE, "Sending presence to %s last=%ds", rev, diff);
Log(LOG_NOTICE, "Sending presence to %s", rev);
XMPPJoinMUC(data->jabber, "parsee", rev, NULL, diff, false);
DbUnlock(data->db, chat);

View file

@ -48,7 +48,7 @@ RouteHead(RouteMedia, arr, argp)
HashMap *reqh, *params;
char *server = ArrayGet(arr, 0);
char *identi = ArrayGet(arr, 1);
char *path, *key, *val;
char *key, *val;
char *hmac, *chkmak = NULL;
params = HttpRequestParams(args->ctx);

View file

@ -10,8 +10,6 @@ RouteHead(RoutePing, arr, argp)
ParseeHttpArg *args = argp;
HashMap *request = NULL;
HashMap *response = NULL;
Array *events;
size_t i;
response = ASVerifyRequest(args);
if (response)

View file

@ -123,6 +123,7 @@ ManageMUCStanza(MUCServer *serv, XMLElement *stanza)
/* TODO: Verify the destination, and make sure we aren't doing
* anything stupid(especially with discovery) */
(void) ret;
return false;
}

View file

@ -18,9 +18,9 @@ void
MUCSetKey(XMPPCommandManager *m, char *from, XMLElement *form, XMLElement *out)
{
ParseeData *data = XMPPGetManagerCookie(m);
char *affiliation, *role;
char *chat_id;
char *muc;
char *affiliation = NULL, *role = NULL;
char *chat_id = NULL;
char *muc = NULL;
char *key = NULL, *val = NULL;