Apply patch to make MatrixErrorCreate() take a custom message.

This commit is contained in:
Jordan Bancino 2023-08-05 19:26:03 +00:00
parent 28d9e1cb3b
commit 6ef965d1e0
21 changed files with 152 additions and 146 deletions

View file

@ -44,8 +44,10 @@ Milestone: v0.4.0
higher level logic set the default from there. higher level logic set the default from there.
[ ] Write man page. [ ] 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 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. [x] Make sure admin registration token is printed to log, not stdout.
Unless they are the same, of course. Unless they are the same, of course.
[ ] Refactor Config to use j2s. [ ] Refactor Config to use j2s.

View file

@ -82,7 +82,7 @@ MatrixHttpHandler(HttpServerContext * context, void *argp)
{ {
HttpResponseHeader(context, "Content-Type", "application/json"); HttpResponseHeader(context, "Content-Type", "application/json");
HttpResponseStatus(context, HTTP_NOT_FOUND); 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 * HashMap *
MatrixErrorCreate(MatrixError errorArg) MatrixErrorCreate(MatrixError errorArg, char *msg)
{ {
HashMap *errorObj; HashMap *errorObj;
char *errcode; char *errcode;
@ -261,6 +261,11 @@ MatrixErrorCreate(MatrixError errorArg)
return NULL; return NULL;
} }
if (msg)
{
error = msg;
}
errorObj = HashMapCreate(); errorObj = HashMapCreate();
if (!errorObj) if (!errorObj)
{ {
@ -289,7 +294,7 @@ MatrixGetAccessToken(HttpServerContext * context, char **accessToken)
if (strncmp(token, "Bearer ", 7) != 0) if (strncmp(token, "Bearer ", 7) != 0)
{ {
HttpResponseStatus(context, HTTP_UNAUTHORIZED); HttpResponseStatus(context, HTTP_UNAUTHORIZED);
return MatrixErrorCreate(M_MISSING_TOKEN); return MatrixErrorCreate(M_MISSING_TOKEN, NULL);
} }
/* Seek past "Bearer" */ /* Seek past "Bearer" */
@ -310,7 +315,7 @@ MatrixGetAccessToken(HttpServerContext * context, char **accessToken)
if (!token) if (!token)
{ {
HttpResponseStatus(context, HTTP_UNAUTHORIZED); HttpResponseStatus(context, HTTP_UNAUTHORIZED);
return MatrixErrorCreate(M_MISSING_TOKEN); return MatrixErrorCreate(M_MISSING_TOKEN, NULL);
} }
} }

View file

@ -71,7 +71,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
{ {
Log(LOG_ERR, "Password endpoint failed to lock configuration."); Log(LOG_ERR, "Password endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
(void) path; (void) path;
@ -79,7 +79,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_POST) if (HttpRequestMethodGet(args->context) != HTTP_POST)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish; goto finish;
} }
@ -93,7 +93,7 @@ ROUTE_IMPL(RouteChangePwd, 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;
} }
@ -107,7 +107,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
if (uiaResult < 0) if (uiaResult < 0)
{ {
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;
} }
else if (!uiaResult) else if (!uiaResult)
@ -120,7 +120,7 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
{ {
JsonFree(request); JsonFree(request);
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -136,7 +136,7 @@ ROUTE_IMPL(RouteChangePwd, 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;
} }

View file

@ -52,14 +52,14 @@ ROUTE_IMPL(RouteConfig, 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;
} }
if (!(UserGetPrivileges(user) & USER_CONFIG)) if (!(UserGetPrivileges(user) & USER_CONFIG))
{ {
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
goto finish; goto finish;
} }
@ -68,7 +68,7 @@ ROUTE_IMPL(RouteConfig, path, argp)
{ {
Log(LOG_ERR, "Config endpoint failed to lock configuration."); Log(LOG_ERR, "Config 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;
} }
@ -82,7 +82,7 @@ ROUTE_IMPL(RouteConfig, 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);
break; break;
} }
@ -90,7 +90,7 @@ ROUTE_IMPL(RouteConfig, path, argp)
if (!newConf) if (!newConf)
{ {
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN, NULL);
break; break;
} }
@ -108,14 +108,13 @@ ROUTE_IMPL(RouteConfig, path, argp)
else else
{ {
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN, NULL);
} }
} }
else else
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
/* TODO: Attach newConf->err as message */ response = MatrixErrorCreate(M_BAD_JSON, newConf->err);
response = MatrixErrorCreate(M_BAD_JSON);
} }
ConfigFree(newConf); ConfigFree(newConf);
@ -125,7 +124,7 @@ ROUTE_IMPL(RouteConfig, path, argp)
/* TODO: Support incremental changes to the config */ /* TODO: Support incremental changes to the config */
default: default:
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
break; break;
} }

