mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-09-26 19:51:26 +08:00
use slices.Contains when possible (#4859)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -47,15 +48,6 @@ func firstThatExists(paths []string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func contains(list []auth.VerifyMethod, item auth.VerifyMethod) bool {
|
||||
for _, i := range list {
|
||||
if i == item {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func copyStructFields(dest interface{}, source interface{}) {
|
||||
rvsource := reflect.ValueOf(source).Elem()
|
||||
rvdest := reflect.ValueOf(dest)
|
||||
@@ -632,7 +624,7 @@ func (conf *Conf) Validate(l logger.Writer) error {
|
||||
l.Log(logger.Warn, "parameter 'authMethods' is deprecated and has been replaced with 'rtspAuthMethods'")
|
||||
conf.RTSPAuthMethods = *conf.AuthMethods
|
||||
}
|
||||
if contains(conf.RTSPAuthMethods, auth.VerifyMethodDigestMD5) {
|
||||
if slices.Contains(conf.RTSPAuthMethods, auth.VerifyMethodDigestMD5) {
|
||||
if conf.AuthMethod != AuthMethodInternal {
|
||||
return fmt.Errorf("when RTSP digest is enabled, the only supported auth method is 'internal'")
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -23,15 +24,6 @@ const (
|
||||
webrtcStreamID = "mediamtx"
|
||||
)
|
||||
|
||||
func stringInSlice(a string, list []string) bool {
|
||||
for _, b := range list {
|
||||
if b == a {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// * skip ConfigureRTCPReports
|
||||
// * add statsInterceptor
|
||||
func registerInterceptors(
|
||||
@@ -145,7 +137,7 @@ func (co *PeerConnection) Start() error {
|
||||
|
||||
settingsEngine.SetInterfaceFilter(func(iface string) bool {
|
||||
return co.IPsFromInterfaces && (len(co.IPsFromInterfacesList) == 0 ||
|
||||
stringInSlice(iface, co.IPsFromInterfacesList))
|
||||
slices.Contains(co.IPsFromInterfacesList, iface))
|
||||
})
|
||||
|
||||
settingsEngine.SetAdditionalHosts(co.AdditionalHosts)
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -42,15 +43,6 @@ func credentialsProvided(req *base.Request) bool {
|
||||
return err == nil && auth.Username != ""
|
||||
}
|
||||
|
||||
func contains(list []rtspauth.VerifyMethod, item rtspauth.VerifyMethod) bool {
|
||||
for _, i := range list {
|
||||
if i == item {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type connParent interface {
|
||||
logger.Writer
|
||||
findSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session
|
||||
@@ -150,7 +142,7 @@ func (c *conn) onDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx,
|
||||
// CustomVerifyFunc prevents hashed credentials from working.
|
||||
// Use it only when strictly needed.
|
||||
var customVerifyFunc func(expectedUser, expectedPass string) bool
|
||||
if contains(c.authMethods, rtspauth.VerifyMethodDigestMD5) {
|
||||
if slices.Contains(c.authMethods, rtspauth.VerifyMethodDigestMD5) {
|
||||
customVerifyFunc = func(expectedUser, expectedPass string) bool {
|
||||
return c.rconn.VerifyCredentials(ctx.Request, expectedUser, expectedPass)
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -150,7 +151,7 @@ func (s *session) onAnnounce(c *conn, ctx *gortsplib.ServerHandlerOnAnnounceCtx)
|
||||
// CustomVerifyFunc prevents hashed credentials from working.
|
||||
// Use it only when strictly needed.
|
||||
var customVerifyFunc func(expectedUser, expectedPass string) bool
|
||||
if contains(c.authMethods, rtspauth.VerifyMethodDigestMD5) {
|
||||
if slices.Contains(c.authMethods, rtspauth.VerifyMethodDigestMD5) {
|
||||
customVerifyFunc = func(expectedUser, expectedPass string) bool {
|
||||
return c.rconn.VerifyCredentials(ctx.Request, expectedUser, expectedPass)
|
||||
}
|
||||
@@ -216,7 +217,7 @@ func (s *session) onSetup(c *conn, ctx *gortsplib.ServerHandlerOnSetupCtx,
|
||||
// CustomVerifyFunc prevents hashed credentials from working.
|
||||
// Use it only when strictly needed.
|
||||
var customVerifyFunc func(expectedUser, expectedPass string) bool
|
||||
if contains(c.authMethods, rtspauth.VerifyMethodDigestMD5) {
|
||||
if slices.Contains(c.authMethods, rtspauth.VerifyMethodDigestMD5) {
|
||||
customVerifyFunc = func(expectedUser, expectedPass string) bool {
|
||||
return c.rconn.VerifyCredentials(ctx.Request, expectedUser, expectedPass)
|
||||
}
|
||||
|
Reference in New Issue
Block a user