[FIX] Make RouteUserDirectory actually buildable.

This commit is contained in:
lda 2023-11-02 13:09:14 +01:00
parent cba882dae5
commit 5295e0295b
Signed by: lda
GPG Key ID: 6898757653ABE3E6
1 changed files with 16 additions and 12 deletions

View File

@ -23,13 +23,14 @@
*/
#include <Routes.h>
#include <Array.h>
#include <HashMap.h>
#include <Json.h>
#include <Str.h>
#include <Memory.h>
#include <Cytoplasm/Array.h>
#include <Cytoplasm/HashMap.h>
#include <Cytoplasm/Json.h>
#include <Cytoplasm/Str.h>
#include <Cytoplasm/Memory.h>
#include <Cytoplasm/Db.h>
#include <User.h>
#include <Db.h>
ROUTE_IMPL(RouteUserDirectory, path, argp)
{
@ -51,6 +52,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
char *token = NULL;
char *searchTerm = NULL;
char *requesterName = NULL;
char *msg = NULL;
size_t limit = 10;
@ -61,8 +63,9 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_POST)
{
msg = "Request supports only POST.";
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED);
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
goto finish;
}
@ -70,7 +73,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
if (!request)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_NOT_JSON);
response = MatrixErrorCreate(M_NOT_JSON, NULL);
goto finish;
}
@ -85,18 +88,19 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
if (!user)
{
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
goto finish;
}
requesterName = UserGetName(user);
/* Parse limit and search_term */
/* TODO: Use j2s instead of an hardcoded parser */
if (!(val = JsonGet(request, 1, "search_term")) ||
JsonValueType(val) != JSON_STRING)
{
/* The Spec requires search_term to be set to a string. */
msg = "search_term must be set to a string";
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON);
response = MatrixErrorCreate(M_BAD_JSON, msg);
goto finish;
}
searchTerm = StrLower(JsonValueAsString(val));
@ -122,7 +126,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
{
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN);
response = MatrixErrorCreate(M_UNKNOWN, NULL);
goto finish;
}