浏览代码

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
Daniel-Constantin Mierla 9 年之前
父节点
当前提交
be677c2f89
共有 2 个文件被更改,包括 13 次插入9 次删除
  1. 8 3
      modules/http_client/functions.c
  2. 5 6
      modules/http_client/http_client.c

+ 8 - 3
modules/http_client/functions.c

@@ -554,7 +554,8 @@ error:
 }
 
 /* Wrapper */
-int curl_con_query_url(struct sip_msg* _m, const str *connection, const str* url, str* result, const char *contenttype, const str* post)
+int curl_con_query_url(struct sip_msg* _m, const str *connection,
+		const str* url, str* result, const char *contenttype, const str* post)
 {
 	return curl_con_query_url_f(_m, connection, url, result, contenttype, post, 0);
 }
@@ -586,8 +587,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);
 

+ 5 - 6
modules/http_client/http_client.c

@@ -530,7 +530,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;
 }
 
 /*
@@ -573,7 +573,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;
 }
 
 
@@ -615,7 +615,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;
 }
@@ -644,7 +644,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;
 }
 
 
@@ -676,7 +676,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;
 }
 
 /*!
@@ -688,7 +688,6 @@ 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;