Skip to content

Commit

Permalink
Send propper Onvif headers for event streaming requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
osery committed May 16, 2023
1 parent fcd422d commit 8351707
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
14 changes: 1 addition & 13 deletions cmd/gonvif/events/stream-events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (

"github.com/eyetowers/gonvif/cmd/gonvif/root"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_onvif_org/ver10/events/wsdl"
"github.com/eyetowers/gonvif/pkg/generated/onvif/www_w3_org/2005/08/addressing"
"github.com/eyetowers/gonvif/pkg/gonvif"
"github.com/eyetowers/gonvif/pkg/gonvif/axis"
)

var streamEvents = &cobra.Command{
Expand All @@ -32,7 +30,7 @@ func runStreamEvents(client gonvif.Client) error {
if err != nil {
return err
}
headers := extractHeaders(resp.SubscriptionReference)
headers := gonvif.ComposeHeaders(resp.SubscriptionReference)
subscription, err := client.Subscription(string(*resp.SubscriptionReference.Address), headers...)
if err != nil {
return err
Expand All @@ -52,13 +50,3 @@ func processEvents(subscription wsdl.PullPointSubscription) error {
}
}
}

func extractHeaders(ref *addressing.EndpointReferenceType) []any {
// NOTE: Axis returns a SubscriptionId that has to be passed into the PullMessages call as SOAP
// header as-is. We try to mimic this behavior here.
var headers []any
if axisHeader, ok := axis.ToHeader(ref); ok {
headers = append(headers, axisHeader)
}
return headers
}
34 changes: 34 additions & 0 deletions pkg/gonvif/headers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gonvif

import (
"encoding/xml"

"github.com/eyetowers/gonvif/pkg/generated/onvif/www_w3_org/2005/08/addressing"
"github.com/eyetowers/gonvif/pkg/gonvif/axis"
)

func ComposeHeaders(ref *addressing.EndpointReferenceType) []any {
// NOTE: Axis returns a SubscriptionId that has to be passed into the PullMessages call as SOAP
// header as-is. We try to mimic this behavior here.
var headers []any
if axisHeader, ok := axis.ToHeader(ref); ok {
headers = append(headers, axisHeader)
}
headers = append(headers,
ReplyToAddressingHeader{Address: "http://www.w3.org/2005/08/addressing/anonymous"},
ToAddressingHeader{Value: string(*ref.Address)},
)
return headers
}

type ToAddressingHeader struct {
XMLName xml.Name `xml:"http://www.w3.org/2005/08/addressing To"`

Value string `xml:",chardata"`
}

type ReplyToAddressingHeader struct {
XMLName xml.Name `xml:"http://www.w3.org/2005/08/addressing ReplyTo"`

Address string `xml:"http://www.w3.org/2005/08/addressing Address"`
}

0 comments on commit 8351707

Please sign in to comment.