Fix ONVIF XML tag parsing in some cases

This commit is contained in:
Alex X
2025-01-03 15:08:38 +03:00
parent bc9194d740
commit 4035e91672
2 changed files with 29 additions and 1 deletions

View File

@@ -12,7 +12,7 @@ import (
)
func FindTagValue(b []byte, tag string) string {
re := regexp.MustCompile(`(?s)[:<]` + tag + `>([^<]+)`)
re := regexp.MustCompile(`(?s)<(?:\w+:)?` + tag + `\b[^>]*>([^<]+)`)
m := re.FindSubmatch(b)
if len(m) != 2 {
return ""

View File

@@ -84,6 +84,34 @@ func TestGetStreamUri(t *testing.T) {
</SOAP-ENV:Envelope>`,
url: "rtsp://192.168.5.53:8090/profile1=r",
},
{
name: "go2rtc 1.9.4",
xml: `<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body>
<trt:GetStreamUriResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
<trt:MediaUri>
<tt:Uri xmlns:tt="http://www.onvif.org/ver10/schema">rtsp://192.168.1.123:8554/rtsp-dahua1</tt:Uri>
</trt:MediaUri>
</trt:GetStreamUriResponse>
</s:Body>
</s:Envelope>`,
url: "rtsp://192.168.1.123:8554/rtsp-dahua1",
},
{
name: "go2rtc 1.9.8",
xml: `<?xml version="1.0" encoding="utf-8" standalone="no"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema">
<s:Body>
<trt:GetStreamUriResponse>
<trt:MediaUri>
<tt:Uri>rtsp://192.168.1.123:8554/rtsp-dahua2</tt:Uri>
</trt:MediaUri>
</trt:GetStreamUriResponse>
</s:Body>
</s:Envelope>
`,
url: "rtsp://192.168.1.123:8554/rtsp-dahua2",
},
}
for _, test := range tests {