From d249fb8017d6836c407df4d022ba34f0dfe7c5ac Mon Sep 17 00:00:00 2001 From: Hailin Zhou <26061625+zhouhailin@users.noreply.github.com> Date: Thu, 27 Jan 2022 21:28:09 +0800 Subject: [PATCH] [mod_json_cdr] add timeout param. --- .../conf/autoload_configs/json_cdr.conf.xml | 2 ++ src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml b/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml index 1862656277..af30c67c07 100644 --- a/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml +++ b/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml @@ -23,6 +23,8 @@ + + diff --git a/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c b/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c index fc4794a482..7f66aa425a 100644 --- a/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c +++ b/src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c @@ -70,6 +70,7 @@ static struct { int disable100continue; int rotate; long auth_scheme; + int timeout; switch_memory_pool_t *pool; switch_event_node_t *node; int encode_values; @@ -361,8 +362,10 @@ static void process_cdr(cdr_data_t *data) switch_curl_easy_setopt(curl_handle, CURLOPT_CAINFO, globals.ssl_cacert_file); } + // tcp timeout + switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.timeout); + /* these were used for testing, optionally they may be enabled if someone desires - switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 120); // tcp timeout switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level */ @@ -607,6 +610,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_json_cdr_load) globals.log_http_and_disk = switch_true(val); } else if (!strcasecmp(var, "log-errors-to-disk")) { globals.log_errors_to_disk = !switch_false(val); + } else if (!strcasecmp(var, "timeout")) { + int tmp = atoi(val); + if (tmp >= 0) { + globals.timeout = tmp; + } else { + globals.timeout = 0; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't set a negative timeout!\n"); + } } else if (!strcasecmp(var, "delay") && !zstr(val)) { globals.delay = (uint32_t) atoi(val); } else if (!strcasecmp(var, "log-b-leg")) {