Move client well-known generation to MatrixClientWellKnown() function.

We'll be using this for client login.
This commit is contained in:
Jordan Bancino 2023-01-16 22:02:08 +00:00
parent 121682c006
commit cc95c10f44
4 changed files with 34 additions and 21 deletions

View file

@ -17,10 +17,10 @@ Milestone: v0.2.0
[x] Move String functions to a new String.h [x] Move String functions to a new String.h
[x] Make StringConcat use varargs [x] Make StringConcat use varargs
[x] Look into seeding random strings (possibly create Random.h?) [x] Look into seeding random strings (possibly create Random.h?)
[~] User registration [x] User registration
[x] Username validation [x] Username validation
[x] Password hashing [x] Password hashing
[~] User API [x] User API
[x] Document MemoryHexDump() [x] Document MemoryHexDump()
[x] Document DbExists() [x] Document DbExists()

View file

@ -358,3 +358,31 @@ MatrixRateLimit(HttpServerContext * context, Db * db)
(void) db; (void) db;
return NULL; return NULL;
} }
HashMap *
MatrixClientWellKnown(char *base, char *identity)
{
HashMap *response;
HashMap *homeserver;
if (!base)
{
return NULL;
}
response = HashMapCreate();
homeserver = HashMapCreate();
HashMapSet(homeserver, "base_url", JsonValueString(StrDuplicate(base)));
HashMapSet(response, "m.homeserver", JsonValueObject(homeserver));
if (identity)
{
HashMap *identityServer = HashMapCreate();
HashMapSet(identityServer, "base_url", JsonValueString(StrDuplicate(identity)));
HashMapSet(response, "m.identity_server", identityServer);
}
return response;
}

View file

@ -32,7 +32,6 @@
ROUTE_IMPL(RouteWellKnown, args) ROUTE_IMPL(RouteWellKnown, args)
{ {
HashMap *response = NULL;
char *pathPart = MATRIX_PATH_POP(args->path); char *pathPart = MATRIX_PATH_POP(args->path);
if (!MATRIX_PATH_EQUALS(pathPart, "matrix") || MATRIX_PATH_PARTS(args->path) != 1) if (!MATRIX_PATH_EQUALS(pathPart, "matrix") || MATRIX_PATH_PARTS(args->path) != 1)
@ -47,24 +46,9 @@ ROUTE_IMPL(RouteWellKnown, args)
if (MATRIX_PATH_EQUALS(pathPart, "client")) if (MATRIX_PATH_EQUALS(pathPart, "client"))
{ {
HashMap *homeserver = HashMapCreate();
Free(pathPart); Free(pathPart);
return MatrixClientWellKnown(args->matrixArgs->config->baseUrl,
response = HashMapCreate(); args->matrixArgs->config->identityServer);
HashMapSet(homeserver, "base_url", JsonValueString(StrDuplicate(args->matrixArgs->config->baseUrl)));
HashMapSet(response, "m.homeserver", JsonValueObject(homeserver));
if (args->matrixArgs->config->identityServer)
{
HashMap *identityServer = HashMapCreate();
HashMapSet(identityServer, "base_url", JsonValueString(StrDuplicate(args->matrixArgs->config->identityServer)));
HashMapSet(response, "m.identity_server", identityServer);
}
return response;
} }
else else
{ {

View file

@ -86,6 +86,7 @@ extern HashMap *
extern HashMap * extern HashMap *
MatrixRateLimit(HttpServerContext *, Db *); MatrixRateLimit(HttpServerContext *, Db *);
extern HashMap *
MatrixClientWellKnown(char *, char *);
#endif #endif