[asterisk-bugs] [JIRA] (ASTERISK-30340) res_media_cache curl options configureable

mseif (JIRA) noreply at issues.asterisk.org
Wed Dec 14 21:36:51 CST 2022


     [ https://issues.asterisk.org/jira/browse/ASTERISK-30340?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

mseif updated ASTERISK-30340:
-----------------------------

    Comment: was deleted

(was: this patch for loaded config from res_curl.conf when the loading or reload res_http_media_cache.so 
after the patch add section [media_cache] like the

[media_cache]
ssl_verify=no
timeout=190
maxheaders=10

ssl_verify: usage on host is self signed ssl and failed ssl error
timeout: default timeout is 180 then set max integer value
maxheaders: default 8 or set to max integer value


--- base/asterisk-20.0.1/res/res_http_media_cache.c	2022-12-01 20:08:11.000000000 +0000
+++ asterisk-20.0.1/res/res_http_media_cache.c	2022-12-15 03:22:11.437365431 +0000
@@ -41,6 +41,7 @@
 #include "asterisk/sorcery.h"
 #include "asterisk/threadstorage.h"
 #include "asterisk/uri.h"
+#include "asterisk/pbx.h"
 
 #define MAX_HEADER_LENGTH 1023
 
@@ -52,6 +53,11 @@
 	FILE *out_file;
 };
 
+
+static int timeout = 180;
+static int maxheaders = 8;
+static int ssl_verify = 1L;
+
 /*!
  * \internal \brief The cURL header callback function
  */
@@ -325,13 +331,14 @@
 	}
 
 	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
-	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
+	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
 	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);
 	curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);
 	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
-	curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 8);
+	curl_easy_setopt(curl, CURLOPT_MAXREDIRS, maxheaders);
 	curl_easy_setopt(curl, CURLOPT_URL, ast_sorcery_object_get_id(cb_data->bucket_file));
 	curl_easy_setopt(curl, CURLOPT_HEADERDATA, cb_data);
+	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, ssl_verify);
 
 	return curl;
 }
@@ -532,6 +539,39 @@
 	.is_stale = bucket_http_wizard_is_stale,
 };
 
+static int reload_module(void)
+{
+	struct ast_flags flags = { CONFIG_FLAG_NOREALTIME };
+	struct ast_config *cfg;
+	struct ast_variable *var;
+
+	if (!(cfg = ast_config_load("res_curl.conf", flags))) {
+		return 0;
+	} else if (cfg == CONFIG_STATUS_FILEINVALID) {
+		ast_log(LOG_WARNING, "res_curl.conf could not be parsed!\n");
+		return 0;
+	}
+
+	if (!(var = ast_variable_browse(cfg, "media_cache")) && !(var = ast_variable_browse(cfg, "media_cache")) ) {
+		ast_log(LOG_WARNING, "[media_cache] not found in res_curl.conf\n");
+		ast_config_destroy(cfg);
+		return 0;
+	}
+
+	for (; var; var = var->next) {
+
+		if (!strcasecmp(var->name, "ssl_verify") && !ast_true(var->value)) {
+			ssl_verify =  0L;
+		} else if (!strcasecmp(var->name, "timeout")) {
+			timeout = atoi(var->value);
+		} else if (!strcasecmp(var->name, "maxheaders")) {
+			maxheaders = atoi(var->value);
+		}
+	}
+	ast_config_destroy(cfg);
+	return 0;
+}
+
 static int unload_module(void)
 {
 	return 0;
@@ -551,6 +591,8 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
+	reload_module();
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
@@ -559,4 +601,5 @@
 		.load = load_module,
 		.unload = unload_module,
 		.requires = "res_curl",
+		.reload = reload_module,
 	);)

> res_media_cache curl options configureable
> ------------------------------------------
>
>                 Key: ASTERISK-30340
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-30340
>             Project: Asterisk
>          Issue Type: Improvement
>      Security Level: None
>          Components: Resources/NewFeature
>    Affects Versions: 20.0.1
>         Environment: Playback a media from URL. 
>            Reporter: Joeran Vinzens
>            Assignee: Joeran Vinzens
>              Labels: patch
>         Attachments: curl_config_cache.patch
>
>
> We use the media_cache module to cache media resources from url.
> When doing so, and the media server providing the files hangs, the timeouts within the re_media_cache are too long. In the asterisk there are error logs showing the problems. Since the real issue is not within the asterisk but in the web server ew like to make the asterisk a bit stronger to have more aggressive timeouts and settings within the media_cache module.
> Unfortunately these CURL options are hardcoded within the module itself. there is no chance to change it.
> We asked a developer to make a config file containing the curl options.
> Now we have a first implementation for it, but we want to bring it upstream.
> This feature request is meant to discuss whether we can simply create a PR.
> Our talented developer will respond to this issue as well, if you are interested in this feature.



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list