Skip to content

Commit

Permalink
diz memory leak + import
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Dec 6, 2023
1 parent bb5a87b commit 71b6d48
Show file tree
Hide file tree
Showing 207 changed files with 830 additions and 832 deletions.
48 changes: 23 additions & 25 deletions Device.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
wsdiscovery "github.com/kerberos-io/onvif/ws-discovery"
)

//Xlmns XML Scheam
// Xlmns XML Scheam
var Xlmns = map[string]string{
"onvif": "http://www.onvif.org/ver10/schema",
"tds": "http://www.onvif.org/ver10/device/wsdl",
Expand All @@ -36,7 +36,7 @@ var Xlmns = map[string]string{
"wsaw": "http://www.w3.org/2006/05/addressing/wsdl",
}

//DeviceType alias for int
// DeviceType alias for int
type DeviceType int

// Onvif Device Tyoe
Expand All @@ -63,7 +63,7 @@ func (devType DeviceType) String() string {
}
}

//DeviceInfo struct contains general information about ONVIF device
// DeviceInfo struct contains general information about ONVIF device
type DeviceInfo struct {
Manufacturer string
Model string
Expand All @@ -72,9 +72,9 @@ type DeviceInfo struct {
HardwareId string
}

//Device for a new device of onvif and DeviceInfo
//struct represents an abstract ONVIF device.
//It contains methods, which helps to communicate with ONVIF device
// Device for a new device of onvif and DeviceInfo
// struct represents an abstract ONVIF device.
// It contains methods, which helps to communicate with ONVIF device
type Device struct {
params DeviceParams
endpoints map[string]string
Expand All @@ -88,12 +88,12 @@ type DeviceParams struct {
HttpClient *http.Client
}

//GetServices return available endpoints
// GetServices return available endpoints
func (dev *Device) GetServices() map[string]string {
return dev.endpoints
}

//GetServices return available endpoints
// GetServices return available endpoints
func (dev *Device) GetDeviceInfo() DeviceInfo {
return dev.info
}
Expand All @@ -106,7 +106,7 @@ func readResponse(resp *http.Response) string {
return string(b)
}

//GetAvailableDevicesAtSpecificEthernetInterface ...
// GetAvailableDevicesAtSpecificEthernetInterface ...
func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) ([]Device, error) {
// Call a ws-discovery Probe Message to Discover NVT type Devices
devices, err := wsdiscovery.SendProbe(interfaceName, nil, []string{"dn:" + NVT.String()}, map[string]string{"dn": "http://www.onvif.org/ver10/network/wsdl"})
Expand Down Expand Up @@ -140,16 +140,8 @@ func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) ([]Dev
return nvtDevices, nil
}

func (dev *Device) getSupportedServices(resp *http.Response) error {
func (dev *Device) getSupportedServices(data []byte) error {
doc := etree.NewDocument()

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}

resp.Body.Close()

if err := doc.ReadFromBytes(data); err != nil {
//log.Println(err.Error())
return err
Expand All @@ -168,7 +160,7 @@ func (dev *Device) getSupportedServices(resp *http.Response) error {
return nil
}

//NewDevice function construct a ONVIF Device entity
// NewDevice function construct a ONVIF Device entity
func NewDevice(params DeviceParams) (*Device, error) {
dev := new(Device)
dev.params = params
Expand All @@ -183,11 +175,17 @@ func NewDevice(params DeviceParams) (*Device, error) {

resp, err := dev.CallMethod(getCapabilities)

var b []byte
if resp != nil {
b, err = ioutil.ReadAll(resp.Body)
resp.Body.Close()
}

if err != nil || resp.StatusCode != http.StatusOK {
return nil, errors.New("camera is not available at " + dev.params.Xaddr + " or it does not support ONVIF services")
}

err = dev.getSupportedServices(resp)
err = dev.getSupportedServices(b)
if err != nil {
return nil, err
}
Expand All @@ -209,7 +207,7 @@ func (dev *Device) addEndpoint(Key, Value string) {
dev.endpoints[lowCaseKey] = Value
}

//GetEndpoint returns specific ONVIF service endpoint address
// GetEndpoint returns specific ONVIF service endpoint address
func (dev *Device) GetEndpoint(name string) string {
return dev.endpoints[name]
}
Expand All @@ -229,7 +227,7 @@ func (dev Device) buildMethodSOAP(msg string) (gosoap.SoapMessage, error) {
return soap, nil
}

//getEndpoint functions get the target service endpoint in a better way
// getEndpoint functions get the target service endpoint in a better way
func (dev Device) getEndpoint(endpoint string) (string, error) {

// common condition, endpointMark in map we use this.
Expand All @@ -250,8 +248,8 @@ func (dev Device) getEndpoint(endpoint string) (string, error) {
return endpointURL, errors.New("target endpoint service not found")
}

//CallMethod functions call an method, defined <method> struct.
//You should use Authenticate method to call authorized requests.
// CallMethod functions call an method, defined <method> struct.
// You should use Authenticate method to call authorized requests.
func (dev Device) CallMethod(method interface{}) (*http.Response, error) {
pkgPath := strings.Split(reflect.TypeOf(method).PkgPath(), "/")
pkg := strings.ToLower(pkgPath[len(pkgPath)-1])
Expand All @@ -263,7 +261,7 @@ func (dev Device) CallMethod(method interface{}) (*http.Response, error) {
return dev.callMethodDo(endpoint, method)
}

//CallMethod functions call an method, defined <method> struct with authentication data
// CallMethod functions call an method, defined <method> struct with authentication data
func (dev Device) callMethodDo(endpoint string, method interface{}) (*http.Response, error) {
output, err := xml.MarshalIndent(method, " ", " ")
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions examples/DeviceService.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"log"
"net/http"

goonvif "github.com/use-go/onvif"
"github.com/use-go/onvif/device"
sdk "github.com/use-go/onvif/sdk/device"
"github.com/use-go/onvif/xsd/onvif"
goonvif "github.com/kerberos-io/onvif"
"github.com/kerberos-io/onvif/device"
sdk "github.com/kerberos-io/onvif/sdk/device"
"github.com/kerberos-io/onvif/xsd/onvif"
)

const (
Expand Down Expand Up @@ -60,7 +60,7 @@ func main() {
if err != nil {
log.Println(err)
} else {
// You could use https://github.com/use-go/onvif/gosoap for pretty printing response
// You could use https://github.com/kerberos-io/onvif/gosoap for pretty printing response
fmt.Println(createUserResponse)
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package {{.Package}}
import (
"context"
"github.com/juju/errors"
"github.com/use-go/onvif"
"github.com/use-go/onvif/sdk"
"github.com/use-go/onvif/{{.StructPackage}}"
"github.com/kerberos-io/onvif"
"github.com/kerberos-io/onvif/sdk"
"github.com/kerberos-io/onvif/{{.StructPackage}}"
)
// Call_{{.TypeRequest}} forwards the call to dev.CallMethod() then parses the payload of the reply as a {{.TypeReply}}.
Expand Down
6 changes: 3 additions & 3 deletions sdk/device/AddIPAddressFilter_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/AddScopes_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/CreateCertificate_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/CreateDot1XConfiguration_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/CreateStorageConfiguration_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/CreateUsers_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/DeleteCertificates_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/DeleteDot1XConfiguration_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/DeleteGeoLocation_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/DeleteStorageConfiguration_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/DeleteUsers_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/GetAccessPolicy_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/GetCACertificates_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/GetCapabilities_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/GetCertificateInformation_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sdk/device/GetCertificatesStatus_auto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 71b6d48

Please sign in to comment.