forked from Telodendria/Telodendria
Apply patch to make MatrixErrorCreate() take a custom message.
This commit is contained in:
parent
28d9e1cb3b
commit
6ef965d1e0
21 changed files with 152 additions and 146 deletions
4
TODO.txt
4
TODO.txt
|
@ -44,8 +44,10 @@ Milestone: v0.4.0
|
|||
higher level logic set the default from there.
|
||||
[ ] Write man page.
|
||||
|
||||
[ ] Refactor MatrixErrorCreate() to take a custom message or NULL to
|
||||
[x] Refactor MatrixErrorCreate() to take a custom message or NULL to
|
||||
use the default. This will make debugging a lot easier.
|
||||
[ ] Use detailed error messages for HTTP 500s at the minimum. Other
|
||||
error messages might also be useful.
|
||||
[x] Make sure admin registration token is printed to log, not stdout.
|
||||
Unless they are the same, of course.
|
||||
[ ] Refactor Config to use j2s.
|
||||
|
|
13
src/Matrix.c
13
src/Matrix.c
|
@ -82,7 +82,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
|||
{
|
||||
HttpResponseHeader(context, "Content-Type", "application/json");
|
||||
HttpResponseStatus(context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -115,7 +115,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
|
|||
}
|
||||
|
||||
HashMap *
|
||||
MatrixErrorCreate(MatrixError errorArg)
|
||||
MatrixErrorCreate(MatrixError errorArg, char *msg)
|
||||
{
|
||||
HashMap *errorObj;
|
||||
char *errcode;
|
||||
|
@ -261,6 +261,11 @@ MatrixErrorCreate(MatrixError errorArg)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
{
|
||||
error = msg;
|
||||
}
|
||||
|
||||
errorObj = HashMapCreate();
|
||||
if (!errorObj)
|
||||
{
|
||||
|
@ -289,7 +294,7 @@ MatrixGetAccessToken(HttpServerContext * context, char **accessToken)
|
|||
if (strncmp(token, "Bearer ", 7) != 0)
|
||||
{
|
||||
HttpResponseStatus(context, HTTP_UNAUTHORIZED);
|
||||
return MatrixErrorCreate(M_MISSING_TOKEN);
|
||||
return MatrixErrorCreate(M_MISSING_TOKEN, NULL);
|
||||
}
|
||||
|
||||
/* Seek past "Bearer" */
|
||||
|
@ -310,7 +315,7 @@ MatrixGetAccessToken(HttpServerContext * context, char **accessToken)
|
|||
if (!token)
|
||||
{
|
||||
HttpResponseStatus(context, HTTP_UNAUTHORIZED);
|
||||
return MatrixErrorCreate(M_MISSING_TOKEN);
|
||||
return MatrixErrorCreate(M_MISSING_TOKEN, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "Password endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
(void) path;
|
||||
|
@ -79,7 +79,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
if (uiaResult < 0)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
else if (!uiaResult)
|
||||
|
@ -120,7 +120,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
{
|
||||
JsonFree(request);
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,14 +52,14 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!(UserGetPrivileges(user) & USER_CONFIG))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "Config endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
if (!newConf)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -108,14 +108,13 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
/* TODO: Attach newConf->err as message */
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, newConf->err);
|
||||
}
|
||||
|
||||
ConfigFree(newConf);
|
||||
|
@ -125,7 +124,7 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
/* TODO: Support incremental changes to the config */
|
||||
default:
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,14 +53,14 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "Deactivate endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
if (uiaResult < 0)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
else if (!uiaResult)
|
||||
|
@ -122,14 +122,14 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,14 +73,14 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
{
|
||||
/* Should be impossible */
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
serverName = GetServerName(db);
|
||||
if (!serverName)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -88,14 +88,14 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
if (!id)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!StrEquals(id->server, serverName))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_UNAUTHORIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -109,14 +109,14 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!StrEquals(id->localpart, UserGetName(user)))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
if (!ref)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -147,14 +147,13 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!FilterFromJson(request, &filter, &parseErr))
|
||||
{
|
||||
/* TODO: send parseErr to client */
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, parseErr);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -163,7 +162,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
if (!filterId)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -172,7 +171,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
{
|
||||
Free(filterId);
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -191,7 +190,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
finish:
|
||||
|
|
|
@ -63,7 +63,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "Login endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
(void) path;
|
||||
|
@ -84,7 +84,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -92,14 +92,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!StrEquals(type, "m.login.password"))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -115,14 +115,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_OBJECT)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -132,14 +132,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!StrEquals(type, "m.id.user"))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -155,14 +155,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!userId)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
|| !UserExists(db, userId->localpart))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -212,14 +212,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (JsonValueType(val) != JSON_BOOLEAN)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
UserUnlock(user);
|
||||
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_USER_DEACTIVATED);
|
||||
response = MatrixErrorCreate(M_USER_DEACTIVATED, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
UserUnlock(user);
|
||||
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
break;
|
||||
default:
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
|
|||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
response = MatrixGetAccessToken(args->context, &tokenstr);
|
||||
|
@ -58,7 +58,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
return MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
return MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
}
|
||||
|
||||
if (ArraySize(path) == 1)
|
||||
|
@ -66,7 +66,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
|
|||
if (!StrEquals(ArrayGet(path, 0), "all"))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
|
|||
/* If we can't delete all of our tokens, then something is
|
||||
* wrong. */
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
response = HashMapCreate();
|
||||
|
@ -85,7 +85,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
|
|||
if (!UserDeleteToken(user, tokenstr))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,14 +49,14 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!(UserGetPrivileges(user) & USER_GRANT_PRIVILEGES))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
if (!val || JsonValueType(val) != JSON_ARRAY)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
if (!UserSetPrivileges(user, privileges))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
break;
|
||||
default:
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -48,14 +48,14 @@ ROUTE_IMPL(RouteProcControl, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!(UserGetPrivileges(user) & USER_PROC_CONTROL))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ ROUTE_IMPL(RouteProcControl, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
break;
|
||||
|
@ -90,12 +90,12 @@ ROUTE_IMPL(RouteProcControl, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
default:
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -56,21 +56,21 @@ ROUTE_IMPL(RouteRefresh, path, argp)
|
|||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_NOT_JSON);
|
||||
return MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
}
|
||||
|
||||
val = HashMapGet(request, "refresh_token");
|
||||
if (!val || JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ ROUTE_IMPL(RouteRefresh, path, argp)
|
|||
if (!rtRef)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ ROUTE_IMPL(RouteRefresh, path, argp)
|
|||
refreshToken);
|
||||
Log(LOG_WARNING, "This refresh token will be deleted.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
|
||||
DbUnlock(db, rtRef);
|
||||
DbDelete(db, 3, "tokens", "refresh", refreshToken);
|
||||
|
@ -114,7 +114,7 @@ ROUTE_IMPL(RouteRefresh, path, argp)
|
|||
oldAccessToken);
|
||||
Log(LOG_WARNING, "This access token will be deleted.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
|
||||
DbUnlock(db, rtRef);
|
||||
DbDelete(db, 3, "tokens", "refresh", refreshToken);
|
||||
|
|
|
@ -83,7 +83,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "Registration endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
if (ArraySize(path) == 0)
|
||||
|
@ -91,7 +91,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
username = StrDuplicate(JsonValueAsString(val));
|
||||
|
@ -117,14 +117,14 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (!UserValidate(username, config->serverName))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_USERNAME);
|
||||
response = MatrixErrorCreate(M_INVALID_USERNAME, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (UserExists(db, username))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_USER_IN_USE);
|
||||
response = MatrixErrorCreate(M_USER_IN_USE, NULL);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (uiaResult < 0)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
else if (!uiaResult)
|
||||
|
@ -159,7 +159,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (kind && !StrEquals(kind, "user"))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -167,14 +167,14 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (!val)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (JsonValueType(val) != JSON_BOOLEAN)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
if (JsonValueType(val) != JSON_BOOLEAN)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -311,12 +311,12 @@ finish:
|
|||
if (!username)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
}
|
||||
else if (!UserValidate(username, config->serverName))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_USERNAME);
|
||||
response = MatrixErrorCreate(M_INVALID_USERNAME, NULL);
|
||||
}
|
||||
else if (!UserExists(db, username))
|
||||
{
|
||||
|
@ -326,13 +326,13 @@ finish:
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_USER_IN_USE);
|
||||
response = MatrixErrorCreate(M_USER_IN_USE, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,21 +38,21 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_NOT_JSON);
|
||||
return MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
}
|
||||
|
||||
val = HashMapGet(request, "client_secret");
|
||||
if (!val || JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (strlen(str) > 255 || StrBlank(str))
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (!val || JsonValueType(val) != JSON_INTEGER)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (val && JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (val && JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (val && JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (val && JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (val && JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (strlen(str) != 2)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
if (val && JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
@ -136,12 +136,12 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
{
|
||||
/* Should not be possible */
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_THREEPID_DENIED);
|
||||
response = MatrixErrorCreate(M_THREEPID_DENIED, NULL);
|
||||
|
||||
finish:
|
||||
JsonFree(request);
|
||||
|
|
|
@ -35,7 +35,7 @@ ROUTE_IMPL(RouteStaticResources, path, argp)
|
|||
{
|
||||
/* Should be impossible */
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
if (StrEquals(res, "js"))
|
||||
|
@ -148,7 +148,7 @@ ROUTE_IMPL(RouteStaticResources, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
return MatrixErrorCreate(M_NOT_FOUND);
|
||||
return MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,14 +47,14 @@ ROUTE_IMPL(RouteTokenValid, path, argp)
|
|||
if (HttpRequestMethodGet(args->context) != HTTP_GET)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_NOT_JSON);
|
||||
return MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
}
|
||||
|
||||
tokenstr = JsonValueAsString(HashMapGet(request, "token"));
|
||||
|
|
|
@ -41,7 +41,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
/* This should never happen */
|
||||
Log(LOG_ERR, "Programmer error in RouteUiaFallback()!");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
if (HttpRequestMethodGet(args->context) == HTTP_POST)
|
||||
|
@ -58,7 +58,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "UIA fallback failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
|
@ -66,7 +66,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
{
|
||||
ConfigUnlock(config);
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_NOT_JSON);
|
||||
return MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
}
|
||||
|
||||
flow = ArrayCreate();
|
||||
|
@ -80,7 +80,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
if (uiaResult < 0)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
else if (uiaResult)
|
||||
{
|
||||
|
@ -94,14 +94,14 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
else if (HttpRequestMethodGet(args->context) != HTTP_GET)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
sessionId = HashMapGet(requestParams, "session");
|
||||
if (!sessionId)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_MISSING_PARAM);
|
||||
return MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
}
|
||||
|
||||
HttpResponseHeader(args->context, "Content-Type", "text/html");
|
||||
|
|
|
@ -54,7 +54,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "User profile endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
serverName = config->serverName;
|
||||
|
@ -64,14 +64,14 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
if (!userId)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
if (strcmp(userId->server, serverName))
|
||||
{
|
||||
/* TODO: Implement lookup over federation. */
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
if (!request)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_NOT_JSON);
|
||||
response = MatrixErrorCreate(M_NOT_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
response = MatrixGetAccessToken(args->context, &token);
|
||||
|
@ -130,7 +130,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
entry = ArrayGet(path, 1);
|
||||
|
@ -149,25 +149,25 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
}
|
||||
/* User is not allowed to carry-on the action */
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
default:
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
break;
|
||||
}
|
||||
finish:
|
||||
|
|
|
@ -41,7 +41,7 @@ ROUTE_IMPL(RouteWellKnown, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "Well-known endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
if (StrEquals(ArrayGet(path, 0), "client"))
|
||||
|
@ -51,7 +51,7 @@ ROUTE_IMPL(RouteWellKnown, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
}
|
||||
|
||||
ConfigUnlock(config);
|
||||
|
|
|
@ -49,7 +49,7 @@ ROUTE_IMPL(RouteWhoami, path, argp)
|
|||
{
|
||||
Log(LOG_ERR, "Who am I endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
(void) path;
|
||||
|
@ -67,7 +67,7 @@ ROUTE_IMPL(RouteWhoami, path, argp)
|
|||
if (!user)
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN);
|
||||
response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -243,7 +243,7 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
|
|||
if (JsonValueType(val) != JSON_OBJECT)
|
||||
{
|
||||
HttpResponseStatus(context, HTTP_BAD_REQUEST);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
|
|||
if (!val || JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(context, HTTP_BAD_REQUEST);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,7 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
|
|||
if (!val || JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
HttpResponseStatus(context, HTTP_BAD_REQUEST);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
ret = 0;
|
||||
goto finish;
|
||||
}
|
||||
|
|
|
@ -110,9 +110,10 @@ extern void MatrixHttpHandler(HttpServerContext *, void *);
|
|||
|
||||
/**
|
||||
* A convenience function that constructs an error payload, including
|
||||
* the error code and message, given just a MatrixError.
|
||||
* the error code and message, given a MatrixError and an optional
|
||||
* message.
|
||||
*/
|
||||
extern HashMap * MatrixErrorCreate(MatrixError);
|
||||
extern HashMap * MatrixErrorCreate(MatrixError, char *);
|
||||
|
||||
/**
|
||||
* Read the request headers and parameters, and attempt to obtain an
|
||||
|
|
Loading…
Reference in a new issue