diff --git a/rust/MANIFEST.json b/rust/MANIFEST.json index 9fe51fc7c..ed5e6ca9a 100644 --- a/rust/MANIFEST.json +++ b/rust/MANIFEST.json @@ -1123,9 +1123,9 @@ }, { "c": "src/video/onvif_detection.c", - "c_sha256": "9313061c20f31118c8ba6f26724dfcbf490c33a99898d72d0c6db4b64ccbe60a", + "c_sha256": "61d4bba85f2224c5d0fd8eb898576976b3319441ab3198741700b42ae1dd50d1", "rust": "generated/src__video__onvif_detection.rs", - "rust_sha256": "0ead02bd229fcb501a56f8f8b9b71c1c310cf0f3f3529d1944ff2fba67a7ff2f", + "rust_sha256": "1ab808faae203105881837996bed3478ddf3c37a7262f76ce32ee55f0a02153c", "adapted": true }, { diff --git a/rust/generated/src__video__onvif_detection.rs b/rust/generated/src__video__onvif_detection.rs index c5dfd2aaf..67cce6e39 100644 --- a/rust/generated/src__video__onvif_detection.rs +++ b/rust/generated/src__video__onvif_detection.rs @@ -47,6 +47,11 @@ unsafe extern "C" { part: *const ::core::ffi::c_char, flags: ::core::ffi::c_uint, ) -> CURLUcode; + unsafe fn url_redact_for_logging( + url: *const ::core::ffi::c_char, + out_url: *mut ::core::ffi::c_char, + out_size: size_t, + ) -> ::core::ffi::c_int; unsafe fn url_is_http_endpoint(url: *const ::core::ffi::c_char) -> bool; unsafe fn pthread_once( __once_control: *mut pthread_once_t, @@ -137,6 +142,11 @@ unsafe extern "C" { unsafe fn ezxml_error(xml: ezxml_t) -> *const ::core::ffi::c_char; unsafe fn ezxml_new(name: *const ::core::ffi::c_char) -> ezxml_t; unsafe fn ezxml_set_txt(xml: ezxml_t, txt: *const ::core::ffi::c_char) -> ezxml_t; + unsafe fn ezxml_set_attr( + xml: ezxml_t, + name: *const ::core::ffi::c_char, + value: *const ::core::ffi::c_char, + ) -> ezxml_t; unsafe fn db_lpr_read_insert( input: *const lpr_read_input_t, uuid_out: *mut ::core::ffi::c_char, @@ -2060,1191 +2070,1227 @@ unsafe extern "C" fn extract_subscription_endpoint_reference( && !ref_params.is_null() && !(*ref_params).child.is_null() { - let mut xml: *mut ::core::ffi::c_char = ezxml_toxml(ref_params); - let mut start: *const ::core::ffi::c_char = if !xml.is_null() { - strchr(xml, '>' as ::core::ffi::c_int) - } else { - ::core::ptr::null_mut::<::core::ffi::c_char>() - }; - let mut end: *const ::core::ffi::c_char = if !xml.is_null() { - strrchr(xml, '<' as ::core::ffi::c_int) - } else { - ::core::ptr::null_mut::<::core::ffi::c_char>() - }; - if !start.is_null() - && !end.is_null() - && end > start.offset(1 as ::core::ffi::c_int as isize) - { - *out_ref_params_xml = strndup( - start.offset(1 as ::core::ffi::c_int as isize), - (end.offset_from(start) - 1isize) as size_t, + let mut param: ezxml_t = (*ref_params).child; + while !param.is_null() { + let mut binding: *const ::core::ffi::c_char = ezxml_attr( + param, + b"xmlns:wsa\0".as_ptr() as *const ::core::ffi::c_char, ); + if !binding.is_null() + && strcmp( + binding, + b"http://www.w3.org/2005/08/addressing\0".as_ptr() + as *const ::core::ffi::c_char, + ) != 0 as ::core::ffi::c_int + { + ok = r#false != 0; + break; + } else { + ezxml_set_attr( + param, + b"wsa:IsReferenceParameter\0".as_ptr() + as *const ::core::ffi::c_char, + b"true\0".as_ptr() as *const ::core::ffi::c_char, + ); + param = (*param).ordered; + } } - if !xml.is_null() { - free(xml as *mut ::core::ffi::c_void); - } - let mut namespaces: [::core::ffi::c_char; 1024] = [ - 0 as ::core::ffi::c_char, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ]; - let mut names: [*const ::core::ffi::c_char; 32] = [ - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ::core::ptr::null::<::core::ffi::c_char>(), - ]; - let mut count: size_t = 0 as size_t; - let mut node: ezxml_t = ref_params; - while !node.is_null() { - let mut i: size_t = 0 as size_t; - while !(*node).attr.is_null() - && !(*(*node).attr.offset(i as isize)).is_null() + if ok { + let mut xml: *mut ::core::ffi::c_char = ezxml_toxml(ref_params); + let mut start: *const ::core::ffi::c_char = if !xml.is_null() { + strchr(xml, '>' as ::core::ffi::c_int) + } else { + ::core::ptr::null_mut::<::core::ffi::c_char>() + }; + let mut end: *const ::core::ffi::c_char = if !xml.is_null() { + strrchr(xml, '<' as ::core::ffi::c_int) + } else { + ::core::ptr::null_mut::<::core::ffi::c_char>() + }; + if !start.is_null() + && !end.is_null() + && end > start.offset(1 as ::core::ffi::c_int as isize) { - let mut name: *const ::core::ffi::c_char = - *(*node).attr.offset(i as isize); - if !(strcmp(name, b"xmlns\0".as_ptr() as *const ::core::ffi::c_char) - != 0 as ::core::ffi::c_int - && strncmp( - name, - b"xmlns:\0".as_ptr() as *const ::core::ffi::c_char, - 6 as size_t, - ) != 0 as ::core::ffi::c_int) + *out_ref_params_xml = strndup( + start.offset(1 as ::core::ffi::c_int as isize), + (end.offset_from(start) - 1isize) as size_t, + ); + } + if !xml.is_null() { + free(xml as *mut ::core::ffi::c_void); + } + let mut namespaces: [::core::ffi::c_char; 1024] = [ + 0 as ::core::ffi::c_char, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ]; + let mut names: [*const ::core::ffi::c_char; 32] = [ + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ::core::ptr::null::<::core::ffi::c_char>(), + ]; + let mut count: size_t = 0 as size_t; + let mut node: ezxml_t = ref_params; + while !node.is_null() { + let mut i: size_t = 0 as size_t; + while !(*node).attr.is_null() + && !(*(*node).attr.offset(i as isize)).is_null() { - if strcmp(name, b"xmlns:s\0".as_ptr() as *const ::core::ffi::c_char) - == 0 as ::core::ffi::c_int - || strcmp( + let mut name: *const ::core::ffi::c_char = + *(*node).attr.offset(i as isize); + if !(strcmp( + name, + b"xmlns\0".as_ptr() as *const ::core::ffi::c_char, + ) != 0 as ::core::ffi::c_int + && strncmp( name, - b"xmlns:wsa\0".as_ptr() as *const ::core::ffi::c_char, - ) == 0 as ::core::ffi::c_int + b"xmlns:\0".as_ptr() as *const ::core::ffi::c_char, + 6 as size_t, + ) != 0 as ::core::ffi::c_int) { - let mut expected: *const ::core::ffi::c_char = if strcmp( + if strcmp( name, b"xmlns:s\0".as_ptr() as *const ::core::ffi::c_char, - ) == 0 - as ::core::ffi::c_int - { - b"http://www.w3.org/2003/05/soap-envelope\0".as_ptr() - as *const ::core::ffi::c_char - } else { - 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 + ) == 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 { - 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), - ) + 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; + } } } } + i = i.wrapping_add(2 as size_t); + } + if !ok { + break; } - i = i.wrapping_add(2 as size_t); + node = (*node).parent; } - if !ok { - break; + if ok { + *out_ref_namespaces = + strdup(&raw mut namespaces as *mut ::core::ffi::c_char); + } + if (*out_ref_params_xml).is_null() || (*out_ref_namespaces).is_null() { + ok = r#false != 0; } - node = (*node).parent; - } - if ok { - *out_ref_namespaces = - strdup(&raw mut namespaces as *mut ::core::ffi::c_char); - } - if (*out_ref_params_xml).is_null() || (*out_ref_namespaces).is_null() { - ok = r#false != 0; } } } @@ -3651,6 +3697,20 @@ unsafe extern "C" fn subscription_address_matches_camera_host( } return ok; } +unsafe extern "C" fn onvif_camera_log_id( + mut url: *const ::core::ffi::c_char, + mut out: *mut ::core::ffi::c_char, + mut size: size_t, +) { + if url_redact_for_logging(url, out, size) != 0 as ::core::ffi::c_int { + safe_strcpy( + out, + b"[invalid-url]\0".as_ptr() as *const ::core::ffi::c_char, + size, + 0 as size_t, + ); + } +} unsafe extern "C" fn send_subscription_request( mut subscription: *mut onvif_subscription_t, mut request_body: *const ::core::ffi::c_char, @@ -3783,13 +3843,19 @@ unsafe extern "C" fn send_subscription_request( if (*subscription).curl.is_null() { free(target_url as *mut ::core::ffi::c_void); pthread_mutex_unlock(lock); + let mut camera_id: [::core::ffi::c_char; 512] = [0; 512]; + onvif_camera_log_id( + &raw mut (*subscription).camera_url as *mut ::core::ffi::c_char, + &raw mut camera_id as *mut ::core::ffi::c_char, + ::core::mem::size_of::<[::core::ffi::c_char; 512]>(), + ); _log_message_ctx( log_level_t::LOG_LEVEL_ERROR, LOG_COMPONENT, _log_stream_name, b"Failed to create a curl handle for the ONVIF subscription of %s\0".as_ptr() as *const ::core::ffi::c_char, - &raw mut (*subscription).camera_url as *mut ::core::ffi::c_char, + &raw mut camera_id as *mut ::core::ffi::c_char, ); return ::core::ptr::null_mut::<::core::ffi::c_char>(); } @@ -3881,13 +3947,19 @@ unsafe extern "C" fn renew_subscription_locked( let mut lease_seconds: ::core::ffi::c_int = subscription_lease_seconds(response); free(response as *mut ::core::ffi::c_void); apply_subscription_lease(subscription, lease_seconds); + let mut camera_id: [::core::ffi::c_char; 512] = [0; 512]; + onvif_camera_log_id( + &raw mut (*subscription).camera_url as *mut ::core::ffi::c_char, + &raw mut camera_id as *mut ::core::ffi::c_char, + ::core::mem::size_of::<[::core::ffi::c_char; 512]>(), + ); _log_message_ctx( log_level_t::LOG_LEVEL_DEBUG, LOG_COMPONENT, _log_stream_name, b"Renewed ONVIF subscription for %s for %d seconds\0".as_ptr() as *const ::core::ffi::c_char, - &raw mut (*subscription).camera_url as *mut ::core::ffi::c_char, + &raw mut camera_id as *mut ::core::ffi::c_char, lease_seconds, ); return r#true != 0; @@ -3914,6 +3986,12 @@ unsafe extern "C" fn unsubscribe_subscription_locked(mut subscription: *mut onvi ::core::ptr::null_mut::(), ::core::ptr::null::<::core::ffi::c_char>(), ); + let mut camera_id: [::core::ffi::c_char; 512] = [0; 512]; + onvif_camera_log_id( + &raw mut (*subscription).camera_url as *mut ::core::ffi::c_char, + &raw mut camera_id as *mut ::core::ffi::c_char, + ::core::mem::size_of::<[::core::ffi::c_char; 512]>(), + ); if !response.is_null() { free(response as *mut ::core::ffi::c_void); _log_message_ctx( @@ -3921,7 +3999,7 @@ unsafe extern "C" fn unsubscribe_subscription_locked(mut subscription: *mut onvi LOG_COMPONENT, _log_stream_name, b"Unsubscribed ONVIF PullPoint for %s\0".as_ptr() as *const ::core::ffi::c_char, - &raw mut (*subscription).camera_url as *mut ::core::ffi::c_char, + &raw mut camera_id as *mut ::core::ffi::c_char, ); } else { _log_message_ctx( @@ -3930,7 +4008,7 @@ unsafe extern "C" fn unsubscribe_subscription_locked(mut subscription: *mut onvi _log_stream_name, b"Unable to unsubscribe ONVIF PullPoint for %s\0".as_ptr() as *const ::core::ffi::c_char, - &raw mut (*subscription).camera_url as *mut ::core::ffi::c_char, + &raw mut camera_id as *mut ::core::ffi::c_char, ); } (*subscription).active = r#false != 0; @@ -5031,6 +5109,12 @@ unsafe extern "C" fn note_pull_failure(mut camera_url: *const ::core::ffi::c_cha (*subscription).first_pull_failure_time = now; } (*subscription).consecutive_pull_failures += 1; + let mut camera_id: [::core::ffi::c_char; 512] = [0; 512]; + onvif_camera_log_id( + camera_url, + &raw mut camera_id as *mut ::core::ffi::c_char, + ::core::mem::size_of::<[::core::ffi::c_char; 512]>(), + ); if (*subscription).consecutive_pull_failures == ONVIF_PULL_FAILURE_WARN_COUNT { _log_message_ctx( log_level_t::LOG_LEVEL_WARN, @@ -5038,7 +5122,7 @@ unsafe extern "C" fn note_pull_failure(mut camera_url: *const ::core::ffi::c_cha _log_stream_name, b"ONVIF PullPoint for %s has failed %d consecutive pulls; retaining the same subscription\0" .as_ptr() as *const ::core::ffi::c_char, - camera_url, + &raw mut camera_id as *mut ::core::ffi::c_char, (*subscription).consecutive_pull_failures, ); } @@ -5052,7 +5136,7 @@ unsafe extern "C" fn note_pull_failure(mut camera_url: *const ::core::ffi::c_cha _log_stream_name, b"ONVIF PullPoint for %s has not completed a pull for %d seconds; unsubscribing before refresh\0" .as_ptr() as *const ::core::ffi::c_char, - camera_url, + &raw mut camera_id as *mut ::core::ffi::c_char, 120 as ::core::ffi::c_int, ); (*subscription).reserved = r#true != 0; @@ -5080,13 +5164,19 @@ unsafe extern "C" fn note_pull_success(mut camera_url: *const ::core::ffi::c_cha i += 1; } else { if (*subscription).consecutive_pull_failures >= ONVIF_PULL_FAILURE_WARN_COUNT { + let mut camera_id: [::core::ffi::c_char; 512] = [0; 512]; + onvif_camera_log_id( + camera_url, + &raw mut camera_id as *mut ::core::ffi::c_char, + ::core::mem::size_of::<[::core::ffi::c_char; 512]>(), + ); _log_message_ctx( log_level_t::LOG_LEVEL_INFO, LOG_COMPONENT, _log_stream_name, b"ONVIF PullPoint for %s recovered after %d failed pulls\0".as_ptr() as *const ::core::ffi::c_char, - camera_url, + &raw mut camera_id as *mut ::core::ffi::c_char, (*subscription).consecutive_pull_failures, ); } diff --git a/src/video/onvif_detection.c b/src/video/onvif_detection.c index 15a8be35a..9d2fb17bc 100644 --- a/src/video/onvif_detection.c +++ b/src/video/onvif_detection.c @@ -595,6 +595,16 @@ static bool extract_subscription_endpoint_reference(const char *response, if (*out_address) { ok = true; if (out_ref_params_xml && out_ref_namespaces && ref_params && ref_params->child) { + for (ezxml_t param = ref_params->child; param; param = param->ordered) { + const char *binding = ezxml_attr(param, "xmlns:wsa"); + if (binding && strcmp(binding, + "http://www.w3.org/2005/08/addressing") != 0) { + ok = false; + break; + } + ezxml_set_attr(param, "wsa:IsReferenceParameter", "true"); + } + if (!ok) goto endpoint_parsed; char *xml = ezxml_toxml(ref_params); const char *start = xml ? strchr(xml, '>') : NULL; const char *end = xml ? strrchr(xml, '<') : NULL; @@ -645,6 +655,8 @@ static bool extract_subscription_endpoint_reference(const char *response, } } +endpoint_parsed: + if (root) ezxml_free(root); free(copy); if (!ok) { @@ -827,6 +839,11 @@ static bool subscription_address_matches_camera_host(const char *camera_url, return ok; } +static void onvif_camera_log_id(const char *url, char *out, size_t size) { + if (url_redact_for_logging(url, out, size) != 0) + safe_strcpy(out, "[invalid-url]", size, 0); +} + /* Send a subscription-scoped request (PullMessages, Renew, Unsubscribe) to the * SubscriptionReference address on the subscription's own connection. * Transport drops are retried on the same subscription @@ -890,8 +907,10 @@ static char *send_subscription_request(onvif_subscription_t *subscription, if (!subscription->curl) { free(target_url); pthread_mutex_unlock(lock); + char camera_id[sizeof(subscription->camera_url)]; + onvif_camera_log_id(subscription->camera_url, camera_id, sizeof(camera_id)); log_error("Failed to create a curl handle for the ONVIF subscription of %s", - subscription->camera_url); + camera_id); return NULL; } while (attempts < ONVIF_PULL_DROP_MAX_ATTEMPTS) { @@ -947,8 +966,10 @@ static bool renew_subscription_locked(onvif_subscription_t *subscription) { int lease_seconds = subscription_lease_seconds(response); free(response); apply_subscription_lease(subscription, lease_seconds); + char camera_id[sizeof(subscription->camera_url)]; + onvif_camera_log_id(subscription->camera_url, camera_id, sizeof(camera_id)); log_debug("Renewed ONVIF subscription for %s for %d seconds", - subscription->camera_url, lease_seconds); + camera_id, lease_seconds); return true; } @@ -965,12 +986,14 @@ static void unsubscribe_subscription_locked(onvif_subscription_t *subscription) ""; char *response = send_subscription_request(subscription, request_body, ONVIF_OPERATION_UNSUBSCRIBE, NULL, NULL); + char camera_id[sizeof(subscription->camera_url)]; + onvif_camera_log_id(subscription->camera_url, camera_id, sizeof(camera_id)); if (response) { free(response); - log_debug("Unsubscribed ONVIF PullPoint for %s", subscription->camera_url); + log_debug("Unsubscribed ONVIF PullPoint for %s", camera_id); } else { log_warn("Unable to unsubscribe ONVIF PullPoint for %s", - subscription->camera_url); + camera_id); } subscription->active = false; release_subscription_curl(subscription); @@ -1320,12 +1343,14 @@ static void note_pull_failure(const char *camera_url) { subscription->first_pull_failure_time = now; } subscription->consecutive_pull_failures++; + char camera_id[sizeof(subscription->camera_url)]; + onvif_camera_log_id(camera_url, camera_id, sizeof(camera_id)); if (subscription->consecutive_pull_failures == ONVIF_PULL_FAILURE_WARN_COUNT) { log_warn("ONVIF PullPoint for %s has failed %d consecutive pulls; " "retaining the same subscription", - camera_url, subscription->consecutive_pull_failures); + camera_id, subscription->consecutive_pull_failures); } if (subscription->consecutive_pull_failures >= @@ -1334,7 +1359,7 @@ static void note_pull_failure(const char *camera_url) { ONVIF_PULL_FAILURE_REFRESH_SECONDS) { log_warn("ONVIF PullPoint for %s has not completed a pull for %d " "seconds; unsubscribing before refresh", - camera_url, ONVIF_PULL_FAILURE_REFRESH_SECONDS); + camera_id, ONVIF_PULL_FAILURE_REFRESH_SECONDS); subscription->reserved = true; pthread_mutex_unlock(&subscription_mutex); unsubscribe_subscription_locked(subscription); @@ -1354,8 +1379,10 @@ static void note_pull_success(const char *camera_url) { if (subscription->consecutive_pull_failures >= ONVIF_PULL_FAILURE_WARN_COUNT) { + char camera_id[sizeof(subscription->camera_url)]; + onvif_camera_log_id(camera_url, camera_id, sizeof(camera_id)); log_info("ONVIF PullPoint for %s recovered after %d failed pulls", - camera_url, subscription->consecutive_pull_failures); + camera_id, subscription->consecutive_pull_failures); } subscription->consecutive_pull_failures = 0; subscription->first_pull_failure_time = 0; diff --git a/tests/unit/test_onvif_transport.c b/tests/unit/test_onvif_transport.c index 5043f6646..82f7be61f 100644 --- a/tests/unit/test_onvif_transport.c +++ b/tests/unit/test_onvif_transport.c @@ -648,18 +648,20 @@ static void test_subscription_reference_parameters_become_soap_headers(void) { "" "http://camera/onvif/pull" "abc&123" + "one" "" ""; char *address = NULL, *params = NULL, *namespaces = NULL; TEST_ASSERT_TRUE(extract_subscription_endpoint_reference(reply, &address, ¶ms, &namespaces)); TEST_ASSERT_EQUAL_STRING("http://camera/onvif/pull", address); - TEST_ASSERT_NOT_NULL(strstr(params, "abc&123")); + TEST_ASSERT_NOT_NULL(strstr(params, "abc&123")); + TEST_ASSERT_NOT_NULL(strstr(params, "one")); TEST_ASSERT_NOT_NULL(strstr(namespaces, "xmlns:tt=\"urn:camera:token\"")); char *request = create_onvif_request("", "", "", ONVIF_OPERATION_PULL_MESSAGES, address, params, namespaces); TEST_ASSERT_NOT_NULL(request); - TEST_ASSERT_NOT_NULL(strstr(request, "abc&123")); + TEST_ASSERT_NOT_NULL(strstr(request, "abc&123")); TEST_ASSERT_NULL(strstr(request, "")); TEST_ASSERT_NOT_NULL(strstr(request, "xmlns:tt=\"urn:camera:token\"")); ezxml_t parsed = ezxml_parse_str(request, strlen(request)); @@ -667,6 +669,8 @@ static void test_subscription_reference_parameters_become_soap_headers(void) { TEST_ASSERT_EQUAL_STRING("", ezxml_error(parsed)); TEST_ASSERT_NOT_NULL(child_by_local_name(child_by_local_name(parsed, "Header"), "Token")); + TEST_ASSERT_NOT_NULL(child_by_local_name(child_by_local_name(parsed, "Header"), + "Lease")); ezxml_free(parsed); free(request); free(namespaces); @@ -692,6 +696,156 @@ static void test_subscription_reference_cannot_rebind_soap_namespace(void) { TEST_ASSERT_NULL(namespaces); } +static void test_reference_parameter_cannot_rebind_addressing_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 char reference_camera_base[128]; +static char reference_pull_request[8192]; + +static void *reference_subscription_server(void *unused) { + (void)unused; + const char *paths[] = {"/onvif/device_service", "/onvif/service", + "/onvif/pull?session=123", "/onvif/pull?session=123", + "/onvif/pull?session=123"}; + for (size_t i = 0; i < 5; i++) { + struct pollfd pending = {.fd = origin, .events = POLLIN}; + if (poll(&pending, 1, 3000) != 1) { server_failed = 1; return NULL; } + int client = accept(origin, NULL, NULL); + if (client < 0) { server_failed = 2; return NULL; } + struct timeval timeout = {.tv_sec = 3}; + setsockopt(client, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); + char request[8192] = {0}; + size_t used = 0; + while (used < sizeof(request) - 1 && !strstr(request, "")) { + ssize_t n = recv(client, request + used, sizeof(request) - 1 - used, 0); + if (n < 0 && errno == EINTR) continue; + if (n <= 0) { server_failed = 3; break; } + used += (size_t)n; + request[used] = '\0'; + } + char target[128]; + snprintf(target, sizeof(target), "POST %s HTTP/", paths[i]); + if (strncmp(request, target, strlen(target)) != 0) server_failed = 4; + if (i == 2) safe_strcpy(reference_pull_request, request, + sizeof(reference_pull_request), 0); + + char body[1500]; + if (i == 0) { + snprintf(body, sizeof(body), + "" + "http://www.onvif.org/ver10/events/wsdl" + "%s/onvif/service" + "", reference_camera_base); + } else if (i == 1) { + snprintf(body, sizeof(body), + "" + "" + "%s/onvif/pull?session=123" + "abc" + "" + "", + reference_camera_base); + } else if (i == 2) { + snprintf(body, sizeof(body), + "" + ""); + } else { + snprintf(body, sizeof(body), + "<%sResponse/>" + "", i == 3 ? "Renew" : "Unsubscribe"); + } + char response[1800]; + int length = snprintf(response, sizeof(response), + "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\nConnection: close\r\n\r\n%s", + strlen(body), body); + if (length < 0 || (size_t)length >= sizeof(response) || + !fixture_send_all(client, response, (size_t)length)) server_failed = 5; + close(client); + if (server_failed) return NULL; + } + return NULL; +} + +static void test_created_subscription_carries_reference_to_pull(void) { + unsigned short port; + origin = listen_local(&port); + TEST_ASSERT_GREATER_OR_EQUAL_INT(0, origin); + snprintf(reference_camera_base, sizeof(reference_camera_base), + "http://127.0.0.1:%u", port); + reference_pull_request[0] = '\0'; + curl_handle = create_curl_handle(); + TEST_ASSERT_NOT_NULL(curl_handle); + curl_easy_setopt(curl_handle, CURLOPT_PROXY, ""); + pthread_t worker; + TEST_ASSERT_EQUAL_INT(0, pthread_create(&worker, NULL, + reference_subscription_server, NULL)); + onvif_subscription_t *sub = get_subscription(reference_camera_base, "", ""); + TEST_ASSERT_NOT_NULL(sub); + char expected_service[160], expected_pull[160]; + snprintf(expected_service, sizeof(expected_service), "%s/onvif/service", + reference_camera_base); + snprintf(expected_pull, sizeof(expected_pull), "%s/onvif/pull?session=123", + reference_camera_base); + TEST_ASSERT_EQUAL_STRING(expected_service, sub->service_url); + TEST_ASSERT_EQUAL_STRING(expected_pull, sub->subscription_address); + TEST_ASSERT_NOT_NULL(strstr(sub->reference_parameters, + "wsa:IsReferenceParameter=\"true\"")); + TEST_ASSERT_NOT_NULL(strstr(sub->reference_namespaces, + "xmlns:tt=\"urn:camera:token\"")); + sub->curl = create_curl_handle(); + TEST_ASSERT_NOT_NULL(sub->curl); + curl_easy_setopt(sub->curl, CURLOPT_PROXY, ""); + char *response = send_subscription_request(sub, "", + ONVIF_OPERATION_PULL_MESSAGES, NULL, NULL); + TEST_ASSERT_NOT_NULL(response); + free(response); + TEST_ASSERT_TRUE(renew_subscription_locked(sub)); + unsubscribe_subscription_locked(sub); + TEST_ASSERT_EQUAL_INT(0, pthread_join(worker, NULL)); + TEST_ASSERT_EQUAL_INT(0, server_failed); + TEST_ASSERT_NOT_NULL(strstr(reference_pull_request, + "abc")); + TEST_ASSERT_NOT_NULL(strstr(reference_pull_request, + "http://127.0.0.1:")); +} + +static void test_onvif_camera_logs_redact_query_credentials(void) { + const char *camera = "http://user:password@127.0.0.1/onvif?token=private-token"; + subscription_count = 1; + onvif_subscription_t *sub = &subscriptions[0]; + safe_strcpy(sub->camera_url, camera, sizeof(sub->camera_url), 0); + sub->active = true; + for (int i = 0; i < ONVIF_PULL_FAILURE_WARN_COUNT; i++) + note_pull_failure(camera); + note_pull_success(camera); + safe_strcpy(sub->subscription_address, "ftp://invalid/pull", + sizeof(sub->subscription_address), 0); + sub->consecutive_pull_failures = ONVIF_PULL_FAILURE_WARN_COUNT - 1; + sub->first_pull_failure_time = time(NULL) - ONVIF_PULL_FAILURE_REFRESH_SECONDS - 1; + note_pull_failure(camera); + TEST_ASSERT_NOT_NULL(strstr(log_capture, "has not completed a pull")); + TEST_ASSERT_NOT_NULL(strstr(log_capture, "127.0.0.1/onvif")); + TEST_ASSERT_NULL(strstr(log_capture, "private-token")); + TEST_ASSERT_NULL(strstr(log_capture, "password")); + TEST_ASSERT_NULL(strstr(log_capture, "user:")); +} + static void test_motion_requires_asserted_state_not_truthy_metadata(void) { char label[32]; const char *metadata_only = @@ -762,6 +916,9 @@ int main(void) { 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_reference_parameter_cannot_rebind_addressing_namespace); + RUN_TEST(test_created_subscription_carries_reference_to_pull); + RUN_TEST(test_onvif_camera_logs_redact_query_credentials); RUN_TEST(test_motion_requires_asserted_state_not_truthy_metadata); RUN_TEST(test_class_flags_ignore_camera_metadata); return UNITY_END();