[Asterisk-code-review] res_http_media_cache: Allow to specify protocols to be used (asterisk[20])

Holger Hans Peter Freyther asteriskteam at digium.com
Fri Dec 9 01:07:37 CST 2022


Holger Hans Peter Freyther has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19700 )


Change subject: res_http_media_cache: Allow to specify protocols to be used
......................................................................

res_http_media_cache: Allow to specify protocols to be used

CURL allows many protocols to be used and might not have
sensible defaults. Allow limiting the protocols and the
redirect behavior.

ASTERISK-30340

Change-Id: Iafbdce91c8cc9505f6b020053c0aa5767618c5b0
---
M res/res_http_media_cache.c
1 file changed, 56 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/19700/1

diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c
index 7528aac..c8ff0e4 100644
--- a/res/res_http_media_cache.c
+++ b/res/res_http_media_cache.c
@@ -52,6 +52,12 @@
 				<configOption name="proxy">
 					<synopsis>The proxy to use for requests. See  https://curl.se/libcurl/c/CURLOPT_PROXY.html for details.</synopsis>
 				</configOption>
+				<configOption name="protocols">
+					<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>
+				</configOption>
+				<configOption name="redir_protocols">
+					<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>
+				</configOption>
 			</configObject>
 		</configFile>
 	</configInfo>
@@ -70,12 +76,17 @@
 
 #define MAX_HEADER_LENGTH 1023
 
+#if CURL_AT_LEAST_VERSION(7, 85, 0)
+#define AST_CURL_HAS_PROTOCOLS_STR 1
+#endif
+
 static int cache_curl_timeout = 180;
 static char *cache_curl_useragent = NULL;
 static int cache_followlocation = 1;
 static int cache_maxredirs = 8;
 static char *cache_curl_proxy = NULL;
-
+static char *cache_curl_protocols = NULL;
+static char *cache_curl_redir_protocols = NULL;
 
 
 /*! \brief Data passed to cURL callbacks */
@@ -368,6 +379,27 @@
 	curl_easy_setopt(curl, CURLOPT_HEADERDATA, cb_data);
 	curl_easy_setopt(curl, CURLOPT_PROXY, cache_curl_proxy);
 
+	if (cache_curl_protocols) {
+#ifdef AST_CURL_HAS_PROTOCOLS_STR
+		CURLcode rc = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, cache_curl_protocols);
+		if (rc != CURLE_OK) {
+			ast_log(AST_LOG_ERROR, "Setting protocols to '%s' failed: %d\n", cache_curl_protocols, rc);
+			curl_easy_cleanup(curl);
+			return NULL;
+		}
+#endif
+	}
+	if (cache_curl_redir_protocols) {
+#ifdef AST_CURL_HAS_PROTOCOLS_STR
+		CURLcode rc = curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS_STR, cache_curl_redir_protocols);
+		if (rc != CURLE_OK) {
+			ast_log(AST_LOG_ERROR, "Setting redir_protocols to '%s' failed: %d\n", cache_curl_redir_protocols, rc);
+			curl_easy_cleanup(curl);
+			return NULL;
+		}
+#endif
+	}
+
 	return curl;
 }
 
@@ -612,6 +644,14 @@
 					} else {
 						cache_curl_proxy = NULL;
 					}
+#ifdef AST_CURL_HAS_PROTOCOLS_STR
+				} else if (strcasecmp(var->name, "protocols") == 0) {
+					ast_free(cache_curl_protocols);
+					cache_curl_protocols = ast_strdup(var->value);
+				} else if (strcasecmp(var->name, "redir_protocols") == 0) {
+					ast_free(cache_curl_redir_protocols);
+					cache_curl_redir_protocols = ast_strdup(var->value);
+#endif
 				} else {
 					ast_log(LOG_ERROR, "Unrecognized variable '%s' in category '%s'\n", var->name, cat);
 					ast_config_destroy(cfg);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19700
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: Iafbdce91c8cc9505f6b020053c0aa5767618c5b0
Gerrit-Change-Number: 19700
Gerrit-PatchSet: 1
Gerrit-Owner: Holger Hans Peter Freyther <automatic at freyther.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221209/7c234bde/attachment.html>


More information about the asterisk-code-review mailing list