hikvision

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrResponseNotOk is returned by Client.Get calls when the
	// the API returns a response with a non-200 HTTP status code.
	ErrResponseNotOk = errors.New("hikvision: response not ok")

	// ErrParseErrorMessageFailure is returned by Client.Get calls
	// when the API call is not successful but there the error
	// message could not be successfully parsed.
	ErrParseErrorMessageFailure = errors.New("hikvision: error parsing error message")

	// ErrUnhandledContentType is returned when the Content-Type
	// header is not unhandled by the client.
	ErrUnhandledContentType = errors.New("hikvision: unhandled content type")
)

Functions

func Hash

func Hash(s string) string

Hash returns a MD5 hash of a string.

Types

type AuthTransport

type AuthTransport struct {
	Username  string
	Password  string
	Transport http.RoundTripper
}

AuthTransport is a http.RoundTripper that takes care of authenticating with the API using HTTP Digest Authentication.

func NewAuthTransport

func NewAuthTransport(username, password string) *AuthTransport

NewAuthTransport is a constructor for AuthTransport.

func (*AuthTransport) RoundTrip

func (t *AuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface. It makes a request expecting a HTTP 401 Unauthorized response. If unauthenticated, it creates the required credentials and follow with the original request.

type Challenge

type Challenge struct {
	Realm     string
	Domain    string
	Nonce     string
	Opaque    string
	Stale     string
	Algorithm string
	Qop       string // TODO: Should Qop be an array of strings?
}

Challenge represents the digest challenge, which is found on the `WWW-Authenticate` header on the initial request.

func NewChallenge

func NewChallenge(header string) *Challenge

NewChallenge is a constructor for Challenge

func (*Challenge) Authorize

func (c *Challenge) Authorize(username, password, method, uri string) *Response

Authorize method returns a Response.

type Client

type Client struct {
	Client  *http.Client
	BaseURL string
}

Client is a http.Client wrapper that handles authentication.

func NewClient

func NewClient(host, username, password string) (*Client, error)

NewClient is a constructor for the Client object.

func (*Client) Do

func (c *Client) Do(r *http.Request) ([]byte, error)

Do executes a HTTP request.

func (*Client) Get

func (c *Client) Get(u *url.URL) ([]byte, error)

Get executes a HTTP GET request.

func (*Client) GetDeviceInfo

func (c *Client) GetDeviceInfo() (resp *DeviceInfo, err error)

GetDeviceInfo executes a HTTP GET request to the /ISAPI/System/deviceInfo endpoint.

func (*Client) GetDeviceInfoCapabilities

func (c *Client) GetDeviceInfoCapabilities() (resp *DeviceInfoCap, err error)

GetDeviceInfoCapabilities executes a HTTP GET request to the /ISAPI/System/deviceInfo/capabilities endpoint.

func (*Client) GetFocusConf

func (c *Client) GetFocusConf(channelId string) (resp *FocusConfiguration, err error)

func (*Client) GetImageFlip

func (c *Client) GetImageFlip(channelId string) (resp *ImageFlip, err error)

func (*Client) GetTime

func (c *Client) GetTime() (resp *Time, err error)

GetTime executes a HTTP GET request to the /ISAPI/System/time endpoint.

func (*Client) Put

func (c *Client) Put(u *url.URL, contentType string, data []byte) ([]byte, error)

Put executes a HTTP PUT request.

func (*Client) PutFocusConf

func (c *Client) PutFocusConf(data *FocusConfiguration, channelId string) (resp *ResponseStatus, err error)

func (*Client) PutImageFlip

func (c *Client) PutImageFlip(data *ImageFlip, channelId string) (resp *ResponseStatus, err error)

func (*Client) PutJSON

func (c *Client) PutJSON(u *url.URL, contentType string, data interface{}) ([]byte, error)

PutJSON executes a HTTP PUT request with `application/json` content type.

func (*Client) PutTime

func (c *Client) PutTime(data *Time) (resp *ResponseStatus, err error)

PutTime executes a HTTP PUT request to the /ISAPI/System/time endpoint.

func (*Client) PutXML

func (c *Client) PutXML(u *url.URL, data interface{}) ([]byte, error)

PutXML executes a HTTP PUT request with `application/xml` content type.

type DeviceInfo

type DeviceInfo struct {
	XMLName              xml.Name                        `xml:"DeviceInfo,omitempty"`
	XMLVersion           string                          `xml:"version,attr"`
	XMLNamespace         string                          `xml:"xmlns,attr"`
	DeviceName           string                          `xml:"deviceName,omitempty" json:"deviceName,omitempty"`
	DeviceID             string                          `xml:"deviceID,omitempty" json:"deviceID,omitempty"`
	DeviceDescription    string                          `xml:"deviceDescription,omitempty" json:"deviceDescription,omitempty"`
	DeviceLocation       string                          `xml:"deviceLocation,omitempty" json:"deviceLocation,omitempty"`
	DeviceStatus         string                          `xml:"deviceStatus,omitempty" json:"deviceStatus,omitempty"`
	DetailAbnormalStatus *DeviceInfoDetailAbnormalStatus `xml:"DetailAbnormalStatus,omitempty" json:"DetailAbnormalStatus,omitempty"`
	SystemContact        string                          `xml:"systemContact,omitempty" json:"systemContact,omitempty"`
	Model                string                          `xml:"model,omitempty" json:"model,omitempty"`
	SerialNumber         string                          `xml:"serialNumber,omitempty" json:"serialNumber,omitempty"`
	MacAddress           string                          `xml:"macAddress,omitempty" json:"macAddress,omitempty"`
	FirmwareVersion      string                          `xml:"firmwareVersion,omitempty" json:"firmwareVersion,omitempty"`
	FirmwareReleasedDate string                          `xml:"firmwareReleasedDate,omitempty" json:"firmwareReleasedDate,omitempty"`
	BootVersion          string                          `xml:"bootVersion,omitempty" json:"bootVersion,omitempty"`
	BootReleasedDate     string                          `xml:"bootReleasedDate,omitempty" json:"bootReleasedDate,omitempty"`
	HardwareVersion      string                          `xml:"hardwareVersion,omitempty" json:"hardwareVersion,omitempty"`
	EncoderVersion       string                          `xml:"encoderVersion,omitempty" json:"encoderVersion,omitempty"`
	EncoderReleasedDate  string                          `xml:"encoderReleasedDate,omitempty" json:"encoderReleasedDate,omitempty"`
	DecoderVersion       string                          `xml:"decoderVersion,omitempty" json:"decoderVersion,omitempty"`
	DecoderReleasedDate  string                          `xml:"decoderReleasedDate,omitempty" json:"decoderReleasedDate,omitempty"`
	SoftwareVersion      string                          `xml:"softwareVersion,omitempty" json:"softwareVersion,omitempty"`
	Capacity             int                             `xml:"capacity,omitempty" json:"capacity,omitempty"`
	UsedCapacity         int                             `xml:"usedCapacity,omitempty" json:"usedCapacity,omitempty"`
	DeviceType           string                          `xml:"deviceType,omitempty" json:"deviceType,omitempty"`
	TelecontrolID        int                             `xml:"telecontrolID,omitempty" json:"telecontrolID,omitempty"`
	SupportBeep          bool                            `xml:"supportBeep,omitempty" json:"supportBeep,omitempty"`
	ActualFloorNum       int                             `xml:"actualFloorNum,omitempty" json:"actualFloorNum,omitempty"`
	SubChannelEnabled    bool                            `xml:"subChannelEnabled,omitempty" json:"subChannelEnabled,omitempty"`
	ThrChannelEnabled    bool                            `xml:"thrChannelEnabled,omitempty" json:"thrChannelEnabled,omitempty"`
	RadarVersion         string                          `xml:"radarVersion,omitempty" json:"radarVersion,omitempty"`
	LocalZoneNum         int                             `xml:"localZoneNum,omitempty" json:"localZoneNum,omitempty"`
	AlarmOutNum          int                             `xml:"alarmOutNum,omitempty" json:"alarmOutNum,omitempty"`
	DistanceResolution   float32                         `xml:"distanceResolution,omitempty" json:"distanceResolution,omitempty"`
	AngleResolution      float32                         `xml:"angleResolution,omitempty" json:"angleResolution,omitempty"`
	SpeedResolution      float32                         `xml:"speedResolution,omitempty" json:"speedResolution,omitempty"`
	DetectDistance       float32                         `xml:"detectDistance,omitempty" json:"detectDistance,omitempty"`
	LanguageType         string                          `xml:"languageType,omitempty" json:"languageType,omitempty"`
	RelayNum             int                             `xml:"relayNum,omitempty" json:"relayNum,omitempty"`
	ElectroLockNum       int                             `xml:"electroLockNum,omitempty" json:"electroLockNum,omitempty"`
	RS485Num             int                             `xml:"RS485Num,omitempty" json:"RS485Num,omitempty"`
	PowerOnMode          string                          `xml:"powerOnMode,omitempty" json:"powerOnMode,omitempty"`
}

DeviceInfo represents the XML_DeviceInfo and JSON_DeviceInfo resource.

type DeviceInfoCap

type DeviceInfoCap struct {
	XMLName              xml.Name `xml:"DeviceInfo,omitempty"`
	XMLVersion           string   `xml:"version,attr"`
	XMLNamespace         string   `xml:"xmlns,attr"`
	DeviceName           string   `xml:"deviceName,omitempty" json:"deviceName,omitempty"`
	LanguageType         string   `xml:"languageType,omitempty" json:"languageType,omitempty"`
	DeviceID             string   `xml:"deviceID,omitempty" json:"deviceID,omitempty"`
	DeviceDescription    string   `xml:"deviceDescription,omitempty" json:"deviceDescription,omitempty"`
	DeviceLocation       string   `xml:"deviceLocation,omitempty" json:"deviceLocation,omitempty"`
	SystemContact        string   `xml:"systemContact,omitempty" json:"systemContact,omitempty"`
	Model                string   `xml:"model,omitempty" json:"model,omitempty"`
	SerialNumber         string   `xml:"serialNumber,omitempty" json:"serialNumber,omitempty"`
	MacAddress           string   `xml:"macAddress,omitempty" json:"macAddress,omitempty"`
	FirmwareVersion      string   `xml:"firmwareVersion,omitempty" json:"firmwareVersion,omitempty"`
	FirmwareReleasedDate string   `xml:"firmwareReleasedDate,omitempty" json:"firmwareReleasedDate,omitempty"`
	BootVersion          string   `xml:"bootVersion,omitempty" json:"bootVersion,omitempty"`
	BootReleasedDate     string   `xml:"bootReleasedDate,omitempty" json:"bootReleasedDate,omitempty"`
	HardwareVersion      string   `xml:"hardwareVersion,omitempty" json:"hardwareVersion,omitempty"`
	EncoderVersion       string   `xml:"encoderVersion,omitempty" json:"encoderVersion,omitempty"`
	EncoderReleasedDate  string   `xml:"encoderReleasedDate,omitempty" json:"encoderReleasedDate,omitempty"`
	DecoderVersion       string   `xml:"decoderVersion,omitempty" json:"decoderVersion,omitempty"`
	DecoderReleasedDate  string   `xml:"decoderReleasedDate,omitempty" json:"decoderReleasedDate,omitempty"`
	DeviceType           string   `xml:"deviceType,omitempty" json:"deviceType,omitempty"`
	TelecontrolID        int      `xml:"telecontrolID,omitempty" json:"telecontrolID,omitempty"`
	SupportBeep          bool     `xml:"supportBeep,omitempty" json:"supportBeep,omitempty"`
	FirmwareVersionInfo  string   `xml:"firmwareVersionInfo,omitempty" json:"firmwareVersionInfo,omitempty"`
	SubChannelEnabled    bool     `xml:"subChannelEnabled,omitempty" json:"subChannelEnabled,omitempty"`
	ThrChannelEnabled    bool     `xml:"thrChannelEnabled,omitempty" json:"thrChannelEnabled,omitempty"`
	ActualFloorNum       int      `xml:"actualFloorNum,omitempty" json:"actualFloorNum,omitempty"`
	RadarVersion         string   `xml:"radarVersion,omitempty" json:"radarVersion,omitempty"`
	PowerOnMode          string   `xml:"powerOnMode,omitempty" json:"powerOnMode,omitempty"`
}

DeviceInfoCap represents the XML_Cap_DeviceInfo and JSON_Cap_DeviceInfo resource.

type DeviceInfoDetailAbnormalStatus

type DeviceInfoDetailAbnormalStatus struct {
	HardDiskFull         bool `xml:"hardDiskFull,omitempty" json:"hardDiskFull,omitempty"`
	HardDiskError        bool `xml:"hardDiskError,omitempty" json:"hardDiskError,omitempty"`
	EthernetBroken       bool `xml:"ethernetBroken,omitempty" json:"ethernetBroken,omitempty"`
	IPAddrConflict       bool `xml:"ipaddrConflict,omitempty" json:"ipaddrConflict,omitempty"`
	IllegalAccess        bool `xml:"illegalAccess,omitempty" json:"illegalAccess,omitempty"`
	RecordError          bool `xml:"recordError,omitempty" json:"recordError,omitempty"`
	RaidLogicDiskError   bool `xml:"raidLogicDiskError,omitempty" json:"raidLogicDiskError,omitempty"`
	SpareWorkDeviceError bool `xml:"spareWorkDeviceError,omitempty" json:"spareWorkDeviceError,omitempty"`
}

DeviceInfoDetailAbnormalStatus represents the device abnormal status, which is used in the XML_DeviceInfo resource.

type FocusConfiguration

type FocusConfiguration struct {
	XMLName                       xml.Name `xml:"FocusConfiguration,omitempty"`
	XMLVersion                    string   `xml:"version,attr"`
	XMLNamespace                  string   `xml:"xmlns,attr"`
	FocusStyle                    string   `xml:"focusStyle,omitempty" json:"focusStyle,omitempty"`                                       //req
	FocusLimited                  int      `xml:"focusLimited,omitempty" json:"focusLimited,omitempty"`                                   //opt
	FocusPosition                 int      `xml:"focusPosition,omitempty" json:"focusPosition,omitempty"`                                 //dep depends on "FocusStyle"
	FocusSpeed                    int      `xml:"focusSpeed,omitempty" json:"focusSpeed,omitempty"`                                       //opt
	FocusSensitivity              int      `xml:"focusSensitivity,omitempty" json:"focusSensitivity,omitempty"`                           //opt
	TemperatureChangeAdaptEnabled bool     `xml:"temperatureChangeAdaptEnabled,omitempty" json:"temperatureChangeAdaptEnabled,omitempty"` //opt
	RelativeFocusPos              int      `xml:"relativeFocusPos,omitempty" json:"relativeFocusPos,omitempty"`                           //opt
	HighTemperaturePriority       bool     `xml:"highTemperaturePriority,omitempty" json:"highTemperaturePriority,omitempty"`             //opt
}

type ImageFlip

type ImageFlip struct {
	XMLName        xml.Name `xml:"ImageFlip,omitempty"`
	XMLVersion     string   `xml:"version,attr"`
	XMLNamespace   string   `xml:"xmlns,attr"`
	Enabled        bool     `xml:"enabled,omitempty" json:"enabled,omitempty"`               //req
	ImageFlipStyle string   `xml:"ImageFlipStyle,omitempty" json:"ImageFlipStyle,omitempty"` //"LEFTRIGHT, UPDOWN, CENTER, AUTO
	FlipAngle      string   `xml:"flipAngle,omitempty" json:"flipAngle,omitempty"`           //"90, 180, 270"
}

type Response

type Response struct {
	Username string
	Realm    string
	Nonce    string
	URI      string
	Qop      string
	Cnonce   string
	Nc       string
	Response string
	Opaque   string
}

Response represents the digest response, which is embedded on the `Authorization` header on every subsequent requests.

func (*Response) String

func (r *Response) String() string

Header method returns Response as header string

type ResponseStatus

type ResponseStatus struct {
	XMLName       xml.Name                     `xml:"ResponseStatus,omitempty"`
	XMLVersion    string                       `xml:"version,attr"`
	XMLNamespace  string                       `xml:"xmlns,attr"`
	RequestURL    string                       `xml:"requestURL,omitempty" json:"requestURL,omitempty"`
	StatusCode    int                          `xml:"statusCode,omitempty" json:"statusCode,omitempty"`
	StatusString  string                       `xml:"statusString,omitempty" json:"statusString,omitempty"`
	ID            int                          `xml:"id,omitempty" json:"id,omitempty"`
	SubStatusCode string                       `xml:"subStatusCode,omitempty" json:"subStatusCode,omitempty"`
	ErrorCode     int                          `xml:"errorCode,omitempty" json:"errorCode,omitempty"`
	ErrorMsg      string                       `xml:"errorMsg,omitempty" json:"errorMsg,omitempty"`
	AdditionalErr *ResponseStatusAdditionalErr `xml:"AdditionalErr,omitempty" json:"AdditionalErr,omitempty"`
}

ResponseStatus represents the XML_ResponseStatus and JSON_ResponseStatus resource.

type ResponseStatusAdditionalErr

type ResponseStatusAdditionalErr struct {
	StatusList []ResponseStatusAdditionalErrStatus `xml:"StatusList,omitempty" json:"StatusList,omitempty"`
}

ResponseStatusAdditionalErr represents the additional error status, which is valid when StatusCode is set to 9.

type ResponseStatusAdditionalErrStatus

type ResponseStatusAdditionalErrStatus struct {
	Status string `xml:"Status,omitempty" json:"Status,omitempty"`
}

ResponseStatusAdditionalErrStatus represents a single status information.

type ResponseStatusAdditionalErrStatusInfo

type ResponseStatusAdditionalErrStatusInfo struct {
	ID            string `xml:"id,omitempty" json:"id,omitempty"`
	StatusCode    int    `xml:"statusCode,omitempty" json:"statusCode,omitempty"`
	StatusString  string `xml:"statusString,omitempty" json:"statusString,omitempty"`
	SubStatusCode string `xml:"subStatusCode,omitempty" json:"subStatusCode,omitempty"`
	ErrorCode     int    `xml:"errorCode,omitempty" json:"errorCode,omitempty"`
	ErrorMsg      string `xml:"errorMsg,omitempty" json:"errorMsg,omitempty"`
}

ResponseStatusAdditionalErrStatusInfo represents information of status.

type Time

type Time struct {
	XMLName           xml.Name `xml:"Time,omitempty"`
	XMLVersion        string   `xml:"version,attr"`
	XMLNamespace      string   `xml:"xmlns,attr"`
	TimeMode          string   `xml:"timeMode,omitempty" json:"timeMode,omitempty"`
	LocalTime         string   `xml:"localTime,omitempty" json:"localTime,omitempty"`
	TimeZone          string   `xml:"timeZone,omitempty" json:"timeZone,omitempty"`
	SatelliteInterval string   `xml:"satelliteInterval,omitempty" json:"satelliteInterval,omitempty"`
}

Time represents the XML_Time and JSON_Time resource.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL