[MOD] One-way Matrix->XMPP comms.

This is not sanitised. I need to make an XML writer.
This commit is contained in:
LDA 2024-06-17 18:26:37 +02:00
commit bdb4fd2f68
17 changed files with 421 additions and 61 deletions

View file

@ -2,33 +2,43 @@
#include <Cytoplasm/Log.h>
#include <string.h>
#include <signal.h>
#include <Parsee.h>
#include <XMPP.h>
#include <XML.h>
#include <AS.h>
static HttpServer *server = NULL;
static void
SignalHandler(int signal)
{
size_t i;
switch (signal)
{
case SIGPIPE:
return;
case SIGTERM:
case SIGINT:
if (!server)
{
return;
}
HttpServerStop(server);
break;
}
}
int
Main(void)
{
HttpServer *server = NULL;
HttpServerConfig conf;
ParseeData *data;
const ParseeConfig *parsee_conf;
Stream *yaml;
{
char *as = "TODO";
char *shared = "TODO";
Stream *jabber = XMPPInitialiseCompStream(as, 0);
XMPPAuthenticateCompStream(jabber, as, shared);
while (!StreamEof(jabber))
{
StreamPutc(StreamStderr(), StreamGetc(jabber));
StreamFlush(StreamStderr());
}
XMPPEndCompStream(jabber);
return 0;
}
XMPPComponent *jabber;
struct sigaction sigAction;
Log(LOG_INFO, "%s - v%s", NAME, VERSION);
ParseeConfigLoad("parsee.json");
@ -39,18 +49,48 @@ Main(void)
StreamClose(yaml);
parsee_conf = ParseeConfigGet();
{
jabber = XMPPInitialiseCompStream(
parsee_conf->component_host,
parsee_conf->component_port
);
XMPPAuthenticateCompStream(
jabber,
parsee_conf->shared_comp_secret
);
}
Log(LOG_INFO, "HS token: %s", parsee_conf->hs_token);
ASRegisterUser(parsee_conf, parsee_conf->sender_localpart);
memset(&conf, 0, sizeof(conf));
conf.port = parsee_conf->port;
conf.threads = 4;
conf.maxConnections = 32;
conf.handlerArgs = ParseeInitData();
conf.handlerArgs = ParseeInitData(jabber);
conf.handler = ParseeRequest;
sigAction.sa_handler = SignalHandler;
sigfillset(&sigAction.sa_mask);
sigAction.sa_flags = SA_RESTART;
#define SIGACTION(sig, act, oact) \
if (sigaction(sig, act, oact) < 0) \
{ \
Log(LOG_ERR, "Unable to install signal handler: %s", #sig); \
} \
else \
{ \
Log(LOG_DEBUG, "Installed signal handler: %s", #sig); \
}
SIGACTION(SIGINT, &sigAction, NULL);
SIGACTION(SIGTERM, &sigAction, NULL);
SIGACTION(SIGPIPE, &sigAction, NULL);
SIGACTION(SIGUSR1, &sigAction, NULL);
#undef SIGACTION
/* TODO: The rest of Parsee. */
server = HttpServerCreate(&conf);
HttpServerStart(server);
@ -60,5 +100,6 @@ Main(void)
HttpServerFree(server);
ParseeConfigFree();
ParseeFreeData(conf.handlerArgs);
return 0;
}