From d66244cb0ac223d638f379cacec74579814d3702 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 11 Oct 2017 18:16:53 +0100 Subject: [PATCH] Merge readers/writers/routing packages (#295) The HTTP handlers in the components are split into reader and writer directories. This was a fairly arbitrary distinction, and turns out to not be so helpful. Most read APIs have a corresponding write API, and it is more natural for them to be in the same file rather than in different directories. --- .../{readers => routing}/account_data.go | 2 +- .../{writers => routing}/createroom.go | 2 +- .../{readers => routing}/directory.go | 2 +- .../clientapi/{readers => routing}/filter.go | 53 +++++++++++- .../{writers => routing}/joinroom.go | 2 +- .../clientapi/{readers => routing}/login.go | 2 +- .../clientapi/{readers => routing}/logout.go | 2 +- .../{writers => routing}/membership.go | 2 +- .../{readers => routing}/memberships.go | 2 +- .../clientapi/{readers => routing}/profile.go | 2 +- .../{writers => routing}/register.go | 17 +++- .../dendrite/clientapi/routing/routing.go | 63 +++++++-------- .../{writers => routing}/sendevent.go | 2 +- .../{readers => routing}/threepid.go | 2 +- .../dendrite/clientapi/writers/filter.go | 80 ------------------- .../{writers => routing}/invite.go | 2 +- .../dendrite/federationapi/routing/routing.go | 9 +-- .../{writers => routing}/send.go | 2 +- .../{writers => routing}/threepid.go | 2 +- .../mediaapi/{writers => routing}/download.go | 2 +- .../dendrite/mediaapi/routing/routing.go | 5 +- .../mediaapi/{writers => routing}/upload.go | 2 +- 22 files changed, 120 insertions(+), 139 deletions(-) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/account_data.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{writers => routing}/createroom.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/directory.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/filter.go (64%) rename src/github.com/matrix-org/dendrite/clientapi/{writers => routing}/joinroom.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/login.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/logout.go (98%) rename src/github.com/matrix-org/dendrite/clientapi/{writers => routing}/membership.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/memberships.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/profile.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{writers => routing}/register.go (95%) rename src/github.com/matrix-org/dendrite/clientapi/{writers => routing}/sendevent.go (99%) rename src/github.com/matrix-org/dendrite/clientapi/{readers => routing}/threepid.go (99%) delete mode 100644 src/github.com/matrix-org/dendrite/clientapi/writers/filter.go rename src/github.com/matrix-org/dendrite/federationapi/{writers => routing}/invite.go (99%) rename src/github.com/matrix-org/dendrite/federationapi/{writers => routing}/send.go (99%) rename src/github.com/matrix-org/dendrite/federationapi/{writers => routing}/threepid.go (99%) rename src/github.com/matrix-org/dendrite/mediaapi/{writers => routing}/download.go (99%) rename src/github.com/matrix-org/dendrite/mediaapi/{writers => routing}/upload.go (99%) diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/account_data.go b/src/github.com/matrix-org/dendrite/clientapi/routing/account_data.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/readers/account_data.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/account_data.go index 9846fd61..bd387eb9 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/account_data.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/account_data.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "io/ioutil" diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go b/src/github.com/matrix-org/dendrite/clientapi/routing/createroom.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/createroom.go index 200d3b93..7e40cb77 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/createroom.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "encoding/json" diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/directory.go b/src/github.com/matrix-org/dendrite/clientapi/routing/directory.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/readers/directory.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/directory.go index a333c0d6..13ab8e2b 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/directory.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/directory.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "net/http" diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/filter.go b/src/github.com/matrix-org/dendrite/clientapi/routing/filter.go similarity index 64% rename from src/github.com/matrix-org/dendrite/clientapi/readers/filter.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/filter.go index db981bec..3c623147 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/filter.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/filter.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "net/http" @@ -70,3 +70,54 @@ func GetFilter( JSON: filter, } } + +type filterResponse struct { + FilterID string `json:"filter_id"` +} + +//PutFilter implements POST /_matrix/client/r0/user/{userId}/filter +func PutFilter( + req *http.Request, device *authtypes.Device, accountDB *accounts.Database, userID string, +) util.JSONResponse { + if req.Method != http.MethodPost { + return util.JSONResponse{ + Code: 405, + JSON: jsonerror.NotFound("Bad method"), + } + } + if userID != device.UserID { + return util.JSONResponse{ + Code: 403, + JSON: jsonerror.Forbidden("Cannot create filters for other users"), + } + } + + localpart, _, err := gomatrixserverlib.SplitID('@', userID) + if err != nil { + return httputil.LogThenError(req, err) + } + + var filter gomatrix.Filter + + if reqErr := httputil.UnmarshalJSONRequest(req, &filter); reqErr != nil { + return *reqErr + } + + filterArray, err := json.Marshal(filter) + if err != nil { + return util.JSONResponse{ + Code: 400, + JSON: jsonerror.BadJSON("Filter is malformed"), + } + } + + filterID, err := accountDB.PutFilter(req.Context(), localpart, string(filterArray)) + if err != nil { + return httputil.LogThenError(req, err) + } + + return util.JSONResponse{ + Code: 200, + JSON: filterResponse{FilterID: filterID}, + } +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/joinroom.go b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/writers/joinroom.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go index 4ebdadca..890d6f1a 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/joinroom.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "fmt" diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/login.go b/src/github.com/matrix-org/dendrite/clientapi/routing/login.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/readers/login.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/login.go index ddbac12c..2fa44d6d 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/login.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/login.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "net/http" diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/logout.go b/src/github.com/matrix-org/dendrite/clientapi/routing/logout.go similarity index 98% rename from src/github.com/matrix-org/dendrite/clientapi/readers/logout.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/logout.go index 9e46c74c..ff214fe5 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/logout.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/logout.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "net/http" diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/membership.go b/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/writers/membership.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/membership.go index 41c42240..fec27ae7 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/membership.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "context" diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/memberships.go b/src/github.com/matrix-org/dendrite/clientapi/routing/memberships.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/readers/memberships.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/memberships.go index a135117e..a4b60531 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/memberships.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/memberships.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "net/http" diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go b/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/readers/profile.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/profile.go index 532f01e4..918292e5 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/profile.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "context" diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/register.go b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go similarity index 95% rename from src/github.com/matrix-org/dendrite/clientapi/writers/register.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/register.go index a405f5ef..eafa0b0b 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/register.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/register.go @@ -1,4 +1,19 @@ -package writers +// Copyright 2017 Vector Creations Ltd +// Copyright 2017 New Vector Ltd +// +// 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. + +package routing import ( "context" diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index 66240a08..0b9e4172 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -25,8 +25,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" - "github.com/matrix-org/dendrite/clientapi/readers" - "github.com/matrix-org/dendrite/clientapi/writers" "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/roomserver/api" @@ -73,13 +71,13 @@ func Setup( r0mux.Handle("/createRoom", common.MakeAuthAPI("createRoom", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return writers.CreateRoom(req, device, cfg, producer, accountDB, aliasAPI) + return CreateRoom(req, device, cfg, producer, accountDB, aliasAPI) }), ).Methods("POST", "OPTIONS") r0mux.Handle("/join/{roomIDOrAlias}", common.MakeAuthAPI("join", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return writers.JoinRoomByIDOrAlias( + return JoinRoomByIDOrAlias( req, device, vars["roomIDOrAlias"], cfg, federation, producer, queryAPI, aliasAPI, keyRing, accountDB, ) }), @@ -87,20 +85,20 @@ func Setup( r0mux.Handle("/rooms/{roomID}/{membership:(?:join|kick|ban|unban|leave|invite)}", common.MakeAuthAPI("membership", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return writers.SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, queryAPI, producer) + return SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, queryAPI, producer) }), ).Methods("POST", "OPTIONS") r0mux.Handle("/rooms/{roomID}/send/{eventType}", common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, queryAPI, producer) + return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, queryAPI, producer) }), ).Methods("POST", "OPTIONS") r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}", common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) txnID := vars["txnID"] - return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID, nil, cfg, queryAPI, producer) + return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID, nil, cfg, queryAPI, producer) }), ).Methods("PUT", "OPTIONS") r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}", @@ -112,53 +110,53 @@ func Setup( if strings.HasSuffix(eventType, "/") { eventType = eventType[:len(eventType)-1] } - return writers.SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, queryAPI, producer) + return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, queryAPI, producer) }), ).Methods("PUT", "OPTIONS") r0mux.Handle("/rooms/{roomID}/state/{eventType}/{stateKey}", common.MakeAuthAPI("send_message", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) stateKey := vars["stateKey"] - return writers.SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, queryAPI, producer) + return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, queryAPI, producer) }), ).Methods("PUT", "OPTIONS") r0mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse { - return writers.Register(req, accountDB, deviceDB, &cfg) + return Register(req, accountDB, deviceDB, &cfg) })).Methods("POST", "OPTIONS") v1mux.Handle("/register", common.MakeExternalAPI("register", func(req *http.Request) util.JSONResponse { - return writers.LegacyRegister(req, accountDB, deviceDB, &cfg) + return LegacyRegister(req, accountDB, deviceDB, &cfg) })).Methods("POST", "OPTIONS") r0mux.Handle("/register/available", common.MakeExternalAPI("registerAvailable", func(req *http.Request) util.JSONResponse { - return writers.RegisterAvailable(req, accountDB) + return RegisterAvailable(req, accountDB) })).Methods("GET") r0mux.Handle("/directory/room/{roomAlias}", common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.DirectoryRoom(req, vars["roomAlias"], federation, &cfg, aliasAPI) + return DirectoryRoom(req, vars["roomAlias"], federation, &cfg, aliasAPI) }), ).Methods("GET") r0mux.Handle("/directory/room/{roomAlias}", common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.SetLocalAlias(req, device, vars["roomAlias"], &cfg, aliasAPI) + return SetLocalAlias(req, device, vars["roomAlias"], &cfg, aliasAPI) }), ).Methods("PUT", "OPTIONS") r0mux.Handle("/directory/room/{roomAlias}", common.MakeAuthAPI("directory_room", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.RemoveLocalAlias(req, device, vars["roomAlias"], aliasAPI) + return RemoveLocalAlias(req, device, vars["roomAlias"], aliasAPI) }), ).Methods("DELETE") r0mux.Handle("/logout", common.MakeAuthAPI("logout", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return readers.Logout(req, deviceDB, device) + return Logout(req, deviceDB, device) }), ).Methods("POST", "OPTIONS") @@ -166,7 +164,7 @@ func Setup( r0mux.Handle("/login", common.MakeExternalAPI("login", func(req *http.Request) util.JSONResponse { - return readers.Login(req, accountDB, deviceDB, cfg) + return Login(req, accountDB, deviceDB, cfg) }), ).Methods("GET", "POST", "OPTIONS") @@ -189,18 +187,17 @@ func Setup( }), ).Methods("GET") - r0mux.Handle("/user/{userId}/filter", common.MakeAuthAPI("put_filter", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return writers.PutFilter(req, device, accountDB, vars["userId"]) + return PutFilter(req, device, accountDB, vars["userId"]) }), ).Methods("POST", "OPTIONS") r0mux.Handle("/user/{userId}/filter/{filterId}", common.MakeAuthAPI("get_filter", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.GetFilter(req, device, accountDB, vars["userId"], vars["filterId"]) + return GetFilter(req, device, accountDB, vars["userId"], vars["filterId"]) }), ).Methods("GET") @@ -209,21 +206,21 @@ func Setup( r0mux.Handle("/profile/{userID}", common.MakeExternalAPI("profile", func(req *http.Request) util.JSONResponse { vars := mux.Vars(req) - return readers.GetProfile(req, accountDB, vars["userID"]) + return GetProfile(req, accountDB, vars["userID"]) }), ).Methods("GET") r0mux.Handle("/profile/{userID}/avatar_url", common.MakeExternalAPI("profile_avatar_url", func(req *http.Request) util.JSONResponse { vars := mux.Vars(req) - return readers.GetAvatarURL(req, accountDB, vars["userID"]) + return GetAvatarURL(req, accountDB, vars["userID"]) }), ).Methods("GET") r0mux.Handle("/profile/{userID}/avatar_url", common.MakeAuthAPI("profile_avatar_url", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.SetAvatarURL(req, accountDB, device, vars["userID"], userUpdateProducer, &cfg, producer, queryAPI) + return SetAvatarURL(req, accountDB, device, vars["userID"], userUpdateProducer, &cfg, producer, queryAPI) }), ).Methods("PUT", "OPTIONS") // Browsers use the OPTIONS HTTP method to check if the CORS policy allows @@ -232,14 +229,14 @@ func Setup( r0mux.Handle("/profile/{userID}/displayname", common.MakeExternalAPI("profile_displayname", func(req *http.Request) util.JSONResponse { vars := mux.Vars(req) - return readers.GetDisplayName(req, accountDB, vars["userID"]) + return GetDisplayName(req, accountDB, vars["userID"]) }), ).Methods("GET") r0mux.Handle("/profile/{userID}/displayname", common.MakeAuthAPI("profile_displayname", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.SetDisplayName(req, accountDB, device, vars["userID"], userUpdateProducer, &cfg, producer, queryAPI) + return SetDisplayName(req, accountDB, device, vars["userID"], userUpdateProducer, &cfg, producer, queryAPI) }), ).Methods("PUT", "OPTIONS") // Browsers use the OPTIONS HTTP method to check if the CORS policy allows @@ -247,25 +244,25 @@ func Setup( r0mux.Handle("/account/3pid", common.MakeAuthAPI("account_3pid", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return readers.GetAssociated3PIDs(req, accountDB, device) + return GetAssociated3PIDs(req, accountDB, device) }), ).Methods("GET") r0mux.Handle("/account/3pid", common.MakeAuthAPI("account_3pid", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return readers.CheckAndSave3PIDAssociation(req, accountDB, device, cfg) + return CheckAndSave3PIDAssociation(req, accountDB, device, cfg) }), ).Methods("POST", "OPTIONS") unstableMux.Handle("/account/3pid/delete", common.MakeAuthAPI("account_3pid", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return readers.Forget3PID(req, accountDB) + return Forget3PID(req, accountDB) }), ).Methods("POST", "OPTIONS") r0mux.Handle("/{path:(?:account/3pid|register)}/email/requestToken", common.MakeExternalAPI("account_3pid_request_token", func(req *http.Request) util.JSONResponse { - return readers.RequestEmailToken(req, accountDB, cfg) + return RequestEmailToken(req, accountDB, cfg) }), ).Methods("POST", "OPTIONS") @@ -313,28 +310,28 @@ func Setup( r0mux.Handle("/user/{userID}/account_data/{type}", common.MakeAuthAPI("user_account_data", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.SaveAccountData(req, accountDB, device, vars["userID"], "", vars["type"], syncProducer) + return SaveAccountData(req, accountDB, device, vars["userID"], "", vars["type"], syncProducer) }), ).Methods("PUT", "OPTIONS") r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}", common.MakeAuthAPI("user_account_data", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.SaveAccountData(req, accountDB, device, vars["userID"], vars["roomID"], vars["type"], syncProducer) + return SaveAccountData(req, accountDB, device, vars["userID"], vars["roomID"], vars["type"], syncProducer) }), ).Methods("PUT", "OPTIONS") r0mux.Handle("/rooms/{roomID}/members", common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.GetMemberships(req, device, vars["roomID"], false, cfg, queryAPI) + return GetMemberships(req, device, vars["roomID"], false, cfg, queryAPI) }), ).Methods("GET") r0mux.Handle("/rooms/{roomID}/joined_members", common.MakeAuthAPI("rooms_members", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { vars := mux.Vars(req) - return readers.GetMemberships(req, device, vars["roomID"], true, cfg, queryAPI) + return GetMemberships(req, device, vars["roomID"], true, cfg, queryAPI) }), ).Methods("GET") diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/sendevent.go b/src/github.com/matrix-org/dendrite/clientapi/routing/sendevent.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/writers/sendevent.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/sendevent.go index 0b2a6a37..d912f10b 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/sendevent.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/sendevent.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "net/http" diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/threepid.go b/src/github.com/matrix-org/dendrite/clientapi/routing/threepid.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/readers/threepid.go rename to src/github.com/matrix-org/dendrite/clientapi/routing/threepid.go index b038e352..dd04b1ed 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/readers/threepid.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/threepid.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package readers +package routing import ( "net/http" diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/filter.go b/src/github.com/matrix-org/dendrite/clientapi/writers/filter.go deleted file mode 100644 index 6deb9a17..00000000 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/filter.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2017 Jan Christian Grünhage -// -// 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. - -package writers - -import ( - "net/http" - - - "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/util" - "github.com/matrix-org/dendrite/clientapi/jsonerror" - "github.com/matrix-org/gomatrix" - "github.com/matrix-org/gomatrixserverlib" - "github.com/matrix-org/dendrite/clientapi/httputil" - "encoding/json" -) - -type filterResponse struct { - FilterID string `json:"filter_id"` -} - -//PutFilter implements POST /_matrix/client/r0/user/{userId}/filter -func PutFilter( - req *http.Request, device *authtypes.Device, accountDB *accounts.Database, userID string, -) util.JSONResponse { - if req.Method != "POST" { - return util.JSONResponse{ - Code: 405, - JSON: jsonerror.NotFound("Bad method"), - } - } - if userID != device.UserID { - return util.JSONResponse{ - Code: 403, - JSON: jsonerror.Forbidden("Cannot create filters for other users"), - } - } - - localpart, _, err := gomatrixserverlib.SplitID('@', userID) - if err != nil { - return httputil.LogThenError(req, err) - } - - var filter gomatrix.Filter - - if reqErr := httputil.UnmarshalJSONRequest(req, &filter); reqErr != nil { - return *reqErr - } - - filterArray, err := json.Marshal(filter) - if err != nil { - return util.JSONResponse{ - Code: 400, - JSON: jsonerror.BadJSON("Filter is malformed"), - } - } - - filterID, err := accountDB.PutFilter(req.Context(), localpart, string(filterArray)) - if err != nil { - return httputil.LogThenError(req, err) - } - - return util.JSONResponse{ - Code: 200, - JSON: filterResponse{FilterID: filterID}, - } -} diff --git a/src/github.com/matrix-org/dendrite/federationapi/writers/invite.go b/src/github.com/matrix-org/dendrite/federationapi/routing/invite.go similarity index 99% rename from src/github.com/matrix-org/dendrite/federationapi/writers/invite.go rename to src/github.com/matrix-org/dendrite/federationapi/routing/invite.go index 223d2016..26da0d8c 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/writers/invite.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/invite.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "encoding/json" diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go index ec8fcd3b..91668af3 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go @@ -24,7 +24,6 @@ import ( "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/federationapi/readers" - "github.com/matrix-org/dendrite/federationapi/writers" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -63,7 +62,7 @@ func Setup( "federation_send", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { vars := mux.Vars(httpReq) - return writers.Send( + return Send( httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]), cfg, query, producer, keys, federation, ) @@ -74,7 +73,7 @@ func Setup( "federation_invite", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { vars := mux.Vars(httpReq) - return writers.Invite( + return Invite( httpReq, request, vars["roomID"], vars["eventID"], cfg, producer, keys, ) @@ -83,7 +82,7 @@ func Setup( v1fedmux.Handle("/3pid/onbind", common.MakeExternalAPI("3pid_onbind", func(req *http.Request) util.JSONResponse { - return writers.CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation, accountDB) + return CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation, accountDB) }, )).Methods("POST", "OPTIONS") @@ -91,7 +90,7 @@ func Setup( "exchange_third_party_invite", cfg.Matrix.ServerName, keys, func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { vars := mux.Vars(httpReq) - return writers.ExchangeThirdPartyInvite( + return ExchangeThirdPartyInvite( httpReq, request, vars["roomID"], query, cfg, federation, producer, ) }, diff --git a/src/github.com/matrix-org/dendrite/federationapi/writers/send.go b/src/github.com/matrix-org/dendrite/federationapi/routing/send.go similarity index 99% rename from src/github.com/matrix-org/dendrite/federationapi/writers/send.go rename to src/github.com/matrix-org/dendrite/federationapi/routing/send.go index 00e1d8d5..47c5efd0 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/writers/send.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/send.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "context" diff --git a/src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go b/src/github.com/matrix-org/dendrite/federationapi/routing/threepid.go similarity index 99% rename from src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go rename to src/github.com/matrix-org/dendrite/federationapi/routing/threepid.go index 7c4ccfcf..42cf502d 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/writers/threepid.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/threepid.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "context" diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go b/src/github.com/matrix-org/dendrite/mediaapi/routing/download.go similarity index 99% rename from src/github.com/matrix-org/dendrite/mediaapi/writers/download.go rename to src/github.com/matrix-org/dendrite/mediaapi/routing/download.go index c611b336..2d7a4b83 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/download.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/routing/download.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "context" diff --git a/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go b/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go index e43404d3..df5979b3 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/routing/routing.go @@ -25,7 +25,6 @@ import ( "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/mediaapi/storage" "github.com/matrix-org/dendrite/mediaapi/types" - "github.com/matrix-org/dendrite/mediaapi/writers" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" "github.com/prometheus/client_golang/prometheus" @@ -51,7 +50,7 @@ func Setup( "upload", deviceDB, func(req *http.Request, _ *authtypes.Device) util.JSONResponse { - return writers.Upload(req, cfg, db, activeThumbnailGeneration) + return Upload(req, cfg, db, activeThumbnailGeneration) }, )).Methods("POST", "OPTIONS") @@ -83,7 +82,7 @@ func makeDownloadAPI( w.Header().Set("Content-Type", "application/json") vars := mux.Vars(req) - writers.Download( + Download( w, req, gomatrixserverlib.ServerName(vars["serverName"]), diff --git a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go b/src/github.com/matrix-org/dendrite/mediaapi/routing/upload.go similarity index 99% rename from src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go rename to src/github.com/matrix-org/dendrite/mediaapi/routing/upload.go index ca566233..e2b6d387 100644 --- a/src/github.com/matrix-org/dendrite/mediaapi/writers/upload.go +++ b/src/github.com/matrix-org/dendrite/mediaapi/routing/upload.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package writers +package routing import ( "context"