Skip to content

Commit

Permalink
Fix ONVIF XML tag parsing in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Jan 3, 2025
1 parent bc9194d commit 4035e91
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/onvif/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
28 changes: 28 additions & 0 deletions pkg/onvif/onvif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4035e91

Please sign in to comment.