2020-07-02 09:41:18 -05:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
2017-04-20 17:40:52 -05:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2017-02-20 09:41:29 -06:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2022-02-18 09:05:03 -06:00
|
|
|
"context"
|
2017-02-20 09:41:29 -06:00
|
|
|
"net/http"
|
2017-08-18 09:33:40 -05:00
|
|
|
"strings"
|
2017-02-20 09:41:29 -06:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-08-20 04:45:17 -05:00
|
|
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
2020-07-02 11:11:33 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/api"
|
2020-07-09 18:39:44 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/auth"
|
2020-10-09 03:15:51 -05:00
|
|
|
clientutil "github.com/matrix-org/dendrite/clientapi/httputil"
|
2017-06-27 06:37:25 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
2017-03-15 08:36:26 -05:00
|
|
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
2021-11-24 04:45:23 -06:00
|
|
|
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
2020-06-12 08:55:57 -05:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-05-21 08:40:13 -05:00
|
|
|
"github.com/matrix-org/dendrite/internal/transactions"
|
2020-07-15 06:02:34 -05:00
|
|
|
keyserverAPI "github.com/matrix-org/dendrite/keyserver/api"
|
2018-08-08 10:17:09 -05:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-12-02 11:41:00 -06:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2022-04-06 06:11:19 -05:00
|
|
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
2020-07-02 09:41:18 -05:00
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
2017-05-25 10:08:28 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2017-02-20 09:41:29 -06:00
|
|
|
"github.com/matrix-org/util"
|
2022-04-06 06:11:19 -05:00
|
|
|
"github.com/nats-io/nats.go"
|
2022-04-08 05:24:40 -05:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-07-09 10:52:31 -05:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-02-20 09:41:29 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
|
|
|
// to clients which need to make outbound HTTP requests.
|
2019-07-03 10:38:50 -05:00
|
|
|
//
|
|
|
|
// Due to Setup being used to call many other functions, a gocyclo nolint is
|
|
|
|
// applied:
|
|
|
|
// nolint: gocyclo
|
2017-05-25 10:08:28 -05:00
|
|
|
func Setup(
|
2022-04-28 10:02:30 -05:00
|
|
|
publicAPIMux, synapseAdminRouter, dendriteAdminRouter *mux.Router,
|
|
|
|
cfg *config.ClientAPI,
|
2022-05-05 07:17:38 -05:00
|
|
|
rsAPI roomserverAPI.ClientRoomserverAPI,
|
2022-05-06 06:39:26 -05:00
|
|
|
asAPI appserviceAPI.AppServiceInternalAPI,
|
2022-05-05 07:17:38 -05:00
|
|
|
userAPI userapi.ClientUserAPI,
|
2022-05-05 13:30:38 -05:00
|
|
|
userDirectoryProvider userapi.QuerySearchProfilesAPI,
|
2017-05-25 10:08:28 -05:00
|
|
|
federation *gomatrixserverlib.FederationClient,
|
2017-08-02 10:21:35 -05:00
|
|
|
syncProducer *producers.SyncAPIProducer,
|
2018-05-18 04:49:40 -05:00
|
|
|
transactionsCache *transactions.Cache,
|
2022-05-05 07:17:38 -05:00
|
|
|
federationSender federationAPI.ClientFederationAPI,
|
|
|
|
keyAPI keyserverAPI.ClientKeyAPI,
|
2020-07-03 06:59:00 -05:00
|
|
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
2022-04-06 06:11:19 -05:00
|
|
|
mscCfg *config.MSCs, natsClient *nats.Conn,
|
2017-05-25 10:08:28 -05:00
|
|
|
) {
|
2022-04-08 05:24:40 -05:00
|
|
|
prometheus.MustRegister(amtRegUsers, sendEventDuration)
|
|
|
|
|
2021-11-24 06:55:44 -06:00
|
|
|
rateLimits := httputil.NewRateLimits(&cfg.RateLimiting)
|
2022-03-24 16:45:44 -05:00
|
|
|
userInteractiveAuth := auth.NewUserInteractive(userAPI, cfg)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2021-08-04 11:56:29 -05:00
|
|
|
unstableFeatures := map[string]bool{
|
2021-08-17 07:44:30 -05:00
|
|
|
"org.matrix.e2e_cross_signing": true,
|
2021-08-04 11:56:29 -05:00
|
|
|
}
|
2021-01-18 07:09:28 -06:00
|
|
|
for _, msc := range cfg.MSCs.MSCs {
|
|
|
|
unstableFeatures["org.matrix."+msc] = true
|
|
|
|
}
|
|
|
|
|
2020-08-13 06:16:37 -05:00
|
|
|
publicAPIMux.Handle("/versions",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
2017-06-27 06:37:25 -05:00
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 06:37:25 -05:00
|
|
|
JSON: struct {
|
2021-01-18 07:09:28 -06:00
|
|
|
Versions []string `json:"versions"`
|
|
|
|
UnstableFeatures map[string]bool `json:"unstable_features"`
|
|
|
|
}{Versions: []string{
|
2017-06-27 06:37:25 -05:00
|
|
|
"r0.0.1",
|
|
|
|
"r0.1.0",
|
|
|
|
"r0.2.0",
|
2018-03-14 12:36:02 -05:00
|
|
|
"r0.3.0",
|
2020-08-25 09:44:33 -05:00
|
|
|
"r0.4.0",
|
|
|
|
"r0.5.0",
|
|
|
|
"r0.6.1",
|
2022-06-01 03:39:17 -05:00
|
|
|
"v1.0",
|
|
|
|
"v1.1",
|
|
|
|
"v1.2",
|
2021-01-18 07:09:28 -06:00
|
|
|
}, UnstableFeatures: unstableFeatures},
|
2017-06-27 06:37:25 -05:00
|
|
|
}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2021-07-09 10:52:31 -05:00
|
|
|
if cfg.RegistrationSharedSecret != "" {
|
|
|
|
logrus.Info("Enabling shared secret registration at /_synapse/admin/v1/register")
|
|
|
|
sr := NewSharedSecretRegistration(cfg.RegistrationSharedSecret)
|
|
|
|
synapseAdminRouter.Handle("/admin/v1/register",
|
|
|
|
httputil.MakeExternalAPI("shared_secret_registration", func(req *http.Request) util.JSONResponse {
|
|
|
|
if req.Method == http.MethodGet {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 200,
|
|
|
|
JSON: struct {
|
|
|
|
Nonce string `json:"nonce"`
|
|
|
|
}{
|
|
|
|
Nonce: sr.GenerateNonce(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if req.Method == http.MethodPost {
|
|
|
|
return handleSharedSecretRegistration(userAPI, sr, req)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusMethodNotAllowed,
|
|
|
|
JSON: jsonerror.NotFound("unknown method"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-04-28 10:02:30 -05:00
|
|
|
dendriteAdminRouter.Handle("/admin/evacuateRoom/{roomID}",
|
|
|
|
httputil.MakeAuthAPI("admin_evacuate_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-04-29 03:10:08 -05:00
|
|
|
return AdminEvacuateRoom(req, device, rsAPI)
|
2022-04-28 10:02:30 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-18 09:05:03 -06:00
|
|
|
// server notifications
|
|
|
|
if cfg.Matrix.ServerNotices.Enabled {
|
|
|
|
logrus.Info("Enabling server notices at /_synapse/admin/v1/send_server_notice")
|
2022-03-24 16:45:44 -05:00
|
|
|
serverNotificationSender, err := getSenderDevice(context.Background(), userAPI, cfg)
|
2022-02-18 09:05:03 -06:00
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Fatal("unable to get account for sending sending server notices")
|
|
|
|
}
|
|
|
|
|
|
|
|
synapseAdminRouter.Handle("/admin/v1/send_server_notice/{txnID}",
|
|
|
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
|
|
|
return SendServerNotice(
|
|
|
|
req, &cfg.Matrix.ServerNotices,
|
2022-03-24 16:45:44 -05:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 09:05:03 -06:00
|
|
|
device, serverNotificationSender,
|
|
|
|
&txnID, transactionsCache,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
synapseAdminRouter.Handle("/admin/v1/send_server_notice",
|
|
|
|
httputil.MakeAuthAPI("send_server_notice", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
// not specced, but ensure we're rate limiting requests to this endpoint
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SendServerNotice(
|
|
|
|
req, &cfg.Matrix.ServerNotices,
|
2022-03-24 16:45:44 -05:00
|
|
|
cfg, userAPI, rsAPI, asAPI,
|
2022-02-18 09:05:03 -06:00
|
|
|
device, serverNotificationSender,
|
|
|
|
nil, transactionsCache,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
// You can't just do PathPrefix("/(r0|v3)") because regexps only apply when inside named path variables.
|
|
|
|
// So make a named path variable called 'apiversion' (which we will never read in handlers) and then do
|
|
|
|
// (r0|v3) - BUT this is a captured group, which makes no sense because you cannot extract this group
|
|
|
|
// from a match (gorilla/mux exposes no way to do this) so it demands you make it a non-capturing group
|
|
|
|
// using ?: so the final regexp becomes what is below. We also need a trailing slash to stop 'v33333' matching.
|
|
|
|
// Note that 'apiversion' is chosen because it must not collide with a variable used in any of the routing!
|
|
|
|
v3mux := publicAPIMux.PathPrefix("/{apiversion:(?:r0|v3)}/").Subrouter()
|
|
|
|
|
2020-08-13 06:16:37 -05:00
|
|
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/createRoom",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return CreateRoom(req, device, cfg, userAPI, rsAPI, asAPI)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/join/{roomIDOrAlias}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-10-11 12:16:53 -05:00
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, userAPI, vars["roomIDOrAlias"],
|
2017-05-25 10:08:28 -05:00
|
|
|
)
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2021-01-22 10:08:47 -06:00
|
|
|
|
|
|
|
if mscCfg.Enabled("msc2753") {
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/peek/{roomIDOrAlias}",
|
2021-01-22 10:08:47 -06:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2021-01-22 10:08:47 -06:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PeekRoomByIDOrAlias(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, vars["roomIDOrAlias"],
|
2021-01-22 10:08:47 -06:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/joined_rooms",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("joined_rooms", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-09-04 09:58:30 -05:00
|
|
|
return GetJoinedRooms(req, device, rsAPI)
|
2020-03-19 05:25:36 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/join",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return JoinRoomByIDOrAlias(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, userAPI, vars["roomID"],
|
2020-06-24 12:19:54 -05:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/leave",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-05-04 12:34:09 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return LeaveRoomByID(
|
|
|
|
req, device, rsAPI, vars["roomID"],
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unpeek",
|
2020-12-03 05:11:46 -06:00
|
|
|
httputil.MakeAuthAPI("unpeek", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return UnpeekRoomByID(
|
2022-03-24 16:45:44 -05:00
|
|
|
req, device, rsAPI, vars["roomID"],
|
2020-12-03 05:11:46 -06:00
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/ban",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendBan(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 12:19:54 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/invite",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendInvite(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 12:19:54 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/kick",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-24 12:19:54 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendKick(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 12:19:54 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/unban",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("membership", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SendUnban(req, userAPI, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2017-08-04 10:32:10 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, rsAPI, nil)
|
2017-09-26 06:55:48 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-09-26 06:55:48 -05:00
|
|
|
txnID := vars["txnID"]
|
2018-05-18 04:49:40 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID,
|
2020-06-10 06:17:54 -05:00
|
|
|
nil, cfg, rsAPI, transactionsCache)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/event/{eventID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("rooms_get_event", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-09 04:45:54 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-05-05 07:17:38 -05:00
|
|
|
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
|
2019-08-09 04:45:54 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 12:36:08 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-25 12:43:56 -05:00
|
|
|
return OnIncomingStateRequest(req.Context(), device, rsAPI, vars["roomID"])
|
2020-04-14 12:36:08 -05:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/aliases", httputil.MakeAuthAPI("aliases", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-07-21 10:53:50 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAliases(req, rsAPI, device, vars["roomID"])
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{type:[^/]+/?}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 12:36:08 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-24 03:59:59 -05:00
|
|
|
// If there's a trailing slash, remove it
|
2021-08-17 04:39:09 -05:00
|
|
|
eventType := strings.TrimSuffix(vars["type"], "/")
|
2020-06-17 10:21:42 -05:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 04:09:10 -05:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], eventType, "", eventFormat)
|
2020-04-14 12:36:08 -05:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", httputil.MakeAuthAPI("room_state", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-04-14 12:36:08 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-17 10:21:42 -05:00
|
|
|
eventFormat := req.URL.Query().Get("format") == "event"
|
2020-07-28 04:09:10 -05:00
|
|
|
return OnIncomingStateTypeRequest(req.Context(), device, rsAPI, vars["roomID"], vars["type"], vars["stateKey"], eventFormat)
|
2020-04-14 12:36:08 -05:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 06:21:52 -05:00
|
|
|
emptyString := ""
|
2021-08-17 04:39:09 -05:00
|
|
|
eventType := strings.TrimSuffix(vars["eventType"], "/")
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, nil)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("send_message", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2017-03-17 06:21:52 -05:00
|
|
|
stateKey := vars["stateKey"]
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, rsAPI, nil)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-02-20 09:41:29 -06:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return Register(req, userAPI, cfg)
|
2018-03-13 10:55:45 -05:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-22 10:13:19 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/register/available", httputil.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return RegisterAvailable(req, cfg, userAPI)
|
2018-03-13 10:55:45 -05:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-09 09:24:38 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("directory_room", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return DirectoryRoom(req, vars["roomAlias"], federation, cfg, rsAPI, federationSender)
|
2017-06-27 06:37:25 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-28 05:31:43 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return SetLocalAlias(req, device, vars["roomAlias"], cfg, rsAPI)
|
2017-07-28 05:31:43 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-28 05:31:43 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/room/{roomAlias}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("directory_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
|
2017-07-28 05:31:43 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2020-07-02 09:41:18 -05:00
|
|
|
httputil.MakeExternalAPI("directory_list", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetVisibility(req, rsAPI, vars["roomID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
// TODO: Add AS support
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/directory/list/room/{roomID}",
|
2020-07-02 09:41:18 -05:00
|
|
|
httputil.MakeAuthAPI("directory_list", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-09-07 08:47:59 -05:00
|
|
|
return SetVisibility(req, rsAPI, device, vars["roomID"])
|
2020-07-02 09:41:18 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/publicRooms",
|
2020-07-02 09:41:18 -05:00
|
|
|
httputil.MakeExternalAPI("public_rooms", func(req *http.Request) util.JSONResponse {
|
2020-09-07 06:38:09 -05:00
|
|
|
return GetPostPublicRooms(req, rsAPI, extRoomsProvider, federation, cfg)
|
2020-07-02 09:41:18 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/logout",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 12:53:40 -05:00
|
|
|
return Logout(req, userAPI, device)
|
2017-07-11 10:04:34 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-07-11 10:04:34 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/logout/all",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("logout", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 12:53:40 -05:00
|
|
|
return LogoutAll(req, userAPI, device)
|
2017-10-15 05:29:47 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-10-15 05:29:47 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/typing/{userID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("rooms_typing", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-29 07:14:35 -05:00
|
|
|
return SendTyping(req, device, vars["roomID"], vars["userID"], rsAPI, syncProducer)
|
2018-07-24 09:49:49 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}",
|
2020-07-03 11:24:51 -05:00
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-04-26 03:28:41 -05:00
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, nil, nil)
|
2020-07-03 11:24:51 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/redact/{eventID}/{txnId}",
|
2020-08-25 04:39:30 -05:00
|
|
|
httputil.MakeAuthAPI("rooms_redact", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-04-26 03:28:41 -05:00
|
|
|
txnID := vars["txnId"]
|
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, &txnID, transactionsCache)
|
2020-08-25 04:39:30 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2018-07-24 09:49:49 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 11:50:19 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2022-03-29 07:14:35 -05:00
|
|
|
return SendToDevice(req, device, syncProducer, transactionsCache, vars["eventType"], &txnID)
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 11:50:19 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
// This is only here because sytest refers to /unstable for this endpoint
|
|
|
|
// rather than r0. It's an exact duplicate of the above handler.
|
|
|
|
// TODO: Remove this if/when sytest is fixed!
|
|
|
|
unstableMux.Handle("/sendToDevice/{eventType}/{txnID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("send_to_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 11:50:19 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
txnID := vars["txnID"]
|
2022-03-29 07:14:35 -05:00
|
|
|
return SendToDevice(req, device, syncProducer, transactionsCache, vars["eventType"], &txnID)
|
Send-to-device support (#1072)
* Groundwork for send-to-device messaging
* Update sample config
* Add unstable routing for now
* Send to device consumer in sync API
* Start the send-to-device consumer
* fix indentation in dendrite-config.yaml
* Create send-to-device database tables, other tweaks
* Add some logic for send-to-device messages, add them into sync stream
* Handle incoming send-to-device messages, count them with EDU stream pos
* Undo changes to test
* pq.Array
* Fix sync
* Logging
* Fix a couple of transaction things, fix client API
* Add send-to-device test, hopefully fix bugs
* Comments
* Refactor a bit
* Fix schema
* Fix queries
* Debug logging
* Fix storing and retrieving of send-to-device messages
* Try to avoid database locks
* Update sync position
* Use latest sync position
* Jiggle about sync a bit
* Fix tests
* Break out the retrieval from the update/delete behaviour
* Comments
* nolint on getResponseWithPDUsForCompleteSync
* Try to line up sync tokens again
* Implement wildcard
* Add all send-to-device tests to whitelist, what could possibly go wrong?
* Only care about wildcard when targeted locally
* Deduplicate transactions
* Handle tokens properly, return immediately if waiting send-to-device messages
* Fix sync
* Update sytest-whitelist
* Fix copyright notice (need to do more of this)
* Comments, copyrights
* Return errors from Do, fix dendritejs
* Review comments
* Comments
* Constructor for TransactionWriter
* defletions
* Update gomatrixserverlib, sytest-blacklist
2020-06-01 11:50:19 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/whoami",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2018-08-04 04:32:02 -05:00
|
|
|
return Whoami(req, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/password",
|
2020-09-04 09:16:13 -05:00
|
|
|
httputil.MakeAuthAPI("password", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-04 09:16:13 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return Password(req, userAPI, device, cfg)
|
2020-09-04 09:16:13 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/deactivate",
|
2020-10-02 11:18:20 -05:00
|
|
|
httputil.MakeAuthAPI("deactivate", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-10-02 11:18:20 -05:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return Deactivate(req, userInteractiveAuth, userAPI, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
// Stub endpoints required by Element
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/login",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return Login(req, userAPI, cfg)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/auth/{authType}/fallback/web",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeHTMLAPI("auth_fallback", func(w http.ResponseWriter, req *http.Request) *util.JSONResponse {
|
2019-08-14 12:34:49 -05:00
|
|
|
vars := mux.Vars(req)
|
|
|
|
return AuthFallback(w, req, vars["authType"], cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 05:40:53 -06:00
|
|
|
// Push rules
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/pushrules/",
|
2022-03-03 05:40:53 -06:00
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetAllPushRules(req.Context(), device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2017-04-20 11:11:53 -05:00
|
|
|
return util.JSONResponse{
|
2022-03-03 05:40:53 -06:00
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("scope, kind and rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPushRulesByScope(req.Context(), vars["scope"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash after scope"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope:[^/]+/?}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("kind and rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPushRulesByKind(req.Context(), vars["scope"], vars["kind"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("missing trailing slash after kind"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind:[^/]+/?}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: http.StatusBadRequest,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("rule ID must be specified"),
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
2017-04-20 11:11:53 -05:00
|
|
|
}
|
2022-03-03 05:40:53 -06:00
|
|
|
return GetPushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], device, userAPI)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-03-03 05:40:53 -06:00
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
query := req.URL.Query()
|
|
|
|
return PutPushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], query.Get("after"), query.Get("before"), req.Body, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeletePushRuleByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}/{attr}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPushRuleAttrByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], vars["attr"], device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushrules/{scope}/{kind}/{ruleID}/{attr}",
|
|
|
|
httputil.MakeAuthAPI("push_rules", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PutPushRuleAttrByRuleID(req.Context(), vars["scope"], vars["kind"], vars["ruleID"], vars["attr"], req.Body, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
// Element user settings
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetProfile(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetAvatarURL(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 08:52:41 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/avatar_url",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("profile_avatar_url", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SetAvatarURL(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2017-07-10 08:52:41 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetDisplayName(req, userAPI, cfg, vars["userID"], asAPI, federation)
|
2017-07-10 08:52:41 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/profile/{userID}/displayname",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("profile_displayname", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-24 16:45:44 -05:00
|
|
|
return SetDisplayName(req, userAPI, device, vars["userID"], cfg, rsAPI)
|
2017-07-10 08:52:41 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-10 08:52:41 -05:00
|
|
|
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
|
|
|
// PUT requests, so we need to allow this method
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/3pid",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return GetAssociated3PIDs(req, userAPI, device)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-01 04:13:10 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/account/3pid",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return CheckAndSave3PIDAssociation(req, userAPI, device, cfg)
|
2017-09-01 04:13:10 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 04:13:10 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/account/3pid/delete",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("account_3pid", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return Forget3PID(req, userAPI)
|
2017-09-01 04:13:10 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-01 04:13:10 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return RequestEmailToken(req, userAPI, cfg)
|
2017-09-01 04:13:10 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/voip/turnServer",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("turn_server", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2017-11-09 03:58:45 -06:00
|
|
|
return RequestTurnServer(req, device, cfg)
|
2017-06-27 06:37:25 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/thirdparty/protocols",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("thirdparty_protocols", func(req *http.Request) util.JSONResponse {
|
2017-06-27 06:37:25 -05:00
|
|
|
// TODO: Return the third party protcols
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2017-06-27 06:37:25 -05:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/initialSync",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("rooms_initial_sync", func(req *http.Request) util.JSONResponse {
|
2017-06-27 06:37:25 -05:00
|
|
|
// TODO: Allow people to peek into rooms.
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusForbidden,
|
2017-06-27 06:37:25 -05:00
|
|
|
JSON: jsonerror.GuestAccessForbidden("Guest access not implemented"),
|
|
|
|
}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], "", vars["type"], syncProducer)
|
2017-07-26 08:53:11 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-07-26 08:53:11 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return SaveAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"], syncProducer)
|
2017-06-27 06:37:25 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/account_data/{type}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 11:53:05 -06:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], "", vars["type"])
|
2020-01-29 11:53:05 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("user_account_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-01-29 11:53:05 -06:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return GetAccountData(req, userAPI, device, vars["userID"], vars["roomID"], vars["type"])
|
2020-01-29 11:53:05 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/admin/whois/{userID}",
|
2020-11-17 04:07:03 -06:00
|
|
|
httputil.MakeAuthAPI("admin_whois", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetAdminWhois(req, userAPI, device, vars["userID"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userID}/openid/request_token",
|
2021-04-07 07:26:20 -05:00
|
|
|
httputil.MakeAuthAPI("openid_request_token", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2021-04-07 07:26:20 -05:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return CreateOpenIDToken(req, userAPI, device, vars["userID"], cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user_directory/search",
|
2020-07-28 04:53:17 -05:00
|
|
|
httputil.MakeAuthAPI("userdirectory_search", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-07-28 04:53:17 -05:00
|
|
|
postContent := struct {
|
|
|
|
SearchString string `json:"search_term"`
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
}{}
|
2020-10-09 03:15:51 -05:00
|
|
|
|
|
|
|
if resErr := clientutil.UnmarshalJSONRequest(req, &postContent); resErr != nil {
|
|
|
|
return *resErr
|
2020-07-28 04:53:17 -05:00
|
|
|
}
|
2022-05-05 07:17:38 -05:00
|
|
|
return SearchUserDirectory(
|
2020-07-28 04:53:17 -05:00
|
|
|
req.Context(),
|
|
|
|
device,
|
|
|
|
userAPI,
|
2020-09-04 05:46:01 -05:00
|
|
|
rsAPI,
|
2022-03-28 10:25:26 -05:00
|
|
|
userDirectoryProvider,
|
2020-07-28 04:53:17 -05:00
|
|
|
cfg.Matrix.ServerName,
|
|
|
|
postContent.SearchString,
|
|
|
|
postContent.Limit,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/members",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return GetMemberships(req, device, vars["roomID"], false, cfg, rsAPI)
|
2017-08-24 10:00:14 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-24 10:00:14 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/joined_members",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("rooms_members", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return GetMemberships(req, device, vars["roomID"], true, cfg, rsAPI)
|
2017-08-21 10:34:26 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-08-21 10:34:26 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/read_markers",
|
2020-10-09 03:15:35 -05:00
|
|
|
httputil.MakeAuthAPI("rooms_read_markers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-10-09 03:15:35 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2022-03-29 07:14:35 -05:00
|
|
|
return SaveReadMarker(req, userAPI, rsAPI, syncProducer, device, vars["roomID"])
|
2017-06-27 06:37:25 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomID}/forget",
|
2020-11-05 04:19:23 -06:00
|
|
|
httputil.MakeAuthAPI("rooms_forget", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-11-05 04:19:23 -06:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return SendForget(req, device, vars["roomID"], rsAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-04-05 04:04:08 -05:00
|
|
|
v3mux.Handle("/rooms/{roomID}/upgrade",
|
|
|
|
httputil.MakeAuthAPI("rooms_upgrade", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return UpgradeRoom(req, device, cfg, vars["roomID"], userAPI, rsAPI, asAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("get_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-08-27 12:53:40 -05:00
|
|
|
return GetDevicesByLocalpart(req, userAPI, device)
|
2017-10-17 13:12:54 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 13:12:54 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("get_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-08-27 12:53:40 -05:00
|
|
|
return GetDeviceByID(req, userAPI, device, vars["deviceID"])
|
2017-10-17 13:12:54 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-17 13:12:54 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("device_data", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-07-03 10:38:50 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-31 08:40:45 -05:00
|
|
|
return UpdateDeviceByID(req, userAPI, device, vars["deviceID"])
|
2017-11-14 03:59:02 -06:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-11-14 03:59:02 -06:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/devices/{deviceID}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("delete_device", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2020-02-11 06:13:38 -06:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-07-30 12:00:56 -05:00
|
|
|
return DeleteDeviceById(req, userInteractiveAuth, userAPI, device, vars["deviceID"])
|
2020-02-11 06:13:38 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/delete_devices",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("delete_devices", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-30 12:00:56 -05:00
|
|
|
return DeleteDevices(req, userAPI, device)
|
2020-02-11 06:13:38 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2022-03-03 05:40:53 -06:00
|
|
|
v3mux.Handle("/notifications",
|
|
|
|
httputil.MakeAuthAPI("get_notifications", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetNotifications(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushers",
|
|
|
|
httputil.MakeAuthAPI("get_pushers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetPushers(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
|
|
|
v3mux.Handle("/pushers/set",
|
|
|
|
httputil.MakeAuthAPI("set_pushers", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return SetPusher(req, device, userAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-09-22 11:28:29 -05:00
|
|
|
// Stub implementations for sytest
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/events",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("events", func(req *http.Request) util.JSONResponse {
|
2018-03-13 10:55:45 -05:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 11:28:29 -05:00
|
|
|
"chunk": []interface{}{},
|
|
|
|
"start": "",
|
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-09-22 11:28:29 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/initialSync",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("initial_sync", func(req *http.Request) util.JSONResponse {
|
2018-03-13 10:55:45 -05:00
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]interface{}{
|
2017-09-22 11:28:29 -05:00
|
|
|
"end": "",
|
|
|
|
}}
|
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2019-08-02 06:17:51 -05:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("get_tags", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 06:17:51 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return GetTags(req, userAPI, device, vars["userId"], vars["roomId"], syncProducer)
|
2019-08-02 06:17:51 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("put_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 06:17:51 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return PutTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2019-08-02 06:17:51 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("delete_tag", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-12 08:55:57 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
2019-08-02 06:17:51 -05:00
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-06-18 12:36:03 -05:00
|
|
|
return DeleteTag(req, userAPI, device, vars["userId"], vars["roomId"], vars["tag"], syncProducer)
|
2019-08-02 06:17:51 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete, http.MethodOptions)
|
2020-02-05 12:06:39 -06:00
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/capabilities",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-09-03 04:12:11 -05:00
|
|
|
return *r
|
|
|
|
}
|
2020-05-01 04:48:17 -05:00
|
|
|
return GetCapabilities(req, rsAPI)
|
2020-02-05 12:06:39 -06:00
|
|
|
}),
|
2020-09-27 16:23:42 -05:00
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-07-13 10:02:35 -05:00
|
|
|
|
2021-07-27 13:29:32 -05:00
|
|
|
// Key Backup Versions (Metadata)
|
|
|
|
|
2021-07-28 04:25:45 -05:00
|
|
|
getBackupKeysVersion := httputil.MakeAuthAPI("get_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return KeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
})
|
|
|
|
|
|
|
|
getLatestBackupKeysVersion := httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return KeyBackupVersion(req, userAPI, device, "")
|
|
|
|
})
|
|
|
|
|
|
|
|
putBackupKeysVersion := httputil.MakeAuthAPI("put_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return ModifyKeyBackupVersionAuthData(req, userAPI, device, vars["version"])
|
|
|
|
})
|
|
|
|
|
|
|
|
deleteBackupKeysVersion := httputil.MakeAuthAPI("delete_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return DeleteKeyBackupVersion(req, userAPI, device, vars["version"])
|
|
|
|
})
|
|
|
|
|
|
|
|
postNewBackupKeysVersion := httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return CreateKeyBackupVersion(req, userAPI, device)
|
|
|
|
})
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/room_keys/version/{version}", getBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/version", getLatestBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/version/{version}", putBackupKeysVersion).Methods(http.MethodPut)
|
|
|
|
v3mux.Handle("/room_keys/version/{version}", deleteBackupKeysVersion).Methods(http.MethodDelete)
|
|
|
|
v3mux.Handle("/room_keys/version", postNewBackupKeysVersion).Methods(http.MethodPost, http.MethodOptions)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", getBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/version", getLatestBackupKeysVersion).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", putBackupKeysVersion).Methods(http.MethodPut)
|
|
|
|
unstableMux.Handle("/room_keys/version/{version}", deleteBackupKeysVersion).Methods(http.MethodDelete)
|
|
|
|
unstableMux.Handle("/room_keys/version", postNewBackupKeysVersion).Methods(http.MethodPost, http.MethodOptions)
|
2021-07-27 06:47:32 -05:00
|
|
|
|
2021-07-27 13:29:32 -05:00
|
|
|
// Inserting E2E Backup Keys
|
|
|
|
|
2021-07-27 11:08:53 -05:00
|
|
|
// Bulk room and session
|
2021-07-28 04:25:45 -05:00
|
|
|
putBackupKeys := httputil.MakeAuthAPI("put_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
if version == "" {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 400,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
2021-07-27 11:08:53 -05:00
|
|
|
}
|
2021-07-28 04:25:45 -05:00
|
|
|
}
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
})
|
|
|
|
|
2021-07-27 11:08:53 -05:00
|
|
|
// Single room bulk session
|
2021-07-28 04:25:45 -05:00
|
|
|
putBackupKeysRoom := httputil.MakeAuthAPI("put_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
if version == "" {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 400,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
2021-07-27 11:08:53 -05:00
|
|
|
}
|
2021-07-28 04:25:45 -05:00
|
|
|
}
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
var reqBody keyBackupSessionRequest
|
|
|
|
reqBody.Rooms = make(map[string]struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
})
|
|
|
|
reqBody.Rooms[roomID] = struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
}{
|
|
|
|
Sessions: map[string]userapi.KeyBackupSession{},
|
|
|
|
}
|
|
|
|
body := reqBody.Rooms[roomID]
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &body)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
reqBody.Rooms[roomID] = body
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &reqBody)
|
|
|
|
})
|
|
|
|
|
2021-07-27 11:08:53 -05:00
|
|
|
// Single room, single session
|
2021-07-28 04:25:45 -05:00
|
|
|
putBackupKeysRoomSession := httputil.MakeAuthAPI("put_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
if version == "" {
|
|
|
|
return util.JSONResponse{
|
|
|
|
Code: 400,
|
|
|
|
JSON: jsonerror.InvalidArgumentValue("version must be specified"),
|
2021-07-27 13:29:32 -05:00
|
|
|
}
|
2021-07-28 04:25:45 -05:00
|
|
|
}
|
|
|
|
var reqBody userapi.KeyBackupSession
|
|
|
|
resErr := clientutil.UnmarshalJSONRequest(req, &reqBody)
|
|
|
|
if resErr != nil {
|
|
|
|
return *resErr
|
|
|
|
}
|
|
|
|
roomID := vars["roomID"]
|
|
|
|
sessionID := vars["sessionID"]
|
|
|
|
var keyReq keyBackupSessionRequest
|
|
|
|
keyReq.Rooms = make(map[string]struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
})
|
|
|
|
keyReq.Rooms[roomID] = struct {
|
|
|
|
Sessions map[string]userapi.KeyBackupSession `json:"sessions"`
|
|
|
|
}{
|
|
|
|
Sessions: make(map[string]userapi.KeyBackupSession),
|
|
|
|
}
|
|
|
|
keyReq.Rooms[roomID].Sessions[sessionID] = reqBody
|
|
|
|
return UploadBackupKeys(req, userAPI, device, version, &keyReq)
|
|
|
|
})
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/room_keys/keys", putBackupKeys).Methods(http.MethodPut)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}", putBackupKeysRoom).Methods(http.MethodPut)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}/{sessionID}", putBackupKeysRoomSession).Methods(http.MethodPut)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/keys", putBackupKeys).Methods(http.MethodPut)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}", putBackupKeysRoom).Methods(http.MethodPut)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}/{sessionID}", putBackupKeysRoomSession).Methods(http.MethodPut)
|
2021-07-27 11:08:53 -05:00
|
|
|
|
2021-07-27 13:29:32 -05:00
|
|
|
// Querying E2E Backup Keys
|
|
|
|
|
2021-07-28 04:25:45 -05:00
|
|
|
getBackupKeys := httputil.MakeAuthAPI("get_backup_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), "", "")
|
|
|
|
})
|
|
|
|
|
|
|
|
getBackupKeysRoom := httputil.MakeAuthAPI("get_backup_keys_room", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], "")
|
|
|
|
})
|
|
|
|
|
|
|
|
getBackupKeysRoomSession := httputil.MakeAuthAPI("get_backup_keys_room_session", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetBackupKeys(req, userAPI, device, req.URL.Query().Get("version"), vars["roomID"], vars["sessionID"])
|
|
|
|
})
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/room_keys/keys", getBackupKeys).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}", getBackupKeysRoom).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
v3mux.Handle("/room_keys/keys/{roomID}/{sessionID}", getBackupKeysRoomSession).Methods(http.MethodGet, http.MethodOptions)
|
2021-07-28 04:25:45 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/room_keys/keys", getBackupKeys).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}", getBackupKeysRoom).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/room_keys/keys/{roomID}/{sessionID}", getBackupKeysRoomSession).Methods(http.MethodGet, http.MethodOptions)
|
2021-07-27 13:29:32 -05:00
|
|
|
|
|
|
|
// Deleting E2E Backup Keys
|
|
|
|
|
2021-08-04 11:56:29 -05:00
|
|
|
// Cross-signing device keys
|
|
|
|
|
|
|
|
postDeviceSigningKeys := httputil.MakeAuthAPI("post_device_signing_keys", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2022-03-24 16:45:44 -05:00
|
|
|
return UploadCrossSigningDeviceKeys(req, userInteractiveAuth, keyAPI, device, userAPI, cfg)
|
2021-08-04 11:56:29 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
postDeviceSigningSignatures := httputil.MakeAuthAPI("post_device_signing_signatures", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return UploadCrossSigningDeviceSignatures(req, keyAPI, device)
|
|
|
|
})
|
|
|
|
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/device_signing/upload", postDeviceSigningKeys).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
v3mux.Handle("/keys/signatures/upload", postDeviceSigningSignatures).Methods(http.MethodPost, http.MethodOptions)
|
2021-08-04 11:56:29 -05:00
|
|
|
|
|
|
|
unstableMux.Handle("/keys/device_signing/upload", postDeviceSigningKeys).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
unstableMux.Handle("/keys/signatures/upload", postDeviceSigningSignatures).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2020-07-13 10:02:35 -05:00
|
|
|
// Supplying a device ID is deprecated.
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/upload/{deviceID}",
|
2020-07-13 10:02:35 -05:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-07-15 06:02:34 -05:00
|
|
|
return UploadKeys(req, keyAPI, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/upload",
|
2020-07-15 06:02:34 -05:00
|
|
|
httputil.MakeAuthAPI("keys_upload", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return UploadKeys(req, keyAPI, device)
|
2020-07-13 10:02:35 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/query",
|
2020-07-15 12:40:41 -05:00
|
|
|
httputil.MakeAuthAPI("keys_query", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-08-04 11:56:29 -05:00
|
|
|
return QueryKeys(req, keyAPI, device)
|
2020-07-15 12:40:41 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/keys/claim",
|
2020-07-21 08:47:53 -05:00
|
|
|
httputil.MakeAuthAPI("keys_claim", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return ClaimKeys(req, keyAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-02-17 11:38:22 -06:00
|
|
|
v3mux.Handle("/rooms/{roomId}/receipt/{receiptType}/{eventId}",
|
2020-11-09 12:46:11 -06:00
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2021-11-24 06:55:44 -06:00
|
|
|
if r := rateLimits.Limit(req); r != nil {
|
2020-11-09 12:46:11 -06:00
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
2022-03-29 07:14:35 -05:00
|
|
|
return SetReceipt(req, syncProducer, device, vars["roomId"], vars["receiptType"], vars["eventId"])
|
2020-11-09 12:46:11 -06:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2022-04-06 06:11:19 -05:00
|
|
|
v3mux.Handle("/presence/{userId}/status",
|
|
|
|
httputil.MakeAuthAPI("set_presence", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return SetPresence(req, cfg, device, syncProducer, vars["userId"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
v3mux.Handle("/presence/{userId}/status",
|
|
|
|
httputil.MakeAuthAPI("get_presence", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return GetPresence(req, device, natsClient, cfg.Matrix.JetStream.Prefixed(jetstream.RequestPresence), vars["userId"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2017-02-20 09:41:29 -06:00
|
|
|
}
|