Support of Unix Sockets for the modules: mod_json_cdr and mod_xml_curl

This commit is contained in:
Anton Sharpaev 2022-02-15 15:15:57 +00:00
parent d249fb8017
commit 0c27661d4c
4 changed files with 26 additions and 0 deletions

View File

@ -25,6 +25,10 @@
<param name="url" value=""/> <param name="url" value=""/>
<!-- optional timeout : second --> <!-- optional timeout : second -->
<param name="timeout" value="5"/> <param name="timeout" value="5"/>
<!-- optional unix-socket-path: path -->
<!-- <param name="unix-socket-path" value="/var/run/nginx/fs-backend.sock"/> -->
<!-- Authentication scheme for the above URL. May be one of basic|digest|NTLM|GSS-NEGOTIATE|any--> <!-- Authentication scheme for the above URL. May be one of basic|digest|NTLM|GSS-NEGOTIATE|any-->
<param name="auth-scheme" value="basic"/> <param name="auth-scheme" value="basic"/>
<!-- Credentials in the form username:password if auth-scheme is used. Leave empty for no authentication. --> <!-- Credentials in the form username:password if auth-scheme is used. Leave empty for no authentication. -->

View File

@ -61,6 +61,7 @@ static struct {
char *ssl_key_password; char *ssl_key_password;
char *ssl_version; char *ssl_version;
char *ssl_cacert_file; char *ssl_cacert_file;
char *unix_socket_path;
uint32_t enable_ssl_verifyhost; uint32_t enable_ssl_verifyhost;
int encode; int encode;
int log_http_and_disk; int log_http_and_disk;
@ -365,6 +366,10 @@ static void process_cdr(cdr_data_t *data)
// tcp timeout // tcp timeout
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.timeout); switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.timeout);
if (!zstr(globals.unix_socket_path)) {
switch_curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, globals.unix_socket_path);
}
/* these were used for testing, optionally they may be enabled if someone desires /* these were used for testing, optionally they may be enabled if someone desires
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
*/ */
@ -674,6 +679,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_json_cdr_load)
globals.ssl_version = switch_core_strdup(globals.pool, val); globals.ssl_version = switch_core_strdup(globals.pool, val);
} else if (!strcasecmp(var, "ssl-cacert-file")) { } else if (!strcasecmp(var, "ssl-cacert-file")) {
globals.ssl_cacert_file = switch_core_strdup(globals.pool, val); globals.ssl_cacert_file = switch_core_strdup(globals.pool, val);
} else if (!strcasecmp(var, "unix-socket-path")) {
globals.unix_socket_path = switch_core_strdup(globals.pool, val);
} else if (!strcasecmp(var, "enable-ssl-verifyhost") && switch_true(val)) { } else if (!strcasecmp(var, "enable-ssl-verifyhost") && switch_true(val)) {
globals.enable_ssl_verifyhost = 1; globals.enable_ssl_verifyhost = 1;
} else if (!strcasecmp(var, "auth-scheme")) { } else if (!strcasecmp(var, "auth-scheme")) {

View File

@ -12,6 +12,9 @@
<!--<param name="gateway-credentials" value="muser:mypass"/>--> <!--<param name="gateway-credentials" value="muser:mypass"/>-->
<!--<param name="auth-scheme" value="basic"/>--> <!--<param name="auth-scheme" value="basic"/>-->
<!-- optional unix-socket-path: path -->
<!-- <param name="unix-socket-path" value="/var/run/nginx/fs-backend.sock"/> -->
<!-- optional: this will enable the CA root certificate check by libcurl to <!-- optional: this will enable the CA root certificate check by libcurl to
verify that the certificate was issued by a major Certificate Authority. verify that the certificate was issued by a major Certificate Authority.
note: default value is disabled. only enable if you want this! --> note: default value is disabled. only enable if you want this! -->

View File

@ -53,6 +53,7 @@ struct xml_binding {
char *ssl_key_password; char *ssl_key_password;
char *ssl_version; char *ssl_version;
char *ssl_cacert_file; char *ssl_cacert_file;
char *unix_socket_path;
uint32_t enable_ssl_verifyhost; uint32_t enable_ssl_verifyhost;
char *cookie_file; char *cookie_file;
switch_hash_t *vars_map; switch_hash_t *vars_map;
@ -281,6 +282,10 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2); switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
} }
if (binding->unix_socket_path) {
switch_curl_easy_setopt(curl_handle, CURLOPT_UNIX_SOCKET_PATH, binding->unix_socket_path);
}
if (binding->cookie_file) { if (binding->cookie_file) {
switch_curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, binding->cookie_file); switch_curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, binding->cookie_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, binding->cookie_file); switch_curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, binding->cookie_file);
@ -372,6 +377,7 @@ static switch_status_t do_config(void)
char *ssl_key_password = NULL; char *ssl_key_password = NULL;
char *ssl_version = NULL; char *ssl_version = NULL;
char *ssl_cacert_file = NULL; char *ssl_cacert_file = NULL;
char *unix_socket_path = NULL;
uint32_t enable_ssl_verifyhost = 0; uint32_t enable_ssl_verifyhost = 0;
char *cookie_file = NULL; char *cookie_file = NULL;
hash_node_t *hash_node; hash_node_t *hash_node;
@ -437,6 +443,8 @@ static switch_status_t do_config(void)
cookie_file = val; cookie_file = val;
} else if (!strcasecmp(var, "use-dynamic-url") && switch_true(val)) { } else if (!strcasecmp(var, "use-dynamic-url") && switch_true(val)) {
use_dynamic_url = 1; use_dynamic_url = 1;
} else if (!strcasecmp(var, "unix-socket-path")) {
unix_socket_path = val;
} else if (!strcasecmp(var, "enable-post-var")) { } else if (!strcasecmp(var, "enable-post-var")) {
if (!vars_map && need_vars_map == 0) { if (!vars_map && need_vars_map == 0) {
if (switch_core_hash_init(&vars_map) != SWITCH_STATUS_SUCCESS) { if (switch_core_hash_init(&vars_map) != SWITCH_STATUS_SUCCESS) {
@ -530,6 +538,10 @@ static switch_status_t do_config(void)
binding->cookie_file = switch_core_strdup(globals.pool, cookie_file); binding->cookie_file = switch_core_strdup(globals.pool, cookie_file);
} }
if (unix_socket_path) {
binding->unix_socket_path = switch_core_strdup(globals.pool, unix_socket_path);
}
binding->vars_map = vars_map; binding->vars_map = vars_map;
if (vars_map) { if (vars_map) {