forked from use-go/onvif
/
ws-discovery.go
79 lines (65 loc) · 2.44 KB
/
ws-discovery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package wsdiscovery
import (
"strings"
"github.com/beevik/etree"
"github.com/kerberos-io/onvif/gosoap"
)
// BuildProbeMessage generates a SOAP ws-discovery Probe message
//
// Example Message:
//
// <?xml version="1.0" encoding="UTF-8"?>
// <soap-env:Envelope xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope"
// xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"
// xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery"
// xmlns:dn="http://www.onvif.org/ver10/network/wsdl"
// xmlns:soap-enc="http://www.w3.org/2003/05/soap-encoding">
// <soap-env:Header>
// <a:Action mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</a:Action>
// <a:MessageID>uuid:a277f13a-ecae-4492-9d6a-218982122d1c</a:MessageID>
// <a:To mustUnderstand="1">urn:schemas-xmlsoap-org:ws:2005:04:discovery</a:To>
// </soap-env:Header>
// <soap-env:Body>
// <d:Probe>
// <d:Types>dn:NetworkVideoTransmitter</d:Types>
// </d:Probe>
// </soap-env:Body>
// </soap-env:Envelope>
func BuildProbeMessage(uuidV4 string, scopes, types []string, nmsp map[string]string) gosoap.SoapMessage {
// Namespace List
namespaces := make(map[string]string)
namespaces["a"] = "http://schemas.xmlsoap.org/ws/2004/08/addressing"
namespaces["d"] = "http://schemas.xmlsoap.org/ws/2005/04/discovery"
namespaces["dn"] = "http://www.onvif.org/ver10/network/wsdl"
probeMessage := gosoap.NewEmptySOAP()
probeMessage.AddRootNamespaces(namespaces)
if len(nmsp) != 0 {
probeMessage.AddRootNamespaces(nmsp)
}
// Probe Header
var headerContent []*etree.Element
action := etree.NewElement("a:Action")
action.SetText("http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe")
action.CreateAttr("mustUnderstand", "1")
msgID := etree.NewElement("a:MessageID")
msgID.SetText("uuid:" + uuidV4)
to := etree.NewElement("a:To")
to.SetText("urn:schemas-xmlsoap-org:ws:2005:04:discovery")
to.CreateAttr("mustUnderstand", "1")
headerContent = append(headerContent, action, msgID, to)
probeMessage.AddHeaderContents(headerContent)
// Probe Body
probe := etree.NewElement("d:Probe")
if len(types) != 0 {
typesTag := etree.NewElement("d:Types")
typesTag.SetText(strings.Join(types, " "))
probe.AddChild(typesTag)
}
if len(scopes) != 0 {
scopesTag := etree.NewElement("d:Scopes")
scopesTag.SetText(strings.Join(scopes, " "))
probe.AddChild(scopesTag)
}
probeMessage.AddBodyContent(probe)
return probeMessage
}