mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48:27 +00:00
Compile room and alias namespace regexs
We'll be needing these for event filtering in the appservice component. Signed-off-by: Andrew Morgan <andrewm@matrix.org>
This commit is contained in:
parent
c238048599
commit
c15cfcb0ff
1 changed files with 16 additions and 8 deletions
|
@ -48,7 +48,8 @@ type ApplicationService struct {
|
||||||
HSToken string `yaml:"hs_token"`
|
HSToken string `yaml:"hs_token"`
|
||||||
// Localpart of application service user
|
// Localpart of application service user
|
||||||
SenderLocalpart string `yaml:"sender_localpart"`
|
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"`
|
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
|
// 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
|
// regex and deny access if it isn't from an application service
|
||||||
exclusiveUsernames := strings.Join(exclusiveUsernameStrings, "|")
|
exclusiveUsernames := strings.Join(exclusiveUsernameStrings, "|")
|
||||||
|
exclusiveAliases := strings.Join(exclusiveAliasStrings, "|")
|
||||||
|
exclusiveRooms := strings.Join(exclusiveRoomStrings, "|")
|
||||||
|
|
||||||
// If there are no exclusive username regexes, compile string so that it
|
// If there are no exclusive regexes, compile string so that it will not match
|
||||||
// will not match any valid usernames
|
// any valid usernames/aliases/roomIDs
|
||||||
if exclusiveUsernames == "" {
|
if exclusiveUsernames == "" {
|
||||||
exclusiveUsernames = "^$"
|
exclusiveUsernames = "^$"
|
||||||
}
|
}
|
||||||
|
if exclusiveAliases == "" {
|
||||||
// TODO: Aliases and rooms. Needed?
|
exclusiveAliases = "^$"
|
||||||
//exclusiveAliases := strings.Join(exclusiveAliasStrings, "|")
|
}
|
||||||
//exclusiveRooms := strings.Join(exclusiveRoomStrings, "|")
|
if exclusiveRooms == "" {
|
||||||
|
exclusiveRooms = "^$"
|
||||||
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveUsernames)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// concatenateExclusiveNamespaces takes a slice of strings and a slice of
|
// Store compiled Regex
|
||||||
|
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveUsernames)
|
||||||
|
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveAliases)
|
||||||
|
cfg.Derived.ExclusiveApplicationServicesUsernameRegexp, _ = regexp.Compile(exclusiveRooms)
|
||||||
|
}
|
||||||
|
|
||||||
|
// appendExclusiveNamespaceRegexs takes a slice of strings and a slice of
|
||||||
// namespaces and will append the regexes of only the exclusive namespaces
|
// namespaces and will append the regexes of only the exclusive namespaces
|
||||||
// into the string slice
|
// into the string slice
|
||||||
func appendExclusiveNamespaceRegexs(
|
func appendExclusiveNamespaceRegexs(
|
||||||
|
|
Loading…
Reference in a new issue