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 (
|
2017-04-20 11:11:53 -05:00
|
|
|
"encoding/json"
|
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"
|
2020-06-10 06:17:54 -05:00
|
|
|
eduServerAPI "github.com/matrix-org/dendrite/eduserver/api"
|
2019-10-01 11:09:47 -05:00
|
|
|
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/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"
|
2020-07-02 09:41:18 -05:00
|
|
|
userapi "github.com/matrix-org/dendrite/userapi/api"
|
2020-06-17 06:05:56 -05:00
|
|
|
"github.com/matrix-org/dendrite/userapi/storage/accounts"
|
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"
|
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(
|
2021-07-09 10:52:31 -05:00
|
|
|
publicAPIMux, synapseAdminRouter *mux.Router, cfg *config.ClientAPI,
|
2020-06-10 06:17:54 -05:00
|
|
|
eduAPI eduServerAPI.EDUServerInputAPI,
|
2020-05-01 04:48:17 -05:00
|
|
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
2018-08-20 04:45:17 -05:00
|
|
|
asAPI appserviceAPI.AppServiceQueryAPI,
|
2020-02-13 11:27:33 -06:00
|
|
|
accountDB accounts.Database,
|
2020-07-02 11:11:33 -05:00
|
|
|
userAPI userapi.UserInternalAPI,
|
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,
|
2020-04-29 05:34:31 -05:00
|
|
|
federationSender federationSenderAPI.FederationSenderInternalAPI,
|
2020-07-15 06:02:34 -05:00
|
|
|
keyAPI keyserverAPI.KeyInternalAPI,
|
2020-07-03 06:59:00 -05:00
|
|
|
extRoomsProvider api.ExtraPublicRoomsProvider,
|
2021-01-22 10:08:47 -06:00
|
|
|
mscCfg *config.MSCs,
|
2017-05-25 10:08:28 -05:00
|
|
|
) {
|
2020-09-03 04:12:11 -05:00
|
|
|
rateLimits := newRateLimits(&cfg.RateLimiting)
|
2020-07-09 18:39:44 -05:00
|
|
|
userInteractiveAuth := auth.NewUserInteractive(accountDB.GetAccountByPassword, cfg)
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2021-01-18 07:09:28 -06:00
|
|
|
unstableFeatures := make(map[string]bool)
|
|
|
|
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",
|
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)
|
|
|
|
}
|
|
|
|
|
2020-08-13 06:16:37 -05:00
|
|
|
r0mux := publicAPIMux.PathPrefix("/r0").Subrouter()
|
|
|
|
unstableMux := publicAPIMux.PathPrefix("/unstable").Subrouter()
|
2017-06-27 06:37:25 -05:00
|
|
|
|
2017-05-18 07:47:23 -05:00
|
|
|
r0mux.Handle("/createRoom",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("createRoom", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-06-10 06:17:54 -05:00
|
|
|
return CreateRoom(req, device, cfg, accountDB, rsAPI, asAPI)
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-05-25 10:08:28 -05:00
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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(
|
2020-05-13 08:53:25 -05:00
|
|
|
req, device, rsAPI, accountDB, 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") {
|
|
|
|
r0mux.Handle("/peek/{roomIDOrAlias}",
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Peek, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return PeekRoomByIDOrAlias(
|
|
|
|
req, device, rsAPI, accountDB, vars["roomIDOrAlias"],
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
}
|
2020-03-19 05:25:36 -05:00
|
|
|
r0mux.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)
|
2020-06-24 12:19:54 -05:00
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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(
|
|
|
|
req, device, rsAPI, accountDB, vars["roomID"],
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2020-05-04 12:34:09 -05:00
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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)
|
2020-12-03 05:11:46 -06:00
|
|
|
r0mux.Handle("/rooms/{roomID}/unpeek",
|
|
|
|
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(
|
|
|
|
req, device, rsAPI, accountDB, vars["roomID"],
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2020-06-24 12:19:54 -05:00
|
|
|
r0mux.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)
|
|
|
|
}
|
|
|
|
return SendBan(req, accountDB, device, vars["roomID"], cfg, rsAPI, asAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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 SendInvite(req, accountDB, device, vars["roomID"], cfg, rsAPI, asAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
r0mux.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)
|
|
|
|
}
|
2020-09-04 06:30:56 -05:00
|
|
|
return SendKick(req, accountDB, device, vars["roomID"], cfg, rsAPI, asAPI)
|
2020-06-24 12:19:54 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
r0mux.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)
|
|
|
|
}
|
2020-06-24 12:19:54 -05:00
|
|
|
return SendUnban(req, accountDB, 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)
|
2017-09-26 06:55:48 -05:00
|
|
|
r0mux.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)
|
2017-03-15 06:22:40 -05:00
|
|
|
r0mux.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)
|
2019-08-09 04:45:54 -05:00
|
|
|
r0mux.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)
|
|
|
|
}
|
2020-06-15 04:13:57 -05:00
|
|
|
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, federation)
|
2019-08-09 04:45:54 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
2020-04-14 12:36:08 -05:00
|
|
|
|
2020-07-02 11:11:33 -05:00
|
|
|
r0mux.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)
|
|
|
|
|
2021-07-21 10:53:50 -05:00
|
|
|
r0mux.Handle("/rooms/{roomID}/aliases", httputil.MakeAuthAPI("aliases", 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 GetAliases(req, rsAPI, device, vars["roomID"])
|
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2020-07-02 11:11:33 -05:00
|
|
|
r0mux.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
|
|
|
|
eventType := vars["type"]
|
|
|
|
if strings.HasSuffix(eventType, "/") {
|
|
|
|
eventType = eventType[:len(eventType)-1]
|
|
|
|
}
|
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)
|
|
|
|
|
2020-07-02 11:11:33 -05:00
|
|
|
r0mux.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)
|
|
|
|
|
2017-08-18 09:33:40 -05:00
|
|
|
r0mux.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 := ""
|
2017-08-18 09:33:40 -05:00
|
|
|
eventType := vars["eventType"]
|
|
|
|
// If there's a trailing slash, remove it
|
|
|
|
if strings.HasSuffix(eventType, "/") {
|
|
|
|
eventType = eventType[:len(eventType)-1]
|
|
|
|
}
|
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
|
|
|
|
2017-03-17 06:21:52 -05:00
|
|
|
r0mux.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
|
|
|
|
2020-06-12 08:55:57 -05:00
|
|
|
r0mux.Handle("/register", httputil.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
2020-06-17 05:22:26 -05:00
|
|
|
return Register(req, userAPI, accountDB, cfg)
|
2018-03-13 10:55:45 -05:00
|
|
|
})).Methods(http.MethodPost, http.MethodOptions)
|
2017-09-22 10:13:19 -05:00
|
|
|
|
2020-06-12 08:55:57 -05:00
|
|
|
r0mux.Handle("/register/available", httputil.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
2018-08-20 04:23:01 -05:00
|
|
|
return RegisterAvailable(req, cfg, accountDB)
|
2018-03-13 10:55:45 -05:00
|
|
|
})).Methods(http.MethodGet, http.MethodOptions)
|
2017-10-09 09:24:38 -05:00
|
|
|
|
2017-06-27 06:37:25 -05:00
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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)
|
2020-07-02 09:41:18 -05:00
|
|
|
r0mux.Handle("/directory/list/room/{roomID}",
|
|
|
|
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
|
|
|
|
r0mux.Handle("/directory/list/room/{roomID}",
|
|
|
|
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)
|
|
|
|
r0mux.Handle("/publicRooms",
|
|
|
|
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
|
|
|
|
2017-07-11 10:04:34 -05:00
|
|
|
r0mux.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
|
|
|
|
2017-10-15 05:29:47 -05:00
|
|
|
r0mux.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
|
|
|
|
2018-07-24 09:49:49 -05:00
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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)
|
|
|
|
}
|
2020-09-04 06:30:56 -05:00
|
|
|
return SendTyping(req, device, vars["roomID"], vars["userID"], accountDB, eduAPI, rsAPI)
|
2018-07-24 09:49:49 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2020-07-03 11:24:51 -05:00
|
|
|
r0mux.Handle("/rooms/{roomID}/redact/{eventID}",
|
|
|
|
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)
|
|
|
|
}
|
2020-09-04 06:30:56 -05:00
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
|
2020-07-03 11:24:51 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2020-08-25 04:39:30 -05:00
|
|
|
r0mux.Handle("/rooms/{roomID}/redact/{eventID}/{txnId}",
|
|
|
|
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)
|
|
|
|
}
|
2020-09-04 06:30:56 -05:00
|
|
|
return SendRedaction(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI)
|
2020-08-25 04:39:30 -05:00
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2018-07-24 09:49:49 -05:00
|
|
|
|
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
|
|
|
r0mux.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"]
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendToDevice(req, device, eduAPI, 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"]
|
2020-06-10 06:17:54 -05:00
|
|
|
return SendToDevice(req, device, eduAPI, 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)
|
|
|
|
|
2018-08-04 04:32:02 -05:00
|
|
|
r0mux.Handle("/account/whoami",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("whoami", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
2018-08-04 04:32:02 -05:00
|
|
|
return Whoami(req, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
|
2020-09-04 09:16:13 -05:00
|
|
|
r0mux.Handle("/account/password",
|
|
|
|
httputil.MakeAuthAPI("password", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
return Password(req, userAPI, accountDB, device, cfg)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2020-10-02 11:18:20 -05:00
|
|
|
r0mux.Handle("/account/deactivate",
|
|
|
|
httputil.MakeAuthAPI("deactivate", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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
|
|
|
|
|
|
|
r0mux.Handle("/login",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
2020-07-31 08:40:45 -05:00
|
|
|
return Login(req, accountDB, 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
|
|
|
|
2019-08-14 12:34:49 -05:00
|
|
|
r0mux.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)
|
|
|
|
|
2017-04-20 11:11:53 -05:00
|
|
|
r0mux.Handle("/pushrules/",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("push_rules", func(req *http.Request) util.JSONResponse {
|
2017-04-20 11:11:53 -05:00
|
|
|
// TODO: Implement push rules API
|
|
|
|
res := json.RawMessage(`{
|
|
|
|
"global": {
|
|
|
|
"content": [],
|
|
|
|
"override": [],
|
|
|
|
"room": [],
|
|
|
|
"sender": [],
|
|
|
|
"underride": []
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2017-04-20 11:11:53 -05:00
|
|
|
JSON: &res,
|
|
|
|
}
|
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
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
// Element user settings
|
2017-04-20 11:11:53 -05:00
|
|
|
|
|
|
|
r0mux.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)
|
|
|
|
}
|
2020-02-11 05:18:12 -06:00
|
|
|
return GetProfile(req, accountDB, 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
|
|
|
|
2017-07-10 08:52:41 -05:00
|
|
|
r0mux.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)
|
|
|
|
}
|
2020-02-11 05:18:12 -06:00
|
|
|
return GetAvatarURL(req, accountDB, 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
|
|
|
|
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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)
|
|
|
|
}
|
2020-09-07 08:47:59 -05:00
|
|
|
return SetAvatarURL(req, accountDB, 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
|
|
|
|
|
|
|
|
r0mux.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)
|
|
|
|
}
|
2020-02-11 05:18:12 -06:00
|
|
|
return GetDisplayName(req, accountDB, 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
|
|
|
|
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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)
|
|
|
|
}
|
2020-09-07 08:47:59 -05:00
|
|
|
return SetDisplayName(req, accountDB, 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
|
|
|
|
|
2017-04-20 11:11:53 -05:00
|
|
|
r0mux.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 {
|
2017-10-11 12:16:53 -05:00
|
|
|
return GetAssociated3PIDs(req, accountDB, 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
|
|
|
|
|
|
|
r0mux.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 {
|
2017-10-11 12:16:53 -05:00
|
|
|
return CheckAndSave3PIDAssociation(req, accountDB, 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 {
|
2017-10-11 12:16:53 -05:00
|
|
|
return Forget3PID(req, accountDB)
|
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
|
|
|
|
|
|
|
r0mux.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 {
|
2017-10-11 12:16:53 -05:00
|
|
|
return RequestEmailToken(req, accountDB, 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
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
// Element logs get flooded unless this is handled
|
2017-04-20 11:11:53 -05:00
|
|
|
r0mux.Handle("/presence/{userID}/status",
|
2020-06-12 08:55:57 -05:00
|
|
|
httputil.MakeExternalAPI("presence", func(req *http.Request) util.JSONResponse {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
2017-04-20 11:11:53 -05:00
|
|
|
// TODO: Set presence (probably the responsibility of a presence server not clientapi)
|
|
|
|
return util.JSONResponse{
|
2018-03-13 10:55:45 -05:00
|
|
|
Code: http.StatusOK,
|
2017-04-20 11:11:53 -05:00
|
|
|
JSON: struct{}{},
|
|
|
|
}
|
2017-05-18 07:47:23 -05:00
|
|
|
}),
|
2018-03-13 10:55:45 -05:00
|
|
|
).Methods(http.MethodPut, http.MethodOptions)
|
2017-04-20 11:11:53 -05:00
|
|
|
|
2017-06-27 06:37:25 -05:00
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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
|
|
|
|
2020-03-19 06:04:08 -05:00
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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
|
|
|
|
2020-01-29 11:53:05 -06:00
|
|
|
r0mux.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)
|
|
|
|
|
|
|
|
r0mux.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)
|
|
|
|
|
2020-11-17 04:07:03 -06:00
|
|
|
r0mux.Handle("/admin/whois/{userID}",
|
|
|
|
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)
|
|
|
|
|
2021-04-07 07:26:20 -05:00
|
|
|
r0mux.Handle("/user/{userID}/openid/request_token",
|
|
|
|
httputil.MakeAuthAPI("openid_request_token", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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)
|
|
|
|
|
2020-07-28 04:53:17 -05:00
|
|
|
r0mux.Handle("/user_directory/search",
|
|
|
|
httputil.MakeAuthAPI("userdirectory_search", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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
|
|
|
}
|
|
|
|
return *SearchUserDirectory(
|
|
|
|
req.Context(),
|
|
|
|
device,
|
|
|
|
userAPI,
|
2020-09-04 05:46:01 -05:00
|
|
|
rsAPI,
|
2020-07-28 04:53:17 -05:00
|
|
|
cfg.Matrix.ServerName,
|
|
|
|
postContent.SearchString,
|
|
|
|
postContent.Limit,
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2017-08-21 10:34:26 -05:00
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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
|
|
|
|
2017-06-27 06:37:25 -05:00
|
|
|
r0mux.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 {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
2020-10-09 03:15:35 -05:00
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
2020-11-09 12:46:11 -06:00
|
|
|
return SaveReadMarker(req, userAPI, rsAPI, eduAPI, 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
|
|
|
|
2020-11-05 04:19:23 -06:00
|
|
|
r0mux.Handle("/rooms/{roomID}/forget",
|
|
|
|
httputil.MakeAuthAPI("rooms_forget", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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)
|
|
|
|
|
2017-10-17 13:12:54 -05:00
|
|
|
r0mux.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
|
|
|
|
2018-05-24 07:53:22 -05:00
|
|
|
r0mux.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
|
|
|
|
2017-11-14 03:59:02 -06:00
|
|
|
r0mux.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
|
|
|
|
2020-02-11 06:13:38 -06:00
|
|
|
r0mux.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)
|
|
|
|
|
|
|
|
r0mux.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)
|
|
|
|
|
2017-09-22 11:28:29 -05:00
|
|
|
// Stub implementations for sytest
|
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.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)
|
|
|
|
|
|
|
|
r0mux.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)
|
|
|
|
|
|
|
|
r0mux.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
|
|
|
|
|
|
|
r0mux.Handle("/capabilities",
|
2020-07-02 11:11:33 -05:00
|
|
|
httputil.MakeAuthAPI("capabilities", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
2020-09-03 04:12:11 -05:00
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
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 06:47:32 -05:00
|
|
|
// Key Backup Versions
|
|
|
|
r0mux.Handle("/room_keys/version/{versionID}",
|
|
|
|
httputil.MakeAuthAPI("get_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
version := req.URL.Query().Get("version")
|
|
|
|
return KeyBackupVersion(req, userAPI, device, version)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
r0mux.Handle("/room_keys/version",
|
|
|
|
httputil.MakeAuthAPI("get_latest_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return KeyBackupVersion(req, userAPI, device, "")
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodGet, http.MethodOptions)
|
|
|
|
r0mux.Handle("/room_keys/version/{versionID}",
|
|
|
|
httputil.MakeAuthAPI("put_backup_keys_version", 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"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ModifyKeyBackupVersionAuthData(req, userAPI, device, version)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPut)
|
|
|
|
r0mux.Handle("/room_keys/version/{versionID}",
|
|
|
|
httputil.MakeAuthAPI("delete_backup_keys_version", 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"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DeleteKeyBackupVersion(req, userAPI, device, version)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodDelete)
|
|
|
|
r0mux.Handle("/room_keys/version",
|
|
|
|
httputil.MakeAuthAPI("post_new_backup_keys_version", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return CreateKeyBackupVersion(req, userAPI, device)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
2020-07-13 10:02:35 -05:00
|
|
|
// Supplying a device ID is deprecated.
|
|
|
|
r0mux.Handle("/keys/upload/{deviceID}",
|
|
|
|
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)
|
|
|
|
r0mux.Handle("/keys/upload",
|
|
|
|
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)
|
2020-07-15 12:40:41 -05:00
|
|
|
r0mux.Handle("/keys/query",
|
|
|
|
httputil.MakeAuthAPI("keys_query", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return QueryKeys(req, keyAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2020-07-21 08:47:53 -05:00
|
|
|
r0mux.Handle("/keys/claim",
|
|
|
|
httputil.MakeAuthAPI("keys_claim", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
return ClaimKeys(req, keyAPI)
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2020-11-09 12:46:11 -06:00
|
|
|
r0mux.Handle("/rooms/{roomId}/receipt/{receiptType}/{eventId}",
|
|
|
|
httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
|
|
|
if r := rateLimits.rateLimit(req); r != nil {
|
|
|
|
return *r
|
|
|
|
}
|
|
|
|
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
|
|
|
if err != nil {
|
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetReceipt(req, eduAPI, device, vars["roomId"], vars["receiptType"], vars["eventId"])
|
|
|
|
}),
|
|
|
|
).Methods(http.MethodPost, http.MethodOptions)
|
2017-02-20 09:41:29 -06:00
|
|
|
}
|