[sr-dev] git:master:875fd4cc: http_client: http_query reuse the default user agent setting

Daniel-Constantin Mierla miconda at gmail.com
Mon Jul 4 15:22:13 CEST 2016


Module: kamailio
Branch: master
Commit: 875fd4cc96d9aab15ab307e8f991a876b8ed31be
URL: https://github.com/kamailio/kamailio/commit/875fd4cc96d9aab15ab307e8f991a876b8ed31be

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-07-04T15:20:21+02:00

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

---

Modified: modules/http_client/functions.c

---

Diff:  https://github.com/kamailio/kamailio/commit/875fd4cc96d9aab15ab307e8f991a876b8ed31be.diff
Patch: https://github.com/kamailio/kamailio/commit/875fd4cc96d9aab15ab307e8f991a876b8ed31be.patch

---

diff --git a/modules/http_client/functions.c b/modules/http_client/functions.c
index 258508d..3b6e808 100644
--- a/modules/http_client/functions.c
+++ b/modules/http_client/functions.c
@@ -54,6 +54,7 @@ typedef struct {
 	char *ciphersuites;
 	char *http_proxy;
 	char *failovercon;
+	char *useragent;
 	unsigned int authmethod;
 	unsigned int http_proxy_port;
 	unsigned int tlsversion;
@@ -68,11 +69,11 @@ typedef struct {
 } curl_query_t;
 
 
-/* 
+/*
  * curl write function that saves received data as zero terminated
  * 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.
  */
 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_WRITEDATA, &stream);
 
+	if(params->useragent)
+		res |= curl_easy_setopt(curl, CURLOPT_USERAGENT, params->useragent);
 
 	if (res != CURLE_OK) {
 		/* 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.oneline = 1;
 	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) {
 		query_params.http_proxy = default_http_proxy.s;
 		if(default_http_proxy_port>0) {




More information about the sr-dev mailing list