From f2793b1a03c26442cd251e87c2a7e86b454ea661 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 23 Oct 2023 13:50:49 +0300 Subject: [PATCH] [mod_xml_cdr] Improve cURL error handling. --- src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c index 8a6efbf544..a466327ccd 100644 --- a/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c +++ b/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c @@ -193,6 +193,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) int fd = -1; uint32_t cur_try; long httpRes; + switch_CURLcode res; switch_CURL *curl_handle = NULL; switch_curl_slist_t *headers = NULL; switch_curl_slist_t *slist = NULL; @@ -385,10 +386,18 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) /* overrides default 300s timeout, could be usefull if the current web server is down to prevent long time waiting for nothing */ /* connection_timeout = retry_timeout */ switch_curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, !globals.delay ? 5 : (long)globals.delay); - switch_curl_easy_perform(curl_handle); - switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes); + res = switch_curl_easy_perform(curl_handle); + if (res != CURLE_OK) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "switch_curl_easy_perform [%s] error [%d]\n", globals.urls[g_url_index], res); + } else { + res = switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes); + if (res != CURLE_OK) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "switch_curl_easy_getinfo [%s] error [%d]\n", globals.urls[g_url_index], res); + } + } + switch_safe_free(destUrl); - if (httpRes >= 200 && httpRes <= 299) { + if (res == CURLE_OK && httpRes >= 200 && httpRes <= 299) { goto success; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Got error [%ld] posting to web server [%s]\n",