[ADD/WIP] Bridge media Matrix->XMPP

We're on that Reverse Ideology phase.
This commit is contained in:
LDA 2024-06-27 20:09:52 +02:00
commit fbf169a080
9 changed files with 118 additions and 6 deletions

49
src/Routes/Media.c Normal file
View file

@ -0,0 +1,49 @@
#include <Routes.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Str.h>
#include <Matrix.h>
#include <Parsee.h>
#include <AS.h>
RouteHead(RouteMedia, arr, argp)
{
ParseeHttpArg *args = argp;
HttpClientContext *cctx;
HashMap *reqh;
char *server = ArrayGet(arr, 0);
char *identi = ArrayGet(arr, 1);
char *path, *key, *val;
/* TODO: Make it check the DB for its validicity. "Purging" would be useful.
*/
if (!server || !identi)
{
HttpResponseStatus(args->ctx, HTTP_BAD_REQUEST);
return MatrixCreateError("M_NOT_YET_UPLOADED", "No server/identifier");
}
server = HttpUrlEncode(server);
identi = HttpUrlEncode(identi);
path = StrConcat(4, "/_matrix/media/v3/download/", server, "/", identi);
cctx = ParseeCreateRequest(args->data->config, HTTP_GET, path);
ASAuthenticateRequest(args->data->config, cctx);
Free(path);
HttpRequestSendHeaders(cctx);
HttpRequestSend(cctx);
reqh = HttpResponseHeaders(cctx);
while (HashMapIterate(reqh, &key, (void **) &val))
{
HttpResponseHeader(args->ctx, key, val);
}
HttpSendHeaders(args->ctx);
StreamCopy(HttpClientStream(cctx), HttpServerStream(args->ctx));
HttpClientContextFree(cctx);
Free(server);
Free(identi);
return NULL;
}