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.

714 lines
27 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
1 week 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
1 week 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
1 week 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
1 week 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
1 week 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
1 week 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
1 week 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
1 week 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
1 week 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. #define PONVIF_SPACE_PT_GENERIC_POS "http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace"
  77. #define PONVIF_SPACE_ZOOM_GENERIC_POS "http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace"
  78. // Log every AbsoluteMove with its coordinates (a rejected move is always logged with them)
  79. #define DEBUG_PONVIF_PTZ
  80. // ContinuousMove is assembled from these parts (pan/tilt and zoom in one request)
  81. #define PONVIF_BODY_CONTINUOUS_MOVE_BEGIN "<ContinuousMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Velocity>"
  82. #define PONVIF_BODY_CONTINUOUS_MOVE_PT \
  83. "<PanTilt x=\"%0.3f\" y=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace\" xmlns=\"" \
  84. PONVIF_NS_SCHEMA "\"/>"
  85. #define PONVIF_BODY_CONTINUOUS_MOVE_ZOOM \
  86. "<Zoom x=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA "\"/>"
  87. #define PONVIF_BODY_CONTINUOUS_MOVE_END "</Velocity><Timeout>PT%dS</Timeout></ContinuousMove>"
  88. #define PONVIF_BODY_PTZ_STOP "<Stop xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PanTilt>%s</PanTilt><Zoom>%s</Zoom></Stop>"
  89. // Default ContinuousMove timeout: the camera stops by itself if the Stop request is lost
  90. #define PONVIF_CONTINUOUS_MOVE_TIMEOUT_S 10
  91. // WS-Security nonce length (bytes before Base64)
  92. #define PONVIF_NONCE_LEN 16
  93. #define PONVIF_ENVELOPE_EXT \
  94. (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>"
  95. #define PONVIF_ENVELOPE_SIM (CSTR) "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">%s%s</s:Envelope>"
  96. #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>"
  97. #define PONVIF_HEADER_PROBE \
  98. (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>"
  99. #define PONVIF_HEADER_SECUR \
  100. (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>"
  101. #define PONVIF_PCK_GET_CAPABILITIES (CSTR) "<GetCapabilities xmlns=\"http://www.onvif.org/ver10/device/wsdl\"><Category>All</Category></GetCapabilities>"
  102. // A position range of the PTZ node or a PTZConfiguration limit (URI + X range, Y range for pan/tilt)
  103. typedef struct S_ptzRange
  104. {
  105. char uri[CTEXT];
  106. float xmin;
  107. float xmax;
  108. float ymin;
  109. float ymax;
  110. bool hasY;
  111. bool valid; // read from the device
  112. } ptzRange;
  113. typedef struct S_videoSourceProfile
  114. {
  115. char sourcetoken[CTEXT];
  116. char profiletoken[CTEXT];
  117. char profilename[CTEXT];
  118. char encoding[16];
  119. int width;
  120. int height;
  121. int fps;
  122. int bitrate;
  123. bool ptz; // profile has a PTZConfiguration (PTZ commands need such a profile)
  124. char ptznodetoken[CTEXT]; // PTZConfiguration/NodeToken
  125. // PTZConfiguration: default absolute position spaces (used when a Position has no space attribute)
  126. // and the configured limits (a move outside them is answered with ter:InvalidPosition)
  127. char ptzdefaultptspace[CTEXT];
  128. char ptzdefaultzoomspace[CTEXT];
  129. ptzRange ptzpantiltlimits;
  130. ptzRange ptzzoomlimits;
  131. } videoSourceProfile;
  132. // A speed space of the PTZ node (GetNode -> SupportedPTZSpaces/PanTiltSpeedSpace | ZoomSpeedSpace)
  133. typedef struct S_ptzSpeedSpace
  134. {
  135. char uri[CTEXT];
  136. float min;
  137. float max;
  138. bool valid; // read from the device
  139. } ptzSpeedSpace;
  140. // Result of the last request (pOnvif::getLastError)
  141. typedef enum E_onvifError
  142. {
  143. PONVIF_OK = 0,
  144. PONVIF_ERR_COMM, // no answer: connection error, timeout, request could not be queued
  145. PONVIF_ERR_HTTP, // HTTP status other than 200 without a SOAP Fault (e.g. 401 HTML page)
  146. PONVIF_ERR_FAULT, // the device answered with a SOAP Fault (see getLastFault)
  147. PONVIF_ERR_PARSE // reply is not the expected XML
  148. } onvifError;
  149. typedef struct S_onvifVideoResolution
  150. {
  151. int Width;
  152. int Height;
  153. } onvifVideoResolution;
  154. typedef struct S_onvifBacklightCompensation
  155. {
  156. bool Mode;
  157. float Level;
  158. } onvifBacklightCompensation;
  159. typedef enum E_onvifExposurePriority
  160. {
  161. LowNoise = 0,
  162. FrameRate
  163. } onvifExposurePriority;
  164. typedef struct S_onvifRectangle
  165. {
  166. int x;
  167. int y;
  168. int width;
  169. int height;
  170. } onvifRectangle;
  171. typedef struct S_onvifExposure
  172. {
  173. bool Mode;
  174. onvifExposurePriority Priority;
  175. onvifRectangle Window;
  176. float MinExposureTime;
  177. float MaxExposureTime;
  178. float MinGain;
  179. float MaxGain;
  180. float MinIris;
  181. float MaxIris;
  182. float ExposureTime;
  183. float Gain;
  184. float Iris;
  185. } onvifExposure;
  186. typedef enum E_onvifOnOffAuto
  187. {
  188. ON = 0,
  189. OFF,
  190. AUTO
  191. } onvifOnOffAuto;
  192. typedef struct S_onvifFocusConfiguration
  193. {
  194. bool AutoFocusMode;
  195. float DefaultSpeed;
  196. float NearLimit;
  197. float FarLimit;
  198. } onvifFocusConfiguration;
  199. typedef struct S_onvifWideDynamicRange
  200. {
  201. bool Mode;
  202. float Level;
  203. } onvifWideDynamicRange;
  204. typedef struct S_onvifWhiteBalanceExtension
  205. {
  206. } onvifWhiteBalanceExtension;
  207. typedef struct S_onvifWhiteBalance
  208. {
  209. bool Mode;
  210. float CrGain;
  211. float CbGain;
  212. onvifWhiteBalanceExtension * Extension;
  213. } onvifWhiteBalance;
  214. typedef struct S_onvifImagingSettingsExtension
  215. {
  216. } onvifImagingSettingsExtension;
  217. typedef struct S_onvifImagingSettings
  218. {
  219. onvifBacklightCompensation * BacklightCompensation;
  220. float Brightness;
  221. float ColorSaturation;
  222. float Contrast;
  223. onvifExposure * Exposure;
  224. onvifFocusConfiguration * Focus;
  225. onvifOnOffAuto IrCutFilter;
  226. float Sharpness;
  227. onvifWideDynamicRange * WideDynamicRange;
  228. onvifWhiteBalance * WhiteBalance;
  229. onvifImagingSettingsExtension * Extension;
  230. } onvifImagingSettings;
  231. typedef struct S_onvifVideoSourceExtension
  232. {
  233. onvifImagingSettings * Imaging;
  234. } onvifVideoSourceExtension;
  235. typedef struct S_onvifVideoSource
  236. {
  237. char token[CTEXT];
  238. float Framerate;
  239. onvifVideoResolution Resolution;
  240. onvifImagingSettings * Imaging;
  241. onvifVideoSourceExtension * Extension;
  242. } videoSource;
  243. typedef struct S_onvifSupportedVersions
  244. {
  245. int Major;
  246. int Minor;
  247. } onvifSupportedVersions;
  248. typedef struct S_onvifNetworkCapabilitiesExtension2
  249. {
  250. } onvifNetworkCapabilitiesExtension2;
  251. typedef struct S_onvifNetworkCapabilitiesExtension
  252. {
  253. bool Dot11Configuration;
  254. onvifNetworkCapabilitiesExtension2 * Extension;
  255. } onvifNetworkCapabilitiesExtension;
  256. typedef struct S_onvifNetworkCapabilities
  257. {
  258. bool IPFilter;
  259. bool ZeroConfiguration;
  260. bool IPVersion6;
  261. bool DynDNS;
  262. onvifNetworkCapabilitiesExtension * Extension;
  263. } onvifNetworkCapabilities;
  264. typedef struct S_onvifIOCapabilitiesExtension2
  265. {
  266. } onvifIOCapabilitiesExtension2;
  267. typedef struct S_onvifIOAuxiliaryData
  268. {
  269. } onvifIOAuxiliaryData;
  270. typedef struct S_onvifIOCapabilitiesExtension
  271. {
  272. bool Auxiliary;
  273. onvifIOAuxiliaryData * AuxiliaryCommands;
  274. onvifIOCapabilitiesExtension2 * Extension;
  275. } onvifIOCapabilitiesExtension;
  276. typedef struct S_onvifIOCapabilities
  277. {
  278. int InputConnectors;
  279. int RelayOutputs;
  280. onvifIOCapabilitiesExtension * Extension;
  281. } onvifIOCapabilities;
  282. typedef struct S_onvifSecurityCapabilitiesExtension2
  283. {
  284. bool Dot1X;
  285. int SupportedEAPMethod;
  286. bool RemoteUserHandling;
  287. } onvifSecurityCapabilitiesExtension2;
  288. typedef struct S_onvifSecurityCapabilitiesExtension
  289. {
  290. bool TLS1_0;
  291. onvifSecurityCapabilitiesExtension2 * Extension;
  292. } onvifSecurityCapabilitiesExtension;
  293. typedef struct S_onvifSecurityCapabilities
  294. {
  295. bool TLS1_1;
  296. bool TLS1_2;
  297. bool OnboardKeyGeneration;
  298. bool AccessPolicyConfig;
  299. bool X_509Token;
  300. bool SAMLToken;
  301. bool KerberosToken;
  302. bool RELToken;
  303. onvifSecurityCapabilitiesExtension * Extension;
  304. } onvifSecurityCapabilities;
  305. typedef struct S_onvifSystemCapabilitiesExtension2
  306. {
  307. } onvifSystemCapabilitiesExtension2;
  308. typedef struct S_onvifSystemCapabilitiesExtension
  309. {
  310. bool HttpFirmwareUpgrade;
  311. bool HttpSystemBackup;
  312. bool HttpSystemLogging;
  313. bool HttpSupportInformation;
  314. onvifSystemCapabilitiesExtension2 * Extension;
  315. } onvifSystemCapabilitiesExtension;
  316. typedef struct S_onvifSystemCapabilities
  317. {
  318. bool DiscoveryResolve;
  319. bool DiscoveryBye;
  320. bool RemoteDiscovery;
  321. bool SystemBackup;
  322. bool SystemLogging;
  323. bool FirmwareUpgrade;
  324. onvifSupportedVersions * SupportedVersions;
  325. onvifSystemCapabilitiesExtension * Extension;
  326. } onvifSystemCapabilities;
  327. typedef struct S_onvifDeviceCapabilitiesExtension
  328. {
  329. } onvifDeviceCapabilitiesExtension;
  330. typedef struct S_onvifAnalyticsCapabilities
  331. {
  332. char XAddr[CTEXT];
  333. bool RuleSupport;
  334. bool AnalyticsModuleSupport;
  335. } onvifAnalyticsCapabilities;
  336. typedef struct S_onvifDeviceCapabilities
  337. {
  338. char XAddr[CTEXT];
  339. onvifNetworkCapabilities * Network;
  340. onvifSystemCapabilities * System;
  341. onvifIOCapabilities * IO;
  342. onvifSecurityCapabilities * Security;
  343. onvifDeviceCapabilitiesExtension * Extension;
  344. } onvifDeviceCapabilities;
  345. typedef struct S_onvifEventCapabilities
  346. {
  347. char XAddr[CTEXT];
  348. bool WSSubscriptionPolicySupport;
  349. bool WSPullPointSupport;
  350. bool WSPausableSubscriptionManagerInterfaceSupport;
  351. } onvifEventCapabilities;
  352. typedef struct S_onvifImagingCapabilities
  353. {
  354. char XAddr[CTEXT];
  355. } onvifImagingCapabilities;
  356. typedef struct S_onvifRealTimeStreamingCapabilitiesExtension
  357. {
  358. } onvifRealTimeStreamingCapabilitiesExtension;
  359. typedef struct S_onvifRealTimeStreamingCapabilities
  360. {
  361. bool RTPMulticast;
  362. bool RTP_TCP;
  363. bool RTP_RTSP_TCP;
  364. onvifRealTimeStreamingCapabilitiesExtension * Extension;
  365. } onvifRealTimeStreamingCapabilities;
  366. typedef struct S_onvifProfileCapabilities
  367. {
  368. int MaximumNumberOfProfiles;
  369. } onvifProfileCapabilities;
  370. typedef struct S_onvifMediaCapabilitiesExtension
  371. {
  372. onvifProfileCapabilities * ProfileCapabilities;
  373. } onvifMediaCapabilitiesExtension;
  374. typedef struct S_onvifMediaCapabilities
  375. {
  376. char XAddr[CTEXT];
  377. onvifRealTimeStreamingCapabilities * StreamingCapabilities;
  378. onvifMediaCapabilitiesExtension * Extension;
  379. } onvifMediaCapabilities;
  380. typedef struct S_onvifPTZCapabilities
  381. {
  382. char XAddr[CTEXT];
  383. } onvifPTZCapabilities;
  384. typedef struct S_onvifDeviceIOCapabilities
  385. {
  386. char XAddr[CTEXT];
  387. int VideoSources;
  388. int VideoOutputs;
  389. int AudioSources;
  390. int AudioOutputs;
  391. int RelayOutputs;
  392. } onvifDeviceIOCapabilities;
  393. typedef struct S_onvifDisplayCapabilities
  394. {
  395. char XAddr[CTEXT];
  396. bool FixedLayout;
  397. } onvifDisplayCapabilities;
  398. typedef struct S_onvifRecordingCapabilities
  399. {
  400. char XAddr[CTEXT];
  401. bool ReceiverSource;
  402. bool MediaProfileSource;
  403. bool DynamicRecordings;
  404. bool DynamicTracks;
  405. int MaxStringLength;
  406. } onvifRecordingCapabilities;
  407. typedef struct S_onvifSearchCapabilities
  408. {
  409. char XAddr[CTEXT];
  410. bool MetadataSearch;
  411. } onvifSearchCapabilities;
  412. typedef struct S_onvifReplayCapabilities
  413. {
  414. char XAddr[CTEXT];
  415. } onvifReplayCapabilities;
  416. typedef struct S_onvifReceiverCapabilities
  417. {
  418. char XAddr[CTEXT];
  419. bool RTP_Multicast;
  420. bool RTP_TCP;
  421. bool RTP_RTSP_TCP;
  422. int SupportedReceivers;
  423. int MaximumRTSPURILength;
  424. } onvifReceiverCapabilities;
  425. typedef struct S_onvifAnalyticsDeviceExtension
  426. {
  427. } onvifAnalyticsDeviceExtension;
  428. typedef struct S_onvifAnalyticsDeviceCapabilities
  429. {
  430. char XAddr[CTEXT];
  431. bool RuleSupport;
  432. onvifAnalyticsDeviceExtension * Extension;
  433. } onvifAnalyticsDeviceCapabilities;
  434. typedef struct S_onvifCapabilitiesExtension2
  435. {
  436. } onvifCapabilitiesExtension2;
  437. typedef struct S_onvifCapabilitiesExtension
  438. {
  439. onvifDeviceIOCapabilities * DeviceIO;
  440. onvifDisplayCapabilities * Display;
  441. onvifRecordingCapabilities * Recording;
  442. onvifSearchCapabilities * Search;
  443. onvifReplayCapabilities * Replay;
  444. onvifReceiverCapabilities * Receiver;
  445. onvifAnalyticsDeviceCapabilities * AnalyticsDevice;
  446. onvifCapabilitiesExtension2 * Extensions;
  447. } onvifCapabilitiesExtension;
  448. typedef struct S_nodeCapability
  449. {
  450. onvifAnalyticsCapabilities * Analytics;
  451. onvifDeviceCapabilities * Device;
  452. onvifEventCapabilities * Events;
  453. onvifImagingCapabilities * Imaging;
  454. onvifMediaCapabilities * Media;
  455. onvifPTZCapabilities * PTZ;
  456. onvifCapabilitiesExtension * Extension;
  457. } nodeCapability;
  458. typedef struct S_discoveryNodeInfo
  459. {
  460. char endpoint_uid[64];
  461. char types[CTEXT];
  462. char scopes[CTEXT];
  463. char x_addrs[CTEXT];
  464. char meta_version[10];
  465. char ip_addrs[32];
  466. } discoveryNodeInfo;
  467. class pOnvif;
  468. typedef std::vector<videoSourceProfile *> videoSourceProfiles;
  469. typedef std::vector<videoSource *> videoSources;
  470. typedef std::vector<discoveryNodeInfo *> discoveryResults;
  471. class pOnvif
  472. {
  473. private:
  474. void cleanNodeCapability( nodeCapability *ptr );
  475. void setGenericSpeedSpaces(void);
  476. bool reachableXAddr(char * xaddr, size_t size); // LAN service address -> reached address (NAT)
  477. curlRequestsManager * m_pHttpAccessManager;
  478. basicMutex m_mResponseProtector;
  479. CURL * m_pCURL;
  480. basicLogCollection * m_pLog;
  481. CSTR m_pIpAddress;
  482. CSTR m_pUsername;
  483. CSTR m_pPassword;
  484. CSTR m_pDeviceURI;
  485. int m_pLastIndex;
  486. CSTR m_pMediaURI;
  487. CSTR m_pSnapshotURI;
  488. CSTR m_pPTZURI;
  489. CSTR m_pBaseURI;
  490. onvifSupportedVersions m_sOnvifVersion;
  491. time_t m_nDeltaTime;
  492. videoSources m_vVideoSources;
  493. videoSourceProfiles m_vVideoProfiles;
  494. videoSourceProfiles m_vActiveSources;
  495. nodeCapability m_sCapabilities;
  496. CSTR m_pProxyHost;
  497. int m_nProxyPort;
  498. CSTR m_pProxyUsername;
  499. CSTR m_pProxyPassword;
  500. CSTR m_pLastResponse;
  501. bool m_bIntransingent;
  502. time_t m_nDiscoveryTimeout;
  503. CSTR m_pDiscoveryBindIP;
  504. CSTR m_pDiscoveryMCastIP;
  505. int m_nDiscoveryMCastPort;
  506. bool m_bDiscoveryHideDuplicates;
  507. volatile bool parser_done;
  508. void * volatile m_pPendingRequest; // reply that _send_request is waiting for
  509. basicMutex m_mParserLock; // parser() vs. _send_request bookkeeping
  510. uint8_t m_bAuthMode;
  511. volatile long m_nLastHttpCode; // HTTP status of the last reply (set by parser())
  512. onvifError m_eLastError;
  513. char m_cLastFault[CTEXT];
  514. ptzSpeedSpace m_sPanTiltSpeedSpace; // speed space used for AbsoluteMove (generic 0..1 by default)
  515. ptzSpeedSpace m_sZoomSpeedSpace;
  516. ptzRange m_sPanTiltPosSpace; // node: absolute pan/tilt position space (generic one if offered)
  517. ptzRange m_sZoomPosSpace; // node: absolute zoom position space
  518. #ifndef CURL_MANAGER
  519. static int _writer(char * data, size_t size, size_t nmemb, pOnvif * Ptr);
  520. #endif
  521. static void * parser(void * obj, void * ptr);
  522. public:
  523. pOnvif();
  524. ~pOnvif();
  525. bool setProxyHost(CSTR proxyHost);
  526. CSTR getProxyHost(void);
  527. bool setProxyPort(int proxyPort);
  528. int getProxyPort(void);
  529. bool setProxyUsername(CSTR proxyUsername);
  530. CSTR getProxyUsername(void);
  531. bool setProxyPassword(CSTR proxyPassword);
  532. CSTR getProxyPassword(void);
  533. bool setUsername(CSTR username);
  534. CSTR getUsername(void);
  535. bool setPassword(CSTR password);
  536. bool setAuthMode(uint8_t Mode);
  537. CSTR getPassword(void);
  538. CSTR getDeviceUri(void);
  539. bool setDeviceUri(CSTR deviceUri);
  540. CSTR getIPAddress(void);
  541. bool setIPAddress(CSTR ipAddress);
  542. videoSources * getSources(void);
  543. videoSourceProfiles * getProfiles(void);
  544. videoSourceProfiles * getActiveProfiles(void);
  545. CSTR getMediaUri(void);
  546. CSTR getPTZUri(void);
  547. CSTR getBaseUrl(void);
  548. void getSupportedVersion(void);
  549. nodeCapability * getCapabilities(void);
  550. bool setBreakOnError(bool intransingent);
  551. CSTR getLastResponse(void);
  552. bool setDiscoveryTimeout(int discoverytimeout);
  553. bool setDiscoveryBindIp(CSTR discoverybindip);
  554. bool setDiscoveryMcastIp(CSTR discoverymcastip);
  555. bool setDiscoveryMcastPort(int discoverymcastport);
  556. bool setDiscoveryHideDuplicates(bool discoveryhideduplicates);
  557. CSTR getSnapshotUri(void);
  558. onvifError getLastError(void);
  559. CSTR getLastFault(void);
  560. // First profile that has a PTZConfiguration, NULL if none
  561. videoSourceProfile * getPTZProfile(void);
  562. discoveryResults discover(void);
  563. bool create(void);
  564. struct tm * core_GetSystemDateAndTime(void);
  565. bool core_GetCapabilities();
  566. bool core_GetDeviceInformation();
  567. bool media_GetVideoSources();
  568. bool media_GetProfiles();
  569. bool media_GetServices();
  570. CSTR media_GetStreamUri(CSTR profileToken, CSTR stream = (CSTR) "RTP-Unicast", CSTR protocol = (CSTR) "RTSP");
  571. CSTR media_GetSnapshotUri(CSTR profileToken);
  572. bool ptz_GetPresets(CSTR profileToken);
  573. // Reads the node's speed spaces (used by ptz_AbsoluteMove: maximal speed). False if not read
  574. bool ptz_GetNode(CSTR ptzNodeToken);
  575. const ptzSpeedSpace & getPanTiltSpeedSpace(void) const
  576. {
  577. return m_sPanTiltSpeedSpace;
  578. }
  579. const ptzSpeedSpace & getZoomSpeedSpace(void) const
  580. {
  581. return m_sZoomSpeedSpace;
  582. }
  583. const ptzRange & getPanTiltPositionSpace(void) const
  584. {
  585. return m_sPanTiltPosSpace;
  586. }
  587. const ptzRange & getZoomPositionSpace(void) const
  588. {
  589. return m_sZoomPosSpace;
  590. }
  591. // Logs the position spaces of the node and the limits of the profile (debug of out-of-bounds moves)
  592. void ptz_LogRanges(CSTR profileToken);
  593. bool ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus);
  594. // PTZ service capabilities (ONVIF PTZ GetServiceCapabilities).
  595. // Each output is 1 = supported, 0 = not supported, -1 = not reported by the device.
  596. bool ptz_GetServiceCapabilities(int8_t * moveStatus, int8_t * statusPosition);
  597. bool ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x);
  598. bool ptz_RemovePreset(CSTR profileToken, CSTR presetToken);
  599. bool ptz_SetPreset(CSTR profileToken, CSTR presetName);
  600. bool ptz_RelativeMove(CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y);
  601. bool ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom);
  602. // Moves at the maximal speed of the speed space (speed < 0, default) or at speed (0..1 of that range)
  603. bool ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom, float speed = -1.0f);
  604. bool ptz_ContinuousMove(CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y);
  605. bool ptz_ContinuousMoveZoom(CSTR profileToken, float zoom);
  606. // One ContinuousMove for pan/tilt and zoom; axes with has* == false are left out of the request
  607. bool ptz_ContinuousMoveAll(CSTR profileToken, bool hasPanTilt, float velocity_pantilt_x, float velocity_pantilt_y, bool hasZoom, float velocity_zoom,
  608. int timeoutSec = PONVIF_CONTINUOUS_MOVE_TIMEOUT_S);
  609. bool ptz_Stop(CSTR profileToken, bool pantilt, bool zoom);
  610. /*
  611. Internal functions
  612. */
  613. public:
  614. // XML-escape src into dst (&, <, >, ", '); always NUL-terminates
  615. static char * _xmlEscape(const char * src, char * dst, size_t dstSize);
  616. private:
  617. accessToken _makeToken(void);
  618. void _getOnvifVersion(nodeCapability & capabilities);
  619. void _getActiveSources(videoSourceProfiles & videoSources, videoSourceProfiles profiles);
  620. void _getProfileData(videoSourceProfiles & videoSources, videoSourceProfiles profiles);
  621. // protected function _xml2array($response);
  622. accessToken _passwordDigest(CSTR username, CSTR password, time_t timestamp = 0);
  623. bool _hasCredentials(void);
  624. // Envelope + (WS-Security header if credentials are set) + body built from bodyFmt
  625. bool _buildRequest(char * out, size_t outSize, const char * bodyFmt, ...) __attribute__((format(printf, 4, 5)));
  626. bool _checkReply(void);
  627. bool _send_request(CSTR url, CSTR post_string, bool mr = true);
  628. bool _post_request(CSTR url, CSTR post_string);
  629. };
  630. #endif