<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18099">View Change</a></p><div style="white-space:pre-wrap">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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">asterisk: Add macro for curl user agent.<br><br>Currently, each module that uses libcurl duplicates the standard<br>Asterisk curl user agent.<br><br>This adds a global macro for the Asterisk user agent used for<br>curl requests to eliminate this duplication.<br><br>ASTERISK-29861 #close<br><br>Change-Id: I9fc37935980384b4daf96ae54fa3c9adb962ed2d<br>---<br>M funcs/func_curl.c<br>M include/asterisk.h<br>M res/res_http_media_cache.c<br>M res/res_stir_shaken/curl.c<br>M tests/test_res_prometheus.c<br>5 files changed, 6 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/funcs/func_curl.c b/funcs/func_curl.c</span><br><span>index 3b04f12..c51d273 100644</span><br><span>--- a/funcs/func_curl.c</span><br><span>+++ b/funcs/func_curl.c</span><br><span>@@ -600,8 +600,6 @@</span><br><span>        return realsize;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static const char * const global_useragent = "asterisk-libcurl-agent/1.0";</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static int curl_instance_init(void *data)</span><br><span> {</span><br><span>      CURL **curl = data;</span><br><span>@@ -612,7 +610,7 @@</span><br><span>    curl_easy_setopt(*curl, CURLOPT_NOSIGNAL, 1);</span><br><span>        curl_easy_setopt(*curl, CURLOPT_TIMEOUT, 180);</span><br><span>       curl_easy_setopt(*curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);</span><br><span style="color: hsl(0, 100%, 40%);">-    curl_easy_setopt(*curl, CURLOPT_USERAGENT, global_useragent);</span><br><span style="color: hsl(120, 100%, 40%);">+ curl_easy_setopt(*curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);</span><br><span> </span><br><span>         return 0;</span><br><span> }</span><br><span>diff --git a/include/asterisk.h b/include/asterisk.h</span><br><span>index 6a02908..1e5fd19 100644</span><br><span>--- a/include/asterisk.h</span><br><span>+++ b/include/asterisk.h</span><br><span>@@ -41,6 +41,8 @@</span><br><span> #endif</span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define AST_CURL_USER_AGENT "asterisk-libcurl-agent/1.0"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #define DEFAULT_LANGUAGE "en"</span><br><span> </span><br><span> #define DEFAULT_SAMPLE_RATE 8000</span><br><span>diff --git a/res/res_http_media_cache.c b/res/res_http_media_cache.c</span><br><span>index 12e7aee..a4efadf 100644</span><br><span>--- a/res/res_http_media_cache.c</span><br><span>+++ b/res/res_http_media_cache.c</span><br><span>@@ -42,8 +42,6 @@</span><br><span> #include "asterisk/threadstorage.h"</span><br><span> #include "asterisk/uri.h"</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #define MAX_HEADER_LENGTH 1023</span><br><span> </span><br><span> /*! \brief Data passed to cURL callbacks */</span><br><span>@@ -338,7 +336,7 @@</span><br><span>    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);</span><br><span>         curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);</span><br><span>        curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);</span><br><span style="color: hsl(0, 100%, 40%);">-   curl_easy_setopt(curl, CURLOPT_USERAGENT, GLOBAL_USERAGENT);</span><br><span style="color: hsl(120, 100%, 40%);">+  curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);</span><br><span>      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);</span><br><span>   curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 8);</span><br><span>        curl_easy_setopt(curl, CURLOPT_URL, ast_sorcery_object_get_id(cb_data->bucket_file));</span><br><span>diff --git a/res/res_stir_shaken/curl.c b/res/res_stir_shaken/curl.c</span><br><span>index 97c1098..b31160f 100644</span><br><span>--- a/res/res_stir_shaken/curl.c</span><br><span>+++ b/res/res_stir_shaken/curl.c</span><br><span>@@ -31,9 +31,6 @@</span><br><span> /* Used to check CURL headers */</span><br><span> #define MAX_HEADER_LENGTH 1023</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* Used for CURL requests */</span><br><span style="color: hsl(0, 100%, 40%);">-#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /* CURL callback data to avoid storing useless info in AstDB */</span><br><span> struct curl_cb_data {</span><br><span>   char *cache_control;</span><br><span>@@ -144,7 +141,7 @@</span><br><span> </span><br><span>       curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);</span><br><span>         curl_easy_setopt(curl, CURLOPT_TIMEOUT, curl_timeout);</span><br><span style="color: hsl(0, 100%, 40%);">-  curl_easy_setopt(curl, CURLOPT_USERAGENT, GLOBAL_USERAGENT);</span><br><span style="color: hsl(120, 100%, 40%);">+  curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);</span><br><span>      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);</span><br><span>   curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);</span><br><span>        curl_easy_setopt(curl, CURLOPT_HEADERDATA, data);</span><br><span>diff --git a/tests/test_res_prometheus.c b/tests/test_res_prometheus.c</span><br><span>index 2719267..4df4cb9 100644</span><br><span>--- a/tests/test_res_prometheus.c</span><br><span>+++ b/tests/test_res_prometheus.c</span><br><span>@@ -54,8 +54,6 @@</span><br><span>       }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static struct prometheus_general_config *config_alloc(void)</span><br><span> {</span><br><span>        struct prometheus_general_config *config;</span><br><span>@@ -84,7 +82,7 @@</span><br><span> </span><br><span>    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);</span><br><span>         curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);</span><br><span style="color: hsl(0, 100%, 40%);">-   curl_easy_setopt(curl, CURLOPT_USERAGENT, GLOBAL_USERAGENT);</span><br><span style="color: hsl(120, 100%, 40%);">+  curl_easy_setopt(curl, CURLOPT_USERAGENT, AST_CURL_USER_AGENT);</span><br><span>      curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);</span><br><span>   curl_easy_setopt(curl, CURLOPT_URL, server_uri);</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/+/18099">change 18099</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/+/18099"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I9fc37935980384b4daf96ae54fa3c9adb962ed2d </div>
<div style="display:none"> Gerrit-Change-Number: 18099 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Michael Bradeen <mbradeen@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>