Browse code

http_client: clang format the code

Daniel-Constantin Mierla authored on 05/12/2017 14:20:55
Showing 9 changed files
... ...
@@ -25,7 +25,7 @@
25 25
 
26 26
 int bind_httpc_api(httpc_api_t *api)
27 27
 {
28
-	if (!api) {
28
+	if(!api) {
29 29
 		ERR("Invalid parameter value\n");
30 30
 		return -1;
31 31
 	}
... ...
@@ -32,19 +32,21 @@
32 32
 #include "functions.h"
33 33
 #include "curlcon.h"
34 34
 
35
-typedef int (*httpcapi_httpconnect_f)(struct sip_msg *msg, const str *connection,
36
-		const str* _url, str* _result, const char *contenttype, const str* _post);
37
-typedef int (*httpcapi_httpquery_f)(struct sip_msg* _m, char* _url, str* _dst,
38
-		char* _post, char* _hdrs);
39
-typedef int (*httpcapi_curlcon_exists_f)(str* _name);
40
-typedef char * (*httpcapi_res_content_type_f)(const str* _name);
35
+typedef int (*httpcapi_httpconnect_f)(struct sip_msg *msg,
36
+		const str *connection, const str *_url, str *_result,
37
+		const char *contenttype, const str *_post);
38
+typedef int (*httpcapi_httpquery_f)(
39
+		struct sip_msg *_m, char *_url, str *_dst, char *_post, char *_hdrs);
40
+typedef int (*httpcapi_curlcon_exists_f)(str *_name);
41
+typedef char *(*httpcapi_res_content_type_f)(const str *_name);
41 42
 
42 43
 
43
-typedef struct httpc_api {
44
-	httpcapi_httpconnect_f	http_connect;
45
-	httpcapi_httpquery_f	http_client_query;
46
-	httpcapi_curlcon_exists_f	http_connection_exists;
47
-	httpcapi_res_content_type_f	http_get_content_type;
44
+typedef struct httpc_api
45
+{
46
+	httpcapi_httpconnect_f http_connect;
47
+	httpcapi_httpquery_f http_client_query;
48
+	httpcapi_curlcon_exists_f http_connection_exists;
49
+	httpcapi_res_content_type_f http_get_content_type;
48 50
 } httpc_api_t;
49 51
 
50 52
 typedef int (*bind_httpc_api_f)(httpc_api_t *api);
... ...
@@ -62,8 +64,7 @@ static inline int httpc_load_api(httpc_api_t *api)
62 64
 		LM_ERR("cannot find bind_http_client\n");
63 65
 		return -1;
64 66
 	}
65
-	if (bindhttpc(api) < 0)
66
-	{
67
+	if(bindhttpc(api) < 0) {
67 68
 		LM_ERR("cannot bind http_client api\n");
68 69
 		return -1;
69 70
 	}
... ...
@@ -36,12 +36,13 @@
36 36
 #include "http_client.h"
37 37
 #include "curlcon.h"
38 38
 
39
-#define KEYVALUE_TYPE_NONE	0
40
-#define KEYVALUE_TYPE_PARAMS	1
39
+#define KEYVALUE_TYPE_NONE 0
40
+#define KEYVALUE_TYPE_PARAMS 1
41 41
 
42 42
 
43
-curl_con_t *_curl_con_root = NULL;		/*!< Shared memory list of connections */
44
-curl_con_pkg_t *_curl_con_pkg_root = NULL;	/*!< Package memory list of connection states, last result */
43
+curl_con_t *_curl_con_root = NULL; /*!< Shared memory list of connections */
44
+curl_con_pkg_t *_curl_con_pkg_root =
45
+		NULL; /*!< Package memory list of connection states, last result */
45 46
 
46 47
 /* Forward declaration */
47 48
 curl_con_t *curl_init_con(str *name);
... ...
@@ -76,37 +77,40 @@ typedef struct raw_http_client_conn
76 77
 static raw_http_client_conn_t *raw_conn_list = NULL;
77 78
 
78 79
 static cfg_option_t tls_versions[] = {
79
-	{"DEFAULT",  .val = 0}, /* CURL_SSLVERSION_DEFAULT */
80
-	{"TLSv1",    .val = 1}, /* CURL_SSLVERSION_TLSv1 */
81
-	{"SSLv2",    .val = 2}, /* CURL_SSLVERSION_SSLv2 */
82
-	{"SSLv3",    .val = 3}, /* CURL_SSLVERSION_SSLv3 */
83
-	{"TLSv1.0",  .val = 4}, /* CURL_SSLVERSION_TLSv1_0 - support after libcurl 7.34.0 */
84
-	{"TLSv1.1",  .val = 5}, /* CURL_SSLVERSION_TLSv1_1 - support after libcurl 7.34.0 */
85
-	{"TLSv1.2",  .val = 6}, /* CURL_SSLVERSION_TLSv1_2 - support after libcurl 7.34.0 */
86
-	{0}
87
-};
80
+		{"DEFAULT", .val = 0}, /* CURL_SSLVERSION_DEFAULT */
81
+		{"TLSv1", .val = 1},   /* CURL_SSLVERSION_TLSv1 */
82
+		{"SSLv2", .val = 2},   /* CURL_SSLVERSION_SSLv2 */
83
+		{"SSLv3", .val = 3},   /* CURL_SSLVERSION_SSLv3 */
84
+		{"TLSv1.0",
85
+				.val = 4}, /* CURL_SSLVERSION_TLSv1_0 - support after libcurl 7.34.0 */
86
+		{"TLSv1.1",
87
+				.val = 5}, /* CURL_SSLVERSION_TLSv1_1 - support after libcurl 7.34.0 */
88
+		{"TLSv1.2",
89
+				.val = 6}, /* CURL_SSLVERSION_TLSv1_2 - support after libcurl 7.34.0 */
90
+		{0}};
88 91
 
89 92
 static cfg_option_t http_client_options[] = {
90
-	{"url",                  .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 0 */
91
-	{"username",             .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 1 */
92
-	{"password",             .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 2 */
93
-	{"failover",             .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 3 */
94
-	{"useragent",            .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 4 */
95
-	{"verify_peer",          .f = cfg_parse_bool_opt},	/* 5 */
96
-	{"verify_host",          .f = cfg_parse_bool_opt},	/* 6 */
97
-	{"client_cert",          .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 7 */
98
-	{"client_key",           .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 8 */
99
-	{"cipher_suites",        .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 9 */
100
-	{"tlsversion",           .f = cfg_parse_enum_opt, .param = tls_versions},	/* 10 */
101
-	{"timeout",              .f = cfg_parse_int_opt},	/* 11 */
102
-	{"maxdatasize",          .f = cfg_parse_int_opt},	/* 12 */
103
-	{"httpredirect",         .f = cfg_parse_bool_opt},	/* 13 */
104
-	{"httpproxy",            .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},	/* 14 */
105
-	{"httpproxyport",        .f = cfg_parse_int_opt},	/* 15 */
106
-	{"authmethod",           .f = cfg_parse_int_opt},	/* 16 */
107
-	{"keepconnections",      .f = cfg_parse_int_opt},	/* 17 */
108
-	{0}
109
-};
93
+		{"url", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},		/* 0 */
94
+		{"username", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},  /* 1 */
95
+		{"password", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},  /* 2 */
96
+		{"failover", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM},  /* 3 */
97
+		{"useragent", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 4 */
98
+		{"verify_peer", .f = cfg_parse_bool_opt},						/* 5 */
99
+		{"verify_host", .f = cfg_parse_bool_opt},						/* 6 */
100
+		{"client_cert", .f = cfg_parse_str_opt,
101
+				.flags = CFG_STR_PKGMEM},								 /* 7 */
102
+		{"client_key", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 8 */
103
+		{"cipher_suites", .f = cfg_parse_str_opt,
104
+				.flags = CFG_STR_PKGMEM},								/* 9 */
105
+		{"tlsversion", .f = cfg_parse_enum_opt, .param = tls_versions}, /* 10 */
106
+		{"timeout", .f = cfg_parse_int_opt},							/* 11 */
107
+		{"maxdatasize", .f = cfg_parse_int_opt},						/* 12 */
108
+		{"httpredirect", .f = cfg_parse_bool_opt},						/* 13 */
109
+		{"httpproxy", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 14 */
110
+		{"httpproxyport", .f = cfg_parse_int_opt},						/* 15 */
111
+		{"authmethod", .f = cfg_parse_int_opt},							/* 16 */
112
+		{"keepconnections", .f = cfg_parse_int_opt},					/* 17 */
113
+		{0}};
110 114
 
111 115
 /*! Count the number of connections 
112 116
  */
... ...
@@ -115,8 +119,7 @@ unsigned int curl_connection_count()
115 119
 	unsigned int i = 0;
116 120
 	curl_con_t *cc;
117 121
 	cc = _curl_con_root;
118
-	while(cc)
119
-	{
122
+	while(cc) {
120 123
 		i++;
121 124
 		cc = cc->next;
122 125
 	}
... ...
@@ -128,7 +131,7 @@ unsigned int curl_connection_count()
128 131
  */
129 132
 int http_connection_exists(str *name)
130 133
 {
131
-	if (curl_get_connection(name) != NULL) {
134
+	if(curl_get_connection(name) != NULL) {
132 135
 		return 1;
133 136
 	}
134 137
 
... ...
@@ -139,40 +142,43 @@ int http_connection_exists(str *name)
139 142
 
140 143
 /*! Find CURL connection by name
141 144
  */
142
-curl_con_t* curl_get_connection(str *name)
145
+curl_con_t *curl_get_connection(str *name)
143 146
 {
144 147
 	curl_con_t *cc;
145 148
 	unsigned int conid;
146 149
 
147 150
 	conid = core_case_hash(name, 0, 0);
148
-	LM_DBG("curl_get_connection looking for httpcon: [%.*s] ID %u\n", name->len, name->s, conid);
151
+	LM_DBG("curl_get_connection looking for httpcon: [%.*s] ID %u\n", name->len,
152
+			name->s, conid);
149 153
 
150 154
 	cc = _curl_con_root;
151
-	while(cc)
152
-	{
153
-		if(conid==cc->conid && cc->name.len==name->len && strncmp(cc->name.s, name->s, name->len)==0) {
155
+	while(cc) {
156
+		if(conid == cc->conid && cc->name.len == name->len
157
+				&& strncmp(cc->name.s, name->s, name->len) == 0) {
154 158
 			return cc;
155 159
 		}
156 160
 		cc = cc->next;
157 161
 	}
158
-	LM_DBG("curl_get_connection no success in looking for httpcon: [%.*s]\n", name->len, name->s);
162
+	LM_DBG("curl_get_connection no success in looking for httpcon: [%.*s]\n",
163
+			name->len, name->s);
159 164
 	return NULL;
160 165
 }
161 166
 
162 167
 /*! Find package memory structure for a connection */
163
-curl_con_pkg_t* curl_get_pkg_connection(curl_con_t *con)
168
+curl_con_pkg_t *curl_get_pkg_connection(curl_con_t *con)
164 169
 {
165 170
 	curl_con_pkg_t *ccp;
166 171
 
167 172
 	ccp = _curl_con_pkg_root;
168
-	while(ccp)
169
-	{
170
-		if (ccp->conid == con->conid) {
173
+	while(ccp) {
174
+		if(ccp->conid == con->conid) {
171 175
 			return ccp;
172 176
 		}
173 177
 		ccp = ccp->next;
174 178
 	}
175
-	LM_ERR("curl_get_pkg_connection no success in looking for pkg memory for httpcon: [%.*s]\n", con->name.len, con->name.s);
179
+	LM_ERR("curl_get_pkg_connection no success in looking for pkg memory for "
180
+		   "httpcon: [%.*s]\n",
181
+			con->name.len, con->name.s);
176 182
 	return NULL;
177 183
 }
178 184
 
... ...
@@ -198,23 +204,23 @@ curl_con_pkg_t* curl_get_pkg_connection(curl_con_t *con)
198 204
  */
199 205
 int curl_parse_param(char *val)
200 206
 {
201
-	str name	= STR_NULL;
202
-	str schema	= STR_NULL;
203
-	str url		= STR_NULL;
204
-	str username	= STR_NULL;
205
-	str password	= STR_NULL;
206
-	str params	= STR_NULL;
207
-	str failover	= STR_NULL;
208
-
209
-	str client_cert  = default_tls_clientcert;
210
-	str client_key   = default_tls_clientkey;
207
+	str name = STR_NULL;
208
+	str schema = STR_NULL;
209
+	str url = STR_NULL;
210
+	str username = STR_NULL;
211
+	str password = STR_NULL;
212
+	str params = STR_NULL;
213
+	str failover = STR_NULL;
214
+
215
+	str client_cert = default_tls_clientcert;
216
+	str client_key = default_tls_clientkey;
211 217
 	str ciphersuites = default_cipher_suite_list;
212
-	str useragent    = default_useragent;
213
-	str http_proxy   = default_http_proxy;
218
+	str useragent = default_useragent;
219
+	str http_proxy = default_http_proxy;
214 220
 
215 221
 	unsigned int http_proxy_port = default_http_proxy_port;
216 222
 	unsigned int maxdatasize = default_maxdatasize;
217
-	unsigned int timeout	= default_connection_timeout;
223
+	unsigned int timeout = default_connection_timeout;
218 224
 	unsigned int http_follow_redirect = default_http_follow_redirect;
219 225
 	unsigned int verify_peer = default_tls_verify_peer;
220 226
 	unsigned int verify_host = default_tls_verify_host;
... ...
@@ -237,34 +243,34 @@ int curl_parse_param(char *val)
237 243
 	p = in.s;
238 244
 
239 245
 	/* Skip white space */
240
-	while(p < in.s+in.len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r')) {
246
+	while(p < in.s + in.len
247
+			&& (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')) {
241 248
 		p++;
242 249
 	}
243
-	if(p > in.s+in.len || *p=='\0') {
250
+	if(p > in.s + in.len || *p == '\0') {
244 251
 		goto error;
245 252
 	}
246 253
 
247 254
 	/* This is the connection name */
248 255
 	name.s = p;
249 256
 	/* Skip to whitespace */
250
-	while(p < in.s + in.len)
251
-	{
252
-		if(*p=='=' || *p==' ' || *p=='\t' || *p=='\n' || *p=='\r') {
257
+	while(p < in.s + in.len) {
258
+		if(*p == '=' || *p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') {
253 259
 			break;
254 260
 		}
255 261
 		p++;
256 262
 	}
257
-	if(p > in.s+in.len || *p=='\0') {
263
+	if(p > in.s + in.len || *p == '\0') {
258 264
 		goto error;
259 265
 	}
260 266
 	name.len = p - name.s;
261
-	if(*p != '=')
262
-	{
267
+	if(*p != '=') {
263 268
 		/* Skip whitespace */
264
-		while(p<in.s+in.len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r')) {
269
+		while(p < in.s + in.len
270
+				&& (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')) {
265 271
 			p++;
266 272
 		}
267
-		if(p>in.s+in.len || *p=='\0' || *p!='=') {
273
+		if(p > in.s + in.len || *p == '\0' || *p != '=') {
268 274
 			goto error;
269 275
 		}
270 276
 	}
... ...
@@ -274,13 +280,13 @@ int curl_parse_param(char *val)
274 280
 	}
275 281
 	p++;
276 282
 	/* Skip white space again */
277
-	while(p < in.s+in.len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r')) {
283
+	while(p < in.s + in.len
284
+			&& (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')) {
278 285
 		p++;
279 286
 	}
280 287
 	schema.s = p;
281 288
 	/* Skip to colon ':' */
282
-	while(p < in.s + in.len)
283
-	{
289
+	while(p < in.s + in.len) {
284 290
 		if(*p == ':') {
285 291
 			break;
286 292
 		}
... ...
@@ -290,7 +296,7 @@ int curl_parse_param(char *val)
290 296
 		goto error;
291 297
 	}
292 298
 	schema.len = p - schema.s;
293
-	p++;	/* Skip the colon */
299
+	p++; /* Skip the colon */
294 300
 	/* Skip two slashes */
295 301
 	if(*p != '/') {
296 302
 		goto error;
... ...
@@ -308,18 +314,17 @@ int curl_parse_param(char *val)
308 314
 	/* Now check if there is a @ character. If so, we need to parse the username
309 315
 	   and password */
310 316
 	/* Skip to at-sign '@' */
311
-	while(p < in.s + in.len)
312
-	{
317
+	while(p < in.s + in.len) {
313 318
 		if(*p == '@') {
314 319
 			break;
315 320
 		}
316 321
 		p++;
317 322
 	}
318
-	if (*p == '@') {
323
+	if(*p == '@') {
319 324
 		/* We have a username and possibly password - parse them out */
320 325
 		username.s = u;
321
-		while (u < p) {
322
-			if (*u == ':') {
326
+		while(u < p) {
327
+			if(*u == ':') {
323 328
 				break;
324 329
 			}
325 330
 			u++;
... ...
@@ -327,24 +332,23 @@ int curl_parse_param(char *val)
327 332
 		username.len = u - username.s;
328 333
 
329 334
 		/* We either have a : or a @ */
330
-		if (*u == ':') {
335
+		if(*u == ':') {
331 336
 			u++;
332 337
 			/* Go look for password */
333 338
 			password.s = u;
334
-			while (u < p) {
339
+			while(u < p) {
335 340
 				u++;
336 341
 			}
337 342
 			password.len = u - password.s;
338 343
 		}
339
-		p++;	/* Skip the at sign */
344
+		p++; /* Skip the at sign */
340 345
 		url.s = p;
341 346
 		url.len = in.len + (int)(in.s - p);
342 347
 	}
343 348
 	/* Reset P to beginning of URL and look for parameters - starting with ; */
344 349
 	p = url.s;
345 350
 	/* Skip to ';' or end of string */
346
-	while(p < url.s + url.len)
347
-	{
351
+	while(p < url.s + url.len) {
348 352
 		if(*p == ';') {
349 353
 			/* Cut off URL at the ; */
350 354
 			url.len = (int)(p - url.s);
... ...
@@ -352,104 +356,138 @@ int curl_parse_param(char *val)
352 356
 		}
353 357
 		p++;
354 358
 	}
355
-	if (*p == ';') {
359
+	if(*p == ';') {
356 360
 		/* We have parameters */
357 361
 		str tok;
358 362
 		param_t *pit = NULL;
359 363
 
360 364
 		/* Adjust the URL length */
361 365
 
362
-		p++;		/* Skip the ; */
366
+		p++; /* Skip the ; */
363 367
 		params.s = p;
364
-		params.len = in.len + (int) (in.s - p);
368
+		params.len = in.len + (int)(in.s - p);
365 369
 		param_hooks_t phooks;
366 370
 
367
-		if (parse_params(&params, CLASS_ANY, &phooks, &conparams) < 0)
368
-                {
369
-                        LM_ERR("CURL failed parsing httpcon parameters value\n");
370
-                        goto error;
371
-                }
371
+		if(parse_params(&params, CLASS_ANY, &phooks, &conparams) < 0) {
372
+			LM_ERR("CURL failed parsing httpcon parameters value\n");
373
+			goto error;
374
+		}
372 375
 
373 376
 		/* Have parameters */
374
-		for (pit = conparams; pit; pit=pit->next)
375
-		{
377
+		for(pit = conparams; pit; pit = pit->next) {
376 378
 			tok = pit->body;
377
-			if(pit->name.len==12 && strncmp(pit->name.s, "httpredirect", 12)==0) {
379
+			if(pit->name.len == 12
380
+					&& strncmp(pit->name.s, "httpredirect", 12) == 0) {
378 381
 				if(str2int(&tok, &http_follow_redirect) != 0) {
379 382
 					/* Bad value */
380
-					LM_WARN("curl connection [%.*s]: httpredirect bad value. Using default\n", name.len, name.s);
383
+					LM_WARN("curl connection [%.*s]: httpredirect bad value. "
384
+							"Using default\n",
385
+							name.len, name.s);
381 386
 					http_follow_redirect = default_http_follow_redirect;
382 387
 				}
383
-				if (http_follow_redirect != 0 && http_follow_redirect != 1) {
384
-					LM_WARN("curl connection [%.*s]: httpredirect bad value. Using default\n", name.len, name.s);
388
+				if(http_follow_redirect != 0 && http_follow_redirect != 1) {
389
+					LM_WARN("curl connection [%.*s]: httpredirect bad value. "
390
+							"Using default\n",
391
+							name.len, name.s);
385 392
 					http_follow_redirect = default_http_follow_redirect;
386 393
 				}
387
-				LM_DBG("curl [%.*s] - httpredirect [%d]\n", pit->name.len, pit->name.s, http_follow_redirect);
388
-			} else if(pit->name.len==7 && strncmp(pit->name.s, "timeout", 7)==0) {
389
-				if(str2int(&tok, &timeout)!=0) {
394
+				LM_DBG("curl [%.*s] - httpredirect [%d]\n", pit->name.len,
395
+						pit->name.s, http_follow_redirect);
396
+			} else if(pit->name.len == 7
397
+					  && strncmp(pit->name.s, "timeout", 7) == 0) {
398
+				if(str2int(&tok, &timeout) != 0) {
390 399
 					/* Bad timeout */
391
-					LM_WARN("curl connection [%.*s]: timeout bad value. Using default\n", name.len, name.s);
400
+					LM_WARN("curl connection [%.*s]: timeout bad value. Using "
401
+							"default\n",
402
+							name.len, name.s);
392 403
 					timeout = default_connection_timeout;
393 404
 				}
394
-				LM_DBG("curl [%.*s] - timeout [%d]\n", pit->name.len, pit->name.s, timeout);
395
-			} else if(pit->name.len==9 && strncmp(pit->name.s, "useragent", 9)==0) {
405
+				LM_DBG("curl [%.*s] - timeout [%d]\n", pit->name.len,
406
+						pit->name.s, timeout);
407
+			} else if(pit->name.len == 9
408
+					  && strncmp(pit->name.s, "useragent", 9) == 0) {
396 409
 				useragent = tok;
397
-				LM_DBG("curl [%.*s] - useragent [%.*s]\n", pit->name.len, pit->name.s,
398
-						useragent.len, useragent.s);
399
-			} else if(pit->name.len==8 && strncmp(pit->name.s, "failover", 8)==0) {
410
+				LM_DBG("curl [%.*s] - useragent [%.*s]\n", pit->name.len,
411
+						pit->name.s, useragent.len, useragent.s);
412
+			} else if(pit->name.len == 8
413
+					  && strncmp(pit->name.s, "failover", 8) == 0) {
400 414
 				failover = tok;
401
-				LM_DBG("curl [%.*s] - failover [%.*s]\n", pit->name.len, pit->name.s,
402
-						failover.len, failover.s);
403
-			} else if(pit->name.len==11 && strncmp(pit->name.s, "maxdatasize", 11)==0) {
404
-				if(str2int(&tok, &maxdatasize)!=0) {
415
+				LM_DBG("curl [%.*s] - failover [%.*s]\n", pit->name.len,
416
+						pit->name.s, failover.len, failover.s);
417
+			} else if(pit->name.len == 11
418
+					  && strncmp(pit->name.s, "maxdatasize", 11) == 0) {
419
+				if(str2int(&tok, &maxdatasize) != 0) {
405 420
 					/* Bad timeout */
406
-					LM_WARN("curl connection [%.*s]: maxdatasize bad value. Using default\n", name.len, name.s);
421
+					LM_WARN("curl connection [%.*s]: maxdatasize bad value. "
422
+							"Using default\n",
423
+							name.len, name.s);
407 424
 					maxdatasize = default_maxdatasize;
408 425
 				}
409
-				LM_DBG("curl [%.*s] - maxdatasize [%d]\n", pit->name.len, pit->name.s, maxdatasize);
410
-			} else if(pit->name.len==11 && strncmp(pit->name.s, "verify_peer", 11)==0) {
411
-				if(str2int(&tok, &verify_peer)!=0) {
426
+				LM_DBG("curl [%.*s] - maxdatasize [%d]\n", pit->name.len,
427
+						pit->name.s, maxdatasize);
428
+			} else if(pit->name.len == 11
429
+					  && strncmp(pit->name.s, "verify_peer", 11) == 0) {
430
+				if(str2int(&tok, &verify_peer) != 0) {
412 431
 					/* Bad integer */
413
-					LM_WARN("curl connection [%.*s]: verify_peer bad value. Using default\n", name.len, name.s);
432
+					LM_WARN("curl connection [%.*s]: verify_peer bad value. "
433
+							"Using default\n",
434
+							name.len, name.s);
414 435
 					verify_peer = default_tls_verify_peer;
415 436
 				}
416
-				if (verify_peer != 0 && verify_peer != 1) {
417
-					LM_WARN("curl connection [%.*s]: verify_peer bad value. Using default\n", name.len, name.s);
437
+				if(verify_peer != 0 && verify_peer != 1) {
438
+					LM_WARN("curl connection [%.*s]: verify_peer bad value. "
439
+							"Using default\n",
440
+							name.len, name.s);
418 441
 					verify_peer = default_tls_verify_peer;
419 442
 				}
420
-				LM_DBG("curl [%.*s] - verify_peer [%d]\n", pit->name.len, pit->name.s, verify_peer);
421
-			} else if(pit->name.len==11 && strncmp(pit->name.s, "verify_host", 11)==0) {
422
-				if(str2int(&tok, &verify_host)!=0) {
443
+				LM_DBG("curl [%.*s] - verify_peer [%d]\n", pit->name.len,
444
+						pit->name.s, verify_peer);
445
+			} else if(pit->name.len == 11
446
+					  && strncmp(pit->name.s, "verify_host", 11) == 0) {
447
+				if(str2int(&tok, &verify_host) != 0) {
423 448
 					/* Bad integer */
424
-					LM_WARN("curl connection [%.*s]: verify_host bad value. Using default\n", name.len, name.s);
449
+					LM_WARN("curl connection [%.*s]: verify_host bad value. "
450
+							"Using default\n",
451
+							name.len, name.s);
425 452
 					verify_host = default_tls_verify_host;
426 453
 				}
427
-				LM_DBG("curl [%.*s] - verify_host [%d]\n", pit->name.len, pit->name.s, verify_host);
428
-			} else if(pit->name.len==10 && strncmp(pit->name.s, "tlsversion", 10)==0) {
429
-				if(str2int(&tok, &tlsversion)!=0) {
454
+				LM_DBG("curl [%.*s] - verify_host [%d]\n", pit->name.len,
455
+						pit->name.s, verify_host);
456
+			} else if(pit->name.len == 10
457
+					  && strncmp(pit->name.s, "tlsversion", 10) == 0) {
458
+				if(str2int(&tok, &tlsversion) != 0) {
430 459
 					/* Bad integer */
431
-					LM_WARN("curl connection [%.*s]: tlsversion bad value. Using default\n", name.len, name.s);
460
+					LM_WARN("curl connection [%.*s]: tlsversion bad value. "
461
+							"Using default\n",
462
+							name.len, name.s);
432 463
 					tlsversion = default_tls_version;
433 464
 				}
434
-				if (tlsversion >= CURL_SSLVERSION_LAST) {
435
-					LM_WARN("curl connection [%.*s]: tlsversion unsupported value. Using default\n", name.len, name.s);
465
+				if(tlsversion >= CURL_SSLVERSION_LAST) {
466
+					LM_WARN("curl connection [%.*s]: tlsversion unsupported "
467
+							"value. Using default\n",
468
+							name.len, name.s);
436 469
 					tlsversion = default_tls_version;
437 470
 				}
438
-				LM_DBG("curl [%.*s] - tlsversion [%d]\n", pit->name.len, pit->name.s, tlsversion);
439
-			} else if(pit->name.len==11 && strncmp(pit->name.s, "client_cert", 11)==0) {
471
+				LM_DBG("curl [%.*s] - tlsversion [%d]\n", pit->name.len,
472
+						pit->name.s, tlsversion);
473
+			} else if(pit->name.len == 11
474
+					  && strncmp(pit->name.s, "client_cert", 11) == 0) {
440 475
 				client_cert = tok;
441
-				LM_DBG("curl [%.*s] - client_cert [%.*s]\n", pit->name.len, pit->name.s,
442
-						client_cert.len, client_cert.s);
443
-			} else if(pit->name.len==10 && strncmp(pit->name.s, "client_key", 10)==0) {
476
+				LM_DBG("curl [%.*s] - client_cert [%.*s]\n", pit->name.len,
477
+						pit->name.s, client_cert.len, client_cert.s);
478
+			} else if(pit->name.len == 10
479
+					  && strncmp(pit->name.s, "client_key", 10) == 0) {
444 480
 				client_key = tok;
445
-				LM_DBG("curl [%.*s] - client_key [%.*s]\n", pit->name.len, pit->name.s,
446
-						client_key.len, client_key.s);
447
-			} else if(pit->name.len==13 && strncmp(pit->name.s, "cipher_suites", 13)==0) {
481
+				LM_DBG("curl [%.*s] - client_key [%.*s]\n", pit->name.len,
482
+						pit->name.s, client_key.len, client_key.s);
483
+			} else if(pit->name.len == 13
484
+					  && strncmp(pit->name.s, "cipher_suites", 13) == 0) {
448 485
 				ciphersuites = tok;
449
-				LM_DBG("curl [%.*s] - cipher_suites [%.*s]\n", pit->name.len, pit->name.s,
450
-						ciphersuites.len, ciphersuites.s);
486
+				LM_DBG("curl [%.*s] - cipher_suites [%.*s]\n", pit->name.len,
487
+						pit->name.s, ciphersuites.len, ciphersuites.s);
451 488
 			} else {
452
-				LM_ERR("curl Unknown parameter [%.*s] \n", pit->name.len, pit->name.s);
489
+				LM_ERR("curl Unknown parameter [%.*s] \n", pit->name.len,
490
+						pit->name.s);
453 491
 			}
454 492
 		}
455 493
 	}
... ...
@@ -460,8 +498,8 @@ int curl_parse_param(char *val)
460 498
 		free_params(conparams);
461 499
 	}
462 500
 
463
-	cc =  curl_init_con(&name);
464
-	if (cc == NULL) {
501
+	cc = curl_init_con(&name);
502
+	if(cc == NULL) {
465 503
 		return -1;
466 504
 	}
467 505
 
... ...
@@ -481,27 +519,37 @@ int curl_parse_param(char *val)
481 519
 	cc->verify_host = verify_host;
482 520
 	cc->timeout = timeout;
483 521
 	cc->maxdatasize = maxdatasize;
484
-	if (http_proxy_port > 0) {
522
+	if(http_proxy_port > 0) {
485 523
 		cc->http_proxy_port = http_proxy_port;
486 524
 		cc->http_proxy = http_proxy.s ? as_asciiz(&http_proxy) : NULL;
487
-		LM_DBG("*** Setting HTTP proxy for connection to %s \n", cc->http_proxy);
525
+		LM_DBG("*** Setting HTTP proxy for connection to %s \n",
526
+				cc->http_proxy);
488 527
 	}
489 528
 	cc->http_follow_redirect = http_follow_redirect;
490 529
 
491
-	LM_DBG("cname: [%.*s] url: [%.*s] username [%s] password [%s] failover [%.*s] timeout [%d] useragent [%s] maxdatasize [%d] keep_connections [%d]\n", 
492
-			cc->name.len, cc->name.s, cc->url.len, cc->url.s, cc->username ? cc->username : "", cc->password ? cc->password : "",
493
-			cc->failover.len, cc->failover.s, cc->timeout, cc->useragent, cc->maxdatasize, cc->keep_connections);
494
-	LM_DBG("cname: [%.*s] client_cert [%s] client_key [%s] ciphersuites [%s] tlsversion [%d] verify_peer [%d] verify_host [%d] authmethod [%d]\n",
495
-			cc->name.len, cc->name.s, cc->clientcert, cc->clientkey, cc->ciphersuites, cc->tlsversion, cc->verify_peer, cc->verify_host, cc->authmethod);
496
-	if (cc->http_proxy_port > 0) {
530
+	LM_DBG("cname: [%.*s] url: [%.*s] username [%s] password [%s] failover "
531
+		   "[%.*s] timeout [%d] useragent [%s] maxdatasize [%d] "
532
+		   "keep_connections [%d]\n",
533
+			cc->name.len, cc->name.s, cc->url.len, cc->url.s,
534
+			cc->username ? cc->username : "", cc->password ? cc->password : "",
535
+			cc->failover.len, cc->failover.s, cc->timeout, cc->useragent,
536
+			cc->maxdatasize, cc->keep_connections);
537
+	LM_DBG("cname: [%.*s] client_cert [%s] client_key [%s] ciphersuites [%s] "
538
+		   "tlsversion [%d] verify_peer [%d] verify_host [%d] authmethod "
539
+		   "[%d]\n",
540
+			cc->name.len, cc->name.s, cc->clientcert, cc->clientkey,
541
+			cc->ciphersuites, cc->tlsversion, cc->verify_peer, cc->verify_host,
542
+			cc->authmethod);
543
+	if(cc->http_proxy_port > 0) {
497 544
 		LM_DBG("cname: [%.*s] http_proxy [%s] http_proxy_port [%d]\n",
498
-		cc->name.len, cc->name.s, cc->http_proxy, cc->http_proxy_port);
545
+				cc->name.len, cc->name.s, cc->http_proxy, cc->http_proxy_port);
499 546
 	}
500 547
 
501 548
 	return 0;
502 549
 
503 550
 error:
504
-	LM_ERR("invalid curl parameter [%.*s] at [%d]\n", in.len, in.s, (int)(p-in.s));
551
+	LM_ERR("invalid curl parameter [%.*s] at [%d]\n", in.len, in.s,
552
+			(int)(p - in.s));
505 553
 
506 554
 	if(conparams != NULL) {
507 555
 		free_params(conparams);
... ...
@@ -511,7 +559,7 @@ error:
511 559
 
512 560
 int curl_parse_conn(void *param, cfg_parser_t *parser, unsigned int flags)
513 561
 {
514
-	str name	= STR_NULL;
562
+	str name = STR_NULL;
515 563
 
516 564
 	raw_http_client_conn_t *raw_cc = NULL;
517 565
 	int i, ret;
... ...
@@ -520,27 +568,28 @@ int curl_parse_conn(void *param, cfg_parser_t *parser, unsigned int flags)
520 568
 	/* Get the name from the section header */
521 569
 
522 570
 	ret = cfg_get_token(&t, parser, 0);
523
-	if (ret < 0) return -1;
524
-	if ((ret > 0) || (t.type != CFG_TOKEN_ALPHA))
525
-	{
526
-		LM_ERR("%s:%d:%d: Invalid or missing connection name\n",
527
-				parser->file, t.start.line, t.start.col);
571
+	if(ret < 0)
572
+		return -1;
573
+	if((ret > 0) || (t.type != CFG_TOKEN_ALPHA)) {
574
+		LM_ERR("%s:%d:%d: Invalid or missing connection name\n", parser->file,
575
+				t.start.line, t.start.col);
528 576
 		return -1;
529 577
 	}
530 578
 	pkg_str_dup(&name, &t.val);
531 579
 	ret = cfg_get_token(&t, parser, 0);
532
-	if (ret < 0) return -1;
533
-	if ((ret > 0) || (t.type != ']'))
534
-	{
535
-		LM_ERR("%s:%d:%d: Syntax error, ']' expected\n",
536
-				parser->file, t.start.line, t.start.col);
580
+	if(ret < 0)
581
+		return -1;
582
+	if((ret > 0) || (t.type != ']')) {
583
+		LM_ERR("%s:%d:%d: Syntax error, ']' expected\n", parser->file,
584
+				t.start.line, t.start.col);
537 585
 		return -1;
538 586
 	}
539 587
 
540
-	if (cfg_eat_eol(parser, flags)) return -1;
588
+	if(cfg_eat_eol(parser, flags))
589
+		return -1;
541 590
 
542 591
 	raw_cc = pkg_malloc(sizeof(raw_http_client_conn_t));
543
-	if (raw_cc == NULL) {
592
+	if(raw_cc == NULL) {
544 593
 		return -1;
545 594
 	}
546 595
 	memset(raw_cc, 0, sizeof(raw_http_client_conn_t));
... ...
@@ -549,23 +598,23 @@ int curl_parse_conn(void *param, cfg_parser_t *parser, unsigned int flags)
549 598
 	raw_cc->name = name;
550 599
 
551 600
 	/* Set default values - memory freed if overridden */
552
-	if (default_tls_clientcert.s != NULL)
553
-		pkg_str_dup(&raw_cc->clientcert,   &default_tls_clientcert);
554
-	if (default_tls_clientkey.s != NULL)
555
-		pkg_str_dup(&raw_cc->clientkey,    &default_tls_clientkey);
556
-	if (default_cipher_suite_list.s != NULL)
601
+	if(default_tls_clientcert.s != NULL)
602
+		pkg_str_dup(&raw_cc->clientcert, &default_tls_clientcert);
603
+	if(default_tls_clientkey.s != NULL)
604
+		pkg_str_dup(&raw_cc->clientkey, &default_tls_clientkey);
605
+	if(default_cipher_suite_list.s != NULL)
557 606
 		pkg_str_dup(&raw_cc->ciphersuites, &default_cipher_suite_list);
558
-	pkg_str_dup(&raw_cc->useragent,    &default_useragent);
559
-	if (default_http_proxy_port > 0) {
607
+	pkg_str_dup(&raw_cc->useragent, &default_useragent);
608
+	if(default_http_proxy_port > 0) {
560 609
 		raw_cc->http_proxy_port = default_http_proxy_port;
561
-		if (default_http_proxy.s != NULL) {
562
-			pkg_str_dup(&raw_cc->http_proxy,   &default_http_proxy);
610
+		if(default_http_proxy.s != NULL) {
611
+			pkg_str_dup(&raw_cc->http_proxy, &default_http_proxy);
563 612
 		}
564 613
 	}
565 614
 	raw_cc->verify_peer = default_tls_verify_peer;
566 615
 	raw_cc->verify_host = default_tls_verify_host;
567 616
 	raw_cc->maxdatasize = default_maxdatasize;
568
-	raw_cc->timeout	= default_connection_timeout;
617
+	raw_cc->timeout = default_connection_timeout;
569 618
 	raw_cc->http_follow_redirect = default_http_follow_redirect;
570 619
 	raw_cc->tlsversion = default_tls_version;
571 620
 	raw_cc->authmethod = default_authmethod;
... ...
@@ -607,10 +656,9 @@ int fixup_raw_http_client_conn_list(void)
607 656
 	char *pos, *end;
608 657
 	int ret = 1;
609 658
 
610
-	for (raw_cc = raw_conn_list; raw_cc != NULL; raw_cc = raw_cc->next)
611
-	{
659
+	for(raw_cc = raw_conn_list; raw_cc != NULL; raw_cc = raw_cc->next) {
612 660
 		cc = curl_init_con(&raw_cc->name);
613
-		if (cc == NULL) {
661
+		if(cc == NULL) {
614 662
 			ret = -1;
615 663
 			goto done;
616 664
 		}
... ...
@@ -618,20 +666,20 @@ int fixup_raw_http_client_conn_list(void)
618 666
 		schema.s = raw_cc->url.s;
619 667
 		pos = schema.s;
620 668
 		end = raw_cc->url.s + raw_cc->url.len;
621
-		while ((pos < end) && (*pos != '\0'))
622
-		{
623
-			if (*pos == ':') break;
669
+		while((pos < end) && (*pos != '\0')) {
670
+			if(*pos == ':')
671
+				break;
624 672
 			pos++;
625 673
 		}
626
-		if (pos[0] != ':' || pos[1] != '/' || pos[2] != '/' || (end-pos < 4))
627
-		{
628
-			LM_ERR("Invalid schema://url definition [%.*s]\n", raw_cc->url.len, raw_cc->url.s);
674
+		if(pos[0] != ':' || pos[1] != '/' || pos[2] != '/' || (end - pos < 4)) {
675
+			LM_ERR("Invalid schema://url definition [%.*s]\n", raw_cc->url.len,
676
+					raw_cc->url.s);
629 677
 			ret = -1;
630 678
 			goto done;
631 679
 		}
632 680
 		schema.len = (int)(pos - schema.s);
633 681
 
634
-		url.s = pos+3;
682
+		url.s = pos + 3;
635 683
 		url.len = end - url.s;
636 684
 
637 685
 		pkg_str_dup(&cc->schema, &schema);
... ...
@@ -640,20 +688,28 @@ int fixup_raw_http_client_conn_list(void)
640 688
 		cc->username = raw_cc->username.s ? as_asciiz(&raw_cc->username) : NULL;
641 689
 		cc->password = raw_cc->password.s ? as_asciiz(&raw_cc->password) : NULL;
642 690
 		cc->authmethod = raw_cc->authmethod;
643
-		if (raw_cc->failover.s != NULL)
691
+		if(raw_cc->failover.s != NULL)
644 692
 			pkg_str_dup(&cc->failover, &raw_cc->failover);
645 693
 		cc->useragent = as_asciiz(&raw_cc->useragent);
646
-		cc->clientcert = raw_cc->clientcert.s ? as_asciiz(&raw_cc->clientcert) : NULL;
647
-		cc->clientkey = raw_cc->clientkey.s ? as_asciiz(&raw_cc->clientkey) : NULL;
648
-		cc->ciphersuites = raw_cc->ciphersuites.s ? as_asciiz(&raw_cc->ciphersuites) : NULL;
694
+		cc->clientcert =
695
+				raw_cc->clientcert.s ? as_asciiz(&raw_cc->clientcert) : NULL;
696
+		cc->clientkey =
697
+				raw_cc->clientkey.s ? as_asciiz(&raw_cc->clientkey) : NULL;
698
+		cc->ciphersuites = raw_cc->ciphersuites.s
699
+								   ? as_asciiz(&raw_cc->ciphersuites)
700
+								   : NULL;
649 701
 		cc->tlsversion = raw_cc->tlsversion;
650
-		if (cc->tlsversion >= CURL_SSLVERSION_LAST) {
651
-			LM_WARN("curl connection [%.*s]: tlsversion %d unsupported value. Using default\n", cc->name.len, cc->name.s, cc->tlsversion);
702
+		if(cc->tlsversion >= CURL_SSLVERSION_LAST) {
703
+			LM_WARN("curl connection [%.*s]: tlsversion %d unsupported value. "
704
+					"Using default\n",
705
+					cc->name.len, cc->name.s, cc->tlsversion);
652 706
 			cc->tlsversion = default_tls_version;
653 707
 		}
654 708
 		cc->http_proxy_port = raw_cc->http_proxy_port;
655
-		if (cc->http_proxy_port > 0 && raw_cc->http_proxy.s != NULL) {
656
-			cc->http_proxy = raw_cc->http_proxy.s ? as_asciiz(&raw_cc->http_proxy) : NULL;
709
+		if(cc->http_proxy_port > 0 && raw_cc->http_proxy.s != NULL) {
710
+			cc->http_proxy = raw_cc->http_proxy.s
711
+									 ? as_asciiz(&raw_cc->http_proxy)
712
+									 : NULL;
657 713
 		}
658 714
 
659 715
 		cc->verify_peer = raw_cc->verify_peer;
... ...
@@ -663,32 +719,48 @@ int fixup_raw_http_client_conn_list(void)
663 719
 		cc->http_follow_redirect = raw_cc->http_follow_redirect;
664 720
 		cc->keep_connections = raw_cc->keep_connections;
665 721
 
666
-		LM_DBG("cname: [%.*s] url: [%.*s] username [%s] password [%s] failover [%.*s] timeout [%d] useragent [%s] maxdatasize [%d]\n", 
667
-			cc->name.len, cc->name.s, cc->url.len, cc->url.s, cc->username ? cc->username : "", cc->password ? cc->password : "",
668
-			cc->failover.len, cc->failover.s, cc->timeout, cc->useragent, cc->maxdatasize);
669
-		LM_DBG("cname: [%.*s] client_cert [%s] client_key [%s] ciphersuites [%s] tlsversion [%d] verify_peer [%d] verify_host [%d] keep_connections [%d]\n",
670
-			cc->name.len, cc->name.s, cc->clientcert, cc->clientkey, cc->ciphersuites, cc->tlsversion, cc->verify_peer, cc->verify_host, cc->keep_connections);
671
-		if (cc->http_proxy_port > 0) {
722
+		LM_DBG("cname: [%.*s] url: [%.*s] username [%s] password [%s] failover "
723
+			   "[%.*s] timeout [%d] useragent [%s] maxdatasize [%d]\n",
724
+				cc->name.len, cc->name.s, cc->url.len, cc->url.s,
725
+				cc->username ? cc->username : "",
726
+				cc->password ? cc->password : "", cc->failover.len,
727
+				cc->failover.s, cc->timeout, cc->useragent, cc->maxdatasize);
728
+		LM_DBG("cname: [%.*s] client_cert [%s] client_key [%s] ciphersuites "
729
+			   "[%s] tlsversion [%d] verify_peer [%d] verify_host [%d] "
730
+			   "keep_connections [%d]\n",
731
+				cc->name.len, cc->name.s, cc->clientcert, cc->clientkey,
732
+				cc->ciphersuites, cc->tlsversion, cc->verify_peer,
733
+				cc->verify_host, cc->keep_connections);
734
+		if(cc->http_proxy_port > 0) {
672 735
 			LM_DBG("cname: [%.*s] http_proxy [%s] http_proxy_port [%d]\n",
673
-			cc->name.len, cc->name.s, cc->http_proxy, cc->http_proxy_port);
736
+					cc->name.len, cc->name.s, cc->http_proxy,
737
+					cc->http_proxy_port);
674 738
 		}
675
-
676 739
 	}
677 740
 done:
678
-	while (raw_conn_list != NULL)
679
-	{
741
+	while(raw_conn_list != NULL) {
680 742
 		raw_cc = raw_conn_list;
681 743
 		raw_conn_list = raw_conn_list->next;
682
-		if (raw_cc->name.s) pkg_free(raw_cc->name.s);
683
-		if (raw_cc->url.s) pkg_free(raw_cc->url.s);
684
-		if (raw_cc->username.s) pkg_free(raw_cc->username.s);
685
-		if (raw_cc->password.s) pkg_free(raw_cc->password.s);
686
-		if (raw_cc->failover.s) pkg_free(raw_cc->failover.s);
687
-		if (raw_cc->useragent.s) pkg_free(raw_cc->useragent.s);
688
-		if (raw_cc->clientcert.s) pkg_free(raw_cc->clientcert.s);
689
-		if (raw_cc->clientkey.s) pkg_free(raw_cc->clientkey.s);
690
-		if (raw_cc->ciphersuites.s) pkg_free(raw_cc->ciphersuites.s);
691
-		if (raw_cc->http_proxy.s) pkg_free(raw_cc->http_proxy.s);
744
+		if(raw_cc->name.s)
745
+			pkg_free(raw_cc->name.s);
746
+		if(raw_cc->url.s)
747
+			pkg_free(raw_cc->url.s);
748
+		if(raw_cc->username.s)
749
+			pkg_free(raw_cc->username.s);
750
+		if(raw_cc->password.s)
751
+			pkg_free(raw_cc->password.s);
752
+		if(raw_cc->failover.s)
753
+			pkg_free(raw_cc->failover.s);
754
+		if(raw_cc->useragent.s)
755
+			pkg_free(raw_cc->useragent.s);
756
+		if(raw_cc->clientcert.s)
757
+			pkg_free(raw_cc->clientcert.s);
758
+		if(raw_cc->clientkey.s)
759
+			pkg_free(raw_cc->clientkey.s);
760
+		if(raw_cc->ciphersuites.s)
761
+			pkg_free(raw_cc->ciphersuites.s);
762
+		if(raw_cc->http_proxy.s)
763
+			pkg_free(raw_cc->http_proxy.s);
692 764
 		pkg_free(raw_cc);
693 765
 	}
694 766
 	return ret;
... ...
@@ -699,14 +771,13 @@ int http_client_load_config(str *config_file)
699 771
 	cfg_parser_t *parser;
700 772
 	str empty = STR_NULL;
701 773
 
702
-	if ((parser = cfg_parser_init(&empty, config_file)) == NULL)
703
-	{
774
+	if((parser = cfg_parser_init(&empty, config_file)) == NULL) {
704 775
 		LM_ERR("Failed to init http_client config file parser\n");
705 776
 		goto error;
706 777
 	}
707 778
 
708 779
 	cfg_section_parser(parser, curl_parse_conn, NULL);
709
-	if (sr_cfg_parse(parser))
780
+	if(sr_cfg_parse(parser))
710 781
 		goto error;
711 782
 	cfg_parser_close(parser);
712 783
 
... ...
@@ -728,29 +799,26 @@ curl_con_t *curl_init_con(str *name)
728 799
 	LM_DBG("curl_init_con httpcon: [%.*s] ID %u\n", name->len, name->s, conid);
729 800
 
730 801
 	cc = _curl_con_root;
731
-	while(cc)
732
-	{
733
-		if(conid==cc->conid && cc->name.len == name->len
734
-				&& strncmp(cc->name.s, name->s, name->len)==0)
735
-		{
802
+	while(cc) {
803
+		if(conid == cc->conid && cc->name.len == name->len
804
+				&& strncmp(cc->name.s, name->s, name->len) == 0) {
736 805
 			LM_ERR("duplicate Curl connection name\n");
737 806
 			return NULL;
738 807
 		}
739 808
 		cc = cc->next;
740 809
 	}
741 810
 
742
-	cc = (curl_con_t*) shm_malloc(sizeof(curl_con_t));	/* Connection structures are shared by all children processes */
743
-	if(cc == NULL)
744
-	{
811
+	cc = (curl_con_t *)shm_malloc(sizeof(
812
+			curl_con_t)); /* Connection structures are shared by all children processes */
813
+	if(cc == NULL) {
745 814
 		LM_ERR("no shm memory\n");
746 815
 		return NULL;
747 816
 	}
748 817
 
749 818
 	/* Each structure is allocated in package memory so each process can write into it without
750 819
 	   any locks or such stuff */
751
-	ccp = (curl_con_pkg_t*) pkg_malloc(sizeof(curl_con_pkg_t));
752
-	if(ccp == NULL)
753
-	{
820
+	ccp = (curl_con_pkg_t *)pkg_malloc(sizeof(curl_con_pkg_t));
821
+	if(ccp == NULL) {
754 822
 		/* We failed to allocate ccp, so let's free cc and quit */
755 823
 		shm_free(cc);
756 824
 		LM_ERR("no pkg memory available\n");
... ...
@@ -47,7 +47,7 @@ int http_client_load_config(str *config_file);
47 47
 
48 48
 int curl_parse_param(char *val);
49 49
 
50
-curl_con_t* curl_get_connection(str *name);
51
-curl_con_pkg_t* curl_get_pkg_connection(curl_con_t *con);
50
+curl_con_t *curl_get_connection(str *name);
51
+curl_con_pkg_t *curl_get_pkg_connection(curl_con_t *con);
52 52
 
53 53
 #endif
... ...
@@ -32,75 +32,62 @@
32 32
 #include "curlcon.h"
33 33
 
34 34
 
35
-static const char* curl_rpc_listcon_doc[2] = {
36
-	"List all CURL connection definitions",
37
-	0
38
-};
35
+static const char *curl_rpc_listcon_doc[2] = {
36
+		"List all CURL connection definitions", 0};
39 37
 
40 38
 
41 39
 /*
42 40
  * RPC command to print curl destination sets
43 41
  */
44
-static void curl_rpc_listcon(rpc_t* rpc, void* ctx)
42
+static void curl_rpc_listcon(rpc_t *rpc, void *ctx)
45 43
 {
46
-	void* th;
47
-	void* rh;
44
+	void *th;
45
+	void *rh;
48 46
 	curl_con_t *cc;
49 47
 
50 48
 	cc = _curl_con_root;
51
-	if(cc==NULL)
52
-	{
49
+	if(cc == NULL) {
53 50
 		LM_ERR("no connection definitions\n");
54 51
 		rpc->fault(ctx, 500, "No Connection Definitions");
55 52
 		return;
56 53
 	}
57 54
 
58 55
 	/* add entry node */
59
-	if (rpc->add(ctx, "{", &th) < 0)
60
-	{
56
+	if(rpc->add(ctx, "{", &th) < 0) {
61 57
 		rpc->fault(ctx, 500, "Internal error root reply");
62 58
 		return;
63 59
 	}
64 60
 
65
-        while(cc)
66
-        {
67
-		int timeout = (int) cc->timeout;
68
-		if (rpc->struct_add(th, "{", "CONNECTION", &rh) < 0)
69
-		{
61
+	while(cc) {
62
+		int timeout = (int)cc->timeout;
63
+		if(rpc->struct_add(th, "{", "CONNECTION", &rh) < 0) {
70 64
 			rpc->fault(ctx, 500, "Internal error set structure");
71 65
 			return;
72 66
 		}
73 67
 
74
-		if(rpc->struct_add(rh, "SSSSSSd", 
75
-				"NAME", &cc->name,
76
-				"SCHEMA", &cc->schema,
77
-				"URI", &cc->url,
78
-				"USERNAME", &cc->username,
79
-				"PASSWORD", &cc->password,
80
-				"FAILOVER", &cc->failover,
81
-				"TIMEOUT", timeout
82
-				) < 0) {
68
+		if(rpc->struct_add(rh, "SSSSSSd", "NAME", &cc->name, "SCHEMA",
69
+				   &cc->schema, "URI", &cc->url, "USERNAME", &cc->username,
70
+				   "PASSWORD", &cc->password, "FAILOVER", &cc->failover,
71
+				   "TIMEOUT", timeout)
72
+				< 0) {
83 73
 			rpc->fault(ctx, 500, "Internal error set structure");
84 74
 			return;
85 75
 		}
86
-                cc = cc->next;
87
-        }
76
+		cc = cc->next;
77
+	}
88 78
 	return;
89 79
 }
90 80
 
91 81
 rpc_export_t curl_rpc_cmds[] = {
92
-	{"httpclient.listcon",   curl_rpc_listcon,
93
-		curl_rpc_listcon_doc,   0},
94
-	{0, 0, 0, 0}
95
-};
82
+		{"httpclient.listcon", curl_rpc_listcon, curl_rpc_listcon_doc, 0},
83
+		{0, 0, 0, 0}};
96 84
 
97 85
 /**
98 86
  * register RPC commands
99 87
  */
100 88
 int curl_init_rpc(void)
101 89
 {
102
-	if (rpc_register_array(curl_rpc_cmds)!=0)
103
-	{
90
+	if(rpc_register_array(curl_rpc_cmds) != 0) {
104 91
 		LM_ERR("failed to register RPC commands\n");
105 92
 		return -1;
106 93
 	}
... ...
@@ -43,7 +43,8 @@
43 43
 #include "http_client.h"
44 44
 #include "curlcon.h"
45 45
 
46
-typedef struct {
46
+typedef struct
47
+{
47 48
 	char *username;
48 49
 	char *secret;
49 50
 	char *contenttype;
... ...
@@ -77,40 +78,43 @@ typedef struct {
77 78
  * This function may be called multiple times for larger responses,
78 79
  * so it reallocs + concatenates the buffer as needed.
79 80
  */
80
-size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
81
+size_t write_function(void *ptr, size_t size, size_t nmemb, void *stream_ptr)
81 82
 {
82
-	curl_res_stream_t *stream = (curl_res_stream_t *) stream_ptr;
83
+	curl_res_stream_t *stream = (curl_res_stream_t *)stream_ptr;
83 84
 
84 85
 
85
-	if (stream->max_size == 0 || stream->curr_size < stream->max_size) {
86
-		char *tmp = (char *) pkg_realloc(stream->buf, stream->curr_size + (size * nmemb));
86
+	if(stream->max_size == 0 || stream->curr_size < stream->max_size) {
87
+		char *tmp = (char *)pkg_realloc(
88
+				stream->buf, stream->curr_size + (size * nmemb));
87 89
 
88
-	    	if (tmp == NULL) {
89
-	        	LM_ERR("cannot allocate memory for stream\n");
90
-	        	return CURLE_WRITE_ERROR;
90
+		if(tmp == NULL) {
91
+			LM_ERR("cannot allocate memory for stream\n");
92
+			return CURLE_WRITE_ERROR;
91 93
 		}
92
-	    	stream->buf = tmp;
94
+		stream->buf = tmp;
93 95
 
94
-		memcpy(&stream->buf[stream->pos], (char *) ptr, (size * nmemb));
96
+		memcpy(&stream->buf[stream->pos], (char *)ptr, (size * nmemb));
95 97
 
96
-	    	stream->curr_size += ((size * nmemb));
98
+		stream->curr_size += ((size * nmemb));
97 99
 		stream->pos += (size * nmemb);
98 100
 
99
-	}  else {
100
-		LM_DBG("****** ##### CURL Max datasize exceeded: max  %u current %u\n", (unsigned int) stream->max_size, (unsigned int)stream->curr_size);
101
+	} else {
102
+		LM_DBG("****** ##### CURL Max datasize exceeded: max  %u current %u\n",
103
+				(unsigned int)stream->max_size,
104
+				(unsigned int)stream->curr_size);
101 105
 	}
102 106
 
103 107
 	return size * nmemb;
104
- }
105
-
108
+}
106 109
 
107 110
 
108 111
 /*! Send query to server, optionally post data.
109 112
  */
110
-static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
111
-		const curl_query_t * const params)
113
+static int curL_query_url(struct sip_msg *_m, const char *_url, str *_dst,
114
+		const curl_query_t *const params)
112 115
 {
113
-	CURL *curl = NULL;;
116
+	CURL *curl = NULL;
117
+	;
114 118
 	CURLcode res;
115 119
 	char *at = NULL;
116 120
 	curl_res_stream_t stream;
... ...
@@ -120,25 +124,26 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
120 124
 	struct curl_slist *headerlist = NULL;
121 125
 
122 126
 	memset(&stream, 0, sizeof(curl_res_stream_t));
123
-	stream.max_size = (size_t) params->maxdatasize;
127
+	stream.max_size = (size_t)params->maxdatasize;
124 128
 
125 129
 	if(params->pconn) {
126 130
 		LM_DBG("****** ##### We have a pconn - keep_connections: %d!\n",
127 131
 				params->keep_connections);
128 132
 		params->pconn->result_content_type[0] = '\0';
129 133
 		params->pconn->redirecturl[0] = '\0';
130
-		if (params->pconn->curl != NULL) {
131
-			LM_DBG("         ****** ##### Reusing existing connection if possible\n");
132
-			curl = params->pconn->curl;	/* Reuse existing handle */
134
+		if(params->pconn->curl != NULL) {
135
+			LM_DBG("         ****** ##### Reusing existing connection if "
136
+				   "possible\n");
137
+			curl = params->pconn->curl; /* Reuse existing handle */
133 138
 			curl_easy_reset(curl);		/* Reset handle */
134 139
 		}
135 140
 	}
136 141
 
137 142
 
138
-	if (curl == NULL) {
143
+	if(curl == NULL) {
139 144
 		curl = curl_easy_init();
140 145
 	}
141
-	if (curl == NULL) {
146
+	if(curl == NULL) {
142 147
 		LM_ERR("Failed to initialize curl connection\n");
143 148
 		return -1;
144 149
 	}
... ...
@@ -147,10 +152,12 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
147 152
 	res = curl_easy_setopt(curl, CURLOPT_URL, _url);
148 153
 
149 154
 	/* Limit to HTTP and HTTPS protocols */
150
-	res = curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
151
-	res = curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
155
+	res = curl_easy_setopt(
156
+			curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
157
+	res = curl_easy_setopt(
158
+			curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
152 159
 
153
-	if (params->post) {
160
+	if(params->post) {
154 161
 		/* Now specify we want to POST data */
155 162
 		res |= curl_easy_setopt(curl, CURLOPT_POST, 1L);
156 163
 
... ...
@@ -158,7 +165,8 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
158 165
 			char ctype[256];
159 166
 
160 167
 			ctype[0] = '\0';
161
-			snprintf(ctype, sizeof(ctype), "Content-Type: %s", params->contenttype);
168
+			snprintf(ctype, sizeof(ctype), "Content-Type: %s",
169
+					params->contenttype);
162 170
 
163 171
 			/* Set the content-type of the DATA */
164 172
 			headerlist = curl_slist_append(headerlist, ctype);
... ...
@@ -172,29 +180,29 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
172 180
 		res |= curl_easy_setopt(curl, CURLOPT_POST, 0L);
173 181
 	}
174 182
 
175
-	if (params->hdrs) {
183
+	if(params->hdrs) {
176 184
 		headerlist = curl_slist_append(headerlist, params->hdrs);
177 185
 	}
178 186
 	if(headerlist) {
179 187
 		res |= curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
180 188
 	}
181 189
 
182
-	if (params->maxdatasize) {
190
+	if(params->maxdatasize) {
183 191
 		/* Maximum data size to download - we always download full response,
184 192
 		 * but cut it off before moving to pvar */
185 193
 		LM_DBG("****** ##### CURL Max datasize %u\n", params->maxdatasize);
186 194
 	}
187 195
 
188
-	if (params->username) {
196
+	if(params->username) {
189 197
 		res |= curl_easy_setopt(curl, CURLOPT_USERNAME, params->username);
190 198
 		res |= curl_easy_setopt(curl, CURLOPT_HTTPAUTH, params->authmethod);
191 199
 	}
192
-	if (params->secret) {
200
+	if(params->secret) {
193 201
 		res |= curl_easy_setopt(curl, CURLOPT_PASSWORD, params->secret);
194 202
 	}
195 203
 
196 204
 	/* Client certificate */
197
-	if (params->clientcert != NULL && params->clientkey != NULL) {
205
+	if(params->clientcert != NULL && params->clientkey != NULL) {
198 206
 		res |= curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
199 207
 		res |= curl_easy_setopt(curl, CURLOPT_SSLCERT, params->clientcert);
200 208
 
... ...
@@ -202,43 +210,43 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
202 210
 		res |= curl_easy_setopt(curl, CURLOPT_SSLKEY, params->clientkey);
203 211
 	}
204 212
 
205
-	if (params->cacert != NULL) {
213
+	if(params->cacert != NULL) {
206 214
 		res |= curl_easy_setopt(curl, CURLOPT_CAINFO, params->cacert);
207 215
 	}
208 216
 
209
-	if (params->tlsversion != CURL_SSLVERSION_DEFAULT) {
210
-		res |= curl_easy_setopt(curl, CURLOPT_SSLVERSION,
211
-				(long) params->tlsversion);
217
+	if(params->tlsversion != CURL_SSLVERSION_DEFAULT) {
218
+		res |= curl_easy_setopt(
219
+				curl, CURLOPT_SSLVERSION, (long)params->tlsversion);
212 220
 	}
213 221
 
214
-	if (params->ciphersuites != NULL) {
215
-		res |= curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST,
216
-				params->ciphersuites);
222
+	if(params->ciphersuites != NULL) {
223
+		res |= curl_easy_setopt(
224
+				curl, CURLOPT_SSL_CIPHER_LIST, params->ciphersuites);
217 225
 	}
218 226
 
219
-	if (params->http_proxy  != NULL) {
227
+	if(params->http_proxy != NULL) {
220 228
 		LM_DBG("****** ##### CURL proxy [%s] \n", params->http_proxy);
221 229
 		res |= curl_easy_setopt(curl, CURLOPT_PROXY, params->http_proxy);
222 230
 	} else {
223 231
 		LM_DBG("****** ##### CURL proxy NOT SET \n");
224 232
 	}
225 233
 
226
-	if (params->http_proxy_port > 0) {
227
-		res |= curl_easy_setopt(curl, CURLOPT_PROXYPORT,
228
-				params->http_proxy_port);
234
+	if(params->http_proxy_port > 0) {
235
+		res |= curl_easy_setopt(
236
+				curl, CURLOPT_PROXYPORT, params->http_proxy_port);
229 237
 	}
230 238
 
231 239
 
232
-	res |= curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER,
233
-			(long) params->verify_peer);
234
-	res |= curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST,
235
-			(long) params->verify_host?2:0);
240
+	res |= curl_easy_setopt(
241
+			curl, CURLOPT_SSL_VERIFYPEER, (long)params->verify_peer);
242
+	res |= curl_easy_setopt(
243
+			curl, CURLOPT_SSL_VERIFYHOST, (long)params->verify_host ? 2 : 0);
236 244
 
237
-	res |= curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long) 1);
238
-	res |= curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long) params->timeout);
239
-	res |= curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,
240
-			(long) params->http_follow_redirect);
241
-	if (params->http_follow_redirect) {
245
+	res |= curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
246
+	res |= curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long)params->timeout);
247
+	res |= curl_easy_setopt(
248
+			curl, CURLOPT_FOLLOWLOCATION, (long)params->http_follow_redirect);
249
+	if(params->http_follow_redirect) {
242 250
 		LM_DBG("Following redirects for this request! \n");
243 251
 	}
244 252
 
... ...
@@ -249,7 +257,7 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
249 257
 	if(params->useragent)
250 258
 		res |= curl_easy_setopt(curl, CURLOPT_USERAGENT, params->useragent);
251 259
 
252
-	if (res != CURLE_OK) {
260
+	if(res != CURLE_OK) {
253 261
 		/* PANIC */
254 262
 		LM_ERR("Could not set CURL options. Library error \n");
255 263
 	} else {
... ...
@@ -259,63 +267,64 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
259 267
 
260 268
 		curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &totaltime);
261 269
 		curl_easy_getinfo(curl, CURLINFO_APPCONNECT_TIME, &connecttime);
262
-		LM_DBG("HTTP Call performed in %f s (connect time %f) \n",
263
-				totaltime, connecttime);
264
-		if (params->pconn) {
270
+		LM_DBG("HTTP Call performed in %f s (connect time %f) \n", totaltime,
271
+				connecttime);
272
+		if(params->pconn) {
265 273
 			params->pconn->querytime = totaltime;
266 274
 			params->pconn->connecttime = connecttime;
267 275
 		}
268
-
269 276
 	}
270 277
 
271 278
 	/* Cleanup */
272
-	if (headerlist) {
279
+	if(headerlist) {
273 280
 		curl_slist_free_all(headerlist);
274 281
 	}
275 282
 
276
-	if (res != CURLE_OK) {
283
+	if(res != CURLE_OK) {
277 284
 		/* http://curl.haxx.se/libcurl/c/libcurl-errors.html */
278
-		if (res == CURLE_COULDNT_CONNECT) {
285
+		if(res == CURLE_COULDNT_CONNECT) {
279 286
 			LM_WARN("failed to connect() to host (url: %s)\n", _url);
280
-		} else if ( res == CURLE_COULDNT_RESOLVE_HOST ) {
287
+		} else if(res == CURLE_COULDNT_RESOLVE_HOST) {
281 288
 			LM_WARN("Couldn't resolve host (url: %s)\n", _url);
282
-		} else if ( res == CURLE_COULDNT_RESOLVE_PROXY ) {
289
+		} else if(res == CURLE_COULDNT_RESOLVE_PROXY) {
283 290
 			LM_WARN("Couldn't resolve http proxy host (url: %s - proxy: %s)\n",
284
-				_url, (params && params->http_proxy)?params->http_proxy:"");
285
-		} else if ( res == CURLE_UNSUPPORTED_PROTOCOL ) {
291
+					_url,
292
+					(params && params->http_proxy) ? params->http_proxy : "");
293
+		} else if(res == CURLE_UNSUPPORTED_PROTOCOL) {
286 294
 			LM_WARN("URL Schema not supported by curl (url: %s)\n", _url);
287
-		} else if ( res == CURLE_URL_MALFORMAT ) {
295
+		} else if(res == CURLE_URL_MALFORMAT) {
288 296
 			LM_WARN("Malformed URL used in http client (url: %s)\n", _url);
289
-		} else if ( res == CURLE_OUT_OF_MEMORY ) {
297
+		} else if(res == CURLE_OUT_OF_MEMORY) {
290 298
 			LM_WARN("Curl library out of memory (url: %s)\n", _url);
291
-		} else if ( res == CURLE_OPERATION_TIMEDOUT ) {
299
+		} else if(res == CURLE_OPERATION_TIMEDOUT) {
292 300
 			LM_WARN("Curl library timed out on request (url: %s)\n", _url);
293
-		} else if ( res == CURLE_SSL_CONNECT_ERROR ) {
301
+		} else if(res == CURLE_SSL_CONNECT_ERROR) {
294 302
 			LM_WARN("TLS error in curl connection (url: %s)\n", _url);
295
-		} else if ( res == CURLE_SSL_CERTPROBLEM ) {
303
+		} else if(res == CURLE_SSL_CERTPROBLEM) {
296 304
 			LM_WARN("TLS local certificate error (url: %s)\n", _url);
297
-		} else if ( res == CURLE_SSL_CIPHER ) {
305
+		} else if(res == CURLE_SSL_CIPHER) {
298 306
 			LM_WARN("TLS cipher error (url: %s)\n", _url);
299
-		} else if ( res == CURLE_SSL_CACERT ) {
307
+		} else if(res == CURLE_SSL_CACERT) {
300 308
 			LM_WARN("TLS server certificate validation error"
301
-					" (No valid CA cert) (url: %s)\n", _url);
302
-		} else if ( res == CURLE_SSL_CACERT_BADFILE ) {
309
+					" (No valid CA cert) (url: %s)\n",
310
+					_url);
311
+		} else if(res == CURLE_SSL_CACERT_BADFILE) {
303 312
 			LM_WARN("TLS CA certificate read error (url: %s)\n", _url);
304
-		} else if ( res == CURLE_SSL_ISSUER_ERROR ) {
313
+		} else if(res == CURLE_SSL_ISSUER_ERROR) {
305 314
 			LM_WARN("TLS issuer certificate check error (url: %s)\n", _url);
306
-		} else if ( res == CURLE_PEER_FAILED_VERIFICATION ) {
315
+		} else if(res == CURLE_PEER_FAILED_VERIFICATION) {
307 316
 			LM_WARN("TLS verification error (url: %s)\n", _url);
308
-		} else if ( res == CURLE_TOO_MANY_REDIRECTS ) {
317
+		} else if(res == CURLE_TOO_MANY_REDIRECTS) {
309 318
 			LM_WARN("Too many redirects (url: %s)\n", _url);
310 319
 		} else {
311 320
 			LM_ERR("failed to perform curl (%d) (url: %s)\n", res, _url);
312 321
 		}
313 322
 
314
-		if (params->pconn) {
323
+		if(params->pconn) {
315 324
 			params->pconn->last_result = res;
316 325
 		}
317
-		if (params->pconn && params->keep_connections) {
318
-			params->pconn->curl = curl;	/* Save connection, don't close */
326
+		if(params->pconn && params->keep_connections) {
327
+			params->pconn->curl = curl; /* Save connection, don't close */
319 328
 		} else {
320 329
 			/* Cleanup and close - bye bye and thank you for all the bytes */
321 330
 			curl_easy_cleanup(curl);
... ...
@@ -324,7 +333,7 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
324 333
 			pkg_free(stream.buf);
325 334
 		}
326 335
 		counter_inc(connfail);
327
-		if (params->failovercon != NULL) {
336
+		if(params->failovercon != NULL) {
328 337
 			LM_ERR("FATAL FAILURE: Trying failover to curl con (%s)\n",
329 338
 					params->failovercon);
330 339
 			return (1000 + res);
... ...
@@ -344,55 +353,58 @@ static int curL_query_url(struct sip_msg* _m, const char* _url, str* _dst,
344 353
 
345 354
 		if(ct) {
346 355
 			LM_DBG("We received Content-Type: %s\n", ct);
347
-			if (params->pconn &&
348
-					strlen(ct)<sizeof(params->pconn->result_content_type)-1) {
356
+			if(params->pconn
357
+					&& strlen(ct) < sizeof(params->pconn->result_content_type)
358
+											- 1) {
349 359
 				strcpy(params->pconn->result_content_type, ct);
350 360
 			}
351 361
 		}
352 362
 		if(url) {
353 363
 			LM_DBG("We visited URL: %s\n", url);
354
-			if (params->pconn
355
-					&& strlen(url)<sizeof(params->pconn->redirecturl)-1) {
364
+			if(params->pconn
365
+					&& strlen(url) < sizeof(params->pconn->redirecturl) - 1) {
356 366
 				strcpy(params->pconn->redirecturl, url);
357 367
 			}
358 368
 		}
359 369
 	}
360
-	if (params->pconn) {
370
+	if(params->pconn) {
361 371
 		params->pconn->last_result = stat;
362 372
 	}
363 373
 
364
-	if ((stat >= 200) && (stat < 500)) {
374
+	if((stat >= 200) && (stat < 500)) {
365 375
 		double datasize = 0;
366 376
 
367 377
 		curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &download_size);
368 378
 		LM_DBG("  -- curl download size: %u \n", (unsigned int)download_size);
369 379
 		datasize = download_size;
370 380
 
371
-		if (download_size > 0) {
381
+		if(download_size > 0) {
372 382
 
373
-			if (params->oneline) {
383
+			if(params->oneline) {
374 384
 				/* search for line feed */
375 385
 				at = memchr(stream.buf, (char)10, download_size);
376
-				if(at!=NULL) {
377
-					datasize = (double) (at - stream.buf);
386
+				if(at != NULL) {
387
+					datasize = (double)(at - stream.buf);
378 388
 					LM_DBG("  -- curl download size cut to first line: %d\n",
379
-							(int) datasize);
389
+							(int)datasize);
380 390
 				} else {
381 391
 					LM_DBG("no end of line found for one line result type\n");
382 392
 				}