diff --git a/src/Matrix.c b/src/Matrix.c index 85fe826..a8548cc 100644 --- a/src/Matrix.c +++ b/src/Matrix.c @@ -47,6 +47,10 @@ MatrixHttpHandler(HttpServerContext * context, void *argp) requestPath = HttpRequestPath(context); + Log(LOG_DEBUG, "%s %s", + HttpRequestMethodToString(HttpRequestMethodGet(context)), + requestPath); + HttpResponseStatus(context, HTTP_OK); HttpResponseHeader(context, "Server", "Telodendria/" TELODENDRIA_VERSION); @@ -93,10 +97,8 @@ MatrixHttpHandler(HttpServerContext * context, void *argp) HttpSendHeaders(context); stream = HttpServerStream(context); - JsonEncode(response, stream, JSON_DEFAULT); JsonFree(response); - StreamPrintf(stream, "\n"); } @@ -342,7 +344,7 @@ MatrixClientWellKnown(char *base, char *identity) HashMap *identityServer = HashMapCreate(); HashMapSet(identityServer, "base_url", JsonValueString(identity)); - HashMapSet(response, "m.identity_server", identityServer); + HashMapSet(response, "m.identity_server", JsonValueObject(identityServer)); } return response; diff --git a/src/Routes.c b/src/Routes.c index 1f63d97..f424219 100644 --- a/src/Routes.c +++ b/src/Routes.c @@ -50,6 +50,7 @@ RouterBuild(void) R("/_matrix/static/client/login", RouteStaticLogin); R("/_matrix/client/v3/auth/(.*)/fallback/web", RouteUiaFallback); + R("/_matrix/client/v3/capabilities", RouteCapabilities); R("/_matrix/client/v3/login", RouteLogin); R("/_matrix/client/v3/logout", RouteLogout); R("/_matrix/client/v3/logout/(all)", RouteLogout); diff --git a/src/Routes/RouteCapabilities.c b/src/Routes/RouteCapabilities.c new file mode 100644 index 0000000..6fcd7ef --- /dev/null +++ b/src/Routes/RouteCapabilities.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022-2023 Jordan Bancino <@jordan:bancino.net> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include + +#include + +#include +#include +#include +#include + +ROUTE_IMPL(RouteCapabilities, path, argp) +{ + RouteArgs *args = argp; + HashMap *response; + HashMap *capabilities; + + response = HashMapCreate(); + capabilities = HashMapCreate(); + + JsonSet(capabilities, JsonValueBoolean(1), 2, "m.change_password", "enabled"); + JsonSet(capabilities, JsonValueBoolean(1), 2, "m.set_displayname", "enabled"); + JsonSet(capabilities, JsonValueBoolean(1), 2, "m.set_avatar_url", "enabled"); + JsonSet(capabilities, JsonValueBoolean(0), 2, "m.3pid_changes", "enabled"); + + HashMapSet(response, "capabilities", JsonValueObject(capabilities)); + return response; +} diff --git a/src/Routes/RouteLogin.c b/src/Routes/RouteLogin.c index ac94a83..e5c62ee 100644 --- a/src/Routes/RouteLogin.c +++ b/src/Routes/RouteLogin.c @@ -308,5 +308,6 @@ ROUTE_IMPL(RouteLogin, path, argp) UserIdFree(userId); JsonFree(request); ConfigUnlock(config); + return response; } diff --git a/src/include/Routes.h b/src/include/Routes.h index d177b61..0d379cf 100644 --- a/src/include/Routes.h +++ b/src/include/Routes.h @@ -55,6 +55,7 @@ HttpRouter * ROUTE(RouteVersions); ROUTE(RouteWellKnown); +ROUTE(RouteCapabilities); ROUTE(RouteLogin); ROUTE(RouteLogout); ROUTE(RouteRegister); diff --git a/tools/env.sh b/tools/env.sh index 9405f53..e16096a 100644 --- a/tools/env.sh +++ b/tools/env.sh @@ -33,4 +33,9 @@ fi export PATH="$(pwd)/tools/bin:$(pwd)/build/tools:$PATH" export MANPATH="$(pwd)/man:$MANPATH" -export MALLOC_OPTIONS="CFGJS" + +if [ "$(uname)" = "OpenBSD" ]; then + # Other platforms use different MALLOC_OPTIONS + # flags. + export MALLOC_OPTIONS="CFGJSU" +fi