/* * Copyright (C) 2022-2025 Jordan Bancino <@jordan:synapse.telodendria.org> * 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 HttpRouter * RouterBuild(void) { HttpRouter *router = HttpRouterCreate(); if (!router) { return NULL; } #define R(path, func) \ if (!HttpRouterAdd(router, path, func)) \ { \ Log(LOG_ERR, "Unable to add route: %s", path); \ HttpRouterFree(router); \ return NULL; \ } /* Matrix Specifification Routes */ R("/.well-known/matrix/(client|server)", RouteWellKnown); R("/_matrix/key/v2/server", RouteKeyServer); R("/_matrix/key/v2/server/(.*)", RouteKeyServer); R("/_matrix/client/versions", RouteVersions); R("/_matrix/static", RouteStaticDefault); R("/_matrix/static/telodendria\\.(js|css)", RouteStaticResources); 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); R("/_matrix/client/v3/register", RouteRegister); R("/_matrix/client/v3/register/(available)", RouteRegister); R("/_matrix/client/v3/refresh", RouteRefresh); R("/_matrix/client/v3/account/whoami", RouteWhoami); R("/_matrix/client/v3/contacts", RouteContacts); R("/_matrix/media/v3/upload", RouteMediaUpload); R("/_matrix/client/v1/media/upload", RouteMediaUpload); R("/_matrix/media/v3/download/(.*)/(.*)", RouteMediaDownload); R("/_matrix/client/v1/media/download/(.*)/(.*)", RouteMediaDownload); R("/_matrix/media/v3/thumbnail/(.*)/(.*)", RouteMediaThumbnail); R("/_matrix/client/v1/media/thumbnail/(.*)/(.*)", RouteMediaThumbnail); R("/_matrix/media/v3/preview_url", RouteMediaPreview); R("/_matrix/client/v1/media/preview_url", RouteMediaPreview); R("/_matrix/client/v3/account/password", RouteChangePwd); R("/_matrix/client/v3/account/deactivate", RouteDeactivate); R("/_matrix/client/v3/account/3pid", RouteThreepidList); R("/_matrix/client/v3/account/3pid/add", RouteThreepidAdd); R("/_matrix/client/v3/account/3pid/delete", RouteThreepidDelete); R("/_matrix/client/v3/account/3pid/bind", RouteThreepidBind); R("/_matrix/client/v3/account/3pid/unbind", RouteThreepidUnbind); R("/_matrix/client/v3/account/3pid/(email|msisdn)/requestToken", RouteRequestToken); R("/_matrix/client/v1/register/m.login.registration_token/validity", RouteTokenValid); R("/_matrix/client/v3/account/password/(email|msisdn)/requestToken", RouteRequestToken); R("/_matrix/client/v3/register/(email|msisdn)/requestToken", RouteRequestToken); R("/_matrix/client/v3/profile/(.*)", RouteUserProfile); R("/_matrix/client/v3/profile/(.*)/(avatar_url|displayname)", RouteUserProfile); R("/_matrix/client/v3/user_directory/search", RouteUserDirectory); R("/_matrix/client/v3/devices", RouteDevices); R("/_matrix/client/v3/devices/(.*)", RouteDevices); R("/_matrix/client/v3/delete_devices", RouteDeleteDevices); R("/_matrix/client/v3/user/(.*)/account_data/(.*)", RouteAccountData); R("/_matrix/client/v3/user/(.*)/rooms/(.*)/account_data/(.*)", RouteAccountData); R("/_matrix/client/v3/user/(.*)/rooms/(.*)/tags/(.*)", RouteRoomTags); R("/_matrix/client/v3/user/(.*)/rooms/(.*)/tags", RouteRoomTags); R("/_matrix/client/v3/presence/(.*)/status", RoutePresence); R("/_matrix/client/v3/keys/upload", RouteKeysUpload); R("/_matrix/client/v1/appservice/(.*)/ping", RouteAppservicePing); R("/_matrix/client/v1/appservice/(.*)/users/(.*)", RouteAppserviceUser); R("/_matrix/client/v1/appservice/(.*)/rooms/(.*)", RouteAppserviceRoom); R("/_matrix/client/v3/keys/query", RouteKeysQuery); R("/_matrix/client/v3/keys/claim", RouteKeysClaim); R("/_matrix/client/v3/keys/changes", RouteKeysChanges); R("/_matrix/client/v3/keys/device_signing/upload", RouteCrossSigningUpload); R("/_matrix/client/v3/keys/signatures/upload", RouteSignaturesUpload); R("/_matrix/client/v3/sendToDevice/(.*)/(.*)", RouteSendToDevice); R("/_matrix/client/v3/user/(.*)/filter", RouteFilter); R("/_matrix/client/v3/user/(.*)/filter/(.*)", RouteFilter); R("/_matrix/client/v3/createRoom", RouteCreateRoom); R("/_matrix/client/v3/directory/room/(.*)", RouteAliasDirectory); R("/_matrix/client/v3/rooms/(.*)/aliases", RouteRoomAliases); R("/_matrix/client/v3/rooms/(.*)/state/(.*)/(.*)", RouteRoomState); R("/_matrix/client/v3/rooms/(.*)/state/(.*)", RouteRoomState); R("/_matrix/client/v3/rooms/(.*)/state", RouteRoomState); R("/_matrix/client/v3/rooms/(.*)/members", RouteRoomMembers); R("/_matrix/client/v3/rooms/(.*)/(invite|kick|ban|unban)", RouteRoomMembership); R("/_matrix/client/v3/rooms/(.*)/redact/(.*)/(.*)", RouteRedact); R("/_matrix/client/v3/rooms/(.*)/receipt/(.*)/(.*)", RouteReceipt); R("/_matrix/client/v3/rooms/(.*)/read_markers", RouteReadMarkers); R("/_matrix/client/v3/rooms/(.*)/typing/(.*)", RouteTyping); R("/_matrix/client/v3/joined_rooms", RouteJoinedRooms); R("/_matrix/client/v3/publicRooms", RoutePublicRooms); R("/_matrix/client/v3/rooms/(.*)/send/(.*)/(.*)", RouteSendEvent); R("/_matrix/client/v3/rooms/(.*)/messages", RouteMessages); R("/_matrix/client/v3/rooms/(.*)/forget", RouteForgetRoom); R("/_matrix/client/v3/rooms/(.*)/timestamp_to_event", RouteTimestampToEvent); R("/_matrix/client/v3/rooms/(.*)/event/(.*)", RouteRoomEvent); R("/_matrix/client/v3/rooms/(.*)/context/(.*)", RouteRoomContext); R("/_matrix/client/v3/rooms/(.*)/relations/(.*)", RouteRoomRelations); R("/_matrix/client/v3/rooms/(.*)/join", RouteJoinRoom); R("/_matrix/client/v3/rooms/(.*)/leave", RouteLeaveRoom); R("/_matrix/client/v3/join/(.*)", RouteJoinRoom); R("/_matrix/client/v3/search", RouteSearch); R("/_matrix/client/v3/pushers", RoutePushers); R("/_matrix/client/v3/pushers/set", RoutePushers); R("/_matrix/client/v3/voip/turnServer", RouteTurnServer); R("/_matrix/client/v1/rooms/(.*)/threads", RouteRoomThreads); R("/_matrix/client/v1/rooms/(.*)/hierarchy", RouteRoomHierarchy); R("/_matrix/client/v3/rooms/(.*)/upgrade", RouteUpgradeRoom); R("/_matrix/client/v3/rooms/(.*)/knock", RouteKnockRoom); R("/_matrix/client/v3/rooms/(.*)/report/(.*)", RouteReport); R("/_matrix/client/v3/users/(.*)/report", RouteReport); R("/_matrix/client/v3/sync", RouteSync); R("/_matrix/client/v3/pushrules", RoutePushRules); R("/_matrix/client/v3/pushrules/(.*)/(.*)/(.*)", RoutePushRules); R("/_matrix/client/v3/pushrules/(.*)/(.*)/(.*)/(.*)", RoutePushRules); R("/_matrix/client/v3/notifications", RouteNotifications); R("/_matrix/client/v3/room_keys/version", RouteKeyBackupVersion); R("/_matrix/client/v3/room_keys/version/(.*)", RouteKeyBackupVersion); R("/_matrix/client/v3/room_keys/keys", RouteRoomKeys); R("/_matrix/client/v3/room_keys/keys/(.*)/(.*)", RouteRoomKeys); R("/_matrix/client/v3/room_keys/keys/(.*)", RouteRoomKeys); R("/_matrix/federation/v1/version",RouteFederationVersion) R("/_matrix/federation/v1/invite/(.*)/(.*)",RouteFedInvite) R("/_matrix/federation/v2/invite/(.*)/(.*)",RouteFedInvite) R("/_matrix/federation/v1/send/(.*)",RouteFedSend) /* Telodendria Admin API Routes */ R("/_telodendria/admin/v1/(restart|shutdown|stats)", RouteProcControl); R("/_telodendria/admin/v1/config", RouteConfig); R("/_telodendria/admin/v1/privileges", RoutePrivileges); R("/_telodendria/admin/v1/privileges/(.*)", RoutePrivileges); R("/_telodendria/admin/v1/deactivate/(.*)", RouteAdminDeactivate); R("/_telodendria/admin/v1/tokens/(.*)", RouteAdminTokens); R("/_telodendria/admin/v1/tokens", RouteAdminTokens); #undef R return router; }