<p>Holger Hans Peter Freyther has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19700">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_http_media_cache: Allow to specify protocols to be used<br><br>CURL allows many protocols to be used and might not have<br>sensible defaults. Allow limiting the protocols and the<br>redirect behavior.<br><br>ASTERISK-30340<br><br>Change-Id: Iafbdce91c8cc9505f6b020053c0aa5767618c5b0<br>---<br>M res/res_http_media_cache.c<br>1 file changed, 56 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/19700/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c</span><br><span>index 7528aac..c8ff0e4 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -52,6 +52,12 @@</span><br><span>                                 <configOption name="proxy"></span><br><span>                                  <synopsis>The proxy to use for requests. See  https://curl.se/libcurl/c/CURLOPT_PROXY.html for details.</synopsis></span><br><span>                               </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.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="redir_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>                        </configObject></span><br><span>                </configFile></span><br><span>  </configInfo></span><br><span>@@ -70,12 +76,17 @@</span><br><span> </span><br><span> #define MAX_HEADER_LENGTH 1023</span><br><span> </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%);">+</span><br><span> static int cache_curl_timeout = 180;</span><br><span> static char *cache_curl_useragent = NULL;</span><br><span> static int cache_followlocation = 1;</span><br><span> static int cache_maxredirs = 8;</span><br><span> static char *cache_curl_proxy = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+static char *cache_curl_protocols = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+static char *cache_curl_redir_protocols = NULL;</span><br><span> </span><br><span> </span><br><span> /*! \brief Data passed to cURL callbacks */</span><br><span>@@ -368,6 +379,27 @@</span><br><span>  curl_easy_setopt(curl, CURLOPT_HEADERDATA, cb_data);</span><br><span>         curl_easy_setopt(curl, CURLOPT_PROXY, cache_curl_proxy);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  if (cache_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, cache_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", cache_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 (cache_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, cache_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 redir_protocols to '%s' failed: %d\n", cache_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>  return curl;</span><br><span> }</span><br><span> </span><br><span>@@ -612,6 +644,14 @@</span><br><span>                                         } else {</span><br><span>                                             cache_curl_proxy = NULL;</span><br><span>                                     }</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef AST_CURL_HAS_PROTOCOLS_STR</span><br><span style="color: hsl(120, 100%, 40%);">+                          } else if (strcasecmp(var->name, "protocols") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                    ast_free(cache_curl_protocols);</span><br><span style="color: hsl(120, 100%, 40%);">+                                       cache_curl_protocols = ast_strdup(var->value);</span><br><span style="color: hsl(120, 100%, 40%);">+                             } else if (strcasecmp(var->name, "redir_protocols") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      ast_free(cache_curl_redir_protocols);</span><br><span style="color: hsl(120, 100%, 40%);">+                                 cache_curl_redir_protocols = ast_strdup(var->value);</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span>                              } else {</span><br><span>                                     ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);</span><br><span>                                    ast_config_destroy(cfg);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19700">change 19700</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/+/19700"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 20 </div>
<div style="display:none"> Gerrit-Change-Id: Iafbdce91c8cc9505f6b020053c0aa5767618c5b0 </div>
<div style="display:none"> Gerrit-Change-Number: 19700 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Holger Hans Peter Freyther <automatic@freyther.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>