View file

@ -53,14 +53,14 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
{ {
Log(LOG_ERR, "Deactivate endpoint failed to lock configuration."); Log(LOG_ERR, "Deactivate 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;
} }
if (HttpRequestMethodGet(args->context) != HTTP_POST) if (HttpRequestMethodGet(args->context) != HTTP_POST)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish; goto finish;
} }
@ -68,7 +68,7 @@ ROUTE_IMPL(RouteDeactivate, 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;
} }
@ -96,7 +96,7 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
if (uiaResult < 0) if (uiaResult < 0)
{ {
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;
} }
else if (!uiaResult) else if (!uiaResult)
@ -122,14 +122,14 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
if (!user) if (!user)
{ {
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN); response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
goto finish; goto finish;
} }
if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user)) if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user))
{ {
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;
} }

View file

@ -73,14 +73,14 @@ ROUTE_IMPL(RouteFilter, path, argp)
{ {
/* Should be impossible */ /* Should be impossible */
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
serverName = GetServerName(db); serverName = GetServerName(db);
if (!serverName) if (!serverName)
{ {
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;
} }
@ -88,14 +88,14 @@ ROUTE_IMPL(RouteFilter, path, argp)
if (!id) if (!id)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_INVALID_PARAM); response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
goto finish; goto finish;
} }
if (!StrEquals(id->server, serverName)) if (!StrEquals(id->server, serverName))
{ {
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
response = MatrixErrorCreate(M_UNAUTHORIZED); response = MatrixErrorCreate(M_UNAUTHORIZED, NULL);
goto finish; goto finish;
} }
@ -109,14 +109,14 @@ ROUTE_IMPL(RouteFilter, path, argp)
if (!user) if (!user)
{ {
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN); response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
goto finish; goto finish;
} }
if (!StrEquals(id->localpart, UserGetName(user))) if (!StrEquals(id->localpart, UserGetName(user)))
{ {
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
response = MatrixErrorCreate(M_INVALID_PARAM); response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
goto finish; goto finish;
} }
@ -127,7 +127,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
if (!ref) if (!ref)
{ {
HttpResponseStatus(args->context, HTTP_NOT_FOUND); HttpResponseStatus(args->context, HTTP_NOT_FOUND);
response = MatrixErrorCreate(M_NOT_FOUND); response = MatrixErrorCreate(M_NOT_FOUND, NULL);
goto finish; goto finish;
} }
@ -147,14 +147,13 @@ ROUTE_IMPL(RouteFilter, 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;
} }
if (!FilterFromJson(request, &filter, &parseErr)) if (!FilterFromJson(request, &filter, &parseErr))
{ {
/* TODO: send parseErr to client */ response = MatrixErrorCreate(M_BAD_JSON, parseErr);
response = MatrixErrorCreate(M_BAD_JSON);
goto finish; goto finish;
} }
@ -163,7 +162,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
if (!filterId) if (!filterId)
{ {
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;
} }
@ -172,7 +171,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
{ {
Free(filterId); Free(filterId);
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;
} }
@ -191,7 +190,7 @@ ROUTE_IMPL(RouteFilter, path, argp)
else else
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
} }
finish: finish:

View file

@ -63,7 +63,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
{ {
Log(LOG_ERR, "Login endpoint failed to lock configuration."); Log(LOG_ERR, "Login endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
(void) path; (void) path;
@ -84,7 +84,7 @@ ROUTE_IMPL(RouteLogin, 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);
break; break;
} }
@ -92,14 +92,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!val) if (!val)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
break; break;
} }
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -107,7 +107,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!StrEquals(type, "m.login.password")) if (!StrEquals(type, "m.login.password"))
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
break; break;
} }
@ -115,14 +115,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!val) if (!val)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
break; break;
} }
if (JsonValueType(val) != JSON_OBJECT) if (JsonValueType(val) != JSON_OBJECT)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -132,14 +132,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!val) if (!val)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
break; break;
} }
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -147,7 +147,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!StrEquals(type, "m.id.user")) if (!StrEquals(type, "m.id.user"))
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
break; break;
} }
@ -155,14 +155,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!val) if (!val)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
break; break;
} }
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -170,7 +170,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!userId) if (!userId)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -178,7 +178,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
|| !UserExists(db, userId->localpart)) || !UserExists(db, userId->localpart))
{ {
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
break; break;
} }
@ -188,7 +188,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -201,7 +201,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -212,14 +212,14 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!val) if (!val)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
break; break;
} }
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -231,7 +231,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (JsonValueType(val) != JSON_BOOLEAN) if (JsonValueType(val) != JSON_BOOLEAN)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -243,7 +243,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
if (!user) if (!user)
{ {
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
break; break;
} }
@ -252,7 +252,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
UserUnlock(user); UserUnlock(user);
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_USER_DEACTIVATED); response = MatrixErrorCreate(M_USER_DEACTIVATED, NULL);
break; break;
} }
@ -264,7 +264,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
UserUnlock(user); UserUnlock(user);
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
break; break;
} }
@ -301,7 +301,7 @@ ROUTE_IMPL(RouteLogin, path, argp)
break; break;
default: default:
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
break; break;
} }

View file

@ -45,7 +45,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_POST) if (HttpRequestMethodGet(args->context) != HTTP_POST)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_UNRECOGNIZED); return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
} }
response = MatrixGetAccessToken(args->context, &tokenstr); response = MatrixGetAccessToken(args->context, &tokenstr);
@ -58,7 +58,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
if (!user) if (!user)
{ {
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
return MatrixErrorCreate(M_UNKNOWN_TOKEN); return MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
} }
if (ArraySize(path) == 1) if (ArraySize(path) == 1)
@ -66,7 +66,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
if (!StrEquals(ArrayGet(path, 0), "all")) if (!StrEquals(ArrayGet(path, 0), "all"))
{ {
HttpResponseStatus(args->context, HTTP_NOT_FOUND); HttpResponseStatus(args->context, HTTP_NOT_FOUND);
response = MatrixErrorCreate(M_NOT_FOUND); response = MatrixErrorCreate(M_NOT_FOUND, NULL);
goto finish; goto finish;
} }
@ -75,7 +75,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
/* If we can't delete all of our tokens, then something is /* If we can't delete all of our tokens, then something is
* wrong. */ * wrong. */
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;
} }
response = HashMapCreate(); response = HashMapCreate();
@ -85,7 +85,7 @@ ROUTE_IMPL(RouteLogout, path, argp)
if (!UserDeleteToken(user, tokenstr)) if (!UserDeleteToken(user, tokenstr))
{ {
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;
} }

View file

@ -49,14 +49,14 @@ ROUTE_IMPL(RoutePrivileges, 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;
} }
if (!(UserGetPrivileges(user) & USER_GRANT_PRIVILEGES)) if (!(UserGetPrivileges(user) & USER_GRANT_PRIVILEGES))
{ {
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
goto finish; goto finish;
} }
@ -69,7 +69,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
if (!user) if (!user)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_INVALID_PARAM); response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
goto finish; goto finish;
} }
} }
@ -83,7 +83,7 @@ ROUTE_IMPL(RoutePrivileges, 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);
break; break;
} }
@ -91,7 +91,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
if (!val || JsonValueType(val) != JSON_ARRAY) if (!val || JsonValueType(val) != JSON_ARRAY)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
break; break;
} }
@ -117,7 +117,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
if (!UserSetPrivileges(user, privileges)) if (!UserSetPrivileges(user, privileges))
{ {
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN, NULL);
break; break;
} }
@ -128,7 +128,7 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
break; break;
default: default:
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish; goto finish;
break; break;
} }

