[sr-dev] git:4.4:e81e1506: http_client: removed unnecessary cloning of proxy parameter

Daniel-Constantin Mierla miconda at gmail.com
Tue Jun 28 09:42:58 CEST 2016


Module: kamailio
Branch: 4.4
Commit: e81e15068b9733c2ed1ec21eb1fb4b5972bde36b
URL: https://github.com/kamailio/kamailio/commit/e81e15068b9733c2ed1ec21eb1fb4b5972bde36b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-06-28T09:42:00+02:00

http_client: removed unnecessary cloning of proxy parameter

- the value is already zero terminated and this way avoid memory leak
- wrap returning code to cfg in order to avoid 0 values
- backported from master branch commit
  be677c2f8930f967277438b7b661baeacd7a5a53

---

Modified: modules/http_client/functions.c
Modified: modules/http_client/http_client.c

---

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

---

diff --git a/modules/http_client/functions.c b/modules/http_client/functions.c
index 45e1b27..c1305ac 100644
--- a/modules/http_client/functions.c
+++ b/modules/http_client/functions.c
@@ -434,8 +434,12 @@ 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;
-	query_params.http_proxy = as_asciiz(&default_http_proxy);
-	query_params.http_proxy_port = default_http_proxy_port;
+	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) {
+				query_params.http_proxy_port = default_http_proxy_port;
+			}
+	}
 
 	res =  curL_query_url(_m, _url, _dst, &query_params);
 
diff --git a/modules/http_client/http_client.c b/modules/http_client/http_client.c
index 14f66cb..d05c346 100644
--- a/modules/http_client/http_client.c
+++ b/modules/http_client/http_client.c
@@ -213,7 +213,7 @@ static void curl_counter_init()
 /* Module initialization function */
 static int mod_init(void)
 {
-	
+
 	LM_DBG("init curl module\n");
 
 	/* Initialize curl */
@@ -293,7 +293,7 @@ int curl_support_ipv6()
 
 /* Child initialization function */
 static int child_init(int rank)
-{	
+{
 	if (rank==PROC_INIT || rank==PROC_MAIN || rank==PROC_TCP_MAIN) {
 		return 0; /* do nothing for the main process */
 	}
@@ -367,7 +367,7 @@ static int fixup_free_http_query_get(void** param, int param_no)
     if (param_no == 2) {
 	return fixup_free_pvar_null(param, 1);
     }
-    
+
     LM_ERR("invalid parameter number <%d>\n", param_no);
     return -1;
 }
@@ -405,8 +405,8 @@ static int fixup_curl_connect(void** param, int param_no)
 }
 
 /*
- * Fix curl_connect params when posting (5 parameters): 
- *	connection (string/pvar), url (string with pvars), content-type, 
+ * Fix curl_connect params when posting (5 parameters):
+ *	connection (string/pvar), url (string with pvars), content-type,
  *      data (string/pvar, pvar)
  */
 static int fixup_curl_connect_post(void** param, int param_no)
@@ -453,7 +453,7 @@ static int fixup_free_curl_connect_post(void** param, int param_no)
     if (param_no == 5) {
 	return fixup_free_pvar_null(param, 1);
     }
-    
+
     LM_ERR("invalid parameter number <%d>\n", param_no);
     return -1;
 }
@@ -474,7 +474,7 @@ static int fixup_free_curl_connect(void** param, int param_no)
     if (param_no == 3) {
 	return fixup_free_pvar_null(param, 1);
     }
-    
+
     LM_ERR("invalid parameter number <%d>\n", param_no);
     return -1;
 }
@@ -515,7 +515,7 @@ static int w_curl_connect(struct sip_msg* _m, char* _con, char * _url, char* _re
 	if (result.s != NULL)
 		pkg_free(result.s);
 
-	return ret;
+	return (ret==0)?-1:ret;
 }
 
 /*
@@ -557,7 +557,7 @@ static int w_curl_connect_post(struct sip_msg* _m, char* _con, char * _url, char
 	if (result.s != NULL)
 		pkg_free(result.s);
 
-	return ret;
+	return (ret==0)?-1:ret;
 }
 
 
@@ -599,7 +599,7 @@ static int fixup_free_http_query_post(void** param, int param_no)
     if (param_no == 3) {
 	return fixup_free_pvar_null(param, 1);
     }
-    
+
     LM_ERR("invalid parameter number <%d>\n", param_no);
     return -1;
 }
@@ -628,7 +628,7 @@ static int w_http_query(struct sip_msg* _m, char* _url, char* _result) {
 
 	if (result.s != NULL)
 		pkg_free(result.s);
-	return ret;
+	return (ret==0)?-1:ret;
 }
 
 
@@ -660,7 +660,7 @@ static int w_http_query_post(struct sip_msg* _m, char* _url, char* _post, char*
 
 	if (result.s != NULL)
 		pkg_free(result.s);
-	return ret;
+	return (ret==0)?-1:ret;
 }
 
 /*!
@@ -672,7 +672,7 @@ static int pv_parse_curlerror(pv_spec_p sp, str *in)
 	if(sp==NULL || in==NULL || in->len<=0)
 		return -1;
 
-	
+
 	cerr = atoi(in->s);
 	LM_DBG(" =====> CURL ERROR %d \n", cerr);
 	sp->pvp.pvn.u.isname.name.n = cerr;




More information about the sr-dev mailing list