<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19952">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_http_media_cache: Introduce options and customize<br><br>Make the existing CURL parameters configurable and allow<br>to specify the usable protocols, proxy and DNS timeout.<br><br>ASTERISK-30340<br><br>Change-Id: I2eb02ef44190e026716720419bcbdbcc8125777b<br>---<br>A configs/samples/res_http_media_cache.conf.sample<br>A doc/CHANGES-staging/res_http_media_cache.txt<br>M res/res_http_media_cache.c<br>3 files changed, 348 insertions(+), 4 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/res_http_media_cache.conf.sample b/configs/samples/res_http_media_cache.conf.sample</span><br><span>new file mode 100644</span><br><span>index 0000000..925156b</span><br><span>--- /dev/null</span><br><span>+++ b/configs/samples/res_http_media_cache.conf.sample</span><br><span>@@ -0,0 +1,69 @@</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; Sample configuration for res_http_media_cache</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; res_http_media_cache is the HTTP backend for the core media cache. The</span><br><span style="color: hsl(120, 100%, 40%);">+; following options can be used to tune the behavior of the implementation</span><br><span style="color: hsl(120, 100%, 40%);">+; or left as default.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See the module's and cURL's documentation for the exact meaning of these</span><br><span style="color: hsl(120, 100%, 40%);">+; options.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+[general]</span><br><span style="color: hsl(120, 100%, 40%);">+; Maximum time in seconds the transfer is allowed to complete in.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_TIMEOUT.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;timeout_secs = 180</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+; The HTTP User-Agent to use for requests.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_USERAGENT.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;user_agent = asterisk-libcurl-agent/1.0</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+; Follow HTTP 3xx redirects on requests. This can be combined with the</span><br><span style="color: hsl(120, 100%, 40%);">+; max_redirects option to limit the number of times a redirect will be</span><br><span style="color: hsl(120, 100%, 40%);">+; followed per request.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;follow_location = false</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+; The maximum number of redirects to follow.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_MAXREDIRS.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;max_redirects = 8</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+; The HTTP/HTTPS proxy to use for requests. Leave unspecified to not use</span><br><span style="color: hsl(120, 100%, 40%);">+; a proxy. This can be a URL with scheme, host and port.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_PROXY.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;proxy = https://localhost:1234</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+; The life-time for DNS cache entries.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_DNS_CACHE_TIMEOUT.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;dns_cache_timeout_secs = 60</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+; The comma separated list of allowed protocols for the request. Available with</span><br><span style="color: hsl(120, 100%, 40%);">+; cURL version 7.85.0 or later.</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_PROTOCOLS_STR.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;protocols = http,https</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+; The comma separated list of allowed protocols for redirects. Available with</span><br><span style="color: hsl(120, 100%, 40%);">+; cURL version 7.85.0 or later. This can be used to prevent a redirect from</span><br><span style="color: hsl(120, 100%, 40%);">+; a protocol like HTTPS to another supported protocol of cURL.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+; See https://curl.se/libcurl/c/CURLOPT_REDIR_PROTOCOLS_STR.html for details.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;redirect_protocols = http,https</span><br><span>diff --git a/doc/CHANGES-staging/res_http_media_cache.txt b/doc/CHANGES-staging/res_http_media_cache.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..79223c0</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_http_media_cache.txt</span><br><span>@@ -0,0 +1,12 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_http_media_cache</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The res_http_media_cache module now attempts to load</span><br><span style="color: hsl(120, 100%, 40%);">+configuration from the res_http_media_cache.conf file.</span><br><span style="color: hsl(120, 100%, 40%);">+The following options were added:</span><br><span style="color: hsl(120, 100%, 40%);">+ * timeout_secs</span><br><span style="color: hsl(120, 100%, 40%);">+ * user_agent</span><br><span style="color: hsl(120, 100%, 40%);">+ * follow_location</span><br><span style="color: hsl(120, 100%, 40%);">+ * max_redirects</span><br><span style="color: hsl(120, 100%, 40%);">+ * protocols</span><br><span style="color: hsl(120, 100%, 40%);">+ * redirect_protocols</span><br><span style="color: hsl(120, 100%, 40%);">+ * dns_cache_timeout_secs</span><br><span>diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c</span><br><span>index dfafdc7..5088ed3 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -31,6 +31,41 @@</span><br><span> <support_level>core</support_level></span><br><span> ***/</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*** DOCUMENTATION</span><br><span style="color: hsl(120, 100%, 40%);">+ <configInfo name="res_http_media_cache" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>HTTP media cache</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <configFile name="http_media_cache.conf"></span><br><span style="color: hsl(120, 100%, 40%);">+ <configObject name="general"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>General configuration</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="timeout_secs" default="180"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>The maximum time the transfer is allowed to complete in seconds. See https://curl.se/libcurl/c/CURLOPT_TIMEOUT.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="user_agent"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>The HTTP User-Agent to use for requests. See https://curl.se/libcurl/c/CURLOPT_USERAGENT.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="follow_location" default="1"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Follow HTTP 3xx redirects on requests. See https://curl.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="max_redirects" default="8"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>The maximum number of redirects to follow. See https://curl.se/libcurl/c/CURLOPT_MAXREDIRS.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="proxy"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>The proxy to use for requests. See https://curl.se/libcurl/c/CURLOPT_PROXY.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="protocols"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>The comma separated list of allowed protocols for the request. Available with cURL 7.85.0 or later. See https://curl.se/libcurl/c/CURLOPT_PROTOCOLS_STR.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="redirect_protocols"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>The comma separated list of allowed protocols for redirects. Available with cURL 7.85.0 or later. See https://curl.se/libcurl/c/CURLOPT_REDIR_PROTOCOLS_STR.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="dns_cache_timeout_secs" default="60"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>The life-time for DNS cache entries. See https://curl.se/libcurl/c/CURLOPT_DNS_CACHE_TIMEOUT.html for details.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ </configObject></span><br><span style="color: hsl(120, 100%, 40%);">+ </configFile></span><br><span style="color: hsl(120, 100%, 40%);">+ </configInfo></span><br><span style="color: hsl(120, 100%, 40%);">+***/</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #include "asterisk.h"</span><br><span> </span><br><span> #include <curl/curl.h></span><br><span>@@ -44,6 +79,123 @@</span><br><span> </span><br><span> #define MAX_HEADER_LENGTH 1023</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef CURL_AT_LEAST_VERSION</span><br><span style="color: hsl(120, 100%, 40%);">+#if CURL_AT_LEAST_VERSION(7, 85, 0)</span><br><span style="color: hsl(120, 100%, 40%);">+#define AST_CURL_HAS_PROTOCOLS_STR 1</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int http_media_cache_config_pre_apply(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief General configuration options for http media cache. */</span><br><span style="color: hsl(120, 100%, 40%);">+struct conf_general_options {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief Request timeout to use */</span><br><span style="color: hsl(120, 100%, 40%);">+ int curl_timeout;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief Follow 3xx redirects automatically. */</span><br><span style="color: hsl(120, 100%, 40%);">+ int curl_followlocation;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief Number of redirects to follow for one request. */</span><br><span style="color: hsl(120, 100%, 40%);">+ int curl_maxredirs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! \brief Life-time of CURL DNS cache entries. */</span><br><span style="color: hsl(120, 100%, 40%);">+ int curl_dns_cache_timeout;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_DECLARE_STRING_FIELDS(</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STRING_FIELD(curl_useragent); /*! \brief User-agent to use for requests. */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STRING_FIELD(curl_proxy); /*! \brief Proxy to use for requests. None by default. */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STRING_FIELD(curl_protocols); /*! \brief Allowed protocols to use for requests. All by default. */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STRING_FIELD(curl_redir_protocols); /*! \brief Allowed protocols to use on redirect. All by default. */</span><br><span style="color: hsl(120, 100%, 40%);">+ );</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief All configuration options for http media cache. */</span><br><span style="color: hsl(120, 100%, 40%);">+struct conf {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The general section configuration options. */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct conf_general_options *general;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Locking container for safe configuration access. */</span><br><span style="color: hsl(120, 100%, 40%);">+static AO2_GLOBAL_OBJ_STATIC(confs);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Mapping of the http media cache conf struct's general to the general context in the config file. */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct aco_type general_option = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .type = ACO_GLOBAL,</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "general",</span><br><span style="color: hsl(120, 100%, 40%);">+ .item_offset = offsetof(struct conf, general),</span><br><span style="color: hsl(120, 100%, 40%);">+ .category = "general",</span><br><span style="color: hsl(120, 100%, 40%);">+ .category_match = ACO_WHITELIST_EXACT,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct aco_type *general_options[] = ACO_TYPES(&general_option);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Disposes of the http media cache conf object */</span><br><span style="color: hsl(120, 100%, 40%);">+static void conf_destructor(void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct conf *cfg = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_string_field_free_memory(cfg->general);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(cfg->general);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief Creates the http media cache conf object. */</span><br><span style="color: hsl(120, 100%, 40%);">+static void *conf_alloc(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct conf *cfg;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(cfg = ao2_alloc(sizeof(*cfg), conf_destructor))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(cfg->general = ao2_alloc(sizeof(*cfg->general), NULL))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(cfg, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_string_field_init(cfg->general, 256)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(cfg, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return cfg;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief The conf file that's processed for the module. */</span><br><span style="color: hsl(120, 100%, 40%);">+static struct aco_file conf_file = {</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The config file name. */</span><br><span style="color: hsl(120, 100%, 40%);">+ .filename = "res_http_media_cache.conf",</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The mapping object types to be processed. */</span><br><span style="color: hsl(120, 100%, 40%);">+ .types = ACO_TYPES(&general_option),</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+CONFIG_INFO_STANDARD(cfg_info, confs, conf_alloc,</span><br><span style="color: hsl(120, 100%, 40%);">+ .pre_apply_config = http_media_cache_config_pre_apply,</span><br><span style="color: hsl(120, 100%, 40%);">+ .files = ACO_FILES(&conf_file));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Pre-apply callback for the config framework.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This validates that used options match the ones supported by CURL.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static int http_media_cache_config_pre_apply(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef AST_CURL_HAS_PROTOCOLS_STR</span><br><span style="color: hsl(120, 100%, 40%);">+ struct conf *cfg = aco_pending_config(&cfg_info);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cfg->general->curl_protocols)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "'protocols' not supported by linked CURL library. Please recompile against newer CURL.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cfg->general->curl_redir_protocols)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "'redirect_protocols' not supported by linked CURL library. Please recompile against newer CURL.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Data passed to cURL callbacks */</span><br><span> struct curl_bucket_file_data {</span><br><span> /*! The \c ast_bucket_file object that caused the operation */</span><br><span>@@ -334,6 +486,8 @@</span><br><span> */</span><br><span> static CURL *get_curl_instance(struct curl_bucket_file_data *cb_data)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ RAII_VAR(struct conf *, cfg, ao2_global_obj_ref(confs), ao2_cleanup);</span><br><span style="color: hsl(120, 100%, 40%);">+ CURLcode rc;</span><br><span> CURL *curl;</span><br><span> </span><br><span> curl = curl_easy_init();</span><br><span>@@ -342,14 +496,47 @@</span><br><span> }</span><br><span> </span><br><span> curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);</span><br><span style="color: hsl(0, 100%, 40%);">- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);</span><br><span> curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);</span><br><span style="color: hsl(0, 100%, 40%);">- curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);</span><br><span style="color: hsl(0, 100%, 40%);">- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);</span><br><span style="color: hsl(0, 100%, 40%);">- curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 8);</span><br><span> curl_easy_setopt(curl, CURLOPT_URL, ast_sorcery_object_get_id(cb_data->bucket_file));</span><br><span> curl_easy_setopt(curl, CURLOPT_HEADERDATA, cb_data);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, cfg->general->curl_timeout);</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_setopt(curl, CURLOPT_USERAGENT, cfg->general->curl_useragent);</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, cfg->general->curl_followlocation ? 1 : 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_setopt(curl, CURLOPT_MAXREDIRS, cfg->general->curl_maxredirs);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cfg->general->curl_proxy)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_setopt(curl, CURLOPT_PROXY, cfg->general->curl_proxy);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cfg->general->curl_protocols)) {</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AST_CURL_HAS_PROTOCOLS_STR</span><br><span style="color: hsl(120, 100%, 40%);">+ CURLcode rc = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, cfg->general->curl_protocols);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc != CURLE_OK) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "Setting protocols to '%s' failed: %d\n", cfg->general->curl_protocols, rc);</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_cleanup(curl);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cfg->general->curl_redir_protocols)) {</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AST_CURL_HAS_PROTOCOLS_STR</span><br><span style="color: hsl(120, 100%, 40%);">+ CURLcode rc = curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, cfg->general->curl_redir_protocols);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc != CURLE_OK) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "Setting redirect_protocols to '%s' failed: %d\n", cfg->general->curl_redir_protocols, rc);</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_cleanup(curl);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, cfg->general->curl_dns_cache_timeout);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc != CURLE_OK) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_ERROR, "Setting dns_cache_timeout to '%d' failed: %d\n", cfg->general->curl_dns_cache_timeout, rc);</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_cleanup(curl);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return curl;</span><br><span> }</span><br><span> </span><br><span>@@ -551,11 +738,73 @@</span><br><span> </span><br><span> static int unload_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_info_destroy(&cfg_info);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_global_obj_release(confs);</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span> static int load_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (aco_info_init(&cfg_info)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_info_destroy(&cfg_info);</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_MODULE_LOAD_DECLINE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "timeout_secs", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ "180", OPT_INT_T, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ FLDSET(struct conf_general_options, curl_timeout));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "user_agent", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CURL_USER_AGENT, OPT_STRINGFIELD_T, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ STRFLDSET(struct conf_general_options, curl_useragent));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "follow_location", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ "yes", OPT_BOOL_T, 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ FLDSET(struct conf_general_options, curl_followlocation));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "max_redirects", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ "8", OPT_INT_T, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ FLDSET(struct conf_general_options, curl_maxredirs));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "proxy", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL, OPT_STRINGFIELD_T, 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ STRFLDSET(struct conf_general_options, curl_proxy));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "dns_cache_timeout_secs", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ "60", OPT_INT_T, 0,</span><br><span style="color: hsl(120, 100%, 40%);">+ FLDSET(struct conf_general_options, curl_dns_cache_timeout));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "protocols", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL, OPT_STRINGFIELD_T, 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ STRFLDSET(struct conf_general_options, curl_protocols));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_option_register(&cfg_info, "redirect_protocols", ACO_EXACT, general_options,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL, OPT_STRINGFIELD_T, 1,</span><br><span style="color: hsl(120, 100%, 40%);">+ STRFLDSET(struct conf_general_options, curl_redir_protocols));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct conf *cfg;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_NOTICE, "Could not load res_http_media_cache config; using defaults\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ cfg = conf_alloc();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!cfg) {</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_info_destroy(&cfg_info);</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_MODULE_LOAD_DECLINE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (aco_set_defaults(&general_option, "general", cfg->general)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to initialize res_http_media_cache defaults.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(cfg, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ aco_info_destroy(&cfg_info);</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_MODULE_LOAD_DECLINE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_global_obj_replace_unref(confs, cfg);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(cfg, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (ast_bucket_scheme_register("http", &http_bucket_wizard, &http_bucket_file_wizard,</span><br><span> NULL, NULL)) {</span><br><span> ast_log(LOG_ERROR, "Failed to register Bucket HTTP wizard scheme implementation\n");</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19952">change 19952</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19952"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I2eb02ef44190e026716720419bcbdbcc8125777b </div>
<div style="display:none"> Gerrit-Change-Number: 19952 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Holger Hans Peter Freyther <automatic@freyther.de> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>