View file

@ -48,14 +48,14 @@ ROUTE_IMPL(RouteProcControl, 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;
} }
if (!(UserGetPrivileges(user) & USER_PROC_CONTROL)) if (!(UserGetPrivileges(user) & USER_PROC_CONTROL))
{ {
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
goto finish; goto finish;
} }
@ -73,7 +73,7 @@ ROUTE_IMPL(RouteProcControl, path, argp)
else else
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish; goto finish;
} }
break; break;
@ -90,12 +90,12 @@ ROUTE_IMPL(RouteProcControl, path, argp)
else else
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish; goto finish;
} }
default: default:
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish; goto finish;
break; break;
} }

View file

@ -56,21 +56,21 @@ ROUTE_IMPL(RouteRefresh, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_POST) if (HttpRequestMethodGet(args->context) != HTTP_POST)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_UNRECOGNIZED); return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
} }
request = JsonDecode(HttpServerStream(args->context)); request = JsonDecode(HttpServerStream(args->context));
if (!request) if (!request)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_NOT_JSON); return MatrixErrorCreate(M_NOT_JSON, NULL);
} }
val = HashMapGet(request, "refresh_token"); val = HashMapGet(request, "refresh_token");
if (!val || JsonValueType(val) != JSON_STRING) if (!val || JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -82,7 +82,7 @@ ROUTE_IMPL(RouteRefresh, path, argp)
if (!rtRef) if (!rtRef)
{ {
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;
} }
@ -96,7 +96,7 @@ ROUTE_IMPL(RouteRefresh, path, argp)
refreshToken); refreshToken);
Log(LOG_WARNING, "This refresh token will be deleted."); Log(LOG_WARNING, "This refresh token will be deleted.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN, NULL);
DbUnlock(db, rtRef); DbUnlock(db, rtRef);
DbDelete(db, 3, "tokens", "refresh", refreshToken); DbDelete(db, 3, "tokens", "refresh", refreshToken);
@ -114,7 +114,7 @@ ROUTE_IMPL(RouteRefresh, path, argp)
oldAccessToken); oldAccessToken);
Log(LOG_WARNING, "This access token will be deleted."); Log(LOG_WARNING, "This access token will be deleted.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN, NULL);
DbUnlock(db, rtRef); DbUnlock(db, rtRef);
DbDelete(db, 3, "tokens", "refresh", refreshToken); DbDelete(db, 3, "tokens", "refresh", refreshToken);

View file

@ -83,7 +83,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
{ {
Log(LOG_ERR, "Registration endpoint failed to lock configuration."); Log(LOG_ERR, "Registration endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
if (ArraySize(path) == 0) if (ArraySize(path) == 0)
@ -91,7 +91,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_POST) if (HttpRequestMethodGet(args->context) != HTTP_POST)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto end; goto end;
} }
@ -99,7 +99,7 @@ ROUTE_IMPL(RouteRegister, 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 end; goto end;
} }
@ -109,7 +109,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
username = StrDuplicate(JsonValueAsString(val)); username = StrDuplicate(JsonValueAsString(val));
@ -117,14 +117,14 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (!UserValidate(username, config->serverName)) if (!UserValidate(username, config->serverName))
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_INVALID_USERNAME); response = MatrixErrorCreate(M_INVALID_USERNAME, NULL);
goto finish; goto finish;
} }
if (UserExists(db, username)) if (UserExists(db, username))
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_USER_IN_USE); response = MatrixErrorCreate(M_USER_IN_USE, NULL);
goto finish; goto finish;
} }
} }
@ -144,7 +144,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (uiaResult < 0) if (uiaResult < 0)
{ {
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;
} }
else if (!uiaResult) else if (!uiaResult)
@ -159,7 +159,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (kind && !StrEquals(kind, "user")) if (kind && !StrEquals(kind, "user"))
{ {
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_INVALID_PARAM); response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
goto finish; goto finish;
} }
@ -167,14 +167,14 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (!val) if (!val)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
goto finish; goto finish;
} }
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -186,7 +186,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -199,7 +199,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (JsonValueType(val) != JSON_BOOLEAN) if (JsonValueType(val) != JSON_BOOLEAN)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -212,7 +212,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (JsonValueType(val) != JSON_STRING) if (JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -225,7 +225,7 @@ ROUTE_IMPL(RouteRegister, path, argp)
if (JsonValueType(val) != JSON_BOOLEAN) if (JsonValueType(val) != JSON_BOOLEAN)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -311,12 +311,12 @@ finish:
if (!username) if (!username)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
} }
else if (!UserValidate(username, config->serverName)) else if (!UserValidate(username, config->serverName))
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_INVALID_USERNAME); response = MatrixErrorCreate(M_INVALID_USERNAME, NULL);
} }
else if (!UserExists(db, username)) else if (!UserExists(db, username))
{ {
@ -326,13 +326,13 @@ finish:
else else
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_USER_IN_USE); response = MatrixErrorCreate(M_USER_IN_USE, NULL);
} }
} }
else else
{ {
HttpResponseStatus(args->context, HTTP_NOT_FOUND); HttpResponseStatus(args->context, HTTP_NOT_FOUND);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
} }
} }

