mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 10:45:11 +00:00
[ADD] Ping homeserver to see if Parsee works
This commit is contained in:
parent
7f41a85a8a
commit
5d13410ac4
5 changed files with 75 additions and 4 deletions
|
|
@ -10,15 +10,16 @@
|
|||
|
||||
#include <Matrix.h>
|
||||
|
||||
void
|
||||
bool
|
||||
ASPing(const ParseeConfig *conf)
|
||||
{
|
||||
HttpClientContext *ctx = NULL;
|
||||
HashMap *json = NULL;
|
||||
char *path;
|
||||
bool ret;
|
||||
if (!conf)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
path = StrConcat(3,
|
||||
|
|
@ -33,7 +34,9 @@ ASPing(const ParseeConfig *conf)
|
|||
Free(path);
|
||||
json = HashMapCreate();
|
||||
ASAuthenticateRequest(conf, ctx);
|
||||
ParseeSetRequestJSON(ctx, json);
|
||||
ret = ParseeSetRequestJSON(ctx, json) == HTTP_OK;
|
||||
HttpClientContextFree(ctx);
|
||||
JsonFree(json);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
29
src/Main.c
29
src/Main.c
|
|
@ -58,6 +58,34 @@ static const Argument arguments[] =
|
|||
#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
|
||||
Main(Array *args, HashMap *env)
|
||||
{
|
||||
|
|
@ -259,6 +287,7 @@ Main(Array *args, HashMap *env)
|
|||
Log(LOG_NOTICE, "Starting up local cronjobs...");
|
||||
cron = CronCreate(10 SECONDS);
|
||||
CronEvery(cron, 5 MINUTES, ParseeCleanup, conf.handlerArgs);
|
||||
CronEvery(cron, 10 SECONDS, ParseeCheckMatrix, conf.handlerArgs);
|
||||
ParseeCleanup(conf.handlerArgs);
|
||||
|
||||
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 *);
|
||||
|
||||
/* 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
|
||||
* as.
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ typedef struct ParseeCmdArg {
|
|||
X_ROUTE("/_matrix/app/v1/transactions/(.*)", RouteTxns) \
|
||||
X_ROUTE("/_matrix/app/v1/users/(.*)", RouteUserAck) \
|
||||
X_ROUTE("/_matrix/app/v1/rooms/(.*)", RouteRoomAck) \
|
||||
X_ROUTE("/_matrix/app/v1/ping", RoutePing) \
|
||||
X_ROUTE("/_matrix/client/v1/media/download/(.*)/(.*)", RouteMedia)
|
||||
|
||||
#define X_ROUTE(path, name) extern void * name(Array *, void *);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue