[FIX] Make RouteUserDirectory actually buildable.
This commit is contained in:
parent
cba882dae5
commit
5295e0295b
1 changed files with 16 additions and 12 deletions
|
@ -23,13 +23,14 @@
|
||||||
*/
|
*/
|
||||||
#include <Routes.h>
|
#include <Routes.h>
|
||||||
|
|
||||||
#include <Array.h>
|
#include <Cytoplasm/Array.h>
|
||||||
#include <HashMap.h>
|
#include <Cytoplasm/HashMap.h>
|
||||||
#include <Json.h>
|
#include <Cytoplasm/Json.h>
|
||||||
#include <Str.h>
|
#include <Cytoplasm/Str.h>
|
||||||
#include <Memory.h>
|
#include <Cytoplasm/Memory.h>
|
||||||
|
#include <Cytoplasm/Db.h>
|
||||||
|
|
||||||
#include <User.h>
|
#include <User.h>
|
||||||
#include <Db.h>
|
|
||||||
|
|
||||||
ROUTE_IMPL(RouteUserDirectory, path, argp)
|
ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
{
|
{
|
||||||
|
@ -51,6 +52,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
char *token = NULL;
|
char *token = NULL;
|
||||||
char *searchTerm = NULL;
|
char *searchTerm = NULL;
|
||||||
char *requesterName = NULL;
|
char *requesterName = NULL;
|
||||||
|
char *msg = NULL;
|
||||||
|
|
||||||
size_t limit = 10;
|
size_t limit = 10;
|
||||||
|
|
||||||
|
@ -61,8 +63,9 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
|
|
||||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||||
{
|
{
|
||||||
|
msg = "Request supports only POST.";
|
||||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +73,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
if (!request)
|
if (!request)
|
||||||
{
|
{
|
||||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||||
response = MatrixErrorCreate(M_NOT_JSON);
|
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,18 +88,19 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
if (!user)
|
if (!user)
|
||||||
{
|
{
|
||||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
requesterName = UserGetName(user);
|
requesterName = UserGetName(user);
|
||||||
|
|
||||||
/* Parse limit and search_term */
|
/* TODO: Use j2s instead of an hardcoded parser */
|
||||||
if (!(val = JsonGet(request, 1, "search_term")) ||
|
if (!(val = JsonGet(request, 1, "search_term")) ||
|
||||||
JsonValueType(val) != JSON_STRING)
|
JsonValueType(val) != JSON_STRING)
|
||||||
{
|
{
|
||||||
/* The Spec requires search_term to be set to a 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);
|
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||||
response = MatrixErrorCreate(M_BAD_JSON);
|
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
searchTerm = StrLower(JsonValueAsString(val));
|
searchTerm = StrLower(JsonValueAsString(val));
|
||||||
|
@ -122,7 +126,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
|
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
|
||||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
response = MatrixErrorCreate(M_UNKNOWN);
|
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||||
|
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue