package onvif import ( "bytes" "fmt" "regexp" "strconv" "time" ) const ( ActionGetCapabilities = "GetCapabilities" ActionGetSystemDateAndTime = "GetSystemDateAndTime" ActionGetNetworkInterfaces = "GetNetworkInterfaces" ActionGetDeviceInformation = "GetDeviceInformation" ActionGetServiceCapabilities = "GetServiceCapabilities" ActionGetProfiles = "GetProfiles" ActionGetStreamUri = "GetStreamUri" ActionSystemReboot = "SystemReboot" ActionGetServices = "GetServices" ActionGetScopes = "GetScopes" ActionGetVideoSources = "GetVideoSources" ActionGetAudioSources = "GetAudioSources" ActionGetVideoSourceConfigurations = "GetVideoSourceConfigurations" ActionGetAudioSourceConfigurations = "GetAudioSourceConfigurations" ActionGetVideoEncoderConfigurations = "GetVideoEncoderConfigurations" ActionGetAudioEncoderConfigurations = "GetAudioEncoderConfigurations" ) func GetRequestAction(b []byte) string { // // re := regexp.MustCompile(`Body[^<]+<([^ />]+)`) m := re.FindSubmatch(b) if len(m) != 2 { return "" } if i := bytes.IndexByte(m[1], ':'); i > 0 { return string(m[1][i+1:]) } return string(m[1]) } func GetCapabilitiesResponse(host string) string { return ` http://` + host + `/onvif/device_service http://` + host + `/onvif/media_service false false true ` } func GetSystemDateAndTimeResponse() string { loc := time.Now() utc := loc.UTC() return fmt.Sprintf(` NTP false GMT%s %d %d %d %d %d %d %d %d %d %d %d %d `, loc.Format("-07:00"), utc.Hour(), utc.Minute(), utc.Second(), utc.Year(), utc.Month(), utc.Day(), loc.Hour(), loc.Minute(), loc.Second(), loc.Year(), loc.Month(), loc.Day(), ) } func GetNetworkInterfacesResponse() string { return ` ` } func GetDeviceInformationResponse(manuf, model, firmware, serial string) string { return ` ` + manuf + ` ` + model + ` ` + firmware + ` ` + serial + ` 1.00 ` } func GetServiceCapabilitiesResponse() string { return ` ` } func SystemRebootResponse() string { return ` system reboot in 1 second... ` } func GetProfilesResponse(names []string) string { buf := bytes.NewBuffer(nil) buf.WriteString(` `) for i, name := range names { buf.WriteString(` ` + name + ` H264 1920 1080 `) } buf.WriteString(` `) return buf.String() } func GetStreamUriResponse(uri string) string { return ` ` + uri + ` ` }