[Asterisk-code-review] asterisk: Add macro for curl user agent. (asterisk[18])
Friendly Automation
asteriskteam at digium.com
Fri Feb 25 12:45:38 CST 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18099 )
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(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Michael Bradeen: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Friendly Automation: Approved for Submit
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 12e7aee..a4efadf 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 */
@@ -338,7 +336,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/+/18099
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I9fc37935980384b4daf96ae54fa3c9adb962ed2d
Gerrit-Change-Number: 18099
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220225/1ba5b309/attachment-0001.html>
More information about the asterisk-code-review
mailing list