From 8740c7049def83d8858204486aa3686877f75865 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 20 Nov 2026 00:53:18 -0500 Subject: [PATCH 1/3] Apply suggested fix to src/video/onvif_detection.c from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/video/onvif_detection.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/video/onvif_detection.c b/src/video/onvif_detection.c index 9f16c0fba..7b416a422 100644 --- a/src/video/onvif_detection.c +++ b/src/video/onvif_detection.c @@ -350,19 +350,22 @@ static char *create_onvif_request(const char *username, const char *password, snprintf(soap_request, envelope_size, "" "" - "" + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" " + "xmlns:onvif=\"urn:lightsensor:onvif:internal\">" + "" "urn:uuid:%s" "%s" "%s" - "%s" + "%s" "%s" "" "%s" "", - ref_namespaces ? ref_namespaces : "", uuid, destination_xml, action, - ref_params ? ref_params : "", security_header, request_body); + uuid, destination_xml, action, + ref_namespaces ? ref_namespaces : "", + ref_params ? ref_params : "", + security_header, request_body); free(security_header); free(destination_xml); From 7a02efe6d75125b6704d3d01645414c115769e5a Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 20 Nov 2026 00:57:38 -0500 Subject: [PATCH 2/3] Keep ONVIF reference parameters as direct SOAP headers --- src/video/onvif_detection.c | 26 ++++++++++++++++++-------- tests/unit/test_onvif_transport.c | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/video/onvif_detection.c b/src/video/onvif_detection.c index 7b416a422..15a8be35a 100644 --- a/src/video/onvif_detection.c +++ b/src/video/onvif_detection.c @@ -350,22 +350,19 @@ static char *create_onvif_request(const char *username, const char *password, snprintf(soap_request, envelope_size, "" "" - "" + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "" "urn:uuid:%s" "%s" "%s" - "%s" + "%s" "%s" "" "%s" "", - uuid, destination_xml, action, - ref_namespaces ? ref_namespaces : "", - ref_params ? ref_params : "", - security_header, request_body); + ref_namespaces ? ref_namespaces : "", uuid, destination_xml, action, + ref_params ? ref_params : "", security_header, request_body); free(security_header); free(destination_xml); @@ -614,6 +611,19 @@ static bool extract_subscription_endpoint_reference(const char *response, const char *name = node->attr[i]; if (strcmp(name, "xmlns") != 0 && strncmp(name, "xmlns:", 6) != 0) continue; + /* Keep SOAP and WS-Addressing header names bound to their + * required namespaces. Camera-supplied bindings may only + * provide namespaces for reference parameter children. */ + if (strcmp(name, "xmlns:s") == 0 || + strcmp(name, "xmlns:wsa") == 0) { + const char *expected = strcmp(name, "xmlns:s") == 0 ? + "http://www.w3.org/2003/05/soap-envelope" : + "http://www.w3.org/2005/08/addressing"; + if (strcmp(node->attr[i + 1], expected) != 0) ok = false; + continue; + } + if (strcmp(name, "xmlns:xml") == 0 || + strcmp(name, "xmlns:xmlns") == 0) continue; bool seen = false; for (size_t j = 0; j < count; j++) if (strcmp(name, names[j]) == 0) seen = true; diff --git a/tests/unit/test_onvif_transport.c b/tests/unit/test_onvif_transport.c index cc9e226da..5043f6646 100644 --- a/tests/unit/test_onvif_transport.c +++ b/tests/unit/test_onvif_transport.c @@ -665,6 +665,8 @@ static void test_subscription_reference_parameters_become_soap_headers(void) { ezxml_t parsed = ezxml_parse_str(request, strlen(request)); TEST_ASSERT_NOT_NULL(parsed); TEST_ASSERT_EQUAL_STRING("", ezxml_error(parsed)); + TEST_ASSERT_NOT_NULL(child_by_local_name(child_by_local_name(parsed, "Header"), + "Token")); ezxml_free(parsed); free(request); free(namespaces); @@ -672,6 +674,24 @@ static void test_subscription_reference_parameters_become_soap_headers(void) { free(address); } +static void test_subscription_reference_cannot_rebind_soap_namespace(void) { + const char *reply = + "" + "" + "http://camera/onvif/pull" + "" + "abc" + "" + ""; + char *address = NULL, *params = NULL, *namespaces = NULL; + TEST_ASSERT_FALSE(extract_subscription_endpoint_reference(reply, &address, + ¶ms, &namespaces)); + TEST_ASSERT_NULL(address); + TEST_ASSERT_NULL(params); + TEST_ASSERT_NULL(namespaces); +} + static void test_motion_requires_asserted_state_not_truthy_metadata(void) { char label[32]; const char *metadata_only = @@ -741,6 +761,7 @@ int main(void) { RUN_TEST(test_motorcycle_class_precedes_bicycle_substrings); RUN_TEST(test_malformed_motion_message_uses_truthy_fallback); RUN_TEST(test_subscription_reference_parameters_become_soap_headers); + RUN_TEST(test_subscription_reference_cannot_rebind_soap_namespace); RUN_TEST(test_motion_requires_asserted_state_not_truthy_metadata); RUN_TEST(test_class_flags_ignore_camera_metadata); return UNITY_END(); From 81466b0dbf7cf4201d9623b1f3f2f7c753546056 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 06:06:00 +0000 Subject: [PATCH 3/3] lightnvr-rs: regenerate from C Generated by tools/rust-transpile/generate.py for 3bdcda1. --- rust/MANIFEST.json | 4 +- rust/generated/src__video__onvif_detection.rs | 95 +++++++++++++------ 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/rust/MANIFEST.json b/rust/MANIFEST.json index 20bc65cd4..9fe51fc7c 100644 --- a/rust/MANIFEST.json +++ b/rust/MANIFEST.json @@ -1123,9 +1123,9 @@ }, { "c": "src/video/onvif_detection.c", - "c_sha256": "4ba3b84c66ae8bfbd39120543e63f43f20faa99215d09ef9387f5d22b8bf9a4c", + "c_sha256": "9313061c20f31118c8ba6f26724dfcbf490c33a99898d72d0c6db4b64ccbe60a", "rust": "generated/src__video__onvif_detection.rs", - "rust_sha256": "31c62475756d219ed23b09954c5a861b11a378d05ce7a5ae15ae04bdb73260ae", + "rust_sha256": "0ead02bd229fcb501a56f8f8b9b71c1c310cf0f3f3529d1944ff2fba67a7ff2f", "adapted": true }, { diff --git a/rust/generated/src__video__onvif_detection.rs b/rust/generated/src__video__onvif_detection.rs index 3c92642de..c5dfd2aaf 100644 --- a/rust/generated/src__video__onvif_detection.rs +++ b/rust/generated/src__video__onvif_detection.rs @@ -3160,36 +3160,75 @@ unsafe extern "C" fn extract_subscription_endpoint_reference( 6 as size_t, ) != 0 as ::core::ffi::c_int) { - let mut seen: bool = r#false != 0; - let mut j: size_t = 0 as size_t; - while j < count { - if strcmp(name, names[j]) == 0 as ::core::ffi::c_int { - seen = r#true != 0; - } - j = j.wrapping_add(1); - } - if !seen { - if count - >= ::core::mem::size_of::<[*const ::core::ffi::c_char; 32]>( - ) - .wrapping_div( - ::core::mem::size_of::<*const ::core::ffi::c_char>(), - ) - || !append_reference_namespace( - &raw mut namespaces as *mut ::core::ffi::c_char, - ::core::mem::size_of::<[::core::ffi::c_char; 1024]>(), - name, - *(*node) - .attr - .offset(i.wrapping_add(1 as size_t) as isize), - ) + if strcmp(name, b"xmlns:s\0".as_ptr() as *const ::core::ffi::c_char) + == 0 as ::core::ffi::c_int + || strcmp( + name, + b"xmlns:wsa\0".as_ptr() as *const ::core::ffi::c_char, + ) == 0 as ::core::ffi::c_int + { + let mut expected: *const ::core::ffi::c_char = if strcmp( + name, + b"xmlns:s\0".as_ptr() as *const ::core::ffi::c_char, + ) == 0 + as ::core::ffi::c_int { - ok = r#false != 0; - break; + b"http://www.w3.org/2003/05/soap-envelope\0".as_ptr() + as *const ::core::ffi::c_char } else { - let c2rust_fresh2 = count; - count = count.wrapping_add(1); - names[c2rust_fresh2] = name; + b"http://www.w3.org/2005/08/addressing\0".as_ptr() + as *const ::core::ffi::c_char + }; + if strcmp( + *(*node).attr.offset(i.wrapping_add(1 as size_t) as isize), + expected, + ) != 0 as ::core::ffi::c_int + { + ok = r#false != 0; + } + } else if !(strcmp( + name, + b"xmlns:xml\0".as_ptr() as *const ::core::ffi::c_char, + ) == 0 as ::core::ffi::c_int + || strcmp( + name, + b"xmlns:xmlns\0".as_ptr() as *const ::core::ffi::c_char, + ) == 0 as ::core::ffi::c_int) + { + let mut seen: bool = r#false != 0; + let mut j: size_t = 0 as size_t; + while j < count { + if strcmp(name, names[j]) == 0 as ::core::ffi::c_int { + seen = r#true != 0; + } + j = j.wrapping_add(1); + } + if !seen { + if count + >= ::core::mem::size_of::< + [*const ::core::ffi::c_char; 32], + >() + .wrapping_div(::core::mem::size_of::< + *const ::core::ffi::c_char, + >( + )) + || !append_reference_namespace( + &raw mut namespaces as *mut ::core::ffi::c_char, + ::core::mem::size_of::<[::core::ffi::c_char; 1024]>( + ), + name, + *(*node) + .attr + .offset(i.wrapping_add(1 as size_t) as isize), + ) + { + ok = r#false != 0; + break; + } else { + let c2rust_fresh2 = count; + count = count.wrapping_add(1); + names[c2rust_fresh2] = name; + } } } }