Jelajahi Sumber

tm: clang-format for coherent indentation and coding style

Victor Seva 2 tahun lalu
induk
melakukan
7769324830
43 mengubah file dengan 4486 tambahan dan 4293 penghapusan
  1. 1 1
      src/modules/tm/callid.c
  2. 159 152
      src/modules/tm/config.c
  3. 50 49
      src/modules/tm/config.h
  4. 1 1
      src/modules/tm/dlg.c
  5. 11 9
      src/modules/tm/dlg.h
  6. 18 19
      src/modules/tm/h_table.c
  7. 15 13
      src/modules/tm/h_table.h
  8. 9 9
      src/modules/tm/lw_parser.c
  9. 269 246
      src/modules/tm/rpc_uac.c
  10. 3 3
      src/modules/tm/rpc_uac.h
  11. 109 75
      src/modules/tm/select.c
  12. 73 67
      src/modules/tm/t_append_branches.c
  13. 2 2
      src/modules/tm/t_append_branches.h
  14. 150 147
      src/modules/tm/t_cancel.c
  15. 30 28
      src/modules/tm/t_cancel.h
  16. 342 310
      src/modules/tm/t_fifo.c
  17. 4 5
      src/modules/tm/t_fifo.h
  18. 125 123
      src/modules/tm/t_funcs.c
  19. 57 66
      src/modules/tm/t_funcs.h
  20. 369 372
      src/modules/tm/t_fwd.c
  21. 32 27
      src/modules/tm/t_fwd.h
  22. 98 104
      src/modules/tm/t_hooks.c
  23. 112 111
      src/modules/tm/t_hooks.h
  24. 326 277
      src/modules/tm/t_lookup.c
  25. 52 52
      src/modules/tm/t_lookup.h
  26. 297 286
      src/modules/tm/t_msgbuilder.c
  27. 17 22
      src/modules/tm/t_msgbuilder.h
  28. 255 266
      src/modules/tm/t_reply.c
  29. 61 57
      src/modules/tm/t_reply.h
  30. 200 192
      src/modules/tm/t_serial.c
  31. 7 7
      src/modules/tm/t_serial.h
  32. 125 121
      src/modules/tm/t_stats.c
  33. 29 20
      src/modules/tm/t_stats.h
  34. 138 137
      src/modules/tm/t_suspend.c
  35. 14 14
      src/modules/tm/t_suspend.h
  36. 13 15
      src/modules/tm/timer.c
  37. 8 7
      src/modules/tm/timer.h
  38. 414 403
      src/modules/tm/tm.c
  39. 21 21
      src/modules/tm/tm_load.c
  40. 70 68
      src/modules/tm/tm_load.h
  41. 261 238
      src/modules/tm/uac.c
  42. 37 36
      src/modules/tm/uac.h
  43. 102 115
      src/modules/tm/ut.h

+ 1 - 1
src/modules/tm/callid.c

@@ -52,7 +52,7 @@
 			+ 42   /* embedded v4inv6 address can be looong '128.' */ \
 			+ 2 /* parenthesis [] */ + 1 /* ZT 0 */                   \
 			+ 16						 /* one never knows ;-) */    \
-			)
+	)
 
 
 static unsigned long callid_nr;

+ 159 - 152
src/modules/tm/config.c

@@ -33,29 +33,29 @@
 #include "t_cancel.h" /* cancel_b_flags_fixup() */
 #include "config.h"
 
-struct cfg_group_tm	default_tm_cfg = {
-	"trying -- your call is important to us",	/* tm_auto_inv_100_r */
-	"Server Internal Error",	/* default_reason */
-	STR_NULL,	/* ac_extra_hdrs */
-	/* should be request-uri matching used as a part of pre-3261
+struct cfg_group_tm default_tm_cfg = {
+		"trying -- your call is important to us", /* tm_auto_inv_100_r */
+		"Server Internal Error",				  /* default_reason */
+		STR_NULL,								  /* ac_extra_hdrs */
+		/* should be request-uri matching used as a part of pre-3261
 	 * transaction matching, as the standard wants us to do so
 	 * (and is reasonable to do so, to be able to distinguish
 	 * spirals)? turn only off for better interaction with
 	 * devices that are broken and send different r-uri in
 	 * CANCEL/ACK than in original INVITE
 	 */
-	1,	/* ruri_matching */
-	1,	/* via1_matching */
-	0,	/* callid_matching */
-	0,	/* callid_cseq_matching */
-	FR_TIME_OUT,	/* fr_timeout */
-	INV_FR_TIME_OUT,	/* fr_inv_timeout */
-	INV_FR_TIME_OUT_NEXT, /* fr_inv_timeout_next */
-	WT_TIME_OUT,	/* wait_timeout */
-	RETR_T1,	/* rt_t1_timeout_ms */
-	RETR_T2,	/* rt_t2_timeout_ms */
+		1,					  /* ruri_matching */
+		1,					  /* via1_matching */
+		0,					  /* callid_matching */
+		0,					  /* callid_cseq_matching */
+		FR_TIME_OUT,		  /* fr_timeout */
+		INV_FR_TIME_OUT,	  /* fr_inv_timeout */
+		INV_FR_TIME_OUT_NEXT, /* fr_inv_timeout_next */
+		WT_TIME_OUT,		  /* wait_timeout */
+		RETR_T1,			  /* rt_t1_timeout_ms */
+		RETR_T2,			  /* rt_t2_timeout_ms */
 
-	/* maximum time an invite or noninv transaction will live, from
+		/* maximum time an invite or noninv transaction will live, from
 	 * the moment of creation (overrides larger fr/fr_inv timeouts,
 	 * extensions due to dns failover, fr_inv restart a.s.o)
 	 * Note: after this time the transaction will not be deleted
@@ -64,150 +64,157 @@ struct cfg_group_tm	default_tm_cfg = {
 	 *  the non-inv or "silent" inv. case and for fr_timeout + wait_timeout for an
 	 *  invite transaction (for which  we must wait for the neg. reply ack)
 	 */
-	MAX_INV_LIFETIME,	/* tm_max_inv_lifetime */
-	MAX_NONINV_LIFETIME,	/* tm_max_noninv_lifetime */
-	1,	/* noisy_ctimer */
-	1,	/* tm_auto_inv_100 */
-	500,	/* tm_unix_tx_timeout -- 500 ms by default */
-	1,	/* restart_fr_on_each_reply */
-	0,	/* pass_provisional_replies */
-	1,	/* tm_aggregate_auth */
-	UM_CANCEL_STATEFULL,	/* unmatched_cancel */
-	500,	/* default_code */
-	1,	/* reparse_invite */
+		MAX_INV_LIFETIME,	 /* tm_max_inv_lifetime */
+		MAX_NONINV_LIFETIME, /* tm_max_noninv_lifetime */
+		1,					 /* noisy_ctimer */
+		1,					 /* tm_auto_inv_100 */
+		500,				 /* tm_unix_tx_timeout -- 500 ms by default */
+		1,					 /* restart_fr_on_each_reply */
+		0,					 /* pass_provisional_replies */
+		1,					 /* tm_aggregate_auth */
+		UM_CANCEL_STATEFULL, /* unmatched_cancel */
+		500,				 /* default_code */
+		1,					 /* reparse_invite */
 
-	0,	/* tm_blst_503 -- if 1 blocklist 503 sources, using tm_blst_503_min,
+		0, /* tm_blst_503 -- if 1 blocklist 503 sources, using tm_blst_503_min,
 		 * tm_blst_503_max, tm_blst_503_default and the Retry-After header
 		 * in the 503 reply */
-	0,	/* tm_blst_503_default -- rfc conformant: do not blocklist if
+		0, /* tm_blst_503_default -- rfc conformant: do not blocklist if
 		 * no retry-after header is present */
-	0,	/* tm_blst_503 -- minimum 503 blocklist time is 0 sec */
-	3600,	/* tm_blst_503_max -- maximum 503 blocklist time is 3600 sec */
-	METHOD_INVITE,	/* tm_blst_methods_add -- backlist only INVITE
+		0, /* tm_blst_503 -- minimum 503 blocklist time is 0 sec */
+		3600, /* tm_blst_503_max -- maximum 503 blocklist time is 3600 sec */
+		METHOD_INVITE, /* tm_blst_methods_add -- backlist only INVITE
 			 * timeouts by default */
-	~METHOD_BYE,	/* tm_blst_methods_lookup -- look-up the blocklist
+		~METHOD_BYE,   /* tm_blst_methods_lookup -- look-up the blocklist
 			 * for every method except BYE by default */
-	1,	/* cancel_b_method used for e2e and 6xx cancels*/
-	1,	/* reparse_on_dns_failover */
-	0, /* disable_6xx, by default off */
-	0,  /* local_ack_mode, default 0 (rfc3261 conformant) */
-	1, /* local_cancel_reason -- add Reason header to locally generated
+		1,			   /* cancel_b_method used for e2e and 6xx cancels*/
+		1,			   /* reparse_on_dns_failover */
+		0,			   /* disable_6xx, by default off */
+		0,			   /* local_ack_mode, default 0 (rfc3261 conformant) */
+		1, /* local_cancel_reason -- add Reason header to locally generated
 		  CANCELs; on by default */
-	1,  /* e2e_cancel_reason -- copy the Reason headers from incoming CANCELs
+		1, /* e2e_cancel_reason -- copy the Reason headers from incoming CANCELs
 		  into the corresp. hop-by-hop CANCELs, on by default */
-	0,   /* relay_100 -- by default, assume stateful proxy and do not relay SIP 100 */
-	0  /* enable_uac_fr */
+		0, /* relay_100 -- by default, assume stateful proxy and do not relay SIP 100 */
+		0 /* enable_uac_fr */
 };
 
-void	*tm_cfg = &default_tm_cfg;
+void *tm_cfg = &default_tm_cfg;
 
-cfg_def_t	tm_cfg_def[] = {
-	{"auto_inv_100_reason",	CFG_VAR_STRING,	0, 0, 0, 0,
-		"reason text of the automatically send 100 to an INVITE"},
-	{"default_reason",	CFG_VAR_STRING,	0, 0, 0, 0,
-		"default SIP reason phrase sent by t_reply(), if the function "
-		"cannot retrieve its parameters"},
-	{"ac_extra_hdrs",	CFG_VAR_STR,	0, 0, 0, 0,
-		"header fields prefixed by this parameter value are included "
-		"in the CANCEL and negative ACK messages if they were present "
-		"in the outgoing INVITE (depends on reparse_invite)"},
-	{"ruri_matching",	CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"perform Request URI check in transaction matching"},
-	{"via1_matching",	CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"perform first Via header check in transaction matching"},
-	{"callid_matching",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
-		"perform callid check in transaction matching"},
-	{"callid_cseq_matching",CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
-		"perform callid+cseq instead of md5 in transaction matching"},
-	{"fr_timer",		CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup, 0,
-		"timer which hits if no final reply for a request "
-		"or ACK for a negative INVITE reply arrives "
-		"(in milliseconds)"},
-	{"fr_inv_timer",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup, 0,
-		"timer which hits if no final reply for an INVITE arrives "
-		"after a provisional message was received (in milliseconds)"},
-	{"fr_inv_timer_next",	CFG_VAR_INT,	0, 0, 0, 0,
-		"The value [ms] of fr_inv_timer for subsequent branches during serial forking."},
-	{"wt_timer",		CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup, 0,
-		"time for which a transaction stays in memory to absorb "
-		"delayed messages after it completed"},
-	{"retr_timer1",		CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup_ms, 0,
-		"initial retransmission period (in milliseconds)"},
-	{"retr_timer2",		CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup_ms, 0,
-		"maximum retransmission period (in milliseconds)"},
-	{"max_inv_lifetime",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup, 0,
-		"maximum time an invite transaction can live "
-		"from the moment of creation"},
-	{"max_noninv_lifetime",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup, 0,
-		"maximum time a non-invite transaction can live "
-		"from the moment of creation"},
-	{"noisy_ctimer",	CFG_VAR_INT,	0, 1, 0, 0,
-		"if set, INVITE transactions that time-out (FR INV timer) "
-		"will be always replied"},
-	{"auto_inv_100",	CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"automatically send 100 to an INVITE"},
-	{"unix_tx_timeout",	CFG_VAR_INT,	0, 0, 0, 0,
-		"Unix socket transmission timeout, in milliseconds"},
-	{"restart_fr_on_each_reply",	CFG_VAR_INT | CFG_ATOMIC ,	0, 1, 0, 0,
-		"restart final response timer on each provisional reply"},
-	{"pass_provisional_replies",	CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"enable/disable passing of provisional replies "
-		"to TMCB_LOCAL_RESPONSE_OUT callbacks"},
-	{"aggregate_challenges",	CFG_VAR_INT /* not atomic */,	0, 1, 0, 0,
-		"if the final response is a 401 or a 407, aggregate all the "
-		"authorization headers (challenges) "
-		"(rfc3261 requires this to be on)"},
-	{"unmatched_cancel",	CFG_VAR_INT,	0, 2, 0, 0,
-		"determines how CANCELs with no matching transaction are handled "
-		"(0: statefull forwarding, 1: stateless forwarding, 2: drop)"},
-	{"default_code",	CFG_VAR_INT | CFG_ATOMIC,	400, 699, 0, 0,
-		"default SIP response code sent by t_reply(), if the function "
-		"cannot retrieve its parameters"},
-	{"reparse_invite",	CFG_VAR_INT,	0, 1, 0, 0,
-		"if set to 1, the CANCEL and negative ACK requests are "
-		"constructed from the INVITE message which was sent out "
-		"instead of building them from the received request"},
-	{"blst_503",		CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"if set to 1, blocklist 503 SIP response sources"},
-	{"blst_503_def_timeout",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
-		"default 503 blocklist time (in s), when no Retry-After "
-		"header is present"},
-	{"blst_503_min_timeout",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
-		"minimum 503 blocklist time (in s)"},
-	{"blst_503_max_timeout",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
-		"maximum 503 blocklist time (in s)"},
-	{"blst_methods_add",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
-		"bitmap of method types that trigger blocklisting on "
-		"transaction timeouts"},
-	{"blst_methods_lookup",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
-		"Bitmap of method types that are looked-up in the blocklist "
-		"before statefull forwarding"},
-	{"cancel_b_method",	CFG_VAR_INT,	0, 2, cancel_b_flags_fixup, 0,
-		"How to cancel branches on which no replies were received: 0 - fake"
-		" reply, 1 - retransmitting the request, 2 - send cancel"},
-	{"reparse_on_dns_failover",	CFG_VAR_INT | CFG_ATOMIC,	0, 1,
-		reparse_on_dns_failover_fixup, 0,
-		"if set to 1, the SIP message after a DNS failover is "
-		"constructed from the outgoing message buffer of the failed "
-		"branch instead of from the received request"},
-	{"disable_6xx_block",	CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"if set to 1, 6xx is treated like a normal reply (breaks rfc)"},
-	{"local_ack_mode",		CFG_VAR_INT | CFG_ATOMIC,	0, 2, 0, 0,
-		"if set to 1 or 2, local 200 ACKs are sent to the same address as the"
-		" corresponding INVITE (1) or the source of the 200 reply (2) instead"
-		" of using the contact and the route set (it breaks the rfc, if "
-		" it is not set to 0 but allows dealing with NATed contacts in some "
-		"simple cases)"
-		},
-	{"local_cancel_reason",	CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"if set to 1, a Reason header is added to locally generated CANCELs"
-		" (see RFC3326)" },
-	{"e2e_cancel_reason",	CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"if set to 1, Reason headers from received CANCELs are copied into"
-		" the corresponding generated hop-by-hop CANCELs"},
-	{"relay_100",		CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"if set to 1, relay SIP 100 messages as a stateless proxy"},
-	{"enable_uac_fr",		CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
-		"if set, enables failure route for UAC messages"},
-	{0, 0, 0, 0, 0, 0}
-};
+cfg_def_t tm_cfg_def[] = {
+		{"auto_inv_100_reason", CFG_VAR_STRING, 0, 0, 0, 0,
+				"reason text of the automatically send 100 to an INVITE"},
+		{"default_reason", CFG_VAR_STRING, 0, 0, 0, 0,
+				"default SIP reason phrase sent by t_reply(), if the function "
+				"cannot retrieve its parameters"},
+		{"ac_extra_hdrs", CFG_VAR_STR, 0, 0, 0, 0,
+				"header fields prefixed by this parameter value are included "
+				"in the CANCEL and negative ACK messages if they were present "
+				"in the outgoing INVITE (depends on reparse_invite)"},
+		{"ruri_matching", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"perform Request URI check in transaction matching"},
+		{"via1_matching", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"perform first Via header check in transaction matching"},
+		{"callid_matching", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
+				"perform callid check in transaction matching"},
+		{"callid_cseq_matching", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
+				"perform callid+cseq instead of md5 in transaction matching"},
+		{"fr_timer", CFG_VAR_INT | CFG_ATOMIC, 0, 0, timer_fixup, 0,
+				"timer which hits if no final reply for a request "
+				"or ACK for a negative INVITE reply arrives "
+				"(in milliseconds)"},
+		{"fr_inv_timer", CFG_VAR_INT | CFG_ATOMIC, 0, 0, timer_fixup, 0,
+				"timer which hits if no final reply for an INVITE arrives "
+				"after a provisional message was received (in milliseconds)"},
+		{"fr_inv_timer_next", CFG_VAR_INT, 0, 0, 0, 0,
+				"The value [ms] of fr_inv_timer for subsequent branches during "
+				"serial forking."},
+		{"wt_timer", CFG_VAR_INT | CFG_ATOMIC, 0, 0, timer_fixup, 0,
+				"time for which a transaction stays in memory to absorb "
+				"delayed messages after it completed"},
+		{"retr_timer1", CFG_VAR_INT | CFG_ATOMIC, 0, 0, timer_fixup_ms, 0,
+				"initial retransmission period (in milliseconds)"},
+		{"retr_timer2", CFG_VAR_INT | CFG_ATOMIC, 0, 0, timer_fixup_ms, 0,
+				"maximum retransmission period (in milliseconds)"},
+		{"max_inv_lifetime", CFG_VAR_INT | CFG_ATOMIC, 0, 0, timer_fixup, 0,
+				"maximum time an invite transaction can live "
+				"from the moment of creation"},
+		{"max_noninv_lifetime", CFG_VAR_INT | CFG_ATOMIC, 0, 0, timer_fixup, 0,
+				"maximum time a non-invite transaction can live "
+				"from the moment of creation"},
+		{"noisy_ctimer", CFG_VAR_INT, 0, 1, 0, 0,
+				"if set, INVITE transactions that time-out (FR INV timer) "
+				"will be always replied"},
+		{"auto_inv_100", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"automatically send 100 to an INVITE"},
+		{"unix_tx_timeout", CFG_VAR_INT, 0, 0, 0, 0,
+				"Unix socket transmission timeout, in milliseconds"},
+		{"restart_fr_on_each_reply", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"restart final response timer on each provisional reply"},
+		{"pass_provisional_replies", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"enable/disable passing of provisional replies "
+				"to TMCB_LOCAL_RESPONSE_OUT callbacks"},
+		{"aggregate_challenges", CFG_VAR_INT /* not atomic */, 0, 1, 0, 0,
+				"if the final response is a 401 or a 407, aggregate all the "
+				"authorization headers (challenges) "
+				"(rfc3261 requires this to be on)"},
+		{"unmatched_cancel", CFG_VAR_INT, 0, 2, 0, 0,
+				"determines how CANCELs with no matching transaction are "
+				"handled "
+				"(0: statefull forwarding, 1: stateless forwarding, 2: drop)"},
+		{"default_code", CFG_VAR_INT | CFG_ATOMIC, 400, 699, 0, 0,
+				"default SIP response code sent by t_reply(), if the function "
+				"cannot retrieve its parameters"},
+		{"reparse_invite", CFG_VAR_INT, 0, 1, 0, 0,
+				"if set to 1, the CANCEL and negative ACK requests are "
+				"constructed from the INVITE message which was sent out "
+				"instead of building them from the received request"},
+		{"blst_503", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"if set to 1, blocklist 503 SIP response sources"},
+		{"blst_503_def_timeout", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
+				"default 503 blocklist time (in s), when no Retry-After "
+				"header is present"},
+		{"blst_503_min_timeout", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
+				"minimum 503 blocklist time (in s)"},
+		{"blst_503_max_timeout", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
+				"maximum 503 blocklist time (in s)"},
+		{"blst_methods_add", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
+				"bitmap of method types that trigger blocklisting on "
+				"transaction timeouts"},
+		{"blst_methods_lookup", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0,
+				"Bitmap of method types that are looked-up in the blocklist "
+				"before statefull forwarding"},
+		{"cancel_b_method", CFG_VAR_INT, 0, 2, cancel_b_flags_fixup, 0,
+				"How to cancel branches on which no replies were received: 0 - "
+				"fake"
+				" reply, 1 - retransmitting the request, 2 - send cancel"},
+		{"reparse_on_dns_failover", CFG_VAR_INT | CFG_ATOMIC, 0, 1,
+				reparse_on_dns_failover_fixup, 0,
+				"if set to 1, the SIP message after a DNS failover is "
+				"constructed from the outgoing message buffer of the failed "
+				"branch instead of from the received request"},
+		{"disable_6xx_block", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"if set to 1, 6xx is treated like a normal reply (breaks rfc)"},
+		{"local_ack_mode", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0,
+				"if set to 1 or 2, local 200 ACKs are sent to the same address "
+				"as the"
+				" corresponding INVITE (1) or the source of the 200 reply (2) "
+				"instead"
+				" of using the contact and the route set (it breaks the rfc, "
+				"if "
+				" it is not set to 0 but allows dealing with NATed contacts in "
+				"some "
+				"simple cases)"},
+		{"local_cancel_reason", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"if set to 1, a Reason header is added to locally generated "
+				"CANCELs"
+				" (see RFC3326)"},
+		{"e2e_cancel_reason", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"if set to 1, Reason headers from received CANCELs are copied "
+				"into"
+				" the corresponding generated hop-by-hop CANCELs"},
+		{"relay_100", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"if set to 1, relay SIP 100 messages as a stateless proxy"},
+		{"enable_uac_fr", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0,
+				"if set, enables failure route for UAC messages"},
+		{0, 0, 0, 0, 0, 0}};

+ 50 - 49
src/modules/tm/config.h

@@ -40,23 +40,23 @@
 #include "../../core/str.h"
 
 /* maximum length of localy generated acknowledgment */
-#define MAX_ACK_LEN   1024
+#define MAX_ACK_LEN 1024
 
 /* FINAL_RESPONSE_TIMER ... tells how long should the transaction engine
    wait if no final response comes back*/
-#define FR_TIME_OUT        30000 /* ms */
-#define INV_FR_TIME_OUT   120000 /* ms */
+#define FR_TIME_OUT 30000	   /* ms */
+#define INV_FR_TIME_OUT 120000 /* ms */
 
 /*! \brief final response timers to be used for serial forwarding */
-#define INV_FR_TIME_OUT_NEXT  30000 /* ms */
+#define INV_FR_TIME_OUT_NEXT 30000 /* ms */
 
 /* WAIT timer ... tells how long state should persist in memory after
    a transaction was finalized*/
-#define WT_TIME_OUT       5000 /* ms */
+#define WT_TIME_OUT 5000 /* ms */
 
 /* retransmission timers */
-#define RETR_T1           500 /* ms */
-#define RETR_T2          4000 /* ms */
+#define RETR_T1 500	 /* ms */
+#define RETR_T2 4000 /* ms */
 
 /* maximum total lifetime for an INVITE or non-INVITE transaction
  * Note: after this time the transaction will not be deleted
@@ -64,8 +64,8 @@
  *  and then wait state, so it will still be alive for either WT_TIME_OUT in
  *  the non-inv or "silent" inv. case and for FR_TIME_OUT + WT_TIME_OUT for an
  *  invite transaction (for which  we must wait for the neg. reply ack)*/
-#define MAX_INV_LIFETIME    180000 /* ms, rfc min. C-timer value */
-#define MAX_NONINV_LIFETIME  32000 /* ms, rfc timer F value */
+#define MAX_INV_LIFETIME 180000	  /* ms, rfc min. C-timer value */
+#define MAX_NONINV_LIFETIME 32000 /* ms, rfc timer F value */
 
 /* when first reply is sent, this additional space is allocated so that
    one does not have to reallocate share memory when the message is
@@ -75,10 +75,10 @@
 #define TAG_OVERBUFFER_LEN 32
 
 /* dimensions of FIFO server */
-#define MAX_METHOD	64
-#define MAX_HEADER	1024
-#define MAX_BODY	1024
-#define MAX_DST	512
+#define MAX_METHOD 64
+#define MAX_HEADER 1024
+#define MAX_BODY 1024
+#define MAX_DST 512
 #define MAX_FROM 512
 
 /* messages generated by server */
@@ -92,39 +92,40 @@
 /* FIFO substitution character */
 #define SUBST_CHAR '!'
 
-struct cfg_group_tm {
-	char	*tm_auto_inv_100_r;
-	char	*default_reason;
-	str	ac_extra_hdrs;
-	int	ruri_matching;
-	int	via1_matching;
-	int	callid_matching;
-	int	callid_cseq_matching;
-	unsigned int	fr_timeout;
-	unsigned int	fr_inv_timeout;
-	unsigned int    fr_inv_timeout_next;
-	unsigned int	wait_timeout;
-	unsigned int	rt_t1_timeout_ms;
-	unsigned int	rt_t2_timeout_ms;
-	unsigned int	tm_max_inv_lifetime;
-	unsigned int	tm_max_noninv_lifetime;
-	int	noisy_ctimer;
-	int	tm_auto_inv_100;
-	int	tm_unix_tx_timeout;
-	int	restart_fr_on_each_reply;
-	int	pass_provisional_replies;
-	int	tm_aggregate_auth;
-	int	unmatched_cancel;
-	int	default_code;
-	int	reparse_invite;
-	int	tm_blst_503;
-	int	tm_blst_503_default;
-	int	tm_blst_503_min;
-	int	tm_blst_503_max;
-	unsigned int	tm_blst_methods_add;
-	unsigned int	tm_blst_methods_lookup;
-	unsigned int	cancel_b_flags;
-	int	reparse_on_dns_failover;
+struct cfg_group_tm
+{
+	char *tm_auto_inv_100_r;
+	char *default_reason;
+	str ac_extra_hdrs;
+	int ruri_matching;
+	int via1_matching;
+	int callid_matching;
+	int callid_cseq_matching;
+	unsigned int fr_timeout;
+	unsigned int fr_inv_timeout;
+	unsigned int fr_inv_timeout_next;
+	unsigned int wait_timeout;
+	unsigned int rt_t1_timeout_ms;
+	unsigned int rt_t2_timeout_ms;
+	unsigned int tm_max_inv_lifetime;
+	unsigned int tm_max_noninv_lifetime;
+	int noisy_ctimer;
+	int tm_auto_inv_100;
+	int tm_unix_tx_timeout;
+	int restart_fr_on_each_reply;
+	int pass_provisional_replies;
+	int tm_aggregate_auth;
+	int unmatched_cancel;
+	int default_code;
+	int reparse_invite;
+	int tm_blst_503;
+	int tm_blst_503_default;
+	int tm_blst_503_min;
+	int tm_blst_503_max;
+	unsigned int tm_blst_methods_add;
+	unsigned int tm_blst_methods_lookup;
+	unsigned int cancel_b_flags;
+	int reparse_on_dns_failover;
 	int disable_6xx;
 	int local_ack_mode;
 	int local_cancel_reason;
@@ -133,8 +134,8 @@ struct cfg_group_tm {
 	int enable_uac_fr;
 };
 
-extern struct cfg_group_tm	default_tm_cfg;
-extern void	*tm_cfg;
-extern cfg_def_t	tm_cfg_def[];
+extern struct cfg_group_tm default_tm_cfg;
+extern void *tm_cfg;
+extern cfg_def_t tm_cfg_def[];
 
 #endif

+ 1 - 1
src/modules/tm/dlg.c

@@ -44,7 +44,7 @@
 #include "callid.h"
 #include "uac.h"
 
-#define NORMAL_ORDER 0  /* Create route set in normal order - UAS */
+#define NORMAL_ORDER 0	/* Create route set in normal order - UAS */
 #define REVERSE_ORDER 1 /* Create route set in reverse order - UAC */
 
 

+ 11 - 9
src/modules/tm/dlg.h

@@ -55,7 +55,7 @@
  */
 typedef struct dlg_seq
 {
-	unsigned int value;   /* Sequence value */
+	unsigned int value;	  /* Sequence value */
 	unsigned char is_set; /* is_set flag */
 } dlg_seq_t;
 
@@ -63,9 +63,10 @@ typedef struct dlg_seq
 /*
  * Dialog state
  */
-typedef enum dlg_state {
+typedef enum dlg_state
+{
 	DLG_NEW = 0,   /* New dialog, no reply received yet */
-	DLG_EARLY,	 /* Early dialog, provisional response received */
+	DLG_EARLY,	   /* Early dialog, provisional response received */
 	DLG_CONFIRMED, /* Confirmed dialog, 2xx received */
 	DLG_DESTROYED  /* Destroyed dialog */
 } dlg_state_t;
@@ -95,7 +96,7 @@ typedef struct dlg_hooks
 	str ru;
 	str nh;
 	str *request_uri;  /* This should be put into Request-URI */
-	str *next_hop;	 /* Where the message should be really sent */
+	str *next_hop;	   /* Where the message should be really sent */
 	rr_t *first_route; /* First route to be printed into the message */
 	str *last_route;   /* If not zero add this as the last route */
 } dlg_hooks_t;
@@ -107,8 +108,8 @@ typedef struct dlg_hooks
 typedef struct dlg
 {
 	dlg_id_t id;		  /* Dialog identifier */
-	dlg_seq_t loc_seq;	/* Local sequence number */
-	dlg_seq_t rem_seq;	/* Remote sequence number */
+	dlg_seq_t loc_seq;	  /* Local sequence number */
+	dlg_seq_t rem_seq;	  /* Remote sequence number */
 	str loc_uri;		  /* Local URI */
 	str rem_uri;		  /* Remote URI */
 	str rem_target;		  /* Remote target URI */
@@ -116,9 +117,9 @@ typedef struct dlg
 	str loc_dname;		  /* Local Display Name */
 	str rem_dname;		  /* Remote Display Name */
 	unsigned char secure; /* Secure flag -- currently not used */
-	dlg_state_t state;	/* State of the dialog */
+	dlg_state_t state;	  /* State of the dialog */
 	rr_t *route_set;	  /* Route set */
-	dlg_hooks_t hooks;	/* Various hooks used to store information that
+	dlg_hooks_t hooks;	  /* Various hooks used to store information that
 				 * can be reused when building a message (to
 				 * prevent repeated analyzing of the dialog data
 				 */
@@ -128,7 +129,8 @@ typedef struct dlg
 #endif
 } dlg_t;
 
-typedef enum {
+typedef enum
+{
 	IS_TARGET_REFRESH,
 	IS_NOT_TARGET_REFRESH,
 	TARGET_REFRESH_UNKNOWN

+ 18 - 19
src/modules/tm/h_table.c

@@ -47,8 +47,9 @@
 #include "uac.h" /* free_local_ack */
 
 
-#define T_UAC_PTR(T) ((tm_ua_client_t*)((char*)T + sizeof(tm_cell_t) \
-								+ MD5_LEN - sizeof(((tm_cell_t*)0)->md5)))
+#define T_UAC_PTR(T)                                            \
+	((tm_ua_client_t *)((char *)T + sizeof(tm_cell_t) + MD5_LEN \
+						- sizeof(((tm_cell_t *)0)->md5)))
 
 
 static enum kill_reason kr;
@@ -131,7 +132,7 @@ void free_cell_helper(
 
 	LM_DBG("freeing transaction %p from %s:%u\n", dead_cell, fname, fline);
 
-	if(dead_cell==NULL) {
+	if(dead_cell == NULL) {
 		return;
 	}
 
@@ -153,10 +154,10 @@ void free_cell_helper(
 	release_cell_lock(dead_cell); /* does nothing */
 
 	dead_cell->fcount++;
-	if(dead_cell->fcount!=1) {
+	if(dead_cell->fcount != 1) {
 		LM_WARN("unexpected fcount value: %d\n", dead_cell->fcount);
 	}
-	if(dead_cell->uac==NULL || dead_cell->uac!=T_UAC_PTR(dead_cell)) {
+	if(dead_cell->uac == NULL || dead_cell->uac != T_UAC_PTR(dead_cell)) {
 		LM_WARN("unexpected tm cell content: %p\n", dead_cell);
 		return;
 	}
@@ -204,8 +205,9 @@ void free_cell_helper(
 #ifdef USE_DNS_FAILOVER
 		if(dead_cell->uac[i].dns_h.a) {
 			LM_DBG("branch %d -> dns_h.srv (%.*s) ref=%d,"
-				" dns_h.a (%.*s) ref=%d\n",
-					i, dead_cell->uac[i].dns_h.srv
+				   " dns_h.a (%.*s) ref=%d\n",
+					i,
+					dead_cell->uac[i].dns_h.srv
 							? dead_cell->uac[i].dns_h.srv->name_len
 							: 0,
 					dead_cell->uac[i].dns_h.srv
@@ -599,21 +601,18 @@ void tm_xdata_replace(tm_xdata_t *newxd, tm_xlinks_t *bakxd)
 void tm_log_transaction(tm_cell_t *tcell, int llev, char *ltext)
 {
 	LOG(llev, "%s [start] transaction %p\n", ltext, tcell);
-	LOG(llev, "%s - tindex=%u tlabel=%u method='%.*s' from_hdr='%.*s'"
+	LOG(llev,
+			"%s - tindex=%u tlabel=%u method='%.*s' from_hdr='%.*s'"
 			" to_hdr='%.*s' callid_hdr='%.*s' cseq_hdr='%.*s' uas_request=%s"
 			" tflags=%u outgoings=%u ref_count=%u lifetime=%u\n",
 			ltext, (unsigned)tcell->hash_index, (unsigned)tcell->label,
-			tcell->method.len, tcell->method.s,
-			tcell->from_hdr.len, tcell->from_hdr.s,
-			tcell->to_hdr.len, tcell->to_hdr.s,
-			tcell->callid_hdr.len, tcell->callid_hdr.s,
-			tcell->cseq_hdr_n.len, tcell->cseq_hdr_n.s,
-			(tcell->uas.request)?"yes":"no",
-			(unsigned)tcell->flags,
-			(unsigned)tcell->nr_of_outgoings,
+			tcell->method.len, tcell->method.s, tcell->from_hdr.len,
+			tcell->from_hdr.s, tcell->to_hdr.len, tcell->to_hdr.s,
+			tcell->callid_hdr.len, tcell->callid_hdr.s, tcell->cseq_hdr_n.len,
+			tcell->cseq_hdr_n.s, (tcell->uas.request) ? "yes" : "no",
+			(unsigned)tcell->flags, (unsigned)tcell->nr_of_outgoings,
 			(unsigned)atomic_get(&tcell->ref_count),
-			(unsigned)TICKS_TO_S(tcell->end_of_life)
-		);
+			(unsigned)TICKS_TO_S(tcell->end_of_life));
 
 	LOG(llev, "%s [end] transaction %p\n", ltext, tcell);
 }
@@ -628,7 +627,7 @@ void tm_clean_lifetime(void)
 
 	texp = get_ticks_raw() - S_TO_TICKS(TM_LIFETIME_LIMIT);
 
-	for (r=0; r<TABLE_ENTRIES; r++) {
+	for(r = 0; r < TABLE_ENTRIES; r++) {
 		/* faster first try without lock */
 		if(clist_empty(&_tm_table->entries[r], next_c)) {
 			continue;

+ 15 - 13
src/modules/tm/h_table.h

@@ -143,9 +143,9 @@ typedef struct retr_buf
 	 * 0 (TYPE_REQUEST) if request, -1 if local CANCEL (TYPE_LOCAL_CANCEL),
 	 * -2 if local ACK (TYPE_LOCAL_ACK) */
 	short rbtype;
-	volatile unsigned short flags;   /* DISABLED, T2 */
+	volatile unsigned short flags;	  /* DISABLED, T2 */
 	volatile unsigned short t_active; /* timer active */
-	unsigned short branch;			 /* no more than 64k branches */
+	unsigned short branch;			  /* no more than 64k branches */
 	int buffer_len;
 	char *buffer;
 	/*the cell that contains this retrans_buff*/
@@ -177,10 +177,10 @@ typedef struct ua_server
 /* User Agent Client content */
 
 /* UAC internal flags */
-#define TM_UAC_FLAG_RR (1)			/* Record-Route applied */
-#define TM_UAC_FLAG_R2 (1 << 1)		/* 2nd Record-Route applied */
-#define TM_UAC_FLAG_FB (1 << 2)		/* Mark first entry in new branch set */
-#define TM_UAC_FLAG_BLIND (1 << 3)	/* A blind uac */
+#define TM_UAC_FLAG_RR (1)		   /* Record-Route applied */
+#define TM_UAC_FLAG_R2 (1 << 1)	   /* 2nd Record-Route applied */
+#define TM_UAC_FLAG_FB (1 << 2)	   /* Mark first entry in new branch set */
+#define TM_UAC_FLAG_BLIND (1 << 3) /* A blind uac */
 
 typedef struct ua_client
 {
@@ -268,14 +268,15 @@ typedef struct async_state
 /* 6xx received => stop forking */
 #define T_6xx (1 << 4)
 
-#define T_IN_AGONY (1 << 5)		/* set if waiting to die (delete timer)
+#define T_IN_AGONY \
+	(1 << 5)					/* set if waiting to die (delete timer)
 								 * TODO: replace it with del on unref */
 #define T_AUTO_INV_100 (1 << 6) /* send an 100 reply automatically  to inv. */
 /* don't generate automatically an ACK for local transaction */
 #define T_NO_AUTO_ACK (1 << 7)
 
-#define T_DISABLE_6xx (1 << 8)		/* treat 6xx as a normal reply */
-#define T_DISABLE_FAILOVER (1 << 9) /* don't perform dns failover */
+#define T_DISABLE_6xx (1 << 8)			 /* treat 6xx as a normal reply */
+#define T_DISABLE_FAILOVER (1 << 9)		 /* don't perform dns failover */
 #define T_NO_E2E_CANCEL_REASON (1 << 10) /* don't propagate CANCEL Reason */
 #define T_DONT_FORK (T_CANCELED | T_6xx)
 
@@ -387,7 +388,7 @@ typedef struct cell
 
 	/* bindings to wait and delete timer */
 	struct timer_ln wait_timer; /* used also for delete */
-	ticks_t wait_start; /* ticks when put on wait first time */
+	ticks_t wait_start;			/* ticks when put on wait first time */
 
 	/* UA Server */
 	struct ua_server uas;
@@ -424,7 +425,7 @@ typedef struct cell
 	ticks_t fr_inv_timeout; /* final inv. response interval for retr_bufs */
 	retr_timeout_t rt_t1_timeout_ms; /* start retr. interval for retr_bufs */
 	retr_timeout_t rt_t2_timeout_ms; /* maximum retr. interval for retr_bufs */
-	ticks_t end_of_life; /* maximum lifetime */
+	ticks_t end_of_life;			 /* maximum lifetime */
 
 	/* nr of replied branch; 0..sr_dst_max_branches=branch value,
 	 * -1 no reply, -2 local reply */
@@ -449,7 +450,8 @@ typedef struct cell
 
 #if 0
 /* warning: padding too much => big size increase */
-#define ENTRY_PAD_TO 128 /* should be a multiple of cacheline size for
+#define ENTRY_PAD_TO \
+	128 /* should be a multiple of cacheline size for
 						 * best performance*/
 #define ENTRY_PAD_BYTES                                            \
 	(ENTRY_PAD_TO - 2 * sizeof(struct cell *) + sizeof(ser_lock_t) \
@@ -468,7 +470,7 @@ typedef struct entry
 	/* sync mutex */
 	ser_lock_t mutex;
 	atomic_t locker_pid; /* pid of the process that holds the lock */
-	int rec_lock_level;  /* recursive lock count */
+	int rec_lock_level;	 /* recursive lock count */
 	/* currently highest sequence number in a synonym list */
 	unsigned int next_label;
 #ifdef TM_HASH_STATS

+ 9 - 9
src/modules/tm/lw_parser.c

@@ -31,14 +31,14 @@
 #define READ(val) \
 	(*(val + 0) + (*(val + 1) << 8) + (*(val + 2) << 16) + (*(val + 3) << 24))
 
-#define LW_HNAME_SET(_p, _end, _hnlen, _type, _htype) \
-	do { \
-		if(_end - _p > _hnlen) { \
+#define LW_HNAME_SET(_p, _end, _hnlen, _type, _htype)    \
+	do {                                                 \
+		if(_end - _p > _hnlen) {                         \
 			if(_p[_hnlen] == ':' || _p[_hnlen] == ' ') { \
-				*_type = _htype; \
-				_p += _hnlen; \
-			} \
-		} \
+				*_type = _htype;                         \
+				_p += _hnlen;                            \
+			}                                            \
+		}                                                \
 	} while(0)
 
 /*
@@ -236,7 +236,7 @@ char *lw_next_line(char *buf, char *buf_end)
 
 	} while((c < buf_end)
 			&& ((*c == ' ')
-					   || (*c == '\t'))); /* next line begins with whitespace line folding */
+					|| (*c == '\t'))); /* next line begins with whitespace line folding */
 
 	return c;
 }
@@ -255,7 +255,7 @@ char *lw_find_via(char *buf, char *buf_end)
 		val = LOWER_DWORD(READ(p));
 		if((val == _via1_) || (val == _via2_)
 				|| ((LOWER_BYTE(*p) == 'v') /* compact header */
-						   && ((*(p + 1) == ' ') || (*(p + 1) == ':'))))
+						&& ((*(p + 1) == ' ') || (*(p + 1) == ':'))))
 			return p;
 
 		p = lw_next_line(p, buf_end);

File diff ditekan karena terlalu besar
+ 269 - 246
src/modules/tm/rpc_uac.c


+ 3 - 3
src/modules/tm/rpc_uac.h

@@ -24,9 +24,9 @@
 int tm_rpc_response_list_init(void);
 int tm_rpc_response_list_destroy(void);
 
-void rpc_t_uac_start(rpc_t* rpc, void* c);
-void rpc_t_uac_wait(rpc_t* rpc, void* c);
-void rpc_t_uac_wait_block(rpc_t* rpc, void* c);
+void rpc_t_uac_start(rpc_t *rpc, void *c);
+void rpc_t_uac_wait(rpc_t *rpc, void *c);
+void rpc_t_uac_wait_block(rpc_t *rpc, void *c);
 
 int t_uac_send(str *method, str *ruri, str *nexthop, str *send_socket,
 		str *headers, str *body);

+ 109 - 75
src/modules/tm/select.c

@@ -31,32 +31,36 @@
 #include "../../core/select_buf.h"
 #include "../../core/parser/msg_parser.h"
 
-#define RETURN0_res(x) {*res=(x);return 0;}
+#define RETURN0_res(x) \
+	{                  \
+		*res = (x);    \
+		return 0;      \
+	}
 
-inline static int select_tm_get_cell(struct sip_msg* msg, int *branch,
-		struct cell **t)
+inline static int select_tm_get_cell(
+		struct sip_msg *msg, int *branch, struct cell **t)
 {
 
 	/* make sure we know the associated transaction ... */
-	if (t_check( msg  , branch )==-1)  /* it's not necessary whan calling
+	if(t_check(msg, branch) == -1) /* it's not necessary whan calling
 										* from script because already done */
 		return -1;
 
 	/*... if there is none, tell the core router to fwd statelessly */
 	*t = get_t();
-	if ( (*t==0)||(*t==T_UNDEFINED)) return -1;
+	if((*t == 0) || (*t == T_UNDEFINED))
+		return -1;
 
 	return 0;
 }
 
-static int select_tm(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm(str *res, select_t *s, struct sip_msg *msg)
 {
 	int branch;
 	struct cell *t;
-	if (select_tm_get_cell(msg, &branch, &t) < 0) {
+	if(select_tm_get_cell(msg, &branch, &t) < 0) {
 		res->s = "0";
-	}
-	else {
+	} else {
 		res->s = "1";
 	}
 	res->len = 1;
@@ -66,21 +70,23 @@ static int select_tm(str* res, select_t* s, struct sip_msg* msg)
 #define SEL_BRANCH_POS 2
 #define BRANCH_NO(_s_) (_s_->params[SEL_BRANCH_POS].v.i)
 
-#define SELECT_check(msg) \
-	int branch; \
-	struct cell *t; \
-	if (select_tm_get_cell(msg, &branch, &t) < 0) return -1;
+#define SELECT_check(msg)                        \
+	int branch;                                  \
+	struct cell *t;                              \
+	if(select_tm_get_cell(msg, &branch, &t) < 0) \
+		return -1;
 
-#define SELECT_check_branch(_s_, _msg_) \
-	SELECT_check(_msg_); \
-	if (BRANCH_NO(_s_) >=t->nr_of_outgoings) return -1;
+#define SELECT_check_branch(_s_, _msg_)      \
+	SELECT_check(_msg_);                     \
+	if(BRANCH_NO(_s_) >= t->nr_of_outgoings) \
+		return -1;
 
 /* string resides in shared memory but I think it's not worth copying to
  * static buffer (str_to_static_buffer) as minimal probability that string
  * is changed by other process (or cell is already locked ?)
  */
 
-static int select_tm_method(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_method(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check(msg);
 	RETURN0_res(t->method);
@@ -88,7 +94,7 @@ static int select_tm_method(str* res, select_t* s, struct sip_msg* msg)
 
 static ABSTRACT_F(select_tm_uas);
 
-static int select_tm_uas_status(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uas_status(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check(msg);
 	return int_to_static_buffer(res, t->uas.status);
@@ -100,7 +106,7 @@ static int select_tm_uas_status(str* res, select_t* s, struct sip_msg* msg)
  * as select may perform any parsing which is stored in sip_msg structure.
  * But transaction cell resides in shared memory while parsing is done in
  * private memory. Therefore we support currently only complete request */
-static int select_tm_uas_request(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uas_request(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check(msg);
 	res->s = t->uas.request->buf;
@@ -108,13 +114,14 @@ static int select_tm_uas_request(str* res, select_t* s, struct sip_msg* msg)
 	return 0;
 }
 
-static int select_tm_uas_local_to_tag(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uas_local_to_tag(
+		str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check(msg);
 	RETURN0_res(t->uas.local_totag);
 }
 
-static int select_tm_uas_response(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uas_response(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check(msg);
 	res->s = t->uas.response.buffer;
@@ -125,20 +132,22 @@ static int select_tm_uas_response(str* res, select_t* s, struct sip_msg* msg)
 /* TODO: implement a general select function that works with any
  * kind of requests not only with negative ACKs
  */
-static int select_tm_uas_request_neg_ack_retransmission(str* res, select_t* s,
-		struct sip_msg* msg)
+static int select_tm_uas_request_neg_ack_retransmission(
+		str *res, select_t *s, struct sip_msg *msg)
 {
 	int rv;
 
 	SELECT_check(msg);
 	rv = ((msg->REQ_METHOD == METHOD_ACK)
-		&& (t->uas.status >= 300)
-		/* Misuse the timer flag of the 200 retransmission buffer
+				 && (t->uas.status >= 300)
+				 /* Misuse the timer flag of the 200 retransmission buffer
 		 * to check whether or not this is an ACK retransmission.
 		 * Warning: this check is not 100% fail-safe because two
 		 * ACKs can be processed in parallel and none of them
 		 * may be considered a retransmission - Miklos */
-		&& (t->uas.response.t_active == 0)) ? 1 : -1;
+				 && (t->uas.response.t_active == 0))
+				 ? 1
+				 : -1;
 
 	return int_to_static_buffer(res, rv);
 }
@@ -146,13 +155,13 @@ static int select_tm_uas_request_neg_ack_retransmission(str* res, select_t* s,
 
 static ABSTRACT_F(select_tm_uac);
 
-static int select_tm_uac_count(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uac_count(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check(msg);
 	return int_to_static_buffer(res, t->nr_of_outgoings);
 }
 
-static int select_tm_uac_relayed(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uac_relayed(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check(msg);
 	return int_to_static_buffer(res, t->relayed_reply_branch);
@@ -165,14 +174,14 @@ static ABSTRACT_F(select_tm_uac_branch);
  * @see selects select_tm_uac_last_status
  * @see select_tm_uac_response_retransmission
  */
-static int get_last_status(struct sip_msg* msg, int *last_status)
+static int get_last_status(struct sip_msg *msg, int *last_status)
 {
 	unsigned int branch;
 	char *bptr;
 	int blen;
 	struct cell *t;
 
-/*	DBG("select_tm_uac_last_status: branch param name: '%.*s', value: '%.*s'\n",
+	/*	DBG("select_tm_uac_last_status: branch param name: '%.*s', value: '%.*s'\n",
 			msg->via1->branch->name.len,
 			msg->via1->branch->name.s,
 			msg->via1->branch->value.len,
@@ -181,22 +190,21 @@ static int get_last_status(struct sip_msg* msg, int *last_status)
 
 	/* branch ID consist of MAGIC '.' HASHID '.'  BRANCH_ID */
 	blen = 0;
-	for (bptr = msg->via1->branch->value.s + msg->via1->branch->value.len - 1;
-			bptr != msg->via1->branch->value.s;
-			bptr--, blen++)
-	{
-		if (*bptr == '.') break;
+	for(bptr = msg->via1->branch->value.s + msg->via1->branch->value.len - 1;
+			bptr != msg->via1->branch->value.s; bptr--, blen++) {
+		if(*bptr == '.')
+			break;
 	}
 	bptr++;
 	/* we have a pointer to the branch number */
 	/*	DBG("branch number: '%.*s'\n", blen, bptr); */
-	if (reverse_hex2int(bptr, blen, &branch) < 0) {
+	if(reverse_hex2int(bptr, blen, &branch) < 0) {
 		LM_ERR("Wrong branch number in Via1 branch param\n");
 		return -1;
 	}
 
 	t = get_t();
-	if ( (t == NULL) || (t == T_UNDEFINED) ) {
+	if((t == NULL) || (t == T_UNDEFINED)) {
 		LM_ERR("no transaction\n");
 		return -1;
 	}
@@ -208,10 +216,11 @@ static int get_last_status(struct sip_msg* msg, int *last_status)
 /**
  * Get last status in current branch.
  */
-static int select_tm_uac_last_status(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uac_last_status(str *res, select_t *s, struct sip_msg *msg)
 {
 	int last_status;
-	if (get_last_status(msg, &last_status) < 0) return -1;
+	if(get_last_status(msg, &last_status) < 0)
+		return -1;
 	return int_to_static_buffer(res, last_status);
 }
 /**
@@ -222,43 +231,44 @@ static int select_tm_uac_last_status(str* res, select_t* s, struct sip_msg* msg)
  *          otherwise returns -1 (not retransmited response).
  * @see get_last_status
  */
-static int select_tm_uac_response_retransmission(str* res, select_t* s,
-		struct sip_msg* msg)
+static int select_tm_uac_response_retransmission(
+		str *res, select_t *s, struct sip_msg *msg)
 {
 	int last_status, rv;
-	if (get_last_status(msg, &last_status) < 0) return -1;
+	if(get_last_status(msg, &last_status) < 0)
+		return -1;
 	rv = msg->first_line.u.reply.statuscode <= last_status ? 1 : -1;
 
 	/*	DBG("select_tm_uac_response_retransmission: %d\n", rv); */
 	return int_to_static_buffer(res, rv);
 }
 
-static int select_tm_uac_status(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uac_status(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check_branch(s, msg);
 	return int_to_static_buffer(res, t->uac[BRANCH_NO(s)].last_received);
 }
 
-static int select_tm_uac_uri(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uac_uri(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check_branch(s, msg);
 	RETURN0_res(t->uac[BRANCH_NO(s)].uri);
 }
 
 /* see select_tm_uas_request comments */
-static int select_tm_uac_response(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uac_response(str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check_branch(s, msg);
-	if (t->uac[BRANCH_NO(s)].reply) {
+	if(t->uac[BRANCH_NO(s)].reply) {
 		res->s = t->uac[BRANCH_NO(s)].reply->buf;
 		res->len = t->uac[BRANCH_NO(s)].reply->len;
 		return 0;
-	}
-	else
+	} else
 		return -1;
 }
 
-static int select_tm_uac_branch_request(str* res, select_t* s, struct sip_msg* msg)
+static int select_tm_uac_branch_request(
+		str *res, select_t *s, struct sip_msg *msg)
 {
 	SELECT_check_branch(s, msg);
 	res->s = t->uac[BRANCH_NO(s)].request.buffer;
@@ -267,32 +277,56 @@ static int select_tm_uac_branch_request(str* res, select_t* s, struct sip_msg* m
 }
 
 static select_row_t select_declaration[] = {
-	{ NULL, SEL_PARAM_STR, STR_STATIC_INIT("tm"), select_tm, 0},
-	{ select_tm, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_tm_method, 0},
-	{ select_tm, SEL_PARAM_STR, STR_STATIC_INIT("uas"), select_tm_uas, SEL_PARAM_EXPECTED},
-	{ select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("status"), select_tm_uas_status, 0},
-	{ select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("request"), select_tm_uas_request, 0},
-	{ select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("req"), select_tm_uas_request, 0},
-	{ select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("local_to_tag"), select_tm_uas_local_to_tag, 0},
-	{ select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("response"), select_tm_uas_response, 0},
-	{ select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("resp"), select_tm_uas_response, 0},
-	{ select_tm_uas_request, SEL_PARAM_STR, STR_STATIC_INIT("neg_ack_retransmission"), select_tm_uas_request_neg_ack_retransmission, 0},
-
-	{ select_tm, SEL_PARAM_STR, STR_STATIC_INIT("uac"), select_tm_uac, SEL_PARAM_EXPECTED},
-	{ select_tm_uac, SEL_PARAM_STR, STR_STATIC_INIT("count"), select_tm_uac_count, 0},
-	{ select_tm_uac, SEL_PARAM_STR, STR_STATIC_INIT("relayed"), select_tm_uac_relayed, 0},
-	{ select_tm_uac, SEL_PARAM_STR, STR_STATIC_INIT("last_status"), select_tm_uac_last_status, 0},  /* last status of current branch */
-	{ select_tm_uac, SEL_PARAM_STR, STR_STATIC_INIT("response_retransmission"), select_tm_uac_response_retransmission, 0},  /* last status of current branch */
-	{ select_tm_uac, SEL_PARAM_INT, STR_NULL, select_tm_uac_branch, SEL_PARAM_EXPECTED},
-	{ select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("status"), select_tm_uac_status, 0},
-	{ select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("uri"), select_tm_uac_uri, 0},
-	{ select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("response"), select_tm_uac_response, 0},
-	{ select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("resp"), select_tm_uac_response, 0},
-	{ select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("request"), select_tm_uac_branch_request, 0},
-	{ select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("req"), select_tm_uac_branch_request, 0},
-
-	{ NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}
-};
+		{NULL, SEL_PARAM_STR, STR_STATIC_INIT("tm"), select_tm, 0},
+		{select_tm, SEL_PARAM_STR, STR_STATIC_INIT("method"), select_tm_method,
+				0},
+		{select_tm, SEL_PARAM_STR, STR_STATIC_INIT("uas"), select_tm_uas,
+				SEL_PARAM_EXPECTED},
+		{select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("status"),
+				select_tm_uas_status, 0},
+		{select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("request"),
+				select_tm_uas_request, 0},
+		{select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("req"),
+				select_tm_uas_request, 0},
+		{select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("local_to_tag"),
+				select_tm_uas_local_to_tag, 0},
+		{select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("response"),
+				select_tm_uas_response, 0},
+		{select_tm_uas, SEL_PARAM_STR, STR_STATIC_INIT("resp"),
+				select_tm_uas_response, 0},
+		{select_tm_uas_request, SEL_PARAM_STR,
+				STR_STATIC_INIT("neg_ack_retransmission"),
+				select_tm_uas_request_neg_ack_retransmission, 0},
+
+		{select_tm, SEL_PARAM_STR, STR_STATIC_INIT("uac"), select_tm_uac,
+				SEL_PARAM_EXPECTED},
+		{select_tm_uac, SEL_PARAM_STR, STR_STATIC_INIT("count"),
+				select_tm_uac_count, 0},
+		{select_tm_uac, SEL_PARAM_STR, STR_STATIC_INIT("relayed"),
+				select_tm_uac_relayed, 0},
+		{select_tm_uac, SEL_PARAM_STR, STR_STATIC_INIT("last_status"),
+				select_tm_uac_last_status,
+				0}, /* last status of current branch */
+		{select_tm_uac, SEL_PARAM_STR,
+				STR_STATIC_INIT("response_retransmission"),
+				select_tm_uac_response_retransmission,
+				0}, /* last status of current branch */
+		{select_tm_uac, SEL_PARAM_INT, STR_NULL, select_tm_uac_branch,
+				SEL_PARAM_EXPECTED},
+		{select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("status"),
+				select_tm_uac_status, 0},
+		{select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("uri"),
+				select_tm_uac_uri, 0},
+		{select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("response"),
+				select_tm_uac_response, 0},
+		{select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("resp"),
+				select_tm_uac_response, 0},
+		{select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("request"),
+				select_tm_uac_branch_request, 0},
+		{select_tm_uac_branch, SEL_PARAM_STR, STR_STATIC_INIT("req"),
+				select_tm_uac_branch_request, 0},
+
+		{NULL, SEL_PARAM_INT, STR_NULL, NULL, 0}};
 
 int tm_init_selects()
 {

+ 73 - 67
src/modules/tm/t_append_branches.c

@@ -57,7 +57,8 @@
  *
  *   If the contact parameter is given, it must be of syntax:
  *     sip:<user>@<host>:<port>   (without parameters) */
-int t_append_branches(str * contact) {
+int t_append_branches(str *contact)
+{
 	struct cell *t = NULL;
 	struct sip_msg *orig_msg = NULL;
 	struct sip_msg *faked_req;
@@ -69,33 +70,33 @@ int t_append_branches(str * contact) {
 
 	str current_uri;
 	str dst_uri, path, instance, ruid, location_ua;
-	struct socket_info* si;
+	struct socket_info *si;
 	int q, i, found, append;
 	flag_t backup_bflags = 0;
 	flag_t bflags = 0;
 	int new_branch, branch_ret, lowest_ret;
-	branch_bm_t	added_branches;
+	branch_bm_t added_branches;
 	int replies_locked = 0;
 	int ret = 0;
 
 	t = get_t();
-	if(t == NULL)
-	{
+	if(t == NULL) {
 		LM_ERR("cannot get transaction\n");
 		return -1;
 	}
 
-	LM_DBG("transaction %u:%u in status %d\n", t->hash_index, t->label, t->uas.status);
+	LM_DBG("transaction %u:%u in status %d\n", t->hash_index, t->label,
+			t->uas.status);
 
 	/* test if transaction has already been canceled */
-	if (t->flags & T_CANCELED) {
-		ser_error=E_CANCELED;
+	if(t->flags & T_CANCELED) {
+		ser_error = E_CANCELED;
 		return -1;
 	}
 
-	if ((t->uas.status >= 200 && t->uas.status<=399)
+	if((t->uas.status >= 200 && t->uas.status <= 399)
 			|| ((t->uas.status >= 600 && t->uas.status)
-				&& !(t->flags & (T_6xx | T_DISABLE_6xx))) ) {
+					&& !(t->flags & (T_6xx | T_DISABLE_6xx)))) {
 		LM_DBG("transaction %u:%u in status %d: cannot append new branch\n",
 				t->hash_index, t->label, t->uas.status);
 		return -1;
@@ -107,137 +108,142 @@ int t_append_branches(str * contact) {
 	outgoings = t->nr_of_outgoings;
 	orig_msg = t->uas.request;
 
-	LM_DBG("Call %.*s: %d (%d) outgoing branches\n",orig_msg->callid->body.len,
-			orig_msg->callid->body.s,outgoings, nr_branches);
+	LM_DBG("Call %.*s: %d (%d) outgoing branches\n", orig_msg->callid->body.len,
+			orig_msg->callid->body.s, outgoings, nr_branches);
 
-	lowest_ret=E_UNSPEC;
-	added_branches=0;
+	lowest_ret = E_UNSPEC;
+	added_branches = 0;
 
 	/* it's a "late" branch so the on_branch variable has already been
 	reset by previous execution of t_forward_nonack: we use the saved
 	   value  */
-	if (t->on_branch_delayed) {
+	if(t->on_branch_delayed) {
 		/* tell add_uac that it should run branch route actions */
 		set_branch_route(t->on_branch_delayed);
 	}
-	faked_req = fake_req(orig_msg, 0, NULL,	&faked_req_len);
-	if (faked_req==NULL) {
+	faked_req = fake_req(orig_msg, 0, NULL, &faked_req_len);
+	if(faked_req == NULL) {
 		LM_ERR("fake_req failed\n");
 		return -1;
 	}
 
 	/* fake also the env. conforming to the fake msg */
-	faked_env( t, faked_req, 0);
+	faked_env(t, faked_req, 0);
 
 	/* DONE with faking ;-) -> run the failure handlers */
 	init_branch_iterator();
 
-	while((current_uri.s=next_branch( &current_uri.len, &q, &dst_uri, &path,
-										&bflags, &si, &ruid, &instance, &location_ua))) {
-		LM_DBG("Current uri %.*s\n",current_uri.len, current_uri.s);
+	while((current_uri.s = next_branch(&current_uri.len, &q, &dst_uri, &path,
+				   &bflags, &si, &ruid, &instance, &location_ua))) {
+		LM_DBG("Current uri %.*s\n", current_uri.len, current_uri.s);
 
 		/* if the contact parameter is given, then append by
 			an exact location that has been requested for this function call */
-		if (contact->s != NULL && contact->len != 0) {
+		if(contact->s != NULL && contact->len != 0) {
 
-			LM_DBG("Comparing requested contact <%.*s> against location <%.*s>\n",
-							contact->len, contact->s, current_uri.len, current_uri.s);
+			LM_DBG("Comparing requested contact <%.*s> against location "
+				   "<%.*s>\n",
+					contact->len, contact->s, current_uri.len, current_uri.s);
 
 			append = 1;
-			if (strstr(current_uri.s, contact->s) == NULL) {
+			if(strstr(current_uri.s, contact->s) == NULL) {
 				append = 0; /* this while cycle will be stopped */
 			}
 
 			/* do not append the branch if a contact does not match */
-			if (!append)
+			if(!append)
 				continue;
 
-			LM_DBG("Branch will be appended for contact <%.*s>\n", contact->len, contact->s);
+			LM_DBG("Branch will be appended for contact <%.*s>\n", contact->len,
+					contact->s);
 		}
 
 		found = 0;
-		for (i=0; i<outgoings; i++) {
-			if (t->uac[i].ruid.len == ruid.len
+		for(i = 0; i < outgoings; i++) {
+			if(t->uac[i].ruid.len == ruid.len
 					&& !memcmp(t->uac[i].ruid.s, ruid.s, ruid.len)
 					&& t->uac[i].uri.len == current_uri.len
-					&& !memcmp(t->uac[i].uri.s, current_uri.s, current_uri.len)) {
+					&& !memcmp(
+							t->uac[i].uri.s, current_uri.s, current_uri.len)) {
 				LM_DBG("branch already added [%.*s]\n", ruid.len, ruid.s);
 				found = 1;
 				break;
 			}
 		}
-		if (found)
+		if(found)
 			continue;
 
 		setbflagsval(0, bflags);
-		new_branch=add_uac( t, faked_req, &current_uri,
-					(dst_uri.len) ? (&dst_uri) : &current_uri,
-					&path, 0, si, faked_req->fwd_send_flags,
-					PROTO_NONE, (dst_uri.len)?0:UAC_SKIP_BR_DST_F, &instance,
-					&ruid, &location_ua);
+		new_branch = add_uac(t, faked_req, &current_uri,
+				(dst_uri.len) ? (&dst_uri) : &current_uri, &path, 0, si,
+				faked_req->fwd_send_flags, PROTO_NONE,
+				(dst_uri.len) ? 0 : UAC_SKIP_BR_DST_F, &instance, &ruid,
+				&location_ua);
 
-		LM_DBG("added branch [%.*s] with ruid [%.*s]\n",
-				current_uri.len, current_uri.s, ruid.len, ruid.s);
+		LM_DBG("added branch [%.*s] with ruid [%.*s]\n", current_uri.len,
+				current_uri.s, ruid.len, ruid.s);
 
 		/* test if cancel was received meanwhile */
-		if (t->flags & T_CANCELED) goto canceled;
+		if(t->flags & T_CANCELED)
+			goto canceled;
 
-		if (new_branch>=0)
-			added_branches |= 1<<new_branch;
+		if(new_branch >= 0)
+			added_branches |= 1 << new_branch;
 		else
-			lowest_ret=MIN_int(lowest_ret, new_branch);
+			lowest_ret = MIN_int(lowest_ret, new_branch);
 	}
 
 	clear_branches();
 
 	LM_DBG("Call %.*s: %d (%d) outgoing branches after clear_branches()\n",
-			orig_msg->callid->body.len, orig_msg->callid->body.s,outgoings, nr_branches);
+			orig_msg->callid->body.len, orig_msg->callid->body.s, outgoings,
+			nr_branches);
 	setbflagsval(0, backup_bflags);
 
 	/* update message flags, if changed in branch route */
 	t->uas.request->flags = faked_req->flags;
 
-	if (added_branches==0) {
-		if(lowest_ret!=E_CFG)
+	if(added_branches == 0) {
+		if(lowest_ret != E_CFG)
 			LM_ERR("failure to add branches (%d)\n", lowest_ret);
-		ser_error=lowest_ret;
+		ser_error = lowest_ret;
 		ret = lowest_ret;
 		goto done;
 	}
 
-	ser_error=0; /* clear branch adding errors */
+	ser_error = 0; /* clear branch adding errors */
 	/* send them out now */
-	success_branch=0;
+	success_branch = 0;
 	/* since t_append_branch can only be called from REQUEST_ROUTE, always lock replies */
 
-	for (i=outgoings; i<t->nr_of_outgoings; i++) {
-		if (added_branches & (1<<i)) {
-			branch_ret=t_send_branch(t, i, faked_req , 0, 0 /* replies are already locked */ );
-			if (branch_ret>=0){ /* some kind of success */
-				if (branch_ret==i) { /* success */
+	for(i = outgoings; i < t->nr_of_outgoings; i++) {
+		if(added_branches & (1 << i)) {
+			branch_ret = t_send_branch(
+					t, i, faked_req, 0, 0 /* replies are already locked */);
+			if(branch_ret >= 0) {	  /* some kind of success */
+				if(branch_ret == i) { /* success */
 					success_branch++;
-					if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
-						run_trans_callbacks_with_buf( TMCB_REQUEST_OUT,
-								&t->uac[nr_branches].request,
-								faked_req, 0, TMCB_NONE_F);
-				}
-				else /* new branch added */
-					added_branches |= 1<<branch_ret;
+					if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
+						run_trans_callbacks_with_buf(TMCB_REQUEST_OUT,
+								&t->uac[nr_branches].request, faked_req, 0,
+								TMCB_NONE_F);
+				} else /* new branch added */
+					added_branches |= 1 << branch_ret;
 			}
 		}
 	}
-	if (success_branch<=0) {
+	if(success_branch <= 0) {
 		/* return always E_SEND for now
 		 * (the real reason could be: denied by onsend routes, blocklisted,
 		 *  send failed or any of the errors listed before + dns failed
 		 *  when attempting dns failover) */
-		ser_error=E_SEND;
+		ser_error = E_SEND;
 		/* else return the last error (?) */
 		ret = -1;
 		goto done;
 	}
 
-	ser_error=0; /* clear branch send errors, we have overall success */
+	ser_error = 0; /* clear branch send errors, we have overall success */
 	set_kr(REQ_FWDED);
 	ret = success_branch;
 	goto done;
@@ -251,17 +257,17 @@ canceled:
 	/* update message flags, if changed in branch route */
 	t->uas.request->flags = faked_req->flags;
 	/* if needed unlock transaction's replies */
-		/* restore the number of outgoing branches
+	/* restore the number of outgoing branches
 		 * since new branches have not been completed */
 	t->nr_of_outgoings = outgoings;
-	ser_error=E_CANCELED;
+	ser_error = E_CANCELED;
 	ret = -1;
 done:
 	/* restore original environment and free the fake msg */
-	faked_env( t, 0, 0);
+	faked_env(t, 0, 0);
 	free_faked_req(faked_req, faked_req_len);
 
-	if (likely(replies_locked)) {
+	if(likely(replies_locked)) {
 		replies_locked = 0;
 		UNLOCK_REPLIES(t);
 	}

+ 2 - 2
src/modules/tm/t_append_branches.h

@@ -31,7 +31,7 @@
 #include "../../core/proxy.h"
 #include "h_table.h"
 
-int t_append_branches(str * contact);
-typedef int (*t_append_branches_f)(str * contact);
+int t_append_branches(str *contact);
+typedef int (*t_append_branches_f)(str *contact);
 
 #endif

+ 150 - 147
src/modules/tm/t_cancel.c

@@ -36,28 +36,27 @@
 #include "t_hooks.h"
 
 
-typedef struct cancel_reason_map {
+typedef struct cancel_reason_map
+{
 	int code;
 	str text;
 } cancel_reason_map_t;
 
 static cancel_reason_map_t _cancel_reason_map[] = {
-	{ 200, str_init("Call completed elsewhere") },
-	{ 0, {0, 0} }
-};
+		{200, str_init("Call completed elsewhere")}, {0, {0, 0}}};
 
 /**
  *
  */
-void cancel_reason_text(struct cancel_info* cancel_data)
+void cancel_reason_text(struct cancel_info *cancel_data)
 {
 	int i;
 
-	if(cancel_data->reason.cause<=0
-			|| cancel_data->reason.u.text.s!=NULL) return;
+	if(cancel_data->reason.cause <= 0 || cancel_data->reason.u.text.s != NULL)
+		return;
 
-	for(i=0; _cancel_reason_map[i].text.s!=0; i++) {
-		if(_cancel_reason_map[i].code==cancel_data->reason.cause) {
+	for(i = 0; _cancel_reason_map[i].text.s != 0; i++) {
+		if(_cancel_reason_map[i].code == cancel_data->reason.cause) {
 			cancel_data->reason.u.text = _cancel_reason_map[i].text;
 			return;
 		}
@@ -81,25 +80,24 @@ void cancel_reason_text(struct cancel_info* cancel_data)
 *    !=0).
 *  @param skip - branch bitmap of branches that should not be canceled
 */
-void prepare_to_cancel(struct cell *t, branch_bm_t *cancel_bm,
-						branch_bm_t skip_branches)
+void prepare_to_cancel(
+		struct cell *t, branch_bm_t *cancel_bm, branch_bm_t skip_branches)
 {
 	int i;
 	int branches_no;
 	branch_bm_t mask;
 
-	*cancel_bm=0;
-	branches_no=t->nr_of_outgoings;
-	mask=~skip_branches;
+	*cancel_bm = 0;
+	branches_no = t->nr_of_outgoings;
+	mask = ~skip_branches;
 	membar_depends();
-	for( i=0 ; i<branches_no ; i++ ) {
-		*cancel_bm |= ((mask & (1<<i)) &&  prepare_cancel_branch(t, i, 1))<<i;
+	for(i = 0; i < branches_no; i++) {
+		*cancel_bm |= ((mask & (1 << i)) && prepare_cancel_branch(t, i, 1))
+					  << i;
 	}
 }
 
 
-
-
 /* cancel branches scheduled for deletion
  * params: t          - transaction
  *          cancel_data - structure filled with the cancel bitmap (bitmap with
@@ -109,27 +107,26 @@ void prepare_to_cancel(struct cell *t, branch_bm_t *cancel_bm,
  * returns: bitmap with the still active branches (on fr timer)
  * WARNING: always fill cancel_data->cancel_bitmap using prepare_to_cancel(),
  *          supplying values in any other way is a bug*/
-int cancel_uacs( struct cell *t, struct cancel_info* cancel_data, int flags)
+int cancel_uacs(struct cell *t, struct cancel_info *cancel_data, int flags)
 {
 	int i;
 	int ret;
 	int r;
 
-	ret=0;
+	ret = 0;
 
 	cancel_reason_text(cancel_data);
 
 	/* cancel pending client transactions, if any */
-	for( i=0 ; i<t->nr_of_outgoings ; i++ )
-		if (cancel_data->cancel_bitmap & (1<<i)){
-			r=cancel_branch(
-				t,
-				i,
-				&cancel_data->reason,
-				flags | ((t->uac[i].request.buffer==NULL)?
-					F_CANCEL_B_FAKE_REPLY:0) /* blind UAC? */
+	for(i = 0; i < t->nr_of_outgoings; i++)
+		if(cancel_data->cancel_bitmap & (1 << i)) {
+			r = cancel_branch(t, i, &cancel_data->reason,
+					flags
+							| ((t->uac[i].request.buffer == NULL)
+											? F_CANCEL_B_FAKE_REPLY
+											: 0) /* blind UAC? */
 			);
-			ret|=(r!=0)<<i;
+			ret |= (r != 0) << i;
 		}
 	return ret;
 }
@@ -137,7 +134,7 @@ int cancel_uacs( struct cell *t, struct cancel_info* cancel_data, int flags)
 int cancel_all_uacs(struct cell *trans, int how)
 {
 	struct cancel_info cancel_data;
-	int i,j;
+	int i, j;
 
 #ifdef EXTRA_DEBUG
 	assert(trans);
@@ -146,18 +143,18 @@ int cancel_all_uacs(struct cell *trans, int how)
 
 	init_cancel_info(&cancel_data);
 	prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0);
-	 /* tell tm to cancel the call */
-	i=cancel_uacs(trans, &cancel_data, how);
+	/* tell tm to cancel the call */
+	i = cancel_uacs(trans, &cancel_data, how);
 
-	if (how & F_CANCEL_UNREF)
+	if(how & F_CANCEL_UNREF)
 		UNREF(trans);
 
 	/* count the still active branches */
-	if (! how) {
-		j=0;
-		while(i){
+	if(!how) {
+		j = 0;
+		while(i) {
 			j++;
-			i&=i-1;
+			i &= i - 1;
 		}
 		return j;
 	}
@@ -203,49 +200,48 @@ int cancel_all_uacs(struct cell *trans, int how)
  *          - checking for buffer==0 under REPLY_LOCK is no enough, an
  *           atomic_cmpxhcg or atomic_get_and_set _must_ be used.
  */
-int cancel_branch( struct cell *t, int branch,
-					struct cancel_reason* reason,
-					int flags )
+int cancel_branch(
+		struct cell *t, int branch, struct cancel_reason *reason, int flags)
 {
 	char *cancel;
 	unsigned int len;
 	struct retr_buf *crb, *irb;
 	int ret;
 	struct cancel_info tmp_cd;
-	void* pcbuf;
+	void *pcbuf;
 	int reply_status;
 
-	crb=&t->uac[branch].local_cancel;
-	irb=&t->uac[branch].request;
-	irb->flags|=F_RB_CANCELED;
-	ret=1;
+	crb = &t->uac[branch].local_cancel;
+	irb = &t->uac[branch].request;
+	irb->flags |= F_RB_CANCELED;
+	ret = 1;
 	init_cancel_info(&tmp_cd);
 
-#	ifdef EXTRA_DEBUG
-	if (crb->buffer!=BUSY_BUFFER) {
+#ifdef EXTRA_DEBUG
+	if(crb->buffer != BUSY_BUFFER) {
 		LM_CRIT("attempt to rewrite cancel buffer: %p\n", crb->buffer);
 		abort();
 	}
-#	endif
+#endif
 
-	if (flags & F_CANCEL_B_KILL){
-		stop_rb_timers( irb );
-		ret=0;
-		if ((t->uac[branch].last_received < 100) &&
-				!(flags & F_CANCEL_B_FORCE_C)) {
+	if(flags & F_CANCEL_B_KILL) {
+		stop_rb_timers(irb);
+		ret = 0;
+		if((t->uac[branch].last_received < 100)
+				&& !(flags & F_CANCEL_B_FORCE_C)) {
 			LM_DBG("no response ever received: giving up on cancel\n");
 			/* remove BUSY_BUFFER -- mark cancel buffer as not used */
-			pcbuf=&crb->buffer; /* workaround for type punning warnings */
+			pcbuf = &crb->buffer; /* workaround for type punning warnings */
 			atomic_set_long(pcbuf, 0);
 			/* try to relay auto-generated 487 canceling response only when
 			 * another one is not under relaying on the branch and there is
 			 * no forced response per transaction from script */
 			if((flags & F_CANCEL_B_FAKE_REPLY)
-					&& !(irb->flags&F_RB_RELAYREPLY)
-					&& !(t->flags&T_ADMIN_REPLY)) {
+					&& !(irb->flags & F_RB_RELAYREPLY)
+					&& !(t->flags & T_ADMIN_REPLY)) {
 				LOCK_REPLIES(t);
-				reply_status = relay_reply(t, FAKED_REPLY, branch, 487,
-						&tmp_cd, 1);
+				reply_status =
+						relay_reply(t, FAKED_REPLY, branch, 487, &tmp_cd, 1);
 				if(reply_status == RPS_ERROR || reply_status == RPS_TGONE) {
 					return -1;
 				}
@@ -253,21 +249,21 @@ int cancel_branch( struct cell *t, int branch,
 			/* do nothing, hope that the caller will clean up */
 			return ret;
 		}
-	}else{
-		if (t->uac[branch].last_received < 100){
-			if (!(flags & F_CANCEL_B_FORCE_C)) {
+	} else {
+		if(t->uac[branch].last_received < 100) {
+			if(!(flags & F_CANCEL_B_FORCE_C)) {
 				/* no response received => don't send a cancel on this branch,
 				 *  just drop it */
-				if (!(flags & F_CANCEL_B_FORCE_RETR))
+				if(!(flags & F_CANCEL_B_FORCE_RETR))
 					stop_rb_retr(irb); /* stop retransmissions */
 				/* remove BUSY_BUFFER -- mark cancel buffer as not used */
-				pcbuf=&crb->buffer; /* workaround for type punning warnings */
+				pcbuf = &crb->buffer; /* workaround for type punning warnings */
 				atomic_set_long(pcbuf, 0);
-				if (flags & F_CANCEL_B_FAKE_REPLY){
-					stop_rb_timers( irb ); /* stop even the fr timer */
+				if(flags & F_CANCEL_B_FAKE_REPLY) {
+					stop_rb_timers(irb); /* stop even the fr timer */
 					LOCK_REPLIES(t);
-					reply_status = relay_reply(t, FAKED_REPLY, branch, 487,
-							&tmp_cd, 1);
+					reply_status = relay_reply(
+							t, FAKED_REPLY, branch, 487, &tmp_cd, 1);
 					if(reply_status == RPS_ERROR || reply_status == RPS_TGONE) {
 						return -1;
 					}
@@ -280,24 +276,29 @@ int cancel_branch( struct cell *t, int branch,
 		stop_rb_retr(irb); /* stop retransmissions */
 	}
 
-	if (cfg_get(tm, tm_cfg, reparse_invite) ||
-			(t->uas.request && t->uas.request->msg_flags&(FL_USE_UAC_FROM|FL_USE_UAC_TO))) {
+	if(cfg_get(tm, tm_cfg, reparse_invite)
+			|| (t->uas.request
+					&& t->uas.request->msg_flags
+							   & (FL_USE_UAC_FROM | FL_USE_UAC_TO))) {
 		/* build the CANCEL from the INVITE which was sent out */
 		cancel = build_local_reparse(t, branch, &len, CANCEL, CANCEL_LEN,
-					(t->uas.request && t->uas.request->msg_flags&FL_USE_UAC_TO)?0:&t->to_hdr,
-					reason);
+				(t->uas.request && t->uas.request->msg_flags & FL_USE_UAC_TO)
+						? 0
+						: &t->to_hdr,
+				reason);
 	} else {
 		/* build the CANCEL from the received INVITE */
-		cancel = build_local(t, branch, &len, CANCEL, CANCEL_LEN, &t->to_hdr, reason);
+		cancel = build_local(
+				t, branch, &len, CANCEL, CANCEL_LEN, &t->to_hdr, reason);
 	}
-	if (!cancel || len<=0) {
+	if(!cancel || len <= 0) {
 		LM_ERR("attempt to build a CANCEL failed\n");
 		if(cancel) {
 			shm_free(cancel);
 			cancel = NULL;
 		}
 		/* remove BUSY_BUFFER -- mark cancel buffer as not used */
-		pcbuf=&crb->buffer; /* workaround for type punning warnings */
+		pcbuf = &crb->buffer; /* workaround for type punning warnings */
 		atomic_set_long(pcbuf, 0);
 		return -1;
 	}
@@ -309,10 +310,12 @@ int cancel_branch( struct cell *t, int branch,
 	crb->rbtype = TYPE_LOCAL_CANCEL;
 	/* be extra carefully and check for bugs (the below if could be replaced
 	 *  by an atomic_set((void*)&crb->buffer, cancel) */
-	if (unlikely(atomic_cmpxchg_long((void*)&crb->buffer, (long)BUSY_BUFFER,
-							(long)cancel)!= (long)BUSY_BUFFER)){
+	if(unlikely(atomic_cmpxchg_long(
+						(void *)&crb->buffer, (long)BUSY_BUFFER, (long)cancel)
+				!= (long)BUSY_BUFFER)) {
 		LM_BUG("local_cancel buffer=%p != BUSY_BUFFER"
-				" (trying to continue)\n", crb->buffer);
+			   " (trying to continue)\n",
+				crb->buffer);
 		shm_free(cancel);
 		return -1;
 	}
@@ -323,14 +326,16 @@ int cancel_branch( struct cell *t, int branch,
 	crb->buffer_len = len;
 
 	LM_DBG("sending cancel...\n");
-	if (SEND_BUFFER( crb )>=0){
-		if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
-			run_trans_callbacks_with_buf(TMCB_REQUEST_OUT, crb, t->uas.request, 0, TMCB_LOCAL_F);
-		if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
-			run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, crb, t->uas.request, 0, TMCB_LOCAL_F);
+	if(SEND_BUFFER(crb) >= 0) {
+		if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_OUT)))
+			run_trans_callbacks_with_buf(
+					TMCB_REQUEST_OUT, crb, t->uas.request, 0, TMCB_LOCAL_F);
+		if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT)))
+			run_trans_callbacks_with_buf(
+					TMCB_REQUEST_SENT, crb, t->uas.request, 0, TMCB_LOCAL_F);
 	}
 	/*sets and starts the FINAL RESPONSE timer */
-	if (start_retr( crb )!=0)
+	if(start_retr(crb) != 0)
 		LM_CRIT("failed to start retransmission for %p\n", crb);
 	return ret;
 }
@@ -343,86 +348,84 @@ int cancel_branch( struct cell *t, int branch,
  * callid\n
  * cseq\n
  */
-void rpc_cancel(rpc_t* rpc, void* c)
+void rpc_cancel(rpc_t *rpc, void *c)
 {
 	struct cell *trans;
 	static char cseq[128], callid[128];
 	struct cancel_info cancel_data;
-	int i,j;
+	int i, j;
 
-	str cseq_s;   /* cseq */
+	str cseq_s;	  /* cseq */
 	str callid_s; /* callid */
 
-	cseq_s.s=cseq;
-	callid_s.s=callid;
+	cseq_s.s = cseq;
+	callid_s.s = callid;
 	init_cancel_info(&cancel_data);
 
-	if (rpc->scan(c, "SS", &callid_s, &cseq_s) < 2) {
+	if(rpc->scan(c, "SS", &callid_s, &cseq_s) < 2) {
 		rpc->fault(c, 400, "Callid and CSeq expected as parameters");
 		return;
 	}
 
-	if( t_lookup_callid(&trans, callid_s, cseq_s) < 0 ) {
+	if(t_lookup_callid(&trans, callid_s, cseq_s) < 0) {
 		LM_DBG("Lookup failed\n");
 		rpc->fault(c, 400, "Transaction not found");
 		return;
 	}
 	/*  find the branches that need cancel-ing */
 	prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0);
-	 /* tell tm to cancel the call */
+	/* tell tm to cancel the call */
 	DBG("Now calling cancel_uacs\n");
-	i=cancel_uacs(trans, &cancel_data, 0); /* don't fake 487s,
+	i = cancel_uacs(trans, &cancel_data, 0); /* don't fake 487s,
 										 just wait for timeout */
 
 	/* t_lookup_callid REF`d the transaction for us, we must UNREF here! */
 	UNREF(trans);
-	j=0;
-	while(i){
+	j = 0;
+	while(i) {
 		j++;
-		i&=i-1;
+		i &= i - 1;
 	}
 	rpc->add(c, "ds", j, "branches remaining (waiting for timeout)");
 }
 
 
-
 /* returns <0 on error */
-int cancel_b_flags_get(unsigned int* f, int m)
+int cancel_b_flags_get(unsigned int *f, int m)
 {
 	int ret;
 
-	ret=0;
-	switch(m){
+	ret = 0;
+	switch(m) {
 		case 1:
-			*f=F_CANCEL_B_FORCE_RETR;
+			*f = F_CANCEL_B_FORCE_RETR;
 			break;
 		case 0:
-			*f=F_CANCEL_B_FAKE_REPLY;
+			*f = F_CANCEL_B_FAKE_REPLY;
 			break;
 		case 2:
-			*f=F_CANCEL_B_FORCE_C;
+			*f = F_CANCEL_B_FORCE_C;
 			break;
 		default:
-			*f=F_CANCEL_B_FAKE_REPLY;
-			ret=-1;
+			*f = F_CANCEL_B_FAKE_REPLY;
+			ret = -1;
 	}
 	return ret;
 }
 
 
-
 /* fixup function for the default cancel branch method/flags
  * (called by the configuration framework) */
-int cancel_b_flags_fixup(void* handle, str* gname, str* name, void** val)
+int cancel_b_flags_fixup(void *handle, str *gname, str *name, void **val)
 {
-	unsigned int m,f;
+	unsigned int m, f;
 	int ret;
 
-	m=(unsigned int)(long)(*val);
-	ret=cancel_b_flags_get(&f, m);
-	if (ret<0)
+	m = (unsigned int)(long)(*val);
+	ret = cancel_b_flags_get(&f, m);
+	if(ret < 0)
 		LM_ERR("invalid value for %.*s; %d\n", name->len, name->s, m);
-	*val=(void*)(long)f;
+	*val = (void *)(long)f;
 	return ret;
 }
 
@@ -432,49 +435,49 @@ int cancel_b_flags_fixup(void* handle, str* gname, str* name, void** val)
  * transaction. The cancel parameter should NOT have any via (CANCEL is
  * hop by hop). returns 0 if error return >0 if OK (returns the LABEL of
  * the cancel).*/
-unsigned int t_uac_cancel( str *headers, str *body,
+unsigned int t_uac_cancel(str *headers, str *body,
 		unsigned int cancelled_hashIdx, unsigned int cancelled_label,
-		transaction_cb cb, void* cbp)
+		transaction_cb cb, void *cbp)
 {
-	struct cell *t_invite,*cancel_cell;
-	struct retr_buf *cancel,*invite;
-	unsigned int len,ret;
+	struct cell *t_invite, *cancel_cell;
+	struct retr_buf *cancel, *invite;
+	unsigned int len, ret;
 	char *buf;
 
-	ret=0;
-	if(t_lookup_ident(&t_invite,cancelled_hashIdx,cancelled_label)<0){
+	ret = 0;
+	if(t_lookup_ident(&t_invite, cancelled_hashIdx, cancelled_label) < 0) {
 		LM_ERR("failed to t_lookup_ident hash_idx=%d,"
-				"label=%d\n", cancelled_hashIdx,cancelled_label);
+			   "label=%d\n",
+				cancelled_hashIdx, cancelled_label);
 		return 0;
 	}
 	/* <sanity_checks> */
-	if(! is_local(t_invite))
-	{
+	if(!is_local(t_invite)) {
 		LM_ERR("tried to cancel a non-local transaction\n");
 		goto error3;
 	}
-	if(t_invite->uac[0].last_received < 100)
-	{
+	if(t_invite->uac[0].last_received < 100) {
 		LM_WARN("trying to cancel a transaction not in "
-					"Proceeding state !\n");
+				"Proceeding state !\n");
 		goto error3;
 	}
-	if(t_invite->uac[0].last_received > 200)
-	{
+	if(t_invite->uac[0].last_received > 200) {
 		LM_WARN("trying to cancel a completed transaction !\n");
 		goto error3;
 	}
 	/* </sanity_checks*/
 	/* <build_cell> */
-	if(!(cancel_cell = build_cell(0))){
-		ret=0;
+	if(!(cancel_cell = build_cell(0))) {
+		ret = 0;
 		LM_ERR("no more shm memory!\n");
 		goto error3;
 	}
 	reset_avps();
-	if(cb && insert_tmcb(&(cancel_cell->tmcb_hl),
-			TMCB_RESPONSE_IN|TMCB_LOCAL_COMPLETED,cb,cbp,0)!=1){
-		ret=0;
+	if(cb
+			&& insert_tmcb(&(cancel_cell->tmcb_hl),
+					   TMCB_RESPONSE_IN | TMCB_LOCAL_COMPLETED, cb, cbp, 0)
+					   != 1) {
+		ret = 0;
 		LM_ERR("short of tmcb shmem !\n");
 		goto error2;
 	}
@@ -482,49 +485,49 @@ unsigned int t_uac_cancel( str *headers, str *body,
 
 	/* <insert_into_hashtable> */
 	cancel_cell->flags |= T_IS_LOCAL_FLAG;
-	cancel_cell->hash_index=t_invite->hash_index;
+	cancel_cell->hash_index = t_invite->hash_index;
 
 	LOCK_HASH(cancel_cell->hash_index);
-	insert_into_hash_table_unsafe(cancel_cell,cancel_cell->hash_index);
-	ret=cancel_cell->label;
-	cancel_cell->label=t_invite->label;
+	insert_into_hash_table_unsafe(cancel_cell, cancel_cell->hash_index);
+	ret = cancel_cell->label;
+	cancel_cell->label = t_invite->label;
 	UNLOCK_HASH(cancel_cell->hash_index);
 	/* </insert_into_hashtable> */
 
 	/* <prepare_cancel> */
 
-	cancel=&cancel_cell->uac[0].request;
-	invite=&t_invite->uac[0].request;
+	cancel = &cancel_cell->uac[0].request;
+	invite = &t_invite->uac[0].request;
 
-	cancel->dst.to              = invite->dst.to;
-	cancel->dst.send_sock       = invite->dst.send_sock;
-	cancel->dst.proto           = invite->dst.proto;
+	cancel->dst.to = invite->dst.to;
+	cancel->dst.send_sock = invite->dst.send_sock;
+	cancel->dst.proto = invite->dst.proto;
 	//cancel->dst.proto_reserved1 = invite->dst.proto_reserved1;
 
 	buf = build_uac_cancel(headers, body, t_invite, 0, &len, &(cancel->dst));
-	if(!buf || len<=0) {
+	if(!buf || len <= 0) {
 		if(buf) {
 			shm_free(buf);
 			buf = NULL;
 		}
-		ret=0;
+		ret = 0;
 		LM_ERR("attempt to build a CANCEL failed\n");
 		goto error1;
 	}
-	cancel->buffer=buf;
-	cancel->buffer_len=len;
+	cancel->buffer = buf;
+	cancel->buffer_len = len;
 	cancel_cell->method.s = buf;
 	cancel_cell->method.len = 6 /*c-a-n-c-e-l*/;
 	/* </prepare_cancel> */
 
 	/* <strart_sending> */
 	cancel_cell->nr_of_outgoings++;
-	if (SEND_BUFFER(cancel)==-1) {
-		ret=0;
+	if(SEND_BUFFER(cancel) == -1) {
+		ret = 0;
 		LM_ERR("send failed\n");
 		goto error1;
 	}
-	if(start_retr(cancel)!=0) {
+	if(start_retr(cancel) != 0) {
 		LM_CRIT("failed to start retransmission for cancel %p\n", cancel);
 	}
 	/* </start_sending> */

+ 30 - 28
src/modules/tm/t_cancel.h

@@ -43,17 +43,21 @@
 #define BUSY_BUFFER ((char *)-1)
 
 /* flags for cancel_uacs(), cancel_branch() */
-#define F_CANCEL_B_KILL 1  /*  will completely stop the  branch (stops the
+#define F_CANCEL_B_KILL \
+	1 /*  will completely stop the  branch (stops the
 							   timers), use only before a put_on_wait()
 							   or set_final_timer()*/
-#define F_CANCEL_B_FAKE_REPLY 2 /* will send a fake 487 to all branches that
+#define F_CANCEL_B_FAKE_REPLY \
+	2 /* will send a fake 487 to all branches that
 								 haven't received any response (>=100). It
 								 assumes the REPLY_LOCK is not held (if it is
 								 => deadlock) */
-#define F_CANCEL_B_FORCE_C 4 /* will send a cancel even if no reply was 
+#define F_CANCEL_B_FORCE_C \
+	4 /* will send a cancel even if no reply was 
 								received; F_CANCEL_B_FAKE_REPLY will be 
 								ignored */
-#define F_CANCEL_B_FORCE_RETR 8  /* will not stop request retr. on a branch
+#define F_CANCEL_B_FORCE_RETR \
+	8					  /* will not stop request retr. on a branch
 									if no provisional response was received;
 									F_CANCEL_B_FORCE_C, F_CANCEL_B_FAKE_REPLY
 									and F_CANCE_B_KILL take precedence */
@@ -61,18 +65,17 @@
 
 
 void prepare_to_cancel(struct cell *t, branch_bm_t *cancel_bm, branch_bm_t s);
-int cancel_uacs( struct cell *t, struct cancel_info* cancel_data, int flags );
+int cancel_uacs(struct cell *t, struct cancel_info *cancel_data, int flags);
 int cancel_all_uacs(struct cell *trans, int how);
-int cancel_branch( struct cell *t, int branch,
-					struct cancel_reason* reason,
-					int flags );
+int cancel_branch(
+		struct cell *t, int branch, struct cancel_reason *reason, int flags);
 
-typedef int(*cancel_uacs_f)(struct cell *t, struct cancel_info* cancel_data,
-		int flags);
+typedef int (*cancel_uacs_f)(
+		struct cell *t, struct cancel_info *cancel_data, int flags);
 typedef int (*cancel_all_uacs_f)(struct cell *trans, int how);
 
-typedef void (*prepare_to_cancel_f)(struct cell *t, branch_bm_t *cancel_bm,
-									branch_bm_t skip_branches);
+typedef void (*prepare_to_cancel_f)(
+		struct cell *t, branch_bm_t *cancel_bm, branch_bm_t skip_branches);
 
 
 /** Check if one branch needs CANCEL-ing and prepare it if it does.
@@ -95,38 +98,37 @@ typedef void (*prepare_to_cancel_f)(struct cell *t, branch_bm_t *cancel_bm,
  *  cancel-in-progress) and 0 if it doesn't (either a CANCEL is not needed or a
  *  CANCEL is in progress: somebody else is trying to CANCEL in the same time).
  */
-inline short static prepare_cancel_branch( struct cell *t, int b, int noreply )
+inline short static prepare_cancel_branch(struct cell *t, int b, int noreply)
 {
 	int last_received;
 	unsigned long old;
 
 	/* blind uac branch (e.g., suspend) without outgoing request */
 	if((t->uac[b].flags & TM_UAC_FLAG_BLIND)
-			&& t->uac[b].request.buffer==NULL)
+			&& t->uac[b].request.buffer == NULL)
 		return 0;
 
-	last_received=t->uac[b].last_received;
+	last_received = t->uac[b].last_received;
 	/* if noreply=1 cancel even if no reply received (in this case
 	 * cancel_branch()  won't actually send the cancel but it will do the
 	 * cleanup) */
-	if (last_received<200 && (noreply || last_received>=100)){
-		old=atomic_cmpxchg_long((void*)&t->uac[b].local_cancel.buffer, 0,
-									(long)(BUSY_BUFFER));
-		return old==0;
+	if(last_received < 200 && (noreply || last_received >= 100)) {
+		old = atomic_cmpxchg_long(
+				(void *)&t->uac[b].local_cancel.buffer, 0, (long)(BUSY_BUFFER));
+		return old == 0;
 	}
 	return 0;
 }
 
-void rpc_cancel(rpc_t* rpc, void* c);
-int cancel_b_flags_fixup(void* handle, str* gname, str* name, void** val);
-int cancel_b_flags_get(unsigned int* f, int m);
+void rpc_cancel(rpc_t *rpc, void *c);
+int cancel_b_flags_fixup(void *handle, str *gname, str *name, void **val);
+int cancel_b_flags_get(unsigned int *f, int m);
 
-typedef unsigned int (*tuaccancel_f)( str *headers,str *body,
-		unsigned int cancelledIdx,unsigned int cancelledLabel,
-		transaction_cb cb, void* cbp);
+typedef unsigned int (*tuaccancel_f)(str *headers, str *body,
+		unsigned int cancelledIdx, unsigned int cancelledLabel,
+		transaction_cb cb, void *cbp);
 
-unsigned int t_uac_cancel(str *headers,str *body,
-		unsigned int cancelledIdx,unsigned int cancelledLabel,
-		transaction_cb cb, void* cbp);
+unsigned int t_uac_cancel(str *headers, str *body, unsigned int cancelledIdx,
+		unsigned int cancelledLabel, transaction_cb cb, void *cbp);
 
 #endif

File diff ditekan karena terlalu besar
+ 342 - 310
src/modules/tm/t_fifo.c


+ 4 - 5
src/modules/tm/t_fifo.h

@@ -20,23 +20,22 @@
  */
 
 
-
 #ifndef _TM_T_FIFO_H_
 #define _TM_T_FIFO_H_
 
 #include "../../core/parser/msg_parser.h"
 #include "../../core/sr_module.h"
 
-int fixup_t_write( void** param, int param_no);
+int fixup_t_write(void **param, int param_no);
 
-int parse_tw_append( modparam_t type, void* val);
+int parse_tw_append(modparam_t type, void *val);
 
 int init_twrite_lines(void);
 
 int init_twrite_sock(void);
 
-int t_write_req(struct sip_msg* msg, char* vm_fifo, char* action);
+int t_write_req(struct sip_msg *msg, char *vm_fifo, char *action);
 
-int t_write_unix(struct sip_msg* msg, char* sock_name, char* action);
+int t_write_unix(struct sip_msg *msg, char *sock_name, char *action);
 
 #endif

+ 125 - 123
src/modules/tm/t_funcs.c

@@ -44,38 +44,40 @@
 #define TM_DELAYED_REPLY
 
 #ifdef USE_DNS_FAILOVER
-extern int** failover_reply_codes;
-extern int* failover_reply_codes_cnt;
+extern int **failover_reply_codes;
+extern int *failover_reply_codes_cnt;
 #endif
 
 /* fr_timer AVP specs */
-static int     fr_timer_avp_type = 0;
+static int fr_timer_avp_type = 0;
 static int_str fr_timer_avp = {0};
-static str     fr_timer_str;
-static int     fr_timer_index = 0;
-int     fr_inv_timer_avp_type = 0;
+static str fr_timer_str;
+static int fr_timer_index = 0;
+int fr_inv_timer_avp_type = 0;
 int_str fr_inv_timer_avp = {0};
-static str     fr_inv_timer_str;
-static int     fr_inv_timer_index = 0;
+static str fr_inv_timer_str;
+static int fr_inv_timer_index = 0;
 
 int tm_error = 0; /* delayed tm error */
 
-struct msgid_var user_cell_set_flags;   /* extra cell->flags to be set */
+struct msgid_var user_cell_set_flags;	/* extra cell->flags to be set */
 struct msgid_var user_cell_reset_flags; /* extra cell->flags to be reset */
 
 /* ----------------------------------------------------- */
-int send_pr_buffer(	struct retr_buf *rb, void *buf, int len
+int send_pr_buffer(struct retr_buf *rb, void *buf, int len
 #ifdef EXTRA_DEBUG
-						, char* file, const char *function, int line
+		,
+		char *file, const char *function, int line
 #endif
-					)
+)
 {
-	if (buf && len && rb )
-		return msg_send( &rb->dst, buf, len);
+	if(buf && len && rb)
+		return msg_send(&rb->dst, buf, len);
 	else {
 #ifdef EXTRA_DEBUG
 		LM_CRIT("sending an empty buffer"
-				"from %s: %s (%d)\n", file, function, line );
+				"from %s: %s (%d)\n",
+				file, function, line);
 #else
 		LM_CRIT("attempt to send an empty buffer\n");
 #endif
@@ -96,7 +98,7 @@ void tm_shutdown()
 #endif
 	/* destroy the hash table */
 	LM_DBG("emptying hash table\n");
-	free_hash_table( );
+	free_hash_table();
 	LM_DBG("removing semaphores\n");
 	lock_cleanup();
 	LM_DBG("destroying tmcb lists\n");
@@ -108,14 +110,14 @@ void tm_shutdown()
 
 /*   returns 1 if everything was OK or -1 for error
 */
-int t_release_transaction( struct cell *trans )
+int t_release_transaction(struct cell *trans)
 {
 	set_kr(REQ_RLSD);
 
 	stop_rb_timers(&trans->uas.response);
-	cleanup_uac_timers( trans );
+	cleanup_uac_timers(trans);
 
-	put_on_wait( trans );
+	put_on_wait(trans);
 	return 1;
 }
 
@@ -125,7 +127,7 @@ int t_release_transaction( struct cell *trans )
 
 /*
  */
-void put_on_wait(  struct cell  *Trans  )
+void put_on_wait(struct cell *Trans)
 {
 
 	LM_DBG("put T [%p] on wait\n", Trans);
@@ -147,13 +149,13 @@ void put_on_wait(  struct cell  *Trans  )
 		4.									WAIT timer executed,
 											transaction deleted
 	*/
-	if (timer_add(&Trans->wait_timer, cfg_get(tm, tm_cfg, wait_timeout))==0){
+	if(timer_add(&Trans->wait_timer, cfg_get(tm, tm_cfg, wait_timeout)) == 0) {
 		/* success */
 		t_stats_wait();
-	}else{
+	} else {
 		LM_DBG("transaction %p already on wait\n", Trans);
 	}
-	if(Trans->wait_start==0) {
+	if(Trans->wait_start == 0) {
 		Trans->wait_start = get_ticks_raw();
 	}
 }
@@ -161,14 +163,14 @@ void put_on_wait(  struct cell  *Trans  )
 
 int t_on_wait(tm_cell_t *Trans)
 {
-	if(Trans->wait_timer.prev!=NULL || Trans->wait_timer.next!=NULL)
+	if(Trans->wait_timer.prev != NULL || Trans->wait_timer.next != NULL)
 		return 1;
 	return 0;
 }
 
 /* WARNING: doesn't work from failure route (deadlock, uses t_reply =>
  *  tries to get the reply lock again) */
-int kill_transaction( struct cell *trans, int error )
+int kill_transaction(struct cell *trans, int error)
 {
 	char err_buffer[128];
 	int sip_err;
@@ -180,11 +182,10 @@ int kill_transaction( struct cell *trans, int error )
 		want to put the forking burden on upstream client;
 		however, it may fail too due to lack of memory */
 
-	ret=err2reason_phrase(error, &sip_err,
-		err_buffer, sizeof(err_buffer), "TM" );
-	if (ret>0) {
-		reply_ret=t_reply( trans, trans->uas.request,
-			sip_err, err_buffer);
+	ret = err2reason_phrase(
+			error, &sip_err, err_buffer, sizeof(err_buffer), "TM");
+	if(ret > 0) {
+		reply_ret = t_reply(trans, trans->uas.request, sip_err, err_buffer);
 		/* t_release_transaction( T ); */
 		return reply_ret;
 	} else {
@@ -197,7 +198,7 @@ int kill_transaction( struct cell *trans, int error )
  * in failure route
  * WARNING: assumes that the reply lock is held!
  */
-int kill_transaction_unsafe( struct cell *trans, int error )
+int kill_transaction_unsafe(struct cell *trans, int error)
 {
 	char err_buffer[128];
 	int sip_err;
@@ -209,11 +210,11 @@ int kill_transaction_unsafe( struct cell *trans, int error )
 		want to put the forking burden on upstream client;
 		however, it may fail too due to lack of memory */
 
-	ret=err2reason_phrase(error, &sip_err,
-		err_buffer, sizeof(err_buffer), "TM" );
-	if (ret>0) {
-		reply_ret=t_reply_unsafe( trans, trans->uas.request,
-			sip_err, err_buffer);
+	ret = err2reason_phrase(
+			error, &sip_err, err_buffer, sizeof(err_buffer), "TM");
+	if(ret > 0) {
+		reply_ret =
+				t_reply_unsafe(trans, trans->uas.request, sip_err, err_buffer);
 		/* t_release_transaction( T ); */
 		return reply_ret;
 	} else {
@@ -225,8 +226,8 @@ int kill_transaction_unsafe( struct cell *trans, int error )
 
 /* WARNING: doesn't work from failure route (deadlock, uses t_reply => tries
  *  to get the reply lock again */
-int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
-				int replicate)
+int t_relay_to(
+		struct sip_msg *p_msg, struct proxy_l *proxy, int proto, int replicate)
 {
 	int ret;
 	int new_tran;
@@ -240,15 +241,16 @@ int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
 	int reply_ret;
 #endif
 
-	ret=0;
+	ret = 0;
 
 	/* special case for CANCEL */
-	if ( p_msg->REQ_METHOD==METHOD_CANCEL){
-		ret=t_forward_cancel(p_msg, proxy, proto, &t);
-		if (t) goto handle_ret;
+	if(p_msg->REQ_METHOD == METHOD_CANCEL) {
+		ret = t_forward_cancel(p_msg, proxy, proto, &t);
+		if(t)
+			goto handle_ret;
 		goto done;
 	}
-	new_tran = t_newtran( p_msg );
+	new_tran = t_newtran(p_msg);
 
 	/* parsing error, memory alloc, whatever ... if via is bad
 	   and we are forced to reply there, return with 0 (->break),
@@ -256,128 +258,128 @@ int t_relay_to( struct sip_msg  *p_msg , struct proxy_l *proxy, int proto,
 	   MMA: return value E_SCRIPT means that transaction was already started
 	   from the script so continue with that transaction
 	*/
-	if (likely(new_tran!=E_SCRIPT)) {
-		if (new_tran<0) {
-			ret = (ser_error==E_BAD_VIA && reply_to_via) ? 0 : new_tran;
+	if(likely(new_tran != E_SCRIPT)) {
+		if(new_tran < 0) {
+			ret = (ser_error == E_BAD_VIA && reply_to_via) ? 0 : new_tran;
 			goto done;
 		}
 		/* if that was a retransmission, return we are happily done */
-		if (new_tran==0) {
+		if(new_tran == 0) {
 			ret = 1;
 			goto done;
 		}
-	}else if (unlikely(p_msg->REQ_METHOD==METHOD_ACK)) {
-			/* transaction previously found (E_SCRIPT) and msg==ACK
+	} else if(unlikely(p_msg->REQ_METHOD == METHOD_ACK)) {
+		/* transaction previously found (E_SCRIPT) and msg==ACK
 			    => ack to neg. reply  or ack to local trans.
 			    => process it and exit */
-			/* FIXME: there's no way to distinguish here between acks to
+		/* FIXME: there's no way to distinguish here between acks to
 			   local trans. and neg. acks */
-			/* in normal operation we should never reach this point, if we
+		/* in normal operation we should never reach this point, if we
 			   do WARN(), it might hide some real bug (apart from possibly
 			   hiding a bug the most harm done is calling the TMCB_ACK_NEG
 			   callbacks twice) */
-			LM_WARN("negative or local ACK caught, please report\n");
-			t=get_t();
-			if (unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN)))
-				run_trans_callbacks(TMCB_ACK_NEG_IN, t, p_msg, 0,
-										p_msg->REQ_METHOD);
-			t_release_transaction(t);
-			ret=1;
-			goto done;
+		LM_WARN("negative or local ACK caught, please report\n");
+		t = get_t();
+		if(unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN)))
+			run_trans_callbacks(
+					TMCB_ACK_NEG_IN, t, p_msg, 0, p_msg->REQ_METHOD);
+		t_release_transaction(t);
+		ret = 1;
+		goto done;
 	}
 
 	/* new transaction */
 
 	/* at this point if the msg is an ACK it is an e2e ACK and
 	   e2e ACKs do not establish a transaction and are fwd-ed statelessly */
-	if ( p_msg->REQ_METHOD==METHOD_ACK) {
+	if(p_msg->REQ_METHOD == METHOD_ACK) {
 		LM_DBG("forwarding ACK statelessly\n");
 		init_dest_info(&dst);
 		if(p_msg->msg_flags & FL_USE_OTCPID) {
 			dst.id = p_msg->otcpid;
 		}
-		if (proxy==0) {
-			dst.proto=proto;
-			if (get_uri_send_info(GET_NEXT_HOP(p_msg), &host, &port,
-									&dst.proto, &comp)!=0){
-				ret=E_BAD_ADDRESS;
+		if(proxy == 0) {
+			dst.proto = proto;
+			if(get_uri_send_info(
+					   GET_NEXT_HOP(p_msg), &host, &port, &dst.proto, &comp)
+					!= 0) {
+				ret = E_BAD_ADDRESS;
 				goto done;
 			}
 #ifdef USE_COMP
-			dst.comp=comp;
+			dst.comp = comp;
 #endif
 			/* dst->send_sock not set, but forward_request will take care
 			 * of it */
-			ret=forward_request(p_msg, &host, port, &dst);
+			ret = forward_request(p_msg, &host, port, &dst);
 		} else {
-			dst.proto=get_proto(proto, proxy->proto);
+			dst.proto = get_proto(proto, proxy->proto);
 			proxy2su(&dst.to, proxy);
 			/* dst->send_sock not set, but forward_request will take care
 			 * of it */
-			ret=forward_request(p_msg , 0, 0, &dst) ;
+			ret = forward_request(p_msg, 0, 0, &dst);
 		}
-		if (ret>=0) {
+		if(ret >= 0) {
 			/* convert return code for cfg script */
-			ret=1;
+			ret = 1;
 		}
 		goto done;
 	}
 
 	/* if replication flag is set, mark the transaction as local
 	   so that replies will not be relayed */
-	t=get_t();
-	if (replicate) t->flags|=T_IS_LOCAL_FLAG;
+	t = get_t();
+	if(replicate)
+		t->flags |= T_IS_LOCAL_FLAG;
 
 	/* INVITE processing might take long, particularly because of DNS
 	   look-ups -- let upstream know we're working on it */
-	if (p_msg->REQ_METHOD==METHOD_INVITE && (t->flags&T_AUTO_INV_100)
-		&& (t->uas.status < 100)
-	) {
+	if(p_msg->REQ_METHOD == METHOD_INVITE && (t->flags & T_AUTO_INV_100)
+			&& (t->uas.status < 100)) {
 		LM_DBG("new INVITE\n");
-		if (!t_reply( t, p_msg , 100 ,
-			cfg_get(tm, tm_cfg, tm_auto_inv_100_r)))
-				LM_DBG("failure for t_reply (100)\n");
+		if(!t_reply(t, p_msg, 100, cfg_get(tm, tm_cfg, tm_auto_inv_100_r)))
+			LM_DBG("failure for t_reply (100)\n");
 	}
 
 	/* now go ahead and forward ... */
-	ret=t_forward_nonack(t, p_msg, proxy, proto);
+	ret = t_forward_nonack(t, p_msg, proxy, proto);
 handle_ret:
-	if (ret<=0) {
+	if(ret <= 0) {
 		LM_DBG("t_forward_nonack returned error %d (%d)\n", ret, ser_error);
 		/* we don't want to pass upstream any reply regarding replicating
 		 * a request; replicated branch must stop at us*/
-		if (likely(!replicate)) {
-			if(t->flags&T_DISABLE_INTERNAL_REPLY) {
+		if(likely(!replicate)) {
+			if(t->flags & T_DISABLE_INTERNAL_REPLY) {
 				/* flag set to don't generate the internal negative reply
 				 * - let the transaction live further, processing should
 				 *   continue in config */
 				LM_DBG("not generating immediate reply for error %d\n",
 						ser_error);
-				tm_error=ser_error;
+				tm_error = ser_error;
 				ret = -4;
 				goto done;
 			}
 #ifdef TM_DELAYED_REPLY
 			/* current error in tm_error */
-			tm_error=ser_error;
+			tm_error = ser_error;
 			set_kr(REQ_ERR_DELAYED);
 			LM_DBG("%d error reply generation delayed \n", ser_error);
 #else
 
-			reply_ret=kill_transaction( t, ser_error );
-			if (reply_ret>0) {
+			reply_ret = kill_transaction(t, ser_error);
+			if(reply_ret > 0) {
 				/* we have taken care of all -- do nothing in
 			  	script */
 				LM_DBG("generation of a stateful reply "
-					"on error succeeded\n");
+					   "on error succeeded\n");
 				/*ret=0; -- we don't want to stop the script */
-			}  else {
+			} else {
 				LM_DBG("generation of a stateful reply "
-					"on error failed\n");
+					   "on error failed\n");
 				t_release_transaction(t);
 			}
 #endif /* TM_DELAYED_REPLY */
-		}else{
+		} else {
 			t_release_transaction(t); /* kill it  silently */
 		}
 	} else {
@@ -389,7 +391,6 @@ done:
 }
 
 
-
 /*
  * Initialize parameters containing the ID of
  * AVPs with various timers
@@ -399,29 +400,30 @@ int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param)
 	pv_spec_t avp_spec;
 	unsigned short avp_type;
 
-	if (fr_timer_param && *fr_timer_param) {
+	if(fr_timer_param && *fr_timer_param) {
 		fr_timer_str.s = fr_timer_param;
 		fr_timer_str.len = strlen(fr_timer_str.s);
 		LM_WARN("using AVP for TM fr_timer is deprecated,"
 				" use t_set_fr(...) instead\n");
 
-		if(fr_timer_str.s[0]==PV_MARKER) {
-			if (pv_parse_spec(&fr_timer_str, &avp_spec)==0
-			        || avp_spec.type!=PVT_AVP) {
-			        LM_ERR("malformed or non AVP %s AVP definition\n",
-							fr_timer_param);
+		if(fr_timer_str.s[0] == PV_MARKER) {
+			if(pv_parse_spec(&fr_timer_str, &avp_spec) == 0
+					|| avp_spec.type != PVT_AVP) {
+				LM_ERR("malformed or non AVP %s AVP definition\n",
+						fr_timer_param);
 				return -1;
 			}
 
-			if(pv_get_avp_name(0, &avp_spec.pvp, &fr_timer_avp, &avp_type)!=0)
-			{
+			if(pv_get_avp_name(0, &avp_spec.pvp, &fr_timer_avp, &avp_type)
+					!= 0) {
 				LM_ERR("[%s]- invalid AVP definition\n", fr_timer_param);
 				return -1;
 			}
 			fr_timer_avp_type = avp_type;
 		} else {
-			if (parse_avp_spec( &fr_timer_str, &fr_timer_avp_type,
-			&fr_timer_avp, &fr_timer_index)<0) {
+			if(parse_avp_spec(&fr_timer_str, &fr_timer_avp_type, &fr_timer_avp,
+					   &fr_timer_index)
+					< 0) {
 				LM_CRIT("invalid fr_timer AVP specs \"%s\"\n", fr_timer_param);
 				return -1;
 			}
@@ -430,30 +432,30 @@ int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param)
 		}
 	}
 
-	if (fr_inv_timer_param && *fr_inv_timer_param) {
+	if(fr_inv_timer_param && *fr_inv_timer_param) {
 		fr_inv_timer_str.s = fr_inv_timer_param;
 		fr_inv_timer_str.len = strlen(fr_inv_timer_str.s);
 		LM_WARN("using AVP for TM fr_inv_timer is deprecated,"
 				" use t_set_fr(...) instead\n");
 
-		if(fr_inv_timer_str.s[0]==PV_MARKER) {
-			if (pv_parse_spec(&fr_inv_timer_str, &avp_spec)==0
-					|| avp_spec.type!=PVT_AVP) {
+		if(fr_inv_timer_str.s[0] == PV_MARKER) {
+			if(pv_parse_spec(&fr_inv_timer_str, &avp_spec) == 0
+					|| avp_spec.type != PVT_AVP) {
 				LM_ERR("malformed or non AVP %s AVP definition\n",
-					fr_inv_timer_param);
+						fr_inv_timer_param);
 				return -1;
 			}
 
-			if(pv_get_avp_name(0, &avp_spec.pvp, &fr_inv_timer_avp,
-								&avp_type)!=0)
-			{
+			if(pv_get_avp_name(0, &avp_spec.pvp, &fr_inv_timer_avp, &avp_type)
+					!= 0) {
 				LM_ERR("[%s]- invalid AVP definition\n", fr_inv_timer_param);
 				return -1;
 			}
 			fr_inv_timer_avp_type = avp_type;
 		} else {
-			if (parse_avp_spec( &fr_inv_timer_str, &fr_inv_timer_avp_type,
-			&fr_inv_timer_avp, &fr_inv_timer_index)<0) {
+			if(parse_avp_spec(&fr_inv_timer_str, &fr_inv_timer_avp_type,
+					   &fr_inv_timer_avp, &fr_inv_timer_index)
+					< 0) {
 				LM_CRIT("invalid fr_inv_timer AVP specs \"%s\"\n",
 						fr_inv_timer_param);
 				return -1;
@@ -471,46 +473,46 @@ int init_avp_params(char *fr_timer_param, char *fr_inv_timer_param)
  * @return 0 on success (use *timer) or 1 on failure (avp non-existent,
  *  avp present  but empty/0, avp value not numeric).
  */
-static inline int avp2timer(unsigned int* timer, int type, int_str name)
+static inline int avp2timer(unsigned int *timer, int type, int_str name)
 {
 	struct usr_avp *avp;
 	int_str val_istr;
 	int err;
 
 	avp = search_first_avp(type, name, &val_istr, 0);
-	if (!avp) {
+	if(!avp) {
 		/*
 		 DBG("avp2timer: AVP '%.*s' not found\n", param.s->len, ZSW(param.s->s));
 		 */
 		return 1;
 	}
 
-	if (avp->flags & AVP_VAL_STR) {
+	if(avp->flags & AVP_VAL_STR) {
 		*timer = str2s(val_istr.s.s, val_istr.s.len, &err);
-		if (err) {
+		if(err) {
 			LM_ERR("failed converting string to integer\n");
 			return -1;
 		}
 	} else {
 		*timer = val_istr.n;
 	}
-	return *timer==0; /* 1 if 0 (use default), 0 if !=0 (use *timer) */
+	return *timer == 0; /* 1 if 0 (use default), 0 if !=0 (use *timer) */
 }
 
 
-int fr_avp2timer(unsigned int* timer)
+int fr_avp2timer(unsigned int *timer)
 {
-	if (fr_timer_avp.n!=0)
-		return avp2timer( timer, fr_timer_avp_type, fr_timer_avp);
+	if(fr_timer_avp.n != 0)
+		return avp2timer(timer, fr_timer_avp_type, fr_timer_avp);
 	else
 		return 1;
 }
 
 
-int fr_inv_avp2timer(unsigned int* timer)
+int fr_inv_avp2timer(unsigned int *timer)
 {
-	if (fr_inv_timer_avp.n!=0)
-		return avp2timer( timer, fr_inv_timer_avp_type, fr_inv_timer_avp);
+	if(fr_inv_timer_avp.n != 0)
+		return avp2timer(timer, fr_inv_timer_avp_type, fr_inv_timer_avp);
 	else
 		return 1;
 }

+ 57 - 66
src/modules/tm/t_funcs.h

@@ -19,7 +19,6 @@
  */
 
 
-
 #ifndef _T_FUNCS_H
 #define _T_FUNCS_H
 
@@ -62,8 +61,8 @@ extern str contacts_avp;
 extern str contact_flows_avp;
 
 /* default names for timer's AVPs  */
-#define FR_TIMER_AVP      "callee_fr_timer"
-#define FR_INV_TIMER_AVP  "callee_fr_inv_timer"
+#define FR_TIMER_AVP "callee_fr_timer"
+#define FR_INV_TIMER_AVP "callee_fr_inv_timer"
 
 
 /* send a private buffer: utilize a retransmission structure
@@ -76,51 +75,48 @@ extern str contact_flows_avp;
    else can affect the buffer during sending time
 */
 #ifdef EXTRA_DEBUG
-int send_pr_buffer( struct retr_buf *rb,
-	void *buf, int len, char* file, const char *function, int line );
-#define SEND_PR_BUFFER(_rb,_bf,_le ) \
-	send_pr_buffer( (_rb), (_bf), (_le), __FILE__,  __FUNCTION__, __LINE__ )
+int send_pr_buffer(struct retr_buf *rb, void *buf, int len, char *file,
+		const char *function, int line);
+#define SEND_PR_BUFFER(_rb, _bf, _le) \
+	send_pr_buffer((_rb), (_bf), (_le), __FILE__, __FUNCTION__, __LINE__)
 #else
-int send_pr_buffer( struct retr_buf *rb, void *buf, int len);
-#define SEND_PR_BUFFER(_rb,_bf,_le ) \
-	send_pr_buffer( (_rb), (_bf), (_le))
+int send_pr_buffer(struct retr_buf *rb, void *buf, int len);
+#define SEND_PR_BUFFER(_rb, _bf, _le) send_pr_buffer((_rb), (_bf), (_le))
 #endif
 
-#define SEND_BUFFER( _rb ) \
-	SEND_PR_BUFFER( (_rb) , (_rb)->buffer , (_rb)->buffer_len )
-
-
-
-#define UNREF_FREE(_T_cell, _T_unlinked) \
-	do{\
-		if (atomic_dec_and_test(&(_T_cell)->ref_count)){ \
-			unlink_timers((_T_cell)); \
-			free_cell((_T_cell)); \
-		}else{ \
-			if(_T_unlinked){ \
-				if(t_linked_timers(_T_cell)) { \
-					unlink_timers((_T_cell)); \
-				} \
-				free_cell((_T_cell)); \
-			}else{ \
-				t_stats_delayed_free(); \
-			} \
-		} \
-	}while(0)
-
-#define UNREF_NOSTATS(_T_cell) \
-	do{\
-		if (_T_cell && atomic_dec_and_test(&(_T_cell)->ref_count)){ \
-			unlink_timers((_T_cell)); \
-			free_cell((_T_cell)); \
-		}\
-	}while(0)
+#define SEND_BUFFER(_rb) SEND_PR_BUFFER((_rb), (_rb)->buffer, (_rb)->buffer_len)
+
+
+#define UNREF_FREE(_T_cell, _T_unlinked)                 \
+	do {                                                 \
+		if(atomic_dec_and_test(&(_T_cell)->ref_count)) { \
+			unlink_timers((_T_cell));                    \
+			free_cell((_T_cell));                        \
+		} else {                                         \
+			if(_T_unlinked) {                            \
+				if(t_linked_timers(_T_cell)) {           \
+					unlink_timers((_T_cell));            \
+				}                                        \
+				free_cell((_T_cell));                    \
+			} else {                                     \
+				t_stats_delayed_free();                  \
+			}                                            \
+		}                                                \
+	} while(0)
+
+#define UNREF_NOSTATS(_T_cell)                                      \
+	do {                                                            \
+		if(_T_cell && atomic_dec_and_test(&(_T_cell)->ref_count)) { \
+			unlink_timers((_T_cell));                               \
+			free_cell((_T_cell));                                   \
+		}                                                           \
+	} while(0)
 
 #define UNREF_UNSAFE(_T_cell) UNREF_NOSTATS(_T_cell)
 /* all the version are safe when using atomic ops */
-#define UNREF(_T_cell) UNREF_UNSAFE(_T_cell); 
+#define UNREF(_T_cell) UNREF_UNSAFE(_T_cell);
 #define REF(_T_cell) (atomic_inc(&(_T_cell)->ref_count))
-#define REF_UNSAFE(_T_cell)  REF(_T_cell)
+#define REF_UNSAFE(_T_cell) REF(_T_cell)
 #define INIT_REF(_T_cell, v) atomic_set(&(_T_cell)->ref_count, v)
 
 /*
@@ -134,34 +130,30 @@ void unref_cell(struct cell *t);
 /*
  * Get the FR_{INV}_TIMER from corresponding AVP
  */
-int fr_avp2timer(unsigned int* timer);
-int fr_inv_avp2timer(unsigned int* timer);
+int fr_avp2timer(unsigned int *timer);
+int fr_inv_avp2timer(unsigned int *timer);
 
 
 #ifdef TIMER_DEBUG
-#define start_retr(rb) \
-	_set_fr_retr((rb), \
-				((rb)->dst.proto==PROTO_UDP) ? RT_T1_TIMEOUT_MS(rb) : \
-												(unsigned)(-1), \
-				__FILE__, __FUNCTION__, __LINE__)
+#define start_retr(rb)                                            \
+	_set_fr_retr((rb),                                            \
+			((rb)->dst.proto == PROTO_UDP) ? RT_T1_TIMEOUT_MS(rb) \
+										   : (unsigned)(-1),      \
+			__FILE__, __FUNCTION__, __LINE__)
 
 #define force_retr(rb) \
 	_set_fr_retr((rb), RT_T1_TIMEOUT_MS(rb), __FILE__, __FUNCTION__, __LINE__)
 
 #else
-#define start_retr(rb) \
-	_set_fr_retr((rb), \
-				((rb)->dst.proto==PROTO_UDP) ? RT_T1_TIMEOUT_MS(rb) : \
-												(unsigned)(-1))
+#define start_retr(rb)                                                       \
+	_set_fr_retr((rb), ((rb)->dst.proto == PROTO_UDP) ? RT_T1_TIMEOUT_MS(rb) \
+													  : (unsigned)(-1))
 
-#define force_retr(rb) \
-	_set_fr_retr((rb), RT_T1_TIMEOUT_MS(rb))
+#define force_retr(rb) _set_fr_retr((rb), RT_T1_TIMEOUT_MS(rb))
 
 #endif
 
 
-
-
 void tm_shutdown(void);
 
 
@@ -169,26 +161,25 @@ void tm_shutdown(void);
  *       1 - a new transaction was created
  *      -1 - error, including retransmission
  */
-int  t_add_transaction( struct sip_msg* p_msg  );
+int t_add_transaction(struct sip_msg *p_msg);
 
 
 /* returns 1 if everything was OK or -1 for error */
-int t_release_transaction( struct cell *trans );
+int t_release_transaction(struct cell *trans);
 typedef int (*trelease_t)(struct cell *t);
 
 
-int get_ip_and_port_from_uri( str* uri , unsigned int *param_ip,
-	unsigned int *param_port);
+int get_ip_and_port_from_uri(
+		str *uri, unsigned int *param_ip, unsigned int *param_port);
 
 
-void put_on_wait(  struct cell  *Trans  );
+void put_on_wait(struct cell *Trans);
 int t_on_wait(tm_cell_t *Trans);
 
 
-int t_relay_to( struct sip_msg  *p_msg ,
-	struct proxy_l *proxy, int proto, int replicate ) ;
+int t_relay_to(
+		struct sip_msg *p_msg, struct proxy_l *proxy, int proto, int replicate);
 
-int kill_transaction( struct cell *trans, int error );
-int kill_transaction_unsafe( struct cell *trans, int error );
+int kill_transaction(struct cell *trans, int error);
+int kill_transaction_unsafe(struct cell *trans, int error);
 #endif
-

File diff ditekan karena terlalu besar
+ 369 - 372
src/modules/tm/t_fwd.c


+ 32 - 27
src/modules/tm/t_fwd.h

@@ -27,24 +27,30 @@
 /* cancel hop by hop */
 #define E2E_CANCEL_HOP_BY_HOP
 
-enum unmatched_cancel_t { UM_CANCEL_STATEFULL=0, UM_CANCEL_STATELESS,
-							UM_CANCEL_DROP };
+enum unmatched_cancel_t
+{
+	UM_CANCEL_STATEFULL = 0,
+	UM_CANCEL_STATELESS,
+	UM_CANCEL_DROP
+};
 
-typedef int (*tfwd_f)(struct sip_msg* p_msg , struct proxy_l * proxy );
-typedef int (*taddblind_f)( /*struct cell *t */ void);
-typedef int (*treplicate_uri_f)(struct sip_msg* p_msg , str *suri );
+typedef int (*tfwd_f)(struct sip_msg *p_msg, struct proxy_l *proxy);
+typedef int (*taddblind_f)(/*struct cell *t */ void);
+typedef int (*treplicate_uri_f)(struct sip_msg *p_msg, str *suri);
 
 void t_on_branch(unsigned int go_to);
 void set_branch_route(unsigned int on_branch);
 unsigned int get_on_branch(void);
 int t_replicate_uri(struct sip_msg *p_msg, str *suri);
-int t_replicate(struct sip_msg *p_msg, struct proxy_l * proxy, int proto);
+int t_replicate(struct sip_msg *p_msg, struct proxy_l *proxy, int proto);
 /*  -- not use outside t_fwd.c for noe
 char *print_uac_request( struct cell *t, struct sip_msg *i_req,
     int branch, str *uri, unsigned int *len, struct dest_info *dst);
 */
-void e2e_cancel( struct sip_msg *cancel_msg, struct cell *t_cancel, struct cell *t_invite );
-int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel, struct cell *t_invite, int branch );
+void e2e_cancel(struct sip_msg *cancel_msg, struct cell *t_cancel,
+		struct cell *t_invite);
+int e2e_cancel_branch(struct sip_msg *cancel_msg, struct cell *t_cancel,
+		struct cell *t_invite, int branch);
 /*
 int add_uac(struct cell *t, struct sip_msg *request, str *uri, str* next_hop,
 				str* path, struct proxy_l *proxy, int proto );
@@ -52,29 +58,28 @@ int add_uac(struct cell *t, struct sip_msg *request, str *uri, str* next_hop,
 
 /* prepare_new_uac flags */
 #define UAC_DNS_FAILOVER_F 1 /**< new branch due to dns failover */
-#define UAC_SKIP_BR_DST_F  2 /**< don't set next hop as dst_uri for
+#define UAC_SKIP_BR_DST_F \
+	2 /**< don't set next hop as dst_uri for
 							   branch_route */
-int add_uac( struct cell *t, struct sip_msg *request, str *uri, str* next_hop,
-			str* path, struct proxy_l *proxy, struct socket_info* fsocket,
-			snd_flags_t snd_flags, int proto, int flags, str *instance, str *ruid,
-			str *location_ua);
+int add_uac(struct cell *t, struct sip_msg *request, str *uri, str *next_hop,
+		str *path, struct proxy_l *proxy, struct socket_info *fsocket,
+		snd_flags_t snd_flags, int proto, int flags, str *instance, str *ruid,
+		str *location_ua);
 #ifdef USE_DNS_FAILOVER
-int add_uac_dns_fallback( struct cell *t, struct sip_msg* msg, 
-									struct ua_client* old_uac,
-									int lock_replies);
+int add_uac_dns_fallback(struct cell *t, struct sip_msg *msg,
+		struct ua_client *old_uac, int lock_replies);
 #endif
 int add_blind_uac(/* struct cell *t */ void);
-int t_forward_nonack( struct cell *t, struct sip_msg* p_msg,
-						struct proxy_l * p, int proto);
-int t_forward_cancel(struct sip_msg* p_msg , struct proxy_l * proxy,
-						int proto, struct cell** tran);
-int t_forward_ack( struct sip_msg* p_msg );
-int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
-					struct proxy_l * proxy, int lock_replies);
-int t_relay_cancel(struct sip_msg* p_msg);
+int t_forward_nonack(
+		struct cell *t, struct sip_msg *p_msg, struct proxy_l *p, int proto);
+int t_forward_cancel(struct sip_msg *p_msg, struct proxy_l *proxy, int proto,
+		struct cell **tran);
+int t_forward_ack(struct sip_msg *p_msg);
+int t_send_branch(struct cell *t, int branch, struct sip_msg *p_msg,
+		struct proxy_l *proxy, int lock_replies);
+int t_relay_cancel(struct sip_msg *p_msg);
 
-int reparse_on_dns_failover_fixup(void *handle, str *gname, str *name, void **val);
+int reparse_on_dns_failover_fixup(
+		void *handle, str *gname, str *name, void **val);
 
 #endif
-
-

+ 98 - 104
src/modules/tm/t_hooks.c

@@ -30,24 +30,25 @@
 #include "t_funcs.h"
 
 
-struct tmcb_head_list* req_in_tmcb_hl = 0;
-struct tmcb_head_list* local_req_in_tmcb_hl = 0;
+struct tmcb_head_list *req_in_tmcb_hl = 0;
+struct tmcb_head_list *local_req_in_tmcb_hl = 0;
 
-struct tm_early_cb {
+struct tm_early_cb
+{
 	unsigned int msgid;
 	struct tmcb_head_list cb_list;
-} tmcb_early_hl = { 0, {0, 0} };
+} tmcb_early_hl = {0, {0, 0}};
 
-struct tmcb_head_list* get_early_tmcb_list(struct sip_msg *msg)
+struct tmcb_head_list *get_early_tmcb_list(struct sip_msg *msg)
 {
 	struct tm_callback *cbp, *cbp_tmp;
-	if (msg->id!=tmcb_early_hl.msgid) {
-		for( cbp=(struct tm_callback*)tmcb_early_hl.cb_list.first; cbp ; ) {
+	if(msg->id != tmcb_early_hl.msgid) {
+		for(cbp = (struct tm_callback *)tmcb_early_hl.cb_list.first; cbp;) {
 			cbp_tmp = cbp;
 			cbp = cbp->next;
-			if (cbp_tmp->param && cbp_tmp->release)
-					cbp_tmp->release( cbp_tmp->param );
-			shm_free( cbp_tmp );
+			if(cbp_tmp->param && cbp_tmp->release)
+				cbp_tmp->release(cbp_tmp->param);
+			shm_free(cbp_tmp);
 		}
 		memset(&tmcb_early_hl.cb_list, 0, sizeof(struct tmcb_head_list));
 		tmcb_early_hl.msgid = msg->id;
@@ -57,7 +58,7 @@ struct tmcb_head_list* get_early_tmcb_list(struct sip_msg *msg)
 
 void set_early_tmcb_list(struct sip_msg *msg, struct cell *t)
 {
-	if (msg->id==tmcb_early_hl.msgid) {
+	if(msg->id == tmcb_early_hl.msgid) {
 		t->tmcb_hl = tmcb_early_hl.cb_list;
 		memset(&tmcb_early_hl.cb_list, 0, sizeof(struct tmcb_head_list));
 		tmcb_early_hl.msgid = 0;
@@ -66,11 +67,11 @@ void set_early_tmcb_list(struct sip_msg *msg, struct cell *t)
 
 int init_tmcb_lists()
 {
-	req_in_tmcb_hl = (struct tmcb_head_list*)shm_malloc
-		( sizeof(struct tmcb_head_list) );
-	local_req_in_tmcb_hl = (struct tmcb_head_list*)shm_malloc
-		( sizeof(struct tmcb_head_list) );
-	if ((req_in_tmcb_hl==0) || (local_req_in_tmcb_hl==0)) {
+	req_in_tmcb_hl =
+			(struct tmcb_head_list *)shm_malloc(sizeof(struct tmcb_head_list));
+	local_req_in_tmcb_hl =
+			(struct tmcb_head_list *)shm_malloc(sizeof(struct tmcb_head_list));
+	if((req_in_tmcb_hl == 0) || (local_req_in_tmcb_hl == 0)) {
 		SHM_MEM_CRITICAL;
 		goto error;
 	}
@@ -80,13 +81,13 @@ int init_tmcb_lists()
 	local_req_in_tmcb_hl->reg_types = 0;
 	return 1;
 error:
-	if (req_in_tmcb_hl){
+	if(req_in_tmcb_hl) {
 		shm_free(req_in_tmcb_hl);
-		req_in_tmcb_hl=0;
+		req_in_tmcb_hl = 0;
 	}
-	if(local_req_in_tmcb_hl){
+	if(local_req_in_tmcb_hl) {
 		shm_free(local_req_in_tmcb_hl);
-		local_req_in_tmcb_hl=0;
+		local_req_in_tmcb_hl = 0;
 	}
 	return -1;
 }
@@ -96,43 +97,41 @@ void destroy_tmcb_lists()
 {
 	struct tm_callback *cbp, *cbp_tmp;
 
-	if (req_in_tmcb_hl){
-		for( cbp=(struct tm_callback*)req_in_tmcb_hl->first; cbp ; ) {
+	if(req_in_tmcb_hl) {
+		for(cbp = (struct tm_callback *)req_in_tmcb_hl->first; cbp;) {
 			cbp_tmp = cbp;
 			cbp = cbp->next;
-			if (cbp_tmp->param && cbp_tmp->release)
-					cbp_tmp->release( cbp_tmp->param );
-			shm_free( cbp_tmp );
+			if(cbp_tmp->param && cbp_tmp->release)
+				cbp_tmp->release(cbp_tmp->param);
+			shm_free(cbp_tmp);
 		}
 		shm_free(req_in_tmcb_hl);
-		req_in_tmcb_hl=0;
+		req_in_tmcb_hl = 0;
 	}
-	if(local_req_in_tmcb_hl){
-		for( cbp=(struct tm_callback*)local_req_in_tmcb_hl->first; cbp ; ) {
+	if(local_req_in_tmcb_hl) {
+		for(cbp = (struct tm_callback *)local_req_in_tmcb_hl->first; cbp;) {
 			cbp_tmp = cbp;
 			cbp = cbp->next;
-			if (cbp_tmp->param && cbp_tmp->release)
-					cbp_tmp->release( cbp_tmp->param );
-			shm_free( cbp_tmp );
+			if(cbp_tmp->param && cbp_tmp->release)
+				cbp_tmp->release(cbp_tmp->param);
+			shm_free(cbp_tmp);
 		}
 		shm_free(local_req_in_tmcb_hl);
-		local_req_in_tmcb_hl=0;
+		local_req_in_tmcb_hl = 0;
 	}
 }
 
 
-
 /* lockless insert: should be always safe */
-int insert_tmcb(struct tmcb_head_list *cb_list, int types,
-				transaction_cb f, void *param,
-				release_tmcb_param rel_func)
+int insert_tmcb(struct tmcb_head_list *cb_list, int types, transaction_cb f,
+		void *param, release_tmcb_param rel_func)
 {
 	struct tm_callback *cbp;
 	struct tm_callback *old;
 
 
 	/* build a new callback structure */
-	if (!(cbp=shm_malloc( sizeof( struct tm_callback)))) {
+	if(!(cbp = shm_malloc(sizeof(struct tm_callback)))) {
 		SHM_MEM_ERROR;
 		return E_OUT_OF_MEM;
 	}
@@ -143,21 +142,20 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
 	cbp->param = param;
 	cbp->release = rel_func;
 	cbp->types = types;
-	cbp->id=0;
-	old=(struct tm_callback*)cb_list->first;
+	cbp->id = 0;
+	old = (struct tm_callback *)cb_list->first;
 	/* link it into the proper place... */
-	do{
+	do {
 		cbp->next = old;
 		membar_write_atomic_op();
-		old=(void*)atomic_cmpxchg_long((void*)&cb_list->first,
-										(long)old, (long)cbp);
-	}while(old!=cbp->next);
+		old = (void *)atomic_cmpxchg_long(
+				(void *)&cb_list->first, (long)old, (long)cbp);
+	} while(old != cbp->next);
 
 	return 1;
 }
 
 
-
 /* register a callback function 'f' for 'types' mask of events;
  * will be called back whenever one of the events occurs in transaction module
  * (global or per transaction, depending of event type)
@@ -166,34 +164,32 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
  *  Special cases: TMCB_REQUEST_IN & TMCB_LOCAL_REQUEST_IN - must be called
  *                 from mod_init (before forking!).
 */
-int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
-				transaction_cb f, void *param,
-				release_tmcb_param rel_func)
+int register_tmcb(struct sip_msg *p_msg, struct cell *t, int types,
+		transaction_cb f, void *param, release_tmcb_param rel_func)
 {
 	//struct cell* t;
 	struct tmcb_head_list *cb_list;
 
 	/* are the callback types valid?... */
-	if ( types<0 || types>TMCB_MAX ) {
-		LM_CRIT("BUG: invalid callback types: mask=%d\n",
-			types);
+	if(types < 0 || types > TMCB_MAX) {
+		LM_CRIT("BUG: invalid callback types: mask=%d\n", types);
 		return E_BUG;
 	}
 	/* we don't register null functions */
-	if (f==0) {
+	if(f == 0) {
 		LM_CRIT("BUG: null callback function\n");
 		return E_BUG;
 	}
 
-	if ((types!=TMCB_MAX) && (types&TMCB_REQUEST_IN)) {
-		if (types!=TMCB_REQUEST_IN) {
+	if((types != TMCB_MAX) && (types & TMCB_REQUEST_IN)) {
+		if(types != TMCB_REQUEST_IN) {
 			LM_CRIT("BUG: callback type TMCB_REQUEST_IN"
-				" can't be register along with types\n");
+					" can't be register along with types\n");
 			return E_BUG;
 		}
 		cb_list = req_in_tmcb_hl;
-	}else if ((types!=TMCB_MAX) && (types & TMCB_LOCAL_REQUEST_IN)) {
-		if (types!=TMCB_LOCAL_REQUEST_IN) {
+	} else if((types != TMCB_MAX) && (types & TMCB_LOCAL_REQUEST_IN)) {
+		if(types != TMCB_LOCAL_REQUEST_IN) {
 			LM_CRIT("BUG: callback type"
 					" TMCB_LOCAL_REQUEST_IN can't be register along with"
 					" other types\n");
@@ -201,14 +197,14 @@ int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
 		}
 		cb_list = local_req_in_tmcb_hl;
 	} else {
-		if (!t) {
-			if (!p_msg) {
+		if(!t) {
+			if(!p_msg) {
 				LM_CRIT("BUG: no sip_msg, nor transaction given\n");
 				return E_BUG;
 			}
 			/* look for the transaction */
-			t=get_t();
-			if ( t!=0 && t!=T_UNDEFINED) {
+			t = get_t();
+			if(t != 0 && t != T_UNDEFINED) {
 				cb_list = &(t->tmcb_hl);
 			} else {
 				cb_list = get_early_tmcb_list(p_msg);
@@ -218,43 +214,41 @@ int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
 		}
 	}
 
-	return insert_tmcb( cb_list, types, f, param, rel_func );
+	return insert_tmcb(cb_list, types, f, param, rel_func);
 }
 
 
-void run_trans_callbacks_internal(struct tmcb_head_list* cb_lst, int type,
-									struct cell *trans,
-									struct tmcb_params *params)
+void run_trans_callbacks_internal(struct tmcb_head_list *cb_lst, int type,
+		struct cell *trans, struct tmcb_params *params)
 {
 	struct tm_callback *cbp;
 	tm_xlinks_t backup_xd;
 
 	tm_xdata_swap(trans, &backup_xd, 0);
 
-	cbp=(struct tm_callback*)cb_lst->first;
-	while(cbp){
+	cbp = (struct tm_callback *)cb_lst->first;
+	while(cbp) {
 		membar_depends(); /* make sure the cache has the correct cbp contents */
-		if ( (cbp->types)&type ) {
-			DBG("DBG: trans=%p, callback type %d, id %d entered\n",
-				trans, type, cbp->id );
+		if((cbp->types) & type) {
+			DBG("DBG: trans=%p, callback type %d, id %d entered\n", trans, type,
+					cbp->id);
 			params->param = &(cbp->param);
-			cbp->callback( trans, type, params );
+			cbp->callback(trans, type, params);
 		}
-		cbp=cbp->next;
+		cbp = cbp->next;
 	}
 
 	tm_xdata_swap(trans, &backup_xd, 1);
 }
 
 
-
-void run_trans_callbacks( int type , struct cell *trans,
-						struct sip_msg *req, struct sip_msg *rpl, int code )
+void run_trans_callbacks(int type, struct cell *trans, struct sip_msg *req,
+		struct sip_msg *rpl, int code)
 {
 	struct tmcb_params params;
-	if (trans->tmcb_hl.first==0 || ((trans->tmcb_hl.reg_types)&type)==0 )
+	if(trans->tmcb_hl.first == 0 || ((trans->tmcb_hl.reg_types) & type) == 0)
 		return;
-	memset (&params, 0, sizeof(params));
+	memset(&params, 0, sizeof(params));
 	params.req = req;
 	params.rpl = rpl;
 	params.code = code;
@@ -262,65 +256,65 @@ void run_trans_callbacks( int type , struct cell *trans,
 }
 
 
-
-void run_trans_callbacks_with_buf(int type, struct retr_buf* rbuf,
-		struct sip_msg* req, struct sip_msg* repl, short flags)
+void run_trans_callbacks_with_buf(int type, struct retr_buf *rbuf,
+		struct sip_msg *req, struct sip_msg *repl, short flags)
 {
 	struct tmcb_params params;
-	struct cell * trans;
+	struct cell *trans;
 
-	trans=rbuf->my_T;
-	if ( trans==0 || trans->tmcb_hl.first==0 ||
-			((trans->tmcb_hl.reg_types)&type)==0 )
+	trans = rbuf->my_T;
+	if(trans == 0 || trans->tmcb_hl.first == 0
+			|| ((trans->tmcb_hl.reg_types) & type) == 0)
 		return;
 	INIT_TMCB_ONSEND_PARAMS(params, req, repl, rbuf, &rbuf->dst, rbuf->buffer,
-					rbuf->buffer_len, flags, rbuf->branch, rbuf->rbtype);
+			rbuf->buffer_len, flags, rbuf->branch, rbuf->rbtype);
 	/* req, rpl */
 	run_trans_callbacks_internal(&trans->tmcb_hl, type, trans, &params);
 }
 
 
-void run_trans_callbacks_off_params(int type, struct cell* trans,
-		struct tmcb_params* p)
+void run_trans_callbacks_off_params(
+		int type, struct cell *trans, struct tmcb_params *p)
 {
 
-	if (p->t_rbuf==0) return;
-	if ( trans==0 || trans->tmcb_hl.first==0 ||
-			((trans->tmcb_hl.reg_types)&type)==0 )
+	if(p->t_rbuf == 0)
+		return;
+	if(trans == 0 || trans->tmcb_hl.first == 0
+			|| ((trans->tmcb_hl.reg_types) & type) == 0)
 		return;
 	run_trans_callbacks_internal(&trans->tmcb_hl, type, p->t_rbuf->my_T, p);
 }
 
 
-static void run_reqin_callbacks_internal(struct tmcb_head_list* hl,
-							struct cell *trans, struct tmcb_params* params)
+static void run_reqin_callbacks_internal(struct tmcb_head_list *hl,
+		struct cell *trans, struct tmcb_params *params)
 {
 	struct tm_callback *cbp;
 	tm_xlinks_t backup_xd;
 
-	if (hl==0 || hl->first==0) return;
+	if(hl == 0 || hl->first == 0)
+		return;
 
 	tm_xdata_swap(trans, &backup_xd, 0);
 
-	for (cbp=(struct tm_callback*)hl->first; cbp; cbp=cbp->next)  {
-		LM_DBG("trans=%p, callback type %d, id %d entered\n",
-			trans, cbp->types, cbp->id );
+	for(cbp = (struct tm_callback *)hl->first; cbp; cbp = cbp->next) {
+		LM_DBG("trans=%p, callback type %d, id %d entered\n", trans, cbp->types,
+				cbp->id);
 		params->param = &(cbp->param);
-		cbp->callback( trans, cbp->types, params );
+		cbp->callback(trans, cbp->types, params);
 	}
 
 	tm_xdata_swap(trans, &backup_xd, 1);
 }
 
 
-
-void run_reqin_callbacks( struct cell *trans, struct sip_msg *req, int code )
+void run_reqin_callbacks(struct cell *trans, struct sip_msg *req, int code)
 {
 	static struct tmcb_params params;
 
-	if (req_in_tmcb_hl->first==0)
+	if(req_in_tmcb_hl->first == 0)
 		return;
-	memset (&params, 0, sizeof(params));
+	memset(&params, 0, sizeof(params));
 	params.req = req;
 	params.code = code;
 
@@ -328,14 +322,14 @@ void run_reqin_callbacks( struct cell *trans, struct sip_msg *req, int code )
 }
 
 
-void run_local_reqin_callbacks( struct cell *trans, struct sip_msg *req,
-								int code )
+void run_local_reqin_callbacks(
+		struct cell *trans, struct sip_msg *req, int code)
 {
 	static struct tmcb_params params;
 
-	if (local_req_in_tmcb_hl->first==0)
+	if(local_req_in_tmcb_hl->first == 0)
 		return;
-	memset (&params, 0, sizeof(params));
+	memset(&params, 0, sizeof(params));
 	params.req = req;
 	params.code = code;
 

+ 112 - 111
src/modules/tm/t_hooks.h

@@ -33,62 +33,62 @@
 struct sip_msg;
 struct cell;
 
-#define TMCB_REQUEST_IN_N       0
-#define TMCB_RESPONSE_IN_N      1
-#define TMCB_E2EACK_IN_N        2
-#define TMCB_REQUEST_PENDING_N  3
-#define TMCB_REQUEST_FWDED_N    4
-#define TMCB_RESPONSE_FWDED_N   5
-#define TMCB_ON_FAILURE_RO_N    6
-#define TMCB_ON_FAILURE_N       7
-#define TMCB_REQUEST_OUT_N      8
-#define TMCB_RESPONSE_OUT_N     9
-#define TMCB_LOCAL_COMPLETED_N  10
+#define TMCB_REQUEST_IN_N 0
+#define TMCB_RESPONSE_IN_N 1
+#define TMCB_E2EACK_IN_N 2
+#define TMCB_REQUEST_PENDING_N 3
+#define TMCB_REQUEST_FWDED_N 4
+#define TMCB_RESPONSE_FWDED_N 5
+#define TMCB_ON_FAILURE_RO_N 6
+#define TMCB_ON_FAILURE_N 7
+#define TMCB_REQUEST_OUT_N 8
+#define TMCB_RESPONSE_OUT_N 9
+#define TMCB_LOCAL_COMPLETED_N 10
 #define TMCB_LOCAL_RESPONSE_OUT_N 11
-#define TMCB_ACK_NEG_IN_N       12
-#define TMCB_REQ_RETR_IN_N      13
+#define TMCB_ACK_NEG_IN_N 12
+#define TMCB_REQ_RETR_IN_N 13
 #define TMCB_LOCAL_RESPONSE_IN_N 14
-#define TMCB_LOCAL_REQUEST_IN_N  15
-#define TMCB_DLG_N              16
-#define TMCB_DESTROY_N          17  /* called on transaction destroy */
-#define TMCB_E2ECANCEL_IN_N     18
-#define TMCB_E2EACK_RETR_IN_N   19
-#define TMCB_RESPONSE_READY_N	20
-#define TMCB_DONT_ACK_N         21 /* TM shoudn't ACK a local UAC  */
-#define TMCB_REQUEST_SENT_N     22
-#define TMCB_RESPONSE_SENT_N    23
+#define TMCB_LOCAL_REQUEST_IN_N 15
+#define TMCB_DLG_N 16
+#define TMCB_DESTROY_N 17 /* called on transaction destroy */
+#define TMCB_E2ECANCEL_IN_N 18
+#define TMCB_E2EACK_RETR_IN_N 19
+#define TMCB_RESPONSE_READY_N 20
+#define TMCB_DONT_ACK_N 21 /* TM shoudn't ACK a local UAC  */
+#define TMCB_REQUEST_SENT_N 22
+#define TMCB_RESPONSE_SENT_N 23
 #define TMCB_ON_BRANCH_FAILURE_RO_N 24
 #define TMCB_ON_BRANCH_FAILURE_N 25
-#define TMCB_MAX_N              25
-
-
-#define TMCB_REQUEST_IN       (1<<TMCB_REQUEST_IN_N)
-#define TMCB_RESPONSE_IN      (1<<TMCB_RESPONSE_IN_N)
-#define TMCB_E2EACK_IN        (1<<TMCB_E2EACK_IN_N)
-#define TMCB_REQUEST_PENDING  (1<<TMCB_REQUEST_PENDING_N)
-#define TMCB_REQUEST_FWDED    (1<<TMCB_REQUEST_FWDED_N)
-#define TMCB_RESPONSE_FWDED   (1<<TMCB_RESPONSE_FWDED_N)
-#define TMCB_ON_FAILURE_RO    (1<<TMCB_ON_FAILURE_RO_N)
-#define TMCB_ON_FAILURE       (1<<TMCB_ON_FAILURE_N)
-#define TMCB_REQUEST_OUT      (1<<TMCB_REQUEST_OUT_N)
-#define TMCB_RESPONSE_OUT     (1<<TMCB_RESPONSE_OUT_N)
-#define TMCB_LOCAL_COMPLETED  (1<<TMCB_LOCAL_COMPLETED_N)
-#define TMCB_LOCAL_RESPONSE_OUT (1<<TMCB_LOCAL_RESPONSE_OUT_N)
-#define TMCB_ACK_NEG_IN       (1<<TMCB_ACK_NEG_IN_N)
-#define TMCB_REQ_RETR_IN      (1<<TMCB_REQ_RETR_IN_N)
-#define TMCB_LOCAL_RESPONSE_IN (1<<TMCB_LOCAL_RESPONSE_IN_N)
-#define TMCB_LOCAL_REQUEST_IN (1<<TMCB_LOCAL_REQUEST_IN_N)
-#define TMCB_DLG              (1<<TMCB_DLG_N)
-#define TMCB_DESTROY          (1<<TMCB_DESTROY_N)
-#define TMCB_E2ECANCEL_IN     (1<<TMCB_E2ECANCEL_IN_N)
-#define TMCB_E2EACK_RETR_IN   (1<<TMCB_E2EACK_RETR_IN_N)
-#define TMCB_RESPONSE_READY   (1<<TMCB_RESPONSE_READY_N)
-#define TMCB_DONT_ACK         (1<<TMCB_DONT_ACK_N)
-#define TMCB_REQUEST_SENT      (1<<TMCB_REQUEST_SENT_N)
-#define TMCB_RESPONSE_SENT     (1<<TMCB_RESPONSE_SENT_N)
-#define TMCB_ON_BRANCH_FAILURE (1<<TMCB_ON_BRANCH_FAILURE_N)
-#define TMCB_ON_BRANCH_FAILURE_RO (1<<TMCB_ON_BRANCH_FAILURE_RO_N)
-#define TMCB_MAX              ((1<<(TMCB_MAX_N+1))-1)
+#define TMCB_MAX_N 25
+
+
+#define TMCB_REQUEST_IN (1 << TMCB_REQUEST_IN_N)
+#define TMCB_RESPONSE_IN (1 << TMCB_RESPONSE_IN_N)
+#define TMCB_E2EACK_IN (1 << TMCB_E2EACK_IN_N)
+#define TMCB_REQUEST_PENDING (1 << TMCB_REQUEST_PENDING_N)
+#define TMCB_REQUEST_FWDED (1 << TMCB_REQUEST_FWDED_N)
+#define TMCB_RESPONSE_FWDED (1 << TMCB_RESPONSE_FWDED_N)
+#define TMCB_ON_FAILURE_RO (1 << TMCB_ON_FAILURE_RO_N)
+#define TMCB_ON_FAILURE (1 << TMCB_ON_FAILURE_N)
+#define TMCB_REQUEST_OUT (1 << TMCB_REQUEST_OUT_N)
+#define TMCB_RESPONSE_OUT (1 << TMCB_RESPONSE_OUT_N)
+#define TMCB_LOCAL_COMPLETED (1 << TMCB_LOCAL_COMPLETED_N)
+#define TMCB_LOCAL_RESPONSE_OUT (1 << TMCB_LOCAL_RESPONSE_OUT_N)
+#define TMCB_ACK_NEG_IN (1 << TMCB_ACK_NEG_IN_N)
+#define TMCB_REQ_RETR_IN (1 << TMCB_REQ_RETR_IN_N)
+#define TMCB_LOCAL_RESPONSE_IN (1 << TMCB_LOCAL_RESPONSE_IN_N)
+#define TMCB_LOCAL_REQUEST_IN (1 << TMCB_LOCAL_REQUEST_IN_N)
+#define TMCB_DLG (1 << TMCB_DLG_N)
+#define TMCB_DESTROY (1 << TMCB_DESTROY_N)
+#define TMCB_E2ECANCEL_IN (1 << TMCB_E2ECANCEL_IN_N)
+#define TMCB_E2EACK_RETR_IN (1 << TMCB_E2EACK_RETR_IN_N)
+#define TMCB_RESPONSE_READY (1 << TMCB_RESPONSE_READY_N)
+#define TMCB_DONT_ACK (1 << TMCB_DONT_ACK_N)
+#define TMCB_REQUEST_SENT (1 << TMCB_REQUEST_SENT_N)
+#define TMCB_RESPONSE_SENT (1 << TMCB_RESPONSE_SENT_N)
+#define TMCB_ON_BRANCH_FAILURE (1 << TMCB_ON_BRANCH_FAILURE_N)
+#define TMCB_ON_BRANCH_FAILURE_RO (1 << TMCB_ON_BRANCH_FAILURE_RO_N)
+#define TMCB_MAX ((1 << (TMCB_MAX_N + 1)) - 1)
 
 
 /*
@@ -327,12 +327,13 @@ struct cell;
 #define TMCB_LOCAL_F 2
 
 /* pack structure with all params passed to callback function */
-struct tmcb_params {
-	struct sip_msg* req;
-	struct sip_msg* rpl;
+struct tmcb_params
+{
+	struct sip_msg *req;
+	struct sip_msg *rpl;
 	void **param;
 	int code;
-	unsigned short flags;  /* set to a combination of:
+	unsigned short flags; /* set to a combination of:
 							* TMCB_RETR_F if this is a _ser_ retransmission
 							* (but not if if it's a "forwarded" retr., like a
 							* retr. 200 Ok for example)
@@ -340,69 +341,70 @@ struct tmcb_params {
 							* (and not forwarded) */
 	unsigned short branch;
 	/* could also be: send_buf, dst, branch */
-	struct retr_buf* t_rbuf;   /* transaction retr. buf., all the information
+	struct retr_buf *t_rbuf; /* transaction retr. buf., all the information
 								* regarding destination, data that is/was
 								* actually sent on the net, branch a.s.o is
 								* inside */
-	struct dest_info* dst; /* destination */
-	str send_buf; /* what was/will be sent on the net, used for ACKs
+	struct dest_info *dst;	 /* destination */
+	str send_buf;			 /* what was/will be sent on the net, used for ACKs
 					(which don't have a retr_buf). */
 };
 
-#define INIT_TMCB_PARAMS(tmcb, request, reply, r_code)\
-do{\
-	memset(&(tmcb), 0, sizeof((tmcb))); \
-	(tmcb).req=(request); (tmcb).rpl=(reply);  \
-	(tmcb).code=(r_code); \
-}while(0)
+#define INIT_TMCB_PARAMS(tmcb, request, reply, r_code) \
+	do {                                               \
+		memset(&(tmcb), 0, sizeof((tmcb)));            \
+		(tmcb).req = (request);                        \
+		(tmcb).rpl = (reply);                          \
+		(tmcb).code = (r_code);                        \
+	} while(0)
 
 #define INIT_TMCB_ONSEND_PARAMS(tmcb, req, repl, rbuf, dest, buf, buf_len, \
-								onsend_flags, t_branch, code) \
-do{ \
-	INIT_TMCB_PARAMS(tmcb, req, repl, code); \
-	tmcb.t_rbuf=(rbuf); tmcb.dst=(dest); \
-	tmcb.send_buf.s=(buf); tmcb.send_buf.len=(buf_len); \
-	tmcb.flags=(onsend_flags); tmcb.branch=(t_branch); \
-}while(0)
+		onsend_flags, t_branch, code)                                      \
+	do {                                                                   \
+		INIT_TMCB_PARAMS(tmcb, req, repl, code);                           \
+		tmcb.t_rbuf = (rbuf);                                              \
+		tmcb.dst = (dest);                                                 \
+		tmcb.send_buf.s = (buf);                                           \
+		tmcb.send_buf.len = (buf_len);                                     \
+		tmcb.flags = (onsend_flags);                                       \
+		tmcb.branch = (t_branch);                                          \
+	} while(0)
 
 /* callback function prototype */
-typedef void (transaction_cb) (struct cell* t, int type, struct tmcb_params*);
+typedef void(transaction_cb)(struct cell *t, int type, struct tmcb_params *);
 /*! \brief function to release the callback param */
-typedef void (release_tmcb_param) (void* param);
+typedef void(release_tmcb_param)(void *param);
 /* register callback function prototype */
-typedef int (*register_tmcb_f)(struct sip_msg* p_msg, struct cell *t,
-			int cb_types, transaction_cb f, void *param,
-			release_tmcb_param func);
+typedef int (*register_tmcb_f)(struct sip_msg *p_msg, struct cell *t,
+		int cb_types, transaction_cb f, void *param, release_tmcb_param func);
 
 
-struct tm_callback {
-	int id;                      /* id of this callback - useless */
-	int types;                   /* types of events that trigger the callback*/
-	transaction_cb* callback;    /* callback function */
-	void *param;                 /* param to be passed to callback function */
-	release_tmcb_param* release; /**< Function to release the callback param
+struct tm_callback
+{
+	int id;						 /* id of this callback - useless */
+	int types;					 /* types of events that trigger the callback*/
+	transaction_cb *callback;	 /* callback function */
+	void *param;				 /* param to be passed to callback function */
+	release_tmcb_param *release; /**< Function to release the callback param
 									* when the callback is deleted */
-	struct tm_callback* next;
+	struct tm_callback *next;
 };
 
-struct tmcb_head_list {
+struct tmcb_head_list
+{
 	struct tm_callback volatile *first;
 	int reg_types;
 };
 
 
-extern struct tmcb_head_list*  req_in_tmcb_hl;
-extern struct tmcb_head_list*  local_req_in_tmcb_hl;
+extern struct tmcb_head_list *req_in_tmcb_hl;
+extern struct tmcb_head_list *local_req_in_tmcb_hl;
 
-void set_early_tmcb_list(struct sip_msg *msg,
-		struct cell *t);
+void set_early_tmcb_list(struct sip_msg *msg, struct cell *t);
 
-#define has_tran_tmcbs(_T_, _types_) \
-	( ((_T_)->tmcb_hl.reg_types)&(_types_) )
-#define has_reqin_tmcbs() \
-	( req_in_tmcb_hl->first!=0 )
-#define has_local_reqin_tmcbs() \
-	( local_req_in_tmcb_hl->first!=0 )
+#define has_tran_tmcbs(_T_, _types_) (((_T_)->tmcb_hl.reg_types) & (_types_))
+#define has_reqin_tmcbs() (req_in_tmcb_hl->first != 0)
+#define has_local_reqin_tmcbs() (local_req_in_tmcb_hl->first != 0)
 
 
 int init_tmcb_lists(void);
@@ -411,32 +413,31 @@ void destroy_tmcb_lists(void);
 
 
 /* register a callback for several types of events */
-int register_tmcb( struct sip_msg* p_msg, struct cell *t, int types,
-			transaction_cb f, void *param, release_tmcb_param rel_func);
+int register_tmcb(struct sip_msg *p_msg, struct cell *t, int types,
+		transaction_cb f, void *param, release_tmcb_param rel_func);
 
 /* inserts a callback into the a callback list */
-int insert_tmcb(struct tmcb_head_list *cb_list, int types,
-				transaction_cb f, void *param,
-				release_tmcb_param rel_func);
+int insert_tmcb(struct tmcb_head_list *cb_list, int types, transaction_cb f,
+		void *param, release_tmcb_param rel_func);
 
 /* run all transaction callbacks for an event type */
-void run_trans_callbacks( int type , struct cell *trans,
-						struct sip_msg *req, struct sip_msg *rpl, int code );
+void run_trans_callbacks(int type, struct cell *trans, struct sip_msg *req,
+		struct sip_msg *rpl, int code);
 /* helper function */
-void run_trans_callbacks_internal(struct tmcb_head_list* cb_lst, int type,
-									struct cell *trans,
-									struct tmcb_params *params);
+void run_trans_callbacks_internal(struct tmcb_head_list *cb_lst, int type,
+		struct cell *trans, struct tmcb_params *params);
 /* run all REQUEST_IN callbacks */
-void run_reqin_callbacks( struct cell *trans, struct sip_msg *req, int code );
-void run_local_reqin_callbacks( struct cell *trans, struct sip_msg *req,
-		int code );
+void run_reqin_callbacks(struct cell *trans, struct sip_msg *req, int code);
+void run_local_reqin_callbacks(
+		struct cell *trans, struct sip_msg *req, int code);
 
 /* like run_trans_callbacks but provide outgoing buffer (i.e., the
  * processed message) to callback */
-void run_trans_callbacks_with_buf(int type, struct retr_buf* rbuf,
-		struct sip_msg* req, struct sip_msg* repl, short flags);
+void run_trans_callbacks_with_buf(int type, struct retr_buf *rbuf,
+		struct sip_msg *req, struct sip_msg *repl, short flags);
 
 /* like run_trans_callbacks but tmcb_params assumed to contain data already */
-void run_trans_callbacks_off_params(int type, struct cell* t, struct tmcb_params* p);
+void run_trans_callbacks_off_params(
+		int type, struct cell *t, struct tmcb_params *p);
 
 #endif

File diff ditekan karena terlalu besar
+ 326 - 277
src/modules/tm/t_lookup.c


+ 52 - 52
src/modules/tm/t_lookup.h

@@ -19,7 +19,6 @@
  */
 
 
-
 #ifndef _T_LOOKUP_H
 #define _T_LOOKUP_H
 
@@ -27,49 +26,47 @@
 #include "config.h"
 #include "t_funcs.h"
 
-#define T_UNDEFINED  ( (struct cell*) -1 )
-#define T_NULL_CELL       ( (struct cell*) 0 )
+#define T_UNDEFINED ((struct cell *)-1)
+#define T_NULL_CELL ((struct cell *)0)
 
 #define T_BR_UNDEFINED (-1)
 
-extern msg_ctx_id_t  tm_global_ctx_id;
+extern msg_ctx_id_t tm_global_ctx_id;
 
 
 void init_t(void);
-int init_rb( struct retr_buf *rb, struct sip_msg *msg );
+int init_rb(struct retr_buf *rb, struct sip_msg *msg);
 
-typedef struct cell* (*tlookup_original_f)( struct sip_msg* p_msg );
-struct cell* t_lookupOriginalT( struct sip_msg* p_msg );
+typedef struct cell *(*tlookup_original_f)(struct sip_msg *p_msg);
+struct cell *t_lookupOriginalT(struct sip_msg *p_msg);
 
-int t_reply_matching( struct sip_msg* , int* );
+int t_reply_matching(struct sip_msg *, int *);
 
-typedef int (*tlookup_request_f)(struct sip_msg*, int, int*);
+typedef int (*tlookup_request_f)(struct sip_msg *, int, int *);
 
-int t_lookup_request( struct sip_msg* p_msg, int leave_new_locked,
-						int* canceled);
-int t_newtran( struct sip_msg* p_msg );
+int t_lookup_request(
+		struct sip_msg *p_msg, int leave_new_locked, int *canceled);
+int t_newtran(struct sip_msg *p_msg);
 
-int _add_branch_label( struct cell *trans,
-    char *str, int *len, int branch );
-int add_branch_label( struct cell *trans, 
-	struct sip_msg *p_msg, int branch );
+int _add_branch_label(struct cell *trans, char *str, int *len, int branch);
+int add_branch_label(struct cell *trans, struct sip_msg *p_msg, int branch);
 
 /* releases T-context */
-int t_unref( struct sip_msg *p_msg);
-typedef int (*tunref_f)( struct sip_msg *p_msg);
+int t_unref(struct sip_msg *p_msg);
+typedef int (*tunref_f)(struct sip_msg *p_msg);
 
-typedef int (*tcheck_f)(struct sip_msg*, int*);
+typedef int (*tcheck_f)(struct sip_msg *, int *);
 
 /* old t_check version (no e2eack support) */
-int t_check(struct sip_msg* , int *branch );
+int t_check(struct sip_msg *, int *branch);
 /* new version, e2eack and different return convention */
-int t_check_msg(struct sip_msg* , int *branch );
+int t_check_msg(struct sip_msg *, int *branch);
 
-typedef struct cell * (*tgett_f)(void);
+typedef struct cell *(*tgett_f)(void);
 struct cell *get_t(void);
 
-typedef struct cell* (*tfind_f)(struct sip_msg*, int*, int*);
-struct cell* t_find(struct sip_msg *msg, int *branch, int *vref);
+typedef struct cell *(*tfind_f)(struct sip_msg *, int *, int *);
+struct cell *t_find(struct sip_msg *msg, int *branch, int *vref);
 
 typedef void (*tunset_f)(void);
 void t_unset(void);
@@ -83,46 +80,48 @@ typedef void (*tsett_f)(struct cell *t, int branch);
 void set_t(struct cell *t, int branch);
 
 
-#define T_GET_TI       "t_get_trans_ident"
+#define T_GET_TI "t_get_trans_ident"
 #define T_LOOKUP_IDENT "t_lookup_ident"
-#define T_IS_LOCAL     "t_is_local"
+#define T_IS_LOCAL "t_is_local"
 
-typedef int (*tislocal_f)(struct sip_msg*);
-typedef int (*tnewtran_f)(struct sip_msg*);
-typedef int (*tget_ti_f)(struct sip_msg*, unsigned int*, unsigned int*);
-typedef int (*tlookup_ident_f)(struct cell**, unsigned int, unsigned int);
-typedef int (*trelease_f)(struct sip_msg*);
+typedef int (*tislocal_f)(struct sip_msg *);
+typedef int (*tnewtran_f)(struct sip_msg *);
+typedef int (*tget_ti_f)(struct sip_msg *, unsigned int *, unsigned int *);
+typedef int (*tlookup_ident_f)(struct cell **, unsigned int, unsigned int);
+typedef int (*trelease_f)(struct sip_msg *);
 typedef int (*tlookup_callid_f)(struct cell **, str, str);
-typedef int (*tset_fr_f)(struct sip_msg*, unsigned int, unsigned int);
-
-int t_is_local(struct sip_msg*);
-int t_get_trans_ident(struct sip_msg* p_msg, unsigned int* hash_index, unsigned int* label);
-int t_lookup_ident(struct cell** trans, unsigned int hash_index, unsigned int label);
-int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index,
+typedef int (*tset_fr_f)(struct sip_msg *, unsigned int, unsigned int);
+
+int t_is_local(struct sip_msg *);
+int t_get_trans_ident(
+		struct sip_msg *p_msg, unsigned int *hash_index, unsigned int *label);
+int t_lookup_ident(
+		struct cell **trans, unsigned int hash_index, unsigned int label);
+int t_lookup_ident_filter(struct cell **trans, unsigned int hash_index,
 		unsigned int label, int filter);
-tm_cell_t *t_find_ident_filter(unsigned int hash_index, unsigned int label,
-		int filter);
+tm_cell_t *t_find_ident_filter(
+		unsigned int hash_index, unsigned int label, int filter);
 /* lookup a transaction by callid and cseq */
-int t_lookup_callid(struct cell** trans, str callid, str cseq);
+int t_lookup_callid(struct cell **trans, str callid, str cseq);
 
-int t_request_search( struct sip_msg* p_msg, struct cell **r_cell);
+int t_request_search(struct sip_msg *p_msg, struct cell **r_cell);
 int t_reply_search(struct sip_msg *p_msg, struct cell **r_cell, int *r_branch);
 
-int t_set_fr(struct sip_msg* msg, unsigned int fr_inv_to, unsigned int fr_to );
+int t_set_fr(struct sip_msg *msg, unsigned int fr_inv_to, unsigned int fr_to);
 int t_reset_fr(void);
-int t_set_retr(struct sip_msg* msg, unsigned int t1_to, unsigned int t2_to);
+int t_set_retr(struct sip_msg *msg, unsigned int t1_to, unsigned int t2_to);
 int t_reset_retr(void);
-int t_set_max_lifetime(struct sip_msg* msg, unsigned int eol_inv,
-											unsigned int eol_noninv);
+int t_set_max_lifetime(
+		struct sip_msg *msg, unsigned int eol_inv, unsigned int eol_noninv);
 int t_reset_max_lifetime(void);
 
 /**
  * Returns the hash coordinates of the transaction current CANCEL is targeting.
  */
-int t_get_canceled_ident(struct sip_msg *msg, unsigned int *hash_index, 
-		unsigned int *label);
-typedef int (*t_get_canceled_ident_f)(struct sip_msg *msg, 
-		unsigned int *hash_index, unsigned int *label);
+int t_get_canceled_ident(
+		struct sip_msg *msg, unsigned int *hash_index, unsigned int *label);
+typedef int (*t_get_canceled_ident_f)(
+		struct sip_msg *msg, unsigned int *hash_index, unsigned int *label);
 
 /**
  * required by TMX (K/O extensions)
@@ -130,13 +129,14 @@ typedef int (*t_get_canceled_ident_f)(struct sip_msg *msg,
 #define WITH_TM_CTX
 #ifdef WITH_TM_CTX
 
-typedef struct _tm_ctx {
+typedef struct _tm_ctx
+{
 	int branch_index;
 } tm_ctx_t;
 
-typedef tm_ctx_t* (*tm_ctx_get_f)(void);
+typedef tm_ctx_t *(*tm_ctx_get_f)(void);
 
-tm_ctx_t* tm_ctx_get(void);
+tm_ctx_t *tm_ctx_get(void);
 void tm_ctx_init(void);
 void tm_ctx_set_branch_index(int v);
 

File diff ditekan karena terlalu besar
+ 297 - 286
src/modules/tm/t_msgbuilder.c


+ 17 - 22
src/modules/tm/t_msgbuilder.h

@@ -28,26 +28,22 @@
 #include "h_table.h"
 #include "t_reply.h"
 
-char *build_local(struct cell *Trans, unsigned int branch,
-	unsigned int *len, char *method, int method_len, str *to
-	, struct cancel_reason* reason
-	);
+char *build_local(struct cell *Trans, unsigned int branch, unsigned int *len,
+		char *method, int method_len, str *to, struct cancel_reason *reason);
 
 char *build_local_reparse(struct cell *Trans, unsigned int branch,
-	unsigned int *len, char *method, int method_len, str *to
-	, struct cancel_reason* reason
-	);
+		unsigned int *len, char *method, int method_len, str *to,
+		struct cancel_reason *reason);
 
-char *build_uac_request(  str msg_type, str dst, str from,
-	str fromtag, int cseq, str callid, str headers,
-	str body, int branch,
-	struct cell *t, unsigned int *len);
+char *build_uac_request(str msg_type, str dst, str from, str fromtag, int cseq,
+		str callid, str headers, str body, int branch, struct cell *t,
+		unsigned int *len);
 
 /*
  * The function creates an UAC CANCEL
  */
-char *build_uac_cancel(str *headers,str *body,struct cell *cancelledT,
-		unsigned int branch, unsigned int *len, struct dest_info* dst);
+char *build_uac_cancel(str *headers, str *body, struct cell *cancelledT,
+		unsigned int branch, unsigned int *len, struct dest_info *dst);
 
 /*
  * The function creates an ACK to 200 OK. Route set will be created
@@ -55,24 +51,23 @@ char *build_uac_cancel(str *headers,str *body,struct cell *cancelledT,
  * request should be send. The function is used by tm when it generates
  * local ACK to 200 OK (on behalf of applications using uac
  */
-char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans,
-					unsigned int branch, str *hdrs, str *body,
-					unsigned int *len, struct dest_info* dst);
+char *build_dlg_ack(struct sip_msg *rpl, struct cell *Trans,
+		unsigned int branch, str *hdrs, str *body, unsigned int *len,
+		struct dest_info *dst);
 
 
 /*
  * Create a request
  */
-char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, int branch,
-		struct cell *t, int* len, struct dest_info* dst);
+char *build_uac_req(str *method, str *headers, str *body, dlg_t *dialog,
+		int branch, struct cell *t, int *len, struct dest_info *dst);
 
 
-int t_calc_branch(struct cell *t,
-	int b, char *branch, int *branch_len);
+int t_calc_branch(struct cell *t, int b, char *branch, int *branch_len);
 
 /* exported minimum functions for use in t_cancel */
-char* print_callid_mini(char* target, str callid);
-char* print_cseq_mini(char* target, str* cseq, str* method);
+char *print_callid_mini(char *target, str callid);
+char *print_cseq_mini(char *target, str *cseq, str *method);
 
 typedef void (*t_uas_request_clean_parsed_f)(tm_cell_t *t);
 void t_uas_request_clean_parsed(tm_cell_t *t);

File diff ditekan karena terlalu besar
+ 255 - 266
src/modules/tm/t_reply.c


+ 61 - 57
src/modules/tm/t_reply.h

@@ -19,7 +19,6 @@
  */
 
 
-
 #ifndef _T_REPLY_H
 #define _T_REPLY_H
 
@@ -30,9 +29,10 @@
 
 
 /* reply processing status */
-enum rps {
+enum rps
+{
 	/* something bad happened */
-	RPS_ERROR=0,
+	RPS_ERROR = 0,
 	/* transaction completed but we still accept the reply */
 	RPS_PUSHED_AFTER_COMPLETION,
 	/* reply discarded */
@@ -57,7 +57,7 @@ extern int failure_reply_mode;
 extern int faked_reply_prio;
 
 extern int tm_rich_redirect;
- 
+
 /* has this to-tag been never seen in previous 200/INVs? */
 int unmatched_totag(struct cell *t, struct sip_msg *ack);
 
@@ -66,9 +66,9 @@ typedef unsigned int branch_bm_t;
 
 /* reason building blocks (see rfc3326) */
 #define REASON_PREFIX "Reason: SIP;cause="
-#define REASON_PREFIX_LEN (sizeof(REASON_PREFIX)-1)
+#define REASON_PREFIX_LEN (sizeof(REASON_PREFIX) - 1)
 #define REASON_TEXT ";text="
-#define REASON_TEXT_LEN (sizeof(REASON_TEXT)-1)
+#define REASON_TEXT_LEN (sizeof(REASON_TEXT) - 1)
 
 #define CANCEL_REAS_UNKNOWN 0
 #define CANCEL_REAS_PACKED_HDRS -1
@@ -78,41 +78,43 @@ typedef unsigned int branch_bm_t;
 
 
 /** cancel reason structure.*/
-struct cancel_reason {
+struct cancel_reason
+{
 	short cause; /**< 0 = unknown, -1 =  cancel, > 0 final reply code. */
-	union{
+	union
+	{
 		str text; /**< reason text if reason is final reply .*/
-		struct sip_msg* e2e_cancel; /**< cancel msg if reason is cancel. */
-		str packed_hdrs; /**< complete reason headers. */
-	}u;
+		struct sip_msg *e2e_cancel; /**< cancel msg if reason is cancel. */
+		str packed_hdrs;			/**< complete reason headers. */
+	} u;
 };
 
-struct cancel_info {
+struct cancel_info
+{
 	branch_bm_t cancel_bitmap; /**< cancel branch bitmap */
 	struct cancel_reason reason;
 };
 
 
-#define init_cancel_reason(cr) \
-	do {\
-		(cr)->cause=0; \
-		(cr)->u.e2e_cancel=0; \
+#define init_cancel_reason(cr)  \
+	do {                        \
+		(cr)->cause = 0;        \
+		(cr)->u.e2e_cancel = 0; \
 	} while(0)
 
-#define init_cancel_info(ci) \
-	do {\
-		(ci)->cancel_bitmap=0; \
+#define init_cancel_info(ci)               \
+	do {                                   \
+		(ci)->cancel_bitmap = 0;           \
 		init_cancel_reason(&(ci)->reason); \
-	}while (0);
+	} while(0);
 
 
 /* reply export types */
-typedef int (*treply_f)(struct sip_msg * , unsigned int , char * );
-typedef int (*treply_wb_f)( struct cell* trans,
-	unsigned int code, str *text, str *body,
-	str *new_header, str *to_tag);
-typedef int (*treply_trans_f)(struct cell *t, struct sip_msg* p_msg, unsigned int code,
-	char * text);
+typedef int (*treply_f)(struct sip_msg *, unsigned int, char *);
+typedef int (*treply_wb_f)(struct cell *trans, unsigned int code, str *text,
+		str *body, str *new_header, str *to_tag);
+typedef int (*treply_trans_f)(
+		struct cell *t, struct sip_msg *p_msg, unsigned int code, char *text);
 
 /* wrapper function needed after changes in w_t_reply */
 int w_t_reply_wrp(struct sip_msg *m, unsigned int code, char *txt);
@@ -131,17 +133,19 @@ void tm_reply_mutex_unlock(tm_cell_t *t);
  * Returns :   0 - core router stops
  *             1 - core router relay statelessly
  */
-int reply_received( struct sip_msg  *p_msg ) ;
+int reply_received(struct sip_msg *p_msg);
 
 /* return 1 if a failure_route processes */
-int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
-					int code, int extra_flags);
-typedef int (*run_failure_handlers_f)(struct cell*, struct sip_msg*, int, int);
+int run_failure_handlers(
+		struct cell *t, struct sip_msg *rpl, int code, int extra_flags);
+typedef int (*run_failure_handlers_f)(
+		struct cell *, struct sip_msg *, int, int);
 
 /* return 1 if a branch_failure_route processes */
-int run_branch_failure_handlers(struct cell *t, struct sip_msg *rpl,
-					int code, int extra_flags);
-typedef int (*run_branch_failure_handlers_f)(struct cell*, struct sip_msg*, int, int);
+int run_branch_failure_handlers(
+		struct cell *t, struct sip_msg *rpl, int code, int extra_flags);
+typedef int (*run_branch_failure_handlers_f)(
+		struct cell *, struct sip_msg *, int, int);
 
 
 /* Retransmits the last sent inbound reply.
@@ -157,49 +161,49 @@ typedef int (*run_branch_failure_handlers_f)(struct cell*, struct sip_msg*, int,
  */
 
 
-int t_reply_with_body(struct cell *trans, unsigned int code,
-		str *text, str *body, str *new_header, str *to_tag);
+int t_reply_with_body(struct cell *trans, unsigned int code, str *text,
+		str *body, str *new_header, str *to_tag);
 
 
 /* send a UAS reply
  * returns 1 if everything was OK or -1 for error
  */
-int t_reply( struct cell *t, struct sip_msg * , unsigned int , char * );
+int t_reply(struct cell *t, struct sip_msg *, unsigned int, char *);
 /* the same as t_reply, except it does not claim
    REPLY_LOCK -- useful to be called within reply
    processing
 */
-int t_reply_str( struct cell *t, struct sip_msg * , unsigned int , str * );
+int t_reply_str(struct cell *t, struct sip_msg *, unsigned int, str *);
 
-int t_reply_unsafe( struct cell *t, struct sip_msg * , unsigned int , char * );
-int t_reply_str_unsafe( struct cell *t, struct sip_msg * , unsigned int , str * );
+int t_reply_unsafe(struct cell *t, struct sip_msg *, unsigned int, char *);
+int t_reply_str_unsafe(struct cell *t, struct sip_msg *, unsigned int, str *);
 
 
-enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch,
-	unsigned int msg_status, struct cancel_info *cancel_data,
-	int do_put_on_wait );
+enum rps relay_reply(struct cell *t, struct sip_msg *p_msg, int branch,
+		unsigned int msg_status, struct cancel_info *cancel_data,
+		int do_put_on_wait);
 
-enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch,
-	unsigned int msg_status, struct cancel_info *cancel_data );
+enum rps local_reply(struct cell *t, struct sip_msg *p_msg, int branch,
+		unsigned int msg_status, struct cancel_info *cancel_data);
 
-void set_final_timer( /* struct s_table *h_table,*/ struct cell *t );
+void set_final_timer(/* struct s_table *h_table,*/ struct cell *t);
 
-void cleanup_uac_timers( struct cell *t );
+void cleanup_uac_timers(struct cell *t);
 
-void on_failure_reply( struct cell* t, struct sip_msg* msg,
-	int code, void *param  );
+void on_failure_reply(
+		struct cell *t, struct sip_msg *msg, int code, void *param);
 
 /* set which 'reply' structure to take if only negative
    replies arrive
 */
-void t_on_failure( unsigned int go_to );
+void t_on_failure(unsigned int go_to);
 unsigned int get_on_failure(void);
-void t_on_branch_failure( unsigned int go_to );
+void t_on_branch_failure(unsigned int go_to);
 unsigned int get_on_branch_failure(void);
-void t_on_reply( unsigned int go_to );
+void t_on_reply(unsigned int go_to);
 unsigned int get_on_reply(void);
 
-int t_retransmit_reply( struct cell *t );
+int t_retransmit_reply(struct cell *t);
 
 void tm_init_tags(void);
 
@@ -213,12 +217,12 @@ int t_pick_branch_blind(struct cell *t, int *res_code);
  */
 void t_drop_replies(int v);
 
-void rpc_reply(rpc_t* rpc, void* c);
-void rpc_reply_callid(rpc_t* rpc, void* c);
+void rpc_reply(rpc_t *rpc, void *c);
+void rpc_reply_callid(rpc_t *rpc, void *c);
 
-int faked_env(struct cell *t,struct sip_msg *msg, int is_async_env);
-struct sip_msg * fake_req(struct sip_msg *shmem_msg,
-	int extra_flags, struct ua_client *uac, int *len);
+int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env);
+struct sip_msg *fake_req(struct sip_msg *shmem_msg, int extra_flags,
+		struct ua_client *uac, int *len);
 
 void free_faked_req(struct sip_msg *faked_req, int len);
 

+ 200 - 192
src/modules/tm/t_serial.c

@@ -41,20 +41,21 @@
 #include "t_lookup.h"
 
 /* usr_avp flag for sequential forking */
-#define Q_FLAG      (1<<2)
+#define Q_FLAG (1 << 2)
 /* t_load_contacts modes/algorithms */
-#define T_LOAD_STANDARD     0
+#define T_LOAD_STANDARD 0
 #define T_LOAD_PROPORTIONAL 1
 
 extern str ulattrs_xavp_name;
 
 /* Struture where information regarding contacts is stored */
-struct contact {
+struct contact
+{
 	str uri;
 	qvalue_t q;
 	str dst_uri;
 	str path;
-	struct socket_info* sock;
+	struct socket_info *sock;
 	str instance;
 	str ruid;
 	str location_ua;
@@ -65,7 +66,8 @@ struct contact {
 	unsigned short q_index;
 };
 
-struct instance_list {
+struct instance_list
+{
 	str instance;
 	struct instance_list *next;
 };
@@ -73,9 +75,10 @@ struct instance_list {
 /* 
  * Frees contact list used by load_contacts function
  */
-static inline void free_contact_list(struct contact *curr) {
+static inline void free_contact_list(struct contact *curr)
+{
 	struct contact *prev;
-	while (curr) {
+	while(curr) {
 		prev = curr;
 		curr = curr->next;
 		pkg_free(prev);
@@ -85,9 +88,10 @@ static inline void free_contact_list(struct contact *curr) {
 /* 
  * Frees instance list used by next_contacts function
  */
-static inline void free_instance_list(struct instance_list *curr) {
+static inline void free_instance_list(struct instance_list *curr)
+{
 	struct instance_list *prev;
-	while (curr) {
+	while(curr) {
 		pkg_free(curr->instance.s);
 		prev = curr;
 		curr = curr->next;
@@ -106,9 +110,8 @@ static str ruid_name = {"ruid", 4};
 static str ua_name = {"ua", 2};
 
 void add_contacts_avp(str *uri, str *dst_uri, str *path, str *sock_str,
-		unsigned int flags, unsigned int q_flag, str *instance,
-		str *ruid, str *location_ua, sr_xavp_t *ulattrs_xavp,
-		sr_xavp_t **pxavp)
+		unsigned int flags, unsigned int q_flag, str *instance, str *ruid,
+		str *location_ua, sr_xavp_t *ulattrs_xavp, sr_xavp_t **pxavp)
 {
 	sr_xavp_t *record;
 	sr_xval_t val;
@@ -119,19 +122,19 @@ void add_contacts_avp(str *uri, str *dst_uri, str *path, str *sock_str,
 	val.v.s = *uri;
 	xavp_add_value(&uri_name, &val, &record);
 
-	if (dst_uri->len > 0) {
+	if(dst_uri->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *dst_uri;
 		xavp_add_value(&dst_uri_name, &val, &record);
 	}
 
-	if (path->len > 0) {
+	if(path->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *path;
 		xavp_add_value(&path_name, &val, &record);
 	}
 
-	if (sock_str->len > 0) {
+	if(sock_str->len > 0) {
 		val.v.s = *sock_str;
 		xavp_add_value(&sock_name, &val, &record);
 	}
@@ -144,19 +147,19 @@ void add_contacts_avp(str *uri, str *dst_uri, str *path, str *sock_str,
 	val.v.l = q_flag;
 	xavp_add_value(&q_flag_name, &val, &record);
 
-	if (instance->len > 0) {
+	if(instance->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *instance;
 		xavp_add_value(&instance_name, &val, &record);
 	}
 
-	if (ruid->len > 0) {
+	if(ruid->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *ruid;
 		xavp_add_value(&ruid_name, &val, &record);
 	}
 
-	if (location_ua->len > 0) {
+	if(location_ua->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *location_ua;
 		xavp_add_value(&ua_name, &val, &record);
@@ -167,14 +170,14 @@ void add_contacts_avp(str *uri, str *dst_uri, str *path, str *sock_str,
 	val.type = SR_XTYPE_XAVP;
 	val.v.xavp = record;
 	if(pxavp) {
-		if((*pxavp = xavp_add_value_after(&contacts_avp, &val, *pxavp))==NULL) {
+		if((*pxavp = xavp_add_value_after(&contacts_avp, &val, *pxavp))
+				== NULL) {
 			/* failed to add xavps to the end of the list */
 			LM_ERR("failed to add xavps to the end of the list\n");
 			xavp_destroy_list(&record);
 		}
-	}
-	else {
-		if(xavp_add_value(&contacts_avp, &val, NULL)==NULL) {
+	} else {
+		if(xavp_add_value(&contacts_avp, &val, NULL) == NULL) {
 			/* failed to add xavps to root list */
 			LM_ERR("failed to add xavps to root list\n");
 			xavp_destroy_list(&record);
@@ -185,14 +188,15 @@ void add_contacts_avp(str *uri, str *dst_uri, str *path, str *sock_str,
 /*
  * Socket preparation for 'add_contacts_avp' function
  */
-int add_contacts_avp_preparation(struct contact *curr, char *sock_buf, sr_xavp_t **pxavp)
+int add_contacts_avp_preparation(
+		struct contact *curr, char *sock_buf, sr_xavp_t **pxavp)
 {
 	str sock_str;
 	int len;
 
-	if (curr->sock) {
+	if(curr->sock) {
 		len = MAX_SOCKET_STR - 1;
-		if (socket2str(sock_buf, &len, curr->sock) < 0) {
+		if(socket2str(sock_buf, &len, curr->sock) < 0) {
 			LM_ERR("failed to convert socket to str\n");
 			return -1;
 		}
@@ -204,10 +208,9 @@ int add_contacts_avp_preparation(struct contact *curr, char *sock_buf, sr_xavp_t
 		sock_str.len = 0;
 	}
 
-	add_contacts_avp(&(curr->uri), &(curr->dst_uri), &(curr->path),
-			&sock_str, curr->flags, curr->q_flag,
-			&(curr->instance), &(curr->ruid), &(curr->location_ua),
-			curr->ulattrs, pxavp);
+	add_contacts_avp(&(curr->uri), &(curr->dst_uri), &(curr->path), &sock_str,
+			curr->flags, curr->q_flag, &(curr->instance), &(curr->ruid),
+			&(curr->location_ua), curr->ulattrs, pxavp);
 
 	return 0;
 }
@@ -224,8 +227,8 @@ int t_load_contacts_standard(struct contact *contacts, char *sock_buf)
 	/* Assign values for q_flags */
 	curr = contacts;
 	curr->q_flag = 0;
-	while (curr->next) {
-		if (curr->q < curr->next->q) {
+	while(curr->next) {
+		if(curr->q < curr->next->q) {
 			curr->next->q_flag = Q_FLAG;
 		} else {
 			curr->next->q_flag = 0;
@@ -235,8 +238,8 @@ int t_load_contacts_standard(struct contact *contacts, char *sock_buf)
 
 	/* Add contacts to contacts_avp */
 	curr = contacts;
-	while (curr) {
-		if (add_contacts_avp_preparation(curr, sock_buf, NULL) < 0) {
+	while(curr) {
+		if(add_contacts_avp_preparation(curr, sock_buf, NULL) < 0) {
 			return -1;
 		}
 
@@ -251,39 +254,41 @@ int t_load_contacts_standard(struct contact *contacts, char *sock_buf)
  * proportional order. Each contact is associated with Q_FLAG beacuse
  * only one contact at a time has to ring.
  */
-int t_load_contacts_proportional(struct contact *contacts, char *sock_buf, int n, unsigned short q_total)
+int t_load_contacts_proportional(
+		struct contact *contacts, char *sock_buf, int n, unsigned short q_total)
 {
 	int q_remove, n_rand, idx;
 	struct contact *curr;
 	sr_xavp_t *lxavp = NULL;
 
 	/* Add contacts with q-value NOT equals to 0 and NOT negative to contacts_avp */
-	for (idx = 0; idx < n; idx++) {
+	for(idx = 0; idx < n; idx++) {
 		q_remove = 0;
 
 		/* Generate a random number from 0 to (q_total -1) */
 		n_rand = kam_rand() % q_total;
 
 		curr = contacts;
-		while (curr) {
-			if (curr->q <= 0) {
+		while(curr) {
+			if(curr->q <= 0) {
 				curr = curr->next;
 				continue;
 			}
 
-			if (q_remove != 0) {
+			if(q_remove != 0) {
 				/* ALREADY FOUND */
 				curr->q_index -= q_remove;
-			}
-			else if (curr->q_index > n_rand) {
+			} else if(curr->q_index > n_rand) {
 				/* FOUND */
-				LM_DBG("proportionally selected contact with uri: %s (q: %d, random: %d, q_index: %d, q_total: %d)\n", curr->uri.s, curr->q, n_rand, curr->q_index, q_total);
+				LM_DBG("proportionally selected contact with uri: %s (q: %d, "
+					   "random: %d, q_index: %d, q_total: %d)\n",
+						curr->uri.s, curr->q, n_rand, curr->q_index, q_total);
 				q_remove = curr->q;
 				q_total -= q_remove;
 				curr->q_index -= q_remove;
 				curr->q_flag = Q_FLAG;
 
-				if (add_contacts_avp_preparation(curr, sock_buf, &lxavp) < 0) {
+				if(add_contacts_avp_preparation(curr, sock_buf, &lxavp) < 0) {
 					return -1;
 				}
 			}
@@ -294,16 +299,17 @@ int t_load_contacts_proportional(struct contact *contacts, char *sock_buf, int n
 
 	/* Add contacts with q-value equals to 0 or negative to contacts_avp */
 	curr = contacts;
-	while (curr) {
-		if (curr->q > 0) {
+	while(curr) {
+		if(curr->q > 0) {
 			curr = curr->next;
 			continue;
 		}
 
-		LM_DBG("proportionally added backup contact with uri: %s (q: %d)\n", curr->uri.s, curr->q);
+		LM_DBG("proportionally added backup contact with uri: %s (q: %d)\n",
+				curr->uri.s, curr->q);
 		curr->q_flag = Q_FLAG;
 
-		if (add_contacts_avp_preparation(curr, sock_buf, &lxavp) < 0) {
+		if(add_contacts_avp_preparation(curr, sock_buf, &lxavp) < 0) {
 			return -1;
 		}
 
@@ -319,7 +325,7 @@ int t_load_contacts_proportional(struct contact *contacts, char *sock_buf, int n
  * function based on the selected ordering machanism. Finally,
  * removes all branches from destination set.
  */
-int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
+int ki_t_load_contacts_mode(struct sip_msg *msg, int mode)
 {
 	branch_t *branch;
 	str *ruri;
@@ -330,31 +336,31 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 	int n_elements = 0;
 
 	/* Check if contacts_avp has been defined */
-	if (contacts_avp.len == 0) {
+	if(contacts_avp.len == 0) {
 		LM_ERR("feature has been disabled - "
-				"to enable define contacts_avp module parameter");
+			   "to enable define contacts_avp module parameter");
 		return -1;
 	}
 
 	/* Check if anything needs to be done */
 	LM_DBG("nr_branches is %d - new uri mode %d\n", nr_branches, ruri_is_new);
 
-	if ((nr_branches == 0) || ((nr_branches == 1) && !ruri_is_new)) {
+	if((nr_branches == 0) || ((nr_branches == 1) && !ruri_is_new)) {
 		LM_DBG("nothing to do - only one contact!\n");
 		return 1;
 	}
 
 	/* Allocate memory for first contact */
 	contacts = (struct contact *)pkg_malloc(sizeof(struct contact));
-	if (!contacts) {
+	if(!contacts) {
 		PKG_MEM_ERROR_FMT("for contact info\n");
 		return -1;
 	}
 	memset(contacts, 0, sizeof(struct contact));
 
-	if (ruri_is_new) {
+	if(ruri_is_new) {
 		ruri = GET_RURI(msg);
-		if (!ruri) {
+		if(!ruri) {
 			free_contact_list(contacts);
 			LM_ERR("no Request-URI found\n");
 			return -1;
@@ -370,8 +376,7 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 		contacts->instance = msg->instance;
 		contacts->ruid = msg->ruid;
 		contacts->location_ua = msg->location_ua;
-		if (ulattrs_xavp_name.s != NULL)
-		{
+		if(ulattrs_xavp_name.s != NULL) {
 			contacts->ulattrs = xavp_get_by_index(&ulattrs_xavp_name, 0, NULL);
 		}
 		first_idx = 0;
@@ -393,18 +398,17 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 		contacts->ruid.len = branch->ruid_len;
 		contacts->location_ua.s = branch->location_ua;
 		contacts->location_ua.len = branch->location_ua_len;
-		if (ulattrs_xavp_name.s != NULL)
-		{
+		if(ulattrs_xavp_name.s != NULL) {
 			contacts->ulattrs = xavp_get_by_index(&ulattrs_xavp_name, 1, NULL);
 		}
 		first_idx = 1;
 	}
 
 	contacts->q_index = contacts->q;
-	if (mode == T_LOAD_PROPORTIONAL) {
+	if(mode == T_LOAD_PROPORTIONAL) {
 		/* Save in q_index the index to check for the proportional order
 		   Don't consider elements with Q value 0 or negative */
-		if (contacts->q > 0) {
+		if(contacts->q > 0) {
 			q_total += contacts->q;
 			n_elements += 1;
 		}
@@ -414,10 +418,10 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 	contacts->next = (struct contact *)0;
 
 	/* Insert (remaining) branches to contact list in increasing q order */
-	for (idx = first_idx; (branch = get_sip_branch(idx)) != 0; idx++) {
+	for(idx = first_idx; (branch = get_sip_branch(idx)) != 0; idx++) {
 
 		next = (struct contact *)pkg_malloc(sizeof(struct contact));
-		if (!next) {
+		if(!next) {
 			PKG_MEM_ERROR_FMT("for contact info\n");
 			free_contact_list(contacts);
 			return -1;
@@ -439,16 +443,16 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 		next->ruid.len = branch->ruid_len;
 		next->location_ua.s = branch->location_ua;
 		next->location_ua.len = branch->location_ua_len;
-		if (ulattrs_xavp_name.s != NULL)
-		{
-			next->ulattrs = xavp_get_by_index(&ulattrs_xavp_name, idx + 1, NULL);
+		if(ulattrs_xavp_name.s != NULL) {
+			next->ulattrs =
+					xavp_get_by_index(&ulattrs_xavp_name, idx + 1, NULL);
 		}
 
 		next->q_index = next->q;
-		if (mode == T_LOAD_PROPORTIONAL) {
+		if(mode == T_LOAD_PROPORTIONAL) {
 			/* Save in q_index the index to check for the proportional order
 			   Don't consider elements with Q value 0 or negative */
-			if (next->q > 0) {
+			if(next->q > 0) {
 				q_total += next->q;
 				n_elements += 1;
 			}
@@ -459,27 +463,29 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 
 		prev = (struct contact *)0;
 		curr = contacts;
-		if (mode == T_LOAD_PROPORTIONAL) {
-			while (curr &&
-					((curr->q_index < next->q_index) ||
-					 ((curr->q_index == next->q_index) && (next->path.len == 0)))) {
+		if(mode == T_LOAD_PROPORTIONAL) {
+			while(curr
+					&& ((curr->q_index < next->q_index)
+							|| ((curr->q_index == next->q_index)
+									&& (next->path.len == 0)))) {
 				prev = curr;
 				curr = curr->next;
 			}
 		} else {
-			while (curr &&
-					((curr->q < next->q) ||
-					 ((curr->q == next->q) && (next->path.len == 0)))) {
+			while(curr
+					&& ((curr->q < next->q)
+							|| ((curr->q == next->q)
+									&& (next->path.len == 0)))) {
 				prev = curr;
 				curr = curr->next;
 			}
 		}
-		if (!curr) {
+		if(!curr) {
 			next->next = (struct contact *)0;
 			prev->next = next;
 		} else {
 			next->next = curr;
-			if (prev) {
+			if(prev) {
 				prev->next = next;
 			} else {
 				contacts = next;
@@ -487,14 +493,14 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 		}
 	}
 
-	if (mode == T_LOAD_PROPORTIONAL) {
-		if (t_load_contacts_proportional(contacts, sock_buf, n_elements, q_total) < 0) {
+	if(mode == T_LOAD_PROPORTIONAL) {
+		if(t_load_contacts_proportional(contacts, sock_buf, n_elements, q_total)
+				< 0) {
 			free_contact_list(contacts);
 			return -1;
 		}
-	}
-	else {
-		if (t_load_contacts_standard(contacts, sock_buf) < 0) {
+	} else {
+		if(t_load_contacts_standard(contacts, sock_buf) < 0) {
 			free_contact_list(contacts);
 			return -1;
 		}
@@ -502,7 +508,7 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 
 	/* Clear all branches */
 	clear_branches();
-	if (ulattrs_xavp_name.s != NULL){
+	if(ulattrs_xavp_name.s != NULL) {
 		xavp_rm_by_name(&ulattrs_xavp_name, 1, NULL);
 	}
 
@@ -512,26 +518,27 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 	return 1;
 }
 
-int ki_t_load_contacts(struct sip_msg* msg)
+int ki_t_load_contacts(struct sip_msg *msg)
 {
 	return ki_t_load_contacts_mode(msg, T_LOAD_STANDARD);
 }
 
-int t_load_contacts(struct sip_msg* msg, char* mode, char* value)
+int t_load_contacts(struct sip_msg *msg, char *mode, char *value)
 {
 	int i = T_LOAD_STANDARD;
 
 	if(mode) {
-		if(get_int_fparam(&i, msg, (fparam_t*)mode)<0) return -1;
+		if(get_int_fparam(&i, msg, (fparam_t *)mode) < 0)
+			return -1;
 
-		if ((i != T_LOAD_STANDARD) && (i != T_LOAD_PROPORTIONAL)) {
-			LM_ERR("invalid load_contact mode: %d, please use 0 (standard) or 1 (proportional)\n", i);
+		if((i != T_LOAD_STANDARD) && (i != T_LOAD_PROPORTIONAL)) {
+			LM_ERR("invalid load_contact mode: %d, please use 0 (standard) or "
+				   "1 (proportional)\n",
+					i);
 			return -1;
 		}
 		LM_DBG("load_contact mode selected: %d\n", i);
-	}
-	else
-	{
+	} else {
 		LM_DBG("load_contact mode not selected, using: %d\n", T_LOAD_STANDARD);
 	}
 
@@ -539,8 +546,8 @@ int t_load_contacts(struct sip_msg* msg, char* mode, char* value)
 }
 
 void add_contact_flows_avp(str *uri, str *dst_uri, str *path, str *sock_str,
-		unsigned int flags, str *instance, str *ruid,
-		str *location_ua, sr_xavp_t *ulattrs_xavp)
+		unsigned int flags, str *instance, str *ruid, str *location_ua,
+		sr_xavp_t *ulattrs_xavp)
 {
 	sr_xavp_t *record;
 	sr_xval_t val;
@@ -551,36 +558,36 @@ void add_contact_flows_avp(str *uri, str *dst_uri, str *path, str *sock_str,
 	val.v.s = *uri;
 	xavp_add_value(&uri_name, &val, &record);
 
-	if (dst_uri->len > 0) {
+	if(dst_uri->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *dst_uri;
 		xavp_add_value(&dst_uri_name, &val, &record);
 	}
 
-	if (path->len > 0) {
+	if(path->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *path;
 		xavp_add_value(&path_name, &val, &record);
 	}
 
-	if (sock_str->len > 0) {
+	if(sock_str->len > 0) {
 		val.v.s = *sock_str;
 		xavp_add_value(&sock_name, &val, &record);
 	}
 
-	if (instance->len > 0) {
+	if(instance->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *instance;
 		xavp_add_value(&instance_name, &val, &record);
 	}
 
-	if (ruid->len > 0) {
+	if(ruid->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *ruid;
 		xavp_add_value(&ruid_name, &val, &record);
 	}
 
-	if (location_ua->len > 0) {
+	if(location_ua->len > 0) {
 		val.type = SR_XTYPE_STR;
 		val.v.s = *location_ua;
 		xavp_add_value(&ua_name, &val, &record);
@@ -594,7 +601,7 @@ void add_contact_flows_avp(str *uri, str *dst_uri, str *path, str *sock_str,
 
 	val.type = SR_XTYPE_XAVP;
 	val.v.xavp = record;
-	if(xavp_add_value(&contact_flows_avp, &val, NULL)==NULL) {
+	if(xavp_add_value(&contact_flows_avp, &val, NULL) == NULL) {
 		/* failed to add xavps to root list */
 		LM_ERR("failed to add xavps to root list\n");
 		xavp_destroy_list(&record);
@@ -612,7 +619,7 @@ void add_contact_flows_avp(str *uri, str *dst_uri, str *path, str *sock_str,
  * Returns 1, if contacts_avp was not empty and a destination set was
  * successfully added.  Returns -2, if contacts_avp was empty and thus
  * there was nothing to do. Returns -1 in case of an error. */
-int ki_t_next_contacts(struct sip_msg* msg)
+int ki_t_next_contacts(struct sip_msg *msg)
 {
 	str uri, dst_uri, path, instance, host, sock_str, ruid, location_ua;
 	struct socket_info *sock;
@@ -622,9 +629,9 @@ int ki_t_next_contacts(struct sip_msg* msg)
 	struct instance_list *il, *ilp;
 
 	/* Check if contacts_avp has been defined */
-	if (contacts_avp.len == 0) {
+	if(contacts_avp.len == 0) {
 		LM_ERR("feature has been disabled - "
-				"to enable define contacts_avp module parameter");
+			   "to enable define contacts_avp module parameter");
 		return -1;
 	}
 
@@ -632,7 +639,7 @@ int ki_t_next_contacts(struct sip_msg* msg)
 
 	/* Find first contacts_avp value */
 	xavp_list = xavp_get(&contacts_avp, NULL);
-	if (!xavp_list) {
+	if(!xavp_list) {
 		LM_DBG("no contacts in contacts_avp - we are done!\n");
 		return -2;
 	}
@@ -643,7 +650,7 @@ int ki_t_next_contacts(struct sip_msg* msg)
 	uri = vavp->val.v.s;
 
 	vavp = xavp_get(&dst_uri_name, xavp->val.v.xavp);
-	if (vavp != NULL) {
+	if(vavp != NULL) {
 		dst_uri = vavp->val.v.s;
 	} else {
 		dst_uri.s = 0;
@@ -651,7 +658,7 @@ int ki_t_next_contacts(struct sip_msg* msg)
 	}
 
 	vavp = xavp_get(&path_name, xavp->val.v.xavp);
-	if (vavp != NULL) {
+	if(vavp != NULL) {
 		path = vavp->val.v.s;
 	} else {
 		path.s = 0;
@@ -659,17 +666,17 @@ int ki_t_next_contacts(struct sip_msg* msg)
 	}
 
 	vavp = xavp_get(&sock_name, xavp->val.v.xavp);
-	if (vavp != NULL) {
+	if(vavp != NULL) {
 		sock_str.s = vavp->val.v.s.s;
-		if (parse_phostport(sock_str.s, &host.s, &host.len, &port, &proto)
+		if(parse_phostport(sock_str.s, &host.s, &host.len, &port, &proto)
 				!= 0) {
 			LM_ERR("parsing of socket info <%s> failed\n", sock_str.s);
 			xavp_rm(xavp_list, NULL);
 			return -1;
 		}
-		sock = grep_sock_info(&host, (unsigned short)port,
-				(unsigned short)proto);
-		if (sock == 0) {
+		sock = grep_sock_info(
+				&host, (unsigned short)port, (unsigned short)proto);
+		if(sock == 0) {
 			xavp_rm(xavp_list, NULL);
 			return -1;
 		}
@@ -685,15 +692,15 @@ int ki_t_next_contacts(struct sip_msg* msg)
 
 	vavp = xavp_get(&instance_name, xavp->val.v.xavp);
 	il = (struct instance_list *)0;
-	if ((vavp != NULL) && !q_flag) {
+	if((vavp != NULL) && !q_flag) {
 		instance = vavp->val.v.s;
 		il = (struct instance_list *)pkg_malloc(sizeof(struct instance_list));
-		if (!il) {
+		if(!il) {
 			PKG_MEM_ERROR_FMT("for instance list entry\n");
 			return -1;
 		}
 		il->instance.s = pkg_malloc(instance.len);
-		if (!il->instance.s) {
+		if(!il->instance.s) {
 			pkg_free(il);
 			PKG_MEM_ERROR_FMT("for instance list instance\n");
 			return -1;
@@ -708,41 +715,40 @@ int ki_t_next_contacts(struct sip_msg* msg)
 	}
 
 	vavp = xavp_get(&ruid_name, xavp->val.v.xavp);
-	if (vavp != NULL) {
+	if(vavp != NULL) {
 		ruid = vavp->val.v.s;
 	} else {
 		ruid.s = 0;
 		ruid.len = 0;
 	}
 	vavp = xavp_get(&ua_name, xavp->val.v.xavp);
-	if (vavp != NULL) {
+	if(vavp != NULL) {
 		location_ua = vavp->val.v.s;
 	} else {
 		location_ua.s = 0;
 		location_ua.len = 0;
 	}
 
-	if (ulattrs_xavp_name.s != NULL)
-	{
+	if(ulattrs_xavp_name.s != NULL) {
 		vavp = xavp_extract(&ulattrs_xavp_name, &xavp->val.v.xavp);
 		xavp_insert(vavp, 0, NULL);
 	}
 
 	/* Rewrite Request-URI */
-	if(rewrite_uri(msg, &uri)<0) {
+	if(rewrite_uri(msg, &uri) < 0) {
 		LM_WARN("failed to rewrite r-uri\n");
 	}
 
-	if (dst_uri.len) {
-		if(set_dst_uri(msg, &dst_uri)<0) {
+	if(dst_uri.len) {
+		if(set_dst_uri(msg, &dst_uri) < 0) {
 			LM_ERR("failed to set dst uri\n");
 		}
 	} else {
 		reset_dst_uri(msg);
 	}
 
-	if (path.len) {
-		if(set_path_vector(msg, &path)<0) {
+	if(path.len) {
+		if(set_path_vector(msg, &path) < 0) {
 			LM_WARN("failed to set path vector\n");
 		}
 	} else {
@@ -758,7 +764,7 @@ int ki_t_next_contacts(struct sip_msg* msg)
 	set_ua(msg, &location_ua);
 
 	/* Check if there was only one contact at this priority */
-	if (q_flag) {
+	if(q_flag) {
 		xavp_rm(xavp, NULL);
 		return 1;
 	}
@@ -770,7 +776,7 @@ int ki_t_next_contacts(struct sip_msg* msg)
 	xavp_rm_by_name(&contact_flows_avp, 1, NULL);
 	prev_xavp = xavp;
 
-	while ((xavp = xavp_get_next(prev_xavp)) != NULL) {
+	while((xavp = xavp_get_next(prev_xavp)) != NULL) {
 
 		xavp_rm(prev_xavp, NULL);
 
@@ -789,32 +795,32 @@ int ki_t_next_contacts(struct sip_msg* msg)
 		}
 
 		vavp = xavp_get(&dst_uri_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			dst_uri = vavp->val.v.s;
 		} else {
 			dst_uri.len = 0;
 		}
 
 		vavp = xavp_get(&path_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			path = vavp->val.v.s;
 		} else {
 			path.len = 0;
 		}
 
 		vavp = xavp_get(&sock_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			sock_str = vavp->val.v.s;
-			if (parse_phostport(sock_str.s, &host.s, &host.len, &port, &proto)
+			if(parse_phostport(sock_str.s, &host.s, &host.len, &port, &proto)
 					!= 0) {
 				LM_ERR("parsing of socket info <%s> failed\n", sock_str.s);
 				free_instance_list(il);
 				xavp_rm(xavp_list, NULL);
 				return -1;
 			}
-			sock = grep_sock_info(&host, (unsigned short)port,
-					(unsigned short)proto);
-			if (sock == 0) {
+			sock = grep_sock_info(
+					&host, (unsigned short)port, (unsigned short)proto);
+			if(sock == 0) {
 				free_instance_list(il);
 				xavp_rm(xavp_list, NULL);
 				return -1;
@@ -826,14 +832,14 @@ int ki_t_next_contacts(struct sip_msg* msg)
 		}
 
 		vavp = xavp_get(&flags_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			flags = (unsigned int)vavp->val.v.l;
 		} else {
 			flags = 0;
 		}
 
 		vavp = xavp_get(&ruid_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			ruid = vavp->val.v.s;
 		} else {
 			ruid.s = 0;
@@ -841,7 +847,7 @@ int ki_t_next_contacts(struct sip_msg* msg)
 		}
 
 		vavp = xavp_get(&ua_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			location_ua = vavp->val.v.s;
 		} else {
 			location_ua.s = 0;
@@ -849,31 +855,34 @@ int ki_t_next_contacts(struct sip_msg* msg)
 		}
 
 		vavp = xavp_get(&instance_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			instance = vavp->val.v.s;
 			ilp = il;
-			while (ilp) {
-				if ((instance.len == ilp->instance.len) &&
-						(strncmp(instance.s, ilp->instance.s, instance.len) == 0))
+			while(ilp) {
+				if((instance.len == ilp->instance.len)
+						&& (strncmp(instance.s, ilp->instance.s, instance.len)
+								== 0))
 					break;
 				ilp = ilp->next;
 			}
-			if (ilp) {
-				vavp = (ulattrs_xavp_name.s != NULL)?xavp_extract(&ulattrs_xavp_name, &xavp->val.v.xavp):NULL;
-				add_contact_flows_avp(&uri, &dst_uri, &path, &sock_str,
-						flags, &instance, &ruid, &location_ua, vavp);
+			if(ilp) {
+				vavp = (ulattrs_xavp_name.s != NULL) ? xavp_extract(
+							   &ulattrs_xavp_name, &xavp->val.v.xavp)
+													 : NULL;
+				add_contact_flows_avp(&uri, &dst_uri, &path, &sock_str, flags,
+						&instance, &ruid, &location_ua, vavp);
 				goto check_q_flag;
 			}
-			if (!q_flag) {
-				ilp = (struct instance_list *)
-					pkg_malloc(sizeof(struct instance_list));
-				if (!ilp) {
+			if(!q_flag) {
+				ilp = (struct instance_list *)pkg_malloc(
+						sizeof(struct instance_list));
+				if(!ilp) {
 					PKG_MEM_ERROR_FMT("for instance list element\n");
 					free_instance_list(il);
 					return -1;
 				}
 				ilp->instance.s = pkg_malloc(instance.len);
-				if (!ilp->instance.s) {
+				if(!ilp->instance.s) {
 					PKG_MEM_ERROR_FMT("for instance list instance\n");
 					pkg_free(ilp);
 					free_instance_list(il);
@@ -890,29 +899,28 @@ int ki_t_next_contacts(struct sip_msg* msg)
 		}
 
 		LM_DBG("Appending branch uri-'%.*s' dst-'%.*s' path-'%.*s' inst-'%.*s'"
-				" ruid-'%.*s' location_ua-'%.*s'\n",
-				uri.len, uri.s,
-				dst_uri.len, (dst_uri.len > 0)?dst_uri.s:"",
-				path.len, (path.len>0)?path.s:"",
-				instance.len, (instance.len>0)?instance.s:"",
-				ruid.len, (ruid.len>0)?ruid.s:"",
-				location_ua.len, (location_ua.len>0)?location_ua.s:"");
-		if (append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, &instance, 0,
-					&ruid, &location_ua) != 1) {
+			   " ruid-'%.*s' location_ua-'%.*s'\n",
+				uri.len, uri.s, dst_uri.len, (dst_uri.len > 0) ? dst_uri.s : "",
+				path.len, (path.len > 0) ? path.s : "", instance.len,
+				(instance.len > 0) ? instance.s : "", ruid.len,
+				(ruid.len > 0) ? ruid.s : "", location_ua.len,
+				(location_ua.len > 0) ? location_ua.s : "");
+		if(append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, &instance,
+				   0, &ruid, &location_ua)
+				!= 1) {
 			LM_ERR("appending branch failed\n");
 			free_instance_list(il);
 			xavp_rm(xavp_list, NULL);
 			return -1;
 		}
 
-		if (ulattrs_xavp_name.s != NULL)
-		{
+		if(ulattrs_xavp_name.s != NULL) {
 			vavp = xavp_extract(&ulattrs_xavp_name, &xavp->val.v.xavp);
 			xavp_insert(vavp, nr_branches, NULL);
 		}
 
-check_q_flag:
-		if (q_flag) {
+	check_q_flag:
+		if(q_flag) {
 			free_instance_list(il);
 			xavp_rm(xavp, NULL);
 			return 1;
@@ -927,7 +935,7 @@ check_q_flag:
 	return 1;
 }
 
-int t_next_contacts(struct sip_msg* msg, char* key, char* value)
+int t_next_contacts(struct sip_msg *msg, char *key, char *value)
 {
 	return ki_t_next_contacts(msg);
 }
@@ -942,7 +950,7 @@ int t_next_contacts(struct sip_msg* msg, char* key, char* value)
  * Returns 1, if contact_flows_avp was not empty and a destination set was
  * successfully added.  Returns -2, if contact_flows_avp was empty and thus
  * there was nothing to do. Returns -1 in case of an error. */
-int ki_t_next_contact_flow(struct sip_msg* msg)
+int ki_t_next_contact_flow(struct sip_msg *msg)
 {
 	str uri, dst_uri, path, instance, host, ruid, location_ua;
 	str this_instance;
@@ -953,75 +961,76 @@ int ki_t_next_contact_flow(struct sip_msg* msg)
 	int port, proto;
 
 	/* Check if contact_flows_avp has been defined */
-	if (contact_flows_avp.len == 0) {
+	if(contact_flows_avp.len == 0) {
 		LM_ERR("feature has been disabled - "
-				"to enable define contact_flows_avp module parameter");
+			   "to enable define contact_flows_avp module parameter");
 		return -1;
 	}
 
 	/* Load Request-URI and branches */
 	t_get_this_branch_instance(msg, &this_instance);
 
-	if (this_instance.len == 0) {
+	if(this_instance.len == 0) {
 		LM_DBG("No instance on this branch\n");
 		return -2;
 	}
 	/* Find first contact_flows_avp value */
 	xavp_list = xavp_get(&contact_flows_avp, NULL);
-	if (!xavp_list) {
+	if(!xavp_list) {
 		LM_DBG("no contacts in contact_flows_avp - we are done!\n");
 		return -2;
 	}
 
 	xavp = xavp_list;
 
-	while (xavp) {
+	while(xavp) {
 		next_xavp = xavp_get_next(xavp);
 
 		vavp = xavp_get(&instance_name, xavp->val.v.xavp);
-		if (vavp == NULL) {
+		if(vavp == NULL) {
 			/* Does not match this instance */
 			goto next_xavp;
 		} else {
 			instance = vavp->val.v.s;
-			if ((instance.len != this_instance.len) ||
-					(strncmp(instance.s, this_instance.s, instance.len) != 0))
+			if((instance.len != this_instance.len)
+					|| (strncmp(instance.s, this_instance.s, instance.len)
+							!= 0))
 				/* Does not match this instance */
 				goto next_xavp;
 		}
 
 		vavp = xavp_get(&uri_name, xavp->val.v.xavp);
-		if (vavp == NULL) {
+		if(vavp == NULL) {
 			goto next_xavp;
 		} else {
 			uri = vavp->val.v.s;
 		}
 
 		vavp = xavp_get(&dst_uri_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			dst_uri = vavp->val.v.s;
 		} else {
 			dst_uri.len = 0;
 		}
 
 		vavp = xavp_get(&path_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			path = vavp->val.v.s;
 		} else {
 			path.len = 0;
 		}
 
 		vavp = xavp_get(&sock_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			tmp = vavp->val.v.s.s;
-			if (parse_phostport(tmp, &host.s, &host.len, &port, &proto) != 0) {
+			if(parse_phostport(tmp, &host.s, &host.len, &port, &proto) != 0) {
 				LM_ERR("parsing of socket info <%s> failed\n", tmp);
 				xavp_rm(xavp, NULL);
 				return -1;
 			}
-			sock = grep_sock_info(&host, (unsigned short)port,
-					(unsigned short)proto);
-			if (sock == 0) {
+			sock = grep_sock_info(
+					&host, (unsigned short)port, (unsigned short)proto);
+			if(sock == 0) {
 				xavp_rm(xavp, NULL);
 				return -1;
 			}
@@ -1030,14 +1039,14 @@ int ki_t_next_contact_flow(struct sip_msg* msg)
 		}
 
 		vavp = xavp_get(&flags_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			flags = (unsigned int)vavp->val.v.l;
 		} else {
 			flags = 0;
 		}
 
 		vavp = xavp_get(&ruid_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			ruid = vavp->val.v.s;
 		} else {
 			ruid.s = "";
@@ -1045,7 +1054,7 @@ int ki_t_next_contact_flow(struct sip_msg* msg)
 		}
 
 		vavp = xavp_get(&ua_name, xavp->val.v.xavp);
-		if (vavp != NULL) {
+		if(vavp != NULL) {
 			location_ua = vavp->val.v.s;
 		} else {
 			location_ua.s = "";
@@ -1053,35 +1062,34 @@ int ki_t_next_contact_flow(struct sip_msg* msg)
 		}
 
 		LM_DBG("Appending branch uri-'%.*s' dst-'%.*s' path-'%.*s'"
-				" inst-'%.*s' ruid-'%.*s' location_ua-'%.*s'\n",
-				uri.len, uri.s,
-				dst_uri.len, (dst_uri.len > 0)?dst_uri.s:"",
-				path.len, (path.len>0)?path.s:"",
-				instance.len, (instance.len>0)?instance.s:"",
-				ruid.len, ruid.s, location_ua.len, location_ua.s);
-		if (append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, &instance, 0,
-					&ruid, &location_ua) != 1) {
+			   " inst-'%.*s' ruid-'%.*s' location_ua-'%.*s'\n",
+				uri.len, uri.s, dst_uri.len, (dst_uri.len > 0) ? dst_uri.s : "",
+				path.len, (path.len > 0) ? path.s : "", instance.len,
+				(instance.len > 0) ? instance.s : "", ruid.len, ruid.s,
+				location_ua.len, location_ua.s);
+		if(append_branch(msg, &uri, &dst_uri, &path, 0, flags, sock, &instance,
+				   0, &ruid, &location_ua)
+				!= 1) {
 			LM_ERR("appending branch failed\n");
 			xavp_rm(xavp_list, NULL);
 			return -1;
 		}
 
-		if (ulattrs_xavp_name.s != NULL)
-		{
+		if(ulattrs_xavp_name.s != NULL) {
 			vavp = xavp_extract(&ulattrs_xavp_name, &xavp->val.v.xavp);
 			xavp_insert(vavp, nr_branches, NULL);
 		}
 
 		xavp_rm(xavp, NULL);
 		return 1;
-next_xavp:
+	next_xavp:
 		xavp = next_xavp;
 	}
 
 	return -1;
 }
 
-int t_next_contact_flow(struct sip_msg* msg, char* key, char* value)
+int t_next_contact_flow(struct sip_msg *msg, char *key, char *value)
 {
 	return ki_t_next_contact_flow(msg);
 }

+ 7 - 7
src/modules/tm/t_serial.h

@@ -30,18 +30,18 @@
 
 extern int fr_inv_timer_next;
 
-int t_load_contacts(struct sip_msg* msg, char* mode, char* value);
+int t_load_contacts(struct sip_msg *msg, char *mode, char *value);
 
-int t_next_contacts(struct sip_msg* msg, char* key, char* value);
+int t_next_contacts(struct sip_msg *msg, char *key, char *value);
 
-int t_next_contact_flow(struct sip_msg* msg, char* key, char* value);
+int t_next_contact_flow(struct sip_msg *msg, char *key, char *value);
 
-int ki_t_load_contacts_mode(struct sip_msg* msg, int mode);
+int ki_t_load_contacts_mode(struct sip_msg *msg, int mode);
 
-int ki_t_load_contacts(struct sip_msg* msg);
+int ki_t_load_contacts(struct sip_msg *msg);
 
-int ki_t_next_contacts(struct sip_msg* msg);
+int ki_t_next_contacts(struct sip_msg *msg);
 
-int ki_t_next_contact_flow(struct sip_msg* msg);
+int ki_t_next_contact_flow(struct sip_msg *msg);
 
 #endif

+ 125 - 121
src/modules/tm/t_stats.c

@@ -20,7 +20,6 @@
  */
 
 
-
 #include <stdio.h>
 #include "t_stats.h"
 #include "../../core/mem/shm_mem.h"
@@ -29,7 +28,7 @@
 #include "../../core/pt.h"
 #include "h_table.h"
 
-union t_stats *tm_stats=0;
+union t_stats *tm_stats = 0;
 
 int init_tm_stats(void)
 {
@@ -51,10 +50,10 @@ int init_tm_stats_child(void)
 	/* We are called from child_init, estimated_process_count has definitive
 	 * value now and thus we can safely allocate the variables
 	 */
-	if (tm_stats==0){
-		size=sizeof(*tm_stats) * get_max_procs();
-		tm_stats=shm_malloc(size);
-		if (tm_stats == 0) {
+	if(tm_stats == 0) {
+		size = sizeof(*tm_stats) * get_max_procs();
+		tm_stats = shm_malloc(size);
+		if(tm_stats == 0) {
 			SHM_MEM_ERROR;
 			goto error;
 		}
@@ -67,85 +66,83 @@ error:
 }
 
 
-
 void free_tm_stats()
 {
-	if (tm_stats == 0) return;
+	if(tm_stats == 0)
+		return;
 	shm_free(tm_stats);
-	tm_stats=0;
+	tm_stats = 0;
 }
 
 
-
 /* res=s1+s2 */
-#define tm_proc_stats_add_base(res, s1, s2) \
-	do{\
-		(res)->waiting=(s1)->waiting+(s2)->waiting; \
-		(res)->transactions=(s1)->transactions+(s2)->transactions; \
-		(res)->client_transactions=(s1)->client_transactions+\
-									(s2)->client_transactions; \
-		(res)->completed_3xx=(s1)->completed_3xx+(s2)->completed_3xx; \
-		(res)->completed_4xx=(s1)->completed_4xx+(s2)->completed_4xx; \
-		(res)->completed_5xx=(s1)->completed_5xx+(s2)->completed_5xx; \
-		(res)->completed_6xx=(s1)->completed_6xx+(s2)->completed_6xx; \
-		(res)->completed_2xx=(s1)->completed_2xx+(s2)->completed_2xx; \
-		(res)->rpl_received=(s1)->rpl_received+(s2)->rpl_received; \
-		(res)->rpl_generated=(s1)->rpl_generated+(s2)->rpl_generated; \
-		(res)->rpl_sent=(s1)->rpl_sent+(s2)->rpl_sent; \
-		(res)->deleted=(s1)->deleted+(s2)->deleted; \
-	}while(0)
+#define tm_proc_stats_add_base(res, s1, s2)                               \
+	do {                                                                  \
+		(res)->waiting = (s1)->waiting + (s2)->waiting;                   \
+		(res)->transactions = (s1)->transactions + (s2)->transactions;    \
+		(res)->client_transactions =                                      \
+				(s1)->client_transactions + (s2)->client_transactions;    \
+		(res)->completed_3xx = (s1)->completed_3xx + (s2)->completed_3xx; \
+		(res)->completed_4xx = (s1)->completed_4xx + (s2)->completed_4xx; \
+		(res)->completed_5xx = (s1)->completed_5xx + (s2)->completed_5xx; \
+		(res)->completed_6xx = (s1)->completed_6xx + (s2)->completed_6xx; \
+		(res)->completed_2xx = (s1)->completed_2xx + (s2)->completed_2xx; \
+		(res)->rpl_received = (s1)->rpl_received + (s2)->rpl_received;    \
+		(res)->rpl_generated = (s1)->rpl_generated + (s2)->rpl_generated; \
+		(res)->rpl_sent = (s1)->rpl_sent + (s2)->rpl_sent;                \
+		(res)->deleted = (s1)->deleted + (s2)->deleted;                   \
+	} while(0)
 
 
 #ifdef TM_MORE_STATS
-#define tm_proc_stats_add(res, s1, s2) \
-	do{\
-		tm_proc_stats_add_base(res, s1, s2); \
-		(res)->t_created=(s1)->t_created+(s2)->t_created; \
-		(res)->t_freed=(s1)->t_freed+(s2)->t_freed; \
-		(res)->delayed_free=(s1)->delayed_free+(s2)->delayed_free; \
-	}while(0)
+#define tm_proc_stats_add(res, s1, s2)                                 \
+	do {                                                               \
+		tm_proc_stats_add_base(res, s1, s2);                           \
+		(res)->t_created = (s1)->t_created + (s2)->t_created;          \
+		(res)->t_freed = (s1)->t_freed + (s2)->t_freed;                \
+		(res)->delayed_free = (s1)->delayed_free + (s2)->delayed_free; \
+	} while(0)
 #else
 #define tm_proc_stats_add(res, s1, s2) tm_proc_stats_add_base(res, s1, s2)
 #endif
 
 
-
 /* we don't worry about locking data during reads (unlike
  * setting values which always happens from some locks)
  */
-void tm_rpc_stats(rpc_t* rpc, void* c)
+void tm_rpc_stats(rpc_t *rpc, void *c)
 {
-	void* st;
+	void *st;
 	unsigned long current, waiting;
 	struct t_proc_stats all;
 	int i, pno;
 
 	pno = get_max_procs();
 	memset(&all, 0, sizeof(all));
-	for(i = 0;i < pno; i++) {
+	for(i = 0; i < pno; i++) {
 		tm_proc_stats_add(&all, &all, &tm_stats[i].s);
 	}
 	current = all.transactions - all.deleted;
 	waiting = all.waiting - all.deleted;
 
-	if (rpc->add(c, "{", &st) < 0) return;
+	if(rpc->add(c, "{", &st) < 0)
+		return;
 
-	rpc->struct_add(st, "dd", "current", (unsigned) current, "waiting",
-									(unsigned) waiting);
-	rpc->struct_add(st, "d", "total", (unsigned) all.transactions);
+	rpc->struct_add(st, "dd", "current", (unsigned)current, "waiting",
+			(unsigned)waiting);
+	rpc->struct_add(st, "d", "total", (unsigned)all.transactions);
 	rpc->struct_add(st, "d", "total_local", (unsigned)all.client_transactions);
 	rpc->struct_add(st, "d", "rpl_received", (unsigned)all.rpl_received);
 	rpc->struct_add(st, "d", "rpl_generated", (unsigned)all.rpl_generated);
 	rpc->struct_add(st, "d", "rpl_sent", (unsigned)all.rpl_sent);
-	rpc->struct_add(st, "ddddd",
-			"6xx", (unsigned int)all.completed_6xx,
-			"5xx", (unsigned int)all.completed_5xx,
-			"4xx", (unsigned int)all.completed_4xx,
-			"3xx", (unsigned int)all.completed_3xx,
-			"2xx", (unsigned int)all.completed_2xx);
+	rpc->struct_add(st, "ddddd", "6xx", (unsigned int)all.completed_6xx, "5xx",
+			(unsigned int)all.completed_5xx, "4xx",
+			(unsigned int)all.completed_4xx, "3xx",
+			(unsigned int)all.completed_3xx, "2xx",
+			(unsigned int)all.completed_2xx);
 #ifdef TM_MORE_STATS
 	rpc->struct_add(st, "dd", "created", (unsigned int)all.t_created, "freed",
-						(unsigned int)all.t_freed);
+			(unsigned int)all.t_freed);
 	rpc->struct_add(st, "d", "delayed_free", (unsigned int)all.delayed_free);
 #endif
 	/* rpc->fault(c, 100, "Trying"); */
@@ -154,7 +151,7 @@ void tm_rpc_stats(rpc_t* rpc, void* c)
 int tm_get_stats(struct t_proc_stats *all)
 {
 	int i, pno;
-	if(all==NULL)
+	if(all == NULL)
 		return -1;
 
 	pno = get_max_procs();
@@ -167,10 +164,10 @@ int tm_get_stats(struct t_proc_stats *all)
 
 
 /*  hash statistics */
-void tm_rpc_hash_stats(rpc_t* rpc, void* c)
+void tm_rpc_hash_stats(rpc_t *rpc, void *c)
 {
 #ifdef TM_HASH_STATS
-	void* st;
+	void *st;
 	unsigned long acc_min, acc_max, acc_zeroes, acc_dev_no;
 	unsigned long crt_min, crt_max, crt_zeroes, crt_dev_no;
 	unsigned long crt_count, acc_count;
@@ -179,114 +176,121 @@ void tm_rpc_hash_stats(rpc_t* rpc, void* c)
 	unsigned long acc, crt;
 	int r;
 
-	acc_count=0;
-	acc_min=(unsigned long)(-1);
-	acc_max=0;
-	acc_zeroes=0;
-	acc_dev_no=0;
-	acc_dev=0;
-	crt_count=0;
-	crt_min=(unsigned long)(-1);
-	crt_max=0;
-	crt_zeroes=0;
-	crt_dev_no=0;
-	crt_dev=0;
-	for (r=0; r<TABLE_ENTRIES; r++){
-		acc=_tm_table->entries[r].acc_entries;
-		crt=_tm_table->entries[r].cur_entries;
-
-		acc_count+=acc;
-		if (acc<acc_min) acc_min=acc;
-		if (acc>acc_max) acc_max=acc;
-		if (acc==0) acc_zeroes++;
-
-		crt_count+=crt;
-		if (crt<crt_min) crt_min=crt;
-		if (crt>crt_max) crt_max=crt;
-		if (crt==0) crt_zeroes++;
+	acc_count = 0;
+	acc_min = (unsigned long)(-1);
+	acc_max = 0;
+	acc_zeroes = 0;
+	acc_dev_no = 0;
+	acc_dev = 0;
+	crt_count = 0;
+	crt_min = (unsigned long)(-1);
+	crt_max = 0;
+	crt_zeroes = 0;
+	crt_dev_no = 0;
+	crt_dev = 0;
+	for(r = 0; r < TABLE_ENTRIES; r++) {
+		acc = _tm_table->entries[r].acc_entries;
+		crt = _tm_table->entries[r].cur_entries;
+
+		acc_count += acc;
+		if(acc < acc_min)
+			acc_min = acc;
+		if(acc > acc_max)
+			acc_max = acc;
+		if(acc == 0)
+			acc_zeroes++;
+
+		crt_count += crt;
+		if(crt < crt_min)
+			crt_min = crt;
+		if(crt > crt_max)
+			crt_max = crt;
+		if(crt == 0)
+			crt_zeroes++;
 	}
-	acc_average=acc_count/(double)TABLE_ENTRIES;
-	crt_average=crt_count/(double)TABLE_ENTRIES;
+	acc_average = acc_count / (double)TABLE_ENTRIES;
+	crt_average = crt_count / (double)TABLE_ENTRIES;
 
-	for (r=0; r<TABLE_ENTRIES; r++){
-		acc=_tm_table->entries[r].acc_entries;
-		crt=_tm_table->entries[r].cur_entries;
+	for(r = 0; r < TABLE_ENTRIES; r++) {
+		acc = _tm_table->entries[r].acc_entries;
+		crt = _tm_table->entries[r].cur_entries;
 
-		acc_d=acc-acc_average;
+		acc_d = acc - acc_average;
 		/* instead of fabs() which requires -lm */
-		if (acc_d<0) acc_d=-acc_d;
-		if (acc_d>1) acc_dev_no++;
-		acc_dev+=acc_d*acc_d;
-		crt_d=crt-crt_average;
+		if(acc_d < 0)
+			acc_d = -acc_d;
+		if(acc_d > 1)
+			acc_dev_no++;
+		acc_dev += acc_d * acc_d;
+		crt_d = crt - crt_average;
 		/* instead of fabs() which requires -lm */
-		if (crt_d<0) crt_d=-crt_d;
-		if (crt_d>1) crt_dev_no++;
-		crt_dev+=crt_d*crt_d;
+		if(crt_d < 0)
+			crt_d = -crt_d;
+		if(crt_d > 1)
+			crt_dev_no++;
+		crt_dev += crt_d * crt_d;
 	}
 
-	if (rpc->add(c, "{", &st) < 0) return;
-	rpc->struct_add(st, "d", "hash_size", (unsigned) TABLE_ENTRIES);
+	if(rpc->add(c, "{", &st) < 0)
+		return;
+	rpc->struct_add(st, "d", "hash_size", (unsigned)TABLE_ENTRIES);
 	rpc->struct_add(st, "d", "crt_transactions", (unsigned)crt_count);
 	rpc->struct_add(st, "f", "crt_target_per_cell", crt_average);
-	rpc->struct_add(st, "dd", "crt_min", (unsigned)crt_min,
-							"crt_max", (unsigned) crt_max);
+	rpc->struct_add(st, "dd", "crt_min", (unsigned)crt_min, "crt_max",
+			(unsigned)crt_max);
 	rpc->struct_add(st, "d", "crt_worst_case_extra_cells",
-							(unsigned)(crt_max-(unsigned)crt_average));
+			(unsigned)(crt_max - (unsigned)crt_average));
 	rpc->struct_add(st, "d", "crt_no_zero_cells", (unsigned)crt_zeroes);
 	rpc->struct_add(st, "d", "crt_no_deviating_cells", crt_dev_no);
 	rpc->struct_add(st, "f", "crt_deviation_sq_sum", crt_dev);
 	rpc->struct_add(st, "d", "acc_transactions", (unsigned)acc_count);
 	rpc->struct_add(st, "f", "acc_target_per_cell", acc_average);
-	rpc->struct_add(st, "dd", "acc_min", (unsigned)acc_min,
-							"acc_max", (unsigned) acc_max);
+	rpc->struct_add(st, "dd", "acc_min", (unsigned)acc_min, "acc_max",
+			(unsigned)acc_max);
 	rpc->struct_add(st, "d", "acc_worst_case_extra_cells",
-							(unsigned)(acc_max-(unsigned)acc_average));
+			(unsigned)(acc_max - (unsigned)acc_average));
 	rpc->struct_add(st, "d", "acc_no_zero_cells", (unsigned)acc_zeroes);
 	rpc->struct_add(st, "d", "acc_no_deviating_cells", acc_dev_no);
 	rpc->struct_add(st, "f", "acc_deviation_sq_sum", acc_dev);
-#else /* TM_HASH_STATS */
-	rpc->fault(c, 500, "Hash statistics not supported (try"
-				"recompiling with -DTM_HASH_STATS)");
+#else  /* TM_HASH_STATS */
+	rpc->fault(c, 500,
+			"Hash statistics not supported (try"
+			"recompiling with -DTM_HASH_STATS)");
 #endif /* TM_HASH_STATS */
 }
 
 /* list active transactions */
-void tm_rpc_list(rpc_t* rpc, void* c)
+void tm_rpc_list(rpc_t *rpc, void *c)
 {
 	int r;
-	void* h;
+	void *h;
 	tm_cell_t *tcell;
 	char pbuf[32];
 
-	for (r=0; r<TABLE_ENTRIES; r++) {
+	for(r = 0; r < TABLE_ENTRIES; r++) {
 		lock_hash(r);
 		if(clist_empty(&_tm_table->entries[r], next_c)) {
 			unlock_hash(r);
 			continue;
 		}
-		if (rpc->add(c, "{", &h) < 0) {
+		if(rpc->add(c, "{", &h) < 0) {
 			LM_ERR("failed to add transaction structure\n");
 			unlock_hash(r);
 			return;
 		}
 		clist_foreach(&_tm_table->entries[r], tcell, next_c)
 		{
-			snprintf(pbuf, 31, "%p", (void*)tcell);
-			rpc->struct_add(h, "sddSSSSSsdddd",
-					"cell", pbuf,
-					"tindex", (unsigned)tcell->hash_index,
-					"tlabel", (unsigned)tcell->label,
-					"method", &tcell->method,
-					"from", &tcell->from_hdr,
-					"to", &tcell->to_hdr,
-					"callid", &tcell->callid_hdr,
-					"cseq", &tcell->cseq_hdr_n,
-					"uas_request", (tcell->uas.request)?"yes":"no",
-					"tflags", (unsigned)tcell->flags,
-					"outgoings", (unsigned)tcell->nr_of_outgoings,
-					"ref_count", (unsigned)atomic_get(&tcell->ref_count),
-					"lifetime", (unsigned)TICKS_TO_S(tcell->end_of_life)
-					);
+			snprintf(pbuf, 31, "%p", (void *)tcell);
+			rpc->struct_add(h, "sddSSSSSsdddd", "cell", pbuf, "tindex",
+					(unsigned)tcell->hash_index, "tlabel",
+					(unsigned)tcell->label, "method", &tcell->method, "from",
+					&tcell->from_hdr, "to", &tcell->to_hdr, "callid",
+					&tcell->callid_hdr, "cseq", &tcell->cseq_hdr_n,
+					"uas_request", (tcell->uas.request) ? "yes" : "no",
+					"tflags", (unsigned)tcell->flags, "outgoings",
+					(unsigned)tcell->nr_of_outgoings, "ref_count",
+					(unsigned)atomic_get(&tcell->ref_count), "lifetime",
+					(unsigned)TICKS_TO_S(tcell->end_of_life));
 		}
 		unlock_hash(r);
 	}
@@ -294,7 +298,7 @@ void tm_rpc_list(rpc_t* rpc, void* c)
 
 
 /* rpc command to clean active but very old transactions */
-void tm_rpc_clean(rpc_t* rpc, void* c)
+void tm_rpc_clean(rpc_t *rpc, void *c)
 {
 	tm_clean_lifetime();
 }

+ 29 - 20
src/modules/tm/t_stats.h

@@ -31,7 +31,8 @@
 
 typedef unsigned long stat_counter;
 
-struct t_proc_stats {
+struct t_proc_stats
+{
 	/* number of transactions in wait state */
 	stat_counter waiting;
 	/* number of server transactions */
@@ -39,8 +40,8 @@ struct t_proc_stats {
 	/* number of UAC transactions (part of transactions) */
 	stat_counter client_transactions;
 	/* number of transactions which completed with this status */
-	stat_counter completed_3xx, completed_4xx, completed_5xx,
-		completed_6xx, completed_2xx;
+	stat_counter completed_3xx, completed_4xx, completed_5xx, completed_6xx,
+			completed_2xx;
 	stat_counter rpl_received;
 	stat_counter rpl_generated;
 	stat_counter rpl_sent;
@@ -55,7 +56,8 @@ struct t_proc_stats {
 #endif /* TM_MORE_STATS */
 };
 
-union t_stats{
+union t_stats
+{
 	struct t_proc_stats s;
 	char _pad[256]; /* pad at least to cache line size
 					 * athlon=64, p4=128, some sparcs=256 */
@@ -82,9 +84,15 @@ inline void static t_stats_delayed_free(void)
 }
 #else /* TM_MORE_STATS  */
 /* do nothing */
-#define t_stats_created()  do{}while(0)
-#define t_stats_freed()  do{}while(0)
-#define t_stats_delayed_free()  do{}while(0)
+#define t_stats_created() \
+	do {                  \
+	} while(0)
+#define t_stats_freed() \
+	do {                \
+	} while(0)
+#define t_stats_delayed_free() \
+	do {                       \
+	} while(0)
 
 #endif /* TM_MORE_STATS */
 
@@ -92,7 +100,8 @@ inline void static t_stats_new(int local)
 {
 	/* keep it in process's piece of shmem */
 	tm_stats[process_no].s.transactions++;
-	if(local) tm_stats[process_no].s.client_transactions++;
+	if(local)
+		tm_stats[process_no].s.client_transactions++;
 }
 
 inline void static t_stats_wait(void)
@@ -101,21 +110,22 @@ inline void static t_stats_wait(void)
 	tm_stats[process_no].s.waiting++;
 }
 
-inline void static t_stats_deleted( int local )
+inline void static t_stats_deleted(int local)
 {
 	tm_stats[process_no].s.deleted++;
 }
 
-inline static void update_reply_stats( int code ) {
-	if (code>=600) {
+inline static void update_reply_stats(int code)
+{
+	if(code >= 600) {
 		tm_stats[process_no].s.completed_6xx++;
-	} else if (code>=500) {
+	} else if(code >= 500) {
 		tm_stats[process_no].s.completed_5xx++;
-	} else if (code>=400) {
+	} else if(code >= 400) {
 		tm_stats[process_no].s.completed_4xx++;
-	} else if (code>=300) {
+	} else if(code >= 300) {
 		tm_stats[process_no].s.completed_3xx++;
-	} else if (code>=200) {
+	} else if(code >= 200) {
 		tm_stats[process_no].s.completed_2xx++;
 	}
 }
@@ -136,18 +146,17 @@ inline void static t_stats_rpl_sent(void)
 }
 
 
-
 int init_tm_stats(void);
 int init_tm_stats_child(void);
 void free_tm_stats(void);
 
-void tm_rpc_stats(rpc_t* rpc, void* c);
+void tm_rpc_stats(rpc_t *rpc, void *c);
 
-void tm_rpc_hash_stats(rpc_t* rpc, void* c);
+void tm_rpc_hash_stats(rpc_t *rpc, void *c);
 
 typedef int (*tm_get_stats_f)(struct t_proc_stats *all);
 int tm_get_stats(struct t_proc_stats *all);
-void tm_rpc_list(rpc_t* rpc, void* c);
-void tm_rpc_clean(rpc_t* rpc, void* c);
+void tm_rpc_list(rpc_t *rpc, void *c);
+void tm_rpc_clean(rpc_t *rpc, void *c);
 
 #endif

+ 138 - 137
src/modules/tm/t_suspend.c

@@ -52,47 +52,44 @@
  * 	0  - success
  * 	<0 - failure
  */
-int t_suspend(struct sip_msg *msg,
-		unsigned int *hash_index, unsigned int *label)
+int t_suspend(
+		struct sip_msg *msg, unsigned int *hash_index, unsigned int *label)
 {
-	struct cell	*t;
+	struct cell *t;
 	int branch;
 	int sip_msg_len;
 
 	t = get_t();
-	if (!t || t == T_UNDEFINED) {
+	if(!t || t == T_UNDEFINED) {
 		LM_ERR("transaction has not been created yet\n");
 		return -1;
 	}
 
-	if (t->flags & T_CANCELED) {
+	if(t->flags & T_CANCELED) {
 		/* The transaction has already been canceled */
 		LM_DBG("trying to suspend an already canceled transaction\n");
 		ser_error = E_CANCELED;
 		return 1;
 	}
-	if (t->uas.status >= 200) {
+	if(t->uas.status >= 200) {
 		LM_DBG("trasaction sent out a final response already - %d\n",
 				t->uas.status);
 		return -3;
 	}
 
-	if (msg->first_line.type != SIP_REPLY) {
+	if(msg->first_line.type != SIP_REPLY) {
 		/* send a 100 Trying reply, because the INVITE processing
 		will probably take a long time */
-		if (msg->REQ_METHOD==METHOD_INVITE && (t->flags&T_AUTO_INV_100)
-			&& (t->uas.status < 100)
-		) {
-			if (!t_reply( t, msg , 100 ,
-				cfg_get(tm, tm_cfg, tm_auto_inv_100_r)))
+		if(msg->REQ_METHOD == METHOD_INVITE && (t->flags & T_AUTO_INV_100)
+				&& (t->uas.status < 100)) {
+			if(!t_reply(t, msg, 100, cfg_get(tm, tm_cfg, tm_auto_inv_100_r)))
 				LM_DBG("suspending request processing - sending 100 reply\n");
 		}
 
-		if ((t->nr_of_outgoings==0) && /* if there had already been
+		if((t->nr_of_outgoings == 0) && /* if there had already been
 			an UAC created, then the lumps were
 			saved as well */
-			save_msg_lumps(t->uas.request, msg)
-		) {
+				save_msg_lumps(t->uas.request, msg)) {
 			LM_ERR("failed to save the message lumps\n");
 			return -1;
 		}
@@ -100,7 +97,7 @@ int t_suspend(struct sip_msg *msg,
 		t->uas.request->flags = msg->flags;
 
 		/* add a blind UAC to let the fr timer running */
-		if (add_blind_uac() < 0) {
+		if(add_blind_uac() < 0) {
 			LM_ERR("failed to add the blind UAC\n");
 			return -1;
 		}
@@ -114,25 +111,28 @@ int t_suspend(struct sip_msg *msg,
 		msg->msg_flags |= FL_RPL_SUSPENDED;
 		/* this is a reply suspend find which branch */
 
-		if (t_check( msg  , &branch )==-1){
+		if(t_check(msg, &branch) == -1) {
 			LM_ERR("failed find UAC branch\n");
 			return -1;
 		}
 
-		if (!t->uac[branch].reply) {
+		if(!t->uac[branch].reply) {
 			sip_msg_len = 0;
 			LM_DBG("found a match with branch id [%d] - "
-				"cloning reply message to t->uac[branch].reply\n", branch);
-			t->uac[branch].reply = sip_msg_cloner( msg, &sip_msg_len );
+				   "cloning reply message to t->uac[branch].reply\n",
+					branch);
+			t->uac[branch].reply = sip_msg_cloner(msg, &sip_msg_len);
 
-			if (! t->uac[branch].reply ) {
+			if(!t->uac[branch].reply) {
 				LM_ERR("can't alloc' clone memory\n");
 				return -1;
 			}
-			t->uac[branch].end_reply = ((char*)t->uac[branch].reply) + sip_msg_len;
+			t->uac[branch].end_reply =
+					((char *)t->uac[branch].reply) + sip_msg_len;
 		} else {
 			LM_DBG("found a match with branch id [%d] - "
-				"message already cloned to t->uac[branch].reply\n", branch);
+				   "message already cloned to t->uac[branch].reply\n",
+					branch);
 			// This can happen when suspending more than once in a reply.
 		}
 		LM_DBG("saving transaction data\n");
@@ -174,9 +174,9 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 	void *erpl = NULL;
 	int faked_req_len = 0;
 	struct cancel_info cancel_data;
-	int	branch;
-	struct ua_client *uac =NULL;
-	int	ret;
+	int branch;
+	struct ua_client *uac = NULL;
+	int ret;
 	int cb_type;
 	int msg_status;
 	int last_uac_status;
@@ -192,19 +192,19 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 	backup_T = get_t();
 	backup_T_branch = get_t_branch();
 
-	if (t_lookup_ident_filter(&t, hash_index, label, skip_timer) < 0) {
+	if(t_lookup_ident_filter(&t, hash_index, label, skip_timer) < 0) {
 		set_t(backup_T, backup_T_branch);
 		LM_WARN("active transaction not found\n");
 		return -1;
 	}
 
-	if (!(t->flags & T_ASYNC_SUSPENDED)) {
+	if(!(t->flags & T_ASYNC_SUSPENDED)) {
 		LM_WARN("transaction is not suspended [%u:%u]\n", hash_index, label);
 		set_t(backup_T, backup_T_branch);
 		return -2;
 	}
 
-	if (t->flags & T_CANCELED) {
+	if(t->flags & T_CANCELED) {
 		t->flags &= ~T_ASYNC_SUSPENDED;
 		/* The transaction has already been canceled,
 		 * needless to continue */
@@ -218,15 +218,15 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 	 * form calling t_continue() multiple times simultaneously */
 	LOCK_ASYNC_CONTINUE(t);
 
-	t->flags |= T_ASYNC_CONTINUE;   /* we can now know anywhere in kamailio
+	t->flags |= T_ASYNC_CONTINUE; /* we can now know anywhere in kamailio
 					 * that we are executing post a suspend */
 
 	/* transaction is no longer suspended, resetting the SUSPEND flag */
 	t->flags &= ~T_ASYNC_SUSPENDED;
 
 	/* which route block type were we in when we were suspended */
-	cb_type =  FAILURE_CB_TYPE;
-	switch (t->async_backup.backup_route) {
+	cb_type = FAILURE_CB_TYPE;
+	switch(t->async_backup.backup_route) {
 		case REQUEST_ROUTE:
 			cb_type = FAILURE_CB_TYPE;
 			break;
@@ -245,10 +245,10 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 		/* resume processing of a sip request */
 		/* get the branch of the blind UAC setup during suspend */
 		branch = t->async_backup.blind_uac;
-		if (branch >= 0) {
+		if(branch >= 0) {
 			stop_rb_timers(&t->uac[branch].request);
 
-			if (t->uac[branch].last_received != 0) {
+			if(t->uac[branch].last_received != 0) {
 				/* Either t_continue() has already been
 				* called or the branch has already timed out.
 				* Needless to continue. */
@@ -267,14 +267,14 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 			 * for example when t_reply() is called from
 			 * a failure route => deadlock, because both
 			 * of them need the reply lock to be held. */
-			t->uac[branch].last_received=500;
-			if(t->uac[branch].reply!=NULL) {
+			t->uac[branch].last_received = 500;
+			if(t->uac[branch].reply != NULL) {
 				LM_WARN("reply (%p) already set for suspended transaction"
 						" (branch: %d)\n",
 						t->uac[branch].reply, branch);
 			} else {
 				/* set it as a faked reply */
-				t->uac[branch].reply=FAKED_REPLY;
+				t->uac[branch].reply = FAKED_REPLY;
 			}
 			uac = &t->uac[branch];
 		}
@@ -290,32 +290,33 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 		 */
 
 		/* fake the request and the environment, like in failure_route */
-		faked_req = fake_req(t->uas.request, 0 /* extra flags */, uac,
-			&faked_req_len);
-		if (faked_req==NULL) {
+		faked_req = fake_req(
+				t->uas.request, 0 /* extra flags */, uac, &faked_req_len);
+		if(faked_req == NULL) {
 			LM_ERR("building fake_req failed\n");
 			ret = -1;
 			goto kill_trans;
 		}
-		faked_env( t, faked_req, 1);
+		faked_env(t, faked_req, 1);
 
 		route_type_bk = get_route_type();
 		set_route_type(FAILURE_ROUTE);
 		/* execute the pre/post -script callbacks based on original route block */
-		if (exec_pre_script_cb(faked_req, cb_type)>0) {
-			if(rtact!=NULL) {
-				if (run_top_route(rtact, faked_req, 0)<0) {
+		if(exec_pre_script_cb(faked_req, cb_type) > 0) {
+			if(rtact != NULL) {
+				if(run_top_route(rtact, faked_req, 0) < 0) {
 					LM_ERR("failure inside run_top_route\n");
 				}
 			} else {
-				if(cbname!=NULL && cbname->s!=NULL) {
+				if(cbname != NULL && cbname->s != NULL) {
 					keng = sr_kemi_eng_get();
-					if(keng!=NULL) {
+					if(keng != NULL) {
 						if(cbparam && cbparam->s) {
 							evname = *cbparam;
 						}
 						if(sr_kemi_route(keng, faked_req, FAILURE_ROUTE, cbname,
-								&evname)<0) {
+								   &evname)
+								< 0) {
 							LM_ERR("error running event route kemi callback\n");
 						}
 					} else {
@@ -333,27 +334,24 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 		/* TODO: save_msg_lumps should clone the lumps to shm mem */
 
 		/* restore original environment */
-		faked_env( t, 0, 1);
+		faked_env(t, 0, 1);
 		/* update the flags */
 		t->uas.request->flags = faked_req->flags;
 		/* free the fake msg */
 		free_faked_req(faked_req, faked_req_len);
 
 
-		if (t->uas.status < 200) {
+		if(t->uas.status < 200) {
 			/* No final reply has been sent yet.
 			* Check whether or not there is any pending branch.
 			*/
-			for (	branch = 0;
-				branch < t->nr_of_outgoings;
-				branch++
-			) {
-				if (t->uac[branch].last_received < 200)
+			for(branch = 0; branch < t->nr_of_outgoings; branch++) {
+				if(t->uac[branch].last_received < 200)
 					break;
 			}
 
-			if (branch == t->nr_of_outgoings) {
-			/* There is not any open branch so there is
+			if(branch == t->nr_of_outgoings) {
+				/* There is not any open branch so there is
 			 * no chance that a final response will be received. */
 				ret = 0;
 				goto kill_trans;
@@ -367,32 +365,34 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 		init_cancel_info(&cancel_data);
 
 		LM_DBG("continuing from a suspended reply"
-				" - resetting the suspend branch flag\n");
+			   " - resetting the suspend branch flag\n");
 
-		if (t->uac[branch].reply) {
+		if(t->uac[branch].reply) {
 			t->uac[branch].reply->msg_flags &= ~FL_RPL_SUSPENDED;
 		} else {
 			LM_WARN("no reply in t_continue for branch. not much we can do\n");
 			return 0;
 		}
-		if (t->uas.request) t->uas.request->msg_flags&= ~FL_RPL_SUSPENDED;
+		if(t->uas.request)
+			t->uas.request->msg_flags &= ~FL_RPL_SUSPENDED;
 
-		faked_env( t, t->uac[branch].reply, 1);
+		faked_env(t, t->uac[branch].reply, 1);
 
-		if (exec_pre_script_cb(t->uac[branch].reply, cb_type)>0) {
-			if(rtact!=NULL) {
-				if (run_top_route(rtact, t->uac[branch].reply, 0)<0){
+		if(exec_pre_script_cb(t->uac[branch].reply, cb_type) > 0) {
+			if(rtact != NULL) {
+				if(run_top_route(rtact, t->uac[branch].reply, 0) < 0) {
 					LM_ERR("Error in run_top_route\n");
 				}
 			} else {
-				if(cbname!=NULL && cbname->s!=NULL) {
+				if(cbname != NULL && cbname->s != NULL) {
 					keng = sr_kemi_eng_get();
-					if(keng!=NULL) {
+					if(keng != NULL) {
 						if(cbparam && cbparam->s) {
 							evname = *cbparam;
 						}
 						if(sr_kemi_route(keng, t->uac[branch].reply,
-									TM_ONREPLY_ROUTE, cbname, &evname)<0) {
+								   TM_ONREPLY_ROUTE, cbname, &evname)
+								< 0) {
 							LM_ERR("error running event route kemi callback\n");
 						}
 					} else {
@@ -407,9 +407,9 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 		}
 
 		LM_DBG("restoring previous environment\n");
-		faked_env( t, 0, 1);
+		faked_env(t, 0, 1);
 
-		if (t->flags & T_ASYNC_SUSPENDED) {
+		if(t->flags & T_ASYNC_SUSPENDED) {
 			LM_DBG("The transaction is suspended, so not continuing\n");
 			t->flags &= ~T_ASYNC_CONTINUE;
 			UNLOCK_ASYNC_CONTINUE(t);
@@ -418,81 +418,84 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label,
 		}
 
 		/*lock transaction replies - will be unlocked when reply is relayed*/
-		LOCK_REPLIES( t );
-		if ( is_local(t) ) {
+		LOCK_REPLIES(t);
+		if(is_local(t)) {
 			LM_DBG("t is local - sending reply with status code: [%d]\n",
 					t->uac[branch].reply->first_line.u.reply.statuscode);
-			reply_status = local_reply( t, t->uac[branch].reply, branch,
+			reply_status = local_reply(t, t->uac[branch].reply, branch,
 					t->uac[branch].reply->first_line.u.reply.statuscode,
-					&cancel_data );
-			if (reply_status == RPS_COMPLETED) {
+					&cancel_data);
+			if(reply_status == RPS_COMPLETED) {
 				/* no more UAC FR/RETR (if I received a 2xx, there may
 				* be still pending branches ...
 				*/
-				cleanup_uac_timers( t );
-				if (is_invite(t)) cancel_uacs(t, &cancel_data, F_CANCEL_B_KILL);
+				cleanup_uac_timers(t);
+				if(is_invite(t))
+					cancel_uacs(t, &cancel_data, F_CANCEL_B_KILL);
 				/* There is no need to call set_final_timer because we know
 				* that the transaction is local */
 				put_on_wait(t);
-			}else if (unlikely(cancel_data.cancel_bitmap)){
+			} else if(unlikely(cancel_data.cancel_bitmap)) {
 				/* cancel everything, even non-INVITEs (e.g in case of 6xx), use
 				* cancel_b_method for canceling unreplied branches */
-				cancel_uacs(t, &cancel_data, cfg_get(tm,tm_cfg, cancel_b_flags));
+				cancel_uacs(
+						t, &cancel_data, cfg_get(tm, tm_cfg, cancel_b_flags));
 			}
 
 		} else {
 			LM_DBG("t is not local - relaying reply with status code: [%d]\n",
 					t->uac[branch].reply->first_line.u.reply.statuscode);
 			do_put_on_wait = 0;
-			if(t->uac[branch].reply->first_line.u.reply.statuscode>=200){
+			if(t->uac[branch].reply->first_line.u.reply.statuscode >= 200) {
 				do_put_on_wait = 1;
 			}
-			reply_status=relay_reply( t, t->uac[branch].reply, branch,
+			reply_status = relay_reply(t, t->uac[branch].reply, branch,
 					t->uac[branch].reply->first_line.u.reply.statuscode,
-					&cancel_data, do_put_on_wait );
-			if (reply_status == RPS_COMPLETED) {
+					&cancel_data, do_put_on_wait);
+			if(reply_status == RPS_COMPLETED) {
 				/* no more UAC FR/RETR (if I received a 2xx, there may
 				be still pending branches ...
 				*/
-				cleanup_uac_timers( t );
+				cleanup_uac_timers(t);
 				/* 2xx is a special case: we can have a COMPLETED request
 				* with branches still open => we have to cancel them */
-				if (is_invite(t) && cancel_data.cancel_bitmap)
-					cancel_uacs( t, &cancel_data,  F_CANCEL_B_KILL);
+				if(is_invite(t) && cancel_data.cancel_bitmap)
+					cancel_uacs(t, &cancel_data, F_CANCEL_B_KILL);
 				/* FR for negative INVITES, WAIT anything else */
 				/* Call to set_final_timer is embedded in relay_reply to avoid
 				* race conditions when reply is sent out and an ACK to stop
 				* retransmissions comes before retransmission timer is set.*/
-			}else if (unlikely(cancel_data.cancel_bitmap)){
+			} else if(unlikely(cancel_data.cancel_bitmap)) {
 				/* cancel everything, even non-INVITEs (e.g in case of 6xx), use
 				* cancel_b_method for canceling unreplied branches */
-				cancel_uacs(t, &cancel_data, cfg_get(tm,tm_cfg, cancel_b_flags));
+				cancel_uacs(
+						t, &cancel_data, cfg_get(tm, tm_cfg, cancel_b_flags));
 			}
-
 		}
-		t->uac[branch].request.flags|=F_RB_REPLIED;
+		t->uac[branch].request.flags |= F_RB_REPLIED;
 
-		if (reply_status==RPS_ERROR){
+		if(reply_status == RPS_ERROR) {
 			goto done;
 		}
 
 		/* update FR/RETR timers on provisional replies */
 
-		msg_status=t->uac[branch].reply->REPLY_STATUS;
-		last_uac_status=t->uac[branch].last_received;
+		msg_status = t->uac[branch].reply->REPLY_STATUS;
+		last_uac_status = t->uac[branch].last_received;
 
-		if (is_invite(t) && msg_status<200 &&
-			( cfg_get(tm, tm_cfg, restart_fr_on_each_reply) ||
-			( (last_uac_status<msg_status) &&
-			((msg_status>=180) || (last_uac_status==0)) )
-		) ) { /* provisional now */
+		if(is_invite(t) && msg_status < 200
+				&& (cfg_get(tm, tm_cfg, restart_fr_on_each_reply)
+						|| ((last_uac_status < msg_status)
+								&& ((msg_status >= 180)
+										|| (last_uac_status
+												== 0))))) { /* provisional now */
 #ifdef TIMER_DEBUG
-			LM_DBG("updating FR/RETR timers, \"fr_inv_timeout\": %d\n", t->fr_inv_timeout);
+			LM_DBG("updating FR/RETR timers, \"fr_inv_timeout\": %d\n",
+					t->fr_inv_timeout);
 #endif
-			restart_rb_fr(& t->uac[branch].request, t->fr_inv_timeout);
-			t->uac[branch].request.flags|=F_RB_FR_INV; /* mark fr_inv */
+			restart_rb_fr(&t->uac[branch].request, t->fr_inv_timeout);
+			t->uac[branch].request.flags |= F_RB_FR_INV; /* mark fr_inv */
 		}
-
 	}
 
 done:
@@ -501,13 +504,13 @@ done:
 		/* response handling */
 		/* backup branch reply to free it later and reset it here under lock */
 		brpl = t->uac[branch].reply;
-		erpl = (void*)t->uac[branch].end_reply;
+		erpl = (void *)t->uac[branch].end_reply;
 		t->uac[branch].reply = 0;
 		t->uac[branch].end_reply = 0;
 	}
 	UNLOCK_ASYNC_CONTINUE(t);
 
-	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE){
+	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE) {
 		/* request handling */
 		/* unref the transaction */
 		t_unref(t->uas.request);
@@ -520,15 +523,15 @@ done:
 			LM_DBG("Freeing earlier cloned reply\n");
 
 			/* free lumps that were added during reply processing */
-			del_nonshm_lump( &(brpl->add_rm) );
-			del_nonshm_lump( &(brpl->body_lumps) );
-			del_nonshm_lump_rpl( &(brpl->reply_lump) );
+			del_nonshm_lump(&(brpl->add_rm));
+			del_nonshm_lump(&(brpl->body_lumps));
+			del_nonshm_lump_rpl(&(brpl->reply_lump));
 
 			/* free header's parsed structures that were added */
-			for( hdr=brpl->headers ; hdr ; hdr=hdr->next ) {
-				if (hdr->parsed && hdr_allocs_parse(hdr) &&
-						(hdr->parsed<(void*)brpl ||
-						(erpl && hdr->parsed>=(void*)erpl))) {
+			for(hdr = brpl->headers; hdr; hdr = hdr->next) {
+				if(hdr->parsed && hdr_allocs_parse(hdr)
+						&& (hdr->parsed < (void *)brpl
+								|| (erpl && hdr->parsed >= (void *)erpl))) {
 					clean_hdr_field(hdr);
 					hdr->parsed = 0;
 				}
@@ -537,11 +540,12 @@ done:
 			/* now go through hdr fields themselves
 			 * and remove the pkg allocated space */
 			hdr = brpl->headers;
-			while (hdr) {
-				if ( hdr && ((void*)hdr<(void*)brpl ||
-						(void*)hdr>=(void*)erpl)) {
+			while(hdr) {
+				if(hdr
+						&& ((void *)hdr < (void *)brpl
+								|| (void *)hdr >= (void *)erpl)) {
 					/* this header needs to be freed and removed form the list */
-					if (!prev) {
+					if(!prev) {
 						brpl->headers = hdr->next;
 					} else {
 						prev->next = hdr->next;
@@ -569,8 +573,7 @@ done:
 kill_trans:
 	/* The script has hopefully set the error code. If not,
 	 * let us reply with a default error. */
-	if ((kill_transaction_unsafe(t,
-				tm_error ? tm_error : E_UNSPEC)) <=0) {
+	if((kill_transaction_unsafe(t, tm_error ? tm_error : E_UNSPEC)) <= 0) {
 		LM_ERR("reply generation failed\n");
 		/* The transaction must be explicitely released,
 		 * no more timer is running */
@@ -583,7 +586,7 @@ kill_trans:
 	}
 
 	/* unref the transaction */
-	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE){
+	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE) {
 		/* request handling */
 		t_unref(t->uas.request);
 	} else {
@@ -594,19 +597,19 @@ kill_trans:
 	return ret;
 }
 
-int t_continue(unsigned int hash_index, unsigned int label,
-		struct action *route)
+int t_continue(
+		unsigned int hash_index, unsigned int label, struct action *route)
 {
 	return t_continue_helper(hash_index, label, route, NULL, NULL, 1);
 }
-int t_continue_skip_timer(unsigned int hash_index, unsigned int label,
-		struct action *route)
+int t_continue_skip_timer(
+		unsigned int hash_index, unsigned int label, struct action *route)
 {
 	return t_continue_helper(hash_index, label, route, NULL, NULL, 0);
 }
 
-int t_continue_cb(unsigned int hash_index, unsigned int label,
-		str *cbname, str *cbparam)
+int t_continue_cb(
+		unsigned int hash_index, unsigned int label, str *cbname, str *cbparam)
 {
 	return t_continue_helper(hash_index, label, NULL, cbname, cbparam, 0);
 }
@@ -624,23 +627,21 @@ int t_continue_cb(unsigned int hash_index, unsigned int label,
  */
 int t_cancel_suspend(unsigned int hash_index, unsigned int label)
 {
-	struct cell	*t;
-	int	branch;
+	struct cell *t;
+	int branch;
 
 	t = get_t();
-	if (!t || t == T_UNDEFINED) {
+	if(!t || t == T_UNDEFINED) {
 		LM_ERR("no active transaction\n");
 		return -1;
 	}
 	/* Only to double-check the IDs */
-	if ((t->hash_index != hash_index)
-		|| (t->label != label)
-	) {
+	if((t->hash_index != hash_index) || (t->label != label)) {
 		LM_ERR("transaction id mismatch\n");
 		return -1;
 	}
 
-	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE){
+	if(t->async_backup.backup_route != TM_ONREPLY_ROUTE) {
 		/* The transaction does not need to be locked because this
 		* function is either executed from the original route block
 		* or from failure route which already locks */
@@ -649,11 +650,11 @@ int t_cancel_suspend(unsigned int hash_index, unsigned int label)
 
 		/* Try to find the blind UAC, and cancel its fr timer.
 		* We assume that the last blind uac called this function. */
-		for (	branch = t->nr_of_outgoings-1;
-			branch >= 0 && t->uac[branch].request.buffer;
-			branch--);
+		for(branch = t->nr_of_outgoings - 1;
+				branch >= 0 && t->uac[branch].request.buffer; branch--)
+			;
 
-		if (branch >= 0) {
+		if(branch >= 0) {
 			stop_rb_timers(&t->uac[branch].request);
 			/* Set last_received to something >= 200,
 			* the actual value does not matter, the branch
@@ -663,21 +664,21 @@ int t_cancel_suspend(unsigned int hash_index, unsigned int label)
 			* for example when t_reply() is called from
 			* a failure rute => deadlock, because both
 			* of them need the reply lock to be held. */
-			t->uac[branch].last_received=500;
+			t->uac[branch].last_received = 500;
 		} else {
 			/* Not a huge problem, fr timer will fire, but CANCEL
 			will not be sent. last_received will be set to 408. */
 			return -1;
 		}
-	}else{
+	} else {
 		branch = t->async_backup.backup_branch;
 
 		LM_DBG("This is a cancel suspend for a response\n");
 
 		t->uac[branch].reply->msg_flags &= ~FL_RPL_SUSPENDED;
-		if (t->uas.request) t->uas.request->msg_flags&= ~FL_RPL_SUSPENDED;
+		if(t->uas.request)
+			t->uas.request->msg_flags &= ~FL_RPL_SUSPENDED;
 	}
 
 	return 0;
 }
-

+ 14 - 14
src/modules/tm/t_suspend.h

@@ -22,22 +22,22 @@
 #ifndef _T_SUSPEND_H
 #define _T_SUSPEND_H
 
-int t_suspend(struct sip_msg *msg,
-		unsigned int *hash_index, unsigned int *label);
-typedef int (*t_suspend_f)(struct sip_msg *msg,
-		unsigned int *hash_index, unsigned int *label);
+int t_suspend(
+		struct sip_msg *msg, unsigned int *hash_index, unsigned int *label);
+typedef int (*t_suspend_f)(
+		struct sip_msg *msg, unsigned int *hash_index, unsigned int *label);
 
-int t_continue(unsigned int hash_index, unsigned int label,
-		struct action *route);
-int t_continue_skip_timer(unsigned int hash_index, unsigned int label,
-		struct action *route);
-typedef int (*t_continue_f)(unsigned int hash_index, unsigned int label,
-		struct action *route);
+int t_continue(
+		unsigned int hash_index, unsigned int label, struct action *route);
+int t_continue_skip_timer(
+		unsigned int hash_index, unsigned int label, struct action *route);
+typedef int (*t_continue_f)(
+		unsigned int hash_index, unsigned int label, struct action *route);
 
-int t_continue_cb(unsigned int hash_index, unsigned int label,
-		str *cbname, str *cbparam);
-typedef int (*t_continue_cb_f)(unsigned int hash_index, unsigned int label,
-		str *cbname, str *cbparam);
+int t_continue_cb(
+		unsigned int hash_index, unsigned int label, str *cbname, str *cbparam);
+typedef int (*t_continue_cb_f)(
+		unsigned int hash_index, unsigned int label, str *cbname, str *cbparam);
 
 int t_cancel_suspend(unsigned int hash_index, unsigned int label);
 typedef int (*t_cancel_suspend_f)(unsigned int hash_index, unsigned int label);

+ 13 - 15
src/modules/tm/timer.c

@@ -88,7 +88,6 @@
  */
 
 
-
 #include "config.h"
 #include "h_table.h"
 #include "timer.h"
@@ -194,9 +193,8 @@ int tm_init_timers(void)
 	LM_DBG("tm init timers - fr=%d fr_inv=%d wait=%d t1=%d t2=%d"
 		   " max_inv_lifetime=%d max_noninv_lifetime=%d\n",
 			default_tm_cfg.fr_timeout, default_tm_cfg.fr_inv_timeout,
-			default_tm_cfg.wait_timeout,
-			default_tm_cfg.rt_t1_timeout_ms, default_tm_cfg.rt_t2_timeout_ms,
-			default_tm_cfg.tm_max_inv_lifetime,
+			default_tm_cfg.wait_timeout, default_tm_cfg.rt_t1_timeout_ms,
+			default_tm_cfg.rt_t2_timeout_ms, default_tm_cfg.tm_max_inv_lifetime,
 			default_tm_cfg.tm_max_noninv_lifetime);
 	return 0;
 error:
@@ -259,7 +257,7 @@ int timer_fixup_ms(void *handle, str *gname, str *name, void **val)
 
 	t = (long)(*val);
 
-/* size fix checks */
+	/* size fix checks */
 	IF_IS_TIMER_NAME(rt_t1_timeout_ms, "retr_timer1")
 	else IF_IS_TIMER_NAME(rt_t2_timeout_ms, "retr_timer2")
 
@@ -293,7 +291,7 @@ static void fake_reply(struct cell *t, int branch, int code)
 		reply_status =
 				relay_reply(t, FAKED_REPLY, branch, code, &cancel_data, 0);
 	}
-	if(reply_status==RPS_TGONE) {
+	if(reply_status == RPS_TGONE) {
 		return;
 	}
 
@@ -322,8 +320,7 @@ inline static ticks_t retransmission_handler(struct retr_buf *r_buf)
 		abort();
 	}
 #endif
-	if(r_buf->rbtype == TYPE_LOCAL_CANCEL
-			|| r_buf->rbtype == TYPE_REQUEST) {
+	if(r_buf->rbtype == TYPE_LOCAL_CANCEL || r_buf->rbtype == TYPE_REQUEST) {
 #ifdef EXTRA_DEBUG
 		LM_DBG("request resending (t=%p, %.9s ... )\n", r_buf->my_T,
 				r_buf->buffer);
@@ -414,7 +411,8 @@ inline static void final_response_handler(
 	if(silent) {
 		UNLOCK_REPLIES(t);
 #ifdef EXTRA_DEBUG
-		LM_DBG("transaction silently dropped (%p), branch %d, last_received %d\n",
+		LM_DBG("transaction silently dropped (%p), branch %d, last_received "
+			   "%d\n",
 				t, r_buf->branch, t->uac[r_buf->branch].last_received);
 #endif
 		put_on_wait(t);
@@ -427,13 +425,13 @@ inline static void final_response_handler(
 			&& /* r_buf->branch is always >=0 */
 			(t->uac[r_buf->branch].last_received == 0)
 			&& (t->uac[r_buf->branch].request.buffer
-					   != NULL) /* not a blind UAC */
-			) {
+					!= NULL) /* not a blind UAC */
+	) {
 /* no reply received */
 #ifdef USE_DST_BLOCKLIST
 		if(r_buf->my_T && r_buf->my_T->uas.request
 				&& (r_buf->my_T->uas.request->REQ_METHOD
-						   & cfg_get(tm, tm_cfg, tm_blst_methods_add)))
+						& cfg_get(tm, tm_cfg, tm_blst_methods_add)))
 			dst_blocklist_add(
 					BLST_ERR_TIMEOUT, &r_buf->dst, r_buf->my_T->uas.request);
 #endif
@@ -514,7 +512,7 @@ ticks_t retr_buf_handler(ticks_t ticks, struct timer_ln *tl, void *p)
 							  nothing bad would happen */
 		rbuf->flags |= F_RB_TIMEOUT;
 #ifdef TIMER_DEBUG
-		if (rbuf->flags & F_RB_FR_INV) {
+		if(rbuf->flags & F_RB_FR_INV) {
 			LM_DBG("reached the \"fr_inv_timeout\"\n");
 		} else {
 			LM_DBG("reached the \"fr_timeout\"\n");
@@ -602,7 +600,7 @@ ticks_t wait_handler(ticks_t ti, struct timer_ln *wait_tl, void *data)
 	int unlinked = 0;
 	int rcount = 0;
 
-	p_cell = (tm_cell_t*)data;
+	p_cell = (tm_cell_t *)data;
 #ifdef TIMER_DEBUG
 	LM_DBG("WAIT timer hit @%d for %p (timer_lm %p)\n", ti, p_cell, wait_tl);
 #endif
@@ -617,7 +615,7 @@ ticks_t wait_handler(ticks_t ti, struct timer_ln *wait_tl, void *data)
 	if(rcount > 1) {
 		/* t still referenced */
 		LM_DBG("transaction: %p referenced with: %d\n", p_cell, rcount);
-		if(p_cell->wait_start==0) {
+		if(p_cell->wait_start == 0) {
 			p_cell->wait_start = ti;
 		}
 		if(p_cell->wait_start + S_TO_TICKS(TM_LIFETIME_LIMIT) < ti) {

+ 8 - 7
src/modules/tm/timer.h

@@ -197,7 +197,7 @@ inline static int _set_fr_retr(struct retr_buf *rb, unsigned retr_ms)
 	 *  (for neg. replies we are force to wait for the ACK so use fr) */
 	if(unlikely((rb->rbtype == TYPE_REQUEST)
 				&& ((s_ticks_t)(eol - (ticks + timeout))
-						   < 0))) { /* fr after end of life */
+						< 0))) { /* fr after end of life */
 		timeout = (((s_ticks_t)(eol - ticks)) > 0) ? (eol - ticks)
 												   : 1; /* expire now */
 	}
@@ -343,7 +343,7 @@ inline static void change_end_of_life(struct cell *t, int adj, ticks_t eol)
 				if((t->uac[i].request.rbtype == TYPE_REQUEST)
 						&& ((s_ticks_t)(t->end_of_life
 										- t->uac[i].request.fr_expire)
-								   < 0))
+								< 0))
 					t->uac[i].request.fr_expire = t->end_of_life;
 			}
 		}
@@ -372,16 +372,17 @@ inline static int t_linked_timers(tm_cell_t *t)
 {
 	int i;
 
-	if(t->uas.response.timer.next!=NULL || t->uas.response.timer.prev!=NULL) {
+	if(t->uas.response.timer.next != NULL
+			|| t->uas.response.timer.prev != NULL) {
 		return 1;
 	}
 	for(i = 0; i < t->nr_of_outgoings; i++) {
-		if(t->uac[i].request.timer.next!=NULL
-				|| t->uac[i].request.timer.prev!=NULL) {
+		if(t->uac[i].request.timer.next != NULL
+				|| t->uac[i].request.timer.prev != NULL) {
 			return 1;
 		}
-		if(t->uac[i].local_cancel.timer.next!=NULL
-				|| t->uac[i].local_cancel.timer.prev!=NULL) {
+		if(t->uac[i].local_cancel.timer.next != NULL
+				|| t->uac[i].local_cancel.timer.prev != NULL) {
 			return 1;
 		}
 	}

File diff ditekan karena terlalu besar
+ 414 - 403
src/modules/tm/tm.c


+ 21 - 21
src/modules/tm/tm_load.c

@@ -27,52 +27,53 @@
 
 int tm_init = 0;
 
-int load_tm( struct tm_binds *tmb)
+int load_tm(struct tm_binds *tmb)
 {
-	if (!tm_init) {
+	if(!tm_init) {
 		LM_ERR(" Module not initialized yet,"
-			" make sure that all modules that need"
-			" tm module are loaded after tm in the configuration file\n");
+			   " make sure that all modules that need"
+			   " tm module are loaded after tm in the configuration file\n");
 		return -1;
 	}
 
 	memset(tmb, 0, sizeof(struct tm_binds));
 
 	/* exported to cfg */
-	if (!( tmb->t_newtran=(tnewtran_f)find_export("t_newtran", 0, 0)) ) {
+	if(!(tmb->t_newtran = (tnewtran_f)find_export("t_newtran", 0, 0))) {
 		LM_ERR(LOAD_ERROR "'t_newtran' not found\n");
 		return -1;
 	}
 #ifdef USE_TCP
-	if (!( tmb->t_relay_to_tcp=find_export("t_relay_to_tcp", 2, 0)) ) {
+	if(!(tmb->t_relay_to_tcp = find_export("t_relay_to_tcp", 2, 0))) {
 		LM_ERR(LOAD_ERROR "'t_relay_to_tcp' not found\n");
 		return -1;
 	}
 #endif
-	if (!( tmb->t_relay_to_udp=find_export("t_relay_to_udp", 2, 0)) ) {
+	if(!(tmb->t_relay_to_udp = find_export("t_relay_to_udp", 2, 0))) {
 		LM_ERR(LOAD_ERROR "'t_relay_to_udp' not found\n");
 		return -1;
 	}
-	if (!( tmb->t_relay=find_export("t_relay", 0, 0)) ) {
+	if(!(tmb->t_relay = find_export("t_relay", 0, 0))) {
 		LM_ERR(LOAD_ERROR "'t_relay' not found\n");
 		return -1;
 	}
-	if (!(tmb->t_forward_nonack=(tfwd_f)find_export("t_forward_nonack",2,0))) {
+	if(!(tmb->t_forward_nonack =
+					   (tfwd_f)find_export("t_forward_nonack", 2, 0))) {
 		LM_ERR(LOAD_ERROR "'t_forward_nonack' not found\n");
 		return -1;
 	}
-	if (!(tmb->t_release=(trelease_f)find_export("t_release",0,0))) {
+	if(!(tmb->t_release = (trelease_f)find_export("t_release", 0, 0))) {
 		LM_ERR(LOAD_ERROR "'t_release' not found\n");
 		return -1;
 	}
-/*	if (!(tmb->t_reply=(treply_f)find_export(T_REPLY, 2, 0)) ) {
+	/*	if (!(tmb->t_reply=(treply_f)find_export(T_REPLY, 2, 0)) ) {
 		LM_ERR(LOAD_ERROR "'t_reply' not found\n");
 		return -1;
 	}*/
 
 	/* non-cfg API */
 	tmb->t_replicate = t_replicate_uri;
-	tmb->register_tmcb =register_tmcb;
+	tmb->register_tmcb = register_tmcb;
 	tmb->t_reply = w_t_reply_wrp;
 	tmb->t_reply_with_body = t_reply_with_body;
 	tmb->t_reply_trans = t_reply;
@@ -110,8 +111,8 @@ int load_tm( struct tm_binds *tmb)
 	tmb->t_cancel_uac = t_uac_cancel;
 
 #ifdef DIALOG_CALLBACKS
-	tmb->register_new_dlg_cb=register_new_dlg_cb;
-	tmb->register_dlg_tmcb=register_dlg_tmcb;
+	tmb->register_new_dlg_cb = register_new_dlg_cb;
+	tmb->register_dlg_tmcb = register_dlg_tmcb;
 #endif
 	tmb->ack_local_uac = ack_local_uac;
 	tmb->t_get_canceled_ident = t_get_canceled_ident;
@@ -147,19 +148,18 @@ int load_tm( struct tm_binds *tmb)
 
 int load_xtm(tm_xapi_t *xapi)
 {
-	if(xapi==NULL)
-	{
+	if(xapi == NULL) {
 		LM_ERR("invalid parameter\n");
 		return -1;
 	}
 
 	memset(xapi, 0, sizeof(tm_xapi_t));
 
-	xapi->t_on_failure    = t_on_failure;
-	xapi->t_on_branch     = t_on_branch;
-	xapi->t_on_reply      = t_on_reply;
-	xapi->t_check_trans   = t_check_trans;
-	xapi->t_is_canceled   = t_is_canceled;
+	xapi->t_on_failure = t_on_failure;
+	xapi->t_on_branch = t_on_branch;
+	xapi->t_on_reply = t_on_reply;
+	xapi->t_check_trans = t_check_trans;
+	xapi->t_is_canceled = t_is_canceled;
 	xapi->t_on_branch_failure = t_on_branch_failure;
 
 	return 0;

+ 70 - 68
src/modules/tm/tm_load.h

@@ -41,66 +41,67 @@
 #include "t_msgbuilder.h"
 
 /* export not usable from scripts */
-#define NO_SCRIPT	-1
-
-struct tm_binds {
-	register_tmcb_f  register_tmcb;
-	cmd_function     t_relay_to_udp; /* WARNING: failure_route unsafe */
-	cmd_function     t_relay_to_tcp; /* WARNING: failure_route unsafe */
-	cmd_function     t_relay;        /* WARNING: failure_route unsafe */
-	treplicate_uri_f t_replicate;    /* WARNING: failure_route unsafe */
-	tnewtran_f       t_newtran;
-	treply_f         t_reply;
-	treply_wb_f      t_reply_with_body;
-	tislocal_f       t_is_local;
-	tget_ti_f        t_get_trans_ident;
-	tlookup_ident_f  t_lookup_ident;
-	taddblind_f      t_addblind;
-	treply_f         t_reply_unsafe;
-	treply_trans_f   t_reply_trans;
-	tfwd_f           t_forward_nonack;
-	reqwith_t        t_request_within;
-	reqout_t         t_request_outside;
-	req_t            t_request;
-	new_dlg_uac_f      new_dlg_uac;
+#define NO_SCRIPT -1
+
+struct tm_binds
+{
+	register_tmcb_f register_tmcb;
+	cmd_function t_relay_to_udp;  /* WARNING: failure_route unsafe */
+	cmd_function t_relay_to_tcp;  /* WARNING: failure_route unsafe */
+	cmd_function t_relay;		  /* WARNING: failure_route unsafe */
+	treplicate_uri_f t_replicate; /* WARNING: failure_route unsafe */
+	tnewtran_f t_newtran;
+	treply_f t_reply;
+	treply_wb_f t_reply_with_body;
+	tislocal_f t_is_local;
+	tget_ti_f t_get_trans_ident;
+	tlookup_ident_f t_lookup_ident;
+	taddblind_f t_addblind;
+	treply_f t_reply_unsafe;
+	treply_trans_f t_reply_trans;
+	tfwd_f t_forward_nonack;
+	reqwith_t t_request_within;
+	reqout_t t_request_outside;
+	req_t t_request;
+	new_dlg_uac_f new_dlg_uac;
 	dlg_response_uac_f dlg_response_uac;
-	new_dlg_uas_f      new_dlg_uas;
-	update_dlg_uas_f   update_dlg_uas;
-	dlg_request_uas_f  dlg_request_uas;
-	set_dlg_target_f   set_dlg_target;
-	free_dlg_f         free_dlg;
-	print_dlg_f        print_dlg;
-	tgett_f            t_gett;
-	tfind_f            t_find;
-	tunset_f           t_unset;
-	tgett_branch_f     t_gett_branch;
-	tsett_f            t_sett;
-	calculate_hooks_f  calculate_hooks;
-	t_uac_t            t_uac;
-	t_uac_with_ids_t   t_uac_with_ids;
-	trelease_f         t_release;
-	tunref_f           t_unref;
+	new_dlg_uas_f new_dlg_uas;
+	update_dlg_uas_f update_dlg_uas;
+	dlg_request_uas_f dlg_request_uas;
+	set_dlg_target_f set_dlg_target;
+	free_dlg_f free_dlg;
+	print_dlg_f print_dlg;
+	tgett_f t_gett;
+	tfind_f t_find;
+	tunset_f t_unset;
+	tgett_branch_f t_gett_branch;
+	tsett_f t_sett;
+	calculate_hooks_f calculate_hooks;
+	t_uac_t t_uac;
+	t_uac_with_ids_t t_uac_with_ids;
+	trelease_f t_release;
+	tunref_f t_unref;
 	run_failure_handlers_f run_failure_handlers;
 	run_branch_failure_handlers_f run_branch_failure_handlers;
-	cancel_uacs_f      cancel_uacs;
-	cancel_all_uacs_f  cancel_all_uacs;
-	prepare_request_within_f  prepare_request_within;
-	send_prepared_request_f   send_prepared_request;
+	cancel_uacs_f cancel_uacs;
+	cancel_all_uacs_f cancel_all_uacs;
+	prepare_request_within_f prepare_request_within;
+	send_prepared_request_f send_prepared_request;
 #ifdef DIALOG_CALLBACKS
 	register_new_dlg_cb_f register_new_dlg_cb;
-	register_dlg_tmcb_f   register_dlg_tmcb;
+	register_dlg_tmcb_f register_dlg_tmcb;
 #else
-	void* reserved1; /* make sure the structure has the same size even
+	void *reserved1; /* make sure the structure has the same size even
 	                    if no dlg callbacks are used/defined*/
-	void* reserved2;
+	void *reserved2;
 #endif
-	ack_local_uac_f           ack_local_uac;
-	t_get_canceled_ident_f    t_get_canceled_ident;
-	t_suspend_f	t_suspend;
-	t_continue_f	t_continue;
-	t_continue_f	t_continue_skip_timer;
-	t_continue_cb_f	t_continue_cb;
-	t_cancel_suspend_f	t_cancel_suspend;
+	ack_local_uac_f ack_local_uac;
+	t_get_canceled_ident_f t_get_canceled_ident;
+	t_suspend_f t_suspend;
+	t_continue_f t_continue;
+	t_continue_f t_continue_skip_timer;
+	t_continue_cb_f t_continue_cb;
+	t_cancel_suspend_f t_cancel_suspend;
 	tget_reply_totag_f t_get_reply_totag;
 	tget_picked_f t_get_picked_branch;
 	tlookup_callid_f t_lookup_callid;
@@ -114,17 +115,17 @@ struct tm_binds {
 	tm_get_stats_f get_stats;
 	tm_get_table_f get_table;
 	dlg_add_extra_f dlg_add_extra;
-	tuaccancel_f    t_cancel_uac;
+	tuaccancel_f t_cancel_uac;
 #ifdef WITH_TM_CTX
 	tm_ctx_get_f tm_ctx_get;
 #else
-	void* reserved5;
+	void *reserved5;
 #endif
-	t_append_branches_f	t_append_branches;
-	cmd_function	t_load_contacts;
-	cmd_function	t_next_contacts;
+	t_append_branches_f t_append_branches;
+	cmd_function t_load_contacts;
+	cmd_function t_next_contacts;
 	tset_fr_f set_fr;
-	trelease_t      t_release_transaction;
+	trelease_t t_release_transaction;
 	t_uas_request_clean_parsed_f t_uas_request_clean_parsed;
 };
 
@@ -132,24 +133,24 @@ typedef struct tm_binds tm_api_t;
 
 extern int tm_init;
 
-typedef int(*load_tm_f)( struct tm_binds *tmb );
+typedef int (*load_tm_f)(struct tm_binds *tmb);
 int load_tm(struct tm_binds *tmb);
 
 
-static inline int load_tm_api(struct tm_binds* tmb)
+static inline int load_tm_api(struct tm_binds *tmb)
 {
 	load_tm_f load_tm;
 
 	/* import the TM auto-loading function */
 	load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0);
 
-	if (load_tm == NULL) {
+	if(load_tm == NULL) {
 		LM_WARN("Cannot import load_tm function from tm module\n");
 		return -1;
 	}
 
 	/* let the auto-loading function load all TM stuff */
-	if (load_tm(tmb) == -1) {
+	if(load_tm(tmb) == -1) {
 		return -1;
 	}
 	return 0;
@@ -167,10 +168,11 @@ static inline int tm_load_api(tm_api_t *tmb)
 typedef void (*t_on_route_f)(unsigned int);
 typedef int (*t_no_param_f)(struct sip_msg *);
 
-int t_check_trans(struct sip_msg* msg);
-int t_is_canceled(struct sip_msg* msg);
+int t_check_trans(struct sip_msg *msg);
+int t_is_canceled(struct sip_msg *msg);
 
-typedef struct tm_xbinds {
+typedef struct tm_xbinds
+{
 	t_on_route_f t_on_failure;
 	t_on_route_f t_on_branch;
 	t_on_route_f t_on_branch_failure;
@@ -179,7 +181,7 @@ typedef struct tm_xbinds {
 	t_no_param_f t_is_canceled;
 } tm_xapi_t;
 
-typedef int(*load_xtm_f)( tm_xapi_t *xtmb );
+typedef int (*load_xtm_f)(tm_xapi_t *xtmb);
 int load_xtm(tm_xapi_t *xtmb);
 
 static inline int tm_load_xapi(tm_xapi_t *xtmb)
@@ -189,13 +191,13 @@ static inline int tm_load_xapi(tm_xapi_t *xtmb)
 	/* import the TM auto-loading function */
 	load_xtm = (load_xtm_f)find_export("load_xtm", NO_SCRIPT, 0);
 
-	if (load_xtm == NULL) {
+	if(load_xtm == NULL) {
 		LM_WARN("Cannot import load_xtm function from tm module\n");
 		return -1;
 	}
 
 	/* let the auto-loading function load all extra TM stuff */
-	if (load_xtm(xtmb) < 0) {
+	if(load_xtm(xtmb) < 0) {
 		LM_WARN("Cannot bind xapi from tm module\n");
 		return -1;
 	}

File diff ditekan karena terlalu besar
+ 261 - 238
src/modules/tm/uac.c


+ 37 - 36
src/modules/tm/uac.h

@@ -39,32 +39,32 @@
  *  - when TMCB_DESTROY callback is called -- you must
  *    register it explicitly!
  */
-typedef struct uac_req {
-	str	*method;
-	str	*headers;
-	str	*body;
+typedef struct uac_req
+{
+	str *method;
+	str *headers;
+	str *body;
 	str *ssock;
 	str *ssockname;
-	dlg_t	*dialog;
-	int	cb_flags;
-	transaction_cb	*cb;
-	void	*cbp;
-	str	*callid;
+	dlg_t *dialog;
+	int cb_flags;
+	transaction_cb *cb;
+	void *cbp;
+	str *callid;
 } uac_req_t;
 
 /* macro for setting the values of uac_req_t struct */
-#define set_uac_req(_req, \
-		_m, _h, _b, _dlg, _cb_flags, _cb, _cbp) \
-	do { \
-		memset((_req), 0, sizeof(uac_req_t)); \
-		(_req)->method = (_m); \
-		(_req)->headers = (_h); \
-		(_req)->body = (_b); \
-		(_req)->dialog = (_dlg); \
-		(_req)->cb_flags = (_cb_flags); \
-		(_req)->cb = (_cb); \
-		(_req)->cbp = (_cbp); \
-	} while (0)
+#define set_uac_req(_req, _m, _h, _b, _dlg, _cb_flags, _cb, _cbp) \
+	do {                                                          \
+		memset((_req), 0, sizeof(uac_req_t));                     \
+		(_req)->method = (_m);                                    \
+		(_req)->headers = (_h);                                   \
+		(_req)->body = (_b);                                      \
+		(_req)->dialog = (_dlg);                                  \
+		(_req)->cb_flags = (_cb_flags);                           \
+		(_req)->cb = (_cb);                                       \
+		(_req)->cbp = (_cbp);                                     \
+	} while(0)
 
 
 #ifdef WITH_EVENT_LOCAL_REQUEST
@@ -76,21 +76,23 @@ extern int goto_on_local_req;
  * Function prototypes
  */
 typedef int (*reqwith_t)(uac_req_t *uac_r);
-typedef int (*reqout_t)(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop);
-typedef int (*req_t)(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop);
+typedef int (*reqout_t)(
+		uac_req_t *uac_r, str *ruri, str *to, str *from, str *next_hop);
+typedef int (*req_t)(
+		uac_req_t *uac_r, str *ruri, str *to, str *from, str *next_hop);
 typedef int (*t_uac_t)(uac_req_t *uac_r);
-typedef int (*t_uac_with_ids_t)(uac_req_t *uac_r,
-		unsigned int *ret_index, unsigned int *ret_label);
+typedef int (*t_uac_with_ids_t)(
+		uac_req_t *uac_r, unsigned int *ret_index, unsigned int *ret_label);
 typedef int (*ack_local_uac_f)(struct cell *trans, str *hdrs, str *body);
-typedef int (*prepare_request_within_f)(uac_req_t *uac_r,
-		struct retr_buf **dst_req);
+typedef int (*prepare_request_within_f)(
+		uac_req_t *uac_r, struct retr_buf **dst_req);
 typedef void (*send_prepared_request_f)(struct retr_buf *request_dst);
-typedef void (*generate_fromtag_f)(str*, str*, str*);
+typedef void (*generate_fromtag_f)(str *, str *, str *);
 
 /*
  * Generate a fromtag based on given Call-ID
  */
-void generate_fromtag(str* tag, str* callid, str* ruri);
+void generate_fromtag(str *tag, str *callid, str *ruri);
 
 
 /*
@@ -108,8 +110,8 @@ int t_uac(uac_req_t *uac_r);
  * Send a request
  * ret_index and ret_label will identify the new cell
  */
-int t_uac_with_ids(uac_req_t *uac_r,
-	unsigned int *ret_index, unsigned int *ret_label);
+int t_uac_with_ids(
+		uac_req_t *uac_r, unsigned int *ret_index, unsigned int *ret_label);
 /*
  * Send a message within a dialog
  */
@@ -119,11 +121,11 @@ int req_within(uac_req_t *uac_r);
 /*
  * Send an initial request that will start a dialog
  */
-int req_outside(uac_req_t *uac_r, str* ruri, str* to, str* from, str* next_hop);
+int req_outside(uac_req_t *uac_r, str *ruri, str *to, str *from, str *next_hop);
 
 
 struct retr_buf *local_ack_rb(sip_msg_t *rpl_2xx, struct cell *trans,
-					unsigned int branch, str *hdrs, str *body);
+		unsigned int branch, str *hdrs, str *body);
 void free_local_ack(struct retr_buf *lack);
 void free_local_ack_unsafe(struct retr_buf *lack);
 
@@ -135,10 +137,9 @@ int ack_local_uac(struct cell *trans, str *hdrs, str *body);
 /*
  * Send a transactional request, no dialogs involved
  */
-int request(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop);
+int request(uac_req_t *uac_r, str *ruri, str *to, str *from, str *next_hop);
 
-int prepare_req_within(uac_req_t *uac_r,
-		struct retr_buf **dst_req);
+int prepare_req_within(uac_req_t *uac_r, struct retr_buf **dst_req);
 
 void send_prepared_request(struct retr_buf *request);
 

+ 102 - 115
src/modules/tm/ut.h

@@ -45,24 +45,22 @@
 
 
 /*! Which header fields should be skipped */
-#define tm_skip_hf(_hf) \
-	(((_hf)->type == HDR_FROM_T)  || \
-	((_hf)->type == HDR_TO_T)     || \
-	((_hf)->type == HDR_CALLID_T) || \
-	((_hf)->type == HDR_CSEQ_T))
+#define tm_skip_hf(_hf)                                       \
+	(((_hf)->type == HDR_FROM_T) || ((_hf)->type == HDR_TO_T) \
+			|| ((_hf)->type == HDR_CALLID_T) || ((_hf)->type == HDR_CSEQ_T))
 
 
 /* a forced_proto takes precedence if != PROTO_NONE */
-inline static enum sip_protos get_proto(enum sip_protos force_proto,
-										enum sip_protos proto)
+inline static enum sip_protos get_proto(
+		enum sip_protos force_proto, enum sip_protos proto)
 {
 	/* calculate transport protocol */
 	switch(force_proto) {
 		case PROTO_NONE: /* no protocol has been forced -- look at proto */
 			switch(proto) {
 				case PROTO_NONE: /* leave it to dns */
-						return PROTO_NONE;
-				case PROTO_UDP:/* transport specified explicitly */
+					return PROTO_NONE;
+				case PROTO_UDP: /* transport specified explicitly */
 #ifdef USE_TCP
 				case PROTO_TCP:
 				case PROTO_WS:
@@ -73,11 +71,11 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
 #ifdef USE_SCTP
 				case PROTO_SCTP:
 #endif
-						return proto;
-				case PROTO_WSS:	/* should never see ;transport=wss */
+					return proto;
+				case PROTO_WSS: /* should never see ;transport=wss */
 				default:
-						LM_ERR("unsupported transport: %d\n", proto);
-						return PROTO_NONE;
+					LM_ERR("unsupported transport: %d\n", proto);
+					return PROTO_NONE;
 			}
 		case PROTO_UDP: /* some protocol has been forced -- take it */
 #ifdef USE_TCP
@@ -99,46 +97,43 @@ inline static enum sip_protos get_proto(enum sip_protos force_proto,
 }
 
 
-
 /*
  * Convert a URI into a proxy structure
  */
-inline static struct proxy_l *uri2proxy( str *uri, int proto )
+inline static struct proxy_l *uri2proxy(str *uri, int proto)
 {
 	struct sip_uri parsed_uri;
 	struct proxy_l *p;
 	enum sip_protos uri_proto;
 
-	if (parse_uri(uri->s, uri->len, &parsed_uri) < 0) {
-		LM_ERR("bad_uri: [%.*s]\n", uri->len, uri->s );
+	if(parse_uri(uri->s, uri->len, &parsed_uri) < 0) {
+		LM_ERR("bad_uri: [%.*s]\n", uri->len, uri->s);
 		return 0;
 	}
 
-	if (parsed_uri.type==SIPS_URI_T){
-		if (parsed_uri.proto==PROTO_UDP) {
+	if(parsed_uri.type == SIPS_URI_T) {
+		if(parsed_uri.proto == PROTO_UDP) {
 			LM_ERR("bad transport for sips uri: %d\n", parsed_uri.proto);
 			return 0;
-		}else if (parsed_uri.proto != PROTO_WS)
-			uri_proto=PROTO_TLS;
+		} else if(parsed_uri.proto != PROTO_WS)
+			uri_proto = PROTO_TLS;
 		else
-			uri_proto=PROTO_WS;
-	}else
-		uri_proto=parsed_uri.proto;
+			uri_proto = PROTO_WS;
+	} else
+		uri_proto = parsed_uri.proto;
 #ifdef HONOR_MADDR
-	if (parsed_uri.maddr_val.s && parsed_uri.maddr_val.len) {
-		p = mk_proxy(&parsed_uri.maddr_val,
-				parsed_uri.port_no,
+	if(parsed_uri.maddr_val.s && parsed_uri.maddr_val.len) {
+		p = mk_proxy(&parsed_uri.maddr_val, parsed_uri.port_no,
 				get_proto(proto, uri_proto));
-		if (p == 0) {
+		if(p == 0) {
 			LM_ERR("bad maddr param in URI <%.*s>\n", uri->len, ZSW(uri->s));
 			return 0;
 		}
 	} else
 #endif
-	p = mk_proxy(&parsed_uri.host,
-			parsed_uri.port_no,
-			get_proto(proto, uri_proto));
-	if (p == 0) {
+		p = mk_proxy(&parsed_uri.host, parsed_uri.port_no,
+				get_proto(proto, uri_proto));
+	if(p == 0) {
 		LM_ERR("bad host name in URI <%.*s>\n", uri->len, ZSW(uri->s));
 		return 0;
 	}
@@ -147,7 +142,6 @@ inline static struct proxy_l *uri2proxy( str *uri, int proto )
 }
 
 
-
 /*
  * parse uri and return send related information
  * params: uri - uri in string form
@@ -159,46 +153,45 @@ inline static struct proxy_l *uri2proxy( str *uri, int proto )
  *         comp - compression (if used)
  * returns 0 on success, < 0 on error
  */
-inline static int get_uri_send_info(str* uri, str* host, unsigned short* port,
-									char* proto, short* comp)
+inline static int get_uri_send_info(
+		str *uri, str *host, unsigned short *port, char *proto, short *comp)
 {
 	struct sip_uri parsed_uri;
 	enum sip_protos uri_proto;
 
-	if (parse_uri(uri->s, uri->len, &parsed_uri) < 0) {
-		LM_ERR("bad_uri: %.*s\n", uri->len, uri->s );
+	if(parse_uri(uri->s, uri->len, &parsed_uri) < 0) {
+		LM_ERR("bad_uri: %.*s\n", uri->len, uri->s);
 		return -1;
 	}
 
-	if (parsed_uri.type==SIPS_URI_T){
-		if (parsed_uri.proto==PROTO_UDP) {
+	if(parsed_uri.type == SIPS_URI_T) {
+		if(parsed_uri.proto == PROTO_UDP) {
 			LM_ERR("bad transport for sips uri: %d\n", parsed_uri.proto);
 			return -1;
-		}else if (parsed_uri.proto != PROTO_WS)
-			uri_proto=PROTO_TLS;
+		} else if(parsed_uri.proto != PROTO_WS)
+			uri_proto = PROTO_TLS;
 		else
-			uri_proto=PROTO_WS;
-	}else
-		uri_proto=parsed_uri.proto;
+			uri_proto = PROTO_WS;
+	} else
+		uri_proto = parsed_uri.proto;
 
-	*proto= get_proto(*proto, uri_proto);
+	*proto = get_proto(*proto, uri_proto);
 #ifdef USE_COMP
-	*comp=parsed_uri.comp;
+	*comp = parsed_uri.comp;
 #endif
 #ifdef HONOR_MADDR
-	if (parsed_uri.maddr_val.s && parsed_uri.maddr_val.len) {
-		*host=parsed_uri.maddr_val;
+	if(parsed_uri.maddr_val.s && parsed_uri.maddr_val.len) {
+		*host = parsed_uri.maddr_val;
 		LM_DBG("maddr dst: %.*s:%d\n", parsed_uri.maddr_val.len,
 				parsed_uri.maddr_val.s, parsed_uri.port_no);
 	} else
 #endif
-		*host=parsed_uri.host;
-	*port=parsed_uri.port_no;
+		*host = parsed_uri.host;
+	*port = parsed_uri.port_no;
 	return 0;
 }
 
 
-
 /*
  * Convert a URI into a dest_info structure.
  * Same as uri2dst, but uses directly force_send_socket instead of msg.
@@ -220,101 +213,99 @@ inline static int get_uri_send_info(str* uri, str* host, unsigned short* port,
  * returns 0 on error, dst on success
  */
 #ifdef USE_DNS_FAILOVER
-inline static struct dest_info *uri2dst2(struct dns_srv_handle* dns_h,
-										struct dest_info* dst,
-										struct socket_info *force_send_socket,
-										snd_flags_t sflags,
-										str *uri, int proto )
+inline static struct dest_info *uri2dst2(struct dns_srv_handle *dns_h,
+		struct dest_info *dst, struct socket_info *force_send_socket,
+		snd_flags_t sflags, str *uri, int proto)
 #else
-inline static struct dest_info *uri2dst2(struct dest_info* dst,
-										struct socket_info *force_send_socket,
-										snd_flags_t sflags,
-										str *uri, int proto )
+inline static struct dest_info *uri2dst2(struct dest_info *dst,
+		struct socket_info *force_send_socket, snd_flags_t sflags, str *uri,
+		int proto)
 #endif
 {
 	struct sip_uri parsed_uri;
 	enum sip_protos uri_proto;
-	str* host;
+	str *host;
 #ifdef USE_DNS_FAILOVER
 	int ip_found;
 	union sockaddr_union to;
 	int err;
 #endif
 
-	if (parse_uri(uri->s, uri->len, &parsed_uri) < 0) {
-		LM_ERR("bad_uri: [%.*s]\n", uri->len, uri->s );
+	if(parse_uri(uri->s, uri->len, &parsed_uri) < 0) {
+		LM_ERR("bad_uri: [%.*s]\n", uri->len, uri->s);
 		return 0;
 	}
 
-	if (parsed_uri.type==SIPS_URI_T){
-		if (parsed_uri.proto==PROTO_UDP) {
+	if(parsed_uri.type == SIPS_URI_T) {
+		if(parsed_uri.proto == PROTO_UDP) {
 			LM_ERR("bad transport for sips uri: %d\n", parsed_uri.proto);
 			return 0;
-		}else if (parsed_uri.proto!=PROTO_WS)
-			uri_proto=PROTO_TLS;
+		} else if(parsed_uri.proto != PROTO_WS)
+			uri_proto = PROTO_TLS;
 		else
-			uri_proto=PROTO_WS;
-	}else
-		uri_proto=parsed_uri.proto;
+			uri_proto = PROTO_WS;
+	} else
+		uri_proto = parsed_uri.proto;
 
 	init_dest_info(dst);
-	dst->proto= get_proto(proto, uri_proto);
+	dst->proto = get_proto(proto, uri_proto);
 #ifdef USE_COMP
-	dst->comp=parsed_uri.comp;
+	dst->comp = parsed_uri.comp;
 #endif
-	dst->send_flags=sflags;
+	dst->send_flags = sflags;
 #ifdef HONOR_MADDR
-	if (parsed_uri.maddr_val.s && parsed_uri.maddr_val.len) {
-		host=&parsed_uri.maddr_val;
+	if(parsed_uri.maddr_val.s && parsed_uri.maddr_val.len) {
+		host = &parsed_uri.maddr_val;
 		LM_DBG("maddr dst: [%.*s:%d]\n", parsed_uri.maddr_val.len,
-								parsed_uri.maddr_val.s, parsed_uri.port_no);
+				parsed_uri.maddr_val.s, parsed_uri.port_no);
 	} else
 #endif
-		host=&parsed_uri.host;
+		host = &parsed_uri.host;
 #ifdef USE_DNS_FAILOVER
-	if (cfg_get(core, core_cfg, use_dns_failover) && dns_h){
-		ip_found=0;
-		do{
+	if(cfg_get(core, core_cfg, use_dns_failover) && dns_h) {
+		ip_found = 0;
+		do {
 			/* try all the ips until we find a good send socket */
-			err=dns_sip_resolve2su(dns_h, &to, host,
-								parsed_uri.port_no, &dst->proto, dns_flags);
-			if (err!=0){
-				if (ip_found==0){
-					if (err!=-E_DNS_EOR)
+			err = dns_sip_resolve2su(dns_h, &to, host, parsed_uri.port_no,
+					&dst->proto, dns_flags);
+			if(err != 0) {
+				if(ip_found == 0) {
+					if(err != -E_DNS_EOR)
 						LM_ERR("failed to resolve \"%.*s\" :"
-								"%s (%d)\n", host->len, ZSW(host->s),
-									dns_strerror(err), err);
+							   "%s (%d)\n",
+								host->len, ZSW(host->s), dns_strerror(err),
+								err);
 					return 0; /* error, no ip found */
 				}
 				break;
 			}
-			if (ip_found==0){
-				dst->to=to;
-				ip_found=1;
+			if(ip_found == 0) {
+				dst->to = to;
+				ip_found = 1;
 			}
-			dst->send_sock = get_send_socket2(force_send_socket, &to,
-												dst->proto, 0);
-			if (dst->send_sock){
-				dst->to=to;
+			dst->send_sock =
+					get_send_socket2(force_send_socket, &to, dst->proto, 0);
+			if(dst->send_sock) {
+				dst->to = to;
 				return dst; /* found a good one */
 			}
-		}while(dns_srv_handle_next(dns_h, err));
+		} while(dns_srv_handle_next(dns_h, err));
 		LM_ERR("no corresponding socket for \"%.*s\" af %d\n", host->len,
 				ZSW(host->s), dst->to.s.sa_family);
 		/* try to continue */
 		return dst;
 	}
 #endif
-	if (sip_hostport2su(&dst->to, host, parsed_uri.port_no, &dst->proto)!=0){
+	if(sip_hostport2su(&dst->to, host, parsed_uri.port_no, &dst->proto) != 0) {
 		LM_ERR("failed to resolve \"%.*s\"\n", host->len, ZSW(host->s));
 		return 0;
 	}
-	dst->send_sock = get_send_socket2(force_send_socket, &dst->to,
-										dst->proto, 0);
-	if (dst->send_sock==0) {
+	dst->send_sock =
+			get_send_socket2(force_send_socket, &dst->to, dst->proto, 0);
+	if(dst->send_sock == 0) {
 		LM_ERR("no corresponding socket found for \"%.*s\" af %d (%s:%s)\n",
-			host->len, ZSW(host->s), dst->to.s.sa_family,
-			proto2a(dst->proto), su2a(&dst->to, sizeof(dst->to)));
+				host->len, ZSW(host->s), dst->to.s.sa_family,
+				proto2a(dst->proto), su2a(&dst->to, sizeof(dst->to)));
 		/* ser_error = E_NO_SOCKET;*/
 		/* try to continue */
 	}
@@ -322,7 +313,6 @@ inline static struct dest_info *uri2dst2(struct dest_info* dst,
 }
 
 
-
 /*
  * Convert a URI into a dest_info structure
  * If the uri host resolves to multiple ips and dns_h!=0 the first ip for
@@ -344,27 +334,24 @@ inline static struct dest_info *uri2dst2(struct dest_info* dst,
  * returns 0 on error, dst on success
  */
 #ifdef USE_DNS_FAILOVER
-inline static struct dest_info *uri2dst(struct dns_srv_handle* dns_h,
-										struct dest_info* dst,
-										struct sip_msg *msg, str *uri,
-											int proto )
+inline static struct dest_info *uri2dst(struct dns_srv_handle *dns_h,
+		struct dest_info *dst, struct sip_msg *msg, str *uri, int proto)
 {
 	snd_flags_t sflags;
-	if (msg)
-		return uri2dst2(dns_h, dst, msg->force_send_socket,
-							msg->fwd_send_flags, uri, proto);
+	if(msg)
+		return uri2dst2(dns_h, dst, msg->force_send_socket, msg->fwd_send_flags,
+				uri, proto);
 	SND_FLAGS_INIT(&sflags);
 	return uri2dst2(dns_h, dst, 0, sflags, uri, proto);
 }
 #else
-inline static struct dest_info *uri2dst(struct dest_info* dst,
-										struct sip_msg *msg, str *uri,
-											int proto )
+inline static struct dest_info *uri2dst(
+		struct dest_info *dst, struct sip_msg *msg, str *uri, int proto)
 {
 	snd_flags_t sflags;
-	if (msg)
-		return uri2dst2(dst, msg->force_send_socket, msg->fwd_send_flags,
-						uri, proto);
+	if(msg)
+		return uri2dst2(
+				dst, msg->force_send_socket, msg->fwd_send_flags, uri, proto);
 	SND_FLAGS_INIT(&sflags);
 	return uri2dst2(dst, 0, sflags, uri, proto);
 }

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini