mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
normalize metadata keys in sub/unsub
This commit is contained in:
parent
401a16365a
commit
0bec0a81a1
2 changed files with 12 additions and 4 deletions
|
|
@ -839,6 +839,8 @@ func (session *Session) isSubscribedTo(key string) bool {
|
|||
}
|
||||
|
||||
func (session *Session) SubscribeTo(keys ...string) ([]string, error) {
|
||||
maxSubs := session.client.server.Config().Metadata.MaxSubs
|
||||
|
||||
session.client.stateMutex.Lock()
|
||||
defer session.client.stateMutex.Unlock()
|
||||
|
||||
|
|
@ -848,8 +850,6 @@ func (session *Session) SubscribeTo(keys ...string) ([]string, error) {
|
|||
|
||||
var added []string
|
||||
|
||||
maxSubs := session.client.server.Config().Metadata.MaxSubs
|
||||
|
||||
for _, k := range keys {
|
||||
if !session.metadataSubscriptions.Has(k) {
|
||||
if len(session.metadataSubscriptions) > maxSubs {
|
||||
|
|
|
|||
|
|
@ -3316,10 +3316,18 @@ func metadataUnregisteredHandler(client *Client, config *Config, subcommand stri
|
|||
// metadataSubsHandler handles subscription-related commands;
|
||||
// these are handled the same whether the client is registered or not
|
||||
func metadataSubsHandler(client *Client, subcommand string, params []string, rb *ResponseBuffer) (exiting bool) {
|
||||
allToLower := func(in []string) (out []string) {
|
||||
out = make([]string, len(in))
|
||||
for i, s := range in {
|
||||
out[i] = strings.ToLower(s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
server := client.server
|
||||
switch subcommand {
|
||||
case "sub":
|
||||
keys := params[2:]
|
||||
keys := allToLower(params[2:])
|
||||
for _, key := range keys {
|
||||
if metadataKeyIsEvil(key) {
|
||||
rb.Add(nil, server.name, "FAIL", "METADATA", "KEY_INVALID", utils.SafeErrorParam(key), client.t("Invalid key name"))
|
||||
|
|
@ -3341,7 +3349,7 @@ func metadataSubsHandler(client *Client, subcommand string, params []string, rb
|
|||
}
|
||||
|
||||
case "unsub":
|
||||
keys := params[2:]
|
||||
keys := allToLower(params[2:])
|
||||
removed := rb.session.UnsubscribeFrom(keys...)
|
||||
|
||||
lineLength := MaxLineLen - len(server.name) - len(RPL_METADATAUNSUBOK) - len(client.Nick()) - 10
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue