[Asterisk-code-review] res_http_media_cache.c: Fix merge errors from 18 -> master (asterisk[master])

Sean Bright asteriskteam at digium.com
Mon Jul 19 07:32:57 CDT 2021


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16155 )


Change subject: res_http_media_cache.c: Fix merge errors from 18 -> master
......................................................................

res_http_media_cache.c: Fix merge errors from 18 -> master

ASTERISK-27871 #close

Change-Id: I6624f2d3a57f76a89bb372ef54a124929a0338d7
---
M res/res_http_media_cache.c
M tests/test_http_media_cache.c
2 files changed, 9 insertions(+), 85 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/55/16155/1

diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c
index ba9428d..5410566 100644
--- a/res/res_http_media_cache.c
+++ b/res/res_http_media_cache.c
@@ -40,6 +40,7 @@
 #include "asterisk/bucket.h"
 #include "asterisk/sorcery.h"
 #include "asterisk/threadstorage.h"
+#include "asterisk/uri.h"
 
 #define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"
 
@@ -229,84 +230,23 @@
 	return NULL;
 }
 
-/* The URL parsing API was introduced in 7.62.0 */
-#if LIBCURL_VERSION_NUM >= 0x073e00
-
 static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)
 {
-	char *path;
-	CURLU *h;
+	struct ast_uri *uri;
 
-	h = curl_url();
-	if (!h) {
-		ast_log(LOG_ERROR, "Failed to allocate cURL URL handle\n");
-		return NULL;
-	}
-
-	if (curl_url_set(h, CURLUPART_URL, ast_sorcery_object_get_id(bucket_file), 0)) {
-		ast_log(LOG_ERROR, "Failed to parse URL: %s\n",
+	uri = ast_uri_parse(ast_sorcery_object_get_id(bucket_file));
+	if (!uri) {
+		ast_log(LOG_ERROR, "Failed to parse URI: %s\n",
 			ast_sorcery_object_get_id(bucket_file));
-		curl_url_cleanup(h);
 		return NULL;
 	}
 
-	curl_url_get(h, CURLUPART_PATH, &path, 0);
-
 	/* Just parse it as a string like before, but without the extra cruft */
-	buffer = file_extension_from_string(path, buffer, capacity);
-
-	curl_free(path);
-	curl_url_cleanup(h);
-
+	buffer = file_extension_from_string(ast_uri_path(uri), buffer, capacity);
+	ao2_cleanup(uri);
 	return buffer;
 }
 
-#elif defined(HAVE_URIPARSER)
-
-#include <uriparser/Uri.h>
-
-static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)
-{
-	UriParserStateA state;
-	UriUriA full_uri;
-	char *path;
-
-	state.uri = &full_uri;
-	if (uriParseUriA(&state, ast_sorcery_object_get_id(bucket_file)) != URI_SUCCESS
-	   || !full_uri.scheme.first
-	   || !full_uri.scheme.afterLast
-	   || !full_uri.pathTail) {
-		ast_log(LOG_ERROR, "Failed to parse URL: %s\n",
-			ast_sorcery_object_get_id(bucket_file));
-		uriFreeUriMembersA(&full_uri);
-		return NULL;
-	}
-
-	if (ast_asprintf(&path,
-			"%.*s",
-			(int) (full_uri.pathTail->text.afterLast - full_uri.pathTail->text.first),
-			full_uri.pathTail->text.first) != -1) {
-		/* Just parse it as a string like before, but without the extra cruft */
-		file_extension_from_string(path, buffer, capacity);
-		ast_free(path);
-		uriFreeUriMembersA(&full_uri);
-		return buffer;
-	}
-
-	uriFreeUriMembersA(&full_uri);
-	return NULL;
-}
-
-#else
-
-static char *file_extension_from_url_path(struct ast_bucket_file *bucket_file, char *buffer, size_t capacity)
-{
-	/* NOP */
-	return NULL;
-}
-
-#endif
-
 static void bucket_file_set_extension(struct ast_bucket_file *bucket_file)
 {
 	/* We will attempt to determine an extension in the following order for backwards
diff --git a/tests/test_http_media_cache.c b/tests/test_http_media_cache.c
index dfb28b7..90d1aef 100644
--- a/tests/test_http_media_cache.c
+++ b/tests/test_http_media_cache.c
@@ -41,14 +41,6 @@
 #include "asterisk/bucket.h"
 #include "asterisk/test.h"
 
-#undef INCLUDE_URI_PARSING_TESTS
-#if defined(HAVE_CURL)
-# include <curl/curl.h>
-#endif
-#if (defined(HAVE_CURL) && LIBCURL_VERSION_NUM >= 0x073e00) || defined(HAVE_URIPARSER)
-# define INCLUDE_URI_PARSING_TESTS 1
-#endif
-
 #define CATEGORY "/res/http_media_cache/"
 
 #define TEST_URI "test_media_cache"
@@ -268,7 +260,6 @@
 	return AST_TEST_PASS;
 }
 
-#ifdef INCLUDE_URI_PARSING_TESTS
 AST_TEST_DEFINE(retrieve_parsed_uri)
 {
 	RAII_VAR(struct ast_bucket_file *, bucket_file, NULL, bucket_file_cleanup);
@@ -302,7 +293,6 @@
 
 	return AST_TEST_PASS;
 }
-#endif
 
 AST_TEST_DEFINE(retrieve_cache_control_directives)
 {
@@ -754,11 +744,8 @@
 	AST_TEST_REGISTER(retrieve_etag_expired);
 	AST_TEST_REGISTER(retrieve_cache_control_age);
 	AST_TEST_REGISTER(retrieve_cache_control_directives);
-	AST_TEST_REGISTER(retrieve_content_type);
-
-#ifdef INCLUDE_URI_PARSING_TESTS
 	AST_TEST_REGISTER(retrieve_parsed_uri);
-#endif
+	AST_TEST_REGISTER(retrieve_content_type);
 
 	ast_test_register_init(CATEGORY, pre_test_cb);
 
@@ -777,11 +764,8 @@
 	AST_TEST_UNREGISTER(retrieve_etag_expired);
 	AST_TEST_UNREGISTER(retrieve_cache_control_age);
 	AST_TEST_UNREGISTER(retrieve_cache_control_directives);
-	AST_TEST_REGISTER(retrieve_content_type);
-
-#ifdef INCLUDE_URI_PARSING_TESTS
 	AST_TEST_REGISTER(retrieve_parsed_uri);
-#endif
+	AST_TEST_REGISTER(retrieve_content_type);
 
 	return 0;
 }

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I6624f2d3a57f76a89bb372ef54a124929a0338d7
Gerrit-Change-Number: 16155
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210719/2c21aab9/attachment-0001.html>


More information about the asterisk-code-review mailing list