[MOD] Die on loopback stanza

Dirty hack to a memory problem.
This commit is contained in:
LDA 2024-06-19 13:45:26 +02:00
commit 14ebef53ce
7 changed files with 77 additions and 16 deletions

View file

@ -1,5 +1,7 @@
#include <Cytoplasm/HttpServer.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Log.h>
#include <Cytoplasm/Str.h>
#include <pthread.h>
#include <string.h>
@ -12,10 +14,14 @@
static HttpServer *server = NULL;
static pthread_t xmpp_thr;
static XMPPComponent *jabber = NULL;
static void
SignalHandler(int signal)
{
size_t i;
XMLElement *message, *body, *data;
char *from;
switch (signal)
{
@ -27,8 +33,22 @@ SignalHandler(int signal)
{
return;
}
/* Create a loopback stanza, forcing the thread to die */
from = StrConcat(2, "jabber_die@", jabber->host);
message = XMLCreateTag("message");
XMLAddAttr(message, "from", from);
XMLAddAttr(message, "to", from);
XMLAddAttr(message, "type", "kill_parsee");
body = XMLCreateTag("body");
XMLAddChild(message, body);
XMLEncode(jabber->stream, message);
StreamFlush(jabber->stream);
XMLFreeElement(message);
Free(from);
HttpServerStop(server);
pthread_cancel(xmpp_thr);
//pthread_cancel(xmpp_thr);
break;
}
}
@ -37,10 +57,9 @@ int
Main(void)
{
HttpServerConfig conf;
ParseeData *data;
ParseeData *data = NULL;
const ParseeConfig *parsee_conf;
Stream *yaml;
XMPPComponent *jabber;
struct sigaction sigAction;
Log(LOG_INFO, "%s - v%s", NAME, VERSION);
@ -59,10 +78,14 @@ Main(void)
parsee_conf->component_host,
parsee_conf->component_port
);
XMPPAuthenticateCompStream(
if (!XMPPAuthenticateCompStream(
jabber,
parsee_conf->shared_comp_secret
);
))
{
Log(LOG_ERR, "Could not connect to XMPP...");
goto end;
}
}
Log(LOG_NOTICE, "Setting up local Matrix user...");
@ -107,6 +130,7 @@ Main(void)
HttpServerStart(server);
HttpServerJoin(server);
end:
HttpServerFree(server);
ParseeConfigFree();
ParseeFreeData(conf.handlerArgs);