View file

@ -38,21 +38,21 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_POST) if (HttpRequestMethodGet(args->context) != HTTP_POST)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_UNRECOGNIZED); return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
} }
request = JsonDecode(HttpServerStream(args->context)); request = JsonDecode(HttpServerStream(args->context));
if (!request) if (!request)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_NOT_JSON); return MatrixErrorCreate(M_NOT_JSON, NULL);
} }
val = HashMapGet(request, "client_secret"); val = HashMapGet(request, "client_secret");
if (!val || JsonValueType(val) != JSON_STRING) if (!val || JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -60,7 +60,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (strlen(str) > 255 || StrBlank(str)) if (strlen(str) > 255 || StrBlank(str))
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -68,7 +68,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (!val || JsonValueType(val) != JSON_INTEGER) if (!val || JsonValueType(val) != JSON_INTEGER)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -76,7 +76,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (val && JsonValueType(val) != JSON_STRING) if (val && JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -84,7 +84,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (val && JsonValueType(val) != JSON_STRING) if (val && JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -92,7 +92,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (val && JsonValueType(val) != JSON_STRING) if (val && JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -102,7 +102,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (val && JsonValueType(val) != JSON_STRING) if (val && JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
} }
@ -112,7 +112,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (val && JsonValueType(val) != JSON_STRING) if (val && JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -120,7 +120,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (strlen(str) != 2) if (strlen(str) != 2)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
@ -128,7 +128,7 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
if (val && JsonValueType(val) != JSON_STRING) if (val && JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_BAD_JSON); response = MatrixErrorCreate(M_BAD_JSON, NULL);
goto finish; goto finish;
} }
} }
@ -136,12 +136,12 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
{ {
/* Should not be possible */ /* Should not be possible */
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;
} }
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_THREEPID_DENIED); response = MatrixErrorCreate(M_THREEPID_DENIED, NULL);
finish: finish:
JsonFree(request); JsonFree(request);

View file

