瀏覽代碼

http_client: http_query reuse the default user agent setting

- based on GH #674, by Jurijs Ivolga
- useful for simplified upgrade of the configs using utils version of
  the http query to the http_client module
Daniel-Constantin Mierla 9 年之前
父節點
當前提交
875fd4cc96
共有 1 個文件被更改,包括 8 次插入2 次删除
  1. 8 2
      modules/http_client/functions.c

+ 8 - 2
modules/http_client/functions.c

@@ -54,6 +54,7 @@ typedef struct {
 	char *ciphersuites;
 	char *ciphersuites;
 	char *http_proxy;
 	char *http_proxy;
 	char *failovercon;
 	char *failovercon;
+	char *useragent;
 	unsigned int authmethod;
 	unsigned int authmethod;
 	unsigned int http_proxy_port;
 	unsigned int http_proxy_port;
 	unsigned int tlsversion;
 	unsigned int tlsversion;
@@ -68,11 +69,11 @@ typedef struct {
 } curl_query_t;
 } curl_query_t;
 
 
 
 
-/* 
+/*
  * curl write function that saves received data as zero terminated
  * curl write function that saves received data as zero terminated
  * to stream. Returns the amount of data taken care of.
  * to stream. Returns the amount of data taken care of.
  *
  *
- * This function may be called multiple times for larger responses, 
+ * This function may be called multiple times for larger responses,
  * so it reallocs + concatenates the buffer as needed.
  * so it reallocs + concatenates the buffer as needed.
  */
  */
 size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
 size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
@@ -228,6 +229,8 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst, const
 	res |= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
 	res |= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
 	res |= curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
 	res |= curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
 
 
+	if(params->useragent)
+		res |= curl_easy_setopt(curl, CURLOPT_USERAGENT, params->useragent);
 
 
 	if (res != CURLE_OK) {
 	if (res != CURLE_OK) {
 		/* PANIC */
 		/* PANIC */
@@ -587,6 +590,9 @@ int http_query(struct sip_msg* _m, char* _url, str* _dst, char* _post)
 	query_params.http_follow_redirect = default_http_follow_redirect;
 	query_params.http_follow_redirect = default_http_follow_redirect;
 	query_params.oneline = 1;
 	query_params.oneline = 1;
 	query_params.maxdatasize = 0;
 	query_params.maxdatasize = 0;
+	if(default_useragent.s!=NULL && default_useragent.len>0) {
+		query_params.useragent = default_useragent.s;
+	}
 	if(default_http_proxy.s!=NULL && default_http_proxy.len>0) {
 	if(default_http_proxy.s!=NULL && default_http_proxy.len>0) {
 		query_params.http_proxy = default_http_proxy.s;
 		query_params.http_proxy = default_http_proxy.s;
 		if(default_http_proxy_port>0) {
 		if(default_http_proxy_port>0) {