mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-13 18:24:58 +00:00
54 lines
923 B
Go
54 lines
923 B
Go
package conf
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"regexp"
|
|
)
|
|
|
|
var rePathName = regexp.MustCompile("^[0-9a-zA-Z_\\-/]+$")
|
|
|
|
func CheckPathName(name string) error {
|
|
if name == "" {
|
|
return fmt.Errorf("cannot be empty")
|
|
}
|
|
|
|
if name[0] == '/' {
|
|
return fmt.Errorf("can't begin with a slash")
|
|
}
|
|
|
|
if name[len(name)-1] == '/' {
|
|
return fmt.Errorf("can't end with a slash")
|
|
}
|
|
|
|
if !rePathName.MatchString(name) {
|
|
return fmt.Errorf("can contain only alfanumeric characters, underscore, minus or slash")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func parseIpCidrList(in []string) ([]interface{}, error) {
|
|
if len(in) == 0 {
|
|
return nil, nil
|
|
}
|
|
|
|
var ret []interface{}
|
|
for _, t := range in {
|
|
_, ipnet, err := net.ParseCIDR(t)
|
|
if err == nil {
|
|
ret = append(ret, ipnet)
|
|
continue
|
|
}
|
|
|
|
ip := net.ParseIP(t)
|
|
if ip != nil {
|
|
ret = append(ret, ip)
|
|
continue
|
|
}
|
|
|
|
return nil, fmt.Errorf("unable to parse ip/network '%s'", t)
|
|
}
|
|
return ret, nil
|
|
}
|