forked from use-go/onvif
/
ws-discovery.go
84 lines (64 loc) · 2.24 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
80
81
82
83
84
package wsdiscovery
import (
"strings"
"github.com/beevik/etree"
"github.com/WalleCYR/onvif/gosoap"
)
func buildProbeMessage(uuidV4 string, scopes, types []string, nmsp map[string]string) gosoap.SoapMessage {
//Список namespace
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"
probeMessage := gosoap.NewEmptySOAP()
probeMessage.AddRootNamespaces(namespaces)
//if len(nmsp) != 0 {
// probeMessage.AddRootNamespaces(nmsp)
//}
//fmt.Println(probeMessage.String())
//Содержимое Head
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)
replyTo := etree.NewElement("a:ReplyTo")
replyTo.CreateElement("a:Address").SetText("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous")
to := etree.NewElement("a:To")
to.SetText("urn:schemas-xmlsoap-org:ws:2005:04:discovery")
to.CreateAttr("mustUnderstand", "1")
headerContent = append(headerContent, action, msgID, replyTo, to)
probeMessage.AddHeaderContents(headerContent)
//Содержимое Body
probe := etree.NewElement("Probe")
probe.CreateAttr("xmlns", "http://schemas.xmlsoap.org/ws/2005/04/discovery")
if len(types) != 0 {
typesTag := etree.NewElement("d:Types")
if len(nmsp) != 0 {
for key, value := range nmsp {
typesTag.CreateAttr("xmlns:"+key, value)
}
}
typesTag.CreateAttr("xmlns:d", "http://schemas.xmlsoap.org/ws/2005/04/discovery")
//typesTag.CreateAttr("xmlns:dp0", "http://www.onvif.org/ver10/network/wsdl")
var typesString string
for _, j := range types {
typesString += j
typesString += " "
}
typesTag.SetText(strings.TrimSpace(typesString))
probe.AddChild(typesTag)
}
if len(scopes) != 0 {
scopesTag := etree.NewElement("d:Scopes")
var scopesString string
for _, j := range scopes {
scopesString += j
scopesString += " "
}
scopesTag.SetText(strings.TrimSpace(scopesString))
probe.AddChild(scopesTag)
}
probeMessage.AddBodyContent(probe)
return probeMessage
}