]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_json_cdr] add timeout param.
authorHailin Zhou <26061625+zhouhailin@users.noreply.github.com>
Thu, 27 Jan 2022 13:28:09 +0000 (21:28 +0800)
committerGitHub <noreply@github.com>
Thu, 27 Jan 2022 13:28:09 +0000 (16:28 +0300)
src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml
src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c

index 18626562773f6a6bf4dcdbcb31d9e84b59534c75..af30c67c07b6c87da438dea6faa372ab391af685 100644 (file)
@@ -23,6 +23,8 @@
                        <!-- HTTP(S) logging -->
                        <!-- URL where to POST JSON CDRs. Leave empty for no URL logging. Up to 20 URLs may be specified. -->
                        <param name="url" value=""/>
+                       <!-- optional timeout : second -->
+                       <param name="timeout" value="5"/>
                        <!-- Authentication scheme for the above URL. May be one of basic|digest|NTLM|GSS-NEGOTIATE|any-->
                        <param name="auth-scheme" value="basic"/>
                        <!-- Credentials in the form  username:password  if auth-scheme is used. Leave empty for no authentication. -->
index fc4794a482970af4a212e95545cd56d23ec2ee87..7f66aa425a8a87080e01c150017c30c3bd4bbe26 100644 (file)
@@ -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")) {