la_mojo pOnvif: ONVIF compliance fixes #13

Merged
ClaudeAI merged 1 commits from feature/ponvif-compliance into master 20 minutes ago
Collaborator

Summary

This fixes points 1-6 of the pOnvif ONVIF compliance review. Point 2 (the request/reply race) was already fixed in #11; it was only re-checked here.

Changes

  1. Camera errors are no longer reported as success.
    • Every request now waits for the answer and checks the HTTP status and any SOAP Fault. Faults are logged with Code, Subcode and Reason.
    • getLastError() and getLastFault() tell the caller what happened.
    • protocolPTZ_ONVIF treats only a communication error as a lost camera. Clearing m_bStatus makes validate() fail and triggers a reconnect; a Fault from a reachable camera no longer does that.
    • AbsoluteMove now waits for its answer too.
  2. Optional elements are read without crashing.
    • New NULL-safe helpers replace every unchecked getText() / getAttribute() read.
    • videoSource is zero-filled.
    • Imaging values are read as floats.
    • IrCutFilter AUTO is no longer read as OFF.
    • A missing XAddr no longer becomes the string "(null)".
    • A device that sends no UTCDateTime no longer breaks the WS-Security timestamp; the local clock is used instead.
  3. PTZ profile selection. GetProfiles now parses PTZConfiguration, and PTZ uses the first profile that has one. If none has it, profile 0 is used and an error is logged. A device with no profiles makes create() fail cleanly instead of throwing.
  4. ContinuousMove. Pan/tilt and zoom are sent in one request with Timeout PT10S (PONVIF_CONTINUOUS_MOVE_TIMEOUT_S). Stop honours its pantilt and zoom flags.
  5. WS-Security and HTTP auth.
    • The nonce is 16 bytes from RAND_bytes.
    • The digest buffer is sized to fit any password.
    • The security header is only added when a user name is set, so anonymous devices work.
    • The user name and all string arguments are XML-escaped.
    • Requests are built by _buildRequest() from body templates.
    • HTTP auth mode 0 now uses CURLAUTH_ANY instead of Basic. No password is sent until the device asks, and Digest is preferred.

Also fixed:

  • the trailing ; in the Content-Type;
  • GetServices and GetDeviceInformation are sent to the device service;
  • printf(reply) format-string bugs.

Testing

  • g++ -fsyntax-only with the la_mojo flags: pOnvif now compiles with no warnings.

  • A simulated strict camera, run under AddressSanitizer and UBSan. The camera:

    • parses every request as XML;
    • verifies the WS-Security digest, with a user name and password containing & < ";
    • can demand HTTP Digest, omit optional elements and send Faults.

    These cases passed:

    • normal, anonymous, HTTP Digest required, no UTC time;
    • a camera without zoom: the Fault fails the move, but the connection stays OK;
    • a lost connection: validate() turns false;
    • the AbsoluteMove wait from #11, with unchanged timings.
  • Not tested on a real camera.

Behaviour changes

  • Mode 0 and Digest cameras: mode 0 no longer sends Basic proactively. Cameras that demand HTTP auth need two round trips per request.
  • ContinuousMove timeout: a continuous move that is not re-sent stops after 10 s.

Generated with Claude Code

https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16

## Summary This fixes points 1-6 of the pOnvif ONVIF compliance review. Point 2 (the request/reply race) was already fixed in #11; it was only re-checked here. ## Changes 1. **Camera errors are no longer reported as success.** - Every request now waits for the answer and checks the HTTP status and any SOAP Fault. Faults are logged with Code, Subcode and Reason. - `getLastError()` and `getLastFault()` tell the caller what happened. - `protocolPTZ_ONVIF` treats only a communication error as a lost camera. Clearing `m_bStatus` makes `validate()` fail and triggers a reconnect; a Fault from a reachable camera no longer does that. - AbsoluteMove now waits for its answer too. 3. **Optional elements are read without crashing.** - New NULL-safe helpers replace every unchecked `getText()` / `getAttribute()` read. - `videoSource` is zero-filled. - Imaging values are read as floats. - IrCutFilter AUTO is no longer read as OFF. - A missing XAddr no longer becomes the string "(null)". - A device that sends no UTCDateTime no longer breaks the WS-Security timestamp; the local clock is used instead. 4. **PTZ profile selection.** GetProfiles now parses PTZConfiguration, and PTZ uses the first profile that has one. If none has it, profile 0 is used and an error is logged. A device with no profiles makes `create()` fail cleanly instead of throwing. 5. **ContinuousMove.** Pan/tilt and zoom are sent in one request with `Timeout PT10S` (`PONVIF_CONTINUOUS_MOVE_TIMEOUT_S`). Stop honours its pantilt and zoom flags. 6. **WS-Security and HTTP auth.** - The nonce is 16 bytes from `RAND_bytes`. - The digest buffer is sized to fit any password. - The security header is only added when a user name is set, so anonymous devices work. - The user name and all string arguments are XML-escaped. - Requests are built by `_buildRequest()` from body templates. - HTTP auth mode 0 now uses `CURLAUTH_ANY` instead of Basic. No password is sent until the device asks, and Digest is preferred. **Also fixed:** - the trailing `;` in the Content-Type; - GetServices and GetDeviceInformation are sent to the device service; - `printf(reply)` format-string bugs. ## Testing - `g++ -fsyntax-only` with the la_mojo flags: pOnvif now compiles with no warnings. - A simulated strict camera, run under AddressSanitizer and UBSan. The camera: - parses every request as XML; - verifies the WS-Security digest, with a user name and password containing `& < "`; - can demand HTTP Digest, omit optional elements and send Faults. These cases passed: - normal, anonymous, HTTP Digest required, no UTC time; - a camera without zoom: the Fault fails the move, but the connection stays OK; - a lost connection: `validate()` turns false; - the AbsoluteMove wait from #11, with unchanged timings. - **Not tested on a real camera.** ## Behaviour changes - **Mode 0 and Digest cameras:** mode 0 no longer sends Basic proactively. Cameras that demand HTTP auth need two round trips per request. - **ContinuousMove timeout:** a continuous move that is not re-sent stops after 10 s. Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
ClaudeAI added 1 commit 23 minutes ago
3d4a1f243d
la_mojo pOnvif: ONVIF compliance fixes (report points 1-6)
ClaudeAI merged commit 22d119ab71 into master 20 minutes ago
The pull request has been merged as 22d119ab71.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.