@ -35,7 +35,7 @@ ROUTE_IMPL(RouteStaticResources, path, argp)
{ {
/* Should be impossible */ /* Should be impossible */
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
if (StrEquals(res, "js")) if (StrEquals(res, "js"))
@ -148,7 +148,7 @@ ROUTE_IMPL(RouteStaticResources, path, argp)
else else
{ {
HttpResponseStatus(args->context, HTTP_NOT_FOUND); HttpResponseStatus(args->context, HTTP_NOT_FOUND);
return MatrixErrorCreate(M_NOT_FOUND); return MatrixErrorCreate(M_NOT_FOUND, NULL);
} }

View file

@ -47,14 +47,14 @@ ROUTE_IMPL(RouteTokenValid, path, argp)
if (HttpRequestMethodGet(args->context) != HTTP_GET) if (HttpRequestMethodGet(args->context) != HTTP_GET)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_UNRECOGNIZED); return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
} }
request = JsonDecode(HttpServerStream(args->context)); request = JsonDecode(HttpServerStream(args->context));
if (!request) if (!request)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_NOT_JSON); return MatrixErrorCreate(M_NOT_JSON, NULL);
} }
tokenstr = JsonValueAsString(HashMapGet(request, "token")); tokenstr = JsonValueAsString(HashMapGet(request, "token"));

View file

@ -41,7 +41,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
/* This should never happen */ /* This should never happen */
Log(LOG_ERR, "Programmer error in RouteUiaFallback()!"); Log(LOG_ERR, "Programmer error in RouteUiaFallback()!");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
if (HttpRequestMethodGet(args->context) == HTTP_POST) if (HttpRequestMethodGet(args->context) == HTTP_POST)
@ -58,7 +58,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
{ {
Log(LOG_ERR, "UIA fallback failed to lock configuration."); Log(LOG_ERR, "UIA fallback failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
request = JsonDecode(HttpServerStream(args->context)); request = JsonDecode(HttpServerStream(args->context));
@ -66,7 +66,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
{ {
ConfigUnlock(config); ConfigUnlock(config);
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_NOT_JSON); return MatrixErrorCreate(M_NOT_JSON, NULL);
} }
flow = ArrayCreate(); flow = ArrayCreate();
@ -80,7 +80,7 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
if (uiaResult < 0) if (uiaResult < 0)
{ {
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN, NULL);
} }
else if (uiaResult) else if (uiaResult)
{ {
@ -94,14 +94,14 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
else if (HttpRequestMethodGet(args->context) != HTTP_GET) else if (HttpRequestMethodGet(args->context) != HTTP_GET)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_UNRECOGNIZED); return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
} }
sessionId = HashMapGet(requestParams, "session"); sessionId = HashMapGet(requestParams, "session");
if (!sessionId) if (!sessionId)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
return MatrixErrorCreate(M_MISSING_PARAM); return MatrixErrorCreate(M_MISSING_PARAM, NULL);
} }
HttpResponseHeader(args->context, "Content-Type", "text/html"); HttpResponseHeader(args->context, "Content-Type", "text/html");

View file

@ -54,7 +54,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
{ {
Log(LOG_ERR, "User profile endpoint failed to lock configuration."); Log(LOG_ERR, "User profile endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
serverName = config->serverName; serverName = config->serverName;
@ -64,14 +64,14 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
if (!userId) if (!userId)
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_INVALID_PARAM); response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
goto finish; goto finish;
} }
if (strcmp(userId->server, serverName)) if (strcmp(userId->server, serverName))
{ {
/* TODO: Implement lookup over federation. */ /* TODO: Implement lookup over federation. */
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
goto finish; goto finish;
} }
@ -83,7 +83,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
if (!user) if (!user)
{ {
HttpResponseStatus(args->context, HTTP_NOT_FOUND); HttpResponseStatus(args->context, HTTP_NOT_FOUND);
response = MatrixErrorCreate(M_NOT_FOUND); response = MatrixErrorCreate(M_NOT_FOUND, NULL);
goto finish; goto finish;
} }
@ -118,7 +118,7 @@ ROUTE_IMPL(RouteUserProfile, 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;
} }
response = MatrixGetAccessToken(args->context, &token); response = MatrixGetAccessToken(args->context, &token);
@ -130,7 +130,7 @@ ROUTE_IMPL(RouteUserProfile, 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;
} }
entry = ArrayGet(path, 1); entry = ArrayGet(path, 1);
@ -149,25 +149,25 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
} }
/* User is not allowed to carry-on the action */ /* User is not allowed to carry-on the action */
HttpResponseStatus(args->context, HTTP_FORBIDDEN); HttpResponseStatus(args->context, HTTP_FORBIDDEN);
response = MatrixErrorCreate(M_FORBIDDEN); response = MatrixErrorCreate(M_FORBIDDEN, NULL);
goto finish; goto finish;
} }
else else
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNRECOGNIZED); response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
goto finish; goto finish;
} }
} }
else else
{ {
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_MISSING_PARAM); response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
goto finish; goto finish;
} }
default: default:
HttpResponseStatus(args->context, HTTP_BAD_REQUEST); HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
response = MatrixErrorCreate(M_UNKNOWN); response = MatrixErrorCreate(M_UNKNOWN, NULL);
break; break;
} }
finish: finish:

