 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
7 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
7 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
7 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
7 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
7 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
7 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
7 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
7 days ago |
|
#ifndef __PONVIF_CLASS_HEADER__
#define __PONVIF_CLASS_HEADER__
// Based on PHP Onvif library
#include <curl/curl.h>
#include <openssl/sha.h>
#include <vector>
#ifdef __linux__
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sys/socket.h>
#include <unistd.h>
#endif
#include "../../alg/generic/base64.h"
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicTypes.h"
#include "../curl/curlRequestsManager.h"
#include "../protocol/xmlParser.h"
#define CURL_MANAGER
// #define DEBUG_ONVIF_PRINTOUT_MESSAGES
// #define DEBUG_ONVIF_TRAFFIC
#define PONVIF_DEFAULT_DISCOVERYBINDIP (CSTR) "0.0.0.0"
#define PONVIF_DEFAULT_DISCOVERYMCASTIP (CSTR) "239.255.255.250"
#define PONVIF_DEFAULT_DISCOVERYMCASTPORT 3702
#define PONVIF_DEFAULT_DISCOVERYTIMEOUT 12
#define PONVIF_PACK_DISCOVERY \
(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>"#define PONVIF_PACK_GET_SYS_DTS \
(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>"/*
Request bodies (the SOAP envelope and the optional WS-Security header are added by pOnvif::_buildRequest). String arguments must be XML-escaped by the caller (pOnvif::_xmlEscape).*/#define PONVIF_NS_DEVICE "http://www.onvif.org/ver10/device/wsdl"
#define PONVIF_NS_MEDIA "http://www.onvif.org/ver10/media/wsdl"
#define PONVIF_NS_PTZ "http://www.onvif.org/ver20/ptz/wsdl"
#define PONVIF_NS_SCHEMA "http://www.onvif.org/ver10/schema"
#define PONVIF_BODY_GET_CAPABILITIES "<GetCapabilities xmlns=\"" PONVIF_NS_DEVICE "\"><Category>All</Category></GetCapabilities>"
#define PONVIF_BODY_GET_SERVICES "<GetServices xmlns=\"" PONVIF_NS_DEVICE "\"><IncludeCapability>false</IncludeCapability></GetServices>"
#define PONVIF_BODY_GET_DEV_INFO "<GetDeviceInformation xmlns=\"" PONVIF_NS_DEVICE "\"/>"
#define PONVIF_BODY_GET_VIDEO_SOURCES "<GetVideoSources xmlns=\"" PONVIF_NS_MEDIA "\"/>"
#define PONVIF_BODY_GET_PROFILES "<GetProfiles xmlns=\"" PONVIF_NS_MEDIA "\"/>"
#define PONVIF_BODY_GET_STREAM_URI \
"<GetStreamUri xmlns=\"" PONVIF_NS_MEDIA "\"><StreamSetup><Stream xmlns=\"" PONVIF_NS_SCHEMA "\">%s</Stream><Transport xmlns=\"" PONVIF_NS_SCHEMA \ "\"><Protocol>%s</Protocol></Transport></StreamSetup><ProfileToken>%s</ProfileToken></GetStreamUri>"#define PONVIF_BODY_GET_SNAPSHOT_URI "<GetSnapshotUri xmlns=\"" PONVIF_NS_MEDIA "\"><ProfileToken>%s</ProfileToken></GetSnapshotUri>"
#define PONVIF_BODY_PTZ_GET_SERVICE_CAPS "<GetServiceCapabilities xmlns=\"" PONVIF_NS_PTZ "\"/>"
#define PONVIF_BODY_GET_PRESETS "<GetPresets xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken></GetPresets>"
#define PONVIF_BODY_GET_PTZ_NODE "<GetNode xmlns=\"" PONVIF_NS_PTZ "\"><NodeToken>%s</NodeToken></GetNode>"
#define PONVIF_BODY_GET_PTZ_STATUS "<GetStatus xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken></GetStatus>"
#define PONVIF_BODY_GOTO_PRESET \
"<GotoPreset xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PresetToken>%s</PresetToken><Speed><PanTilt x=\"%0.3f\" y=\"%0.3f\" xmlns=\"" PONVIF_NS_SCHEMA \ "\"/><Zoom x=\"%0.3f\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Speed></GotoPreset>"#define PONVIF_BODY_REMOVE_PRESET "<RemovePreset xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PresetToken>%s</PresetToken></RemovePreset>"
#define PONVIF_BODY_SET_PRESET "<SetPreset xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PresetName>%s</PresetName></SetPreset>"
#define PONVIF_BODY_RELATIVE_MOVE \
"<RelativeMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Translation><PanTilt x=\"%0.4f\" y=\"%0.4f\" " \ "space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Translation><Speed><PanTilt " \ "x=\"%0.3f\" y=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/GenericSpeedSpace\" xmlns=\"" PONVIF_NS_SCHEMA \ "\"/></Speed></RelativeMove>"#define PONVIF_BODY_RELATIVE_ZOOM \
"<RelativeMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Translation><Zoom x=\"%0.4f\" xmlns=\"" PONVIF_NS_SCHEMA \ "\"/></Translation><Speed><Zoom x=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/ZoomGenericSpeedSpace\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Speed></RelativeMove>"#define PONVIF_BODY_ABSOLUTE_MOVE \
"<AbsoluteMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Position><PanTilt x=\"%0.6f\" y=\"%0.6f\" xmlns=\"" PONVIF_NS_SCHEMA \ "\"/><Zoom x=\"%0.6f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA \ "\"/></Position><Speed><PanTilt x=\"1\" y=\"1\" xmlns=\"" PONVIF_NS_SCHEMA "\"/><Zoom x=\"1\" xmlns=\"" PONVIF_NS_SCHEMA "\"/></Speed></AbsoluteMove>"// ContinuousMove is assembled from these parts (pan/tilt and zoom in one request)
#define PONVIF_BODY_CONTINUOUS_MOVE_BEGIN "<ContinuousMove xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><Velocity>"
#define PONVIF_BODY_CONTINUOUS_MOVE_PT \
"<PanTilt x=\"%0.3f\" y=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace\" xmlns=\"" \ PONVIF_NS_SCHEMA "\"/>"#define PONVIF_BODY_CONTINUOUS_MOVE_ZOOM \
"<Zoom x=\"%0.3f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace\" xmlns=\"" PONVIF_NS_SCHEMA "\"/>"#define PONVIF_BODY_CONTINUOUS_MOVE_END "</Velocity><Timeout>PT%dS</Timeout></ContinuousMove>"
#define PONVIF_BODY_PTZ_STOP "<Stop xmlns=\"" PONVIF_NS_PTZ "\"><ProfileToken>%s</ProfileToken><PanTilt>%s</PanTilt><Zoom>%s</Zoom></Stop>"
// Default ContinuousMove timeout: the camera stops by itself if the Stop request is lost
#define PONVIF_CONTINUOUS_MOVE_TIMEOUT_S 10
// WS-Security nonce length (bytes before Base64)
#define PONVIF_NONCE_LEN 16
#define PONVIF_ENVELOPE_EXT \
(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>"#define PONVIF_ENVELOPE_SIM (CSTR) "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">%s%s</s:Envelope>"
#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>"
#define PONVIF_HEADER_PROBE \
(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>"#define PONVIF_HEADER_SECUR \
(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>"
#define PONVIF_PCK_GET_CAPABILITIES (CSTR) "<GetCapabilities xmlns=\"http://www.onvif.org/ver10/device/wsdl\"><Category>All</Category></GetCapabilities>"
typedef struct S_videoSourceProfile{ char sourcetoken[CTEXT]; char profiletoken[CTEXT]; char profilename[CTEXT]; char encoding[16]; int width; int height; int fps; int bitrate; bool ptz; // profile has a PTZConfiguration (PTZ commands need such a profile)
char ptznodetoken[CTEXT]; // PTZConfiguration/NodeToken
} videoSourceProfile;
// Result of the last request (pOnvif::getLastError)
typedef enum E_onvifError{ PONVIF_OK = 0, PONVIF_ERR_COMM, // no answer: connection error, timeout, request could not be queued
PONVIF_ERR_HTTP, // HTTP status other than 200 without a SOAP Fault (e.g. 401 HTML page)
PONVIF_ERR_FAULT, // the device answered with a SOAP Fault (see getLastFault)
PONVIF_ERR_PARSE // reply is not the expected XML
} onvifError;
typedef struct S_onvifVideoResolution{ int Width; int Height;} onvifVideoResolution;
typedef struct S_onvifBacklightCompensation{ bool Mode; float Level;} onvifBacklightCompensation;
typedef enum E_onvifExposurePriority{ LowNoise = 0, FrameRate} onvifExposurePriority;
typedef struct S_onvifRectangle{ int x; int y; int width; int height;} onvifRectangle;
typedef struct S_onvifExposure{ bool Mode; onvifExposurePriority Priority; onvifRectangle Window; float MinExposureTime; float MaxExposureTime; float MinGain; float MaxGain; float MinIris; float MaxIris; float ExposureTime; float Gain; float Iris;} onvifExposure;
typedef enum E_onvifOnOffAuto{ ON = 0, OFF, AUTO} onvifOnOffAuto;
typedef struct S_onvifFocusConfiguration{ bool AutoFocusMode; float DefaultSpeed; float NearLimit; float FarLimit;} onvifFocusConfiguration;
typedef struct S_onvifWideDynamicRange{ bool Mode; float Level;} onvifWideDynamicRange;
typedef struct S_onvifWhiteBalanceExtension{} onvifWhiteBalanceExtension;
typedef struct S_onvifWhiteBalance{ bool Mode; float CrGain; float CbGain; onvifWhiteBalanceExtension * Extension;} onvifWhiteBalance;
typedef struct S_onvifImagingSettingsExtension{} onvifImagingSettingsExtension;
typedef struct S_onvifImagingSettings{ onvifBacklightCompensation * BacklightCompensation; float Brightness; float ColorSaturation; float Contrast; onvifExposure * Exposure; onvifFocusConfiguration * Focus; onvifOnOffAuto IrCutFilter; float Sharpness; onvifWideDynamicRange * WideDynamicRange; onvifWhiteBalance * WhiteBalance; onvifImagingSettingsExtension * Extension;} onvifImagingSettings;
typedef struct S_onvifVideoSourceExtension{ onvifImagingSettings * Imaging;} onvifVideoSourceExtension;
typedef struct S_onvifVideoSource{ char token[CTEXT]; float Framerate; onvifVideoResolution Resolution; onvifImagingSettings * Imaging; onvifVideoSourceExtension * Extension;} videoSource;
typedef struct S_onvifSupportedVersions{ int Major; int Minor;} onvifSupportedVersions;
typedef struct S_onvifNetworkCapabilitiesExtension2{} onvifNetworkCapabilitiesExtension2;
typedef struct S_onvifNetworkCapabilitiesExtension{ bool Dot11Configuration; onvifNetworkCapabilitiesExtension2 * Extension;} onvifNetworkCapabilitiesExtension;
typedef struct S_onvifNetworkCapabilities{ bool IPFilter; bool ZeroConfiguration; bool IPVersion6; bool DynDNS; onvifNetworkCapabilitiesExtension * Extension;} onvifNetworkCapabilities;
typedef struct S_onvifIOCapabilitiesExtension2{} onvifIOCapabilitiesExtension2;
typedef struct S_onvifIOAuxiliaryData{} onvifIOAuxiliaryData;
typedef struct S_onvifIOCapabilitiesExtension{ bool Auxiliary; onvifIOAuxiliaryData * AuxiliaryCommands; onvifIOCapabilitiesExtension2 * Extension;} onvifIOCapabilitiesExtension;
typedef struct S_onvifIOCapabilities{ int InputConnectors; int RelayOutputs; onvifIOCapabilitiesExtension * Extension;} onvifIOCapabilities;
typedef struct S_onvifSecurityCapabilitiesExtension2{ bool Dot1X; int SupportedEAPMethod; bool RemoteUserHandling;} onvifSecurityCapabilitiesExtension2;
typedef struct S_onvifSecurityCapabilitiesExtension{ bool TLS1_0; onvifSecurityCapabilitiesExtension2 * Extension;} onvifSecurityCapabilitiesExtension;
typedef struct S_onvifSecurityCapabilities{ bool TLS1_1; bool TLS1_2; bool OnboardKeyGeneration; bool AccessPolicyConfig; bool X_509Token; bool SAMLToken; bool KerberosToken; bool RELToken; onvifSecurityCapabilitiesExtension * Extension;} onvifSecurityCapabilities;
typedef struct S_onvifSystemCapabilitiesExtension2{} onvifSystemCapabilitiesExtension2;
typedef struct S_onvifSystemCapabilitiesExtension{ bool HttpFirmwareUpgrade; bool HttpSystemBackup; bool HttpSystemLogging; bool HttpSupportInformation; onvifSystemCapabilitiesExtension2 * Extension;} onvifSystemCapabilitiesExtension;
typedef struct S_onvifSystemCapabilities{ bool DiscoveryResolve; bool DiscoveryBye; bool RemoteDiscovery; bool SystemBackup; bool SystemLogging; bool FirmwareUpgrade; onvifSupportedVersions * SupportedVersions; onvifSystemCapabilitiesExtension * Extension;} onvifSystemCapabilities;
typedef struct S_onvifDeviceCapabilitiesExtension{} onvifDeviceCapabilitiesExtension;
typedef struct S_onvifAnalyticsCapabilities{ char XAddr[CTEXT]; bool RuleSupport; bool AnalyticsModuleSupport;} onvifAnalyticsCapabilities;
typedef struct S_onvifDeviceCapabilities{ char XAddr[CTEXT]; onvifNetworkCapabilities * Network; onvifSystemCapabilities * System; onvifIOCapabilities * IO; onvifSecurityCapabilities * Security; onvifDeviceCapabilitiesExtension * Extension;} onvifDeviceCapabilities;
typedef struct S_onvifEventCapabilities{ char XAddr[CTEXT]; bool WSSubscriptionPolicySupport; bool WSPullPointSupport; bool WSPausableSubscriptionManagerInterfaceSupport;} onvifEventCapabilities;
typedef struct S_onvifImagingCapabilities{ char XAddr[CTEXT];} onvifImagingCapabilities;
typedef struct S_onvifRealTimeStreamingCapabilitiesExtension{} onvifRealTimeStreamingCapabilitiesExtension;
typedef struct S_onvifRealTimeStreamingCapabilities{ bool RTPMulticast; bool RTP_TCP; bool RTP_RTSP_TCP; onvifRealTimeStreamingCapabilitiesExtension * Extension;} onvifRealTimeStreamingCapabilities;
typedef struct S_onvifProfileCapabilities{ int MaximumNumberOfProfiles;} onvifProfileCapabilities;
typedef struct S_onvifMediaCapabilitiesExtension{ onvifProfileCapabilities * ProfileCapabilities;} onvifMediaCapabilitiesExtension;
typedef struct S_onvifMediaCapabilities{ char XAddr[CTEXT]; onvifRealTimeStreamingCapabilities * StreamingCapabilities; onvifMediaCapabilitiesExtension * Extension;} onvifMediaCapabilities;
typedef struct S_onvifPTZCapabilities{ char XAddr[CTEXT];} onvifPTZCapabilities;
typedef struct S_onvifDeviceIOCapabilities{ char XAddr[CTEXT]; int VideoSources; int VideoOutputs; int AudioSources; int AudioOutputs; int RelayOutputs;} onvifDeviceIOCapabilities;
typedef struct S_onvifDisplayCapabilities{ char XAddr[CTEXT]; bool FixedLayout;} onvifDisplayCapabilities;
typedef struct S_onvifRecordingCapabilities{ char XAddr[CTEXT]; bool ReceiverSource; bool MediaProfileSource; bool DynamicRecordings; bool DynamicTracks; int MaxStringLength;} onvifRecordingCapabilities;
typedef struct S_onvifSearchCapabilities{ char XAddr[CTEXT]; bool MetadataSearch;} onvifSearchCapabilities;
typedef struct S_onvifReplayCapabilities{ char XAddr[CTEXT];} onvifReplayCapabilities;
typedef struct S_onvifReceiverCapabilities{ char XAddr[CTEXT]; bool RTP_Multicast; bool RTP_TCP; bool RTP_RTSP_TCP; int SupportedReceivers; int MaximumRTSPURILength;} onvifReceiverCapabilities;
typedef struct S_onvifAnalyticsDeviceExtension{} onvifAnalyticsDeviceExtension;
typedef struct S_onvifAnalyticsDeviceCapabilities{ char XAddr[CTEXT]; bool RuleSupport; onvifAnalyticsDeviceExtension * Extension;} onvifAnalyticsDeviceCapabilities;
typedef struct S_onvifCapabilitiesExtension2{} onvifCapabilitiesExtension2;
typedef struct S_onvifCapabilitiesExtension{ onvifDeviceIOCapabilities * DeviceIO; onvifDisplayCapabilities * Display; onvifRecordingCapabilities * Recording; onvifSearchCapabilities * Search; onvifReplayCapabilities * Replay; onvifReceiverCapabilities * Receiver; onvifAnalyticsDeviceCapabilities * AnalyticsDevice; onvifCapabilitiesExtension2 * Extensions;} onvifCapabilitiesExtension;
typedef struct S_nodeCapability{ onvifAnalyticsCapabilities * Analytics; onvifDeviceCapabilities * Device; onvifEventCapabilities * Events; onvifImagingCapabilities * Imaging; onvifMediaCapabilities * Media; onvifPTZCapabilities * PTZ; onvifCapabilitiesExtension * Extension;} nodeCapability;
typedef struct S_discoveryNodeInfo{ char endpoint_uid[64]; char types[CTEXT]; char scopes[CTEXT]; char x_addrs[CTEXT]; char meta_version[10]; char ip_addrs[32];} discoveryNodeInfo;
class pOnvif;
typedef std::vector<videoSourceProfile *> videoSourceProfiles;typedef std::vector<videoSource *> videoSources;typedef std::vector<discoveryNodeInfo *> discoveryResults;
class pOnvif{ private: void cleanNodeCapability( nodeCapability *ptr ); curlRequestsManager * m_pHttpAccessManager; basicMutex m_mResponseProtector; CURL * m_pCURL; basicLogCollection * m_pLog; CSTR m_pIpAddress; CSTR m_pUsername; CSTR m_pPassword; CSTR m_pDeviceURI; int m_pLastIndex; CSTR m_pMediaURI; CSTR m_pSnapshotURI;
CSTR m_pPTZURI; CSTR m_pBaseURI; onvifSupportedVersions m_sOnvifVersion; time_t m_nDeltaTime; videoSources m_vVideoSources; videoSourceProfiles m_vVideoProfiles; videoSourceProfiles m_vActiveSources; nodeCapability m_sCapabilities; CSTR m_pProxyHost; int m_nProxyPort; CSTR m_pProxyUsername; CSTR m_pProxyPassword; CSTR m_pLastResponse; bool m_bIntransingent; time_t m_nDiscoveryTimeout; CSTR m_pDiscoveryBindIP; CSTR m_pDiscoveryMCastIP; int m_nDiscoveryMCastPort; bool m_bDiscoveryHideDuplicates; volatile bool parser_done; void * volatile m_pPendingRequest; // reply that _send_request is waiting for
basicMutex m_mParserLock; // parser() vs. _send_request bookkeeping
uint8_t m_bAuthMode; volatile long m_nLastHttpCode; // HTTP status of the last reply (set by parser())
onvifError m_eLastError; char m_cLastFault[CTEXT];#ifndef CURL_MANAGER
static int _writer(char * data, size_t size, size_t nmemb, pOnvif * Ptr);#endif
static void * parser(void * obj, void * ptr);
public:
pOnvif(); ~pOnvif(); bool setProxyHost(CSTR proxyHost); CSTR getProxyHost(void); bool setProxyPort(int proxyPort); int getProxyPort(void); bool setProxyUsername(CSTR proxyUsername); CSTR getProxyUsername(void); bool setProxyPassword(CSTR proxyPassword); CSTR getProxyPassword(void); bool setUsername(CSTR username); CSTR getUsername(void); bool setPassword(CSTR password); bool setAuthMode(uint8_t Mode); CSTR getPassword(void); CSTR getDeviceUri(void); bool setDeviceUri(CSTR deviceUri); CSTR getIPAddress(void); bool setIPAddress(CSTR ipAddress); videoSources * getSources(void); videoSourceProfiles * getProfiles(void); videoSourceProfiles * getActiveProfiles(void); CSTR getMediaUri(void); CSTR getPTZUri(void); CSTR getBaseUrl(void); void getSupportedVersion(void); nodeCapability * getCapabilities(void); bool setBreakOnError(bool intransingent); CSTR getLastResponse(void); bool setDiscoveryTimeout(int discoverytimeout); bool setDiscoveryBindIp(CSTR discoverybindip); bool setDiscoveryMcastIp(CSTR discoverymcastip); bool setDiscoveryMcastPort(int discoverymcastport); bool setDiscoveryHideDuplicates(bool discoveryhideduplicates); CSTR getSnapshotUri(void); onvifError getLastError(void); CSTR getLastFault(void); // First profile that has a PTZConfiguration, NULL if none
videoSourceProfile * getPTZProfile(void);
discoveryResults discover(void); bool create(void);
struct tm * core_GetSystemDateAndTime(void); bool core_GetCapabilities(); bool core_GetDeviceInformation();
bool media_GetVideoSources(); bool media_GetProfiles(); bool media_GetServices(); CSTR media_GetStreamUri(CSTR profileToken, CSTR stream = (CSTR) "RTP-Unicast", CSTR protocol = (CSTR) "RTSP"); CSTR media_GetSnapshotUri(CSTR profileToken);
bool ptz_GetPresets(CSTR profileToken); bool ptz_GetNode(CSTR ptzNodeToken); bool ptz_GetStatus(CSTR profileToken, ptzStatus * tStatus); // PTZ service capabilities (ONVIF PTZ GetServiceCapabilities).
// Each output is 1 = supported, 0 = not supported, -1 = not reported by the device.
bool ptz_GetServiceCapabilities(int8_t * moveStatus, int8_t * statusPosition); bool ptz_GotoPreset(CSTR profileToken, CSTR presetToken, float speed_pantilt_x, float speed_pantilt_y, float speed_zoom_x); bool ptz_RemovePreset(CSTR profileToken, CSTR presetToken); bool ptz_SetPreset(CSTR profileToken, CSTR presetName); bool ptz_RelativeMove(CSTR profileToken, float translation_pantilt_x, float translation_pantilt_y, float speed_pantilt_x, float speed_pantilt_y); bool ptz_RelativeMoveZoom(CSTR profileToken, float zoom, float speedZoom); bool ptz_AbsoluteMove(CSTR profileToken, float position_pantilt_x, float position_pantilt_y, float zoom); bool ptz_ContinuousMove(CSTR profileToken, float velocity_pantilt_x, float velocity_pantilt_y); bool ptz_ContinuousMoveZoom(CSTR profileToken, float zoom); // One ContinuousMove for pan/tilt and zoom; axes with has* == false are left out of the request
bool ptz_ContinuousMoveAll(CSTR profileToken, bool hasPanTilt, float velocity_pantilt_x, float velocity_pantilt_y, bool hasZoom, float velocity_zoom, int timeoutSec = PONVIF_CONTINUOUS_MOVE_TIMEOUT_S); bool ptz_Stop(CSTR profileToken, bool pantilt, bool zoom); /*
Internal functions */ public:
// XML-escape src into dst (&, <, >, ", '); always NUL-terminates
static char * _xmlEscape(const char * src, char * dst, size_t dstSize);
private:
accessToken _makeToken(void); void _getOnvifVersion(nodeCapability & capabilities); void _getActiveSources(videoSourceProfiles & videoSources, videoSourceProfiles profiles); void _getProfileData(videoSourceProfiles & videoSources, videoSourceProfiles profiles); // protected function _xml2array($response);
accessToken _passwordDigest(CSTR username, CSTR password, time_t timestamp = 0); bool _hasCredentials(void); // Envelope + (WS-Security header if credentials are set) + body built from bodyFmt
bool _buildRequest(char * out, size_t outSize, const char * bodyFmt, ...) __attribute__((format(printf, 4, 5))); bool _checkReply(void); bool _send_request(CSTR url, CSTR post_string, bool mr = true); bool _post_request(CSTR url, CSTR post_string);};
#endif
|