mirror of
https://github.com/kerberos-io/onvif.git
synced 2026-08-23 15:08:33 +00:00
Critical
- Renew busy-loop on persistent failure: after a failed
renewPullPoint, the loop re-read the (now in-past)
GrantedTermination and nextRenewInterval floored to 1s, hammering
the camera at 1 Hz until reconnect. nextRenewIntervalAfterError
decouples the failure path from the stale grant and backs off
at opts.RetryBackoff. renewLoop also routes through s.now() so
test clocks can drive it deterministically.
- Lost-update race on GrantedTermination: a renew result for an
old subscription could overwrite the grant on a new one if
attemptRecreate swapped pullPoint mid-flight. A generation
counter on Stream tracks subscription rotation; the renew loop
captures the generation before the SOAP call and discards the
result if the subscription was rotated.
- Credential leak when <Security> straddled the 64 KiB error cap:
the non-greedy regex required a closing tag and missed the
truncated case. wsseSecurityRE now matches close-tag-or-EOF.
Belt-and-braces wssePasswordRE redacts <Password> elements
outside any Security wrapper.
- addHeaderChildren accepted well-formed-but-element-free input
and produced a header-less request. Now errors out.
Important
- Wrapper detection in buildRefParamsHeader was HasSuffix-based and
misfired on children named *ReferenceParameters. Replaced with the
unambiguous wrapper-only contract: input must be the full
<*:ReferenceParameters> element returned by extractReferenceParameters.
- Renamed SoapOption → SendSoapOption and WithHeader → WithSOAPHeader
to disambiguate at call sites.
- Renamed WithHeader's `xml` parameter to headerContent to avoid
shadowing the encoding/xml package name.
- Documented terminationTimeRE's "first match only" semantics so
nobody re-uses it from PullMessages context where multiple
TerminationTime elements appear.
- goleak is now a direct require (go mod tidy).
Performance
- Added gosoap.AddStringHeaderContents (plural) for multi-root
header content. AddStringHeaderContent remains as-is for
backwards compatibility with external consumers. Device.go's
addHeaderChildren workaround is gone — one etree parse per
SendSoapWithOptions call instead of two.
Migration
- Device.go's own CallOnvifFunction and the three examples now
call SendSoapWithOptions, modelling the canonical path.
Docs / tests
- Trust-boundary warning on SendSoapWithHeader/Options godoc.
- Comments on createPullPointResp/Alt explain why TerminationTime
is intentionally omitted (renew timing fixtures).
- New tests: digest retry strips WS-Security, duplicate
WithSOAPHeader is last-wins, malformed TerminationTime yields
zero, margin==base falls to base/2, empty SubscriptionReference
yields empty ref params, Security straddling cap is redacted,
bare Password redacted, wrapper-only contract is enforced.
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"github.com/kerberos-io/onvif"
|
|
"github.com/kerberos-io/onvif/event"
|
|
"github.com/kerberos-io/onvif/xsd"
|
|
"io/ioutil"
|
|
"log"
|
|
)
|
|
|
|
// === Geovision ===
|
|
// Request:
|
|
// <tev:PullMessages>
|
|
// <tev:Timeout>PT20S</tev:Timeout>
|
|
// <tev:MessageLimit>10</tev:MessageLimit>
|
|
// </tev:PullMessages>
|
|
// Response:
|
|
// <tev:PullMessagesResponse>
|
|
// <tev:CurrentTime>2021-12-02T02:42:30Z</tev:CurrentTime>
|
|
// <tev:TerminationTime>2021-12-02T02:42:50Z</tev:TerminationTime>
|
|
// <wsnt:NotificationMessage> ... </wsnt:NotificationMessage>
|
|
// </tev:PullMessagesResponse>
|
|
//
|
|
// Test Summary:
|
|
// 1. the TerminationTime = CurrentTime+Timeout
|
|
// 2. even current time exceed the TerminationTime, the pull point still alive
|
|
|
|
// === BOSCH ===
|
|
// Request:
|
|
// <tev:PullMessages>
|
|
// <tev:Timeout>PT20S</tev:Timeout>
|
|
// <tev:MessageLimit>10</tev:MessageLimit>
|
|
// </tev:PullMessages>
|
|
// Response:
|
|
// <tev:PullMessagesResponse>
|
|
// <tev:CurrentTime>2021-12-02T03:06:39Z</tev:CurrentTime>
|
|
// <tev:TerminationTime>2021-12-02T03:07:39Z</tev:TerminationTime>
|
|
// <wsnt:NotificationMessage> ... </wsnt:NotificationMessage>
|
|
// </tev:PullMessagesResponse>
|
|
//
|
|
// Test Summary:
|
|
// the TerminationTime increase one minute
|
|
|
|
// === Hikvisiion ===
|
|
// Request:
|
|
//
|
|
// Response:
|
|
// <tev:PullMessagesResponse><tev:CurrentTime>2021-12-02T06:08:35Z</tev:CurrentTime>
|
|
//
|
|
// <tev:TerminationTime>2021-12-02T06:18:40Z</tev:TerminationTime>
|
|
// <wsnt:NotificationMessage><wsnt:Topic Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">tns1:RuleEngine/CellMotionDetector/Motion</wsnt:Topic>
|
|
// ...
|
|
// </wsnt:NotificationMessage>
|
|
// </tev:PullMessagesResponse>
|
|
//
|
|
// Test Summary:
|
|
//
|
|
// the TerminationTime increase ten minutes
|
|
func main() {
|
|
dev, err := onvif.NewDevice(onvif.DeviceParams{
|
|
Xaddr: "192.168.12.148", // BOSCH
|
|
//Xaddr: "192.168.12.149", // Geovision
|
|
//Xaddr: "192.168.12.123", //Hikvision
|
|
Username: "administrator",
|
|
Password: "Password1!",
|
|
AuthMode: onvif.UsernameTokenAuth,
|
|
})
|
|
if err != nil {
|
|
log.Fatalln("fail to new device:", err)
|
|
}
|
|
|
|
pullMessage := event.PullMessages{
|
|
Timeout: xsd.Duration("PT5S"),
|
|
MessageLimit: 10,
|
|
}
|
|
|
|
endPoint := "http://192.168.12.148/Web_Service?Idx=0" // BOSCH
|
|
//endPoint := "http://192.168.12.149:80/onvif/events" // Geovision
|
|
//endPoint := "http://192.168.12.123/onvif/Events/PullSubManager_2021-12-02T06:07:58Z_0"
|
|
requestBody, err := xml.Marshal(pullMessage)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
res, err := dev.SendSoapWithOptions(endPoint, string(requestBody))
|
|
if err != nil {
|
|
log.Fatalln("fail to CallMethod:", err)
|
|
}
|
|
bs, _ := ioutil.ReadAll(res.Body)
|
|
|
|
log.Printf(">> Result: %+v \n %s", res.StatusCode, bs)
|
|
}
|