Skip to content

Commit 4035e91

Browse files
committed
Fix ONVIF XML tag parsing in some cases
1 parent bc9194d commit 4035e91

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pkg/onvif/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

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

pkg/onvif/onvif_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,34 @@ func TestGetStreamUri(t *testing.T) {
8484
</SOAP-ENV:Envelope>`,
8585
url: "rtsp://192.168.5.53:8090/profile1=r",
8686
},
87+
{
88+
name: "go2rtc 1.9.4",
89+
xml: `<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
90+
<s:Body>
91+
<trt:GetStreamUriResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
92+
<trt:MediaUri>
93+
<tt:Uri xmlns:tt="http://www.onvif.org/ver10/schema">rtsp://192.168.1.123:8554/rtsp-dahua1</tt:Uri>
94+
</trt:MediaUri>
95+
</trt:GetStreamUriResponse>
96+
</s:Body>
97+
</s:Envelope>`,
98+
url: "rtsp://192.168.1.123:8554/rtsp-dahua1",
99+
},
100+
{
101+
name: "go2rtc 1.9.8",
102+
xml: `<?xml version="1.0" encoding="utf-8" standalone="no"?>
103+
<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">
104+
<s:Body>
105+
<trt:GetStreamUriResponse>
106+
<trt:MediaUri>
107+
<tt:Uri>rtsp://192.168.1.123:8554/rtsp-dahua2</tt:Uri>
108+
</trt:MediaUri>
109+
</trt:GetStreamUriResponse>
110+
</s:Body>
111+
</s:Envelope>
112+
`,
113+
url: "rtsp://192.168.1.123:8554/rtsp-dahua2",
114+
},
87115
}
88116

89117
for _, test := range tests {

0 commit comments

Comments
 (0)