diff --git a/conf/conf.go b/conf/conf.go index 7b11bb95..6fedc2b6 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -326,9 +326,15 @@ func Load(fpath string) (*Conf, error) { return nil, fmt.Errorf("publish password must be alphanumeric") } } - pconf.PublishIpsParsed, err = parseIpCidrList(pconf.PublishIps) - if err != nil { - return nil, err + + if len(pconf.PublishIps) > 0 { + pconf.PublishIpsParsed, err = parseIpCidrList(pconf.PublishIps) + if err != nil { + return nil, err + } + } else { + // yaml doesn't use nil dicts - avoid test fails by using nil + pconf.PublishIps = nil } if pconf.ReadUser != "" && pconf.ReadPass == "" || pconf.ReadUser == "" && pconf.ReadPass != "" { @@ -347,9 +353,15 @@ func Load(fpath string) (*Conf, error) { if pconf.ReadUser != "" && pconf.ReadPass == "" || pconf.ReadUser == "" && pconf.ReadPass != "" { return nil, fmt.Errorf("read username and password must be both filled") } - pconf.ReadIpsParsed, err = parseIpCidrList(pconf.ReadIps) - if err != nil { - return nil, err + + if len(pconf.ReadIps) > 0 { + pconf.ReadIpsParsed, err = parseIpCidrList(pconf.ReadIps) + if err != nil { + return nil, err + } + } else { + // yaml doesn't use nil dicts - avoid test fails by using nil + pconf.ReadIps = nil } if pconf.Regexp != nil && pconf.RunOnInit != "" { diff --git a/main_test.go b/main_test.go index fca27cee..3d32905c 100644 --- a/main_test.go +++ b/main_test.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "os/exec" + "regexp" "strconv" "testing" "time" @@ -143,11 +144,19 @@ func TestEnvironment(t *testing.T) { os.Setenv("RTSP_PATHS_TEST2", "") defer os.Unsetenv("RTSP_PATHS_TEST2") - // map value - os.Setenv("RTSP_PATHS_TEST_SOURCE", "rtsp://testing") - defer os.Unsetenv("RTSP_PATHS_TEST_SOURCE") - os.Setenv("RTSP_PATHS_TEST_SOURCEPROTOCOL", "tcp") - defer os.Unsetenv("RTSP_PATHS_TEST_SOURCEPROTOCOL") + // map values, "all" path + os.Setenv("RTSP_PATHS_ALL_READUSER", "testuser") + defer os.Unsetenv("RTSP_PATHS_ALL_READUSER") + os.Setenv("RTSP_PATHS_ALL_READPASS", "testpass") + defer os.Unsetenv("RTSP_PATHS_ALL_READPASS") + + // map values, generic path + os.Setenv("RTSP_PATHS_CAM1_SOURCE", "rtsp://testing") + defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCE") + os.Setenv("RTSP_PATHS_CAM1_SOURCEPROTOCOL", "tcp") + defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCEPROTOCOL") + os.Setenv("RTSP_PATHS_CAM1_SOURCEONDEMAND", "yes") + defer os.Unsetenv("RTSP_PATHS_CAM1_SOURCEONDEMAND") p, err := testProgram("") require.NoError(t, err) @@ -169,7 +178,17 @@ func TestEnvironment(t *testing.T) { Source: "record", }, pa) - pa, ok = p.conf.Paths["test"] + pa, ok = p.conf.Paths["~^.*$"] + require.Equal(t, true, ok) + require.Equal(t, &conf.PathConf{ + Regexp: regexp.MustCompile("^.*$"), + Source: "record", + SourceProtocol: "udp", + ReadUser: "testuser", + ReadPass: "testpass", + }, pa) + + pa, ok = p.conf.Paths["cam1"] require.Equal(t, true, ok) require.Equal(t, &conf.PathConf{ Source: "rtsp://testing", @@ -179,6 +198,7 @@ func TestEnvironment(t *testing.T) { }(), SourceProtocol: "tcp", SourceProtocolParsed: gortsplib.StreamProtocolTCP, + SourceOnDemand: true, }, pa) }