Browse code

sca: clang format code

Victor Seva authored on 16/06/2020 07:31:55
Showing 22 changed files
... ...
@@ -60,9 +60,9 @@ sca_mod *sca = NULL;
60 60
 /*
61 61
  * EXTERNAL API
62 62
  */
63
-db_func_t dbf;	// db api
63
+db_func_t dbf;		 // db api
64 64
 struct tm_binds tmb; // tm functions for sending messages
65
-sl_api_t slb; // sl callback, function for getting to-tag
65
+sl_api_t slb;		 // sl callback, function for getting to-tag
66 66
 
67 67
 /*
68 68
  * PROTOTYPES
... ...
@@ -71,10 +71,10 @@ static int sca_mod_init(void);
71 71
 static int sca_child_init(int);
72 72
 static void sca_mod_destroy(void);
73 73
 static int sca_set_config(sca_mod *);
74
-static int sca_call_info_update_0_f(sip_msg_t* msg, char*, char*);
75
-static int sca_call_info_update_1_f(sip_msg_t* msg, char*, char*);
76
-static int sca_call_info_update_2_f(sip_msg_t* msg, char*, char*);
77
-static int sca_call_info_update_3_f(sip_msg_t* msg, char*, char*, char *);
74
+static int sca_call_info_update_0_f(sip_msg_t *msg, char *, char *);
75
+static int sca_call_info_update_1_f(sip_msg_t *msg, char *, char *);
76
+static int sca_call_info_update_2_f(sip_msg_t *msg, char *, char *);
77
+static int sca_call_info_update_3_f(sip_msg_t *msg, char *, char *, char *);
78 78
 int fixup_ciu(void **, int);
79 79
 int fixup_free_ciu(void **param, int param_no);
80 80
 
... ...
@@ -84,16 +84,18 @@ int fixup_free_ciu(void **param, int param_no);
84 84
 static cmd_export_t cmds[] = {
85 85
 		{"sca_handle_subscribe", (cmd_function)sca_handle_subscribe, 0, NULL, 0,
86 86
 				REQUEST_ROUTE},
87
-		{"sca_call_info_update", (cmd_function)sca_call_info_update_0_f, 0, NULL, 0,
88
-				REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
87
+		{"sca_call_info_update", (cmd_function)sca_call_info_update_0_f, 0,
88
+				NULL, 0, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
89 89
 		{"sca_call_info_update", (cmd_function)sca_call_info_update_1_f, 1,
90
-			fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
90
+				fixup_ciu, fixup_free_ciu,
91
+				REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
91 92
 		{"sca_call_info_update", (cmd_function)sca_call_info_update_2_f, 2,
92
-			fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
93
+				fixup_ciu, fixup_free_ciu,
94
+				REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
93 95
 		{"sca_call_info_update", (cmd_function)sca_call_info_update_3_f, 3,
94
-			fixup_ciu, fixup_free_ciu, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
95
-		{ 0, 0, 0, 0, 0, 0 }
96
-};
96
+				fixup_ciu, fixup_free_ciu,
97
+				REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE},
98
+		{0, 0, 0, 0, 0, 0}};
97 99
 
98 100
 /*
99 101
  * EXPORTED RPC INTERFACE
... ...
@@ -158,6 +160,7 @@ static param_export_t params[] = {
158 160
 /*
159 161
  * MODULE EXPORTS
160 162
  */