View file

@ -41,7 +41,7 @@ ROUTE_IMPL(RouteWellKnown, path, argp)
{ {
Log(LOG_ERR, "Well-known endpoint failed to lock configuration."); Log(LOG_ERR, "Well-known endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
if (StrEquals(ArrayGet(path, 0), "client")) if (StrEquals(ArrayGet(path, 0), "client"))
@ -51,7 +51,7 @@ ROUTE_IMPL(RouteWellKnown, path, argp)
else else
{ {
HttpResponseStatus(args->context, HTTP_NOT_FOUND); HttpResponseStatus(args->context, HTTP_NOT_FOUND);
response = MatrixErrorCreate(M_NOT_FOUND); response = MatrixErrorCreate(M_NOT_FOUND, NULL);
} }
ConfigUnlock(config); ConfigUnlock(config);

View file

@ -49,7 +49,7 @@ ROUTE_IMPL(RouteWhoami, path, argp)
{ {
Log(LOG_ERR, "Who am I endpoint failed to lock configuration."); Log(LOG_ERR, "Who am I endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR); HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
return MatrixErrorCreate(M_UNKNOWN); return MatrixErrorCreate(M_UNKNOWN, NULL);
} }
(void) path; (void) path;
@ -67,7 +67,7 @@ ROUTE_IMPL(RouteWhoami, path, argp)
if (!user) if (!user)
{ {
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
response = MatrixErrorCreate(M_UNKNOWN_TOKEN); response = MatrixErrorCreate(M_UNKNOWN_TOKEN, NULL);
goto finish; goto finish;
} }

View file

@ -243,7 +243,7 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
if (JsonValueType(val) != JSON_OBJECT) if (JsonValueType(val) != JSON_OBJECT)
{ {
HttpResponseStatus(context, HTTP_BAD_REQUEST); HttpResponseStatus(context, HTTP_BAD_REQUEST);
*response = MatrixErrorCreate(M_BAD_JSON); *response = MatrixErrorCreate(M_BAD_JSON, NULL);
return 0; return 0;
} }
@ -253,7 +253,7 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
if (!val || JsonValueType(val) != JSON_STRING) if (!val || JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(context, HTTP_BAD_REQUEST); HttpResponseStatus(context, HTTP_BAD_REQUEST);
*response = MatrixErrorCreate(M_BAD_JSON); *response = MatrixErrorCreate(M_BAD_JSON, NULL);
return 0; return 0;
} }
@ -312,7 +312,7 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
if (!val || JsonValueType(val) != JSON_STRING) if (!val || JsonValueType(val) != JSON_STRING)
{ {
HttpResponseStatus(context, HTTP_BAD_REQUEST); HttpResponseStatus(context, HTTP_BAD_REQUEST);
*response = MatrixErrorCreate(M_BAD_JSON); *response = MatrixErrorCreate(M_BAD_JSON, NULL);
ret = 0; ret = 0;
goto finish; goto finish;
} }

View file

@ -110,9 +110,10 @@ extern void MatrixHttpHandler(HttpServerContext *, void *);
/** /**
* A convenience function that constructs an error payload, including * 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 * Read the request headers and parameters, and attempt to obtain an