[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 <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <Unistring.h> #include <StanzaBuilder.h>
#include <Parsee.h> #include <Parsee.h>
#include <XMPP.h> #include <XMPP.h>
#include <AS.h> #include <AS.h>
@ -66,21 +66,36 @@ ParseeCheckMatrix(void *datp)
if (!ASPing(data->config)) if (!ASPing(data->config))
{ {
Log(LOG_ERR, "Cannot reach '%s' properly...", data->config->homeserver_host); 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."); DbRef *ref = DbLockIntent(data->db, DB_HINT_READONLY, 1, "chats");
Log(LOG_ERR, "Please check if your homeserver is active."); HashMap *json = DbJson(ref);
Log(LOG_ERR, "%s shall now exit...", NAME); 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); /* Notify any potential MUCs about this */
//pthread_join(xmpp_thr, NULL); while (HashMapIterate(mucs, &muc, &ignored))
Log(LOG_INFO, "Stopping server..."); {
HttpServerStop(data->server); 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; return;
} }
@ -109,7 +124,7 @@ Main(Array *args, HashMap *env)
); );
ParseePrintASCII(); ParseePrintASCII();
Log(LOG_INFO, "======================="); 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.)"); Log(LOG_INFO, "(This program is free software, see LICENSE.)");
#ifdef PLATFORM_IPHONE #ifdef PLATFORM_IPHONE

View file

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

View file

@ -538,7 +538,6 @@ ParseeGetMUCID(ParseeData *data, char *chat_id)
return ret; return ret;
} }
void void
ParseeSendPresence(ParseeData *data) ParseeSendPresence(ParseeData *data)
{ {
@ -562,7 +561,7 @@ ParseeSendPresence(ParseeData *data)
uint64_t ts = GrabInteger(DbJson(chat), 1, "ts"); uint64_t ts = GrabInteger(DbJson(chat), 1, "ts");
int diff = ts ? (int) ((UtilTsMillis() - ts) / 1000) : -1; int diff = ts ? (int) ((UtilTsMillis() - ts) / 1000) : -1;
/* Make a fake user join the MUC */ /* 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); XMPPJoinMUC(data->jabber, "parsee", rev, NULL, diff, false);
DbUnlock(data->db, chat); DbUnlock(data->db, chat);

View file

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

View file

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

View file

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

View file

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