163
+/* clang-format off */
161 164
 struct module_exports exports= {
162 165
 	"sca",           /* module name */
163 166
 	DEFAULT_DLFLAGS, /* dlopen flags */
... ...
@@ -170,6 +173,7 @@ struct module_exports exports= {
170 173
 	sca_child_init,  /* per-child init function */
171 174
 	sca_mod_destroy  /* module destroy function */
172 175
 };
176
+/* clang-format on */
173 177
 
174 178
 static int sca_bind_sl(sca_mod *scam, sl_api_t *sl_api)
175 179
 {
... ...
@@ -178,16 +182,17 @@ static int sca_bind_sl(sca_mod *scam, sl_api_t *sl_api)
178 182
 	assert(scam != NULL);
179 183
 	assert(sl_api != NULL);
180 184
 
181
-	if (sl_load_api(sl_api) != 0) {
182
-		LM_ERR("Failed to initialize required sl API. Check if the \"sl\" module is loaded.\n");
185
+	if(sl_load_api(sl_api) != 0) {
186
+		LM_ERR("Failed to initialize required sl API. Check if the \"sl\" "
187
+			   "module is loaded.\n");
183 188
 		return (-1);
184 189
 	}
185 190
 	scam->sl_api = sl_api;
186 191
 
187 192
 	sl_cbe.type = SLCB_REPLY_READY;
188
-	sl_cbe.cbf = (sl_cbf_f) sca_call_info_sl_reply_cb;
193
+	sl_cbe.cbf = (sl_cbf_f)sca_call_info_sl_reply_cb;
189 194
 
190
-	if (scam->sl_api->register_cb(&sl_cbe) < 0) {
195
+	if(scam->sl_api->register_cb(&sl_cbe) < 0) {
191 196
 		LM_ERR("Failed to register sl reply callback\n");
192 197
 		return (-1);
193 198
 	}
... ...
@@ -200,13 +205,14 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api)
200 205
 	db1_con_t *db_con = NULL;
201 206
 	int rc = -1;
202 207
 
203
-	if (db_bind_mod(scam->cfg->db_url, db_api) != 0) {
204
-		LM_ERR("Failed to initialize required DB API - %.*s\n", STR_FMT(scam->cfg->db_url));
208
+	if(db_bind_mod(scam->cfg->db_url, db_api) != 0) {
209
+		LM_ERR("Failed to initialize required DB API - %.*s\n",
210
+				STR_FMT(scam->cfg->db_url));
205 211
 		goto done;
206 212
 	}
207 213
 	scam->db_api = db_api;
208 214
 
209
-	if (!DB_CAPABILITY((*db_api), DB_CAP_ALL)) {
215
+	if(!DB_CAPABILITY((*db_api), DB_CAP_ALL)) {
210 216
 		LM_ERR("Selected database %.*s lacks required capabilities\n",
211 217
 				STR_FMT(scam->cfg->db_url));
212 218
 		goto done;
... ...
@@ -214,14 +220,15 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api)
214 220
 
215 221
 	// ensure database exists and table schemas are correct
216 222
 	db_con = db_api->init(scam->cfg->db_url);
217
-	if (db_con == NULL) {
223
+	if(db_con == NULL) {
218 224
 		LM_ERR("sca_bind_srdb1: failed to connect to DB %.*s\n",
219 225
 				STR_FMT(scam->cfg->db_url));
220 226
 		goto done;
221 227
 	}
222 228
 
223
-	if (db_check_table_version(db_api, db_con, scam->cfg->subs_table,
224
-			SCA_DB_SUBSCRIPTIONS_TABLE_VERSION) < 0) {
229
+	if(db_check_table_version(db_api, db_con, scam->cfg->subs_table,
230
+			   SCA_DB_SUBSCRIPTIONS_TABLE_VERSION)
231
+			< 0) {
225 232
 		str tmp = *scam->cfg->subs_table;
226 233
 		DB_TABLE_VERSION_ERROR(tmp);
227 234
 		goto done;
... ...
@@ -230,7 +237,8 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api)
230 237
 	// DB and tables are OK, close DB handle. reopen in each child.
231 238
 	rc = 0;
232 239
 
233
-	done: if (db_con != NULL) {
240
+done:
241
+	if(db_con != NULL) {
234 242
 		db_api->close(db_con);
235 243
 		db_con = NULL;
236 244
 	}
... ...
@@ -240,36 +248,36 @@ static int sca_bind_srdb1(sca_mod *scam, db_func_t *db_api)
240 248
 
241 249
 static int sca_set_config(sca_mod *scam)
242 250
 {
243
-	scam->cfg = (sca_config *) shm_malloc(sizeof(sca_config));
244
-	if (scam->cfg == NULL) {
251
+	scam->cfg = (sca_config *)shm_malloc(sizeof(sca_config));
252
+	if(scam->cfg == NULL) {
245 253
 		LM_ERR("Failed to shm_malloc module configuration\n");
246 254
 		return (-1);
247 255
 	}
248 256
 	memset(scam->cfg, 0, sizeof(sca_config));
249 257
 
250
-	if (outbound_proxy.s) {
258
+	if(outbound_proxy.s) {
251 259
 		scam->cfg->outbound_proxy = &outbound_proxy;
252 260
 	}
253 261
 
254
-	if (!db_url.s || db_url.len <= 0) {
262
+	if(!db_url.s || db_url.len <= 0) {
255 263
 		LM_ERR("sca_set_config: db_url must be set!\n");
256 264
 		return (-1);
257 265
 	}
258 266
 	scam->cfg->db_url = &db_url;
259 267
 
260
-	if (!db_subs_table.s || db_subs_table.len <= 0) {
268
+	if(!db_subs_table.s || db_subs_table.len <= 0) {
261 269
 		LM_ERR("sca_set_config: subs_table must be set!\n");
262 270
 		return (-1);
263 271
 	}
264 272
 	scam->cfg->subs_table = &db_subs_table;
265 273
 
266
-	if (!db_state_table.s || db_state_table.len <= 0) {
274
+	if(!db_state_table.s || db_state_table.len <= 0) {
267 275
 		LM_ERR("sca_set_config: state_table must be set!\n");
268 276
 		return (-1);
269 277
 	}
270 278
 	scam->cfg->state_table = &db_state_table;
271 279
 
272
-	if (hash_table_size > 0) {
280
+	if(hash_table_size > 0) {
273 281
 		scam->cfg->hash_table_size = 1 << hash_table_size;
274 282
 	} else {
275 283
 		scam->cfg->hash_table_size = 512;
... ...
@@ -285,7 +293,7 @@ static int sca_set_config(sca_mod *scam)
285 293
 	}
286 294
 	scam->cfg->onhold_bflag = onhold_bflag;
287 295
 
288
-	if (server_address.s) {
296
+	if(server_address.s) {
289 297
 		scam->cfg->server_address = &server_address;
290 298
 	}
291 299
 
... ...
@@ -294,24 +302,26 @@ static int sca_set_config(sca_mod *scam)
294 302
 
295 303
 static int sca_child_init(int rank)
296 304
 {
297
-	if (rank == PROC_INIT || rank == PROC_TCP_MAIN) {
305
+	if(rank == PROC_INIT || rank == PROC_TCP_MAIN) {
298 306
 		return (0);
299 307
 	}
300 308
 
301
-	if (rank == PROC_MAIN) {
302
-		if (fork_dummy_timer(PROC_TIMER, "SCA DB SYNC PROCESS", 0, // we don't need sockets, just writing to DB
303
-		sca_subscription_db_update_timer, // timer cb
304
-		NULL, // parameter passed to callback
305
-		sca->cfg->db_update_interval) < 0) {
309
+	if(rank == PROC_MAIN) {
310
+		if(fork_dummy_timer(PROC_TIMER, "SCA DB SYNC PROCESS",
311
+				   0, // we don't need sockets, just writing to DB
312
+				   sca_subscription_db_update_timer, // timer cb
313
+				   NULL, // parameter passed to callback
314
+				   sca->cfg->db_update_interval)
315
+				< 0) {
306 316
 			LM_ERR("sca_child_init: failed to register subscription DB "
307
-					"sync timer process\n");
317
+				   "sync timer process\n");
308 318
 			return (-1);
309 319
 		}
310 320
 
311 321
 		return (0);
312 322
 	}
313 323
 
314
-	if (sca->db_api == NULL || sca->db_api->init == NULL) {
324
+	if(sca->db_api == NULL || sca->db_api->init == NULL) {
315 325
 		LM_CRIT("sca_child_init: DB API not loaded!\n");
316 326
 		return (-1);
317 327
 	}
... ...
@@ -321,45 +331,47 @@ static int sca_child_init(int rank)
321 331
 
322 332
 static int sca_mod_init(void)
323 333
 {
324
-	sca = (sca_mod *) shm_malloc(sizeof(sca_mod));
325
-	if (sca == NULL) {
334
+	sca = (sca_mod *)shm_malloc(sizeof(sca_mod));
335
+	if(sca == NULL) {
326 336
 		LM_ERR("Failed to shm_malloc module object\n");
327 337
 		return (-1);
328 338
 	}
329 339
 	memset(sca, 0, sizeof(sca_mod));
330 340
 
331
-	if (sca_set_config(sca) != 0) {
341
+	if(sca_set_config(sca) != 0) {
332 342
 		LM_ERR("Failed to set configuration\n");
333 343
 		goto error;
334 344
 	}
335 345
 
336
-	if (rpc_register_array(sca_rpc) != 0) {
346
+	if(rpc_register_array(sca_rpc) != 0) {
337 347
 		LM_ERR("Failed to register RPC commands\n");
338 348
 		goto error;
339 349
 	}
340 350
 
341
-	if (sca_bind_srdb1(sca, &dbf) != 0) {
351
+	if(sca_bind_srdb1(sca, &dbf) != 0) {
342 352
 		LM_ERR("Failed to initialize required DB API\n");
343 353
 		goto error;
344 354
 	}
345 355
 
346
-	if (load_tm_api(&tmb) != 0) {
347
-		LM_ERR("Failed to initialize required tm API. Check that the \"tm\" module is loaded before this module.\n");
356
+	if(load_tm_api(&tmb) != 0) {
357
+		LM_ERR("Failed to initialize required tm API. Check that the \"tm\" "
358
+			   "module is loaded before this module.\n");
348 359
 		goto error;
349 360
 	}
350 361
 	sca->tm_api = &tmb;
351 362
 
352
-	if (sca_bind_sl(sca, &slb) != 0) {
353
-		LM_ERR("Failed to initialize required sl API. Check that the \"sl\" module is loaded before this module.\n");
363
+	if(sca_bind_sl(sca, &slb) != 0) {
364
+		LM_ERR("Failed to initialize required sl API. Check that the \"sl\" "
365
+			   "module is loaded before this module.\n");
354 366
 		goto error;
355 367
 	}
356 368
 
357
-	if (sca_hash_table_create(&sca->subscriptions, sca->cfg->hash_table_size)
369
+	if(sca_hash_table_create(&sca->subscriptions, sca->cfg->hash_table_size)
358 370
 			!= 0) {
359 371
 		LM_ERR("Failed to create subscriptions hash table\n");
360 372
 		goto error;
361 373
 	}
362
-	if (sca_hash_table_create(&sca->appearances, sca->cfg->hash_table_size)
374
+	if(sca_hash_table_create(&sca->appearances, sca->cfg->hash_table_size)
363 375
 			!= 0) {
364 376
 		LM_ERR("Failed to create appearances hash table\n");
365 377
 		goto error;
... ...
@@ -369,8 +381,8 @@ static int sca_mod_init(void)
369 381
 
370 382
 	register_timer(sca_subscription_purge_expired, sca,
371 383
 			sca->cfg->purge_expired_interval);
372
-	register_timer(sca_appearance_purge_stale, sca,
373
-			sca->cfg->purge_expired_interval);
384
+	register_timer(
385
+			sca_appearance_purge_stale, sca, sca->cfg->purge_expired_interval);
374 386
 
375 387
 	// register separate timer process to write subscriptions to DB.
376 388
 	// move to 3.3+ timer API (register_basic_timer) at some point.
... ...
@@ -381,14 +393,15 @@ static int sca_mod_init(void)
381 393
 
382 394
 	return (0);
383 395
 
384
-	error: if (sca != NULL) {
385
-		if (sca->cfg != NULL) {
396
+error:
397
+	if(sca != NULL) {
398
+		if(sca->cfg != NULL) {
386 399
 			shm_free(sca->cfg);
387 400
 		}
388
-		if (sca->subscriptions != NULL) {
401
+		if(sca->subscriptions != NULL) {
389 402
 			sca_hash_table_free(sca->subscriptions);
390 403
 		}
391
-		if (sca->appearances != NULL) {
404
+		if(sca->appearances != NULL) {
392 405
 			sca_hash_table_free(sca->appearances);
393 406
 		}
394 407
 		shm_free(sca);
... ...
@@ -400,75 +413,73 @@ static int sca_mod_init(void)
400 413
 
401 414
 void sca_mod_destroy(void)
402 415
 {
403
-	if (sca == 0)
416
+	if(sca == 0)
404 417
 		return;
405 418
 
406 419
 	// write back to the DB to retain most current subscription info
407
-	if (sca_subscription_db_update() != 0) {
408
-		if (sca && sca->cfg && sca->cfg->db_url) {
420
+	if(sca_subscription_db_update() != 0) {
421
+		if(sca && sca->cfg && sca->cfg->db_url) {
409 422
 			LM_ERR("sca_mod_destroy: failed to save current subscriptions \n"
410
-					"in DB %.*s", STR_FMT(sca->cfg->db_url));
423
+				   "in DB %.*s",
424
+					STR_FMT(sca->cfg->db_url));
411 425
 		}
412 426
 	}
413 427
 
414 428
 	sca_db_disconnect();
415 429
 }
416 430
 
417
-static int sca_call_info_update_0_f(sip_msg_t* msg, char* p1, char* p2)
431
+static int sca_call_info_update_0_f(sip_msg_t *msg, char *p1, char *p2)
418 432
 {
419 433
 	return sca_call_info_update(msg, SCA_CALL_INFO_SHARED_BOTH, NULL, NULL);
420 434
 }
421 435
 
422
-static int sca_call_info_update_1_f(sip_msg_t* msg, char* p1, char* p2)
436
+static int sca_call_info_update_1_f(sip_msg_t *msg, char *p1, char *p2)
423 437
 {
424 438
 	int update_mask = SCA_CALL_INFO_SHARED_BOTH;
425 439
 
426
-	if (get_int_fparam(&update_mask, msg, (fparam_t *) p1) < 0) {
440
+	if(get_int_fparam(&update_mask, msg, (fparam_t *)p1) < 0) {
427 441
 		LM_ERR("sca_call_info_update: argument 1: bad value "
428
-				"(integer expected)\n");
442
+			   "(integer expected)\n");
429 443
 		return (-1);
430 444
 	}
431 445
 
432 446
 	return sca_call_info_update(msg, update_mask, NULL, NULL);
433 447
 }
434 448
 
435
-static int sca_call_info_update_2_f(sip_msg_t* msg, char* p1, char* p2)
449
+static int sca_call_info_update_2_f(sip_msg_t *msg, char *p1, char *p2)
436 450
 {
437 451
 	str uri_to = STR_NULL;
438 452
 	int update_mask = SCA_CALL_INFO_SHARED_BOTH;
439 453
 
440
-	if (get_int_fparam(&update_mask, msg, (fparam_t *) p1) < 0) {
454
+	if(get_int_fparam(&update_mask, msg, (fparam_t *)p1) < 0) {
441 455
 		LM_ERR("sca_call_info_update: argument 1: bad value "
442
-				"(integer expected)\n");
456
+			   "(integer expected)\n");
443 457
 		return (-1);
444 458
 	}
445
-	if(get_str_fparam(&uri_to, msg, (gparam_p)p2)!=0)
446
-	{
459
+	if(get_str_fparam(&uri_to, msg, (gparam_p)p2) != 0) {
447 460
 		LM_ERR("unable to get value from param pvar_to\n");
448 461
 		return -1;
449 462
 	}
450 463
 	return sca_call_info_update(msg, update_mask, &uri_to, NULL);
451 464
 }
452 465
 
453
-static int sca_call_info_update_3_f(sip_msg_t* msg,
454
-	char* p1, char* p2, char * p3)
466
+static int sca_call_info_update_3_f(
467
+		sip_msg_t *msg, char *p1, char *p2, char *p3)
455 468
 {
456 469
 	str uri_to = STR_NULL;
457 470
 	str uri_from = STR_NULL;
458 471
 	int update_mask = SCA_CALL_INFO_SHARED_BOTH;
459 472
 
460
-	if (get_int_fparam(&update_mask, msg, (fparam_t *) p1) < 0) {
473
+	if(get_int_fparam(&update_mask, msg, (fparam_t *)p1) < 0) {
461 474
 		LM_ERR("sca_call_info_update: argument 1: bad value "
462
-				"(integer expected)\n");
475
+			   "(integer expected)\n");
463 476
 		return (-1);
464 477
 	}
465
-	if(get_str_fparam(&uri_to, msg, (gparam_p)p2)!=0)
466
-	{
478
+	if(get_str_fparam(&uri_to, msg, (gparam_p)p2) != 0) {
467 479
 		LM_ERR("unable to get value from param pvar_to\n");
468 480
 		return -1;
469 481
 	}
470
-	if(get_str_fparam(&uri_from, msg, (gparam_p)p3)!=0)
471
-	{
482
+	if(get_str_fparam(&uri_from, msg, (gparam_p)p3) != 0) {
472 483
 		LM_ERR("unable to get value from param pvar_from\n");
473 484
 		return -1;
474 485
 	}
... ...
@@ -490,7 +501,7 @@ int ki_sca_call_info_update_turi(sip_msg_t *msg, int umask, str *sto)
490 501
 
491 502
 int fixup_ciu(void **param, int param_no)
492 503
 {
493
-	switch (param_no) {
504
+	switch(param_no) {
494 505
 		case 1:
495 506
 			return fixup_var_int_1(param, param_no);
496 507
 		case 2:
... ...
@@ -503,7 +514,7 @@ int fixup_ciu(void **param, int param_no)
503 514
 
504 515
 int fixup_free_ciu(void **param, int param_no)
505 516
 {
506
-	switch (param_no) {
517
+	switch(param_no) {
507 518
 		case 1:
508 519
 			return 0;
509 520
 		case 2:
... ...
@@ -27,7 +27,8 @@
27 27
 #ifndef SCA_H
28 28
 #define SCA_H
29 29
 
30
-struct _sca_config {
30
+struct _sca_config
31
+{
31 32
 	str *outbound_proxy;
32 33
 	str *db_url;
33 34
 	str *subs_table;
... ...
@@ -42,7 +43,8 @@ struct _sca_config {
42 43
 };
43 44
 typedef struct _sca_config sca_config;
44 45
 
45
-struct _sca_mod {
46
+struct _sca_mod
47
+{
46 48
 	sca_config *cfg;
47 49
 	sca_hash_table *subscriptions;
48 50
 	sca_hash_table *appearances;
... ...
@@ -37,7 +37,8 @@ const str SCA_APPEARANCE_STATE_STR_PROGRESSING = STR_STATIC_INIT("progressing");
37 37
 const str SCA_APPEARANCE_STATE_STR_ALERTING = STR_STATIC_INIT("alerting");
38 38
 const str SCA_APPEARANCE_STATE_STR_ACTIVE = STR_STATIC_INIT("active");
39 39
 const str SCA_APPEARANCE_STATE_STR_HELD = STR_STATIC_INIT("held");
40
-const str SCA_APPEARANCE_STATE_STR_HELD_PRIVATE = STR_STATIC_INIT("held-private");
40
+const str SCA_APPEARANCE_STATE_STR_HELD_PRIVATE =
41
+		STR_STATIC_INIT("held-private");
41 42
 const str SCA_APPEARANCE_STATE_STR_UNKNOWN = STR_STATIC_INIT("unknown");
42 43
 
43 44
 // STR_ACTIVE is repeated, once for ACTIVE_PENDING, once for ACTIVE
... ...
@@ -59,7 +60,7 @@ void sca_appearance_state_to_str(int state, str *state_str)
59 60
 {
60 61
 	assert(state_str != NULL);
61 62
 
62
-	if (state >= SCA_APPEARANCE_STATE_NAME_COUNT || state < 0) {
63
+	if(state >= SCA_APPEARANCE_STATE_NAME_COUNT || state < 0) {
63 64
 		state_str->len = SCA_APPEARANCE_STATE_STR_UNKNOWN.len;
64 65
 		state_str->s = SCA_APPEARANCE_STATE_STR_UNKNOWN.s;
65 66
 
... ...
@@ -76,12 +77,12 @@ int sca_appearance_state_from_str(str *state_str)
76 77
 
77 78
 	assert(state_str != NULL);
78 79
 
79
-	for (state = 0; state < SCA_APPEARANCE_STATE_NAME_COUNT; state++) {
80
-		if (SCA_STR_EQ(state_str, state_names[state])) {
80
+	for(state = 0; state < SCA_APPEARANCE_STATE_NAME_COUNT; state++) {
81
+		if(SCA_STR_EQ(state_str, state_names[state])) {
81 82
 			break;
82 83
 		}
83 84
 	}
84
-	if (state >= SCA_APPEARANCE_STATE_NAME_COUNT) {
85
+	if(state >= SCA_APPEARANCE_STATE_NAME_COUNT) {
85 86
 		state = SCA_APPEARANCE_STATE_UNKNOWN;
86 87
 	}
87 88
 
... ...
@@ -95,16 +96,16 @@ sca_appearance *sca_appearance_create(int appearance_index, str *owner_uri)
95 96
 	// we use multiple shm_malloc calls here because uri, owner,
96 97
 	// dialog and callee are mutable. could also shm_malloc a big
97 98
 	// block and divide it among the strs....
98
-	new_appearance = (sca_appearance *) shm_malloc(sizeof(sca_appearance));
99
-	if (new_appearance == NULL) {
99
+	new_appearance = (sca_appearance *)shm_malloc(sizeof(sca_appearance));
100
+	if(new_appearance == NULL) {
100 101
 		LM_ERR("Failed to shm_malloc new sca_appearance for %.*s, index %d\n",
101 102
 				STR_FMT(owner_uri), appearance_index);
102 103
 		goto error;
103 104
 	}
104 105
 	memset(new_appearance, 0, sizeof(sca_appearance));
105 106
 
106
-	new_appearance->owner.s = (char *) shm_malloc(owner_uri->len);
107
-	if (new_appearance->owner.s == NULL) {
107
+	new_appearance->owner.s = (char *)shm_malloc(owner_uri->len);
108
+	if(new_appearance->owner.s == NULL) {
108 109
 		LM_ERR("Failed to shm_malloc space for owner %.*s, index %d\n",
109 110
 				STR_FMT(owner_uri), appearance_index);
110 111
 		goto error;
... ...
@@ -113,14 +114,15 @@ sca_appearance *sca_appearance_create(int appearance_index, str *owner_uri)
113 114
 
114 115
 	new_appearance->index = appearance_index;
115 116
 	new_appearance->times.ctime = time(NULL);
116
-	sca_appearance_update_state_unsafe(new_appearance,
117
-			SCA_APPEARANCE_STATE_IDLE);
117
+	sca_appearance_update_state_unsafe(
118
+			new_appearance, SCA_APPEARANCE_STATE_IDLE);
118 119
 	new_appearance->next = NULL;
119 120
 
120 121
 	return (new_appearance);
121 122
 
122
-	error: if (new_appearance != NULL) {
123
-		if (!SCA_STR_EMPTY(&new_appearance->owner)) {
123
+error:
124
+	if(new_appearance != NULL) {
125
+		if(!SCA_STR_EMPTY(&new_appearance->owner)) {
124 126
 			shm_free(new_appearance->owner.s);
125 127
 		}
126 128
 		shm_free(new_appearance);
... ...
@@ -130,24 +132,24 @@ sca_appearance *sca_appearance_create(int appearance_index, str *owner_uri)
130 132
 
131 133
 void sca_appearance_free(sca_appearance *appearance)
132 134
 {
133
-	if (appearance != NULL) {
134
-		if (appearance->owner.s != NULL) {
135
+	if(appearance != NULL) {
136
+		if(appearance->owner.s != NULL) {
135 137
 			shm_free(appearance->owner.s);
136 138
 		}
137
-		if (appearance->uri.s != NULL) {
139
+		if(appearance->uri.s != NULL) {
138 140
 			shm_free(appearance->uri.s);
139 141
 		}
140
-		if (appearance->dialog.id.s != NULL) {
142
+		if(appearance->dialog.id.s != NULL) {
141 143
 			shm_free(appearance->dialog.id.s);
142 144
 		}
143 145
 
144
-		if (appearance->prev_owner.s != NULL) {
146
+		if(appearance->prev_owner.s != NULL) {
145 147
 			shm_free(appearance->prev_owner.s);
146 148
 		}
147
-		if (appearance->prev_callee.s != NULL) {
149
+		if(appearance->prev_callee.s != NULL) {
148 150
 			shm_free(appearance->prev_callee.s);
149 151
 		}
150
-		if (appearance->prev_dialog.id.s != NULL) {
152
+		if(appearance->prev_dialog.id.s != NULL) {
151 153
 			shm_free(appearance->prev_dialog.id.s);
152 154
 		}
153 155
 		shm_free(appearance);
... ...
@@ -170,9 +172,9 @@ static int sca_appearance_list_next_available_index_unsafe(
170 172
 
171 173
 	assert(app_list != NULL);
172 174
 
173
-	for (app_cur = app_list->appearances; app_cur != NULL;
175
+	for(app_cur = app_list->appearances; app_cur != NULL;
174 176
 			app_cur = app_cur->next, idx++) {
175
-		if (idx < app_cur->index) {
177
+		if(idx < app_cur->index) {
176 178
 			break;
177 179
 		}
178 180
 	}
... ...
@@ -186,15 +188,15 @@ static sca_appearance_list *sca_appearance_list_create(sca_mod *scam, str *aor)
186 188
 	int len;
187 189
 
188 190
 	len = sizeof(sca_appearance_list) + aor->len;
189
-	app_list = (sca_appearance_list *) shm_malloc(len);
190
-	if (app_list == NULL) {
191
+	app_list = (sca_appearance_list *)shm_malloc(len);
192
+	if(app_list == NULL) {
191 193
 		LM_ERR("Failed to shm_malloc sca_appearance_list for %.*s\n",
192 194
 				STR_FMT(aor));
193 195
 		return (NULL);
194 196
 	}
195 197
 	memset(app_list, 0, sizeof(sca_appearance_list));
196 198
 	len = sizeof(sca_appearance_list);
197
-	app_list->aor.s = (char *) app_list + len;
199
+	app_list->aor.s = (char *)app_list + len;
198 200
 	SCA_STR_COPY(&app_list->aor, aor);
199 201
 
200 202
 	return (app_list);
... ...
@@ -206,8 +208,8 @@ sca_appearance_list *sca_appearance_list_for_line(sca_mod *scam, str *aor)
206 208
 	return (NULL);
207 209
 }
208 210
 
209
-void sca_appearance_list_insert_appearance(sca_appearance_list *app_list,
210
-		sca_appearance *app)
211
+void sca_appearance_list_insert_appearance(
212
+		sca_appearance_list *app_list, sca_appearance *app)
211 213
 {
212 214
 	sca_appearance **cur;
213 215
 
... ...
@@ -216,8 +218,8 @@ void sca_appearance_list_insert_appearance(sca_appearance_list *app_list,
216 218
 
217 219
 	app->appearance_list = app_list;
218 220
 
219
-	for (cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) {
220
-		if (app->index < (*cur)->index) {
221
+	for(cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) {
222
+		if(app->index < (*cur)->index) {
221 223
 			break;
222 224
 		}
223 225
 	}
... ...
@@ -225,8 +227,8 @@ void sca_appearance_list_insert_appearance(sca_appearance_list *app_list,
225 227
 	*cur = app;
226 228
 }
227 229
 
228
-sca_appearance *sca_appearance_list_unlink_index(sca_appearance_list *app_list,
229
-		int idx)
230
+sca_appearance *sca_appearance_list_unlink_index(
231
+		sca_appearance_list *app_list, int idx)
230 232
 {
231 233
 	sca_appearance *app = NULL;
232 234
 	sca_appearance **cur;
... ...
@@ -234,8 +236,8 @@ sca_appearance *sca_appearance_list_unlink_index(sca_appearance_list *app_list,
234 236
 	assert(app_list != NULL);
235 237
 	assert(idx > 0);
236 238
 
237
-	for (cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) {
238
-		if ((*cur)->index == idx) {
239
+	for(cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) {
240
+		if((*cur)->index == idx) {
239 241
 			app = *cur;
240 242
 			app->appearance_list = NULL;
241 243
 			*cur = (*cur)->next;
... ...
@@ -243,15 +245,15 @@ sca_appearance *sca_appearance_list_unlink_index(sca_appearance_list *app_list,
243 245
 		}
244 246
 	}
245 247
 
246
-	if (app == NULL) {
248
+	if(app == NULL) {
247 249
 		LM_ERR("Tried to remove inactive %.*s appearance at index %d\n",
248 250
 				STR_FMT(&app_list->aor), idx);
249 251
 	}
250 252
 	return (app);
251 253
 }
252 254
 
253
-int sca_appearance_list_unlink_appearance(sca_appearance_list *app_list,
254
-		sca_appearance **app)
255
+int sca_appearance_list_unlink_appearance(
256
+		sca_appearance_list *app_list, sca_appearance **app)
255 257
 {
256 258
 	sca_appearance **cur;
257 259
 	int rc = 0;
... ...
@@ -259,8 +261,8 @@ int sca_appearance_list_unlink_appearance(sca_appearance_list *app_list,
259 261
 	assert(app_list != NULL);
260 262
 	assert(app != NULL && *app != NULL);
261 263
 
262
-	for (cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) {
263
-		if (*cur == *app) {
264
+	for(cur = &app_list->appearances; *cur != NULL; cur = &(*cur)->next) {
265
+		if(*cur == *app) {
264 266
 			*cur = (*cur)->next;
265 267
 			(*app)->appearance_list = NULL;
266 268
 			(*app)->next = NULL;
... ...
@@ -272,44 +274,45 @@ int sca_appearance_list_unlink_appearance(sca_appearance_list *app_list,
272 274
 	return (rc);
273 275
 }
274 276
 
275
-int sca_appearance_list_aor_cmp(str *aor, void *cmp_value) {
276
-	sca_appearance_list *app_list = (sca_appearance_list *) cmp_value;
277
+int sca_appearance_list_aor_cmp(str *aor, void *cmp_value)
278
+{
279
+	sca_appearance_list *app_list = (sca_appearance_list *)cmp_value;
277 280
 	int cmp;
278 281
 
279
-	if ((cmp = aor->len - app_list->aor.len) != 0) {
282
+	if((cmp = aor->len - app_list->aor.len) != 0) {
280 283
 		return (cmp);
281 284
 	}
282 285
 
283 286
 	return (memcmp(aor->s, app_list->aor.s, aor->len));
284 287
 }
285 288
 
286
-void sca_appearance_list_print(void *value) {
287
-	sca_appearance_list *app_list = (sca_appearance_list *) value;
289
+void sca_appearance_list_print(void *value)
290
+{
291
+	sca_appearance_list *app_list = (sca_appearance_list *)value;
288 292
 	sca_appearance *app;
289 293
 	str state_str = STR_NULL;
290 294
 
291 295
 	LM_INFO("Appearance state for AoR %.*s:\n", STR_FMT(&app_list->aor));
292 296
 
293
-	for (app = app_list->appearances; app != NULL; app = app->next) {
297
+	for(app = app_list->appearances; app != NULL; app = app->next) {
294 298
 		sca_appearance_state_to_str(app->state, &state_str);
295 299
 		LM_INFO("index: %d, state: %.*s, uri: %.*s, owner: %.*s, "
296 300
 				"callee: %.*s, dialog: %.*s;%.*s;%.*s\n",
297
-				app->index, STR_FMT(&state_str),
298
-				STR_FMT(&app->uri), STR_FMT(&app->owner),
299
-				STR_FMT(&app->callee), STR_FMT(&app->dialog.call_id),
300
-				STR_FMT(&app->dialog.from_tag),
301
+				app->index, STR_FMT(&state_str), STR_FMT(&app->uri),
302
+				STR_FMT(&app->owner), STR_FMT(&app->callee),
303
+				STR_FMT(&app->dialog.call_id), STR_FMT(&app->dialog.from_tag),
301 304
 				STR_FMT(&app->dialog.to_tag));
302 305
 	}
303 306
 }
304 307
 
305 308
 void sca_appearance_list_free(void *value)
306 309
 {
307
-	sca_appearance_list *app_list = (sca_appearance_list *) value;
310
+	sca_appearance_list *app_list = (sca_appearance_list *)value;
308 311
 	sca_appearance *app, *app_tmp;
309 312
 
310 313
 	LM_DBG("Freeing appearance list for AoR %.*s\n", STR_FMT(&app_list->aor));
311 314
 
312
-	for (app = app_list->appearances; app != NULL; app = app_tmp) {
315
+	for(app = app_list->appearances; app != NULL; app = app_tmp) {
313 316
 		app_tmp = app->next;
314 317
 		shm_free(app);
315 318
 	}
... ...
@@ -324,28 +327,31 @@ int sca_appearance_register(sca_mod *scam, str *aor)
324 327
 	assert(scam != NULL);
325 328
 	assert(aor != NULL);
326 329
 
327
-	if (sca_uri_is_shared_appearance(scam, aor)) {
330
+	if(sca_uri_is_shared_appearance(scam, aor)) {
328 331
 		// we've already registered
329 332
 		rc = 0;
330 333
 		goto done;
331 334
 	}
332 335
 
333 336
 	app_list = sca_appearance_list_create(scam, aor);
334
-	if (app_list == NULL) {
337
+	if(app_list == NULL) {
335 338
 		goto done;
336 339
 	}
337 340
 
338
-	if (sca_hash_table_kv_insert(scam->appearances, aor, app_list,
339
-			sca_appearance_list_aor_cmp, sca_appearance_list_print,
340
-			sca_appearance_list_free) < 0) {
341
+	if(sca_hash_table_kv_insert(scam->appearances, aor, app_list,
342
+			   sca_appearance_list_aor_cmp, sca_appearance_list_print,
343
+			   sca_appearance_list_free)
344
+			< 0) {
341 345
 		LM_ERR("sca_appearance_register: failed to insert appearance list "
342
-				"for %.*s\n", STR_FMT(aor));
346
+			   "for %.*s\n",
347
+				STR_FMT(aor));
343 348
 		goto done;
344 349
 	}
345 350
 
346 351
 	rc = 1;
347 352
 
348
-	done: return (rc);
353
+done:
354
+	return (rc);
349 355
 }
350 356
 
351 357
 int sca_appearance_unregister(sca_mod *scam, str *aor)
... ...
@@ -355,8 +361,8 @@ int sca_appearance_unregister(sca_mod *scam, str *aor)
355 361
 	assert(scam != NULL);
356 362
 	assert(aor != NULL);
357 363
 
358
-	if (sca_uri_is_shared_appearance(scam, aor)) {
359
-		if ((rc = sca_hash_table_kv_delete(scam->appearances, aor)) == 0) {
364
+	if(sca_uri_is_shared_appearance(scam, aor)) {
365
+		if((rc = sca_hash_table_kv_delete(scam->appearances, aor)) == 0) {
360 366
 			rc = 1;
361 367
 			LM_INFO("unregistered SCA AoR %.*s\n", STR_FMT(aor));
362 368
 		}
... ...
@@ -376,22 +382,23 @@ sca_appearance *sca_appearance_seize_index_unsafe(sca_mod *scam, str *aor,
376 382
 	slot = sca_hash_table_slot_for_index(scam->appearances, slot_idx);
377 383
 
378 384
 	app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor);
379
-	if (app_list == NULL) {
385
+	if(app_list == NULL) {
380 386
 		LM_ERR("sca_appearance_seize_index_unsafe: no appearance list for "
381
-				"%.*s\n", STR_FMT(aor));
387
+			   "%.*s\n",
388
+				STR_FMT(aor));
382 389
 		goto done;
383 390
 	}
384 391
 
385
-	if (app_idx <= 0) {
392
+	if(app_idx <= 0) {
386 393
 		app_idx = sca_appearance_list_next_available_index_unsafe(app_list);
387 394
 	}
388 395
 
389
-	for (app = app_list->appearances; app != NULL; app = app->next) {
390
-		if (app->index >= app_idx) {
396
+	for(app = app_list->appearances; app != NULL; app = app->next) {
397
+		if(app->index >= app_idx) {
391 398
 			break;
392 399
 		}
393 400
 	}
394
-	if (app != NULL && app->index == app_idx) {
401
+	if(app != NULL && app->index == app_idx) {
395 402
 		// attempt to seize in-use appearance-index
396 403
 		error = SCA_APPEARANCE_ERR_INDEX_UNAVAILABLE;
397 404
 		app = NULL;
... ...
@@ -399,7 +406,7 @@ sca_appearance *sca_appearance_seize_index_unsafe(sca_mod *scam, str *aor,
399 406
 	}
400 407
 
401 408
 	app = sca_appearance_create(app_idx, owner_uri);
402
-	if (app == NULL) {
409
+	if(app == NULL) {
403 410
 		LM_ERR("Failed to create new appearance for %.*s at index %d\n",
404 411
 				STR_FMT(owner_uri), app_idx);
405 412
 		error = SCA_APPEARANCE_ERR_MALLOC;
... ...
@@ -409,14 +416,16 @@ sca_appearance *sca_appearance_seize_index_unsafe(sca_mod *scam, str *aor,
409 416
 	sca_appearance_list_insert_appearance(app_list, app);
410 417
 	error = SCA_APPEARANCE_OK;
411 418
 
412
-	done: if (seize_error) {
419
+done:
420
+	if(seize_error) {
413 421
 		*seize_error = error;
414 422
 	}
415 423
 
416 424
 	return (app);
417 425
 }
418 426
 
419
-int sca_appearance_seize_index(sca_mod *scam, str *aor, int idx, str *owner_uri) {
427
+int sca_appearance_seize_index(sca_mod *scam, str *aor, int idx, str *owner_uri)
428
+{
420 429
 	sca_appearance *app;
421 430
 	int slot_idx;
422 431
 	int app_idx = -1;
... ...
@@ -425,23 +434,23 @@ int sca_appearance_seize_index(sca_mod *scam, str *aor, int idx, str *owner_uri)
425 434
 	slot_idx = sca_hash_table_index_for_key(scam->appearances, aor);
426 435
 	sca_hash_table_lock_index(scam->appearances, slot_idx);
427 436
 
428
-	app = sca_appearance_seize_index_unsafe(scam, aor, owner_uri, idx, slot_idx,
429
-			&error);
430
-	if (app != NULL) {
437
+	app = sca_appearance_seize_index_unsafe(
438
+			scam, aor, owner_uri, idx, slot_idx, &error);
439
+	if(app != NULL) {
431 440
 		app_idx = app->index;
432 441
 	}
433 442
 
434 443
 	sca_hash_table_unlock_index(scam->appearances, slot_idx);
435 444
 
436
-	if (error == SCA_APPEARANCE_ERR_INDEX_UNAVAILABLE) {
445
+	if(error == SCA_APPEARANCE_ERR_INDEX_UNAVAILABLE) {
437 446
 		app_idx = SCA_APPEARANCE_INDEX_UNAVAILABLE;
438 447
 	}
439 448
 
440 449
 	return (app_idx);
441 450
 }
442 451
 
443
-sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam,
444
-		str *aor, str *owner_uri, int slot_idx)
452
+sca_appearance *sca_appearance_seize_next_available_unsafe(
453
+		sca_mod *scam, str *aor, str *owner_uri, int slot_idx)
445 454
 {
446 455
 	sca_appearance_list *app_list;
447 456
 	sca_appearance *app = NULL;
... ...
@@ -451,17 +460,17 @@ sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam,
451 460
 	slot = sca_hash_table_slot_for_index(scam->appearances, slot_idx);
452 461
 
453 462
 	app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor);
454
-	if (app_list == NULL) {
463
+	if(app_list == NULL) {
455 464
 		app_list = sca_appearance_list_create(scam, aor);
456
-		if (app_list == NULL) {
465
+		if(app_list == NULL) {
457 466
 			goto done;
458 467
 		}
459 468
 
460
-		if (sca_hash_table_slot_kv_insert_unsafe(slot, app_list,
461
-				sca_appearance_list_aor_cmp, sca_appearance_list_print,
462
-				sca_appearance_list_free) < 0) {
463
-			LM_ERR("Failed to insert appearance list for %.*s\n",
464
-					STR_FMT(aor));
469
+		if(sca_hash_table_slot_kv_insert_unsafe(slot, app_list,
470
+				   sca_appearance_list_aor_cmp, sca_appearance_list_print,
471
+				   sca_appearance_list_free)
472
+				< 0) {
473
+			LM_ERR("Failed to insert appearance list for %.*s\n", STR_FMT(aor));
465 474
 			goto done;
466 475
 		}
467 476
 	}
... ...
@@ -471,7 +480,7 @@ sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam,
471 480
 	// XXX check idx > any configured max appearance index
472 481
 
473 482
 	app = sca_appearance_create(idx, owner_uri);
474
-	if (app == NULL) {
483
+	if(app == NULL) {
475 484
 		LM_ERR("Failed to create new appearance for %.*s at index %d\n",
476 485
 				STR_FMT(owner_uri), idx);
477 486
 		goto done;
... ...
@@ -480,11 +489,12 @@ sca_appearance *sca_appearance_seize_next_available_unsafe(sca_mod *scam,
480 489
 
481 490
 	sca_appearance_list_insert_appearance(app_list, app);
482 491
 
483
-	done: return (app);
492
+done:
493
+	return (app);
484 494
 }
485 495
 
486
-int sca_appearance_seize_next_available_index(sca_mod *scam, str *aor,
487
-		str *owner_uri)
496
+int sca_appearance_seize_next_available_index(
497
+		sca_mod *scam, str *aor, str *owner_uri)
488 498
 {
489 499
 	sca_appearance *app;
490 500
 	int slot_idx;
... ...
@@ -493,9 +503,9 @@ int sca_appearance_seize_next_available_index(sca_mod *scam, str *aor,
493 503
 	slot_idx = sca_hash_table_index_for_key(scam->appearances, aor);
494 504
 	sca_hash_table_lock_index(scam->appearances, slot_idx);
495 505
 
496
-	app = sca_appearance_seize_next_available_unsafe(scam, aor, owner_uri,
497
-			slot_idx);
498
-	if (app != NULL) {
506
+	app = sca_appearance_seize_next_available_unsafe(
507
+			scam, aor, owner_uri, slot_idx);
508
+	if(app != NULL) {
499 509
 		idx = app->index;
500 510
 	}
501 511
 
... ...
@@ -517,25 +527,26 @@ int sca_appearance_update_owner_unsafe(sca_appearance *app, str *owner)
517 527
 	assert(app != NULL);
518 528
 	assert(owner != NULL);
519 529
 
520
-	if (!SCA_STR_EMPTY(&app->owner)) {
521
-		if (app->prev_owner.s != NULL) {
530
+	if(!SCA_STR_EMPTY(&app->owner)) {
531
+		if(app->prev_owner.s != NULL) {
522 532
 			shm_free(app->prev_owner.s);
523 533
 		}
524 534
 		app->prev_owner.s = app->owner.s;
525 535
 		app->prev_owner.len = app->owner.len;
526 536
 	}
527 537
 
528
-	app->owner.s = (char *) shm_malloc(owner->len);
529
-	if (app->owner.s == NULL) {
538
+	app->owner.s = (char *)shm_malloc(owner->len);
539
+	if(app->owner.s == NULL) {
530 540
 		LM_ERR("sca_appearance_update_owner_unsafe: shm_malloc for new "
531
-				"owner %.*s failed: out of memory\n", STR_FMT(owner));
541
+			   "owner %.*s failed: out of memory\n",
542
+				STR_FMT(owner));
532 543
 		goto error;
533 544
 	}
534 545
 	SCA_STR_COPY(&app->owner, owner);
535 546
 
536 547
 	return (1);
537 548
 
538
-	error:
549
+error:
539 550
 	// restore owner
540 551
 	app->owner.s = app->prev_owner.s;
541 552
 	app->owner.len = app->prev_owner.len;
... ...
@@ -549,25 +560,26 @@ int sca_appearance_update_callee_unsafe(sca_appearance *app, str *callee)
549 560
 	assert(app != NULL);
550 561
 	assert(callee != NULL);
551 562
 
552
-	if (!SCA_STR_EMPTY(&app->callee)) {
553
-		if (app->prev_callee.s != NULL) {
563
+	if(!SCA_STR_EMPTY(&app->callee)) {
564
+		if(app->prev_callee.s != NULL) {
554 565
 			shm_free(app->prev_callee.s);
555 566
 		}
556 567
 		app->prev_callee.s = app->callee.s;
557 568
 		app->prev_callee.len = app->callee.len;
558 569
 	}
559 570
 
560
-	app->callee.s = (char *) shm_malloc(callee->len);
561
-	if (app->callee.s == NULL) {
571
+	app->callee.s = (char *)shm_malloc(callee->len);
572
+	if(app->callee.s == NULL) {
562 573
 		LM_ERR("sca_appearance_update_owner_unsafe: shm_malloc for new "
563
-				"callee %.*s failed: out of memory\n", STR_FMT(callee));
574
+			   "callee %.*s failed: out of memory\n",
575
+				STR_FMT(callee));
564 576
 		goto error;
565 577
 	}
566 578
 	SCA_STR_COPY(&app->callee, callee);
567 579
 
568 580
 	return (1);
569 581
 
570
-	error:
582
+error:
571 583
 	// restore callee
572 584
 	app->callee.s = app->prev_callee.s;
573 585
 	app->callee.len = app->prev_callee.len;
... ...
@@ -575,8 +587,8 @@ int sca_appearance_update_callee_unsafe(sca_appearance *app, str *callee)
575 587
 
576 588
 	return (-1);
577 589
 }
578
-int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id,
579
-		str *from_tag, str *to_tag)
590
+int sca_appearance_update_dialog_unsafe(
591
+		sca_appearance *app, str *call_id, str *from_tag, str *to_tag)
580 592
 {
581 593
 	int len;
582 594
 
... ...
@@ -584,8 +596,8 @@ int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id,
584 596
 	assert(call_id != NULL);
585 597
 	assert(from_tag != NULL);
586 598
 
587
-	if (!SCA_STR_EMPTY(&app->dialog.id)) {
588
-		if (app->prev_dialog.id.s != NULL) {
599
+	if(!SCA_STR_EMPTY(&app->dialog.id)) {
600
+		if(app->prev_dialog.id.s != NULL) {
589 601
 			shm_free(app->prev_dialog.id.s);
590 602
 		}
591 603
 		app->prev_dialog.id.s = app->dialog.id.s;
... ...
@@ -602,14 +614,14 @@ int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id,
602 614
 	}
603 615
 
604 616
 	len = call_id->len + from_tag->len;
605
-	if (!SCA_STR_EMPTY(to_tag)) {
617
+	if(!SCA_STR_EMPTY(to_tag)) {
606 618
 		len += to_tag->len;
607 619
 	}
608 620
 
609
-	app->dialog.id.s = (char *) shm_malloc(len);
610
-	if (app->dialog.id.s == NULL) {
621
+	app->dialog.id.s = (char *)shm_malloc(len);
622
+	if(app->dialog.id.s == NULL) {
611 623
 		LM_ERR("sca_appearance_update_dialog_unsafe: shm_malloc new dialog "
612
-				"failed: out of memory\n");
624
+			   "failed: out of memory\n");
613 625
 		goto error;
614 626
 	}
615 627
 	SCA_STR_COPY(&app->dialog.id, call_id);
... ...
@@ -626,7 +638,7 @@ int sca_appearance_update_dialog_unsafe(sca_appearance *app, str *call_id,
626 638
 
627 639
 	return (1);
628 640
 
629
-	error:
641
+error:
630 642
 	// restore dialog
631 643
 	app->prev_dialog.id.s = app->dialog.id.s;
632 644
 	app->prev_dialog.id.len = app->dialog.id.len;
... ...
@@ -651,12 +663,12 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display,
651 663
 	int rc = SCA_APPEARANCE_OK;
652 664
 	int len;
653 665
 
654
-	if (state != SCA_APPEARANCE_STATE_UNKNOWN) {
666
+	if(state != SCA_APPEARANCE_STATE_UNKNOWN) {
655 667
 		sca_appearance_update_state_unsafe(app, state);
656 668
 	}
657 669
 
658
-	if (!SCA_STR_EMPTY(uri)) {
659
-		if (!SCA_STR_EMPTY(&app->uri)) {
670
+	if(!SCA_STR_EMPTY(uri)) {
671
+		if(!SCA_STR_EMPTY(&app->uri)) {
660 672
 			// the uri str's s member is shm_malloc'd separately
661 673
 			shm_free(app->uri.s);
662 674
 			memset(&app->uri, 0, sizeof(str));
... ...
@@ -664,20 +676,20 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display,
664 676
 
665 677
 		// +2 for left & right carets surrounding URI
666 678
 		len = uri->len + 2;
667
-		if (!SCA_STR_EMPTY(display)) {
679
+		if(!SCA_STR_EMPTY(display)) {
668 680
 			// cheaper to scan string than shm_malloc 2x display?
669 681
 			len += sca_uri_display_escapes_count(display);
670 682
 			// +1 for space between display & uri
671 683
 			len += display->len + 1;
672 684
 		}
673
-		app->uri.s = (char *) shm_malloc(len);
674
-		if (app->uri.s == NULL) {
685
+		app->uri.s = (char *)shm_malloc(len);
686
+		if(app->uri.s == NULL) {
675 687
 			LM_ERR("shm_malloc %d bytes returned NULL\n", uri->len);
676 688
 			rc = SCA_APPEARANCE_ERR_MALLOC;
677 689
 			goto done;
678 690
 		}
679 691
 
680
-		if (!SCA_STR_EMPTY(display)) {
692
+		if(!SCA_STR_EMPTY(display)) {
681 693
 			// copy escaped display information...
682 694
 			app->uri.len = escape_common(app->uri.s, display->s, display->len);
683 695
 
... ...
@@ -695,16 +707,16 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display,
695 707
 		app->uri.len++;
696 708
 	}
697 709
 
698
-	if (!SCA_DIALOG_EMPTY(dialog)) {
699
-		if (!SCA_STR_EQ(&dialog->id, &app->dialog.id)) {
700
-			if (app->dialog.id.s != NULL) {
710
+	if(!SCA_DIALOG_EMPTY(dialog)) {
711
+		if(!SCA_STR_EQ(&dialog->id, &app->dialog.id)) {
712
+			if(app->dialog.id.s != NULL) {
701 713
 				shm_free(app->dialog.id.s);
702 714
 			}
703 715
 
704
-			app->dialog.id.s = (char *) shm_malloc(dialog->id.len);
705
-			if (app->dialog.id.s == NULL) {
716
+			app->dialog.id.s = (char *)shm_malloc(dialog->id.len);
717
+			if(app->dialog.id.s == NULL) {
706 718
 				LM_ERR("sca_appearance_update_unsafe: shm_malloc dialog id "
707
-						"failed: out of shared memory\n");
719
+					   "failed: out of shared memory\n");
708 720
 				// XXX this seems bad enough to abort...
709 721
 				return (-1);
710 722
 			}
... ...
@@ -716,9 +728,9 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display,
716 728
 			app->dialog.from_tag.s = app->dialog.id.s + dialog->call_id.len;
717 729
 			app->dialog.from_tag.len = dialog->from_tag.len;
718 730
 
719
-			if (!SCA_STR_EMPTY(&dialog->to_tag)) {
731
+			if(!SCA_STR_EMPTY(&dialog->to_tag)) {
720 732
 				app->dialog.to_tag.s = app->dialog.id.s + dialog->call_id.len
721
-						+ dialog->from_tag.len;
733
+									   + dialog->from_tag.len;
722 734
 				app->dialog.to_tag.len = dialog->to_tag.len;
723 735
 			} else {
724 736
 				app->dialog.to_tag.s = NULL;
... ...
@@ -728,39 +740,40 @@ int sca_appearance_update_unsafe(sca_appearance *app, int state, str *display,
728 740
 	}
729 741
 
730 742
 	// NOTE these two blocks could be condensed and inlined
731
-	if (!SCA_STR_EMPTY(owner)) {
732
-		if (!SCA_STR_EQ(&app->owner, owner)) {
733
-			if (app->owner.s != NULL) {
743
+	if(!SCA_STR_EMPTY(owner)) {
744
+		if(!SCA_STR_EQ(&app->owner, owner)) {
745
+			if(app->owner.s != NULL) {
734 746
 				shm_free(app->owner.s);
735 747
 			}
736 748
 
737
-			app->owner.s = (char *) shm_malloc(owner->len);
738
-			if (app->owner.s == NULL) {
749
+			app->owner.s = (char *)shm_malloc(owner->len);
750
+			if(app->owner.s == NULL) {
739 751
 				LM_ERR("sca_appearance_update_unsafe: shm_malloc "
740
-						"appearance owner URI failed: out of shared memory\n");
752
+					   "appearance owner URI failed: out of shared memory\n");
741 753
 				return (-1);
742 754
 			}
743 755
 			SCA_STR_COPY(&app->owner, owner);
744 756
 		}
745 757
 	}
746 758
 
747
-	if (!SCA_STR_EMPTY(callee)) {
748
-		if (!SCA_STR_EQ(&app->callee, callee)) {
749
-			if (app->callee.s != NULL) {
759
+	if(!SCA_STR_EMPTY(callee)) {
760
+		if(!SCA_STR_EQ(&app->callee, callee)) {
761
+			if(app->callee.s != NULL) {
750 762
 				shm_free(app->callee.s);
751 763
 			}
752 764
 
753
-			app->callee.s = (char *) shm_malloc(callee->len);
754
-			if (app->callee.s == NULL) {
765
+			app->callee.s = (char *)shm_malloc(callee->len);
766
+			if(app->callee.s == NULL) {
755 767
 				LM_ERR("sca_appearance_update_unsafe: shm_malloc "
756
-						"appearance callee URI failed: out of shared memory\n");
768
+					   "appearance callee URI failed: out of shared memory\n");
757 769
 				return (-1);
758 770
 			}
759 771
 			SCA_STR_COPY(&app->callee, callee);
760 772
 		}
761 773
 	}
762 774
 
763
-	done: return (rc);
775
+done:
776
+	return (rc);
764 777
 }
765 778
 
766 779
 int sca_uri_is_shared_appearance(sca_mod *scam, str *aor)
... ...
@@ -776,7 +789,7 @@ int sca_uri_is_shared_appearance(sca_mod *scam, str *aor)
776 789
 	app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor);
777 790
 	sca_hash_table_unlock_index(scam->appearances, slot_idx);
778 791
 
779
-	if (app_list == NULL) {
792
+	if(app_list == NULL) {
780 793
 		return (0);
781 794
 	}
782 795
 
... ...
@@ -789,7 +802,7 @@ int sca_uri_lock_shared_appearance(sca_mod *scam, str *aor)
789 802
 	sca_appearance_list *app_list;
790 803
 	int slot_idx;
791 804
 
792
-	if (SCA_STR_EMPTY(aor)) {
805
+	if(SCA_STR_EMPTY(aor)) {
793 806
 		return (-1);
794 807
 	}
795 808
 
... ...
@@ -799,7 +812,7 @@ int sca_uri_lock_shared_appearance(sca_mod *scam, str *aor)
799 812
 	sca_hash_table_lock_index(scam->appearances, slot_idx);
800 813
 	app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor);
801 814
 
802
-	if (app_list == NULL) {
815
+	if(app_list == NULL) {
803 816
 		sca_hash_table_unlock_index(scam->appearances, slot_idx);
804 817
 		slot_idx = -1;
805 818
 	}
... ...
@@ -814,7 +827,7 @@ int sca_uri_lock_if_shared_appearance(sca_mod *scam, str *aor, int *slot_idx)
814 827
 
815 828
 	assert(slot_idx != NULL);
816 829
 
817
-	if (SCA_STR_EMPTY(aor)) {
830
+	if(SCA_STR_EMPTY(aor)) {
818 831
 		*slot_idx = -1;
819 832
 		return (0);
820 833
 	}
... ...
@@ -825,7 +838,7 @@ int sca_uri_lock_if_shared_appearance(sca_mod *scam, str *aor, int *slot_idx)
825 838
 	sca_hash_table_lock_index(scam->appearances, *slot_idx);
826 839
 	app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor);
827 840
 
828
-	if (app_list == NULL) {
841
+	if(app_list == NULL) {
829 842
 		sca_hash_table_unlock_index(scam->appearances, *slot_idx);
830 843
 		*slot_idx = -1;
831 844
 
... ...
@@ -849,25 +862,24 @@ int sca_appearance_state_for_index(sca_mod *scam, str *aor, int idx)
849 862
 	sca_hash_table_lock_index(scam->appearances, slot_idx);
850 863
 
851 864
 	app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor);
852
-	if (app_list == NULL) {
865
+	if(app_list == NULL) {
853 866
 		LM_DBG("%.*s has no in-use appearances\n", STR_FMT(aor));
854 867
 		goto done;
855 868
 	}
856 869
 
857
-	for (app = app_list->appearances; app != NULL; app = app->next) {
858
-		if (app->index == idx) {
870
+	for(app = app_list->appearances; app != NULL; app = app->next) {
871
+		if(app->index == idx) {
859 872
 			break;
860 873
 		}
861 874
 	}
862
-	if (app == NULL) {
863
-		LM_WARN("%.*s appearance-index %d is not in use\n",
864
-				STR_FMT(aor), idx);
875
+	if(app == NULL) {
876
+		LM_WARN("%.*s appearance-index %d is not in use\n", STR_FMT(aor), idx);
865 877
 		goto done;
866 878
 	}
867 879
 
868 880
 	state = app->state;
869 881
 
870
-	done:
882
+done:
871 883
 	sca_hash_table_unlock_index(scam->appearances, slot_idx);
872 884
 
873 885
 	return (state);
... ...
@@ -892,36 +904,36 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state,
892 904
 	sca_appearance_state_to_str(state, &state_str);
893 905
 
894 906
 	app_list = sca_hash_table_slot_kv_find_unsafe(slot, aor);
895
-	if (app_list == NULL) {
907
+	if(app_list == NULL) {
896 908
 		LM_WARN("Cannot update %.*s index %d to state %.*s: %.*s has no "
897
-				"in-use appearances\n", STR_FMT(aor), idx,
898
-				STR_FMT(&state_str), STR_FMT(aor));
909
+				"in-use appearances\n",
910
+				STR_FMT(aor), idx, STR_FMT(&state_str), STR_FMT(aor));
899 911
 		rc = SCA_APPEARANCE_ERR_NOT_IN_USE;
900 912
 		goto done;
901 913
 	}
902 914
 
903
-	for (app = app_list->appearances; app != NULL; app = app->next) {
904
-		if (app->index == idx) {
915
+	for(app = app_list->appearances; app != NULL; app = app->next) {
916
+		if(app->index == idx) {
905 917
 			break;
906
-		} else if (idx == 0) {
907
-			if (SCA_STR_EQ(&dialog->id, &app->dialog.id)) {
918
+		} else if(idx == 0) {
919
+			if(SCA_STR_EQ(&dialog->id, &app->dialog.id)) {
908 920
 				break;
909 921
 			}
910 922
 		}
911 923
 	}
912
-	if (app == NULL) {
924
+	if(app == NULL) {
913 925
 		LM_WARN("Cannot update %.*s index %d to %.*s: index %d not in use\n",
914 926
 				STR_FMT(aor), idx, STR_FMT(&state_str), idx);
915 927
 		rc = SCA_APPEARANCE_ERR_INDEX_INVALID;
916 928
 		goto done;
917 929
 	}
918 930
 
919
-	if (state != SCA_APPEARANCE_STATE_UNKNOWN && app->state != state) {
931
+	if(state != SCA_APPEARANCE_STATE_UNKNOWN && app->state != state) {
920 932
 		sca_appearance_update_state_unsafe(app, state);
921 933
 	}
922 934
 
923
-	if (!SCA_STR_EMPTY(uri)) {
924
-		if (!SCA_STR_EMPTY(&app->uri)) {
935
+	if(!SCA_STR_EMPTY(uri)) {
936
+		if(!SCA_STR_EMPTY(&app->uri)) {
925 937
 			// the uri str's s member is shm_malloc'd separately
926 938
 			shm_free(app->uri.s);
927 939
 			memset(&app->uri, 0, sizeof(str));
... ...
@@ -929,22 +941,22 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state,
929 941
 
930 942
 		// +2 for left & right carets surrounding URI
931 943
 		len = uri->len + 2;
932
-		if (!SCA_STR_EMPTY(display)) {
944
+		if(!SCA_STR_EMPTY(display)) {
933 945
 			// cheaper to scan string than shm_malloc 2x display?
934 946
 			len += sca_uri_display_escapes_count(display);
935 947
 			// +1 for space between display & uri
936 948
 			len += display->len + 1;
937 949
 		}
938
-		app->uri.s = (char *) shm_malloc(len);
939
-		if (app->uri.s == NULL) {
950
+		app->uri.s = (char *)shm_malloc(len);
951
+		if(app->uri.s == NULL) {
940 952
 			LM_ERR("Failed to update %.*s index %d uri to %.*s: "
941
-					"shm_malloc %d bytes returned NULL\n",
953
+				   "shm_malloc %d bytes returned NULL\n",
942 954
 					STR_FMT(aor), idx, STR_FMT(uri), uri->len);
943 955
 			rc = SCA_APPEARANCE_ERR_MALLOC;
944 956
 			goto done;
945 957
 		}
946 958
 
947
-		if (!SCA_STR_EMPTY(display)) {
959
+		if(!SCA_STR_EMPTY(display)) {
948 960
 			// copy escaped display information...
949 961
 			app->uri.len = escape_common(app->uri.s, display->s, display->len);
950 962
 
... ...
@@ -962,13 +974,13 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state,
962 974
 		app->uri.len++;
963 975
 	}
964 976
 
965
-	if (!SCA_DIALOG_EMPTY(dialog)) {
966
-		if (!SCA_STR_EQ(&dialog->id, &app->dialog.id)) {
967
-			if (app->dialog.id.s != NULL) {
977
+	if(!SCA_DIALOG_EMPTY(dialog)) {
978
+		if(!SCA_STR_EQ(&dialog->id, &app->dialog.id)) {
979
+			if(app->dialog.id.s != NULL) {
968 980
 				shm_free(app->dialog.id.s);
969 981
 			}
970 982
 
971
-			app->dialog.id.s = (char *) shm_malloc(dialog->id.len);
983
+			app->dialog.id.s = (char *)shm_malloc(dialog->id.len);
972 984
 			SCA_STR_COPY(&app->dialog.id, &dialog->id);
973 985
 
974 986
 			app->dialog.call_id.s = app->dialog.id.s;
... ...
@@ -977,9 +989,9 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state,
977 989
 			app->dialog.from_tag.s = app->dialog.id.s + dialog->call_id.len;
978 990
 			app->dialog.from_tag.len = dialog->from_tag.len;
979 991
 
980
-			if (!SCA_STR_EMPTY(&dialog->to_tag)) {
992
+			if(!SCA_STR_EMPTY(&dialog->to_tag)) {
981 993
 				app->dialog.to_tag.s = app->dialog.id.s + dialog->call_id.len
982
-						+ dialog->from_tag.len;
994
+									   + dialog->from_tag.len;
983 995
 				app->dialog.to_tag.len = dialog->to_tag.len;
984 996
 			} else {
985 997
 				app->dialog.to_tag.s = NULL;
... ...
@@ -990,7 +1002,7 @@ int sca_appearance_update_index(sca_mod *scam, str *aor, int idx, int state,
990 1002
 
991 1003
 	rc = SCA_APPEARANCE_OK;
992 1004
 
993
-	done:
1005
+done:
994 1006
 	sca_hash_table_unlock_index(scam->appearances, slot_idx);
995 1007
 
996 1008
 	return (rc);
... ...
@@ -1011,20 +1023,20 @@ int sca_appearance_release_index(sca_mod *scam, str *aor, int idx)
1011 1023
 	sca_hash_table_lock_index(scam->appearances, slot_idx);
1012 1024
 
1013 1025
 	app_list = NULL;
1014
-	for (ent = slot->entries; ent != NULL; ent = ent->next) {
1015
-		if (ent->compare(aor, ent->value) == 0) {
1016
-			app_list = (sca_appearance_list *) ent->value;
1026
+	for(ent = slot->entries; ent != NULL; ent = ent->next) {
1027
+		if(ent->compare(aor, ent->value) == 0) {
1028
+			app_list = (sca_appearance_list *)ent->value;
1017 1029
 			break;
1018 1030
 		}
1019 1031
 	}
1020
-	if (app_list == NULL) {
1032
+	if(app_list == NULL) {
1021 1033
 		LM_ERR("No appearances for %.*s\n", STR_FMT(aor));
1022 1034
 		rc = SCA_APPEARANCE_ERR_NOT_IN_USE;
1023 1035
 		goto done;
1024 1036
 	}
1025 1037
 
1026 1038
 	app = sca_appearance_list_unlink_index(app_list, idx);
1027
-	if (app == NULL) {
1039
+	if(app == NULL) {
1028 1040
 		LM_ERR("Failed to unlink %.*s appearance-index %d: invalid index\n",
1029 1041
 				STR_FMT(aor), idx);
1030 1042
 		rc = SCA_APPEARANCE_ERR_INDEX_INVALID;
... ...
@@ -1034,13 +1046,14 @@ int sca_appearance_release_index(sca_mod *scam, str *aor, int idx)
1034 1046
 
1035 1047
 	rc = SCA_APPEARANCE_OK;
1036 1048
 
1037
-	done:
1049
+done:
1038 1050
 	sca_hash_table_unlock_index(scam->appearances, slot_idx);
1039 1051
 
1040 1052
 	return (rc);
1041 1053
 }
1042 1054
 
1043
-int sca_appearance_owner_release_all(str *aor, str *owner) {
1055
+int sca_appearance_owner_release_all(str *aor, str *owner)
1056
+{
1044 1057
 	sca_appearance_list *app_list = NULL;
1045 1058
 	sca_appearance *app, **cur_app, **tmp_app;
1046 1059
 	sca_hash_slot *slot;
... ...
@@ -1051,26 +1064,25 @@ int sca_appearance_owner_release_all(str *aor, str *owner) {
1051 1064
 	slot_idx = sca_uri_lock_shared_appearance(sca, aor);
1052 1065
 	slot = sca_hash_table_slot_for_index(sca->appearances, slot_idx);
1053 1066
 
1054
-	for (ent = slot->entries; ent != NULL; ent = ent->next) {
1055
-		if (ent->compare(aor, ent->value) == 0) {
1056
-			app_list = (sca_appearance_list *) ent->value;
1067
+	for(ent = slot->entries; ent != NULL; ent = ent->next) {
1068
+		if(ent->compare(aor, ent->value) == 0) {
1069
+			app_list = (sca_appearance_list *)ent->value;
1057 1070
 			break;
1058 1071
 		}
1059 1072
 	}
1060 1073
 
1061 1074
 	released = 0;
1062 1075
 
1063
-	if (app_list == NULL) {
1076
+	if(app_list == NULL) {
1064 1077
 		LM_DBG("sca_appearance_owner_release_all: No appearances for %.*s\n",
1065 1078
 				STR_FMT(aor));
1066 1079
 		goto done;
1067 1080
 	}
1068 1081
 
1069
-	for (cur_app = &app_list->appearances; *cur_app != NULL; cur_app =
1070
-			tmp_app) {
1082
+	for(cur_app = &app_list->appearances; *cur_app != NULL; cur_app = tmp_app) {
1071 1083
 		tmp_app = &(*cur_app)->next;
1072 1084
 
1073
-		if (!SCA_STR_EQ(owner, &(*cur_app)->owner)) {
1085
+		if(!SCA_STR_EQ(owner, &(*cur_app)->owner)) {