From d9030622b64c5cdfe770b51e08f232bab85be81f Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 20 Nov 2026 01:15:34 -0500 Subject: [PATCH 1/6] 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/video/onvif_detection.c b/src/video/onvif_detection.c index 15a8be35a..e928cf1b6 100644 --- a/src/video/onvif_detection.c +++ b/src/video/onvif_detection.c @@ -1321,11 +1321,12 @@ static void note_pull_failure(const char *camera_url) { } subscription->consecutive_pull_failures++; + const char *camera_id = url_sanitize_for_logging(camera_url); 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 +1335,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); From a99a354dcd049ae6b53408d318341ac15fb8820a Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 20 Nov 2026 01:15:35 -0500 Subject: [PATCH 2/6] 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/video/onvif_detection.c b/src/video/onvif_detection.c index e928cf1b6..9331c1d1f 100644 --- a/src/video/onvif_detection.c +++ b/src/video/onvif_detection.c @@ -1273,12 +1273,18 @@ static onvif_subscription_t *get_subscription(const char *url, const char *usern // Store subscription address safe_strcpy(subscriptions[slot].subscription_address, subscription_address, sizeof(subscriptions[slot].subscription_address), 0); - if (reference_parameters) + if (reference_parameters) { safe_strcpy(subscriptions[slot].reference_parameters, reference_parameters, sizeof(subscriptions[slot].reference_parameters), 0); - if (reference_namespaces) + } else { + subscriptions[slot].reference_parameters[0] = '\0'; + } + if (reference_namespaces) { safe_strcpy(subscriptions[slot].reference_namespaces, reference_namespaces, sizeof(subscriptions[slot].reference_namespaces), 0); + } else { + subscriptions[slot].reference_namespaces[0] = '\0'; + } safe_strcpy(subscriptions[slot].service_url, attempted_event_url, sizeof(subscriptions[slot].service_url), 0); From daa5af23288e1fc7b2a991d71e05dfe643e96cbf Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 20 Nov 2026 01:15:36 -0500 Subject: [PATCH 3/6] 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 | 70 +++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/src/video/onvif_detection.c b/src/video/onvif_detection.c index 9331c1d1f..c93459b97 100644 --- a/src/video/onvif_detection.c +++ b/src/video/onvif_detection.c @@ -288,6 +288,62 @@ typedef struct { * destination URL; both are required (strict ONVIF servers * such as Reolink reject requests missing either — #374). */ +static char *normalize_reference_parameters(const char *ref_params) { + if (!ref_params || ref_params[0] == '\0') { + return strdup(""); + } + + size_t wrapped_len = strlen(ref_params) + 128; + char *wrapped = malloc(wrapped_len); + if (!wrapped) return NULL; + + snprintf(wrapped, wrapped_len, + "%s", + ref_params); + + ezxml_t root = ezxml_parse_str(wrapped, (size_t)strlen(wrapped)); + free(wrapped); + if (!root) { + return NULL; + } + + for (ezxml_t child = ezxml_child(root, NULL); child; child = child->next) { + const char *is_ref = ezxml_attr(child, "wsa:IsReferenceParameter"); + if (!is_ref) { + ezxml_set_attr(child, "wsa:IsReferenceParameter", "true"); + } + } + + char *xml = ezxml_toxml(root); + if (!xml) { + ezxml_free(root); + return NULL; + } + + char *start = strchr(xml, '>'); + char *end = strrchr(xml, '<'); + if (!start || !end || end <= start) { + free(xml); + ezxml_free(root); + return NULL; + } + + start++; + size_t out_len = (size_t)(end - start); + char *out = malloc(out_len + 1); + if (!out) { + free(xml); + ezxml_free(root); + return NULL; + } + memcpy(out, start, out_len); + out[out_len] = '\0'; + + free(xml); + ezxml_free(root); + return out; +} + static char *create_onvif_request(const char *username, const char *password, const char *request_body, onvif_operation_t operation, const char *to, @@ -297,6 +353,7 @@ static char *create_onvif_request(const char *username, const char *password, if (!action || !request_body) return NULL; bool has_credentials = (username && strlen(username) > 0 && password && strlen(password) > 0); char *security_header = NULL; + char *normalized_ref_params = NULL; if (!has_credentials) { log_debug("Creating ONVIF request without authentication (no credentials provided)"); @@ -336,14 +393,22 @@ static char *create_onvif_request(const char *username, const char *password, * MessageID (urn:uuid:… = ~45 chars), the action URI, the destination URL, * the security header, and the body. 2 KB of slack above those sizes is * plenty. */ + normalized_ref_params = normalize_reference_parameters(ref_params); + if (!normalized_ref_params) { + free(security_header); + free(destination_xml); + return NULL; + } + size_t envelope_size = strlen(request_body) + strlen(security_header) + strlen(action) + strlen(destination_xml) - + (ref_params ? strlen(ref_params) : 0) + + strlen(normalized_ref_params) + (ref_namespaces ? strlen(ref_namespaces) : 0) + 2048; char *soap_request = malloc(envelope_size); if (!soap_request) { free(security_header); free(destination_xml); + free(normalized_ref_params); return NULL; } @@ -362,10 +427,11 @@ static char *create_onvif_request(const char *username, const char *password, "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">%s" "", ref_namespaces ? ref_namespaces : "", uuid, destination_xml, action, - ref_params ? ref_params : "", security_header, request_body); + normalized_ref_params, security_header, request_body); free(security_header); free(destination_xml); + free(normalized_ref_params); return soap_request; } From ac5dc47248a463671cf90cfe62ad42f004403642 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 20 Nov 2026 01:21:28 -0500 Subject: [PATCH 4/6] Mark ONVIF reference headers and redact camera logs --- src/video/onvif_detection.c | 118 ++++++++------------------ tests/unit/test_onvif_transport.c | 133 +++++++++++++++++++++++++++++- 2 files changed, 167 insertions(+), 84 deletions(-) diff --git a/src/video/onvif_detection.c b/src/video/onvif_detection.c index c93459b97..9d2fb17bc 100644 --- a/src/video/onvif_detection.c +++ b/src/video/onvif_detection.c @@ -288,62 +288,6 @@ typedef struct { * destination URL; both are required (strict ONVIF servers * such as Reolink reject requests missing either — #374). */ -static char *normalize_reference_parameters(const char *ref_params) { - if (!ref_params || ref_params[0] == '\0') { - return strdup(""); - } - - size_t wrapped_len = strlen(ref_params) + 128; - char *wrapped = malloc(wrapped_len); - if (!wrapped) return NULL; - - snprintf(wrapped, wrapped_len, - "%s", - ref_params); - - ezxml_t root = ezxml_parse_str(wrapped, (size_t)strlen(wrapped)); - free(wrapped); - if (!root) { - return NULL; - } - - for (ezxml_t child = ezxml_child(root, NULL); child; child = child->next) { - const char *is_ref = ezxml_attr(child, "wsa:IsReferenceParameter"); - if (!is_ref) { - ezxml_set_attr(child, "wsa:IsReferenceParameter", "true"); - } - } - - char *xml = ezxml_toxml(root); - if (!xml) { - ezxml_free(root); - return NULL; - } - - char *start = strchr(xml, '>'); - char *end = strrchr(xml, '<'); - if (!start || !end || end <= start) { - free(xml); - ezxml_free(root); - return NULL; - } - - start++; - size_t out_len = (size_t)(end - start); - char *out = malloc(out_len + 1); - if (!out) { - free(xml); - ezxml_free(root); - return NULL; - } - memcpy(out, start, out_len); - out[out_len] = '\0'; - - free(xml); - ezxml_free(root); - return out; -} - static char *create_onvif_request(const char *username, const char *password, const char *request_body, onvif_operation_t operation, const char *to, @@ -353,7 +297,6 @@ static char *create_onvif_request(const char *username, const char *password, if (!action || !request_body) return NULL; bool has_credentials = (username && strlen(username) > 0 && password && strlen(password) > 0); char *security_header = NULL; - char *normalized_ref_params = NULL; if (!has_credentials) { log_debug("Creating ONVIF request without authentication (no credentials provided)"); @@ -393,22 +336,14 @@ static char *create_onvif_request(const char *username, const char *password, * MessageID (urn:uuid:… = ~45 chars), the action URI, the destination URL, * the security header, and the body. 2 KB of slack above those sizes is * plenty. */ - normalized_ref_params = normalize_reference_parameters(ref_params); - if (!normalized_ref_params) { - free(security_header); - free(destination_xml); - return NULL; - } - size_t envelope_size = strlen(request_body) + strlen(security_header) + strlen(action) + strlen(destination_xml) - + strlen(normalized_ref_params) + + (ref_params ? strlen(ref_params) : 0) + (ref_namespaces ? strlen(ref_namespaces) : 0) + 2048; char *soap_request = malloc(envelope_size); if (!soap_request) { free(security_header); free(destination_xml); - free(normalized_ref_params); return NULL; } @@ -427,11 +362,10 @@ static char *create_onvif_request(const char *username, const char *password, "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">%s" "", ref_namespaces ? ref_namespaces : "", uuid, destination_xml, action, - normalized_ref_params, security_header, request_body); + ref_params ? ref_params : "", security_header, request_body); free(security_header); free(destination_xml); - free(normalized_ref_params); return soap_request; } @@ -661,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; @@ -711,6 +655,8 @@ static bool extract_subscription_endpoint_reference(const char *response, } } +endpoint_parsed: + if (root) ezxml_free(root); free(copy); if (!ok) { @@ -893,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 @@ -956,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) { @@ -1013,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; } @@ -1031,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); @@ -1339,18 +1296,12 @@ static onvif_subscription_t *get_subscription(const char *url, const char *usern // Store subscription address safe_strcpy(subscriptions[slot].subscription_address, subscription_address, sizeof(subscriptions[slot].subscription_address), 0); - if (reference_parameters) { + if (reference_parameters) safe_strcpy(subscriptions[slot].reference_parameters, reference_parameters, sizeof(subscriptions[slot].reference_parameters), 0); - } else { - subscriptions[slot].reference_parameters[0] = '\0'; - } - if (reference_namespaces) { + if (reference_namespaces) safe_strcpy(subscriptions[slot].reference_namespaces, reference_namespaces, sizeof(subscriptions[slot].reference_namespaces), 0); - } else { - subscriptions[slot].reference_namespaces[0] = '\0'; - } safe_strcpy(subscriptions[slot].service_url, attempted_event_url, sizeof(subscriptions[slot].service_url), 0); @@ -1392,8 +1343,9 @@ 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)); - const char *camera_id = url_sanitize_for_logging(camera_url); if (subscription->consecutive_pull_failures == ONVIF_PULL_FAILURE_WARN_COUNT) { log_warn("ONVIF PullPoint for %s has failed %d consecutive pulls; " @@ -1427,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..53a4344d1 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,129 @@ static void test_subscription_reference_cannot_rebind_soap_namespace(void) { 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"}; + for (size_t i = 0; i < 3; 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 { + snprintf(body, sizeof(body), + "" + ""); + } + 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_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); + unsubscribe_subscription_locked(sub); + 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 +889,8 @@ 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_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(); From 3e84f72e7f7328c15b5198a064a338c7cf211003 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 20 Nov 2026 01:28:04 -0500 Subject: [PATCH 5/6] Cover ONVIF renew, unsubscribe, and namespace rejection --- tests/unit/test_onvif_transport.c | 34 ++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_onvif_transport.c b/tests/unit/test_onvif_transport.c index 53a4344d1..82f7be61f 100644 --- a/tests/unit/test_onvif_transport.c +++ b/tests/unit/test_onvif_transport.c @@ -696,14 +696,32 @@ 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 < 3; i++) { + 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); @@ -743,10 +761,14 @@ static void *reference_subscription_server(void *unused) { "" "", reference_camera_base); - } else { + } 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), @@ -793,6 +815,8 @@ static void test_created_subscription_carries_reference_to_pull(void) { 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, @@ -812,7 +836,10 @@ static void test_onvif_camera_logs_redact_query_credentials(void) { note_pull_success(camera); safe_strcpy(sub->subscription_address, "ftp://invalid/pull", sizeof(sub->subscription_address), 0); - unsubscribe_subscription_locked(sub); + 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")); @@ -889,6 +916,7 @@ 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); From d3f62c0684d563bcbd210b1e55a18d8a947b5adc 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:36:05 +0000 Subject: [PATCH 6/6] lightnvr-rs: regenerate from C Generated by tools/rust-transpile/generate.py for bbb2a31. --- rust/MANIFEST.json | 4 +- rust/generated/src__video__onvif_detection.rs | 2440 +++++++++-------- 2 files changed, 1267 insertions(+), 1177 deletions(-) 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, ); }