You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

677 lines
26 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
​
​
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6) 1. Faults are no longer reported as success: every request waits for the answer, checks the HTTP status and the SOAP Fault (logged with Code/Subcode/Reason); getLastError()/getLastFault() tell the caller. protocolPTZ_ONVIF clears m_bStatus (-> reconnect) only on communication errors, not on a Fault from a reachable camera. AbsoluteMove now waits for its answer too. 2. Request/reply race: already fixed in #11 (checked). 3. NULL-safe parsing of optional elements (safeCopy/safeAtoi/safeAtof), videoSource zero-filled, Imaging values parsed as float, IrCutFilter AUTO no longer read as OFF, missing XAddr no longer becomes "(null)", GetSystemDateAndTime without UTCDateTime no longer breaks the token time (falls back to the local clock). 4. GetProfiles parses PTZConfiguration; the PTZ profile is the first one that has it (fallback to profile 0 with an error log); create() fails cleanly when the device has no profiles instead of throwing. 5. Pan/tilt and zoom in one ContinuousMove with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); Stop honours its pantilt/zoom flags. 6. WS-Security: 16-byte RAND_bytes nonce, no fixed-size digest buffer, header only when a user name is set (anonymous devices), user name and all string arguments XML-escaped. Requests are built by _buildRequest() from body templates. HTTP auth mode 0 now uses CURLAUTH_ANY (sends no password until the device asks; Digest preferred) instead of Basic; no HTTP auth without credentials. Also: Content-Type without the trailing ';', GetServices/ GetDeviceInformation sent to the device service, printf format-string bugs on device replies fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
6 days ago
​
​
​
​
​
​
​
​
  1. #ifndef __PONVIF_CLASS_HEADER__
  2. #define __PONVIF_CLASS_HEADER__
  3. // Based on PHP Onvif library
  4. #include <curl/curl.h>
  5. #include <openssl/sha.h>
  6. #include <vector>
  7. #ifdef __linux__
  8. #include <arpa/inet.h>
  9. #include <netdb.h>
  10. #include <netinet/in.h>
  11. #include <pthread.h>
  12. #include <sys/socket.h>
  13. #include <unistd.h>
  14. #endif
  15. #include "../../alg/generic/base64.h"
  16. #include "../../components/base/basicLogCollection.h"
  17. #include "../../components/base/basicTypes.h"
  18. #include "../curl/curlRequestsManager.h"
  19. #include "../protocol/xmlParser.h"
  20. #define CURL_MANAGER
  21. // #define DEBUG_ONVIF_PRINTOUT_MESSAGES
  22. // #define DEBUG_ONVIF_TRAFFIC
  23. #define PONVIF_DEFAULT_DISCOVERYBINDIP (CSTR) "0.0.0.0"
  24. #define PONVIF_DEFAULT_DISCOVERYMCASTIP (CSTR) "239.255.255.250"
  25. #define PONVIF_DEFAULT_DISCOVERYMCASTPORT 3702
  26. #define PONVIF_DEFAULT_DISCOVERYTIMEOUT 12
  27. #define PONVIF_PACK_DISCOVERY \
  28. (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\"><s:Header><w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID><w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></s:Header><s:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></s:Body></s:Envelope>"
  29. #define PONVIF_PACK_GET_SYS_DTS \
  30. (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><GetSystemDateAndTime xmlns=\"http://www.onvif.org/ver10/device/wsdl\"/></s:Body></s:Envelope>"
  31. /*
  32. Request bodies (the SOAP envelope and the optional WS-Security header are added by pOnvif::_buildRequest).
  33. String arguments must be XML-escaped by the caller (pOnvif::_xmlEscape).
  34. */
  35. #define PONVIF_NS_DEVICE "http://www.onvif.org/ver10/device/wsdl"
  36. #define PONVIF_NS_MEDIA "http://www.onvif.org/ver10/media/wsdl"
  37. #define PONVIF_NS_PTZ "http://www.onvif.org/ver20/ptz/wsdl"
  38. #define PONVIF_NS_SCHEMA "http://www.onvif.org/ver10/schema"
  39. #define PONVIF_BODY_GET_CAPABILITIES "<GetCapabilities xmlns=\"" PONVIF_NS_DEVICE "\"><Category>All</Category></GetCapabilities>"
  40. #define PONVIF_BODY_GET_SERVICES "<GetServices xmlns=\"" PONVIF_NS_DEVICE "\"><IncludeCapability>false</IncludeCapability></GetServices>"
  41. #define PONVIF_BODY_GET_DEV_INFO "<GetDeviceInformation xmlns=\"" PONVIF_NS_DEVICE "\"/>"
  42. #define PONVIF_BODY_GET_VIDEO_SOURCES "<GetVideoSources xmlns=\"" PONVIF_NS_MEDIA "\"/>"
  43. #define PONVIF_BODY_GET_PROFILES "<GetProfiles xmlns=\"" PONVIF_NS_MEDIA "\"/>"
  44. #define PONVIF_BODY_GET_STREAM_URI \
  45. "<GetStreamUri xmlns=\"" PONVIF_NS_MEDIA "\"><StreamSetup><Stream xmlns=\"" PONVIF_NS_SCHEMA "\">%s</Stream><Transport xmlns=\"" PONVIF_NS_SCHEMA \
  46. "\"><Protocol>%s</Protocol></Transport></StreamSetup><ProfileToken>%s</ProfileToken></GetStreamUri>"
  47. #define PONVIF_BODY_GET_SNAPSHOT_URI "<GetSnapshotUri xmlns=\"" PONVIF_NS_MEDIA "\"><ProfileToken>%s</ProfileToken></GetSnapshotUri>"
  48. #define PONVIF_BODY_PTZ_GET_SERVICE_CAPS "<GetServiceCapabilities xmlns=\"" PONVIF_NS_PTZ "\"/>"
  49. #define PONVIF_BODY_GET_PRESETS "<GetPresets xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken></GetPresets>"
  50. #define PONVIF_BODY_GET_PTZ_NODE "<GetNode xmlns=\"" PONVIF_NS_PTZ "\"><NodeToken>%s</NodeToken></GetNode>"
  51. #define PONVIF_BODY_GET_PTZ_STATUS "<GetStatus xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken></GetStatus>"
  52. #define PONVIF_BODY_GOTO_PRESET \
  53. "<GotoPreset xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PresetToken>%s</PresetToken><Speed><PanTilt x=\"%0.3f\" y=\"%0.3f\" xmlns=\"" PONVIF_NS_SCHEMA \
  54. "\"/><Zoom x=\"%0.3f\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Speed></GotoPreset>"
  55. #define PONVIF_BODY_REMOVE_PRESET "<RemovePreset xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PresetToken>%s</PresetToken></RemovePreset>"
  56. #define PONVIF_BODY_SET_PRESET "<SetPreset xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PresetName>%s</PresetName></SetPreset>"
  57. #define PONVIF_BODY_RELATIVE_MOVE \
  58. "<RelativeMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Translation><PanTilt x=\"%0.4f\" y=\"%0.4f\" " \
  59. "space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Translation><Speed><PanTilt " \
  60. "x=\"%0.3f\" y=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/GenericSpeedSpace\" xmlns=\"" PONVIF_NS_SCHEMA \
  61. "\"/></Speed></RelativeMove>"
  62. #define PONVIF_BODY_RELATIVE_ZOOM \
  63. "<RelativeMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Translation><Zoom x=\"%0.4f\" xmlns=\"" PONVIF_NS_SCHEMA \
  64. "\"/></Translation><Speed><Zoom x=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/ZoomGenericSpeedSpace\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Speed></RelativeMove>"
  65. #define PONVIF_BODY_ABSOLUTE_MOVE \
  66. "<AbsoluteMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Position><PanTilt x=\"%0.6f\" y=\"%0.6f\" xmlns=\"" PONVIF_NS_SCHEMA \
  67. "\"/><Zoom x=\"%0.6f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA \
  68. "\"/></Position><Speed><PanTilt x=\"%0.4f\" y=\"%0.4f\" space=\"%s\" xmlns=\"" PONVIF_NS_SCHEMA "\"/><Zoom x=\"%0.4f\" space=\"%s\" xmlns=\"" PONVIF_NS_SCHEMA \
  69. "\"/></Speed></AbsoluteMove>"
  70. // Generic speed spaces (ONVIF PTZ spec: every node with configurable speed provides them, range 0..1).
  71. // The speed of an AbsoluteMove is sent in these spaces (or in the node's own speed space, see ptzSpeedSpace).
  72. // Without a space attribute, a device interprets the value in its own default speed space (the one of
  73. // the PTZConfiguration's DefaultPTZSpeed): there "1" can be a slow speed.
  74. #define PONVIF_SPACE_PT_GENERIC_SPEED "http://www.onvif.org/ver10/tptz/PanTiltSpaces/GenericSpeedSpace"
  75. #define PONVIF_SPACE_ZOOM_GENERIC_SPEED "http://www.onvif.org/ver10/tptz/ZoomSpaces/ZoomGenericSpeedSpace"
  76. // ContinuousMove is assembled from these parts (pan/tilt and zoom in one request)
  77. #define PONVIF_BODY_CONTINUOUS_MOVE_BEGIN "<ContinuousMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Velocity>"
  78. #define PONVIF_BODY_CONTINUOUS_MOVE_PT \
  79. "<PanTilt x=\"%0.3f\" y=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace\" xmlns=\"" \
  80. PONVIF_NS_SCHEMA "\"/>"
  81. #define PONVIF_BODY_CONTINUOUS_MOVE_ZOOM \
  82. "<Zoom x=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA "\"/>"
  83. #define PONVIF_BODY_CONTINUOUS_MOVE_END "</Velocity><Timeout>PT%dS</Timeout></ContinuousMove>"
  84. #define PONVIF_BODY_PTZ_STOP "<Stop xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PanTilt>%s</PanTilt><Zoom>%s</Zoom></Stop>"
  85. // Default ContinuousMove timeout: the camera stops by itself if the Stop request is lost
  86. #define PONVIF_CONTINUOUS_MOVE_TIMEOUT_S 10
  87. // WS-Security nonce length (bytes before Base64)
  88. #define PONVIF_NONCE_LEN 16
  89. #define PONVIF_ENVELOPE_EXT \
  90. (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><e:Envelope xmlns:e=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\">%s%s</e:Envelope>"
  91. #define PONVIF_ENVELOPE_SIM (CSTR) "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">%s%s</s:Envelope>"
  92. #define PONVIF_BODY (CSTR) "<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">%s</s:Body>"
  93. #define PONVIF_HEADER_PROBE \
  94. (CSTR)"<e:Header><w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID><w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To><w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action></e:Header>"
  95. #define PONVIF_HEADER_SECUR \
  96. (CSTR)"<s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header>"
  97. #define PONVIF_PCK_GET_CAPABILITIES (CSTR) "<GetCapabilities xmlns=\"http://www.onvif.org/ver10/device/wsdl\"><Category>All</Category></GetCapabilities>"
  98. typedef struct S_videoSourceProfile
  99. {
  100. char sourcetoken[CTEXT];
  101. char profiletoken[CTEXT];
  102. char profilename[CTEXT];
  103. char encoding[16];
  104. int width;
  105. int height;
  106. int fps;
  107. int bitrate;
  108. bool ptz; // profile has a PTZConfiguration (PTZ commands need such a profile)
  109. char ptznodetoken[CTEXT]; // PTZConfiguration/NodeToken
  110. } videoSourceProfile;
  111. // A speed space of the PTZ node (GetNode -> SupportedPTZSpaces/PanTiltSpeedSpace | ZoomSpeedSpace)
  112. typedef struct S_ptzSpeedSpace
  113. {
  114. char uri[CTEXT];
  115. float min;
  116. float max;
  117. bool valid; // read from the device
  118. } ptzSpeedSpace;
  119. // Result of the last request (pOnvif::getLastError)
  120. typedef enum E_onvifError
  121. {
  122. PONVIF_OK = 0,
  123. PONVIF_ERR_COMM, // no answer: connection error, timeout, request could not be queued
  124. PONVIF_ERR_HTTP, // HTTP status other than 200 without a SOAP Fault (e.g. 401 HTML page)
  125. PONVIF_ERR_FAULT, // the device answered with a SOAP Fault (see getLastFault)
  126. PONVIF_ERR_PARSE // reply is not the expected XML
  127. } onvifError;
  128. typedef struct S_onvifVideoResolution
  129. {
  130. int Width;
  131. int Height;
  132. } onvifVideoResolution;
  133. typedef struct S_onvifBacklightCompensation
  134. {
  135. bool Mode;
  136. float Level;
  137. } onvifBacklightCompensation;
  138. typedef enum E_onvifExposurePriority
  139. {
  140. LowNoise = 0,
  141. FrameRate
  142. } onvifExposurePriority;
  143. typedef struct S_onvifRectangle
  144. {
  145. int x;
  146. int y;
  147. int width;
  148. int height;
  149. } onvifRectangle;
  150. typedef struct S_onvifExposure
  151. {
  152. bool Mode;
  153. onvifExposurePriority Priority;
  154. onvifRectangle Window;
  155. float MinExposureTime;
  156. float MaxExposureTime;
  157. float MinGain;
  158. float MaxGain;
  159. float MinIris;
  160. float MaxIris;
  161. float ExposureTime;
  162. float Gain;
  163. float Iris;
  164. } onvifExposure;
  165. typedef enum E_onvifOnOffAuto
  166. {
  167. ON = 0,
  168. OFF,
  169. AUTO
  170. } onvifOnOffAuto;
  171. typedef struct S_onvifFocusConfiguration
  172. {
  173. bool AutoFocusMode;
  174. float DefaultSpeed;
  175. float NearLimit;
  176. float FarLimit;
  177. } onvifFocusConfiguration;
  178. typedef struct S_onvifWideDynamicRange
  179. {
  180. bool Mode;
  181. float Level;
  182. } onvifWideDynamicRange;
  183. typedef struct S_onvifWhiteBalanceExtension
  184. {
  185. } onvifWhiteBalanceExtension;
  186. typedef struct S_onvifWhiteBalance
  187. {
  188. bool Mode;
  189. float CrGain;
  190. float CbGain;
  191. onvifWhiteBalanceExtension * Extension;
  192. } onvifWhiteBalance;
  193. typedef struct S_onvifImagingSettingsExtension
  194. {
  195. } onvifImagingSettingsExtension;
  196. typedef struct S_onvifImagingSettings
  197. {
  198. onvifBacklightCompensation * BacklightCompensation;
  199. float Brightness;
  200. float ColorSaturation;
  201. float Contrast;
  202. onvifExposure * Exposure;
  203. onvifFocusConfiguration * Focus;
  204. onvifOnOffAuto IrCutFilter;
  205. float Sharpness;
  206. onvifWideDynamicRange * WideDynamicRange;
  207. onvifWhiteBalance * WhiteBalance;
  208. onvifImagingSettingsExtension * Extension;
  209. } onvifImagingSettings;
  210. typedef struct S_onvifVideoSourceExtension
  211. {
  212. onvifImagingSettings * Imaging;
  213. } onvifVideoSourceExtension;
  214. typedef struct S_onvifVideoSource
  215. {
  216. char token[CTEXT];
  217. float Framerate;
  218. onvifVideoResolution Resolution;
  219. onvifImagingSettings * Imaging;
  220. onvifVideoSourceExtension * Extension;
  221. } videoSource;
  222. typedef struct S_onvifSupportedVersions
  223. {
  224. int Major;
  225. int Minor;
  226. } onvifSupportedVersions;
  227. typedef struct S_onvifNetworkCapabilitiesExtension2
  228. {
  229. } onvifNetworkCapabilitiesExtension2;
  230. typedef struct S_onvifNetworkCapabilitiesExtension
  231. {
  232. bool Dot11Configuration;
  233. onvifNetworkCapabilitiesExtension2 * Extension;
  234. } onvifNetworkCapabilitiesExtension;
  235. typedef struct S_onvifNetworkCapabilities
  236. {
  237. bool IPFilter;
  238. bool ZeroConfiguration;
  239. bool IPVersion6;
  240. bool DynDNS;
  241. onvifNetworkCapabilitiesExtension * Extension;
  242. } onvifNetworkCapabilities;
  243. typedef struct S_onvifIOCapabilitiesExtension2
  244. {
  245. } onvifIOCapabilitiesExtension2;
  246. typedef struct S_onvifIOAuxiliaryData
  247. {
  248. } onvifIOAuxiliaryData;
  249. typedef struct S_onvifIOCapabilitiesExtension
  250. {
  251. bool Auxiliary;
  252. onvifIOAuxiliaryData * AuxiliaryCommands;
  253. onvifIOCapabilitiesExtension2 * Extension;
  254. } onvifIOCapabilitiesExtension;
  255. typedef struct S_onvifIOCapabilities
  256. {
  257. int InputConnectors;
  258. int RelayOutputs;
  259. onvifIOCapabilitiesExtension * Extension;
  260. } onvifIOCapabilities;
  261. typedef struct S_onvifSecurityCapabilitiesExtension2
  262. {
  263. bool Dot1X;
  264. int SupportedEAPMethod;
  265. bool RemoteUserHandling;
  266. } onvifSecurityCapabilitiesExtension2;
  267. typedef struct S_onvifSecurityCapabilitiesExtension
  268. {
  269. bool TLS1_0;
  270. onvifSecurityCapabilitiesExtension2 * Extension;
  271. } onvifSecurityCapabilitiesExtension;
  272. typedef struct S_onvifSecurityCapabilities
  273. {
  274. bool TLS1_1;
  275. bool TLS1_2;
  276. bool OnboardKeyGeneration;
  277. bool AccessPolicyConfig;
  278. bool X_509Token;
  279. bool SAMLToken;
  280. bool KerberosToken;
  281. bool RELToken;
  282. onvifSecurityCapabilitiesExtension * Extension;
  283. } onvifSecurityCapabilities;
  284. typedef struct S_onvifSystemCapabilitiesExtension2
  285. {
  286. } onvifSystemCapabilitiesExtension2;
  287. typedef struct S_onvifSystemCapabilitiesExtension
  288. {
  289. bool HttpFirmwareUpgrade;
  290. bool HttpSystemBackup;
  291. bool HttpSystemLogging;
  292. bool HttpSupportInformation;
  293. onvifSystemCapabilitiesExtension2 * Extension;
  294. } onvifSystemCapabilitiesExtension;
  295. typedef struct S_onvifSystemCapabilities
  296. {
  297. bool DiscoveryResolve;
  298. bool DiscoveryBye;
  299. bool RemoteDiscovery;
  300. bool SystemBackup;
  301. bool SystemLogging;
  302. bool FirmwareUpgrade;
  303. onvifSupportedVersions * SupportedVersions;
  304. onvifSystemCapabilitiesExtension * Extension;
  305. } onvifSystemCapabilities;
  306. typedef struct S_onvifDeviceCapabilitiesExtension
  307. {
  308. } onvifDeviceCapabilitiesExtension;
  309. typedef struct S_onvifAnalyticsCapabilities
  310. {
  311. char XAddr[CTEXT];
  312. bool RuleSupport;
  313. bool AnalyticsModuleSupport;
  314. } onvifAnalyticsCapabilities;
  315. typedef struct S_onvifDeviceCapabilities
  316. {
  317. char XAddr[CTEXT];
  318. onvifNetworkCapabilities * Network;
  319. onvifSystemCapabilities * System;
  320. onvifIOCapabilities * IO;
  321. onvifSecurityCapabilities * Security;
  322. onvifDeviceCapabilitiesExtension * Extension;
  323. } onvifDeviceCapabilities;
  324. typedef struct S_onvifEventCapabilities
  325. {
  326. char XAddr[CTEXT];
  327. bool WSSubscriptionPolicySupport;
  328. bool WSPullPointSupport;
  329. bool WSPausableSubscriptionManagerInterfaceSupport;
  330. } onvifEventCapabilities;
  331. typedef struct S_onvifImagingCapabilities
  332. {
  333. char XAddr[CTEXT];
  334. } onvifImagingCapabilities;
  335. typedef struct S_onvifRealTimeStreamingCapabilitiesExtension
  336. {
  337. } onvifRealTimeStreamingCapabilitiesExtension;
  338. typedef struct S_onvifRealTimeStreamingCapabilities
  339. {
  340. bool RTPMulticast;
  341. bool RTP_TCP;
  342. bool RTP_RTSP_TCP;
  343. onvifRealTimeStreamingCapabilitiesExtension * Extension;
  344. } onvifRealTimeStreamingCapabilities;
  345. typedef struct S_onvifProfileCapabilities
  346. {
  347. int MaximumNumberOfProfiles;
  348. } onvifProfileCapabilities;
  349. typedef struct S_onvifMediaCapabilitiesExtension
  350. {
  351. onvifProfileCapabilities * ProfileCapabilities;
  352. } onvifMediaCapabilitiesExtension;
  353. typedef struct S_onvifMediaCapabilities
  354. {
  355. char XAddr[CTEXT];
  356. onvifRealTimeStreamingCapabilities * StreamingCapabilities;
  357. onvifMediaCapabilitiesExtension * Extension;
  358. } onvifMediaCapabilities;
  359. typedef struct S_onvifPTZCapabilities
  360. {
  361. char XAddr[CTEXT];
  362. } onvifPTZCapabilities;
  363. typedef struct S_onvifDeviceIOCapabilities
  364. {
  365. char XAddr[CTEXT];
  366. int VideoSources;
  367. int VideoOutputs;
  368. int AudioSources;
  369. int AudioOutputs;
  370. int RelayOutputs;
  371. } onvifDeviceIOCapabilities;
  372. typedef struct S_onvifDisplayCapabilities
  373. {
  374. char XAddr[CTEXT];
  375. bool FixedLayout;
  376. } onvifDisplayCapabilities;
  377. typedef struct S_onvifRecordingCapabilities
  378. {
  379. char XAddr[CTEXT];
  380. bool ReceiverSource;
  381. bool MediaProfileSource;
  382. bool DynamicRecordings;
  383. bool DynamicTracks;
  384. int MaxStringLength;
  385. } onvifRecordingCapabilities;
  386. typedef struct S_onvifSearchCapabilities
  387. {
  388. char XAddr[CTEXT];
  389. bool MetadataSearch;
  390. } onvifSearchCapabilities;
  391. typedef struct S_onvifReplayCapabilities
  392. {
  393. char XAddr[CTEXT];
  394. } onvifReplayCapabilities;
  395. typedef struct S_onvifReceiverCapabilities
  396. {
  397. char XAddr[CTEXT];
  398. bool RTP_Multicast;
  399. bool RTP_TCP;
  400. bool RTP_RTSP_TCP;
  401. int SupportedReceivers;
  402. int MaximumRTSPURILength;
  403. } onvifReceiverCapabilities;
  404. typedef struct S_onvifAnalyticsDeviceExtension
  405. {
  406. } onvifAnalyticsDeviceExtension;
  407. typedef struct S_onvifAnalyticsDeviceCapabilities
  408. {
  409. char XAddr[CTEXT];
  410. bool RuleSupport;
  411. onvifAnalyticsDeviceExtension * Extension;
  412. } onvifAnalyticsDeviceCapabilities;
  413. typedef struct S_onvifCapabilitiesExtension2
  414. {
  415. } onvifCapabilitiesExtension2;
  416. typedef struct S_onvifCapabilitiesExtension
  417. {
  418. onvifDeviceIOCapabilities * DeviceIO;
  419. onvifDisplayCapabilities * Display;
  420. onvifRecordingCapabilities * Recording;
  421. onvifSearchCapabilities * Search;
  422. onvifReplayCapabilities * Replay;
  423. onvifReceiverCapabilities * Receiver;
  424. onvifAnalyticsDeviceCapabilities * AnalyticsDevice;
  425. onvifCapabilitiesExtension2 * Extensions;
  426. } onvifCapabilitiesExtension;
  427. typedef struct S_nodeCapability
  428. {
  429. onvifAnalyticsCapabilities * Analytics;
  430. onvifDeviceCapabilities * Device;
  431. onvifEventCapabilities * Events;
  432. onvifImagingCapabilities * Imaging;
  433. onvifMediaCapabilities * Media;
  434. onvifPTZCapabilities * PTZ;
  435. onvifCapabilitiesExtension * Extension;
  436. } nodeCapability;
  437. typedef struct S_discoveryNodeInfo
  438. {
  439. char endpoint_uid[64];
  440. char types[CTEXT];
  441. char scopes[CTEXT];
  442. char x_addrs[CTEXT];
  443. char meta_version[10];
  444. char ip_addrs[32];
  445. } discoveryNodeInfo;
  446. class pOnvif;
  447. typedef std::vector<videoSourceProfile *> videoSourceProfiles;
  448. typedef std::vector<videoSource *> videoSources;
  449. typedef std::vector<discoveryNodeInfo *> discoveryResults;
  450. class pOnvif
  451. {
  452. private:
  453. void cleanNodeCapability( nodeCapability *ptr );
  454. void setGenericSpeedSpaces(void);
  455. curlRequestsManager * m_pHttpAccessManager;
  456. basicMutex m_mResponseProtector;
  457. CURL * m_pCURL;
  458. basicLogCollection * m_pLog;
  459. CSTR m_pIpAddress;
  460. CSTR m_pUsername;
  461. CSTR m_pPassword;
  462. CSTR m_pDeviceURI;
  463. int m_pLastIndex;
  464. CSTR m_pMediaURI;
  465. CSTR m_pSnapshotURI;
  466. CSTR m_pPTZURI;
  467. CSTR m_pBaseURI;
  468. onvifSupportedVersions m_sOnvifVersion;
  469. time_t m_nDeltaTime;
  470. videoSources m_vVideoSources;
  471. videoSourceProfiles m_vVideoProfiles;
  472. videoSourceProfiles m_vActiveSources;
  473. nodeCapability m_sCapabilities;
  474. CSTR m_pProxyHost;
  475. int m_nProxyPort;
  476. CSTR m_pProxyUsername;
  477. CSTR m_pProxyPassword;
  478. CSTR m_pLastResponse;
  479. bool m_bIntransingent;
  480. time_t m_nDiscoveryTimeout;
  481. CSTR m_pDiscoveryBindIP;
  482. CSTR m_pDiscoveryMCastIP;
  483. int m_nDiscoveryMCastPort;
  484. bool m_bDiscoveryHideDuplicates;
  485. volatile bool parser_done;
  486. void * volatile m_pPendingRequest; // reply that _send_request is waiting for
  487. basicMutex m_mParserLock; // parser() vs. _send_request bookkeeping
  488. uint8_t m_bAuthMode;
  489. volatile long m_nLastHttpCode; // HTTP status of the last reply (set by parser())
  490. onvifError m_eLastError;
  491. char m_cLastFault[CTEXT];
  492. ptzSpeedSpace m_sPanTiltSpeedSpace; // speed space used for AbsoluteMove (generic 0..1 by default)
  493. ptzSpeedSpace m_sZoomSpeedSpace;
  494. #ifndef CURL_MANAGER
  495. static int _writer(char * data, size_t size, size_t nmemb, pOnvif * Ptr);
  496. #endif
  497. static void * parser(void * obj, void * ptr);
  498. public:
  499. pOnvif();
  500. ~pOnvif();
  501. bool setProxyHost(CSTR proxyHost);
  502. CSTR getProxyHost(void);
  503. bool setProxyPort(int proxyPort);
  504. int getProxyPort(void);
  505. bool setProxyUsername(CSTR proxyUsername);
  506. CSTR getProxyUsername(void);
  507. bool setProxyPassword(CSTR proxyPassword);
  508. CSTR getProxyPassword(void);
  509. bool setUsername(CSTR username);
  510. CSTR getUsername(void);
  511. bool setPassword(CSTR password);
  512. bool setAuthMode(uint8_t Mode);
  513. CSTR getPassword(void);
  514. CSTR getDeviceUri(void);
  515. bool setDeviceUri(CSTR deviceUri);
  516. CSTR getIPAddress(void);
  517. bool setIPAddress(CSTR ipAddress);
  518. videoSources * getSources(void);
  519. videoSourceProfiles * getProfiles(void);
  520. videoSourceProfiles * getActiveProfiles(void);
  521. CSTR getMediaUri(void);
  522. CSTR getPTZUri(void);
  523. CSTR getBaseUrl(void);
  524. void getSupportedVersion(void);
  525. nodeCapability * getCapabilities(void);
  526. bool setBreakOnError(bool intransingent);
  527. CSTR getLastResponse(void);
  528. bool setDiscoveryTimeout(int discoverytimeout);
  529. bool setDiscoveryBindIp(CSTR discoverybindip);
  530. bool setDiscoveryMcastIp(CSTR discoverymcastip);
  531. bool setDiscoveryMcastPort(int discoverymcastport);
  532. bool setDiscoveryHideDuplicates(bool discoveryhideduplicates);
  533. CSTR getSnapshotUri(void);
  534. onvifError getLastError(void);
  535. CSTR getLastFault(void);
  536. // First profile that has a PTZConfiguration, NULL if none
  537. videoSourceProfile * getPTZProfile(void);
  538. discoveryResults discover(void);
  539. bool create(void);
  540. struct tm * core_GetSystemDateAndTime(void);
  541. bool core_GetCapabilities();
  542. bool core_GetDeviceInformation();
  543. bool media_GetVideoSources();
  544. bool media_GetProfiles();
  545. bool media_GetServices();
  546. CSTR media_GetStreamUri(CSTR profileToken, CSTR stream = (CSTR) "RTP-Unicast", CSTR protocol = (CSTR) "RTSP");
  547. CSTR media_GetSnapshotUri(CSTR profileToken);
  548. bool ptz_GetPresets(CSTR profileToken);
  549. // Reads the node's speed spaces (used by ptz_AbsoluteMove: maximal speed). False if not read
  550. bool ptz_GetNode(CSTR ptzNodeToken);
  551. const ptzSpeedSpace & getPanTiltSpeedSpace(void) const
  552. {
  553. return m_sPanTiltSpeedSpace;
  554. }
  555. const ptzSpeedSpace & getZoomSpeedSpace(void) const
  556. {
  557. return m_sZoomSpeedSpace;
  558. }
  559. bool ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus);
  560. // PTZ service capabilities (ONVIF PTZ GetServiceCapabilities).
  561. // Each output is 1 = supported, 0 = not supported, -1 = not reported by the device.
  562. bool ptz_GetServiceCapabilities(int8_t * moveStatus, int8_t * statusPosition);
  563. bool ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x);
  564. bool ptz_RemovePreset(CSTR profileToken, CSTR presetToken);
  565. bool ptz_SetPreset(CSTR profileToken, CSTR presetName);
  566. bool ptz_RelativeMove(CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y);
  567. bool ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom);
  568. // Moves at the maximal speed of the speed space (speed < 0, default) or at speed (0..1 of that range)
  569. bool ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom, float speed = -1.0f);
  570. bool ptz_ContinuousMove(CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y);
  571. bool ptz_ContinuousMoveZoom(CSTR profileToken, float zoom);
  572. // One ContinuousMove for pan/tilt and zoom; axes with has* == false are left out of the request
  573. bool ptz_ContinuousMoveAll(CSTR profileToken, bool hasPanTilt, float velocity_pantilt_x, float velocity_pantilt_y, bool hasZoom, float velocity_zoom,
  574. int timeoutSec = PONVIF_CONTINUOUS_MOVE_TIMEOUT_S);
  575. bool ptz_Stop(CSTR profileToken, bool pantilt, bool zoom);
  576. /*
  577. Internal functions
  578. */
  579. public:
  580. // XML-escape src into dst (&, <, >, ", '); always NUL-terminates
  581. static char * _xmlEscape(const char * src, char * dst, size_t dstSize);
  582. private:
  583. accessToken _makeToken(void);
  584. void _getOnvifVersion(nodeCapability & capabilities);
  585. void _getActiveSources(videoSourceProfiles & videoSources, videoSourceProfiles profiles);
  586. void _getProfileData(videoSourceProfiles & videoSources, videoSourceProfiles profiles);
  587. // protected function _xml2array($response);
  588. accessToken _passwordDigest(CSTR username, CSTR password, time_t timestamp = 0);
  589. bool _hasCredentials(void);
  590. // Envelope + (WS-Security header if credentials are set) + body built from bodyFmt
  591. bool _buildRequest(char * out, size_t outSize, const char * bodyFmt, ...) __attribute__((format(printf, 4, 5)));
  592. bool _checkReply(void);
  593. bool _send_request(CSTR url, CSTR post_string, bool mr = true);
  594. bool _post_request(CSTR url, CSTR post_string);
  595. };
  596. #endif