mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-06 08:46:57 +08:00
Improve ONVIF server
This commit is contained in:
72
examples/onvif_client/main.go
Normal file
72
examples/onvif_client/main.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/onvif"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var rawURL = os.Args[1]
|
||||
var operation = os.Args[2]
|
||||
var token string
|
||||
if len(os.Args) > 3 {
|
||||
token = os.Args[3]
|
||||
}
|
||||
|
||||
client, err := onvif.NewClient(rawURL)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
var b []byte
|
||||
|
||||
switch operation {
|
||||
case onvif.ServiceGetServiceCapabilities:
|
||||
b, err = client.MediaRequest(operation)
|
||||
case onvif.DeviceGetCapabilities,
|
||||
onvif.DeviceGetDeviceInformation,
|
||||
onvif.DeviceGetDiscoveryMode,
|
||||
onvif.DeviceGetDNS,
|
||||
onvif.DeviceGetHostname,
|
||||
onvif.DeviceGetNetworkDefaultGateway,
|
||||
onvif.DeviceGetNetworkInterfaces,
|
||||
onvif.DeviceGetNetworkProtocols,
|
||||
onvif.DeviceGetNTP,
|
||||
onvif.DeviceGetScopes,
|
||||
onvif.DeviceGetServices,
|
||||
onvif.DeviceGetSystemDateAndTime,
|
||||
onvif.DeviceSystemReboot:
|
||||
b, err = client.DeviceRequest(operation)
|
||||
case onvif.MediaGetProfiles, onvif.MediaGetVideoSources:
|
||||
b, err = client.MediaRequest(operation)
|
||||
case onvif.MediaGetProfile:
|
||||
b, err = client.GetProfile(token)
|
||||
case onvif.MediaGetVideoSourceConfiguration:
|
||||
b, err = client.GetVideoSourceConfiguration(token)
|
||||
case onvif.MediaGetStreamUri:
|
||||
b, err = client.GetStreamUri(token)
|
||||
case onvif.MediaGetSnapshotUri:
|
||||
b, err = client.GetSnapshotUri(token)
|
||||
default:
|
||||
log.Printf("unknown action\n")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Printf("%s\n", err)
|
||||
}
|
||||
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
host, _, _ := net.SplitHostPort(u.Host)
|
||||
|
||||
if err = os.WriteFile(host+"_"+operation+".xml", b, 0644); err != nil {
|
||||
log.Printf("%s\n", err)
|
||||
}
|
||||
}
|
25
internal/onvif/README.md
Normal file
25
internal/onvif/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# ONVIF
|
||||
|
||||
A regular camera has a single video source (`GetVideoSources`) and two profiles (`GetProfiles`).
|
||||
|
||||
Go2rtc has one video source and one profile per stream.
|
||||
|
||||
## Tested clients
|
||||
|
||||
Go2rtc works as ONVIF server:
|
||||
|
||||
- Happytime onvif client (windows)
|
||||
- Home Assistant ONVIF integration (linux)
|
||||
- Onvier (android)
|
||||
- ONVIF Device Manager (windows)
|
||||
|
||||
PS. Support only TCP transport for RTSP protocol. UDP and HTTP transports - unsupported yet.
|
||||
|
||||
## Tested cameras
|
||||
|
||||
Go2rtc works as ONVIF client:
|
||||
|
||||
- Dahua IPC-K42
|
||||
- OpenIPC
|
||||
- Reolink RLC-520A
|
||||
- TP-Link Tapo TC60
|
@@ -55,55 +55,65 @@ func onvifDeviceService(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
action := onvif.GetRequestAction(b)
|
||||
if action == "" {
|
||||
operation := onvif.GetRequestAction(b)
|
||||
if operation == "" {
|
||||
http.Error(w, "malformed request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace().Msgf("[onvif] %s", action)
|
||||
log.Trace().Msgf("[onvif] server request %s %s:\n%s", r.Method, r.RequestURI, b)
|
||||
|
||||
var res string
|
||||
switch operation {
|
||||
case onvif.DeviceGetNetworkInterfaces, // important for Hass
|
||||
onvif.DeviceGetSystemDateAndTime, // important for Hass
|
||||
onvif.DeviceGetDiscoveryMode,
|
||||
onvif.DeviceGetDNS,
|
||||
onvif.DeviceGetHostname,
|
||||
onvif.DeviceGetNetworkDefaultGateway,
|
||||
onvif.DeviceGetNetworkProtocols,
|
||||
onvif.DeviceGetNTP,
|
||||
onvif.DeviceGetScopes:
|
||||
b = onvif.StaticResponse(operation)
|
||||
|
||||
switch action {
|
||||
case onvif.ActionGetCapabilities:
|
||||
case onvif.DeviceGetCapabilities:
|
||||
// important for Hass: Media section
|
||||
res = onvif.GetCapabilitiesResponse(r.Host)
|
||||
b = onvif.GetCapabilitiesResponse(r.Host)
|
||||
|
||||
case onvif.ActionGetServices:
|
||||
res = onvif.GetServicesResponse(r.Host)
|
||||
case onvif.DeviceGetServices:
|
||||
b = onvif.GetServicesResponse(r.Host)
|
||||
|
||||
case onvif.ActionGetSystemDateAndTime:
|
||||
// important for Hass
|
||||
res = onvif.GetSystemDateAndTimeResponse()
|
||||
|
||||
case onvif.ActionGetNetworkInterfaces:
|
||||
// important for Hass: none
|
||||
res = onvif.GetNetworkInterfacesResponse()
|
||||
|
||||
case onvif.ActionGetDeviceInformation:
|
||||
case onvif.DeviceGetDeviceInformation:
|
||||
// important for Hass: SerialNumber (unique server ID)
|
||||
res = onvif.GetDeviceInformationResponse("", "go2rtc", app.Version, r.Host)
|
||||
b = onvif.GetDeviceInformationResponse("", "go2rtc", app.Version, r.Host)
|
||||
|
||||
case onvif.ActionGetServiceCapabilities:
|
||||
case onvif.ServiceGetServiceCapabilities:
|
||||
// important for Hass
|
||||
res = onvif.GetServiceCapabilitiesResponse()
|
||||
// TODO: check path links to media
|
||||
b = onvif.GetMediaServiceCapabilitiesResponse()
|
||||
|
||||
case onvif.ActionSystemReboot:
|
||||
res = onvif.SystemRebootResponse()
|
||||
case onvif.DeviceSystemReboot:
|
||||
b = onvif.StaticResponse(operation)
|
||||
|
||||
time.AfterFunc(time.Second, func() {
|
||||
os.Exit(0)
|
||||
})
|
||||
|
||||
case onvif.ActionGetProfiles:
|
||||
case onvif.MediaGetVideoSources:
|
||||
b = onvif.GetVideoSourcesResponse(streams.GetAll())
|
||||
|
||||
case onvif.MediaGetProfiles:
|
||||
// important for Hass: H264 codec, width, height
|
||||
res = onvif.GetProfilesResponse(streams.GetAll())
|
||||
b = onvif.GetProfilesResponse(streams.GetAll())
|
||||
|
||||
case onvif.ActionGetVideoSources:
|
||||
res = onvif.GetVideoSourcesResponse(streams.GetAll())
|
||||
case onvif.MediaGetProfile:
|
||||
token := onvif.FindTagValue(b, "ProfileToken")
|
||||
b = onvif.GetProfileResponse(token)
|
||||
|
||||
case onvif.ActionGetStreamUri:
|
||||
case onvif.MediaGetVideoSourceConfiguration:
|
||||
token := onvif.FindTagValue(b, "ConfigurationToken")
|
||||
b = onvif.GetVideoSourceConfigurationResponse(token)
|
||||
|
||||
case onvif.MediaGetStreamUri:
|
||||
host, _, err := net.SplitHostPort(r.Host)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@@ -111,20 +121,22 @@ func onvifDeviceService(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
uri := "rtsp://" + host + ":" + rtsp.Port + "/" + onvif.FindTagValue(b, "ProfileToken")
|
||||
res = onvif.GetStreamUriResponse(uri)
|
||||
b = onvif.GetStreamUriResponse(uri)
|
||||
|
||||
case onvif.ActionGetSnapshotUri:
|
||||
case onvif.MediaGetSnapshotUri:
|
||||
uri := "http://" + r.Host + "/api/frame.jpeg?src=" + onvif.FindTagValue(b, "ProfileToken")
|
||||
res = onvif.GetSnapshotUriResponse(uri)
|
||||
b = onvif.GetSnapshotUriResponse(uri)
|
||||
|
||||
default:
|
||||
http.Error(w, "unsupported action", http.StatusBadRequest)
|
||||
http.Error(w, "unsupported operation", http.StatusBadRequest)
|
||||
log.Debug().Msgf("[onvif] unsupported request:\n%s", b)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace().Msgf("[onvif] server response:\n%s", b)
|
||||
|
||||
w.Header().Set("Content-Type", "application/soap+xml; charset=utf-8")
|
||||
if _, err = w.Write([]byte(res)); err != nil {
|
||||
if _, err = w.Write(b); err != nil {
|
||||
log.Error().Err(err).Caller().Send()
|
||||
}
|
||||
}
|
||||
@@ -170,7 +182,7 @@ func apiOnvif(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if l := log.Trace(); l.Enabled() {
|
||||
b, _ := client.GetProfiles()
|
||||
b, _ := client.MediaRequest(onvif.MediaGetProfiles)
|
||||
l.Msgf("[onvif] src=%s profiles:\n%s", src, b)
|
||||
}
|
||||
|
38
pkg/onvif/README.md
Normal file
38
pkg/onvif/README.md
Normal file
@@ -0,0 +1,38 @@
|
||||
## Profiles
|
||||
|
||||
- Profile A - For access control configuration
|
||||
- Profile C - For door control and event management
|
||||
- Profile S - For basic video streaming
|
||||
- Video streaming and configuration
|
||||
- Profile T - For advanced video streaming
|
||||
- H.264 / H.265 video compression
|
||||
- Imaging settings
|
||||
- Motion alarm and tampering events
|
||||
- Metadata streaming
|
||||
- Bi-directional audio
|
||||
|
||||
## Services
|
||||
|
||||
https://www.onvif.org/profiles/specifications/
|
||||
|
||||
- https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl
|
||||
- https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl
|
||||
- https://www.onvif.org/ver10/media/wsdl/media.wsdl
|
||||
|
||||
## TMP
|
||||
|
||||
| | Dahua | Reolink | TP-Link |
|
||||
|------------------------|---------|---------|---------|
|
||||
| GetCapabilities | no auth | no auth | no auth |
|
||||
| GetServices | no auth | no auth | no auth |
|
||||
| GetServiceCapabilities | no auth | no auth | auth |
|
||||
| GetSystemDateAndTime | no auth | no auth | no auth |
|
||||
| GetNetworkInterfaces | auth | auth | auth |
|
||||
| GetDeviceInformation | auth | auth | auth |
|
||||
| GetProfiles | auth | auth | auth |
|
||||
| GetScopes | auth | auth | auth |
|
||||
|
||||
- Dahua - onvif://192.168.10.90:80
|
||||
- Reolink - onvif://192.168.10.92:8000
|
||||
- TP-Link - onvif://192.168.10.91:2020/onvif/device_service
|
||||
-
|
@@ -2,8 +2,6 @@ package onvif
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"html"
|
||||
"io"
|
||||
@@ -12,8 +10,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
)
|
||||
|
||||
const PathDevice = "/onvif/device_service"
|
||||
@@ -41,7 +37,7 @@ func NewClient(rawURL string) (*Client, error) {
|
||||
client.deviceURL = baseURL + u.Path
|
||||
}
|
||||
|
||||
b, err := client.GetCapabilities()
|
||||
b, err := client.DeviceRequest(DeviceGetCapabilities)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -95,7 +91,7 @@ func (c *Client) GetURI() (string, error) {
|
||||
}
|
||||
|
||||
func (c *Client) GetName() (string, error) {
|
||||
b, err := c.GetDeviceInformation()
|
||||
b, err := c.DeviceRequest(DeviceGetDeviceInformation)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -104,7 +100,7 @@ func (c *Client) GetName() (string, error) {
|
||||
}
|
||||
|
||||
func (c *Client) GetProfilesTokens() ([]string, error) {
|
||||
b, err := c.GetProfiles()
|
||||
b, err := c.MediaRequest(MediaGetProfiles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,86 +123,53 @@ func (c *Client) HasSnapshots() bool {
|
||||
return strings.Contains(string(b), `SnapshotUri="true"`)
|
||||
}
|
||||
|
||||
func (c *Client) GetCapabilities() ([]byte, error) {
|
||||
func (c *Client) GetProfile(token string) ([]byte, error) {
|
||||
return c.Request(
|
||||
c.deviceURL,
|
||||
`<tds:GetCapabilities xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
|
||||
<tds:Category>All</tds:Category>
|
||||
</tds:GetCapabilities>`,
|
||||
c.mediaURL, `<trt:GetProfile><trt:ProfileToken>`+token+`</trt:ProfileToken></trt:GetProfile>`,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) GetNetworkInterfaces() ([]byte, error) {
|
||||
return c.Request(
|
||||
c.deviceURL, `<tds:GetNetworkInterfaces xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) GetDeviceInformation() ([]byte, error) {
|
||||
return c.Request(
|
||||
c.deviceURL, `<tds:GetDeviceInformation xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) GetProfiles() ([]byte, error) {
|
||||
return c.Request(
|
||||
c.mediaURL, `<trt:GetProfiles xmlns:trt="http://www.onvif.org/ver10/media/wsdl"/>`,
|
||||
)
|
||||
func (c *Client) GetVideoSourceConfiguration(token string) ([]byte, error) {
|
||||
return c.Request(c.mediaURL, `<trt:GetVideoSourceConfiguration>
|
||||
<trt:ConfigurationToken>`+token+`</trt:ConfigurationToken>
|
||||
</trt:GetVideoSourceConfiguration>`)
|
||||
}
|
||||
|
||||
func (c *Client) GetStreamUri(token string) ([]byte, error) {
|
||||
return c.Request(
|
||||
c.mediaURL,
|
||||
`<trt:GetStreamUri xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema">
|
||||
return c.Request(c.mediaURL, `<trt:GetStreamUri>
|
||||
<trt:StreamSetup>
|
||||
<tt:Stream>RTP-Unicast</tt:Stream>
|
||||
<tt:Transport><tt:Protocol>RTSP</tt:Protocol></tt:Transport>
|
||||
</trt:StreamSetup>
|
||||
<trt:ProfileToken>`+token+`</trt:ProfileToken>
|
||||
</trt:GetStreamUri>`,
|
||||
)
|
||||
</trt:GetStreamUri>`)
|
||||
}
|
||||
|
||||
func (c *Client) GetSnapshotUri(token string) ([]byte, error) {
|
||||
return c.Request(
|
||||
c.imaginURL,
|
||||
`<trt:GetSnapshotUri xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
|
||||
<trt:ProfileToken>`+token+`</trt:ProfileToken>
|
||||
</trt:GetSnapshotUri>`,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) GetSystemDateAndTime() ([]byte, error) {
|
||||
return c.Request(
|
||||
c.deviceURL, `<tds:GetSystemDateAndTime xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
|
||||
c.imaginURL, `<trt:GetSnapshotUri><trt:ProfileToken>`+token+`</trt:ProfileToken></trt:GetSnapshotUri>`,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) GetServiceCapabilities() ([]byte, error) {
|
||||
// some cameras answer GetServiceCapabilities for media only for path = "/onvif/media"
|
||||
return c.Request(
|
||||
c.mediaURL, `<trt:GetServiceCapabilities xmlns:trt="http://www.onvif.org/ver10/media/wsdl"/>`,
|
||||
c.mediaURL, `<trt:GetServiceCapabilities />`,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) SystemReboot() ([]byte, error) {
|
||||
return c.Request(
|
||||
c.deviceURL, `<tds:SystemReboot xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>`,
|
||||
)
|
||||
func (c *Client) DeviceRequest(operation string) ([]byte, error) {
|
||||
if operation == DeviceGetServices {
|
||||
operation = `<tds:GetServices><tds:IncludeCapability>true</tds:IncludeCapability></tds:GetServices>`
|
||||
} else {
|
||||
operation = `<tds:` + operation + `/>`
|
||||
}
|
||||
return c.Request(c.deviceURL, operation)
|
||||
}
|
||||
|
||||
func (c *Client) GetServices() ([]byte, error) {
|
||||
return c.Request(
|
||||
c.deviceURL, `<tds:GetServices xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
|
||||
<tds:IncludeCapability>true</tds:IncludeCapability>
|
||||
</tds:GetServices>`,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Client) GetScopes() ([]byte, error) {
|
||||
return c.Request(
|
||||
c.deviceURL, `<tds:GetScopes xmlns:tds="http://www.onvif.org/ver10/device/wsdl" />`,
|
||||
)
|
||||
func (c *Client) MediaRequest(operation string) ([]byte, error) {
|
||||
operation = `<trt:` + operation + `/>`
|
||||
return c.Request(c.mediaURL, operation)
|
||||
}
|
||||
|
||||
func (c *Client) Request(url, body string) ([]byte, error) {
|
||||
@@ -214,35 +177,11 @@ func (c *Client) Request(url, body string) ([]byte, error) {
|
||||
return nil, errors.New("onvif: unsupported service")
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf.WriteString(
|
||||
`<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">`,
|
||||
)
|
||||
|
||||
if user := c.url.User; user != nil {
|
||||
nonce := core.RandString(16, 36)
|
||||
created := time.Now().UTC().Format(time.RFC3339Nano)
|
||||
pass, _ := user.Password()
|
||||
|
||||
h := sha1.New()
|
||||
h.Write([]byte(nonce + created + pass))
|
||||
|
||||
buf.WriteString(`<s:Header>
|
||||
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
||||
<wsse:UsernameToken>
|
||||
<wsse:Username>` + user.Username() + `</wsse:Username>
|
||||
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">` + base64.StdEncoding.EncodeToString(h.Sum(nil)) + `</wsse:Password>
|
||||
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">` + base64.StdEncoding.EncodeToString([]byte(nonce)) + `</wsse:Nonce>
|
||||
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">` + created + `</wsu:Created>
|
||||
</wsse:UsernameToken>
|
||||
</wsse:Security>
|
||||
</s:Header>`)
|
||||
}
|
||||
|
||||
buf.WriteString(`<s:Body>` + body + `</s:Body></s:Envelope>`)
|
||||
e := NewEnvelopeWithUser(c.url.User)
|
||||
e.Append(body)
|
||||
|
||||
client := &http.Client{Timeout: time.Second * 5000}
|
||||
res, err := client.Post(url, `application/soap+xml;charset=utf-8`, buf)
|
||||
res, err := client.Post(url, `application/soap+xml;charset=utf-8`, bytes.NewReader(e.Bytes()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
79
pkg/onvif/envelope.go
Normal file
79
pkg/onvif/envelope.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package onvif
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
)
|
||||
|
||||
type Envelope struct {
|
||||
buf []byte
|
||||
}
|
||||
|
||||
const (
|
||||
prefix1 = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
|
||||
`
|
||||
prefix2 = `<s:Body>
|
||||
`
|
||||
suffix = `
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
)
|
||||
|
||||
func NewEnvelope() *Envelope {
|
||||
e := &Envelope{buf: make([]byte, 0, 1024)}
|
||||
e.Append(prefix1, prefix2)
|
||||
return e
|
||||
}
|
||||
|
||||
func NewEnvelopeWithUser(user *url.Userinfo) *Envelope {
|
||||
if user == nil {
|
||||
return NewEnvelope()
|
||||
}
|
||||
|
||||
nonce := core.RandString(16, 36)
|
||||
created := time.Now().UTC().Format(time.RFC3339Nano)
|
||||
pass, _ := user.Password()
|
||||
|
||||
h := sha1.New()
|
||||
h.Write([]byte(nonce + created + pass))
|
||||
|
||||
e := &Envelope{buf: make([]byte, 0, 1024)}
|
||||
e.Append(prefix1)
|
||||
e.Appendf(`<s:Header>
|
||||
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
|
||||
<wsse:UsernameToken>
|
||||
<wsse:Username>%s</wsse:Username>
|
||||
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">%s</wsse:Password>
|
||||
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">%s</wsse:Nonce>
|
||||
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">%s</wsu:Created>
|
||||
</wsse:UsernameToken>
|
||||
</wsse:Security>
|
||||
</s:Header>
|
||||
`,
|
||||
user.Username(),
|
||||
base64.StdEncoding.EncodeToString(h.Sum(nil)),
|
||||
base64.StdEncoding.EncodeToString([]byte(nonce)),
|
||||
created)
|
||||
e.Append(prefix2)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Envelope) Append(args ...string) {
|
||||
for _, s := range args {
|
||||
e.buf = append(e.buf, s...)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Envelope) Appendf(format string, args ...any) {
|
||||
e.buf = fmt.Appendf(e.buf, format, args...)
|
||||
}
|
||||
|
||||
func (e *Envelope) Bytes() []byte {
|
||||
return append(e.buf, suffix...)
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package onvif
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -106,3 +107,25 @@ func atoi(s string) int {
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func GetPosixTZ(current time.Time) string {
|
||||
// Thanks to https://github.com/Path-Variable/go-posix-time
|
||||
_, offset := current.Zone()
|
||||
|
||||
if current.IsDST() {
|
||||
_, end := current.ZoneBounds()
|
||||
endPlus1 := end.Add(time.Hour * 25)
|
||||
_, offset = endPlus1.Zone()
|
||||
}
|
||||
|
||||
var prefix string
|
||||
if offset < 0 {
|
||||
prefix = "GMT+"
|
||||
offset = -offset / 60
|
||||
} else {
|
||||
prefix = "GMT-"
|
||||
offset = offset / 60
|
||||
}
|
||||
|
||||
return prefix + fmt.Sprintf("%02d:%02d", offset/60, offset%60)
|
||||
}
|
||||
|
@@ -2,31 +2,40 @@ package onvif
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ActionGetCapabilities = "GetCapabilities"
|
||||
ActionGetSystemDateAndTime = "GetSystemDateAndTime"
|
||||
ActionGetNetworkInterfaces = "GetNetworkInterfaces"
|
||||
ActionGetDeviceInformation = "GetDeviceInformation"
|
||||
ActionGetServiceCapabilities = "GetServiceCapabilities"
|
||||
ActionGetProfiles = "GetProfiles"
|
||||
ActionGetStreamUri = "GetStreamUri"
|
||||
ActionGetSnapshotUri = "GetSnapshotUri"
|
||||
ActionSystemReboot = "SystemReboot"
|
||||
const ServiceGetServiceCapabilities = "GetServiceCapabilities"
|
||||
|
||||
ActionGetServices = "GetServices"
|
||||
ActionGetScopes = "GetScopes"
|
||||
ActionGetVideoSources = "GetVideoSources"
|
||||
ActionGetAudioSources = "GetAudioSources"
|
||||
ActionGetVideoSourceConfigurations = "GetVideoSourceConfigurations"
|
||||
ActionGetAudioSourceConfigurations = "GetAudioSourceConfigurations"
|
||||
ActionGetVideoEncoderConfigurations = "GetVideoEncoderConfigurations"
|
||||
ActionGetAudioEncoderConfigurations = "GetAudioEncoderConfigurations"
|
||||
const (
|
||||
DeviceGetCapabilities = "GetCapabilities"
|
||||
DeviceGetDeviceInformation = "GetDeviceInformation"
|
||||
DeviceGetDiscoveryMode = "GetDiscoveryMode"
|
||||
DeviceGetDNS = "GetDNS"
|
||||
DeviceGetHostname = "GetHostname"
|
||||
DeviceGetNetworkDefaultGateway = "GetNetworkDefaultGateway"
|
||||
DeviceGetNetworkInterfaces = "GetNetworkInterfaces"
|
||||
DeviceGetNetworkProtocols = "GetNetworkProtocols"
|
||||
DeviceGetNTP = "GetNTP"
|
||||
DeviceGetScopes = "GetScopes"
|
||||
DeviceGetServices = "GetServices"
|
||||
DeviceGetSystemDateAndTime = "GetSystemDateAndTime"
|
||||
DeviceSystemReboot = "SystemReboot"
|
||||
)
|
||||
|
||||
const (
|
||||
MediaGetAudioEncoderConfigurations = "GetAudioEncoderConfigurations"
|
||||
MediaGetAudioSources = "GetAudioSources"
|
||||
MediaGetAudioSourceConfigurations = "GetAudioSourceConfigurations"
|
||||
MediaGetProfile = "GetProfile"
|
||||
MediaGetProfiles = "GetProfiles"
|
||||
MediaGetSnapshotUri = "GetSnapshotUri"
|
||||
MediaGetStreamUri = "GetStreamUri"
|
||||
MediaGetVideoEncoderConfigurations = "GetVideoEncoderConfigurations"
|
||||
MediaGetVideoSources = "GetVideoSources"
|
||||
MediaGetVideoSourceConfiguration = "GetVideoSourceConfiguration"
|
||||
MediaGetVideoSourceConfigurations = "GetVideoSourceConfigurations"
|
||||
)
|
||||
|
||||
func GetRequestAction(b []byte) string {
|
||||
@@ -43,17 +52,15 @@ func GetRequestAction(b []byte) string {
|
||||
return string(m[1])
|
||||
}
|
||||
|
||||
func GetCapabilitiesResponse(host string) string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<tds:GetCapabilitiesResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
|
||||
<tds:Capabilities xmlns:tt="http://www.onvif.org/ver10/schema">
|
||||
func GetCapabilitiesResponse(host string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<tds:GetCapabilitiesResponse>
|
||||
<tds:Capabilities>
|
||||
<tt:Device>
|
||||
<tt:XAddr>http://` + host + `/onvif/device_service</tt:XAddr>
|
||||
<tt:XAddr>http://`, host, `/onvif/device_service</tt:XAddr>
|
||||
</tt:Device>
|
||||
<tt:Media>
|
||||
<tt:XAddr>http://` + host + `/onvif/media_service</tt:XAddr>
|
||||
<tt:XAddr>http://`, host, `/onvif/media_service</tt:XAddr>
|
||||
<tt:StreamingCapabilities>
|
||||
<tt:RTPMulticast>false</tt:RTPMulticast>
|
||||
<tt:RTP_TCP>false</tt:RTP_TCP>
|
||||
@@ -61,218 +68,183 @@ func GetCapabilitiesResponse(host string) string {
|
||||
</tt:StreamingCapabilities>
|
||||
</tt:Media>
|
||||
</tds:Capabilities>
|
||||
</tds:GetCapabilitiesResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
</tds:GetCapabilitiesResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func GetServicesResponse(host string) string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<tds:GetServicesResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
|
||||
func GetServicesResponse(host string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<tds:GetServicesResponse>
|
||||
<tds:Service>
|
||||
<tds:Namespace>http://www.onvif.org/ver10/device/wsdl</tds:Namespace>
|
||||
<tds:XAddr>http://` + host + `/onvif/device_service</tds:XAddr>
|
||||
<tds:Version>
|
||||
<tds:Major>2</tds:Major>
|
||||
<tds:Minor>5</tds:Minor>
|
||||
</tds:Version>
|
||||
<tds:XAddr>http://`, host, `/onvif/device_service</tds:XAddr>
|
||||
<tds:Version><tt:Major>2</tt:Major><tt:Minor>5</tt:Minor></tds:Version>
|
||||
</tds:Service>
|
||||
<tds:Service>
|
||||
<tds:Namespace>http://www.onvif.org/ver10/media/wsdl</tds:Namespace>
|
||||
<tds:XAddr>http://` + host + `/onvif/media_service</tds:XAddr>
|
||||
<tds:Version>
|
||||
<tds:Major>2</tds:Major>
|
||||
<tds:Minor>5</tds:Minor>
|
||||
</tds:Version>
|
||||
<tds:XAddr>http://`, host, `/onvif/media_service</tds:XAddr>
|
||||
<tds:Version><tt:Major>2</tt:Major><tt:Minor>5</tt:Minor></tds:Version>
|
||||
</tds:Service>
|
||||
</tds:GetServicesResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
</tds:GetServicesResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func GetSystemDateAndTimeResponse() string {
|
||||
func GetSystemDateAndTimeResponse() []byte {
|
||||
loc := time.Now()
|
||||
utc := loc.UTC()
|
||||
|
||||
return fmt.Sprintf(`<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<tds:GetSystemDateAndTimeResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
|
||||
<tds:SystemDateAndTime xmlns:tt="http://www.onvif.org/ver10/schema">
|
||||
e := NewEnvelope()
|
||||
e.Appendf(`<tds:GetSystemDateAndTimeResponse>
|
||||
<tds:SystemDateAndTime>
|
||||
<tt:DateTimeType>NTP</tt:DateTimeType>
|
||||
<tt:DaylightSavings>false</tt:DaylightSavings>
|
||||
<tt:DaylightSavings>true</tt:DaylightSavings>
|
||||
<tt:TimeZone>
|
||||
<tt:TZ>GMT%s</tt:TZ>
|
||||
<tt:TZ>%s</tt:TZ>
|
||||
</tt:TimeZone>
|
||||
<tt:UTCDateTime>
|
||||
<tt:Time>
|
||||
<tt:Hour>%d</tt:Hour>
|
||||
<tt:Minute>%d</tt:Minute>
|
||||
<tt:Second>%d</tt:Second>
|
||||
</tt:Time>
|
||||
<tt:Date>
|
||||
<tt:Year>%d</tt:Year>
|
||||
<tt:Month>%d</tt:Month>
|
||||
<tt:Day>%d</tt:Day>
|
||||
</tt:Date>
|
||||
<tt:Time><tt:Hour>%d</tt:Hour><tt:Minute>%d</tt:Minute><tt:Second>%d</tt:Second></tt:Time>
|
||||
<tt:Date><tt:Year>%d</tt:Year><tt:Month>%d</tt:Month><tt:Day>%d</tt:Day></tt:Date>
|
||||
</tt:UTCDateTime>
|
||||
<tt:LocalDateTime>
|
||||
<tt:Time>
|
||||
<tt:Hour>%d</tt:Hour>
|
||||
<tt:Minute>%d</tt:Minute>
|
||||
<tt:Second>%d</tt:Second>
|
||||
</tt:Time>
|
||||
<tt:Date>
|
||||
<tt:Year>%d</tt:Year>
|
||||
<tt:Month>%d</tt:Month>
|
||||
<tt:Day>%d</tt:Day>
|
||||
</tt:Date>
|
||||
<tt:Time><tt:Hour>%d</tt:Hour><tt:Minute>%d</tt:Minute><tt:Second>%d</tt:Second></tt:Time>
|
||||
<tt:Date><tt:Year>%d</tt:Year><tt:Month>%d</tt:Month><tt:Day>%d</tt:Day></tt:Date>
|
||||
</tt:LocalDateTime>
|
||||
</tds:SystemDateAndTime>
|
||||
</tds:GetSystemDateAndTimeResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`,
|
||||
loc.Format("-07:00"),
|
||||
</tds:GetSystemDateAndTimeResponse>`,
|
||||
GetPosixTZ(loc),
|
||||
utc.Hour(), utc.Minute(), utc.Second(), utc.Year(), utc.Month(), utc.Day(),
|
||||
loc.Hour(), loc.Minute(), loc.Second(), loc.Year(), loc.Month(), loc.Day(),
|
||||
)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func GetNetworkInterfacesResponse() string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<tds:GetNetworkInterfacesResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl"/>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
}
|
||||
|
||||
func GetDeviceInformationResponse(manuf, model, firmware, serial string) string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<tds:GetDeviceInformationResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
|
||||
<tds:Manufacturer>` + manuf + `</tds:Manufacturer>
|
||||
<tds:Model>` + model + `</tds:Model>
|
||||
<tds:FirmwareVersion>` + firmware + `</tds:FirmwareVersion>
|
||||
<tds:SerialNumber>` + serial + `</tds:SerialNumber>
|
||||
func GetDeviceInformationResponse(manuf, model, firmware, serial string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<tds:GetDeviceInformationResponse>
|
||||
<tds:Manufacturer>`, manuf, `</tds:Manufacturer>
|
||||
<tds:Model>`, model, `</tds:Model>
|
||||
<tds:FirmwareVersion>`, firmware, `</tds:FirmwareVersion>
|
||||
<tds:SerialNumber>`, serial, `</tds:SerialNumber>
|
||||
<tds:HardwareId>1.00</tds:HardwareId>
|
||||
</tds:GetDeviceInformationResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
</tds:GetDeviceInformationResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func GetServiceCapabilitiesResponse() string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<trt:GetServiceCapabilitiesResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
|
||||
func GetMediaServiceCapabilitiesResponse() []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<trt:GetServiceCapabilitiesResponse>
|
||||
<trt:Capabilities SnapshotUri="true" Rotation="false" VideoSourceMode="false" OSD="false" TemporaryOSDText="false" EXICompression="false">
|
||||
<trt:StreamingCapabilities RTPMulticast="false" RTP_TCP="false" RTP_RTSP_TCP="true" NonAggregateControl="false" NoRTSPStreaming="false" />
|
||||
</trt:Capabilities>
|
||||
</trt:GetServiceCapabilitiesResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
</trt:GetServiceCapabilitiesResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func SystemRebootResponse() string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<tds:SystemRebootResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
|
||||
<tds:Message>system reboot in 1 second...</tds:Message>
|
||||
</tds:SystemRebootResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
func GetProfilesResponse(names []string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<trt:GetProfilesResponse>
|
||||
`)
|
||||
for _, name := range names {
|
||||
appendProfile(e, "Profiles", name)
|
||||
}
|
||||
e.Append(`</trt:GetProfilesResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func GetProfilesResponse(names []string) string {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf.WriteString(`<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<trt:GetProfilesResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tt="http://www.onvif.org/ver10/schema">`)
|
||||
|
||||
for i, name := range names {
|
||||
buf.WriteString(`
|
||||
<trt:Profiles token="` + name + `" fixed="true">
|
||||
<trt:Name>` + name + `</trt:Name>
|
||||
<trt:VideoEncoderConfiguration token="` + strconv.Itoa(i) + `">
|
||||
<trt:Name>` + name + `</trt:Name>
|
||||
<trt:Encoding>H264</trt:Encoding>
|
||||
<trt:Resolution>
|
||||
<trt:Width>1920</trt:Width>
|
||||
<trt:Height>1080</trt:Height>
|
||||
</trt:Resolution>
|
||||
<trt:RateControl>
|
||||
</trt:RateControl>
|
||||
</trt:VideoEncoderConfiguration>
|
||||
<trt:VideoSourceConfiguration token="` + strconv.Itoa(i) + `">
|
||||
<trt:Name>` + name + `</trt:Name>
|
||||
<trt:SourceToken>` + strconv.Itoa(i) + `</trt:SourceToken>
|
||||
<trt:Bounds x="0" y="0" width="1920" height="1080"></trt:Bounds>
|
||||
</trt:VideoSourceConfiguration>
|
||||
</trt:Profiles>`)
|
||||
func GetProfileResponse(name string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<trt:GetProfileResponse>
|
||||
`)
|
||||
appendProfile(e, "Profile", name)
|
||||
e.Append(`</trt:GetProfileResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
buf.WriteString(`
|
||||
</trt:GetProfilesResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`)
|
||||
|
||||
return buf.String()
|
||||
func appendProfile(e *Envelope, tag, name string) {
|
||||
e.Append(`<trt:`, tag, ` token="`, name, `" fixed="true">
|
||||
<tt:Name>`, name, `</tt:Name>
|
||||
<tt:VideoSourceConfiguration token="`, name, `">
|
||||
<tt:Name>VSC</tt:Name>
|
||||
<tt:SourceToken>`, name, `</tt:SourceToken>
|
||||
<tt:Bounds x="0" y="0" width="1920" height="1080"></tt:Bounds>
|
||||
</tt:VideoSourceConfiguration>
|
||||
<tt:VideoEncoderConfiguration token="vec">
|
||||
<tt:Name>VEC</tt:Name>
|
||||
<tt:Encoding>H264</tt:Encoding>
|
||||
<tt:Resolution><tt:Width>1920</tt:Width><tt:Height>1080</tt:Height></tt:Resolution>
|
||||
</tt:VideoEncoderConfiguration>
|
||||
</trt:`, tag, `>
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
func GetVideoSourcesResponse(names []string) string {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf.WriteString(`<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<trt:GetVideoSourcesResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl">`)
|
||||
|
||||
for i, _ := range names {
|
||||
buf.WriteString(`
|
||||
<trt:VideoSources token="` + strconv.Itoa(i) + `">
|
||||
<trt:Resolution>
|
||||
<trt:Width>1920</trt:Width>
|
||||
<trt:Height>1080</trt:Height>
|
||||
</trt:Resolution>
|
||||
</trt:VideoSources>`)
|
||||
func GetVideoSourceConfigurationResponse(name string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<trt:GetVideoSourceConfigurationResponse>
|
||||
<trt:Configuration token="`, name, `">
|
||||
<tt:Name>VSC</tt:Name>
|
||||
<tt:SourceToken>`, name, `</tt:SourceToken>
|
||||
<tt:Bounds x="0" y="0" width="1920" height="1080"></tt:Bounds>
|
||||
</trt:Configuration>
|
||||
</trt:GetVideoSourceConfigurationResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
buf.WriteString(`
|
||||
</trt:GetVideoSourcesResponse >
|
||||
</s:Body>
|
||||
</s:Envelope>`)
|
||||
|
||||
return buf.String()
|
||||
func GetVideoSourcesResponse(names []string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<trt:GetVideoSourcesResponse>
|
||||
`)
|
||||
for _, name := range names {
|
||||
e.Append(`<trt:VideoSources token="`, name, `">
|
||||
<tt:Framerate>30.000000</tt:Framerate>
|
||||
<tt:Resolution><tt:Width>1920</tt:Width><tt:Height>1080</tt:Height></tt:Resolution>
|
||||
</trt:VideoSources>
|
||||
`)
|
||||
}
|
||||
e.Append(`</trt:GetVideoSourcesResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func GetStreamUriResponse(uri string) string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<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>
|
||||
<trt:Uri>` + uri + `</trt:Uri>
|
||||
</trt:MediaUri>
|
||||
</trt:GetStreamUriResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
func GetStreamUriResponse(uri string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<trt:GetStreamUriResponse><trt:MediaUri><tt:Uri>`, uri, `</tt:Uri></trt:MediaUri></trt:GetStreamUriResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func GetSnapshotUriResponse(uri string) string {
|
||||
return `<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
|
||||
<s:Body>
|
||||
<trt:GetSnapshotUriResponse xmlns:trt="http://www.onvif.org/ver10/media/wsdl">
|
||||
<trt:MediaUri>
|
||||
<trt:Uri>` + uri + `</trt:Uri>
|
||||
</trt:MediaUri>
|
||||
</trt:GetSnapshotUriResponse>
|
||||
</s:Body>
|
||||
</s:Envelope>`
|
||||
func GetSnapshotUriResponse(uri string) []byte {
|
||||
e := NewEnvelope()
|
||||
e.Append(`<trt:GetSnapshotUriResponse><trt:MediaUri><tt:Uri>`, uri, `</tt:Uri></trt:MediaUri></trt:GetSnapshotUriResponse>`)
|
||||
return e.Bytes()
|
||||
}
|
||||
|
||||
func StaticResponse(operation string) []byte {
|
||||
switch operation {
|
||||
case DeviceGetSystemDateAndTime:
|
||||
return GetSystemDateAndTimeResponse()
|
||||
}
|
||||
|
||||
e := NewEnvelope()
|
||||
e.Append(responses[operation])
|
||||
b := e.Bytes()
|
||||
if operation == DeviceGetNetworkInterfaces {
|
||||
println()
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
var responses = map[string]string{
|
||||
DeviceGetDiscoveryMode: `<tds:GetDiscoveryModeResponse><tds:DiscoveryMode>Discoverable</tds:DiscoveryMode></tds:GetDiscoveryModeResponse>`,
|
||||
DeviceGetDNS: `<tds:GetDNSResponse><tds:DNSInformation /></tds:GetDNSResponse>`,
|
||||
DeviceGetHostname: `<tds:GetHostnameResponse><tds:HostnameInformation /></tds:GetHostnameResponse>`,
|
||||
DeviceGetNetworkDefaultGateway: `<tds:GetNetworkDefaultGatewayResponse><tds:NetworkGateway /></tds:GetNetworkDefaultGatewayResponse>`,
|
||||
DeviceGetNTP: `<tds:GetNTPResponse><tds:NTPInformation /></tds:GetNTPResponse>`,
|
||||
DeviceSystemReboot: `<tds:SystemRebootResponse><tds:Message>OK</tds:Message></tds:SystemRebootResponse>`,
|
||||
|
||||
DeviceGetNetworkInterfaces: `<tds:GetNetworkInterfacesResponse />`,
|
||||
DeviceGetNetworkProtocols: `<tds:GetNetworkProtocolsResponse />`,
|
||||
DeviceGetScopes: `<tds:GetScopesResponse>
|
||||
<tds:Scopes><tt:ScopeDef>Fixed</tt:ScopeDef><tt:ScopeItem>onvif://www.onvif.org/name/go2rtc</tt:ScopeItem></tds:Scopes>
|
||||
<tds:Scopes><tt:ScopeDef>Fixed</tt:ScopeDef><tt:ScopeItem>onvif://www.onvif.org/location/github</tt:ScopeItem></tds:Scopes>
|
||||
<tds:Scopes><tt:ScopeDef>Fixed</tt:ScopeDef><tt:ScopeItem>onvif://www.onvif.org/Profile/Streaming</tt:ScopeItem></tds:Scopes>
|
||||
<tds:Scopes><tt:ScopeDef>Fixed</tt:ScopeDef><tt:ScopeItem>onvif://www.onvif.org/type/Network_Video_Transmitter</tt:ScopeItem></tds:Scopes>
|
||||
</tds:GetScopesResponse>`,
|
||||
}
|
||||
|
Reference in New Issue
Block a user