Parsee/src/include/Routes.h
LDA bb836789b2 [FIX/WIP] Plumbing, -Werror, death to hitmen
Suspend killers are now no more. Except the actual killers to be gone
eventually.
Plumbing is also very basic as of now, but it "works".
2024-07-05 20:24:15 +02:00

93 lines
3.8 KiB
C

#ifndef PARSEE_ROUTES_H
#define PARSEE_ROUTES_H
#include <Parsee.h>
typedef struct ParseeHttpArg {
ParseeData *data;
HttpServerContext *ctx;
Stream *stream;
} ParseeHttpArg;
typedef struct ParseeCmdArg {
ParseeData *data;
HashMap *event;
} ParseeCmdArg;
/* A list of all commands. */
#define COMMANDS X_COMMAND( \
"ban-user", CmdBanUser, \
"Bans a user from a room or a MUC" \
) \
X_COMMAND( \
"ban-list", CmdNoFlyList, \
"Globally bans a user from using Parsee" \
) \
X_COMMAND( \
"nuke-muc", CmdUnlinkMUC, \
"Removes a MUC. Users should then run " \
"!ban-list to remove all access to the MUC" \
) \
X_COMMAND( \
"list-bans", CmdListBans, \
"Shows all global bans from Parsee" \
) \
X_COMMAND( \
"set-pl", CmdSetPL, \
"Sets the power level in a Parsee room" \
) \
X_COMMAND( \
"set-min-pl", CmdSetMin, \
"Sets the power level to send a specific event " \
"in a Parsee room" \
) \
X_COMMAND( \
"plumb-muc", CmdPlumb, \
"Plumbs an existing Matrix room to a MUC." \
"You'll need to give the Parsee bot enough " \
"privileges, however. " \
) \
X_COMMAND( \
"help", CmdHelp, \
"Shows the command list" \
) \
X_COMMAND( \
"stats", CmdStats, \
"Shows some Parsee statistics." \
)
#define X_COMMAND(path, name,d) extern void name(Command *, void *);
COMMANDS
#undef X_COMMAND
#define CommandHead(name, cmd, argp) void \
name(Command * cmd, void *argp)
/* A list of all routes. */
#define ROUTES X_ROUTE("/", RouteRoot) \
X_ROUTE("/_matrix/app/v1/transactions/(.*)", RouteTxns) \
X_ROUTE("/_matrix/app/v1/ping", RoutePing) \
X_ROUTE("/_matrix/app/v1/users/(.*)", RouteUserAck) \
X_ROUTE("/_matrix/app/v1/rooms/(.*)", RouteRoomAck) \
X_ROUTE("/_matrix/client/v1/media/download/(.*)/(.*)", RouteMedia)
#define X_ROUTE(path, name) extern void * name(Array *, void *);
ROUTES
#undef X_ROUTE
#define RouteHead(name, pathargs, argp) void * \
name(Array * pathargs, void *argp)
#define RequestJSON() do \
{ \
Stream *s = args->stream;\
if (!(request = JsonDecode(s))) \
{ \
HttpResponseStatus( \
args->ctx, \
HTTP_BAD_REQUEST \
); \
response = MatrixCreateError(\
"M_NO_JSON", \
"Invalid JSON stream." \
); \
} \
} \
while (0)
#endif