Browse code

dispatcher: use clang format across the module

Daniel-Constantin Mierla authored on 10/01/2017 22:36:18
Showing 8 changed files
... ...
@@ -31,22 +31,23 @@
31 31
 
32 32
 #include "../../core/sr_module.h"
33 33
 
34
-typedef int (*ds_select_dst_f)(struct sip_msg *msg, int set,
35
-			int alg, int mode);
34
+typedef int (*ds_select_dst_f)(struct sip_msg *msg, int set, int alg, int mode);
36 35
 typedef int (*ds_next_dst_f)(struct sip_msg *msg, int mode);
37 36
 typedef int (*ds_mark_dst_f)(struct sip_msg *msg, int mode);
38 37
 
39 38
 typedef int (*ds_is_from_list_f)(struct sip_msg *_m, int group);
40 39
 
40
+/* clang-format off */
41 41
 typedef struct dispatcher_api {
42 42
 	ds_select_dst_f   select;
43 43
 	ds_next_dst_f     next;
44 44
 	ds_mark_dst_f     mark;
45 45
 	ds_is_from_list_f is_from;
46 46
 } dispatcher_api_t;
47
+/* clang-format on */
47 48
 
48
-typedef int (*bind_dispatcher_f)(dispatcher_api_t* api);
49
-int bind_dispatcher(dispatcher_api_t* api);
49
+typedef int (*bind_dispatcher_f)(dispatcher_api_t *api);
50
+int bind_dispatcher(dispatcher_api_t *api);
50 51
 
51 52
 /**
52 53
  * @brief Load the dispatcher API
... ...
@@ -60,8 +61,7 @@ static inline int dispatcher_load_api(dispatcher_api_t *api)
60 61
 		LM_ERR("cannot find bind_dispatcher\n");
61 62
 		return -1;
62 63
 	}
63
-	if(binddispatcher(api)<0)
64
-	{
64
+	if(binddispatcher(api) < 0) {
65 65
 		LM_ERR("cannot bind dispatcher api\n");
66 66
 		return -1;
67 67
 	}
... ...
@@ -70,4 +70,3 @@ static inline int dispatcher_load_api(dispatcher_api_t *api)
70 70
 
71 71
 
72 72
 #endif
73
-
... ...
@@ -18,7 +18,7 @@
18 18
  */
19 19
 
20 20
 /*!
21
- * \file 
21
+ * \file
22 22
  * \brief Dispatcher :: Configuration
23 23
  * \ingroup Dispatcher
24 24
  */
... ...
@@ -29,11 +29,12 @@
29 29
 
30 30
 #include "config.h"
31 31
 
32
+/* clang-format off */
32 33
 struct cfg_group_dispatcher	default_dispatcher_cfg = {
33
-		1,	/* Probing threshold */	
34
-		1,      /* Inactive threshold */
35
-		{0,0}	/* reply codes */
36
-	    };
34
+	1,	/* Probing threshold */
35
+	1,      /* Inactive threshold */
36
+	{0,0}	/* reply codes */
37
+};
37 38
 
38 39
 void	*dispatcher_cfg = &default_dispatcher_cfg;
39 40
 
... ...
@@ -49,3 +50,4 @@ cfg_def_t	dispatcher_cfg_def[] = {
49 50
 		"Additional, valid reply codes for the OPTIONS Pinger. Default is \"\""},
50 51
 	{0, 0, 0, 0, 0, 0}
51 52
 };
53
+/* clang-format on */
... ...
@@ -31,16 +31,17 @@
31 31
 #include "../../core/cfg/cfg.h"
32 32
 #include "../../core/str.h"
33 33
 
34
-struct cfg_group_dispatcher {
34
+struct cfg_group_dispatcher
35
+{
35 36
 	int probing_threshold;
36 37
 	int inactive_threshold;
37 38
 	str ds_ping_reply_codes_str;
38 39
 };
39 40
 
40
-extern struct cfg_group_dispatcher	default_dispatcher_cfg;
41
-extern void	*dispatcher_cfg;
42
-extern cfg_def_t	dispatcher_cfg_def[];
41
+extern struct cfg_group_dispatcher default_dispatcher_cfg;
42
+extern void *dispatcher_cfg;
43
+extern cfg_def_t dispatcher_cfg_def[];
43 44
 
44
-extern void ds_ping_reply_codes_update(str*, str*);
45
+extern void ds_ping_reply_codes_update(str *, str *);
45 46
 
46 47
 #endif
... ...
@@ -57,13 +57,13 @@
57 57
 #include "api.h"
58 58
 #include "dispatch.h"
59 59
 
60
-#define DS_TABLE_VERSION	1
61
-#define DS_TABLE_VERSION2	2
62
-#define DS_TABLE_VERSION3	3
63
-#define DS_TABLE_VERSION4	4
60
+#define DS_TABLE_VERSION 1
61
+#define DS_TABLE_VERSION2 2
62
+#define DS_TABLE_VERSION3 3
63
+#define DS_TABLE_VERSION4 4
64 64
 
65
-#define DS_ALG_RROBIN	4
66
-#define DS_ALG_LOAD		10
65
+#define DS_ALG_RROBIN 4
66
+#define DS_ALG_LOAD 10
67 67
 
68 68
 static int _ds_table_version = DS_TABLE_VERSION;
69 69
 
... ...
@@ -74,31 +74,32 @@ static int *_ds_ping_active = NULL;
74 74
 extern int ds_force_dst;
75 75
 
76 76
 static db_func_t ds_dbf;
77
-static db1_con_t* ds_db_handle=NULL;
77
+static db1_con_t *ds_db_handle = NULL;
78 78
 
79
-ds_set_t **ds_lists=NULL;
79
+ds_set_t **ds_lists = NULL;
80 80
 
81 81
 int *ds_list_nr = NULL;
82
-int *crt_idx    = NULL;
83
-int *next_idx   = NULL;
82
+int *crt_idx = NULL;
83
+int *next_idx = NULL;
84 84
 
85
-#define _ds_list 	(ds_lists[*crt_idx])
85
+#define _ds_list (ds_lists[*crt_idx])
86 86
 #define _ds_list_nr (*ds_list_nr)
87 87
 
88 88
 static void ds_run_route(struct sip_msg *msg, str *uri, char *route);
89 89
 
90
-void shuffle_uint100array(unsigned int* arr);
91
-int ds_reinit_rweight_on_state_change(int old_state, int new_state, ds_set_t *dset);
90
+void shuffle_uint100array(unsigned int *arr);
91
+int ds_reinit_rweight_on_state_change(
92
+		int old_state, int new_state, ds_set_t *dset);
92 93
 
93 94
 /**
94 95
  *
95 96
  */
96 97
 int ds_ping_active_init(void)
97 98
 {
98
-	if(_ds_ping_active!=NULL)
99
+	if(_ds_ping_active != NULL)
99 100
 		return 0;
100
-	_ds_ping_active = (int*)shm_malloc(sizeof(int));
101
-	if(_ds_ping_active==NULL) {
101
+	_ds_ping_active = (int *)shm_malloc(sizeof(int));
102
+	if(_ds_ping_active == NULL) {
102 103
 		LM_ERR("no more shared memory\n");
103 104
 		return -1;
104 105
 	}
... ...
@@ -111,7 +112,7 @@ int ds_ping_active_init(void)
111 112
  */
112 113
 int ds_ping_active_get(void)
113 114
 {
114
-	if(_ds_ping_active==NULL)
115
+	if(_ds_ping_active == NULL)
115 116
 		return -1;
116 117
 	return *_ds_ping_active;
117 118
 }
... ...
@@ -121,7 +122,7 @@ int ds_ping_active_get(void)
121 122
  */
122 123
 int ds_ping_active_set(int v)
123 124
 {
124
-	if(_ds_ping_active==NULL)
125
+	if(_ds_ping_active == NULL)
125 126
 		return -1;
126 127
 	*_ds_ping_active = v;
127 128
 	return 0;
... ...
@@ -155,24 +156,22 @@ int ds_hash_load_destroy(void)
155 156
 /**
156 157
  * Recursivly print ds_set
157 158
  */
158
-void ds_log_set( ds_set_t* node )
159
+void ds_log_set(ds_set_t *node)
159 160
 {
160
-	if ( !node )
161
+	if(!node)
161 162
 		return;
162 163
 
163 164
 	int i;
164 165
 
165
-	for( i=0;i<2;++i)
166
-		ds_log_set( node->next[i] );
166
+	for(i = 0; i < 2; ++i)
167
+		ds_log_set(node->next[i]);
167 168
 
168
-	for(i=0; i<node->nr; i++)
169
-	{
169
+	for(i = 0; i < node->nr; i++) {
170 170
 		LM_DBG("dst>> %d %.*s %d %d (%.*s,%d,%d,%d)\n", node->id,
171 171
 				node->dlist[i].uri.len, node->dlist[i].uri.s,
172 172
 				node->dlist[i].flags, node->dlist[i].priority,
173 173
 				node->dlist[i].attrs.duid.len, node->dlist[i].attrs.duid.s,
174
-				node->dlist[i].attrs.maxload,
175
-				node->dlist[i].attrs.weight,
174
+				node->dlist[i].attrs.maxload, node->dlist[i].attrs.weight,
176 175
 				node->dlist[i].attrs.rweight);
177 176
 	}
178 177
 
... ...
@@ -184,10 +183,10 @@ void ds_log_set( ds_set_t* node )
184 183
  */
185 184
 int ds_log_sets(void)
186 185
 {
187
-	if(_ds_list==NULL)
186
+	if(_ds_list == NULL)
188 187
 		return -1;
189 188
 
190
-	ds_log_set( _ds_list );
189
+	ds_log_set(_ds_list);
191 190
 
192 191
 	return 0;
193 192
 }
... ...
@@ -197,29 +196,27 @@ int ds_log_sets(void)
197 196
  */
198 197
 int init_data(void)
199 198
 {
200
-	int * p;
199
+	int *p;
201 200
 
202
-	ds_lists = (ds_set_t**)shm_malloc(2*sizeof(ds_set_t*));
203
-	if(!ds_lists)
204
-	{
201
+	ds_lists = (ds_set_t **)shm_malloc(2 * sizeof(ds_set_t *));
202
+	if(!ds_lists) {
205 203
 		LM_ERR("Out of memory\n");
206 204
 		return -1;
207 205
 	}
208
-	memset(ds_lists, 0, 2*sizeof(ds_set_t*));
206
+	memset(ds_lists, 0, 2 * sizeof(ds_set_t *));
209 207
 
210 208
 
211
-	p = (int*)shm_malloc(3*sizeof(int));
212
-	if(!p)
213
-	{
209
+	p = (int *)shm_malloc(3 * sizeof(int));
210
+	if(!p) {
214 211
 		LM_ERR("Out of memory\n");
215 212
 		return -1;
216 213
 	}
217
-	memset(p, 0, 3*sizeof(int));
214
+	memset(p, 0, 3 * sizeof(int));
218 215
 
219 216
 	crt_idx = p;
220
-	next_idx = p+1;
221
-	ds_list_nr = p+2;
222
-	*crt_idx= *next_idx = 0;
217
+	next_idx = p + 1;
218
+	ds_list_nr = p + 2;
219
+	*crt_idx = *next_idx = 0;
223 220
 
224 221
 	return 0;
225 222
 }
... ...
@@ -229,20 +226,19 @@ int init_data(void)
229 226
  */
230 227
 int ds_set_attrs(ds_dest_t *dest, str *attrs)
231 228
 {
232
-	param_t* params_list = NULL;
229
+	param_t *params_list = NULL;
233 230
 	param_hooks_t phooks;
234
-	param_t *pit=NULL;
231
+	param_t *pit = NULL;
235 232
 	str param;
236 233
 	int tmp_rweight = 0;
237 234
 
238
-	if(attrs==NULL || attrs->len<=0)
235
+	if(attrs == NULL || attrs->len <= 0)
239 236
 		return 0;
240
-	if(attrs->s[attrs->len-1]==';')
237
+	if(attrs->s[attrs->len - 1] == ';')
241 238
 		attrs->len--;
242 239
 	/* clone in shm */
243
-	dest->attrs.body.s = (char*)shm_malloc(attrs->len+1);
244
-	if(dest->attrs.body.s==NULL)
245
-	{
240
+	dest->attrs.body.s = (char *)shm_malloc(attrs->len + 1);
241
+	if(dest->attrs.body.s == NULL) {
246 242
 		LM_ERR("no more shm\n");
247 243
 		return -1;
248 244
 	}
... ...
@@ -251,36 +247,33 @@ int ds_set_attrs(ds_dest_t *dest, str *attrs)
251 247
 	dest->attrs.body.len = attrs->len;
252 248
 
253 249
 	param = dest->attrs.body;
254
-	if (parse_params(&param, CLASS_ANY, &phooks, &params_list)<0)
250
+	if(parse_params(&param, CLASS_ANY, &phooks, &params_list) < 0)
255 251
 		return -1;
256
-	for (pit = params_list; pit; pit=pit->next)
257
-	{
258
-		if (pit->name.len==4
259
-				&& strncasecmp(pit->name.s, "duid", 4)==0) {
252
+	for(pit = params_list; pit; pit = pit->next) {
253
+		if(pit->name.len == 4 && strncasecmp(pit->name.s, "duid", 4) == 0) {
260 254
 			dest->attrs.duid = pit->body;
261
-		} else if(pit->name.len==6
262
-				&& strncasecmp(pit->name.s, "weight", 6)==0) {
255
+		} else if(pit->name.len == 6
256
+				  && strncasecmp(pit->name.s, "weight", 6) == 0) {
263 257
 			str2sint(&pit->body, &dest->attrs.weight);
264
-		} else if(pit->name.len==7
265
-				&& strncasecmp(pit->name.s, "maxload", 7)==0) {
258
+		} else if(pit->name.len == 7
259
+				  && strncasecmp(pit->name.s, "maxload", 7) == 0) {
266 260
 			str2sint(&pit->body, &dest->attrs.maxload);
267
-		} else if(pit->name.len==6
268
-				&& strncasecmp(pit->name.s, "socket", 6)==0) {
261
+		} else if(pit->name.len == 6
262
+				  && strncasecmp(pit->name.s, "socket", 6) == 0) {
269 263
 			dest->attrs.socket = pit->body;
270
-		}else if(pit->name.len==7
271
-				&& strncasecmp(pit->name.s, "rweight", 7)==0) {
264
+		} else if(pit->name.len == 7
265
+				  && strncasecmp(pit->name.s, "rweight", 7) == 0) {
272 266
 			tmp_rweight = 0;
273 267
 			str2sint(&pit->body, &tmp_rweight);
274
-			if ( tmp_rweight>=1 && tmp_rweight<=100 ) {
268
+			if(tmp_rweight >= 1 && tmp_rweight <= 100) {
275 269
 				dest->attrs.rweight = tmp_rweight;
276
-			}
277
-			else{
270
+			} else {
278 271
 				LM_ERR("rweight %d not in 1-100 range; skipped", tmp_rweight);
279 272
 			}
280 273
 		}
281
-
282 274
 	}
283
-	if(params_list) free_params(params_list);
275
+	if(params_list)
276
+		free_params(params_list);
284 277
 	return 0;
285 278
 }
286 279
 
... ...
@@ -292,91 +285,89 @@ ds_dest_t *pack_dest(str uri, int flags, int priority, str *attrs)
292 285
 	ds_dest_t *dp = NULL;
293 286
 	/* For DNS-Lookups */
294 287
 	static char hn[256];
295
-	struct hostent* he;
288
+	struct hostent *he;
296 289
 	struct sip_uri puri;
297 290
 	str host;
298 291
 	int port, proto;
299 292
 	char c = 0;
300 293
 
301 294
 	/* check uri */
302
-	if(parse_uri(uri.s, uri.len, &puri)!=0 || puri.host.len>254)
303
-	{
295
+	if(parse_uri(uri.s, uri.len, &puri) != 0 || puri.host.len > 254) {
304 296
 		LM_ERR("bad uri [%.*s]\n", uri.len, uri.s);
305 297
 		goto err;
306 298
 	}
307 299
 
308 300
 	/* skip IPv6 references if IPv6 lookups are disabled */
309
-	if (default_core_cfg.dns_try_ipv6 == 0 &&
310
-			puri.host.s[0] == '[' && puri.host.s[puri.host.len-1] == ']') {
301
+	if(default_core_cfg.dns_try_ipv6 == 0 && puri.host.s[0] == '['
302
+			&& puri.host.s[puri.host.len - 1] == ']') {
311 303
 		LM_DBG("skipping IPv6 record %.*s\n", puri.host.len, puri.host.s);
312 304
 		return NULL;
313 305
 	}
314 306
 
315 307
 	/* store uri */
316
-	dp = (ds_dest_t*)shm_malloc(sizeof(ds_dest_t));
317
-	if(dp==NULL)
318
-	{
308
+	dp = (ds_dest_t *)shm_malloc(sizeof(ds_dest_t));
309
+	if(dp == NULL) {
319 310
 		LM_ERR("no more memory!\n");
320 311
 		goto err;
321 312
 	}
322 313
 	memset(dp, 0, sizeof(ds_dest_t));
323 314
 
324
-	dp->uri.s = (char*)shm_malloc((uri.len+1)*sizeof(char));
325
-	if(dp->uri.s==NULL)
326
-	{
315
+	dp->uri.s = (char *)shm_malloc((uri.len + 1) * sizeof(char));
316
+	if(dp->uri.s == NULL) {
327 317
 		LM_ERR("no more memory!\n");
328 318
 		goto err;
329 319
 	}
330 320
 	strncpy(dp->uri.s, uri.s, uri.len);
331
-	dp->uri.s[uri.len]='\0';
321
+	dp->uri.s[uri.len] = '\0';
332 322
 	dp->uri.len = uri.len;
333 323
 
334 324
 	dp->flags = flags;
335 325
 	dp->priority = priority;
336 326
 
337
-	if(ds_set_attrs(dp, attrs)<0)
338
-	{
327
+	if(ds_set_attrs(dp, attrs) < 0) {
339 328
 		LM_ERR("cannot set attributes!\n");
340 329
 		goto err;
341 330
 	}
342 331
 
343 332
 	/* check socket attribute */
344
-	if (dp->attrs.socket.s && dp->attrs.socket.len > 0) {
333
+	if(dp->attrs.socket.s && dp->attrs.socket.len > 0) {
345 334
 		/* parse_phostport(...) expects 0-terminated string
346 335
 		 * - after socket parameter is either ';' or '\0' */
347
-		if(dp->attrs.socket.s[dp->attrs.socket.len]!='\0') {
336
+		if(dp->attrs.socket.s[dp->attrs.socket.len] != '\0') {
348 337
 			c = dp->attrs.socket.s[dp->attrs.socket.len];
349 338
 			dp->attrs.socket.s[dp->attrs.socket.len] = '\0';
350 339
 		}
351
-		if (parse_phostport(dp->attrs.socket.s, &host.s, &host.len,
352
-					&port, &proto)!=0) {
353
-			LM_ERR("bad socket <%.*s>\n", dp->attrs.socket.len, dp->attrs.socket.s);
354
-			if(c!=0) {
340
+		if(parse_phostport(
341
+				   dp->attrs.socket.s, &host.s, &host.len, &port, &proto)
342
+				!= 0) {
343
+			LM_ERR("bad socket <%.*s>\n", dp->attrs.socket.len,
344
+					dp->attrs.socket.s);
345
+			if(c != 0) {
355 346
 				dp->attrs.socket.s[dp->attrs.socket.len] = c;
356 347
 			}
357 348
 			goto err;
358 349
 		}
359
-		if(c!=0) {
350
+		if(c != 0) {
360 351
 			dp->attrs.socket.s[dp->attrs.socket.len] = c;
361 352
 		}
362
-		dp->sock = grep_sock_info( &host, (unsigned short)port, proto);
363
-		if (dp->sock==0) {
364
-			LM_ERR("non-local socket <%.*s>\n", dp->attrs.socket.len, dp->attrs.socket.s);
353
+		dp->sock = grep_sock_info(&host, (unsigned short)port, proto);
354
+		if(dp->sock == 0) {
355
+			LM_ERR("non-local socket <%.*s>\n", dp->attrs.socket.len,
356
+					dp->attrs.socket.s);
365 357
 			goto err;
366 358
 		}
367
-	} else if (ds_default_sockinfo) {
359
+	} else if(ds_default_sockinfo) {
368 360
 		dp->sock = ds_default_sockinfo;
369 361
 	}
370 362
 
371 363
 	/* The Hostname needs to be \0 terminated for resolvehost, so we
372 364
 	 * make a copy here. */
373 365
 	strncpy(hn, puri.host.s, puri.host.len);
374
-	hn[puri.host.len]='\0';
366
+	hn[puri.host.len] = '\0';
375 367
 
376 368
 	/* Do a DNS-Lookup for the Host-Name: */
377
-	he=resolvehost(hn);
378
-	if (he==0)
379
-	{
369
+	he = resolvehost(hn);
370
+	if(he == 0) {
380 371
 		LM_ERR("could not resolve %.*s\n", puri.host.len, puri.host.s);
381 372
 		goto err;
382 373
 	}
... ...
@@ -390,9 +381,8 @@ ds_dest_t *pack_dest(str uri, int flags, int priority, str *attrs)
390 381
 
391 382
 	return dp;
392 383
 err:
393
-	if(dp!=NULL)
394
-	{
395
-		if(dp->uri.s!=NULL)
384
+	if(dp != NULL) {
385
+		if(dp->uri.s != NULL)
396 386
 			shm_free(dp->uri.s);
397 387
 		shm_free(dp);
398 388
 	}
... ...
@@ -404,27 +394,25 @@ err:
404 394
  *
405 395
  */
406 396
 int add_dest2list(int id, str uri, int flags, int priority, str *attrs,
407
-		int list_idx, int* setn)
397
+		int list_idx, int *setn)
408 398
 {
409 399
 	ds_dest_t *dp = NULL;
410
-	ds_set_t  *sp = NULL;
400
+	ds_set_t *sp = NULL;
411 401
 	ds_dest_t *dp0 = NULL;
412 402
 	ds_dest_t *dp1 = NULL;
413 403
 
414
-	dp = pack_dest( uri, flags, priority, attrs );
415
-	if ( !dp )
404
+	dp = pack_dest(uri, flags, priority, attrs);
405
+	if(!dp)
416 406
 		goto err;
417 407
 
418
-	sp = ds_avl_insert( &ds_lists[list_idx], id, setn );
419
-	if( !sp )
420
-	{
408
+	sp = ds_avl_insert(&ds_lists[list_idx], id, setn);
409
+	if(!sp) {
421 410
 		LM_ERR("no more memory.\n");
422 411
 		goto err;
423 412
 	}
424 413
 	sp->nr++;
425 414
 
426
-	if(sp->dlist==NULL)
427
-	{
415
+	if(sp->dlist == NULL) {
428 416
 		sp->dlist = dp;
429 417
 	} else {
430 418
 		dp1 = NULL;
... ...
@@ -434,14 +422,13 @@ int add_dest2list(int id, str uri, int flags, int priority, str *attrs,
434 422
 			if(dp0->priority > dp->priority)
435 423
 				break;
436 424
 			dp1 = dp0;
437
-			dp0=dp0->next;
425
+			dp0 = dp0->next;
438 426
 		}
439
-		if(dp1==NULL)
440
-		{
427
+		if(dp1 == NULL) {
441 428
 			dp->next = sp->dlist;
442 429
 			sp->dlist = dp;
443 430
 		} else {
444
-			dp->next  = dp1->next;
431
+			dp->next = dp1->next;
445 432
 			dp1->next = dp;
446 433
 		}
447 434
 	}
... ...
@@ -450,9 +437,8 @@ int add_dest2list(int id, str uri, int flags, int priority, str *attrs,
450 437
 
451 438
 	return 0;
452 439
 err:
453
-	if(dp!=NULL)
454
-	{
455
-		if(dp->uri.s!=NULL)
440
+	if(dp != NULL) {
441
+		if(dp->uri.s != NULL)
456 442
 			shm_free(dp->uri.s);
457 443
 		shm_free(dp);
458 444
 	}
... ...
@@ -462,16 +448,16 @@ err:
462 448
 
463 449
 
464 450
 /* for internal usage; arr must be arr[100] */
465
-void shuffle_uint100array(unsigned int* arr){
466
-	if (arr == NULL)
451
+void shuffle_uint100array(unsigned int *arr)
452
+{
453
+	if(arr == NULL)
467 454
 		return;
468 455
 	int k;
469 456
 	int j;
470 457
 	unsigned int t;
471 458
 	kam_srand(time(0));
472
-	for (j=0; j<100; j++)
473
-	{
474
-		k = j + (kam_rand() % (100-j));
459
+	for(j = 0; j < 100; j++) {
460
+		k = j + (kam_rand() % (100 - j));
475 461
 		t = arr[j];
476 462
 		arr[j] = arr[k];
477 463
 		arr[k] = t;
... ...
@@ -491,39 +477,39 @@ int dp_init_relative_weights(ds_set_t *dset)
491 477
 	int k;
492 478
 	int t;
493 479
 
494
-	if(dset==NULL || dset->dlist==NULL)
480
+	if(dset == NULL || dset->dlist == NULL)
495 481
 		return -1;
496 482
 
497 483
 	int rw_sum = 0;
498 484
 	/* find the sum of relative weights*/
499
-	for(j=0; j<dset->nr; j++){
500
-		if( ds_skip_dst(dset->dlist[j].flags ) )
485
+	for(j = 0; j < dset->nr; j++) {
486
+		if(ds_skip_dst(dset->dlist[j].flags))
501 487
 			continue;
502 488
 		rw_sum += dset->dlist[j].attrs.rweight;
503 489
 	}
504 490
 
505
-	if (rw_sum == 0){
491
+	if(rw_sum == 0) {
506 492
 		return 0;
507 493
 	}
508 494
 
509 495
 	/* fill the array based on the relative weight of each destination */
510 496
 	t = 0;
511
-	for(j=0; j<dset->nr; j++)
512
-	{
513
-		if( ds_skip_dst(dset->dlist[j].flags ) )
497
+	for(j = 0; j < dset->nr; j++) {
498
+		if(ds_skip_dst(dset->dlist[j].flags))
514 499
 			continue;
515 500
 
516
-		int current_slice = dset->dlist[j].attrs.rweight*100/rw_sum;  //truncate here;
517
-		for(k=0; k<current_slice; k++)
518
-		{
501
+		int current_slice =
502
+				dset->dlist[j].attrs.rweight * 100 / rw_sum; //truncate here;
503
+		for(k = 0; k < current_slice; k++) {
519 504
 			dset->rwlist[t] = (unsigned int)j;
520 505
 			t++;
521 506
 		}
522 507
 	}
523 508
 	/* if the array was not completely filled (i.e., the sum of rweights is
524 509
 	 * less than 100 due to truncated), then use last address to fill the rest */
525
-	unsigned int last_insert = t>0? dset->rwlist[t-1] : (unsigned int)(dset->nr-1);
526
-	for(j=t; j<100; j++)
510
+	unsigned int last_insert =
511
+			t > 0 ? dset->rwlist[t - 1] : (unsigned int)(dset->nr - 1);
512
+	for(j = t; j < 100; j++)
527 513
 		dset->rwlist[j] = last_insert;
528 514
 
529 515
 	/* shuffle the content of the array in order to mix the selection
... ...
@@ -548,11 +534,11 @@ int dp_init_weights(ds_set_t *dset)
548 534
 	int k;
549 535
 	int t;
550 536
 
551
-	if(dset==NULL || dset->dlist==NULL)
537
+	if(dset == NULL || dset->dlist == NULL)
552 538
 		return -1;
553 539
 
554 540
 	/* is weight set for dst list? (first address must have weight!=0) */
555
-	if(dset->dlist[0].attrs.weight==0)
541
+	if(dset->dlist[0].attrs.weight == 0)
556 542
 		return 0;
557 543
 
558 544
 	/* first fill the array based on the weight of each destination
... ...
@@ -561,11 +547,9 @@ int dp_init_weights(ds_set_t *dset)
561 547
 	 * - if the sum of weights is more than 100, the addresses over the
562 548
 	 *   limit are ignored */
563 549
 	t = 0;
564
-	for(j=0; j<dset->nr; j++)
565
-	{
566
-		for(k=0; k<dset->dlist[j].attrs.weight; k++)
567
-		{
568
-			if(t>=100)
550
+	for(j = 0; j < dset->nr; j++) {
551
+		for(k = 0; k < dset->dlist[j].attrs.weight; k++) {
552
+			if(t >= 100)
569 553
 				goto randomize;
570 554
 			dset->wlist[t] = (unsigned int)j;
571 555
 			t++;
... ...
@@ -573,8 +557,8 @@ int dp_init_weights(ds_set_t *dset)
573 557
 	}
574 558
 	/* if the array was not completely filled (i.e., the sum of weights is
575 559
 	 * less than 100), then use last address to fill the rest */
576
-	for(; t<100; t++)
577
-		dset->wlist[t] = (unsigned int)(dset->nr-1);
560
+	for(; t < 100; t++)
561
+		dset->wlist[t] = (unsigned int)(dset->nr - 1);
578 562
 randomize:
579 563
 	/* shuffle the content of the array in order to mix the selection
580 564
 	 * of the addresses (e.g., if first address has weight=20, avoid
... ...
@@ -586,46 +570,43 @@ randomize:
586 570
 }
587 571
 
588 572
 /*! \brief  compact destinations from sets for fast access */
589
-int reindex_dests( ds_set_t* node )
573
+int reindex_dests(ds_set_t *node)
590 574
 {
591
-	int i=0;
592
-	int j=0;
575
+	int i = 0;
576
+	int j = 0;
593 577
 
594
-	if ( !node )
578
+	if(!node)
595 579
 		return 0;
596 580
 
597
-	for( ;i<2;++i)
598
-	{
599
-		int rc = reindex_dests( node->next[i] );
600
-		if ( rc != 0 )
581
+	for(; i < 2; ++i) {
582
+		int rc = reindex_dests(node->next[i]);
583
+		if(rc != 0)
601 584
 			return rc;
602 585
 	}
603 586
 
604
-	ds_dest_t *dp = NULL, *dp0= NULL;
587
+	ds_dest_t *dp = NULL, *dp0 = NULL;
605 588
 
606
-	dp0 = (ds_dest_t*)shm_malloc(node->nr*sizeof(ds_dest_t));
607
-	if(dp0==NULL)
608
-	{
589
+	dp0 = (ds_dest_t *)shm_malloc(node->nr * sizeof(ds_dest_t));
590
+	if(dp0 == NULL) {
609 591
 		LM_ERR("no more memory!\n");
610 592
 		goto err1;
611 593
 	}
612
-	memset(dp0, 0, node->nr*sizeof(ds_dest_t));
594
+	memset(dp0, 0, node->nr * sizeof(ds_dest_t));
613 595
 
614 596
 	/* copy from the old pointer to destination, and then free it */
615
-	for(j=node->nr-1; j>=0 && node->dlist!= NULL; j--)
616
-	{
597
+	for(j = node->nr - 1; j >= 0 && node->dlist != NULL; j--) {
617 598
 		memcpy(&dp0[j], node->dlist, sizeof(ds_dest_t));
618
-		if(j==node->nr-1)
599
+		if(j == node->nr - 1)
619 600
 			dp0[j].next = NULL;
620 601
 		else
621
-			dp0[j].next = &dp0[j+1];
602
+			dp0[j].next = &dp0[j + 1];
622 603
 
623 604
 
624 605
 		dp = node->dlist;
625 606
 		node->dlist = dp->next;
626 607
 
627 608
 		shm_free(dp);
628
-		dp=NULL;
609
+		dp = NULL;
629 610
 	}
630 611
 	node->dlist = dp0;
631 612
 	dp_init_weights(node);
... ...
@@ -646,115 +627,109 @@ int ds_load_list(char *lfile)
646 627
 	str uri;
647 628
 	str attrs;
648 629
 
649
-	if( (*crt_idx) != (*next_idx)) {
630
+	if((*crt_idx) != (*next_idx)) {
650 631
 		LM_WARN("load command already generated, aborting reload...\n");
651 632
 		return 0;
652 633
 	}
653 634
 
654
-	if(lfile==NULL || strlen(lfile)<=0)
655
-	{
635
+	if(lfile == NULL || strlen(lfile) <= 0) {
656 636
 		LM_ERR("bad list file\n");
657 637
 		return -1;
658 638
 	}
659 639
 
660 640
 	f = fopen(lfile, "r");
661
-	if(f==NULL)
662
-	{
641
+	if(f == NULL) {
663 642
 		LM_ERR("can't open list file [%s]\n", lfile);
664 643
 		return -1;
665
-
666 644
 	}
667 645
 
668 646
 	id = setn = flags = priority = 0;
669 647
 
670
-	*next_idx = (*crt_idx + 1)%2;
671
-	ds_avl_destroy( &ds_lists[*next_idx] );
648
+	*next_idx = (*crt_idx + 1) % 2;
649
+	ds_avl_destroy(&ds_lists[*next_idx]);
672 650
 
673 651
 	p = fgets(line, 256, f);
674
-	while(p)
675
-	{
652
+	while(p) {
676 653
 		/* eat all white spaces */
677
-		while(*p && (*p==' ' || *p=='\t' || *p=='\r' || *p=='\n'))
654
+		while(*p && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n'))
678 655
 			p++;
679
-		if(*p=='\0' || *p=='#')
656
+		if(*p == '\0' || *p == '#')
680 657
 			goto next_line;
681 658
 
682 659
 		/* get set id */
683 660
 		id = 0;
684
-		while(*p>='0' && *p<='9')
685
-		{
686
-			id = id*10+ (*p-'0');
661
+		while(*p >= '0' && *p <= '9') {
662
+			id = id * 10 + (*p - '0');
687 663
 			p++;
688 664
 		}
689 665
 
690 666
 		/* eat all white spaces */
691
-		while(*p && (*p==' ' || *p=='\t' || *p=='\r' || *p=='\n'))
667
+		while(*p && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n'))
692 668
 			p++;
693
-		if(*p=='\0' || *p=='#')
694
-		{
669
+		if(*p == '\0' || *p == '#') {
695 670
 			LM_ERR("bad line [%s]\n", line);
696 671
 			goto error;
697 672
 		}
698 673
 
699 674
 		/* get uri */
700 675
 		uri.s = p;
701
-		while(*p && *p!=' ' && *p!='\t' && *p!='\r' && *p!='\n' && *p!='#')
676
+		while(*p && *p != ' ' && *p != '\t' && *p != '\r' && *p != '\n'
677
+				&& *p != '#')
702 678
 			p++;
703
-		uri.len = p-uri.s;
679
+		uri.len = p - uri.s;
704 680
 
705 681
 		/* eat all white spaces */
706
-		while(*p && (*p==' ' || *p=='\t' || *p=='\r' || *p=='\n'))
682
+		while(*p && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n'))
707 683
 			p++;
708 684
 
709 685
 		/* get flags */
710 686
 		flags = 0;
711 687
 		priority = 0;
712
-		attrs.s = 0; attrs.len = 0;
713
-		if(*p=='\0' || *p=='#')
688
+		attrs.s = 0;
689
+		attrs.len = 0;
690
+		if(*p == '\0' || *p == '#')
714 691
 			goto add_destination; /* no flags given */
715 692
 
716
-		while(*p>='0' && *p<='9')
717
-		{
718
-			flags = flags*10+ (*p-'0');
693
+		while(*p >= '0' && *p <= '9') {
694
+			flags = flags * 10 + (*p - '0');
719 695
 			p++;
720 696
 		}
721 697
 
722 698
 		/* eat all white spaces */
723
-		while(*p && (*p==' ' || *p=='\t' || *p=='\r' || *p=='\n'))
699
+		while(*p && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n'))
724 700
 			p++;
725 701
 
726 702
 		/* get priority */
727
-		if(*p=='\0' || *p=='#')
703
+		if(*p == '\0' || *p == '#')
728 704
 			goto add_destination; /* no priority given */
729 705
 
730
-		while(*p>='0' && *p<='9')
731
-		{
732
-			priority = priority*10+ (*p-'0');
706
+		while(*p >= '0' && *p <= '9') {
707
+			priority = priority * 10 + (*p - '0');
733 708
 			p++;
734 709
 		}
735 710
 
736 711
 		/* eat all white spaces */
737
-		while(*p && (*p==' ' || *p=='\t' || *p=='\r' || *p=='\n'))
712
+		while(*p && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n'))
738 713
 			p++;
739
-		if(*p=='\0' || *p=='#')
714
+		if(*p == '\0' || *p == '#')
740 715
 			goto add_destination; /* no attrs given */
741 716
 
742 717
 		/* get attributes */
743 718
 		attrs.s = p;
744
-		while(*p && *p!=' ' && *p!='\t' && *p!='\r' && *p!='\n')
719
+		while(*p && *p != ' ' && *p != '\t' && *p != '\r' && *p != '\n')
745 720
 			p++;
746
-		attrs.len = p-attrs.s;
721
+		attrs.len = p - attrs.s;
747 722
 
748
-add_destination:
749
-		if(add_dest2list(id, uri, flags, priority, &attrs,
750
-					*next_idx, &setn ) != 0)
723
+	add_destination:
724
+		if(add_dest2list(id, uri, flags, priority, &attrs, *next_idx, &setn)
725
+				!= 0)
751 726
 			LM_WARN("unable to add destination %.*s to set %d -- skipping\n",
752 727
 					uri.len, uri.s, id);
753
-next_line:
728
+	next_line:
754 729
 		p = fgets(line, 256, f);
755 730
 	}
756 731
 
757
-	if(reindex_dests(ds_lists[*next_idx])!=0){
732
+	if(reindex_dests(ds_lists[*next_idx]) != 0) {
758 733
 		LM_ERR("error on reindex\n");
759 734
 		goto error;
760 735
 	}
... ...
@@ -771,9 +746,9 @@ next_line:
771 746
 	return 0;
772 747
 
773 748
 error:
774
-	if(f!=NULL)
749
+	if(f != NULL)
775 750
 		fclose(f);
776
-	ds_avl_destroy( &ds_lists[*next_idx] );
751
+	ds_avl_destroy(&ds_lists[*next_idx]);
777 752
 	*next_idx = *crt_idx;
778 753
 	return -1;
779 754
 }
... ...
@@ -783,7 +758,7 @@ error:
783 758
  */
784 759
 int ds_connect_db(void)
785 760
 {
786
-	if(ds_db_url.s==NULL)
761
+	if(ds_db_url.s == NULL)
787 762
 		return -1;
788 763
 
789 764
 	if((ds_db_handle = ds_dbf.init(&ds_db_url)) == 0) {
... ...
@@ -798,8 +773,7 @@ int ds_connect_db(void)
798 773
  */
799 774
 void ds_disconnect_db(void)
800 775
 {
801
-	if(ds_db_handle)
802
-	{
776
+	if(ds_db_handle) {
803 777
 		ds_dbf.close(ds_db_handle);
804 778
 		ds_db_handle = 0;
805 779
 	}
... ...
@@ -810,44 +784,39 @@ int init_ds_db(void)
810 784
 {
811 785
 	int ret;
812 786
 
813
-	if(ds_table_name.s == 0)
814
-	{
787
+	if(ds_table_name.s == 0) {
815 788
 		LM_ERR("invalid database name\n");
816 789
 		return -1;
817 790
 	}
818 791
 
819 792
 	/* Find a database module */
820
-	if (db_bind_mod(&ds_db_url, &ds_dbf) < 0)
821
-	{
793
+	if(db_bind_mod(&ds_db_url, &ds_dbf) < 0) {
822 794
 		LM_ERR("Unable to bind to a database driver\n");
823 795
 		return -1;
824 796
 	}
825 797
 
826
-	if(ds_connect_db()!=0)
827
-	{
798
+	if(ds_connect_db() != 0) {
828 799
 		LM_ERR("unable to connect to the database\n");
829 800
 		return -1;
830 801
 	}
831 802
 
832 803
 	_ds_table_version = db_table_version(&ds_dbf, ds_db_handle, &ds_table_name);
833
-	if (_ds_table_version < 0)
834
-	{
804
+	if(_ds_table_version < 0) {
835 805
 		LM_ERR("failed to query table version\n");
836 806
 		return -1;
837
-	} else if (_ds_table_version != DS_TABLE_VERSION
838
-			&& _ds_table_version != DS_TABLE_VERSION2
839
-			&& _ds_table_version != DS_TABLE_VERSION3
840
-			&& _ds_table_version != DS_TABLE_VERSION4) {
807
+	} else if(_ds_table_version != DS_TABLE_VERSION
808
+			  && _ds_table_version != DS_TABLE_VERSION2
809
+			  && _ds_table_version != DS_TABLE_VERSION3
810
+			  && _ds_table_version != DS_TABLE_VERSION4) {
841 811
 		LM_ERR("invalid table version (found %d , required %d, %d, %d or %d)\n"
842
-				"(use kamdbctl reinit)\n",
812
+			   "(use kamdbctl reinit)\n",
843 813
 				_ds_table_version, DS_TABLE_VERSION, DS_TABLE_VERSION2,
844 814
 				DS_TABLE_VERSION3, DS_TABLE_VERSION4);
845 815
 		return -1;
846 816
 	}
847 817
 
848 818
 	ret = ds_load_db();
849
-	if (ret == -2)
850
-	{
819
+	if(ret == -2) {
851 820
 		LM_WARN("failure while loading one or more dispatcher entries\n");
852 821
 		ret = 0;
853 822
 	}
... ...
@@ -862,14 +831,12 @@ int ds_reload_db(void)
862 831
 {
863 832
 	int ret;
864 833
 
865
-	if(ds_connect_db()!=0)
866
-	{
834
+	if(ds_connect_db() != 0) {
867 835
 		LM_ERR("unable to connect to the database\n");
868 836
 		return -1;
869 837
 	}
870 838
 	ret = ds_load_db();
871
-	if (ret == -2)
872
-	{
839
+	if(ret == -2) {
873 840
 		LM_WARN("failure while loading one or more dispatcher entries\n");
874 841
 	}
875 842
 	ds_disconnect_db();
... ...
@@ -887,13 +854,12 @@ int ds_load_db(void)
887 854
 	int dest_errs = 0;
888 855
 	str uri;
889 856
 	str attrs = {0, 0};
890
-	db1_res_t * res;
891
-	db_val_t * values;
892
-	db_row_t * rows;
857
+	db1_res_t *res;
858
+	db_val_t *values;
859
+	db_row_t *rows;
893 860
 
894 861
 	db_key_t query_cols[5] = {&ds_set_id_col, &ds_dest_uri_col,
895
-		&ds_dest_flags_col, &ds_dest_priority_col,
896
-		&ds_dest_attrs_col};
862
+			&ds_dest_flags_col, &ds_dest_priority_col, &ds_dest_attrs_col};
897 863
 
898 864
 	nrcols = 2;
899 865
 	if(_ds_table_version == DS_TABLE_VERSION2)
... ...
@@ -903,69 +869,64 @@ int ds_load_db(void)
903 869
 	else if(_ds_table_version == DS_TABLE_VERSION4)
904 870
 		nrcols = 5;
905 871
 
906
-	if( (*crt_idx) != (*next_idx))
907
-	{
872
+	if((*crt_idx) != (*next_idx)) {
908 873
 		LM_WARN("load command already generated, aborting reload...\n");
909 874
 		return 0;
910 875
 	}
911 876
 
912
-	if(ds_db_handle == NULL){
877
+	if(ds_db_handle == NULL) {
913 878
 		LM_ERR("invalid DB handler\n");
914 879
 		return -1;
915 880
 	}
916 881
 
917
-	if (ds_dbf.use_table(ds_db_handle, &ds_table_name) < 0)
918
-	{
882
+	if(ds_dbf.use_table(ds_db_handle, &ds_table_name) < 0) {
919 883
 		LM_ERR("error in use_table\n");
920 884
 		return -1;
921 885
 	}
922 886
 
923 887
 	/*select the whole table and all the columns*/
924
-	if(ds_dbf.query(ds_db_handle,0,0,0,query_cols,0,nrcols,0,&res) < 0)
925
-	{
888
+	if(ds_dbf.query(ds_db_handle, 0, 0, 0, query_cols, 0, nrcols, 0, &res)
889
+			< 0) {
926 890
 		LM_ERR("error while querying database\n");
927 891
 		return -1;
928 892
 	}
929 893
 
930 894
 	nr_rows = RES_ROW_N(res);
931
-	rows 	= RES_ROWS(res);
895
+	rows = RES_ROWS(res);
932 896
 	if(nr_rows == 0)
933 897
 		LM_WARN("no dispatching data in the db -- empty destination set\n");
934 898
 
935 899
 	setn = 0;
936
-	*next_idx = (*crt_idx + 1)%2;
937
-	ds_avl_destroy( &ds_lists[*next_idx] );
900
+	*next_idx = (*crt_idx + 1) % 2;
901
+	ds_avl_destroy(&ds_lists[*next_idx]);
938 902
 
939
-	for(i=0; i<nr_rows; i++)
940
-	{
941
-		values = ROW_VALUES(rows+i);
903
+	for(i = 0; i < nr_rows; i++) {
904
+		values = ROW_VALUES(rows + i);
942 905
 
943 906
 		id = VAL_INT(values);
944
-		uri.s = VAL_STR(values+1).s;
907
+		uri.s = VAL_STR(values + 1).s;
945 908
 		uri.len = strlen(uri.s);
946 909
 		flags = 0;
947
-		if(nrcols>=3)
948
-			flags = VAL_INT(values+2);
949
-		priority=0;
950
-		if(nrcols>=4)
951
-			priority = VAL_INT(values+3);
952
-
953
-		attrs.s = 0; attrs.len = 0;
954
-		if(nrcols>=5)
955
-		{
956
-			attrs.s = VAL_STR(values+4).s;
910
+		if(nrcols >= 3)
911
+			flags = VAL_INT(values + 2);
912
+		priority = 0;
913
+		if(nrcols >= 4)
914
+			priority = VAL_INT(values + 3);
915
+
916
+		attrs.s = 0;
917
+		attrs.len = 0;
918
+		if(nrcols >= 5) {
919
+			attrs.s = VAL_STR(values + 4).s;
957 920
 			attrs.len = strlen(attrs.s);
958 921
 		}
959
-		if(add_dest2list(id, uri, flags, priority, &attrs,
960
-					*next_idx, &setn) != 0)
961
-		{
922
+		if(add_dest2list(id, uri, flags, priority, &attrs, *next_idx, &setn)
923
+				!= 0) {
962 924
 			dest_errs++;
963 925
 			LM_WARN("unable to add destination %.*s to set %d -- skipping\n",
964 926
 					uri.len, uri.s, id);
965 927
 		}
966 928
 	}
967
-	if(reindex_dests(ds_lists[*next_idx])!=0)
968
-	{
929
+	if(reindex_dests(ds_lists[*next_idx]) != 0) {
969 930
 		LM_ERR("error on reindex\n");
970 931
 		goto err2;
971 932
 	}
... ...
@@ -981,12 +942,12 @@ int ds_load_db(void)
981 942
 
982 943
 	ds_log_sets();
983 944
 
984
-	if (dest_errs > 0)
945
+	if(dest_errs > 0)
985 946
 		return -2;
986 947
 	return 0;
987 948
 
988 949
 err2:
989
-	ds_avl_destroy( &ds_lists[*next_idx] );
950
+	ds_avl_destroy(&ds_lists[*next_idx]);
990 951
 	ds_dbf.free_result(ds_db_handle, res);
991 952
 	*next_idx = *crt_idx;
992 953
 
... ...
@@ -996,13 +957,13 @@ err2:
996 957
 /*! \brief called from dispatcher.c: free all*/
997 958
 int ds_destroy_list(void)
998 959
 {
999
-	if (ds_lists) {
1000
-		ds_avl_destroy( &ds_lists[0] );
1001
-		ds_avl_destroy( &ds_lists[1] );
960
+	if(ds_lists) {
961
+		ds_avl_destroy(&ds_lists[0]);
962
+		ds_avl_destroy(&ds_lists[1]);
1002 963
 		shm_free(ds_lists);
1003 964
 	}
1004 965
 
1005
-	if (crt_idx)
966
+	if(crt_idx)
1006 967
 		shm_free(crt_idx);
1007 968
 
1008 969
 	return 0;
... ...
@@ -1013,55 +974,47 @@ int ds_destroy_list(void)
1013 974
  */
1014 975
 unsigned int ds_get_hash(str *x, str *y)
1015 976
 {
1016
-	char* p;
977
+	char *p;
1017 978
 	register unsigned v;
1018 979
 	register unsigned h;
1019 980
 
1020 981
 	if(!x && !y)
1021 982
 		return 0;
1022
-	h=0;
1023
-	if(x)
1024
-	{
1025
-		p=x->s;
1026
-		if (x->len>=4)
1027
-		{
1028
-			for (; p<=(x->s+x->len-4); p+=4)
1029
-			{
1030
-				v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
1031
-				h+=v^(v>>3);
983
+	h = 0;
984
+	if(x) {
985
+		p = x->s;
986
+		if(x->len >= 4) {
987
+			for(; p <= (x->s + x->len - 4); p += 4) {
988
+				v = (*p << 24) + (p[1] << 16) + (p[2] << 8) + p[3];
989
+				h += v ^ (v >> 3);
1032 990
 			}
1033 991
 		}
1034
-		v=0;
1035
-		for (;p<(x->s+x->len); p++)
1036
-		{
1037
-			v<<=8;
1038
-			v+=*p;
992
+		v = 0;
993
+		for(; p < (x->s + x->len); p++) {
994
+			v <<= 8;
995
+			v += *p;
1039 996
 		}
1040
-		h+=v^(v>>3);
1041
-	}
1042
-	if(y)
1043
-	{
1044
-		p=y->s;
1045
-		if (y->len>=4)
1046
-		{
1047
-			for (; p<=(y->s+y->len-4); p+=4)
1048
-			{
1049
-				v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
1050
-				h+=v^(v>>3);
997
+		h += v ^ (v >> 3);
998
+	}
999
+	if(y) {
1000
+		p = y->s;
1001
+		if(y->len >= 4) {
1002
+			for(; p <= (y->s + y->len - 4); p += 4) {
1003
+				v = (*p << 24) + (p[1] << 16) + (p[2] << 8) + p[3];
1004
+				h += v ^ (v >> 3);
1051 1005
 			}
1052 1006
 		}
1053 1007
 
1054
-		v=0;
1055
-		for (;p<(y->s+y->len); p++)
1056
-		{
1057
-			v<<=8;
1058
-			v+=*p;
1008
+		v = 0;
1009
+		for(; p < (y->s + y->len); p++) {
1010
+			v <<= 8;
1011
+			v += *p;
1059 1012
 		}
1060
-		h+=v^(v>>3);
1013
+		h += v ^ (v >> 3);
1061 1014
 	}
1062
-	h=((h)+(h>>11))+((h>>13)+(h>>23));
1015
+	h = ((h) + (h >> 11)) + ((h >> 13) + (h >> 23));
1063 1016
 
1064
-	return (h)?h:1;
1017
+	return (h) ? h : 1;
1065 1018
 }
1066 1019
 
1067 1020
 
... ...
@@ -1079,49 +1032,44 @@ unsigned int ds_get_hash(str *x, str *y)
1079 1032
  *                      will be used
1080 1033
  * \return: -1 on error, 0 on success
1081 1034
  */
1082
-static inline int get_uri_hash_keys(str* key1, str* key2,
1083
-		str* uri, struct sip_uri* parsed_uri, int flags)
1035
+static inline int get_uri_hash_keys(
1036
+		str *key1, str *key2, str *uri, struct sip_uri *parsed_uri, int flags)
1084 1037
 {
1085 1038
 	struct sip_uri tmp_p_uri; /* used only if parsed_uri==0 */
1086 1039
 
1087
-	if (parsed_uri==0)
1088
-	{
1089
-		if (parse_uri(uri->s, uri->len, &tmp_p_uri)<0)
1090
-		{
1091
-			LM_ERR("invalid uri %.*s\n", uri->len, uri->len?uri->s:"");
1040
+	if(parsed_uri == 0) {
1041
+		if(parse_uri(uri->s, uri->len, &tmp_p_uri) < 0) {
1042
+			LM_ERR("invalid uri %.*s\n", uri->len, uri->len ? uri->s : "");
1092 1043
 			goto error;
1093 1044
 		}
1094
-		parsed_uri=&tmp_p_uri;
1045
+		parsed_uri = &tmp_p_uri;
1095 1046
 	}
1096 1047
 	/* uri sanity checks */
1097
-	if (parsed_uri->host.s==0)
1098
-	{
1099
-		LM_ERR("invalid uri, no host present: %.*s\n",
1100
-				uri->len, uri->len?uri->s:"");
1048
+	if(parsed_uri->host.s == 0) {
1049
+		LM_ERR("invalid uri, no host present: %.*s\n", uri->len,
1050
+				uri->len ? uri->s : "");
1101 1051
 		goto error;
1102 1052
 	}
1103 1053
 
1104 1054
 	/* we want: user@host:port if port !=5060
1105 1055
 	 *          user@host if port==5060
1106 1056
 	 *          user if the user flag is set*/
1107
-	*key1=parsed_uri->user;
1108
-	key2->s=0;
1109
-	key2->len=0;
1110
-	if (!(flags & DS_HASH_USER_ONLY))
1111
-	{	/* key2=host */
1112
-		*key2=parsed_uri->host;
1057
+	*key1 = parsed_uri->user;
1058
+	key2->s = 0;
1059
+	key2->len = 0;
1060
+	if(!(flags & DS_HASH_USER_ONLY)) { /* key2=host */
1061
+		*key2 = parsed_uri->host;
1113 1062
 		/* add port if needed */
1114
-		if (parsed_uri->port.s!=0)
1115
-		{ /* uri has a port */
1063
+		if(parsed_uri->port.s != 0) { /* uri has a port */
1116 1064
 			/* skip port if == 5060 or sips and == 5061 */
1117
-			if (parsed_uri->port_no !=
1118
-					((parsed_uri->type==SIPS_URI_T)?SIPS_PORT:SIP_PORT))
1119
-				key2->len+=parsed_uri->port.len+1 /* ':' */;
1065
+			if(parsed_uri->port_no != ((parsed_uri->type == SIPS_URI_T)
1066
+													  ? SIPS_PORT
1067
+													  : SIP_PORT))
1068
+				key2->len += parsed_uri->port.len + 1 /* ':' */;
1120 1069
 		}
1121 1070
 	}
1122
-	if (key1->s==0)
1123
-	{
1124
-		LM_WARN("empty username in: %.*s\n", uri->len, uri->len?uri->s:"");
1071
+	if(key1->s == 0) {
1072
+		LM_WARN("empty username in: %.*s\n", uri->len, uri->len ? uri->s : "");
1125 1073
 	}
1126 1074
 	return 0;
1127 1075
 error:
... ...
@@ -1138,27 +1086,24 @@ int ds_hash_fromuri(struct sip_msg *msg, unsigned int *hash)
1138 1086
 	str key1;
1139 1087
 	str key2;
1140 1088
 
1141
-	if(msg==NULL || hash == NULL)
1142
-	{
1089
+	if(msg == NULL || hash == NULL) {
1143 1090
 		LM_ERR("bad parameters\n");
1144 1091
 		return -1;
1145 1092
 	}
1146 1093
 
1147
-	if(parse_from_header(msg)<0)
1148
-	{
1094
+	if(parse_from_header(msg) < 0) {
1149 1095
 		LM_ERR("cannot parse From hdr\n");
1150 1096
 		return -1;
1151 1097
 	}
1152 1098
 
1153
-	if(msg->from==NULL || get_from(msg)==NULL)
1154
-	{
1099
+	if(msg->from == NULL || get_from(msg) == NULL) {
1155 1100
 		LM_ERR("cannot get From uri\n");
1156 1101
 		return -1;
1157 1102
 	}
1158 1103
 
1159
-	from   = get_from(msg)->uri;
1104
+	from = get_from(msg)->uri;
1160 1105
 	trim(&from);
1161
-	if (get_uri_hash_keys(&key1, &key2, &from, 0, ds_flags)<0)
1106
+	if(get_uri_hash_keys(&key1, &key2, &from, 0, ds_flags) < 0)
1162 1107
 		return -1;
1163 1108
 	*hash = ds_get_hash(&key1, &key2);
1164 1109
 
... ...
@@ -1175,23 +1120,21 @@ int ds_hash_touri(struct sip_msg *msg, unsigned int *hash)
1175 1120
 	str key1;
1176 1121
 	str key2;
1177 1122
 
1178
-	if(msg==NULL || hash == NULL)
1179
-	{
1123
+	if(msg == NULL || hash == NULL) {
1180 1124
 		LM_ERR("bad parameters\n");
1181 1125
 		return -1;
1182 1126
 	}
1183
-	if ((msg->to==0) && ((parse_headers(msg, HDR_TO_F, 0)==-1) ||
1184
-				(msg->to==0)))
1185
-	{
1127
+	if((msg->to == 0)
1128
+			&& ((parse_headers(msg, HDR_TO_F, 0) == -1) || (msg->to == 0))) {
1186 1129
 		LM_ERR("cannot parse To hdr\n");
1187 1130
 		return -1;
1188 1131
 	}
1189 1132
 
1190 1133
 
1191
-	to   = get_to(msg)->uri;
1134
+	to = get_to(msg)->uri;
1192 1135
 	trim(&to);
1193 1136
 
1194
-	if (get_uri_hash_keys(&key1, &key2, &to, 0, ds_flags)<0)
1137
+	if(get_uri_hash_keys(&key1, &key2, &to, 0, ds_flags) < 0)
1195 1138
 		return -1;
1196 1139
 	*hash = ds_get_hash(&key1, &key2);
1197 1140
 
... ...
@@ -1205,20 +1148,18 @@ int ds_hash_touri(struct sip_msg *msg, unsigned int *hash)
1205 1148
 int ds_hash_callid(struct sip_msg *msg, unsigned int *hash)
1206 1149
 {
1207 1150
 	str cid;
1208
-	if(msg==NULL || hash == NULL)
1209
-	{
1151
+	if(msg == NULL || hash == NULL) {
1210 1152
 		LM_ERR("bad parameters\n");
1211 1153
 		return -1;
1212 1154
 	}
1213 1155
 
1214
-	if(msg->callid==NULL && ((parse_headers(msg, HDR_CALLID_F, 0)==-1) ||
1215
-				(msg->callid==NULL)) )
1216
-	{
1156
+	if(msg->callid == NULL && ((parse_headers(msg, HDR_CALLID_F, 0) == -1)
1157
+									  || (msg->callid == NULL))) {
1217 1158
 		LM_ERR("cannot parse Call-Id\n");
1218 1159
 		return -1;
1219 1160
 	}
1220 1161
 
1221
-	cid.s   = msg->callid->body.s;
1162
+	cid.s = msg->callid->body.s;
1222 1163
 	cid.len = msg->callid->body.len;
1223 1164
 	trim(&cid);
1224 1165
 
... ...
@@ -1233,23 +1174,22 @@ int ds_hash_callid(struct sip_msg *msg, unsigned int *hash)
1233 1174
  */
1234 1175
 int ds_hash_ruri(struct sip_msg *msg, unsigned int *hash)
1235 1176
 {
1236
-	str* uri;
1177
+	str *uri;
1237 1178
 	str key1;
1238 1179
 	str key2;
1239 1180
 
1240 1181
 
1241
-	if(msg==NULL || hash == NULL)
1242
-	{
1182
+	if(msg == NULL || hash == NULL) {
1243 1183
 		LM_ERR("bad parameters\n");
1244 1184
 		return -1;
1245 1185
 	}
1246
-	if (parse_sip_msg_uri(msg)<0){
1186
+	if(parse_sip_msg_uri(msg) < 0) {
1247 1187
 		LM_ERR("bad request uri\n");
1248 1188
 		return -1;
1249 1189
 	}
1250 1190
 
1251
-	uri=GET_RURI(msg);
1252
-	if (get_uri_hash_keys(&key1, &key2, uri, &msg->parsed_uri, ds_flags)<0)
1191
+	uri = GET_RURI(msg);
1192
+	if(get_uri_hash_keys(&key1, &key2, uri, &msg->parsed_uri, ds_flags) < 0)
1253 1193
 		return -1;
1254 1194
 
1255 1195
 	*hash = ds_get_hash(&key1, &key2);
... ...
@@ -1262,49 +1202,43 @@ int ds_hash_ruri(struct sip_msg *msg, unsigned int *hash)
1262 1202
 int ds_hash_authusername(struct sip_msg *msg, unsigned int *hash)
1263 1203
 {
1264 1204
 	/* Header, which contains the authorization */
1265
-	struct hdr_field* h = 0;
1205
+	struct hdr_field *h = 0;
1266 1206
 	/* The Username */
1267 1207
 	str username = {0, 0};
1268 1208
 	/* The Credentials from this request */
1269
-	auth_body_t* cred;
1209
+	auth_body_t *cred;
1270 1210
 
1271
-	if(msg==NULL || hash == NULL)
1272
-	{
1211
+	if(msg == NULL || hash == NULL) {
1273 1212
 		LM_ERR("bad parameters\n");
1274 1213
 		return -1;
1275 1214
 	}
1276
-	if (parse_headers(msg, HDR_PROXYAUTH_F, 0) == -1)
1277
-	{
1215
+	if(parse_headers(msg, HDR_PROXYAUTH_F, 0) == -1) {
1278 1216
 		LM_ERR("error parsing headers!\n");
1279 1217
 		return -1;
1280 1218
 	}
1281
-	if (msg->proxy_auth && !msg->proxy_auth->parsed)
1219
+	if(msg->proxy_auth && !msg->proxy_auth->parsed)
1282 1220
 		parse_credentials(msg->proxy_auth);
1283
-	if (msg->proxy_auth && msg->proxy_auth->parsed) {
1221
+	if(msg->proxy_auth && msg->proxy_auth->parsed) {
1284 1222
 		h = msg->proxy_auth;
1285 1223
 	}
1286
-	if (!h)
1287
-	{
1288
-		if (parse_headers(msg, HDR_AUTHORIZATION_F, 0) == -1)
1289
-		{
1224
+	if(!h) {
1225
+		if(parse_headers(msg, HDR_AUTHORIZATION_F, 0) == -1) {
1290 1226
 			LM_ERR("error parsing headers!\n");
1291 1227
 			return -1;
1292 1228
 		}
1293
-		if (msg->authorization && !msg->authorization->parsed)
1229
+		if(msg->authorization && !msg->authorization->parsed)
1294 1230
 			parse_credentials(msg->authorization);
1295
-		if (msg->authorization && msg->authorization->parsed) {
1231
+		if(msg->authorization && msg->authorization->parsed) {
1296 1232
 			h = msg->authorization;
1297 1233
 		}
1298 1234
 	}
1299
-	if (!h)
1300
-	{
1235
+	if(!h) {
1301 1236
 		LM_DBG("No Authorization-Header!\n");
1302