diff --git a/src/github.com/matrix-org/dendrite/federationapi/routing/query.go b/src/github.com/matrix-org/dendrite/federationapi/routing/query.go index 3aa2e4681..ef4b8961a 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/query.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/query.go @@ -15,27 +15,33 @@ package routing import ( - "net/http" "fmt" + "net/http" - "github.com/matrix-org/util" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/util" ) // RoomAliasToID converts the queried alias into a room ID and returns it -func RoomAliasToID ( +func RoomAliasToID( httpReq *http.Request, federation *gomatrixserverlib.FederationClient, cfg config.Dendrite, aliasAPI api.RoomserverAliasAPI, - roomAlias string, ) util.JSONResponse { - _, domain, err := gomatrixserverlib.SplitID('#', httpReq.FormValue("alias")) + roomAlias := httpReq.FormValue("alias") + if roomAlias == "" { + return util.JSONResponse{ + Code: 400, + JSON: jsonerror.BadJSON("Must supply room alias parameter."), + } + } + _, domain, err := gomatrixserverlib.SplitID('#', roomAlias) if err != nil { return util.JSONResponse{ Code: 400, @@ -43,7 +49,7 @@ func RoomAliasToID ( } } -var resp gomatrixserverlib.RespDirectory + var resp gomatrixserverlib.RespDirectory if domain == cfg.Matrix.ServerName { queryReq := api.GetAliasRoomIDRequest{Alias: roomAlias} @@ -52,7 +58,7 @@ var resp gomatrixserverlib.RespDirectory return httputil.LogThenError(httpReq, err) } - if (queryRes.RoomID == "") { + if queryRes.RoomID == "" { // TODO: List servers that are aware of this room alias resp = gomatrixserverlib.RespDirectory{ RoomID: queryRes.RoomID, @@ -87,4 +93,4 @@ var resp gomatrixserverlib.RespDirectory Code: 200, JSON: resp, } -} \ No newline at end of file +} 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 f83826946..3b7e48edc 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/federationapi/routing/routing.go @@ -81,45 +81,44 @@ func Setup( )).Methods("PUT", "OPTIONS") v1fedmux.Handle("/3pid/onbind", common.MakeExternalAPI("3pid_onbind", - func(req *http.Request) util.JSONResponse { - return CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation, accountDB) - }, + func(req *http.Request) util.JSONResponse { + return CreateInvitesFrom3PIDInvites(req, query, cfg, producer, federation, accountDB) + }, )).Methods("POST", "OPTIONS") -v1fedmux.Handle("/exchange_third_party_invite/{roomID}", common.MakeFedAPI( - "exchange_third_party_invite", cfg.Matrix.ServerName, keys, - func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars := mux.Vars(httpReq) - return ExchangeThirdPartyInvite( - httpReq, request, vars["roomID"], query, cfg, federation, producer, - ) - }, -)).Methods("PUT", "OPTIONS") + v1fedmux.Handle("/exchange_third_party_invite/{roomID}", common.MakeFedAPI( + "exchange_third_party_invite", cfg.Matrix.ServerName, keys, + func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { + vars := mux.Vars(httpReq) + return ExchangeThirdPartyInvite( + httpReq, request, vars["roomID"], query, cfg, federation, producer, + ) + }, + )).Methods("PUT", "OPTIONS") -v1fedmux.Handle("/event/{eventID}", common.MakeFedAPI( - "federation_get_event", cfg.Matrix.ServerName, keys, - func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars := mux.Vars(httpReq) - return GetEvent( - httpReq.Context(), request, cfg, query, time.Now(), keys, vars["eventID"], - ) - }, -)).Methods("GET") + v1fedmux.Handle("/event/{eventID}", common.MakeFedAPI( + "federation_get_event", cfg.Matrix.ServerName, keys, + func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { + vars := mux.Vars(httpReq) + return GetEvent( + httpReq.Context(), request, cfg, query, time.Now(), keys, vars["eventID"], + ) + }, + )).Methods("GET") -v1fedmux.Handle("/version", common.MakeExternalAPI( - "federation_version", - func(httpReq *http.Request) util.JSONResponse { - return Version() - }, -)).Methods("GET") + v1fedmux.Handle("/version", common.MakeExternalAPI( + "federation_version", + func(httpReq *http.Request) util.JSONResponse { + return Version() + }, + )).Methods("GET") -v1fedmux.Handle("/query/directory/?room_alias={alias}", common.MakeFedAPI( - "federation_query_room_alias", cfg.Matrix.ServerName, keys, - func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { - vars := mux.Vars(httpReq) - return RoomAliasToID( - httpReq, federation, cfg, aliasAPI, vars["alias"], - ) - }, -)).Methods("Get") -} \ No newline at end of file + v1fedmux.Handle("/query/directory/", common.MakeFedAPI( + "federation_query_room_alias", cfg.Matrix.ServerName, keys, + func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { + return RoomAliasToID( + httpReq, federation, cfg, aliasAPI, + ) + }, + )).Methods("Get") +}