From c15cfcb0ff0b0a356a8c8e41664fa18a9a68c31c Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 24 May 2018 11:14:47 +0100 Subject: [PATCH] Compile room and alias namespace regexs We'll be needing these for event filtering in the appservice component. Signed-off-by: Andrew Morgan --- .../dendrite/common/config/appservice.go | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/common/config/appservice.go b/src/github.com/matrix-org/dendrite/common/config/appservice.go index 4d91f958..506be9a8 100644 --- a/src/github.com/matrix-org/dendrite/common/config/appservice.go +++ b/src/github.com/matrix-org/dendrite/common/config/appservice.go @@ -48,7 +48,8 @@ type ApplicationService struct { HSToken string `yaml:"hs_token"` // Localpart of application service user SenderLocalpart string `yaml:"sender_localpart"` - // Information about an application service's namespaces + // Information about an application service's namespaces. Key is either + // "users", "aliases" or "rooms" NamespaceMap map[string][]ApplicationServiceNamespace `yaml:"namespaces"` } @@ -112,21 +113,28 @@ func setupRegexps(cfg *Dendrite) { // Later we can check if a username or some other string matches any exclusive // regex and deny access if it isn't from an application service exclusiveUsernames := strings.Join(exclusiveUsernameStrings, "|") + exclusiveAliases := strings.Join(exclusiveAliasStrings, "|") + exclusiveRooms := strings.Join(exclusiveRoomStrings, "|") - // If there are no exclusive username regexes, compile string so that it - // will not match any valid usernames + // If there are no exclusive regexes, compile string so that it will not match + // any valid usernames/aliases/roomIDs if exclusiveUsernames == "" { exclusiveUsernames = "^$" } + if exclusiveAliases == "" { + exclusiveAliases = "^$" + } + if exclusiveRooms == "" { + exclusiveRooms = "^$" + } - // TODO: Aliases and rooms. Needed? - //exclusiveAliases := strings.Join(exclusiveAliasStrings, "|") - //exclusiveRooms := strings.Join(exclusiveRoomStrings, "|") - + // Store compiled Regex cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveUsernames) + cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveAliases) + cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveRooms) } -// concatenateExclusiveNamespaces takes a slice of strings and a slice of +// appendExclusiveNamespaceRegexs takes a slice of strings and a slice of // namespaces and will append the regexes of only the exclusive namespaces // into the string slice func appendExclusiveNamespaceRegexs(