<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16155">View Change</a></p><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; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_http_media_cache.c: Fix merge errors from 18 -> master<br><br>ASTERISK-27871 #close<br><br>Change-Id: I6624f2d3a57f76a89bb372ef54a124929a0338d7<br>---<br>M res/res_http_media_cache.c<br>M tests/test_http_media_cache.c<br>2 files changed, 9 insertions(+), 85 deletions(-)<br><br></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 ba9428d..5410566 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -40,6 +40,7 @@</span><br><span> #include "asterisk/bucket.h"</span><br><span> #include "asterisk/sorcery.h"</span><br><span> #include "asterisk/threadstorage.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/uri.h"</span><br><span> </span><br><span> #define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"</span><br><span> </span><br><span>@@ -229,84 +230,23 @@</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* The URL parsing API was introduced in 7.62.0 */</span><br><span style="color: hsl(0, 100%, 40%);">-#if LIBCURL_VERSION_NUM >= 0x073e00</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- char *path;</span><br><span style="color: hsl(0, 100%, 40%);">- CURLU *h;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_uri *uri;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- h = curl_url();</span><br><span style="color: hsl(0, 100%, 40%);">- if (!h) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Failed to allocate cURL URL handle\n");</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (curl_url_set(h, CURLUPART_URL, ast_sorcery_object_get_id(bucket_file), 0)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Failed to parse URL: %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ uri = ast_uri_parse(ast_sorcery_object_get_id(bucket_file));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!uri) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to parse URI: %s\n",</span><br><span> ast_sorcery_object_get_id(bucket_file));</span><br><span style="color: hsl(0, 100%, 40%);">- curl_url_cleanup(h);</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- curl_url_get(h, CURLUPART_PATH, &path, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /* Just parse it as a string like before, but without the extra cruft */</span><br><span style="color: hsl(0, 100%, 40%);">- buffer = file_extension_from_string(path, buffer, capacity);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- curl_free(path);</span><br><span style="color: hsl(0, 100%, 40%);">- curl_url_cleanup(h);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ buffer = file_extension_from_string(ast_uri_path(uri), buffer, capacity);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(uri);</span><br><span> return buffer;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#elif defined(HAVE_URIPARSER)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <uriparser/Uri.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- UriParserStateA state;</span><br><span style="color: hsl(0, 100%, 40%);">- UriUriA full_uri;</span><br><span style="color: hsl(0, 100%, 40%);">- char *path;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- state.uri = &full_uri;</span><br><span style="color: hsl(0, 100%, 40%);">- if (uriParseUriA(&state, ast_sorcery_object_get_id(bucket_file)) != URI_SUCCESS</span><br><span style="color: hsl(0, 100%, 40%);">- || !full_uri.scheme.first</span><br><span style="color: hsl(0, 100%, 40%);">- || !full_uri.scheme.afterLast</span><br><span style="color: hsl(0, 100%, 40%);">- || !full_uri.pathTail) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_ERROR, "Failed to parse URL: %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_object_get_id(bucket_file));</span><br><span style="color: hsl(0, 100%, 40%);">- uriFreeUriMembersA(&full_uri);</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_asprintf(&path,</span><br><span style="color: hsl(0, 100%, 40%);">- "%.*s",</span><br><span style="color: hsl(0, 100%, 40%);">- (int) (full_uri.pathTail->text.afterLast - full_uri.pathTail->text.first),</span><br><span style="color: hsl(0, 100%, 40%);">- full_uri.pathTail->text.first) != -1) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Just parse it as a string like before, but without the extra cruft */</span><br><span style="color: hsl(0, 100%, 40%);">- file_extension_from_string(path, buffer, capacity);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(path);</span><br><span style="color: hsl(0, 100%, 40%);">- uriFreeUriMembersA(&full_uri);</span><br><span style="color: hsl(0, 100%, 40%);">- return buffer;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- uriFreeUriMembersA(&full_uri);</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#else</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- /* NOP */</span><br><span style="color: hsl(0, 100%, 40%);">- return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static void bucket_file_set_extension(struct ast_bucket_file *bucket_file)</span><br><span> {</span><br><span> /* We will attempt to determine an extension in the following order for backwards</span><br><span>diff --git a/tests/test_http_media_cache.c b/tests/test_http_media_cache.c</span><br><span>index dfb28b7..90d1aef 100644</span><br><span>--- a/tests/test_http_media_cache.c</span><br><span>+++ b/tests/test_http_media_cache.c</span><br><span>@@ -41,14 +41,6 @@</span><br><span> #include "asterisk/bucket.h"</span><br><span> #include "asterisk/test.h"</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#undef INCLUDE_URI_PARSING_TESTS</span><br><span style="color: hsl(0, 100%, 40%);">-#if defined(HAVE_CURL)</span><br><span style="color: hsl(0, 100%, 40%);">-# include <curl/curl.h></span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-#if (defined(HAVE_CURL) && LIBCURL_VERSION_NUM >= 0x073e00) || defined(HAVE_URIPARSER)</span><br><span style="color: hsl(0, 100%, 40%);">-# define INCLUDE_URI_PARSING_TESTS 1</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #define CATEGORY "/res/http_media_cache/"</span><br><span> </span><br><span> #define TEST_URI "test_media_cache"</span><br><span>@@ -268,7 +260,6 @@</span><br><span> return AST_TEST_PASS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef INCLUDE_URI_PARSING_TESTS</span><br><span> AST_TEST_DEFINE(retrieve_parsed_uri)</span><br><span> {</span><br><span> RAII_VAR(struct ast_bucket_file *, bucket_file, NULL, bucket_file_cleanup);</span><br><span>@@ -302,7 +293,6 @@</span><br><span> </span><br><span> return AST_TEST_PASS;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span> </span><br><span> AST_TEST_DEFINE(retrieve_cache_control_directives)</span><br><span> {</span><br><span>@@ -754,11 +744,8 @@</span><br><span> AST_TEST_REGISTER(retrieve_etag_expired);</span><br><span> AST_TEST_REGISTER(retrieve_cache_control_age);</span><br><span> AST_TEST_REGISTER(retrieve_cache_control_directives);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_TEST_REGISTER(retrieve_content_type);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef INCLUDE_URI_PARSING_TESTS</span><br><span> AST_TEST_REGISTER(retrieve_parsed_uri);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(retrieve_content_type);</span><br><span> </span><br><span> ast_test_register_init(CATEGORY, pre_test_cb);</span><br><span> </span><br><span>@@ -777,11 +764,8 @@</span><br><span> AST_TEST_UNREGISTER(retrieve_etag_expired);</span><br><span> AST_TEST_UNREGISTER(retrieve_cache_control_age);</span><br><span> AST_TEST_UNREGISTER(retrieve_cache_control_directives);</span><br><span style="color: hsl(0, 100%, 40%);">- AST_TEST_REGISTER(retrieve_content_type);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef INCLUDE_URI_PARSING_TESTS</span><br><span> AST_TEST_REGISTER(retrieve_parsed_uri);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(retrieve_content_type);</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16155">change 16155</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/+/16155"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I6624f2d3a57f76a89bb372ef54a124929a0338d7 </div>
<div style="display:none"> Gerrit-Change-Number: 16155 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean@seanbright.com> </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>