From 6ef965d1e0acbc3385c394407c173ebbd26a7b40 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Sat, 5 Aug 2023 19:26:03 +0000 Subject: [PATCH] Apply patch to make MatrixErrorCreate() take a custom message. --- TODO.txt | 4 ++- src/Matrix.c | 13 ++++++--- src/Routes/RouteChangePwd.c | 12 ++++---- src/Routes/RouteConfig.c | 17 ++++++------ src/Routes/RouteDeactivate.c | 12 ++++---- src/Routes/RouteFilter.c | 25 ++++++++--------- src/Routes/RouteLogin.c | 46 +++++++++++++++---------------- src/Routes/RouteLogout.c | 10 +++---- src/Routes/RoutePrivileges.c | 14 +++++----- src/Routes/RouteProcControl.c | 10 +++---- src/Routes/RouteRefresh.c | 12 ++++---- src/Routes/RouteRegister.c | 36 ++++++++++++------------ src/Routes/RouteRequestToken.c | 28 +++++++++---------- src/Routes/RouteStaticResources.c | 4 +-- src/Routes/RouteTokenValid.c | 4 +-- src/Routes/RouteUiaFallback.c | 12 ++++---- src/Routes/RouteUserProfile.c | 20 +++++++------- src/Routes/RouteWellKnown.c | 4 +-- src/Routes/RouteWhoami.c | 4 +-- src/Uia.c | 6 ++-- src/include/Matrix.h | 5 ++-- 21 files changed, 152 insertions(+), 146 deletions(-) diff --git a/TODO.txt b/TODO.txt index 6ca44b9..e2b7064 100644 --- a/TODO.txt +++ b/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. diff --git a/src/Matrix.c b/src/Matrix.c index 802979e..39a7914 100644 --- a/src/Matrix.c +++ b/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); } } diff --git a/src/Routes/RouteChangePwd.c b/src/Routes/RouteChangePwd.c index 90fee75..a0d1ccd 100644 --- a/src/Routes/RouteChangePwd.c +++ b/src/Routes/RouteChangePwd.c @@ -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; } diff --git a/src/Routes/RouteConfig.c b/src/Routes/RouteConfig.c index a3b7142..194a147 100644 --- a/src/Routes/RouteConfig.c +++ b/src/Routes/RouteConfig.c @@ -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; } diff --git a/src/Routes/RouteDeactivate.c b/src/Routes/RouteDeactivate.c index 309f8c2..09538f8 100644 --- a/src/Routes/RouteDeactivate.c +++ b/src/Routes/RouteDeactivate.c @@ -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; } diff --git a/src/Routes/RouteFilter.c b/src/Routes/RouteFilter.c index aeee5e6..5b79901 100644 --- a/src/Routes/RouteFilter.c +++ b/src/Routes/RouteFilter.c @@ -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: diff --git a/src/Routes/RouteLogin.c b/src/Routes/RouteLogin.c index 4e8d768..e73f599 100644 --- a/src/Routes/RouteLogin.c +++ b/src/Routes/RouteLogin.c @@ -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; } diff --git a/src/Routes/RouteLogout.c b/src/Routes/RouteLogout.c index ecaf4bd..c469ee1 100644 --- a/src/Routes/RouteLogout.c +++ b/src/Routes/RouteLogout.c @@ -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; } diff --git a/src/Routes/RoutePrivileges.c b/src/Routes/RoutePrivileges.c index 1d7bbe3..f0273ad 100644 --- a/src/Routes/RoutePrivileges.c +++ b/src/Routes/RoutePrivileges.c @@ -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; } diff --git a/src/Routes/RouteProcControl.c b/src/Routes/RouteProcControl.c index 4fad31b..adc8758 100644 --- a/src/Routes/RouteProcControl.c +++ b/src/Routes/RouteProcControl.c @@ -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; } diff --git a/src/Routes/RouteRefresh.c b/src/Routes/RouteRefresh.c index 04de9e9..624029d 100644 --- a/src/Routes/RouteRefresh.c +++ b/src/Routes/RouteRefresh.c @@ -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); diff --git a/src/Routes/RouteRegister.c b/src/Routes/RouteRegister.c index d9a366a..d8e4103 100644 --- a/src/Routes/RouteRegister.c +++ b/src/Routes/RouteRegister.c @@ -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); } } diff --git a/src/Routes/RouteRequestToken.c b/src/Routes/RouteRequestToken.c index 33970ca..46bba31 100644 --- a/src/Routes/RouteRequestToken.c +++ b/src/Routes/RouteRequestToken.c @@ -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); diff --git a/src/Routes/RouteStaticResources.c b/src/Routes/RouteStaticResources.c index a89b018..5d59705 100644 --- a/src/Routes/RouteStaticResources.c +++ b/src/Routes/RouteStaticResources.c @@ -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); } diff --git a/src/Routes/RouteTokenValid.c b/src/Routes/RouteTokenValid.c index e17cf43..157eb3b 100644 --- a/src/Routes/RouteTokenValid.c +++ b/src/Routes/RouteTokenValid.c @@ -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")); diff --git a/src/Routes/RouteUiaFallback.c b/src/Routes/RouteUiaFallback.c index eb4c2de..88e477b 100644 --- a/src/Routes/RouteUiaFallback.c +++ b/src/Routes/RouteUiaFallback.c @@ -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"); diff --git a/src/Routes/RouteUserProfile.c b/src/Routes/RouteUserProfile.c index 4a741bb..0c99338 100644 --- a/src/Routes/RouteUserProfile.c +++ b/src/Routes/RouteUserProfile.c @@ -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: diff --git a/src/Routes/RouteWellKnown.c b/src/Routes/RouteWellKnown.c index b62169f..855bf90 100644 --- a/src/Routes/RouteWellKnown.c +++ b/src/Routes/RouteWellKnown.c @@ -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); diff --git a/src/Routes/RouteWhoami.c b/src/Routes/RouteWhoami.c index 9532a46..66bf7c0 100644 --- a/src/Routes/RouteWhoami.c +++ b/src/Routes/RouteWhoami.c @@ -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; } diff --git a/src/Uia.c b/src/Uia.c index c2bedf0..de6b04e 100644 --- a/src/Uia.c +++ b/src/Uia.c @@ -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; } diff --git a/src/include/Matrix.h b/src/include/Matrix.h index 2239906..1d71e83 100644 --- a/src/include/Matrix.h +++ b/src/include/Matrix.h @@ -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