mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 15:05:11 +00:00
Merge branch 'master' of https://git.kappach.at/lda/Parsee into janet
This commit is contained in:
commit
e3979e0e6e
5 changed files with 75 additions and 4 deletions
|
|
@ -10,15 +10,16 @@
|
||||||
|
|
||||||
#include <Matrix.h>
|
#include <Matrix.h>
|
||||||
|
|
||||||
void
|
bool
|
||||||
ASPing(const ParseeConfig *conf)
|
ASPing(const ParseeConfig *conf)
|
||||||
{
|
{
|
||||||
HttpClientContext *ctx = NULL;
|
HttpClientContext *ctx = NULL;
|
||||||
HashMap *json = NULL;
|
HashMap *json = NULL;
|
||||||
char *path;
|
char *path;
|
||||||
|
bool ret;
|
||||||
if (!conf)
|
if (!conf)
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = StrConcat(3,
|
path = StrConcat(3,
|
||||||
|
|
@ -33,7 +34,9 @@ ASPing(const ParseeConfig *conf)
|
||||||
Free(path);
|
Free(path);
|
||||||
json = HashMapCreate();
|
json = HashMapCreate();
|
||||||
ASAuthenticateRequest(conf, ctx);
|
ASAuthenticateRequest(conf, ctx);
|
||||||
ParseeSetRequestJSON(ctx, json);
|
ret = ParseeSetRequestJSON(ctx, json) == HTTP_OK;
|
||||||
HttpClientContextFree(ctx);
|
HttpClientContextFree(ctx);
|
||||||
JsonFree(json);
|
JsonFree(json);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
src/Main.c
29
src/Main.c
|
|
@ -63,6 +63,34 @@ static const Argument arguments[] =
|
||||||
#undef Argument
|
#undef Argument
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
ParseeCheckMatrix(void *datp)
|
||||||
|
{
|
||||||
|
static volatile uint64_t streak = 0;
|
||||||
|
ParseeData *data = datp;
|
||||||
|
if (!ASPing(data->config))
|
||||||
|
{
|
||||||
|
Log(LOG_ERR, "Cannot reach '%s' properly...", data->config->homeserver_host);
|
||||||
|
if (++streak >= 5)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
streak = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
Main(Array *args, HashMap *env)
|
Main(Array *args, HashMap *env)
|
||||||
{
|
{
|
||||||
|
|
@ -273,6 +301,7 @@ Main(Array *args, HashMap *env)
|
||||||
Log(LOG_NOTICE, "Starting up local cronjobs...");
|
Log(LOG_NOTICE, "Starting up local cronjobs...");
|
||||||
cron = CronCreate(10 SECONDS);
|
cron = CronCreate(10 SECONDS);
|
||||||
CronEvery(cron, 5 MINUTES, ParseeCleanup, conf.handlerArgs);
|
CronEvery(cron, 5 MINUTES, ParseeCleanup, conf.handlerArgs);
|
||||||
|
CronEvery(cron, 10 SECONDS, ParseeCheckMatrix, conf.handlerArgs);
|
||||||
ParseeCleanup(conf.handlerArgs);
|
ParseeCleanup(conf.handlerArgs);
|
||||||
|
|
||||||
CronStart(cron);
|
CronStart(cron);
|
||||||
|
|
|
||||||
38
src/Routes/Ping.c
Normal file
38
src/Routes/Ping.c
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#include <Routes.h>
|
||||||
|
|
||||||
|
#include <Cytoplasm/Log.h>
|
||||||
|
|
||||||
|
#include <Matrix.h>
|
||||||
|
#include <AS.h>
|
||||||
|
|
||||||
|
RouteHead(RoutePing, arr, argp)
|
||||||
|
{
|
||||||
|
ParseeHttpArg *args = argp;
|
||||||
|
HashMap *request = NULL;
|
||||||
|
HashMap *response = NULL;
|
||||||
|
Array *events;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
response = ASVerifyRequest(args);
|
||||||
|
if (response)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (HttpRequestMethodGet(args->ctx) != HTTP_POST)
|
||||||
|
{
|
||||||
|
HttpResponseStatus(args->ctx, HTTP_METHOD_NOT_ALLOWED);
|
||||||
|
response = MatrixCreateError(
|
||||||
|
"M_UNRECOGNIZED",
|
||||||
|
"Path /ping only accepts POST as a valid method."
|
||||||
|
);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestJSON();
|
||||||
|
|
||||||
|
response = HashMapCreate();
|
||||||
|
end:
|
||||||
|
(void) arr;
|
||||||
|
JsonFree(request);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ extern void ASAuthenticateRequest(const ParseeConfig *, HttpClientContext *);
|
||||||
extern bool ASRegisterUser(const ParseeConfig *, char *);
|
extern bool ASRegisterUser(const ParseeConfig *, char *);
|
||||||
|
|
||||||
/* Pings the homeserver to get attention. */
|
/* Pings the homeserver to get attention. */
|
||||||
extern void ASPing(const ParseeConfig *);
|
extern bool ASPing(const ParseeConfig *);
|
||||||
|
|
||||||
/** Joins a room from an {id} and a given {user} we want to masquerade
|
/** Joins a room from an {id} and a given {user} we want to masquerade
|
||||||
* as.
|
* as.
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ typedef struct ParseeCmdArg {
|
||||||
X_ROUTE("/_matrix/app/v1/transactions/(.*)", RouteTxns) \
|
X_ROUTE("/_matrix/app/v1/transactions/(.*)", RouteTxns) \
|
||||||
X_ROUTE("/_matrix/app/v1/users/(.*)", RouteUserAck) \
|
X_ROUTE("/_matrix/app/v1/users/(.*)", RouteUserAck) \
|
||||||
X_ROUTE("/_matrix/app/v1/rooms/(.*)", RouteRoomAck) \
|
X_ROUTE("/_matrix/app/v1/rooms/(.*)", RouteRoomAck) \
|
||||||
|
X_ROUTE("/_matrix/app/v1/ping", RoutePing) \
|
||||||
X_ROUTE("/_matrix/client/v1/media/download/(.*)/(.*)", RouteMedia)
|
X_ROUTE("/_matrix/client/v1/media/download/(.*)/(.*)", RouteMedia)
|
||||||
|
|
||||||
#define X_ROUTE(path, name) extern void * name(Array *, void *);
|
#define X_ROUTE(path, name) extern void * name(Array *, void *);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue