From 20dc0d02fcc51092c228e0ebb01615c31980fb2f Mon Sep 17 00:00:00 2001 From: Cloudmule Date: Tue, 31 Jan 2023 16:03:59 -0500 Subject: [PATCH] Handle failure to subscribe gracefully, de-initing soap instead of crashing. --- src/zm_monitor.cpp | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 0eda55d77..f14a15e6c 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -1016,28 +1016,40 @@ bool Monitor::connect() { soap->send_timeout = 5; soap_register_plugin(soap, soap_wsse); proxyEvent = PullPointSubscriptionBindingProxy(soap); - std::string full_url = onvif_url + "/Events"; - proxyEvent.soap_endpoint = full_url.c_str(); + if (!onvif_url.empty()) { + std::string full_url = onvif_url + "/Events"; + proxyEvent.soap_endpoint = full_url.c_str(); - set_credentials(soap); - Debug(1, "ONVIF Endpoint: %s", proxyEvent.soap_endpoint); - if (proxyEvent.CreatePullPointSubscription(&request, response) != SOAP_OK) { - Error("Couldn't create subscription! %s, %s", soap_fault_string(soap), soap_fault_detail(soap)); - } else { - //Empty the stored messages set_credentials(soap); - if ((proxyEvent.PullMessages(response.SubscriptionReference.Address, NULL, &tev__PullMessages, tev__PullMessagesResponse) != SOAP_OK) && - ( soap->error != SOAP_EOF)) { //SOAP_EOF could indicate no messages to pull. - Error("Couldn't do initial event pull! Error %i %s, %s", soap->error, soap_fault_string(soap), soap_fault_detail(soap)); + Debug(1, "ONVIF Endpoint: %s", proxyEvent.soap_endpoint); + if (proxyEvent.CreatePullPointSubscription(&request, response) != SOAP_OK) { + const char *detail = soap_fault_detail(soap); + Error("Couldn't create subscription! %s, %s", soap_fault_string(soap), detail ? detail : "null"); + _wsnt__Unsubscribe wsnt__Unsubscribe; + _wsnt__UnsubscribeResponse wsnt__UnsubscribeResponse; + proxyEvent.Unsubscribe(response.SubscriptionReference.Address, NULL, &wsnt__Unsubscribe, wsnt__UnsubscribeResponse); + soap_destroy(soap); + soap_end(soap); + soap_free(soap); + soap = nullptr; } else { - Debug(1, "Good Initial ONVIF Pull"); - Event_Poller_Healthy = TRUE; + //Empty the stored messages + set_credentials(soap); + if ((proxyEvent.PullMessages(response.SubscriptionReference.Address, NULL, &tev__PullMessages, tev__PullMessagesResponse) != SOAP_OK) && + ( soap->error != SOAP_EOF)) { //SOAP_EOF could indicate no messages to pull. + Error("Couldn't do initial event pull! Error %i %s, %s", soap->error, soap_fault_string(soap), soap_fault_detail(soap)); + } else { + Debug(1, "Good Initial ONVIF Pull"); + Event_Poller_Healthy = TRUE; + } } + } else { + Warning("You must specify the url to the onvif endpoint"); } #else - Error("zmc not compiled with GSOAP. ONVIF support not built in!"); + Error("zmc not compiled with GSOAP. ONVIF support not built in!"); #endif - } + } // end if Armcrest of GSOAP } else { Debug(1, "Not Starting ONVIF"); }