[Asterisk-code-review] asterisk: Add macro for curl user agent. (asterisk[19])

N A asteriskteam at digium.com
Thu Feb 24 06:43:05 CST 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18098 )


Change subject: asterisk: Add macro for curl user agent.
......................................................................

asterisk: Add macro for curl user agent.

Currently, each module that uses libcurl duplicates the standard
Asterisk curl user agent.

This adds a global macro for the Asterisk user agent used for
curl requests to eliminate this duplication.

ASTERISK-29861 #close

Change-Id: I9fc37935980384b4daf96ae54fa3c9adb962ed2d
---
M funcs/func_curl.c
M include/asterisk.h
M res/res_http_media_cache.c
M res/res_stir_shaken/curl.c
M tests/test_res_prometheus.c
5 files changed, 6 insertions(+), 13 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/98/18098/1

diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index 3b04f12..c51d273 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -600,8 +600,6 @@
 	return realsize;
 }
 
-static const char * const global_useragent = "asterisk-libcurl-agent/1.0";
-
 static int curl_instance_init(void *data)
 {
 	CURL **curl = data;
@@ -612,7 +610,7 @@
 	curl_easy_setopt(*curl, CURLOPT_NOSIGNAL, 1);
 	curl_easy_setopt(*curl, CURLOPT_TIMEOUT, 180);
 	curl_easy_setopt(*curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
-	curl_easy_setopt(*curl, CURLOPT_USERAGENT, global_useragent);
+	curl_easy_setopt(*curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);
 
 	return 0;
 }
diff --git a/include/asterisk.h b/include/asterisk.h
index 6a02908..1e5fd19 100644
--- a/include/asterisk.h
+++ b/include/asterisk.h
@@ -41,6 +41,8 @@
 #endif
 
 
+#define AST_CURL_USER_AGENT "asterisk-libcurl-agent/1.0"
+
 #define DEFAULT_LANGUAGE "en"
 
 #define DEFAULT_SAMPLE_RATE 8000
diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c
index c0363b1..2bace1e 100644
--- a/res/res_http_media_cache.c
+++ b/res/res_http_media_cache.c
@@ -42,8 +42,6 @@
 #include "asterisk/threadstorage.h"
 #include "asterisk/uri.h"
 
-#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"
-
 #define MAX_HEADER_LENGTH 1023
 
 /*! \brief Data passed to cURL callbacks */
@@ -328,7 +326,7 @@
 	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
 	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, GLOBAL_USERAGENT);
+	curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);
 	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
 	curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 8);
 	curl_easy_setopt(curl, CURLOPT_URL, ast_sorcery_object_get_id(cb_data->bucket_file));
diff --git a/res/res_stir_shaken/curl.c b/res/res_stir_shaken/curl.c
index 97c1098..b31160f 100644
--- a/res/res_stir_shaken/curl.c
+++ b/res/res_stir_shaken/curl.c
@@ -31,9 +31,6 @@
 /* Used to check CURL headers */
 #define MAX_HEADER_LENGTH 1023
 
-/* Used for CURL requests */
-#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"
-
 /* CURL callback data to avoid storing useless info in AstDB */
 struct curl_cb_data {
 	char *cache_control;
@@ -144,7 +141,7 @@
 
 	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 	curl_easy_setopt(curl, CURLOPT_TIMEOUT, curl_timeout);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, GLOBAL_USERAGENT);
+	curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);
 	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
 	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);
 	curl_easy_setopt(curl, CURLOPT_HEADERDATA, data);
diff --git a/tests/test_res_prometheus.c b/tests/test_res_prometheus.c
index 2719267..4df4cb9 100644
--- a/tests/test_res_prometheus.c
+++ b/tests/test_res_prometheus.c
@@ -54,8 +54,6 @@
 	}
 }
 
-#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"
-
 static struct prometheus_general_config *config_alloc(void)
 {
 	struct prometheus_general_config *config;
@@ -84,7 +82,7 @@
 
 	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
-	curl_easy_setopt(curl, CURLOPT_USERAGENT, GLOBAL_USERAGENT);
+	curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);
 	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
 	curl_easy_setopt(curl, CURLOPT_URL, server_uri);
 

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

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: I9fc37935980384b4daf96ae54fa3c9adb962ed2d
Gerrit-Change-Number: 18098
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220224/829d9efc/attachment.html>


More information about the asterisk-code-review mailing list