forked from Telodendria/Telodendria
Compare commits
No commits in common. "12061afe6267a066135a0653ca4b743cc85f43d7" and "18488d463e06f88c1c467b1ff71ed566168d3524" have entirely different histories.
12061afe62
...
18488d463e
19 changed files with 80 additions and 161 deletions
|
@ -65,8 +65,6 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
char *token;
|
||||
char *newPassword;
|
||||
|
||||
char *msg;
|
||||
|
||||
Config *config = ConfigLock(db);
|
||||
|
||||
if (!config)
|
||||
|
@ -80,9 +78,8 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
msg = "Route only supports POST.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -121,10 +118,9 @@ ROUTE_IMPL(RouteChangePwd, path, argp)
|
|||
newPassword = JsonValueAsString(HashMapGet(request, "new_password"));
|
||||
if (!newPassword)
|
||||
{
|
||||
msg = "'new_password' is unset or not a string.";
|
||||
JsonFree(request);
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
RouteArgs *args = argp;
|
||||
HashMap *response;
|
||||
char *token;
|
||||
char *msg;
|
||||
|
||||
User *user = NULL;
|
||||
Config *config = NULL;
|
||||
|
@ -60,19 +59,17 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
|
||||
if (!(UserGetPrivileges(user) & USER_CONFIG))
|
||||
{
|
||||
msg = "User does not have the 'CONFIG' privilege.";
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
config = ConfigLock(args->matrixArgs->db);
|
||||
if (!config)
|
||||
{
|
||||
msg = "Internal server error while locking configuration.";
|
||||
Log(LOG_ERR, "Config endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -93,9 +90,8 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
newConf = ConfigParse(request);
|
||||
if (!newConf)
|
||||
{
|
||||
msg = "Internal server error while parsing config.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -112,9 +108,8 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
}
|
||||
else
|
||||
{
|
||||
msg = "Internal server error while writing the config.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -142,9 +137,8 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
|
||||
if (!newConf)
|
||||
{
|
||||
msg = "Internal server error while parsing config.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -161,9 +155,8 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
}
|
||||
else
|
||||
{
|
||||
msg = "Internal server error while writing the config.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -177,9 +170,8 @@ ROUTE_IMPL(RouteConfig, path, argp)
|
|||
JsonFree(newJson);
|
||||
break;
|
||||
default:
|
||||
msg = "Unknown request method.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, "Unknown request method.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,8 @@ ROUTE_IMPL(RouteCreateRoom, path, argp)
|
|||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
err = "Unknown request method.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, err);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, "Unknown request method.");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,6 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
User *user = NULL;
|
||||
Config *config = ConfigLock(db);
|
||||
|
||||
char *msg;
|
||||
|
||||
(void) path;
|
||||
|
||||
if (!config)
|
||||
|
@ -61,9 +59,8 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
msg = "Route only accepts POST.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -131,9 +128,8 @@ ROUTE_IMPL(RouteDeactivate, path, argp)
|
|||
|
||||
if (!UserDeleteTokens(user, NULL) || !UserDeactivate(user, NULL, NULL))
|
||||
{
|
||||
msg = "Internal server error: couldn't remove user properly.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,8 +69,6 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
|
||||
char *userParam = ArrayGet(path, 0);
|
||||
|
||||
char *msg;
|
||||
|
||||
if (!userParam)
|
||||
{
|
||||
/* Should be impossible */
|
||||
|
@ -89,17 +87,15 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
id = UserIdParse(userParam, serverName);
|
||||
if (!id)
|
||||
{
|
||||
msg = "Invalid user ID.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, msg);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!StrEquals(id->server, serverName))
|
||||
{
|
||||
msg = "Cannot use /filter for non-local users.";
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_UNAUTHORIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNAUTHORIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -119,9 +115,8 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
|
||||
if (!StrEquals(id->localpart, UserGetName(user)))
|
||||
{
|
||||
msg = "Unauthorized to use /filter.";
|
||||
HttpResponseStatus(args->context, HTTP_UNAUTHORIZED);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, msg);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -131,9 +126,8 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
|
||||
if (!ref)
|
||||
{
|
||||
msg = "The filter for this user was not found.";
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, msg);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -167,9 +161,8 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
filterId = StrRandom(12);
|
||||
if (!filterId)
|
||||
{
|
||||
msg = "Couldn't generate random filter ID; this is unintended.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -177,9 +170,8 @@ ROUTE_IMPL(RouteFilter, path, argp)
|
|||
if (!ref)
|
||||
{
|
||||
Free(filterId);
|
||||
msg = "Couldn't write filter to the database, this is unintended.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,9 +107,8 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
|
||||
if (loginRequest.type != REQUEST_TYPE_PASSWORD)
|
||||
{
|
||||
msg = "Unsupported login type.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -118,7 +117,6 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
val = HashMapGet(identifier, "type");
|
||||
if (!val)
|
||||
{
|
||||
msg = "No login identifier type set.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
break;
|
||||
|
@ -126,18 +124,16 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
|
||||
if (JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
msg = "Invalid login identifier type.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
type = JsonValueAsString(val);
|
||||
if (!StrEquals(type, "m.id.user"))
|
||||
{
|
||||
msg = "Invalid login identifier type.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
break;
|
||||
}
|
||||
if (!LoginRequestUserIdentifierFromJson(identifier,
|
||||
|
@ -152,18 +148,16 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
userId = UserIdParse(userIdentifier.user, config->serverName);
|
||||
if (!userId)
|
||||
{
|
||||
msg = "Invalid user ID.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!StrEquals(userId->server, config->serverName)
|
||||
|| !UserExists(db, userId->localpart))
|
||||
{
|
||||
msg = "Unknown user ID.";
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -177,9 +171,8 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
|
||||
if (!user)
|
||||
{
|
||||
msg = "Couldn't lock user.";
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -197,11 +190,10 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
|
||||
if (!loginInfo)
|
||||
{
|
||||
msg = "Invalid creditentials for user.";
|
||||
UserUnlock(user);
|
||||
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -237,9 +229,8 @@ ROUTE_IMPL(RouteLogin, path, argp)
|
|||
|
||||
break;
|
||||
default:
|
||||
msg = "Route only accepts GET and POST.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,17 +38,14 @@ ROUTE_IMPL(RouteLogout, path, argp)
|
|||
|
||||
char *tokenstr;
|
||||
|
||||
char *msg;
|
||||
|
||||
Db *db = args->matrixArgs->db;
|
||||
|
||||
User *user;
|
||||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
msg = "This route only accepts POST.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
response = MatrixGetAccessToken(args->context, &tokenstr);
|
||||
|
@ -87,9 +84,8 @@ ROUTE_IMPL(RouteLogout, path, argp)
|
|||
{
|
||||
if (!UserDeleteToken(user, tokenstr))
|
||||
{
|
||||
msg = "Internal server error: couldn't delete token.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
JsonValue *val;
|
||||
int privileges;
|
||||
|
||||
char *msg;
|
||||
|
||||
response = MatrixGetAccessToken(args->context, &token);
|
||||
if (response)
|
||||
{
|
||||
|
@ -57,9 +55,8 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
|
||||
if (!(UserGetPrivileges(user) & USER_GRANT_PRIVILEGES))
|
||||
{
|
||||
msg = "User doesn't have the GRANT_PRIVILEGES privilege";
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -71,9 +68,8 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
user = UserLock(args->matrixArgs->db, ArrayGet(path, 0));
|
||||
if (!user)
|
||||
{
|
||||
msg = "Unknown user.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, msg);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
@ -94,9 +90,8 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
val = HashMapGet(request, "privileges");
|
||||
if (!val || JsonValueType(val) != JSON_ARRAY)
|
||||
{
|
||||
msg = "'privileges' is unset or not an array.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -121,9 +116,8 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
|
||||
if (!UserSetPrivileges(user, privileges))
|
||||
{
|
||||
msg = "Internal server error: couldn't set privileges.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -133,9 +127,8 @@ ROUTE_IMPL(RoutePrivileges, path, argp)
|
|||
HashMapSet(response, "privileges", JsonValueArray(UserEncodePrivileges(UserGetPrivileges(user))));
|
||||
break;
|
||||
default:
|
||||
msg = "Route only accepts POST, PUT, DELETE, and GET.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ ROUTE_IMPL(RouteProcControl, path, argp)
|
|||
char *op = ArrayGet(path, 0);
|
||||
HashMap *response;
|
||||
char *token;
|
||||
char *msg;
|
||||
User *user = NULL;
|
||||
|
||||
response = MatrixGetAccessToken(args->context, &token);
|
||||
|
@ -56,13 +55,11 @@ ROUTE_IMPL(RouteProcControl, path, argp)
|
|||
|
||||
if (!(UserGetPrivileges(user) & USER_PROC_CONTROL))
|
||||
{
|
||||
msg = "User doesn't have PROC_CONTROL privilege.";
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
msg = "Unknown operation.";
|
||||
switch (HttpRequestMethodGet(args->context))
|
||||
{
|
||||
case HTTP_POST:
|
||||
|
@ -77,7 +74,7 @@ ROUTE_IMPL(RouteProcControl, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
break;
|
||||
|
@ -109,12 +106,12 @@ ROUTE_IMPL(RouteProcControl, path, argp)
|
|||
else
|
||||
{
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
default:
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -45,8 +45,6 @@ ROUTE_IMPL(RouteRefresh, path, argp)
|
|||
UserAccessToken *newAccessToken;
|
||||
char *deviceId;
|
||||
|
||||
char *msg;
|
||||
|
||||
Db *db = args->matrixArgs->db;
|
||||
|
||||
User *user = NULL;
|
||||
|
@ -57,9 +55,8 @@ ROUTE_IMPL(RouteRefresh, path, argp)
|
|||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
msg = "This route only accepts POST.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
|
@ -72,9 +69,8 @@ ROUTE_IMPL(RouteRefresh, path, argp)
|
|||
val = HashMapGet(request, "refresh_token");
|
||||
if (!val || JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
msg = "'refresh_token' is unset or not a string.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,10 +86,9 @@ ROUTE_IMPL(RouteRegister, path, argp)
|
|||
|
||||
if (!config)
|
||||
{
|
||||
msg = "Internal server error while locking configuration.";
|
||||
Log(LOG_ERR, "Registration endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
if (ArraySize(path) == 0)
|
||||
|
@ -255,9 +254,8 @@ finish:
|
|||
|
||||
if (!username)
|
||||
{
|
||||
msg = "'username' path parameter is not set.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, msg);
|
||||
response = MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
}
|
||||
else if (!UserValidate(username, config->serverName))
|
||||
{
|
||||
|
|
|
@ -54,9 +54,8 @@ ROUTE_IMPL(RouteRequestToken, path, argp)
|
|||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||
{
|
||||
msg = "This route only accepts POST.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
|
|
|
@ -47,8 +47,8 @@ ROUTE_IMPL(RouteStaticResources, path, argp)
|
|||
"function findGetParameter(parameterName) {"
|
||||
" var result = null;"
|
||||
" var tmp = [];"
|
||||
" var items = location.search.substr(1).split(\"&\");"
|
||||
" for (var index = 0; index < items.length; index++) {"
|
||||
" var items = location.search.substr(1).split(\"&\");"
|
||||
" for (var index = 0; index < items.length; index++) {"
|
||||
" tmp = items[index].split(\"=\");"
|
||||
" if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);"
|
||||
" }"
|
||||
|
|
|
@ -41,15 +41,13 @@ ROUTE_IMPL(RouteTokenValid, path, argp)
|
|||
RegTokenInfo *info = NULL;
|
||||
|
||||
char *tokenstr;
|
||||
char *msg;
|
||||
|
||||
(void) path;
|
||||
|
||||
if (HttpRequestMethodGet(args->context) != HTTP_GET)
|
||||
{
|
||||
msg = "This route only accepts GET.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
|
|
|
@ -36,8 +36,6 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
char *authType = ArrayGet(path, 0);
|
||||
char *sessionId;
|
||||
|
||||
char *msg;
|
||||
|
||||
if (!authType)
|
||||
{
|
||||
/* This should never happen */
|
||||
|
@ -58,10 +56,9 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
config = ConfigLock(args->matrixArgs->db);
|
||||
if (!config)
|
||||
{
|
||||
msg = "Internal server error: failed to lock configuration.";
|
||||
Log(LOG_ERR, "UIA fallback failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
request = JsonDecode(HttpServerStream(args->context));
|
||||
|
@ -96,17 +93,15 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
}
|
||||
else if (HttpRequestMethodGet(args->context) != HTTP_GET)
|
||||
{
|
||||
msg = "Route only supports GET.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
return MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
}
|
||||
|
||||
sessionId = HashMapGet(requestParams, "session");
|
||||
if (!sessionId)
|
||||
{
|
||||
msg = "'session' parameter is unset.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
return MatrixErrorCreate(M_MISSING_PARAM, msg);
|
||||
return MatrixErrorCreate(M_MISSING_PARAM, NULL);
|
||||
}
|
||||
|
||||
HttpResponseHeader(args->context, "Content-Type", "text/html");
|
||||
|
@ -126,25 +121,25 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
HtmlEndForm(stream);
|
||||
HtmlBeginJs(stream);
|
||||
StreamPrintf(stream,
|
||||
"function buildRequest() {"
|
||||
"function buildRequest() {"
|
||||
" let user = document.getElementById('user').value;"
|
||||
" let pass = document.getElementById('password').value;"
|
||||
" if (!user || !pass) {"
|
||||
" setFormError('Please specify a username and password.');"
|
||||
" return false;"
|
||||
" }"
|
||||
" return {"
|
||||
" auth: {"
|
||||
" type: '%s',"
|
||||
" identifier: {"
|
||||
" type: 'm.id.user',"
|
||||
" user: user"
|
||||
" },"
|
||||
" password: pass,"
|
||||
" session: '%s'"
|
||||
" }"
|
||||
" };"
|
||||
"}", authType, sessionId);
|
||||
" let pass = document.getElementById('password').value;"
|
||||
" if (!user || !pass) {"
|
||||
" setFormError('Please specify a username and password.');"
|
||||
" return false;"
|
||||
" }"
|
||||
" return {"
|
||||
" auth: {"
|
||||
" type: '%s',"
|
||||
" identifier: {"
|
||||
" type: 'm.id.user',"
|
||||
" user: user"
|
||||
" },"
|
||||
" password: pass,"
|
||||
" session: '%s'"
|
||||
" }"
|
||||
" };"
|
||||
"}", authType, sessionId);
|
||||
HtmlEndJs(stream);
|
||||
}
|
||||
else if (StrEquals(authType, "m.login.registration_token"))
|
||||
|
@ -191,10 +186,10 @@ ROUTE_IMPL(RouteUiaFallback, path, argp)
|
|||
"function processResponse(xhr) {"
|
||||
" let r = JSON.parse(xhr.responseText);"
|
||||
" console.log(r);"
|
||||
" if (xhr.status == 200 || r.completed.includes('%s')) {"
|
||||
" if (xhr.status == 200 || r.completed.includes('%s')) {"
|
||||
" if (window.onAuthDone) {"
|
||||
" window.onAuthDone();"
|
||||
" } else if (window.opener && window.opener.postMessage) {"
|
||||
" } else if (window.opener && window.opener.postMessage) {"
|
||||
" window.opener.postMessage('authDone', '*');"
|
||||
" } else {"
|
||||
" setFormError('Client error.');"
|
||||
|
|
|
@ -48,8 +48,6 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
char *token = NULL;
|
||||
char *value = NULL;
|
||||
|
||||
char *msg;
|
||||
|
||||
Config *config = ConfigLock(db);
|
||||
|
||||
if (!config)
|
||||
|
@ -65,18 +63,15 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
userId = UserIdParse(username, serverName);
|
||||
if (!userId)
|
||||
{
|
||||
msg = "Invalid user ID.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, msg);
|
||||
response = MatrixErrorCreate(M_INVALID_PARAM, NULL);
|
||||
goto finish;
|
||||
}
|
||||
if (strcmp(userId->server, serverName))
|
||||
{
|
||||
/* TODO: Implement lookup over federation. */
|
||||
msg = "User profile endpoint currently doesn't support lookup over "
|
||||
"federation.";
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -87,9 +82,8 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
user = UserLock(db, userId->localpart);
|
||||
if (!user)
|
||||
{
|
||||
msg = "Couldn't lock user.";
|
||||
HttpResponseStatus(args->context, HTTP_NOT_FOUND);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, msg);
|
||||
response = MatrixErrorCreate(M_NOT_FOUND, NULL);
|
||||
goto finish;
|
||||
}
|
||||
|
||||
|
@ -144,7 +138,7 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
StrEquals(entry, "avatar_url"))
|
||||
{
|
||||
/* Check if user has privilege to do that action. */
|
||||
if (StrEquals(userId->localpart, UserGetName(user)))
|
||||
if (strcmp(userId->localpart, UserGetName(user)) == 0)
|
||||
{
|
||||
value = JsonValueAsString(HashMapGet(request, entry));
|
||||
/* TODO: Make UserSetProfile notify other
|
||||
|
@ -154,16 +148,14 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
goto finish;
|
||||
}
|
||||
/* User is not allowed to carry-on the action */
|
||||
msg = "Cannot change another user's profile.";
|
||||
HttpResponseStatus(args->context, HTTP_FORBIDDEN);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, msg);
|
||||
response = MatrixErrorCreate(M_FORBIDDEN, NULL);
|
||||
goto finish;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "Invalid property being changed.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, msg);
|
||||
response = MatrixErrorCreate(M_UNRECOGNIZED, NULL);
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
@ -174,9 +166,8 @@ ROUTE_IMPL(RouteUserProfile, path, argp)
|
|||
goto finish;
|
||||
}
|
||||
default:
|
||||
msg = "Route only accepts GET and PUT.";
|
||||
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
break;
|
||||
}
|
||||
finish:
|
||||
|
|
|
@ -37,14 +37,11 @@ ROUTE_IMPL(RouteWellKnown, path, argp)
|
|||
|
||||
Config *config = ConfigLock(args->matrixArgs->db);
|
||||
|
||||
char *msg;
|
||||
|
||||
if (!config)
|
||||
{
|
||||
Log(LOG_ERR, "Well-known endpoint failed to lock configuration.");
|
||||
msg = "Internal server error: couldn't lock database.";
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
if (StrEquals(ArrayGet(path, 0), "client"))
|
||||
|
|
|
@ -42,16 +42,14 @@ ROUTE_IMPL(RouteWhoami, path, argp)
|
|||
char *token;
|
||||
char *userID;
|
||||
char *deviceID;
|
||||
char *msg;
|
||||
|
||||
Config *config = ConfigLock(db);
|
||||
|
||||
if (!config)
|
||||
{
|
||||
msg = "Internal server error: couldn't lock database.";
|
||||
Log(LOG_ERR, "Who am I endpoint failed to lock configuration.");
|
||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||
return MatrixErrorCreate(M_UNKNOWN, msg);
|
||||
return MatrixErrorCreate(M_UNKNOWN, NULL);
|
||||
}
|
||||
|
||||
(void) path;
|
||||
|
|
11
src/Uia.c
11
src/Uia.c
|
@ -222,8 +222,6 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
|
|||
HashMap *dbJson;
|
||||
int ret;
|
||||
|
||||
char *msg;
|
||||
|
||||
if (!flows)
|
||||
{
|
||||
return -1;
|
||||
|
@ -244,9 +242,8 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
|
|||
|
||||
if (JsonValueType(val) != JSON_OBJECT)
|
||||
{
|
||||
msg = "'auth' is not an object.";
|
||||
HttpResponseStatus(context, HTTP_BAD_REQUEST);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -255,9 +252,8 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
|
|||
|
||||
if (!val || JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
msg = "'auth->session' is unset or not a string.";
|
||||
HttpResponseStatus(context, HTTP_BAD_REQUEST);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -315,9 +311,8 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db,
|
|||
|
||||
if (!val || JsonValueType(val) != JSON_STRING)
|
||||
{
|
||||
msg = "'auth->type' is unset or not a string.";
|
||||
HttpResponseStatus(context, HTTP_BAD_REQUEST);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, msg);
|
||||
*response = MatrixErrorCreate(M_BAD_JSON, NULL);
|
||||
ret = 0;
|
||||
goto finish;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue