Replace xml lib
This commit is contained in:
parent
21548f76b6
commit
afe338f3d8
|
@ -0,0 +1,28 @@
|
|||
package goonvif
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.pyer.club/kingecg/goonvif/onvif/media"
|
||||
"git.pyer.club/kingecg/goxml"
|
||||
)
|
||||
|
||||
func TestDecodeGetProfile(t *testing.T) {
|
||||
type Envelope struct {
|
||||
Header struct{}
|
||||
Body struct {
|
||||
GetProfilesResponse media.GetProfilesResponse
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile("result.xml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e := Envelope{}
|
||||
de := goxml.Unmarshal(data, &e)
|
||||
if de != nil {
|
||||
t.Fatal(de)
|
||||
}
|
||||
t.Log(e.Body.GetProfilesResponse)
|
||||
}
|
1
go.mod
1
go.mod
|
@ -12,6 +12,7 @@ require (
|
|||
)
|
||||
|
||||
require (
|
||||
git.pyer.club/kingecg/goxml v1.0.1 // indirect
|
||||
github.com/bytedance/sonic v1.11.6 // indirect
|
||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,3 +1,7 @@
|
|||
git.pyer.club/kingecg/goxml v1.0.0 h1:csJ+gcWjTvMTy2pR4XpYLoevTro8hT7l1kpoUt4Xmpw=
|
||||
git.pyer.club/kingecg/goxml v1.0.0/go.mod h1:w/5zeL8crK/Be3k+RxEn4NNzQ/ybqZuU3uplw86mTt4=
|
||||
git.pyer.club/kingecg/goxml v1.0.1 h1:V2PbUSDkoq4gQUqkFO4zud+41GtSKq28A24lDeLkXaM=
|
||||
git.pyer.club/kingecg/goxml v1.0.1/go.mod h1:w/5zeL8crK/Be3k+RxEn4NNzQ/ybqZuU3uplw86mTt4=
|
||||
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
|
||||
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
|
||||
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package onvif
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
@ -10,6 +9,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
xml "git.pyer.club/kingecg/goxml"
|
||||
|
||||
"git.pyer.club/kingecg/goonvif/onvif/device"
|
||||
"git.pyer.club/kingecg/goonvif/onvif/gosoap"
|
||||
"git.pyer.club/kingecg/goonvif/onvif/networking"
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package gosoap
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"log"
|
||||
|
||||
xml "git.pyer.club/kingecg/goxml"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
)
|
||||
|
||||
//SoapMessage type from string
|
||||
// SoapMessage type from string
|
||||
type SoapMessage string
|
||||
|
||||
// NewEmptySOAP return new SoapMessage
|
||||
|
@ -20,7 +21,7 @@ func NewEmptySOAP() SoapMessage {
|
|||
return SoapMessage(res)
|
||||
}
|
||||
|
||||
//NewSOAP Get a new soap message
|
||||
// NewSOAP Get a new soap message
|
||||
func NewSOAP(headContent []*etree.Element, bodyContent []*etree.Element, namespaces map[string]string) SoapMessage {
|
||||
doc := buildSoapRoot()
|
||||
//doc.IndentTabs()
|
||||
|
@ -34,7 +35,7 @@ func (msg SoapMessage) String() string {
|
|||
return string(msg)
|
||||
}
|
||||
|
||||
//StringIndent handle indent
|
||||
// StringIndent handle indent
|
||||
func (msg SoapMessage) StringIndent() string {
|
||||
doc := etree.NewDocument()
|
||||
|
||||
|
@ -48,7 +49,7 @@ func (msg SoapMessage) StringIndent() string {
|
|||
return res
|
||||
}
|
||||
|
||||
//Body return body from Envelope
|
||||
// Body return body from Envelope
|
||||
func (msg SoapMessage) Body() string {
|
||||
|
||||
doc := etree.NewDocument()
|
||||
|
@ -65,7 +66,7 @@ func (msg SoapMessage) Body() string {
|
|||
return res
|
||||
}
|
||||
|
||||
//AddStringBodyContent for Envelope
|
||||
// AddStringBodyContent for Envelope
|
||||
func (msg *SoapMessage) AddStringBodyContent(data string) {
|
||||
doc := etree.NewDocument()
|
||||
|
||||
|
@ -89,7 +90,7 @@ func (msg *SoapMessage) AddStringBodyContent(data string) {
|
|||
*msg = SoapMessage(res)
|
||||
}
|
||||
|
||||
//AddBodyContent for Envelope
|
||||
// AddBodyContent for Envelope
|
||||
func (msg *SoapMessage) AddBodyContent(element *etree.Element) {
|
||||
doc := etree.NewDocument()
|
||||
if err := doc.ReadFromString(msg.String()); err != nil {
|
||||
|
@ -105,7 +106,7 @@ func (msg *SoapMessage) AddBodyContent(element *etree.Element) {
|
|||
*msg = SoapMessage(res)
|
||||
}
|
||||
|
||||
//AddBodyContents for Envelope body
|
||||
// AddBodyContents for Envelope body
|
||||
func (msg *SoapMessage) AddBodyContents(elements []*etree.Element) {
|
||||
doc := etree.NewDocument()
|
||||
if err := doc.ReadFromString(msg.String()); err != nil {
|
||||
|
@ -126,7 +127,7 @@ func (msg *SoapMessage) AddBodyContents(elements []*etree.Element) {
|
|||
*msg = SoapMessage(res)
|
||||
}
|
||||
|
||||
//AddStringHeaderContent for Envelope body
|
||||
// AddStringHeaderContent for Envelope body
|
||||
func (msg *SoapMessage) AddStringHeaderContent(data string) error {
|
||||
doc := etree.NewDocument()
|
||||
|
||||
|
@ -154,7 +155,7 @@ func (msg *SoapMessage) AddStringHeaderContent(data string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
//AddHeaderContent for Envelope body
|
||||
// AddHeaderContent for Envelope body
|
||||
func (msg *SoapMessage) AddHeaderContent(element *etree.Element) {
|
||||
doc := etree.NewDocument()
|
||||
if err := doc.ReadFromString(msg.String()); err != nil {
|
||||
|
@ -170,7 +171,7 @@ func (msg *SoapMessage) AddHeaderContent(element *etree.Element) {
|
|||
*msg = SoapMessage(res)
|
||||
}
|
||||
|
||||
//AddHeaderContents for Envelope body
|
||||
// AddHeaderContents for Envelope body
|
||||
func (msg *SoapMessage) AddHeaderContents(elements []*etree.Element) {
|
||||
doc := etree.NewDocument()
|
||||
if err := doc.ReadFromString(msg.String()); err != nil {
|
||||
|
@ -191,7 +192,7 @@ func (msg *SoapMessage) AddHeaderContents(elements []*etree.Element) {
|
|||
*msg = SoapMessage(res)
|
||||
}
|
||||
|
||||
//AddRootNamespace for Envelope body
|
||||
// AddRootNamespace for Envelope body
|
||||
func (msg *SoapMessage) AddRootNamespace(key, value string) {
|
||||
doc := etree.NewDocument()
|
||||
if err := doc.ReadFromString(msg.String()); err != nil {
|
||||
|
@ -204,7 +205,7 @@ func (msg *SoapMessage) AddRootNamespace(key, value string) {
|
|||
*msg = SoapMessage(res)
|
||||
}
|
||||
|
||||
//AddRootNamespaces for Envelope body
|
||||
// AddRootNamespaces for Envelope body
|
||||
func (msg *SoapMessage) AddRootNamespaces(namespaces map[string]string) {
|
||||
for key, value := range namespaces {
|
||||
msg.AddRootNamespace(key, value)
|
||||
|
@ -242,7 +243,7 @@ func buildSoapRoot() *etree.Document {
|
|||
return doc
|
||||
}
|
||||
|
||||
//AddWSSecurity Header for soapMessage
|
||||
// AddWSSecurity Header for soapMessage
|
||||
func (msg *SoapMessage) AddWSSecurity(username, password string) {
|
||||
//doc := etree.NewDocument()
|
||||
//if err := doc.ReadFromString(msg.String()); err != nil {
|
||||
|
@ -276,7 +277,7 @@ func (msg *SoapMessage) AddWSSecurity(username, password string) {
|
|||
//*msg = SoapMessage(res)
|
||||
}
|
||||
|
||||
//AddAction Header handling for soapMessage
|
||||
// AddAction Header handling for soapMessage
|
||||
func (msg *SoapMessage) AddAction() {
|
||||
|
||||
doc := etree.NewDocument()
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package gosoap
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
xml "git.pyer.club/kingecg/goxml"
|
||||
)
|
||||
|
||||
//Xlmns XML Scheam
|
||||
// Xlmns XML Scheam
|
||||
var actionHeaders = map[string]string{
|
||||
"wsnt:Subscribe": "http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest",
|
||||
"ResumeSubscription": "http://docs.oasis-open.org/wsn/bw-2/PausableSubscriptionManager/ResumeSubscriptionRequest",
|
||||
|
@ -17,7 +17,7 @@ var actionHeaders = map[string]string{
|
|||
Action Type in Header
|
||||
*************************/
|
||||
|
||||
//Action type
|
||||
// Action type
|
||||
type Action struct {
|
||||
//XMLName xml.Name `xml:"wsse:Security"`
|
||||
XMLName xml.Name `xml:"wsa:Action"`
|
||||
|
@ -30,7 +30,7 @@ type Action struct {
|
|||
</wsa:Action>
|
||||
*/
|
||||
|
||||
//NewAction get a new Action Section
|
||||
// NewAction get a new Action Section
|
||||
func NewAction(key, value string) Action {
|
||||
|
||||
/** Generating Nonce sequence **/
|
||||
|
|
|
@ -3,21 +3,26 @@ package gosoap
|
|||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/xml"
|
||||
"time"
|
||||
|
||||
xml "git.pyer.club/kingecg/goxml"
|
||||
|
||||
"github.com/elgs/gostrgen"
|
||||
)
|
||||
|
||||
/*************************
|
||||
/*
|
||||
************************
|
||||
|
||||
WS-Security types
|
||||
*************************/
|
||||
|
||||
************************
|
||||
*/
|
||||
const (
|
||||
passwordType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"
|
||||
encodingType = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
|
||||
)
|
||||
|
||||
//Security type :XMLName xml.Name `xml:"http://purl.org/rss/1.0/modules/content/ encoded"`
|
||||
// Security type :XMLName xml.Name `xml:"http://purl.org/rss/1.0/modules/content/ encoded"`
|
||||
type Security struct {
|
||||
//XMLName xml.Name `xml:"wsse:Security"`
|
||||
XMLName xml.Name `xml:"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd Security"`
|
||||
|
@ -55,7 +60,7 @@ type wsAuth struct {
|
|||
</Security>
|
||||
*/
|
||||
|
||||
//NewSecurity get a new security
|
||||
// NewSecurity get a new security
|
||||
func NewSecurity(username, passwd string) Security {
|
||||
/** Generating Nonce sequence **/
|
||||
charsToGenerate := 32
|
||||
|
@ -81,7 +86,7 @@ func NewSecurity(username, passwd string) Security {
|
|||
return auth
|
||||
}
|
||||
|
||||
//Digest = B64ENCODE( SHA1( B64DECODE( Nonce ) + Date + Password ) )
|
||||
// Digest = B64ENCODE( SHA1( B64DECODE( Nonce ) + Date + Password ) )
|
||||
func generateToken(Username string, Nonce string, Created string, Password string) string {
|
||||
sDec, _ := base64.StdEncoding.DecodeString(Nonce)
|
||||
|
||||
|
|
|
@ -2,12 +2,13 @@ package sdk
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
xml "git.pyer.club/kingecg/goxml"
|
||||
|
||||
"github.com/beevik/etree"
|
||||
"github.com/juju/errors"
|
||||
"github.com/rs/zerolog"
|
||||
|
|
|
@ -358,7 +358,7 @@ type Profile struct {
|
|||
type VideoSourceConfiguration struct {
|
||||
ConfigurationEntity
|
||||
ViewMode string `xml:"ViewMode,attr"`
|
||||
SourceToken ReferenceToken `xml:"onvif:SourceToken"`
|
||||
SourceToken ReferenceToken `xml:"tt:SourceToken"`
|
||||
Bounds IntRectangle `xml:"onvif:Bounds"`
|
||||
Extension *VideoSourceConfigurationExtension `xml:"onvif:Extension"`
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package search
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"testing"
|
||||
|
||||
xml "git.pyer.club/kingecg/goxml"
|
||||
|
||||
xsd "git.pyer.club/kingecg/goonvif/onvif/xsd"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue