Update routing slightly, apply #35 to new RouteLogin

This commit is contained in:
Jordan Bancino 2022-12-10 15:41:19 +00:00
parent fb5a8e4587
commit 3b636a9d22

View file

@ -52,6 +52,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
char *requestPath; char *requestPath;
Array *pathParts; Array *pathParts;
char *pathPart; char *pathPart;
RouteArgs routeArgs;
requestPath = HttpRequestPath(context); requestPath = HttpRequestPath(context);
@ -70,7 +71,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
LogConfigUnindent(lc); LogConfigUnindent(lc);
HttpResponseStatus(context, HTTP_OK); HttpResponseStatus(context, HTTP_OK);
HttpResponseHeader(context, "Server", "Telodendria v" TELODENDRIA_VERSION); HttpResponseHeader(context, "Server", "Telodendria/" TELODENDRIA_VERSION);
HttpResponseHeader(context, "Content-Type", "application/json"); HttpResponseHeader(context, "Content-Type", "application/json");
/* CORS */ /* CORS */
@ -103,15 +104,19 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
ArrayAdd(pathParts, decoded); ArrayAdd(pathParts, decoded);
} }
routeArgs.matrixArgs = args;
routeArgs.context = context;
routeArgs.path = pathParts;
pathPart = MATRIX_PATH_POP(pathParts); pathPart = MATRIX_PATH_POP(pathParts);
if (MATRIX_PATH_EQUALS(pathPart, ".well-known")) if (MATRIX_PATH_EQUALS(pathPart, ".well-known"))
{ {
response = RouteWellKnown(args, context, pathParts); response = RouteWellKnown(&routeArgs);
} }
else if (MATRIX_PATH_EQUALS(pathPart, "_matrix")) else if (MATRIX_PATH_EQUALS(pathPart, "_matrix"))
{ {
response = RouteMatrix(args, context, pathParts); response = RouteMatrix(&routeArgs);
} }
else else
{ {
@ -122,7 +127,6 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
Free(pathPart); Free(pathPart);
HttpSendHeaders(context); HttpSendHeaders(context);
stream = HttpStream(context);
if (!response) if (!response)
{ {
@ -131,6 +135,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN);
} }
stream = HttpStream(context);
JsonEncode(response, stream); JsonEncode(response, stream);
fprintf(stream, "\n"); fprintf(stream, "\n");