This merge is VERY necessary
This commit is contained in:
yakovlevdmv
2018-04-04 02:06:54 +03:00
6 changed files with 54 additions and 12 deletions

View File

@@ -12,6 +12,13 @@ import (
"crypto/sha1"
"github.com/elgs/gostrgen"
"github.com/yakovlevdmv/gosoap"
"reflect"
"strings"
"github.com/yakovlevdmv/goonvif/Device"
"github.com/yakovlevdmv/goonvif/Imaging"
"github.com/yakovlevdmv/goonvif/Media"
"github.com/yakovlevdmv/goonvif/PTZ"
"errors"
)
type DeviceInfo struct {
@@ -45,7 +52,7 @@ func (dev *device) AddAuthentification(username, password string) {
dev.password = password
}
func buildMethodSOAP(msg string) (gosoap.SoapMessage, error) {
func buildMethodSOAP(msg, space string) (gosoap.SoapMessage, error) {
doc := etree.NewDocument()
if err := doc.ReadFromString(msg); err != nil {
log.Println("Got error")
@@ -56,11 +63,30 @@ func buildMethodSOAP(msg string) (gosoap.SoapMessage, error) {
soap := gosoap.NewEmptySOAP()
soap.AddBodyContent(element)
soap.AddRootNamespace("wsdl", "http://www.onvif.org/ver10/device/wsdl")
soap.AddRootNamespace("onvif", "http://www.onvif.org/ver10/device/wsdl")
soap.AddRootNamespace("wsdl", space)
return soap, nil
}
func setXMLNamespaces(strct interface{}) (string, error) {
pkgName := reflect.TypeOf( strct ).PkgPath()
pkgSplit := strings.Split(pkgName, "/")
pkgName = pkgSplit[len(pkgSplit)-1]
switch pkgName {
case "Device":
return Device.WSDL, nil
case "Imaging":
return Imaging.WSDL, nil
case "Media":
return Media.WSDL, nil
case "PTZ":
return PTZ.WSDL, nil
default:
return "", errors.New("Can't find Service")
}
}
//TODO: Get endpoint automatically
func (dev device) CallMethod(endpoint string, method interface{}) {
@@ -72,10 +98,18 @@ func (dev device) CallMethod(endpoint string, method interface{}) {
}
fmt.Println(string(output))
soap, err := buildMethodSOAP(string(output))
wsdlSpaces, err := setXMLNamespaces(method)
if err != nil {
fmt.Println(err)
}
soap, err := buildMethodSOAP(string(output), wsdlSpaces)
if err != nil {
log.Fatal(err)
}
fmt.Println("Send soap\n")
fmt.Println(soap.String())
@@ -134,18 +168,16 @@ func (dev device) CallAuthorizedMethod(endpoint string, method interface{}) {
log.Println("Marshalled struct: ", string(output))
}
soap, err := buildMethodSOAP(string(output))
wsdlSpaces, err := setXMLNamespaces(method)
if err != nil {
fmt.Println(err)
}
soap, err := buildMethodSOAP(string(output), wsdlSpaces)
if err != nil {
log.Fatal(err)
}
/**soap := gosoap.NewEmptySOAP()
soap.AddStringBodyContent(
//`<tds:SetHostname xmlns:tds="http://www.onvif.org/ver10/device/wsdl"><tds:Name>Test</tds:Name></tds:SetHostname>`,
`<tds:GetHostname xmlns:tds="http://www.onvif.org/ver10/device/wsdl" />`,
)*/
/** Generating Nonce sequence **/
charsToGenerate := 16
charSet := gostrgen.Lower | gostrgen.Digit

View File

@@ -5,6 +5,8 @@ import (
"github.com/yakovlevdmv/goonvif/xsd/onvif"
)
const WSDL = "http://www.onvif.org/ver10/device/wsdl"
type Service struct {
Namespace xsd.AnyURI
XAddr xsd.AnyURI

View File

@@ -5,6 +5,8 @@ import (
"github.com/yakovlevdmv/goonvif/xsd"
)
const WSDL = "http://www.onvif.org/ver20/imaging/wsdl"
type GetServiceCapabilities struct {
XMLName string `xml:"wsdl:GetServiceCapabilities"`
}

View File

@@ -5,6 +5,8 @@ import (
"github.com/yakovlevdmv/goonvif/xsd"
)
const WSDL = "http://www.onvif.org/ver10/media/wsdl"
type Capabilities struct {
SnapshotUri bool `xml:"SnapshotUri,attr"`
Rotation bool `xml:"Rotation,attr"`

View File

@@ -11,6 +11,8 @@ type Capabilities struct {
StatusPosition xsd.Boolean `xml:"StatusPosition,attr"`
}
const WSDL = "http://www.onvif.org/ver20/ptz/wsdl"
//PTZ main types

View File

@@ -4,6 +4,8 @@ import (
"github.com/yakovlevdmv/goonvif/xsd"
)
const ONVIF = "http://www.onvif.org/ver10/schema"
//TODO: rename package xsdTypes
//TODO: enumerations
//TODO: type <typeName> struct {Any string} convert to type <typeName> AnyType
@@ -1924,7 +1926,7 @@ type NetworkZeroConfigurationExtension2 xsd.AnyType
type IPAddressFilter struct {
Type IPAddressFilterType `xml:"onvif:Type"`
Type string `xml:"onvif:Type"`
IPv4Address PrefixedIPv4Address `xml:"onvif:IPv4Address,omitempty"`
IPv6Address PrefixedIPv6Address `xml:"onvif:IPv6Address,omitempty"`
Extension IPAddressFilterExtension `xml:"onvif:Extension,omitempty"`