diff --git a/src/Routes.c b/src/Routes.c index 76b9491..1bd8f46 100644 --- a/src/Routes.c +++ b/src/Routes.c @@ -93,6 +93,10 @@ RouterBuild(void) R("/_matrix/client/v3/directory/room/(.*)", RouteAliasDirectory); R("/_matrix/client/v3/rooms/(.*)/aliases", RouteRoomAliases); + /* Spoofed endpoints, to be TODO'd */ + R("/_matrix/client/v3/keys/(query|upload)", RouteKeyQuery); + R("/_matrix/client/v3/pushrules", RoutePushrules); + /* Telodendria Admin API Routes */ diff --git a/src/Routes/RouteJoinRoomAlias.c b/src/Routes/RouteJoinRoomAlias.c index 51b9be4..a3e23a3 100644 --- a/src/Routes/RouteJoinRoomAlias.c +++ b/src/Routes/RouteJoinRoomAlias.c @@ -84,7 +84,6 @@ ROUTE_IMPL(RouteJoinRoomAlias, path, argp) if (*roomId != '!') { roomId = RoomResolveAlias(db, roomId); - Log(LOG_NOTICE, "Here's my guess: %s", roomId); } else { @@ -127,7 +126,6 @@ ROUTE_IMPL(RouteJoinRoomAlias, path, argp) goto finish; } - Log(LOG_INFO, "Trying with token %s", token); user = UserAuthenticate(db, token); if (!user) { @@ -138,7 +136,6 @@ ROUTE_IMPL(RouteJoinRoomAlias, path, argp) id = UserIdParse(UserGetName(user), serverName); id->sigil = '@'; sender = ParserRecomposeCommonID(*id); - Log(LOG_INFO, "Now as %s", sender); room = RoomLock(db, roomId); if (!room) @@ -151,7 +148,6 @@ ROUTE_IMPL(RouteJoinRoomAlias, path, argp) if (RoomContainsUser(room, sender)) { err = "User is already in the room."; - Log(LOG_INFO, "qhar for %s", sender); HttpResponseStatus(args->context, HTTP_UNAUTHORIZED); response = MatrixErrorCreate(M_FORBIDDEN, err); diff --git a/src/Routes/RouteKeyQuery.c b/src/Routes/RouteKeyQuery.c new file mode 100644 index 0000000..7352d4a --- /dev/null +++ b/src/Routes/RouteKeyQuery.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net> with + * other valuable contributors. See CONTRIBUTORS.txt for the full list. + * + * 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 + +ROUTE_IMPL(RouteKeyQuery, path, argp) +{ + HashMap *response = HashMapCreate(); + char *action = ArrayGet(path, 0); + + (void) argp; + + if (StrEquals(action, "upload")) + { + HashMapSet(response, + "one_time_key_counts", JsonValueObject(HashMapCreate()) + ); + } + /* TODO: Spoofed endpoint */ + + return response; +} diff --git a/src/Routes/RoutePushRules.c b/src/Routes/RoutePushRules.c index d07709b..d6a474d 100644 --- a/src/Routes/RoutePushRules.c +++ b/src/Routes/RoutePushRules.c @@ -37,7 +37,7 @@ #include -ROUTE_IMPL(RoutePushRules, path, argp) +ROUTE_IMPL(RoutePushrules, path, argp) { RouteArgs *args = argp; Db *db = args->matrixArgs->db; diff --git a/src/Routes/RoutePushrules.c b/src/Routes/RoutePushrules.c new file mode 100644 index 0000000..94e6159 --- /dev/null +++ b/src/Routes/RoutePushrules.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022-2024 Jordan Bancino <@jordan:bancino.net> with + * other valuable contributors. See CONTRIBUTORS.txt for the full list. + * + * 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 + +ROUTE_IMPL(RouteKeyQuery, path, argp) +{ + HashMap *response = HashMapCreate(); + + (void) path; + (void) argp; + + /* TODO: Spoofed endpoint */ + HashMapSet(response, "global", JsonValueObject(HashMapCreate())); + + return response; +} + diff --git a/src/Uia.c b/src/Uia.c index 8ff58b5..622d3a9 100644 --- a/src/Uia.c +++ b/src/Uia.c @@ -312,6 +312,7 @@ UiaComplete(Array * flows, HttpServerContext * context, Db * db, } } + /* TODO: The type may sometimes be omitted. */ val = HashMapGet(auth, "type"); if (!val || JsonValueType(val) != JSON_STRING) diff --git a/src/User.c b/src/User.c index 3998078..2b2d688 100644 --- a/src/User.c +++ b/src/User.c @@ -130,6 +130,9 @@ UserLock(Db * db, char *name) user->name = StrDuplicate(name); user->deviceId = NULL; + user->inviteRef = DbLock(db, 3, "users", user->name, "invites"); + user->joinRef = DbLock(db, 3, "users", user->name, "joins"); + return user; } @@ -195,7 +198,7 @@ UserUnlock(User * user) Free(user->name); Free(user->deviceId); - ret = DbUnlock(db, ref) && + ret = DbUnlock(db, ref) && DbUnlock(db, user->joinRef) && DbUnlock(db, user->inviteRef); user->db = NULL; @@ -1683,6 +1686,7 @@ UserNotifyUser(User *user) entry = Malloc(sizeof(*entry)); entry->type = NOTIF_GOTTEN; + HashMapSet(pushTable, user->name, entry); pthread_mutex_unlock(&pushLock); return; } diff --git a/src/include/Routes.h b/src/include/Routes.h index e149bbe..107ff3f 100644 --- a/src/include/Routes.h +++ b/src/include/Routes.h @@ -115,6 +115,9 @@ ROUTE(RouteRoomAliases); ROUTE(RouteAdminDeactivate); ROUTE(RouteAdminTokens); + +ROUTE(RouteKeyQuery); +ROUTE(RoutePushrules); #undef ROUTE #endif