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
This commit is contained in:
parent
1633410161
commit
e26b57984f
|
@ -600,8 +600,6 @@ static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *da
|
||||||
return realsize;
|
return realsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const global_useragent = "asterisk-libcurl-agent/1.0";
|
|
||||||
|
|
||||||
static int curl_instance_init(void *data)
|
static int curl_instance_init(void *data)
|
||||||
{
|
{
|
||||||
CURL **curl = data;
|
CURL **curl = data;
|
||||||
|
@ -612,7 +610,7 @@ static int curl_instance_init(void *data)
|
||||||
curl_easy_setopt(*curl, CURLOPT_NOSIGNAL, 1);
|
curl_easy_setopt(*curl, CURLOPT_NOSIGNAL, 1);
|
||||||
curl_easy_setopt(*curl, CURLOPT_TIMEOUT, 180);
|
curl_easy_setopt(*curl, CURLOPT_TIMEOUT, 180);
|
||||||
curl_easy_setopt(*curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define AST_CURL_USER_AGENT "asterisk-libcurl-agent/1.0"
|
||||||
|
|
||||||
#define DEFAULT_LANGUAGE "en"
|
#define DEFAULT_LANGUAGE "en"
|
||||||
|
|
||||||
#define DEFAULT_SAMPLE_RATE 8000
|
#define DEFAULT_SAMPLE_RATE 8000
|
||||||
|
|
|
@ -42,8 +42,6 @@
|
||||||
#include "asterisk/threadstorage.h"
|
#include "asterisk/threadstorage.h"
|
||||||
#include "asterisk/uri.h"
|
#include "asterisk/uri.h"
|
||||||
|
|
||||||
#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"
|
|
||||||
|
|
||||||
#define MAX_HEADER_LENGTH 1023
|
#define MAX_HEADER_LENGTH 1023
|
||||||
|
|
||||||
/*! \brief Data passed to cURL callbacks */
|
/*! \brief Data passed to cURL callbacks */
|
||||||
|
@ -328,7 +326,7 @@ static CURL *get_curl_instance(struct curl_bucket_file_data *cb_data)
|
||||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);
|
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_FOLLOWLOCATION, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 8);
|
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 8);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, ast_sorcery_object_get_id(cb_data->bucket_file));
|
curl_easy_setopt(curl, CURLOPT_URL, ast_sorcery_object_get_id(cb_data->bucket_file));
|
||||||
|
|
|
@ -31,9 +31,6 @@
|
||||||
/* Used to check CURL headers */
|
/* Used to check CURL headers */
|
||||||
#define MAX_HEADER_LENGTH 1023
|
#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 */
|
/* CURL callback data to avoid storing useless info in AstDB */
|
||||||
struct curl_cb_data {
|
struct curl_cb_data {
|
||||||
char *cache_control;
|
char *cache_control;
|
||||||
|
@ -144,7 +141,7 @@ static CURL *get_curl_instance(struct curl_cb_data *data)
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, curl_timeout);
|
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_FOLLOWLOCATION, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);
|
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_header_callback);
|
||||||
curl_easy_setopt(curl, CURLOPT_HEADERDATA, data);
|
curl_easy_setopt(curl, CURLOPT_HEADERDATA, data);
|
||||||
|
|
|
@ -54,8 +54,6 @@ static void prometheus_metric_free_wrapper(void *ptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GLOBAL_USERAGENT "asterisk-libcurl-agent/1.0"
|
|
||||||
|
|
||||||
static struct prometheus_general_config *config_alloc(void)
|
static struct prometheus_general_config *config_alloc(void)
|
||||||
{
|
{
|
||||||
struct prometheus_general_config *config;
|
struct prometheus_general_config *config;
|
||||||
|
@ -84,7 +82,7 @@ static CURL *get_curl_instance(void)
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
|
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_FOLLOWLOCATION, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, server_uri);
|
curl_easy_setopt(curl, CURLOPT_URL, server_uri);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue