Skip to content

Commit c5fe522

Browse files
committed
WithoutAuth instead CallWithoutAuth, GetSystemDateAndTime can required auth on some cameras
parse posix timezone can stop on H:m defer resp.Body.Close for try fix memory leak
1 parent bc3ae5c commit c5fe522

6 files changed

+30
-11
lines changed

deviceService.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ func NewDeviceService(onvifDevice *OnvifDevice) *DeviceService {
1717
}
1818
}
1919

20+
func (s *DeviceService) WithoutAuth() *DeviceService {
21+
return &DeviceService{
22+
Client: s.Client.WithoutAuth(),
23+
}
24+
}
25+
2026
// GetDeviceInformation gets basic device information from the device.
2127
func (s *DeviceService) GetDeviceInformation() (res tds.GetDeviceInformationResponse, err error) {
2228
err = s.Client.Call(tds.GetDeviceInformation{}, &res)
@@ -38,7 +44,7 @@ func (s *DeviceService) GetServices(includeCapability bool) (res tds.GetServices
3844
//
3945
// A device shall provide the UTCDateTime information.
4046
func (s *DeviceService) GetSystemDateAndTime() (res tds.GetSystemDateAndTimeResponse, err error) {
41-
err = s.Client.CallWithoutAuth(tds.GetSystemDateAndTime{}, &res)
47+
err = s.Client.Call(tds.GetSystemDateAndTime{}, &res)
4248
return
4349
}
4450

mediaService.go

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ func NewMediaService(endpoint string, onvifAuth *onvifAuth) *MediaService {
1515
}
1616
}
1717

18+
func (s *MediaService) WithoutAuth() *MediaService {
19+
return &MediaService{
20+
Client: s.Client.WithoutAuth(),
21+
}
22+
}
23+
1824
// GetProfiles using for ask the existing media profiles of a device
1925
// Pre-configured or dynamically configured profiles can be retrieved using this command.
2026
// This command lists all configured profiles in a device.

onvif/posix_timezone.go

+6
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ func parsePosixTimezoneTime(t *posixTimezoneTime, timePart string) error {
223223
switch state {
224224
case weekend:
225225
t.Weekday, err = strconv.Atoi(timePart[start:])
226+
case hours:
227+
t.Hours, err = strconv.Atoi(timePart[start:])
228+
t.Minutes, t.Seconds = 0, 0
229+
case minutes:
230+
t.Minutes, err = strconv.Atoi(timePart[start:])
231+
t.Seconds = 0
226232
case seconds:
227233
t.Seconds, err = strconv.Atoi(timePart[start:])
228234
}

onvifClient.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type onvifCaller interface {
1010
Call(request, response interface{}) error
1111

12-
CallWithoutAuth(request, response interface{}) error
12+
WithoutAuth() onvifCaller
1313
}
1414

1515
type onvifAuth struct {
@@ -30,19 +30,18 @@ func NewOnvifClient(endpoint string, auth *onvifAuth) *onvifClient {
3030
}
3131
}
3232

33-
func (c *onvifClient) callOnInternal(request, response interface{}, useAuth bool) error {
34-
if c.auth.login != "" && useAuth {
33+
func (c *onvifClient) Call(request, response interface{}) error {
34+
if c.auth.login != "" {
3535
return c.soapClient.Do(request, response,
3636
soap.MakeWSSecurity(c.auth.login, c.auth.password, c.auth.timeDiff))
3737
}
3838

3939
return c.soapClient.Do(request, response)
4040
}
4141

42-
func (c *onvifClient) Call(request, response interface{}) error {
43-
return c.callOnInternal(request, response, true)
44-
}
45-
46-
func (c *onvifClient) CallWithoutAuth(request, response interface{}) error {
47-
return c.callOnInternal(request, response, false)
42+
func (c *onvifClient) WithoutAuth() onvifCaller {
43+
return &onvifClient{
44+
soapClient: c.soapClient,
45+
auth: &onvifAuth{},
46+
}
4847
}

onvifdevice.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (onvifDevice *OnvifDevice) Initialize() error {
6262
deviceService := NewDeviceService(onvifDevice)
6363

6464
currentTime := time.Now().UTC()
65-
systemDateAndTimeResponse, err := deviceService.GetSystemDateAndTime()
65+
systemDateAndTimeResponse, err := deviceService.WithoutAuth().GetSystemDateAndTime()
6666
if err == nil {
6767
//TODO: warn if GetSystemDateAndTime return err
6868
deviceTime, _ := systemDateAndTimeResponse.SystemDateAndTime.GetUTCTime()

soap/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func (soap *SoapClient) Do(request, response interface{}, headers ...interface{}
4343
if err != nil {
4444
return err
4545
}
46+
defer resp.Body.Close()
47+
4648
if resp.StatusCode != http.StatusOK &&
4749
resp.StatusCode != http.StatusInternalServerError &&
4850
resp.StatusCode != http.StatusBadRequest {

0 commit comments

Comments
 (0)