Refactor XML response handling in device extended and security tests

- Adjusted formatting in XML response strings for consistency in device_extended_test.go and device_security_test.go.
- Improved readability by aligning XML declaration and body content.
- Updated mock server responses to ensure proper handling of various ONVIF operations.

Enhance device security and storage handling

- Refactored struct field declarations in device_security.go and device_storage_test.go for improved clarity.
- Ensured consistent formatting across struct definitions and XML tags.

Standardize whitespace and formatting across multiple files

- Removed unnecessary blank lines and adjusted indentation in discovery, imaging, media, and PTZ server files.
- Improved overall code readability and maintainability by ensuring consistent formatting.

Update example applications for better readability

- Cleaned up whitespace in example applications to enhance code clarity.
- Ensured consistent formatting in main.go files across various examples.

Refactor server and SOAP handler code for consistency

- Standardized struct field declarations and XML tag formatting in server and SOAP handler files.
- Improved readability by aligning struct fields and ensuring consistent use of whitespace.

General code cleanup and formatting adjustments

- Applied consistent formatting across various files, including types.go and test files.
- Enhanced readability by aligning struct fields and removing unnecessary blank lines.
This commit is contained in:
ProtoTess
2025-12-01 00:49:36 +00:00
parent 856f49c82d
commit b4e4982876
37 changed files with 318 additions and 322 deletions
+12 -12
View File
@@ -45,10 +45,10 @@ type AnalyticsCapabilities struct {
// DeviceCapabilities represents device service capabilities
type DeviceCapabilities struct {
XAddr string `xml:"XAddr"`
Network *NetworkCapabilities `xml:"Network,omitempty"`
System *SystemCapabilities `xml:"System,omitempty"`
IO *IOCapabilities `xml:"IO,omitempty"`
XAddr string `xml:"XAddr"`
Network *NetworkCapabilities `xml:"Network,omitempty"`
System *SystemCapabilities `xml:"System,omitempty"`
IO *IOCapabilities `xml:"IO,omitempty"`
Security *SecurityCapabilities `xml:"Security,omitempty"`
}
@@ -62,12 +62,12 @@ type NetworkCapabilities struct {
// SystemCapabilities represents system capabilities
type SystemCapabilities struct {
DiscoveryResolve bool `xml:"DiscoveryResolve,attr"`
DiscoveryBye bool `xml:"DiscoveryBye,attr"`
RemoteDiscovery bool `xml:"RemoteDiscovery,attr"`
SystemBackup bool `xml:"SystemBackup,attr"`
SystemLogging bool `xml:"SystemLogging,attr"`
FirmwareUpgrade bool `xml:"FirmwareUpgrade,attr"`
DiscoveryResolve bool `xml:"DiscoveryResolve,attr"`
DiscoveryBye bool `xml:"DiscoveryBye,attr"`
RemoteDiscovery bool `xml:"RemoteDiscovery,attr"`
SystemBackup bool `xml:"SystemBackup,attr"`
SystemLogging bool `xml:"SystemLogging,attr"`
FirmwareUpgrade bool `xml:"FirmwareUpgrade,attr"`
}
// IOCapabilities represents I/O capabilities
@@ -127,8 +127,8 @@ type GetServicesResponse struct {
// Service represents a service
type Service struct {
Namespace string `xml:"Namespace"`
XAddr string `xml:"XAddr"`
Namespace string `xml:"Namespace"`
XAddr string `xml:"XAddr"`
Version Version `xml:"Version"`
}
+20 -20
View File
@@ -42,18 +42,18 @@ type BacklightCompensationSettings struct {
// ExposureSettings20 represents exposure settings for ONVIF 2.0
type ExposureSettings20 struct {
Mode string `xml:"Mode"`
Priority *string `xml:"Priority,omitempty"`
Mode string `xml:"Mode"`
Priority *string `xml:"Priority,omitempty"`
Window *Rectangle `xml:"Window,omitempty"`
MinExposureTime *float64 `xml:"MinExposureTime,omitempty"`
MaxExposureTime *float64 `xml:"MaxExposureTime,omitempty"`
MinGain *float64 `xml:"MinGain,omitempty"`
MaxGain *float64 `xml:"MaxGain,omitempty"`
MinIris *float64 `xml:"MinIris,omitempty"`
MaxIris *float64 `xml:"MaxIris,omitempty"`
ExposureTime *float64 `xml:"ExposureTime,omitempty"`
Gain *float64 `xml:"Gain,omitempty"`
Iris *float64 `xml:"Iris,omitempty"`
MinExposureTime *float64 `xml:"MinExposureTime,omitempty"`
MaxExposureTime *float64 `xml:"MaxExposureTime,omitempty"`
MinGain *float64 `xml:"MinGain,omitempty"`
MaxGain *float64 `xml:"MaxGain,omitempty"`
MinIris *float64 `xml:"MinIris,omitempty"`
MaxIris *float64 `xml:"MaxIris,omitempty"`
ExposureTime *float64 `xml:"ExposureTime,omitempty"`
Gain *float64 `xml:"Gain,omitempty"`
Iris *float64 `xml:"Iris,omitempty"`
}
// FocusConfiguration20 represents focus configuration for ONVIF 2.0
@@ -168,15 +168,15 @@ type WhiteBalanceOptions struct {
// MoveRequest represents Move (focus) request
type MoveRequest struct {
XMLName xml.Name `xml:"http://www.onvif.org/ver20/imaging/wsdl Move"`
VideoSourceToken string `xml:"VideoSourceToken"`
Focus *FocusMove `xml:"Focus"`
XMLName xml.Name `xml:"http://www.onvif.org/ver20/imaging/wsdl Move"`
VideoSourceToken string `xml:"VideoSourceToken"`
Focus *FocusMove `xml:"Focus"`
}
// FocusMove represents focus move parameters
type FocusMove struct {
Absolute *AbsoluteFocus `xml:"Absolute,omitempty"`
Relative *RelativeFocus `xml:"Relative,omitempty"`
Absolute *AbsoluteFocus `xml:"Absolute,omitempty"`
Relative *RelativeFocus `xml:"Relative,omitempty"`
Continuous *ContinuousFocus `xml:"Continuous,omitempty"`
}
@@ -342,10 +342,10 @@ func (s *Server) HandleSetImagingSettings(body interface{}) (interface{}, error)
func (s *Server) HandleGetOptions(body interface{}) (interface{}, error) {
// Return available imaging options/capabilities
options := &ImagingOptions{
Brightness: &FloatRange{Min: 0, Max: 100},
ColorSaturation: &FloatRange{Min: 0, Max: 100},
Contrast: &FloatRange{Min: 0, Max: 100},
Sharpness: &FloatRange{Min: 0, Max: 100},
Brightness: &FloatRange{Min: 0, Max: 100},
ColorSaturation: &FloatRange{Min: 0, Max: 100},
Contrast: &FloatRange{Min: 0, Max: 100},
Sharpness: &FloatRange{Min: 0, Max: 100},
IrCutFilterModes: []string{"ON", "OFF", "AUTO"},
BacklightCompensation: &BacklightCompensationOptions{
Mode: []string{"OFF", "ON"},
+11 -11
View File
@@ -9,7 +9,7 @@ import (
// GetProfilesResponse represents GetProfiles response
type GetProfilesResponse struct {
XMLName xml.Name `xml:"http://www.onvif.org/ver10/media/wsdl GetProfilesResponse"`
XMLName xml.Name `xml:"http://www.onvif.org/ver10/media/wsdl GetProfilesResponse"`
Profiles []MediaProfile `xml:"Profiles"`
}
@@ -46,16 +46,16 @@ type AudioSourceConfiguration struct {
// VideoEncoderConfiguration represents video encoder configuration
type VideoEncoderConfiguration struct {
Token string `xml:"token,attr"`
Name string `xml:"Name"`
UseCount int `xml:"UseCount"`
Encoding string `xml:"Encoding"`
Resolution VideoResolution `xml:"Resolution"`
Quality float64 `xml:"Quality"`
RateControl *VideoRateControl `xml:"RateControl,omitempty"`
H264 *H264Configuration `xml:"H264,omitempty"`
Token string `xml:"token,attr"`
Name string `xml:"Name"`
UseCount int `xml:"UseCount"`
Encoding string `xml:"Encoding"`
Resolution VideoResolution `xml:"Resolution"`
Quality float64 `xml:"Quality"`
RateControl *VideoRateControl `xml:"RateControl,omitempty"`
H264 *H264Configuration `xml:"H264,omitempty"`
Multicast *MulticastConfiguration `xml:"Multicast,omitempty"`
SessionTimeout string `xml:"SessionTimeout"`
SessionTimeout string `xml:"SessionTimeout"`
}
// AudioEncoderConfiguration represents audio encoder configuration
@@ -130,7 +130,7 @@ type MulticastConfiguration struct {
// IPAddress represents an IP address
type IPAddress struct {
Type string `xml:"Type"`
Type string `xml:"Type"`
IPv4Address string `xml:"IPv4Address,omitempty"`
IPv6Address string `xml:"IPv6Address,omitempty"`
}
+9 -9
View File
@@ -75,9 +75,9 @@ type GetStatusResponse struct {
// PTZStatus represents PTZ status
type PTZStatus struct {
Position PTZVector `xml:"Position"`
MoveStatus PTZMoveStatus `xml:"MoveStatus"`
UTCTime string `xml:"UtcTime"`
Position PTZVector `xml:"Position"`
MoveStatus PTZMoveStatus `xml:"MoveStatus"`
UTCTime string `xml:"UtcTime"`
}
// PTZMoveStatus represents PTZ movement status
@@ -113,7 +113,7 @@ type GetPresetsRequest struct {
// GetPresetsResponse represents GetPresets response
type GetPresetsResponse struct {
XMLName xml.Name `xml:"http://www.onvif.org/ver20/ptz/wsdl GetPresetsResponse"`
XMLName xml.Name `xml:"http://www.onvif.org/ver20/ptz/wsdl GetPresetsResponse"`
Preset []PTZPreset `xml:"Preset"`
}
@@ -153,16 +153,16 @@ type SetPresetResponse struct {
// GetConfigurationsResponse represents GetConfigurations response
type GetConfigurationsResponse struct {
XMLName xml.Name `xml:"http://www.onvif.org/ver20/ptz/wsdl GetConfigurationsResponse"`
XMLName xml.Name `xml:"http://www.onvif.org/ver20/ptz/wsdl GetConfigurationsResponse"`
PTZConfiguration []PTZConfigurationExt `xml:"PTZConfiguration"`
}
// PTZConfigurationExt represents PTZ configuration with extensions
type PTZConfigurationExt struct {
Token string `xml:"token,attr"`
Name string `xml:"Name"`
UseCount int `xml:"UseCount"`
NodeToken string `xml:"NodeToken"`
Token string `xml:"token,attr"`
Name string `xml:"Name"`
UseCount int `xml:"UseCount"`
NodeToken string `xml:"NodeToken"`
PanTiltLimits *PanTiltLimits `xml:"PanTiltLimits,omitempty"`
ZoomLimits *ZoomLimits `xml:"ZoomLimits,omitempty"`
}
+5 -5
View File
@@ -27,14 +27,14 @@ func New(config *Config) (*Server, error) {
for i := range config.Profiles {
profile := &config.Profiles[i]
streamPath := fmt.Sprintf("/stream%d", i)
host := config.Host
if host == "0.0.0.0" || host == "" {
host = "localhost"
}
streamURI := fmt.Sprintf("rtsp://%s:8554%s", host, streamPath)
server.streams[profile.Token] = &StreamConfig{
ProfileToken: profile.Token,
RTSPPath: streamPath,
@@ -104,11 +104,11 @@ func (s *Server) Start(ctx context.Context) error {
// Register service handlers
s.registerDeviceService(mux)
s.registerMediaService(mux)
if s.config.SupportPTZ {
s.registerPTZService(mux)
}
if s.config.SupportImaging {
s.registerImagingService(mux)
}
+7 -7
View File
@@ -130,7 +130,7 @@ func (h *Handler) extractAction(bodyXML []byte) string {
decoder := xml.NewDecoder(bytes.NewReader(bodyXML))
inBody := false
depth := 0
for {
token, err := decoder.Token()
if err != nil {
@@ -241,17 +241,17 @@ type GetSystemDateAndTimeRequest struct {
// GetSystemDateAndTimeResponse represents GetSystemDateAndTime response
type GetSystemDateAndTimeResponse struct {
XMLName xml.Name `xml:"http://www.onvif.org/ver10/device/wsdl GetSystemDateAndTimeResponse"`
XMLName xml.Name `xml:"http://www.onvif.org/ver10/device/wsdl GetSystemDateAndTimeResponse"`
SystemDateAndTime SystemDateAndTime `xml:"SystemDateAndTime"`
}
// SystemDateAndTime represents system date and time
type SystemDateAndTime struct {
DateTimeType string `xml:"DateTimeType"`
DaylightSavings bool `xml:"DaylightSavings"`
TimeZone TimeZone `xml:"TimeZone,omitempty"`
UTCDateTime DateTime `xml:"UTCDateTime,omitempty"`
LocalDateTime DateTime `xml:"LocalDateTime,omitempty"`
DateTimeType string `xml:"DateTimeType"`
DaylightSavings bool `xml:"DaylightSavings"`
TimeZone TimeZone `xml:"TimeZone,omitempty"`
UTCDateTime DateTime `xml:"UTCDateTime,omitempty"`
LocalDateTime DateTime `xml:"LocalDateTime,omitempty"`
}
// TimeZone represents timezone information
+10 -10
View File
@@ -88,15 +88,15 @@ type AudioEncoderConfig struct {
// PTZConfig represents PTZ configuration
type PTZConfig struct {
NodeToken string // PTZ node token
PanRange Range // Pan range in degrees
TiltRange Range // Tilt range in degrees
ZoomRange Range // Zoom range
DefaultSpeed PTZSpeed // Default speed
NodeToken string // PTZ node token
PanRange Range // Pan range in degrees
TiltRange Range // Tilt range in degrees
ZoomRange Range // Zoom range
DefaultSpeed PTZSpeed // Default speed
SupportsContinuous bool // Supports continuous move
SupportsAbsolute bool // Supports absolute move
SupportsRelative bool // Supports relative move
Presets []Preset // Predefined presets
Presets []Preset // Predefined presets
}
// SnapshotConfig represents snapshot configuration
@@ -195,8 +195,8 @@ type BacklightCompensation struct {
// ExposureSettings represents exposure settings
type ExposureSettings struct {
Mode string // AUTO, MANUAL
Priority string // LowNoise, FrameRate
Mode string // AUTO, MANUAL
Priority string // LowNoise, FrameRate
MinExposure float64
MaxExposure float64
MinGain float64
@@ -207,7 +207,7 @@ type ExposureSettings struct {
// FocusSettings represents focus settings
type FocusSettings struct {
AutoFocusMode string // AUTO, MANUAL
AutoFocusMode string // AUTO, MANUAL
DefaultSpeed float64
NearLimit float64
FarLimit float64
@@ -216,7 +216,7 @@ type FocusSettings struct {
// WhiteBalanceSettings represents white balance settings
type WhiteBalanceSettings struct {
Mode string // AUTO, MANUAL
Mode string // AUTO, MANUAL
CrGain float64
CbGain float64
}