From 77693248300a6cecb802950fad754bf933218163 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 17 May 2023 16:37:38 +0200 Subject: [PATCH] tm: clang-format for coherent indentation and coding style --- src/modules/tm/callid.c | 2 +- src/modules/tm/config.c | 311 ++-- src/modules/tm/config.h | 99 +- src/modules/tm/dlg.c | 2 +- src/modules/tm/dlg.h | 20 +- src/modules/tm/h_table.c | 37 +- src/modules/tm/h_table.h | 28 +- src/modules/tm/lw_parser.c | 18 +- src/modules/tm/rpc_uac.c | 534 +++---- src/modules/tm/rpc_uac.h | 6 +- src/modules/tm/select.c | 184 ++- src/modules/tm/t_append_branches.c | 140 +- src/modules/tm/t_append_branches.h | 4 +- src/modules/tm/t_cancel.c | 297 ++-- src/modules/tm/t_cancel.h | 58 +- src/modules/tm/t_fifo.c | 687 ++++----- src/modules/tm/t_fifo.h | 9 +- src/modules/tm/t_funcs.c | 248 ++-- src/modules/tm/t_funcs.h | 123 +- src/modules/tm/t_fwd.c | 1426 +++++++++---------- src/modules/tm/t_fwd.h | 59 +- src/modules/tm/t_hooks.c | 202 ++- src/modules/tm/t_hooks.h | 223 +-- src/modules/tm/t_lookup.c | 1705 +++++++++++----------- src/modules/tm/t_lookup.h | 104 +- src/modules/tm/t_msgbuilder.c | 1122 ++++++++------- src/modules/tm/t_msgbuilder.h | 39 +- src/modules/tm/t_reply.c | 1928 ++++++++++++------------- src/modules/tm/t_reply.h | 118 +- src/modules/tm/t_serial.c | 392 ++--- src/modules/tm/t_serial.h | 14 +- src/modules/tm/t_stats.c | 246 ++-- src/modules/tm/t_stats.h | 49 +- src/modules/tm/t_suspend.c | 275 ++-- src/modules/tm/t_suspend.h | 28 +- src/modules/tm/timer.c | 28 +- src/modules/tm/timer.h | 15 +- src/modules/tm/tm.c | 2131 ++++++++++++++-------------- src/modules/tm/tm_load.c | 42 +- src/modules/tm/tm_load.h | 138 +- src/modules/tm/uac.c | 548 +++---- src/modules/tm/uac.h | 73 +- src/modules/tm/ut.h | 217 ++- 43 files changed, 7112 insertions(+), 6817 deletions(-) diff --git a/src/modules/tm/callid.c b/src/modules/tm/callid.c index b439f39004b..e223a8f1a98 100644 --- a/src/modules/tm/callid.c +++ b/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; diff --git a/src/modules/tm/config.c b/src/modules/tm/config.c index 5c5ea585908..3cf4f156528 100644 --- a/src/modules/tm/config.c +++ b/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}}; diff --git a/src/modules/tm/config.h b/src/modules/tm/config.h index 47f05e0c4c6..b0fedbbfbbe 100644 --- a/src/modules/tm/config.h +++ b/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 diff --git a/src/modules/tm/dlg.c b/src/modules/tm/dlg.c index 4743e09003a..6d131b53c79 100644 --- a/src/modules/tm/dlg.c +++ b/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 */ diff --git a/src/modules/tm/dlg.h b/src/modules/tm/dlg.h index 262f6500436..9c8841d55ab 100644 --- a/src/modules/tm/dlg.h +++ b/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 diff --git a/src/modules/tm/h_table.c b/src/modules/tm/h_table.c index a31c191dafb..cb9a56b361d 100644 --- a/src/modules/tm/h_table.c +++ b/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; rentries[r], next_c)) { continue; diff --git a/src/modules/tm/h_table.h b/src/modules/tm/h_table.h index 5ebba9b0fc6..69f89ee3d0e 100644 --- a/src/modules/tm/h_table.h +++ b/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 diff --git a/src/modules/tm/lw_parser.c b/src/modules/tm/lw_parser.c index 6f48304f53e..4686f7c4359 100644 --- a/src/modules/tm/lw_parser.c +++ b/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); diff --git a/src/modules/tm/rpc_uac.c b/src/modules/tm/rpc_uac.c index 5c2fc7be56a..ce22b6121c1 100644 --- a/src/modules/tm/rpc_uac.c +++ b/src/modules/tm/rpc_uac.c @@ -39,7 +39,8 @@ void tm_rpc_response_list_clean(unsigned int ticks, void *param); -typedef struct tm_rpc_response { +typedef struct tm_rpc_response +{ str ruid; int flags; int rcode; @@ -48,7 +49,8 @@ typedef struct tm_rpc_response { struct tm_rpc_response *next; } tm_rpc_response_t; -typedef struct tm_rpc_response_list { +typedef struct tm_rpc_response_list +{ gen_lock_t rlock; tm_rpc_response_t *rlist; } tm_rpc_response_list_t; @@ -65,12 +67,12 @@ int tm_rpc_response_list_init(void) if(_tm_rpc_response_list != NULL) { return 0; } - if(sruid_init(&_tm_rpc_sruid, '-', "tmrp", SRUID_INC)<0) { + if(sruid_init(&_tm_rpc_sruid, '-', "tmrp", SRUID_INC) < 0) { LM_ERR("failed to init sruid\n"); return -1; } - if(sr_wtimer_add(tm_rpc_response_list_clean, 0, - TM_RPC_RESPONSE_TIMERSTEP)<0) { + if(sr_wtimer_add(tm_rpc_response_list_clean, 0, TM_RPC_RESPONSE_TIMERSTEP) + < 0) { LM_ERR("failed to register timer routine\n"); return -1; } @@ -101,7 +103,7 @@ int tm_rpc_response_list_destroy(void) rl1 = _tm_rpc_response_list->rlist; - while(rl1!=NULL) { + while(rl1 != NULL) { rl0 = rl1; rl1 = rl1->next; shm_free(rl0); @@ -126,21 +128,21 @@ int tm_rpc_response_list_add(str *ruid, int rcode, str *rtext) } rsize = sizeof(tm_rpc_response_t) + ruid->len + 2 - + ((rtext!=NULL)?rtext->len:0); + + ((rtext != NULL) ? rtext->len : 0); - ri = (tm_rpc_response_t*)shm_malloc(rsize); - if(ri==NULL) { + ri = (tm_rpc_response_t *)shm_malloc(rsize); + if(ri == NULL) { SHM_MEM_ERROR; return -1; } memset(ri, 0, rsize); - ri->ruid.s = (char*)ri + sizeof(tm_rpc_response_t); + ri->ruid.s = (char *)ri + sizeof(tm_rpc_response_t); ri->ruid.len = ruid->len; memcpy(ri->ruid.s, ruid->s, ruid->len); ri->rtime = time(NULL); ri->rcode = rcode; - if(rtext!=NULL) { + if(rtext != NULL) { ri->rtext.s = ri->ruid.s + ri->ruid.len + 1; ri->rtext.len = rtext->len; memcpy(ri->rtext.s, rtext->s, rtext->len); @@ -168,9 +170,9 @@ tm_rpc_response_t *tm_rpc_response_list_get(str *ruid) lock_get(&_tm_rpc_response_list->rlock); ri1 = _tm_rpc_response_list->rlist; - while(ri1!=NULL) { - if(ri1->ruid.len==ruid->len - && memcmp(ri1->ruid.s, ruid->s, ruid->len)==0) { + while(ri1 != NULL) { + if(ri1->ruid.len == ruid->len + && memcmp(ri1->ruid.s, ruid->s, ruid->len) == 0) { if(ri0 == NULL) { _tm_rpc_response_list->rlist = ri1->next; } else { @@ -202,7 +204,7 @@ void tm_rpc_response_list_clean(unsigned int ticks, void *param) tnow = time(NULL); lock_get(&_tm_rpc_response_list->rlock); ri1 = _tm_rpc_response_list->rlist; - while(ri1!=NULL) { + while(ri1 != NULL) { if(ri1->rtime < tnow - TM_RPC_RESPONSE_LIFETIME) { LM_DBG("freeing item [%.*s]\n", ri1->ruid.len, ri1->ruid.s); if(ri0 == NULL) { @@ -237,44 +239,42 @@ void tm_rpc_response_list_clean(unsigned int ticks, void *param) * @callid - filled on success with a pointer to the callid in the msg. * @return -1 on error (and sends the rpc reply), 0 on success */ -static int rpc_uac_check_msg(rpc_t *rpc, void* c, - struct sip_msg* msg, - str* method, str* body, - str* fromtag, int *cseq_is, int* cseq, - str* callid) +static int rpc_uac_check_msg(rpc_t *rpc, void *c, struct sip_msg *msg, + str *method, str *body, str *fromtag, int *cseq_is, int *cseq, + str *callid) { - struct to_body* parsed_from; + struct to_body *parsed_from; struct cseq_body *parsed_cseq; int i; char ch; - if (body->len && !msg->content_type) { + if(body->len && !msg->content_type) { rpc->fault(c, 400, "Content-Type missing"); goto err; } - if (body->len && msg->content_length) { + if(body->len && msg->content_length) { rpc->fault(c, 400, "Content-Length disallowed"); goto err; } - if (!msg->to) { - rpc->fault(c, 400, "To missing"); + if(!msg->to) { + rpc->fault(c, 400, "To missing"); goto err; } - if (!msg->from) { + if(!msg->from) { rpc->fault(c, 400, "From missing"); goto err; } /* we also need to know if there is from-tag and add it otherwise */ - if (parse_from_header(msg) < 0) { + if(parse_from_header(msg) < 0) { rpc->fault(c, 400, "Error in From"); goto err; } - parsed_from = (struct to_body*)msg->from->parsed; + parsed_from = (struct to_body *)msg->from->parsed; if(parsed_from->tag_value.s && parsed_from->tag_value.len) { fromtag->s = parsed_from->tag_value.s; fromtag->len = parsed_from->tag_value.len; @@ -284,22 +284,22 @@ static int rpc_uac_check_msg(rpc_t *rpc, void* c, } *cseq = 0; - if (msg->cseq && (parsed_cseq = get_cseq(msg))) { + if(msg->cseq && (parsed_cseq = get_cseq(msg))) { *cseq_is = 1; - for (i = 0; i < parsed_cseq->number.len; i++) { + for(i = 0; i < parsed_cseq->number.len; i++) { ch = parsed_cseq->number.s[i]; - if (ch >= '0' && ch <= '9' ) { + if(ch >= '0' && ch <= '9') { *cseq = (*cseq) * 10 + ch - '0'; } else { LM_DBG("Found non-numerical in CSeq: <%i>='%c'\n", (unsigned int)ch, ch); - rpc->fault(c, 400, "Non-numerical CSeq"); + rpc->fault(c, 400, "Non-numerical CSeq"); goto err; } } - if (parsed_cseq->method.len != method->len || - memcmp(parsed_cseq->method.s, method->s, method->len) !=0 ) { + if(parsed_cseq->method.len != method->len + || memcmp(parsed_cseq->method.s, method->s, method->len) != 0) { rpc->fault(c, 400, "CSeq method mismatch"); goto err; } @@ -307,7 +307,7 @@ static int rpc_uac_check_msg(rpc_t *rpc, void* c, *cseq_is = 0; } - if (msg->callid) { + if(msg->callid) { callid->s = msg->callid->body.s; callid->len = msg->callid->body.len; } else { @@ -327,7 +327,7 @@ static int rpc_uac_check_msg(rpc_t *rpc, void* c, * 0 on error. */ static int get_hfblock(str *uri, struct hdr_field *hf, int proto, - struct socket_info* ssock, str* hout) + struct socket_info *ssock, str *hout) { struct str_list sl, *last, *i, *foo; int p, frag_len, total_len; @@ -343,12 +343,13 @@ static int get_hfblock(str *uri, struct hdr_field *hf, int proto, last->next = 0; sock_name = 0; portname = 0; - if (ssock){ + if(ssock) { si_get_signaling_data(ssock, &sock_name, &portname); } - for (; hf; hf = hf->next) { - if (tm_skip_hf(hf)) continue; + for(; hf; hf = hf->next) { + if(tm_skip_hf(hf)) + continue; begin = needle = hf->name.s; p = hf->len; @@ -356,8 +357,9 @@ static int get_hfblock(str *uri, struct hdr_field *hf, int proto, /* substitution loop */ while(p) { d = q_memchr(needle, SUBST_CHAR, p); - if (!d || d + 1 >= needle + p) { /* nothing to substitute */ - if (!append_str_list(begin, p, &last, &total_len)) goto error; + if(!d || d + 1 >= needle + p) { /* nothing to substitute */ + if(!append_str_list(begin, p, &last, &total_len)) + goto error; break; } else { frag_len = d - begin; @@ -365,29 +367,32 @@ static int get_hfblock(str *uri, struct hdr_field *hf, int proto, switch(*d) { case SUBST_CHAR: /* double SUBST_CHAR: IP */ /* string before substitute */ - if (!append_str_list(begin, frag_len, &last, &total_len)) + if(!append_str_list(begin, frag_len, &last, &total_len)) goto error; /* substitute */ - if (!sock_name) { - if ( + if(!sock_name) { + if( #ifdef USE_DNS_FAILOVER uri2dst(0, &di, 0, uri, proto) #else uri2dst(&di, 0, uri, proto) #endif /* USE_DNS_FAILOVER */ - == 0 ){ + == 0) { LM_ERR("send_sock failed\n"); goto error; } - si_get_signaling_data(di.send_sock, &sock_name, &portname); + si_get_signaling_data( + di.send_sock, &sock_name, &portname); } - if (!append_str_list(sock_name->s, sock_name->len, &last, - &total_len)) + if(!append_str_list(sock_name->s, sock_name->len, &last, + &total_len)) goto error; /* inefficient - FIXME --andrei*/ - if (!append_str_list(":", 1, &last, &total_len)) goto error; - if (!append_str_list(portname->s, portname->len, &last, - &total_len)) goto error; + if(!append_str_list(":", 1, &last, &total_len)) + goto error; + if(!append_str_list(portname->s, portname->len, &last, + &total_len)) + goto error; /* keep going ... */ begin = needle = d + 1; p -= frag_len + 2; @@ -398,18 +403,19 @@ static int get_hfblock(str *uri, struct hdr_field *hf, int proto, needle = d; } } /* possible substitute */ - } /* substitution loop */ + } /* substitution loop */ LM_DBG("one more hf processed\n"); } /* header loop */ - if(total_len==0) { + if(total_len == 0) { LM_DBG("empty result for headers block\n"); - return 1;; + return 1; + ; } /* construct a single header block now */ ret = pkg_malloc(total_len); - if (!ret) { + if(!ret) { PKG_MEM_ERROR; goto error; } @@ -437,10 +443,10 @@ static int get_hfblock(str *uri, struct hdr_field *hf, int proto, } -#define RPC_ROUTE_PREFIX "Route: " -#define RPC_ROUTE_PREFIX_LEN (sizeof(RPC_ROUTE_PREFIX)-1) -#define RPC_ROUTE_SEPARATOR ", " -#define RPC_ROUTE_SEPARATOR_LEN (sizeof(RPC_ROUTE_SEPARATOR)-1) +#define RPC_ROUTE_PREFIX "Route: " +#define RPC_ROUTE_PREFIX_LEN (sizeof(RPC_ROUTE_PREFIX) - 1) +#define RPC_ROUTE_SEPARATOR ", " +#define RPC_ROUTE_SEPARATOR_LEN (sizeof(RPC_ROUTE_SEPARATOR) - 1) /** internal print routes into rpc reply function. @@ -450,53 +456,52 @@ static int get_hfblock(str *uri, struct hdr_field *hf, int proto, * @param c - rpc context * @param reply - sip reply */ -static void rpc_print_routes(rpc_t* rpc, void* c, - dlg_t* d) +static void rpc_print_routes(rpc_t *rpc, void *c, dlg_t *d) { - rr_t* ptr; + rr_t *ptr; int size; - char* buf; - char* p; + char *buf; + char *p; - if (d->hooks.first_route == 0){ + if(d->hooks.first_route == 0) { rpc->add(c, "s", ""); return; } - size=RPC_ROUTE_PREFIX_LEN; - for (ptr=d->hooks.first_route; ptr; ptr=ptr->next) - size+=ptr->len+(ptr->next!=0)*RPC_ROUTE_SEPARATOR_LEN; - if (d->hooks.last_route) - size+=RPC_ROUTE_SEPARATOR_LEN + 1 /* '<' */ + - d->hooks.last_route->len +1 /* '>' */; + size = RPC_ROUTE_PREFIX_LEN; + for(ptr = d->hooks.first_route; ptr; ptr = ptr->next) + size += ptr->len + (ptr->next != 0) * RPC_ROUTE_SEPARATOR_LEN; + if(d->hooks.last_route) + size += RPC_ROUTE_SEPARATOR_LEN + 1 /* '<' */ + d->hooks.last_route->len + + 1 /* '>' */; - buf=pkg_malloc(size+1); - if (buf==0){ + buf = pkg_malloc(size + 1); + if(buf == 0) { PKG_MEM_ERROR; rpc->add(c, "s", ""); return; } - p=buf; + p = buf; memcpy(p, RPC_ROUTE_PREFIX, RPC_ROUTE_PREFIX_LEN); - p+=RPC_ROUTE_PREFIX_LEN; - for (ptr=d->hooks.first_route; ptr; ptr=ptr->next){ + p += RPC_ROUTE_PREFIX_LEN; + for(ptr = d->hooks.first_route; ptr; ptr = ptr->next) { memcpy(p, ptr->nameaddr.name.s, ptr->len); - p+=ptr->len; - if (ptr->next!=0){ + p += ptr->len; + if(ptr->next != 0) { memcpy(p, RPC_ROUTE_SEPARATOR, RPC_ROUTE_SEPARATOR_LEN); - p+=RPC_ROUTE_SEPARATOR_LEN; + p += RPC_ROUTE_SEPARATOR_LEN; } } - if (d->hooks.last_route){ + if(d->hooks.last_route) { memcpy(p, RPC_ROUTE_SEPARATOR, RPC_ROUTE_SEPARATOR_LEN); - p+=RPC_ROUTE_SEPARATOR_LEN; - *p='<'; + p += RPC_ROUTE_SEPARATOR_LEN; + *p = '<'; p++; memcpy(p, d->hooks.last_route->s, d->hooks.last_route->len); - p+=d->hooks.last_route->len; - *p='>'; + p += d->hooks.last_route->len; + *p = '>'; p++; } - *p=0; + *p = 0; rpc->add(c, "s", buf); pkg_free(buf); return; @@ -510,30 +515,30 @@ static void rpc_print_routes(rpc_t* rpc, void* c, * @param c - rpc context * @param reply - sip reply */ -static void rpc_print_uris(rpc_t* rpc, void* c, struct sip_msg* reply) +static void rpc_print_uris(rpc_t *rpc, void *c, struct sip_msg *reply) { - dlg_t* dlg; - dlg=shm_malloc(sizeof(dlg_t)); - if (dlg==0){ + dlg_t *dlg; + dlg = shm_malloc(sizeof(dlg_t)); + if(dlg == 0) { SHM_MEM_ERROR; return; } memset(dlg, 0, sizeof(dlg_t)); - if (dlg_response_uac(dlg, reply, TARGET_REFRESH_UNKNOWN) < 0) { + if(dlg_response_uac(dlg, reply, TARGET_REFRESH_UNKNOWN) < 0) { LM_ERR("failure while filling dialog structure\n"); free_dlg(dlg); return; } - if (dlg->state != DLG_CONFIRMED) { + if(dlg->state != DLG_CONFIRMED) { free_dlg(dlg); return; } - if (dlg->hooks.request_uri->s){ + if(dlg->hooks.request_uri->s) { rpc->add(c, "S", dlg->hooks.request_uri); - }else{ + } else { rpc->add(c, "s", ""); } - if (dlg->hooks.next_hop->s) { + if(dlg->hooks.next_hop->s) { rpc->add(c, "S", dlg->hooks.next_hop); } else { rpc->add(c, "s", ""); @@ -544,58 +549,57 @@ static void rpc_print_uris(rpc_t* rpc, void* c, struct sip_msg* reply) } - /* t_uac callback */ -static void rpc_uac_callback(struct cell* t, int type, struct tmcb_params* ps) +static void rpc_uac_callback(struct cell *t, int type, struct tmcb_params *ps) { - rpc_delayed_ctx_t* dctx; + rpc_delayed_ctx_t *dctx; str text; - rpc_t* rpc; - void* c; + rpc_t *rpc; + void *c; int code; - str* preason; + str *preason; - dctx=(rpc_delayed_ctx_t*)*ps->param; - *ps->param=0; - if (dctx==0){ + dctx = (rpc_delayed_ctx_t *)*ps->param; + *ps->param = 0; + if(dctx == 0) { BUG("null delayed reply ctx\n"); return; } - rpc=&dctx->rpc; - c=dctx->reply_ctx; - if (ps->rpl==FAKED_REPLY) { - text.s=error_text(ps->code); - text.len=strlen(text.s); - code=ps->code; - preason=&text; + rpc = &dctx->rpc; + c = dctx->reply_ctx; + if(ps->rpl == FAKED_REPLY) { + text.s = error_text(ps->code); + text.len = strlen(text.s); + code = ps->code; + preason = &text; rpc->add(c, "dS", code, preason); rpc->add(c, "s", ""); /* request uri (rpc_print_uris)*/ rpc->add(c, "s", ""); /* next hop (rpc_print_uris) */ rpc->add(c, "s", ""); /* dialog routes (rpc_print_routes) */ rpc->add(c, "s", ""); /* rest of the reply */ - }else{ - code=ps->rpl->first_line.u.reply.statuscode; - preason=&ps->rpl->first_line.u.reply.reason; + } else { + code = ps->rpl->first_line.u.reply.statuscode; + preason = &ps->rpl->first_line.u.reply.reason; rpc->add(c, "dS", code, preason); rpc_print_uris(rpc, c, ps->rpl); /* print all the reply (from the first header) */ rpc->add(c, "s", ps->rpl->headers->name.s); } rpc->delayed_ctx_close(dctx); - ps->param=0; + ps->param = 0; } /* t_uac callback */ -static void rpc_uac_block_callback(struct cell* t, int type, - struct tmcb_params* ps) +static void rpc_uac_block_callback( + struct cell *t, int type, struct tmcb_params *ps) { str *ruid; str rtext; - ruid = (str*)(*ps->param); - *ps->param=0; - if (ps->rpl==FAKED_REPLY) { + ruid = (str *)(*ps->param); + *ps->param = 0; + if(ps->rpl == FAKED_REPLY) { rtext.s = error_text(ps->code); rtext.len = strlen(rtext.s); } else { @@ -629,7 +633,7 @@ static void rpc_uac_block_callback(struct cell* t, int type, * for the transaction arrives, if 0 immediately send * an rpc reply (see above). */ -static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) +static void rpc_t_uac(rpc_t *rpc, void *c, int reply_wait) { /* rpc params */ str method, ruri, nexthop, send_socket, headers, body; @@ -637,7 +641,7 @@ static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) str hfb, callid; struct sip_uri p_uri, pnexthop; struct sip_msg faked_msg; - struct socket_info* ssock; + struct socket_info *ssock; str saddr; int sport, sproto; int ret, sip_error, err_ret, cseq_is, cseq; @@ -645,105 +649,115 @@ static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) char err_buf[MAX_REASON_LEN]; dlg_t dlg; uac_req_t uac_req; - rpc_delayed_ctx_t* dctx; + rpc_delayed_ctx_t *dctx; str *ruid = NULL; tm_rpc_response_t *ritem = NULL; int rcount = 0; - void* th = NULL; - - body.s=0; - body.len=0; - dctx=0; - if (reply_wait==1 && (rpc->capabilities == 0 || - !(rpc->capabilities(c) & RPC_DELAYED_REPLY))) { - rpc->fault(c, 600, "Reply wait/async mode not supported" + void *th = NULL; + + body.s = 0; + body.len = 0; + dctx = 0; + if(reply_wait == 1 + && (rpc->capabilities == 0 + || !(rpc->capabilities(c) & RPC_DELAYED_REPLY))) { + rpc->fault(c, 600, + "Reply wait/async mode not supported" " by this rpc transport"); return; } - ret=rpc->scan(c, "SSSSS*S", - &method, &ruri, &nexthop, &send_socket, &headers, &body); - if (ret<5 && ! (-ret == 5)){ - rpc->fault(c, 400, "too few parameters (%d/5)", ret?ret:-ret); + ret = rpc->scan(c, "SSSSS*S", &method, &ruri, &nexthop, &send_socket, + &headers, &body); + if(ret < 5 && !(-ret == 5)) { + rpc->fault(c, 400, "too few parameters (%d/5)", ret ? ret : -ret); return; } /* check and parse parameters */ - if (method.len==0){ + if(method.len == 0) { rpc->fault(c, 400, "Empty method"); return; } - if (parse_uri(ruri.s, ruri.len, &p_uri)<0){ + if(parse_uri(ruri.s, ruri.len, &p_uri) < 0) { rpc->fault(c, 400, "Invalid request uri \"%s\"", ruri.s); return; } /* old fifo & unixsock backwards compatibility for nexthop: '.' is still allowed */ - if (nexthop.len==1 && nexthop.s[0]=='.'){ + if(nexthop.len == 1 && nexthop.s[0] == '.') { /* empty nextop */ - nexthop.len=0; - nexthop.s=0; - }else if (nexthop.len==0){ - nexthop.s=0; - }else if (parse_uri(nexthop.s, nexthop.len, &pnexthop)<0){ + nexthop.len = 0; + nexthop.s = 0; + } else if(nexthop.len == 0) { + nexthop.s = 0; + } else if(parse_uri(nexthop.s, nexthop.len, &pnexthop) < 0) { rpc->fault(c, 400, "Invalid next-hop uri \"%s\"", nexthop.s); return; } /* kamailio backwards compatibility for send_socket: '.' is still allowed for an empty socket */ - ssock=0; - saddr.s=0; - saddr.len=0; - if (send_socket.len==1 && send_socket.s[0]=='.'){ + ssock = 0; + saddr.s = 0; + saddr.len = 0; + if(send_socket.len == 1 && send_socket.s[0] == '.') { /* empty send socket */ - send_socket.len=0; - }else if (send_socket.len && - (parse_phostport(send_socket.s, &saddr.s, &saddr.len, - &sport, &sproto)!=0 || - /* check also if it's not a MH addr. */ - saddr.len==0 || saddr.s[0]=='(') - ){ + send_socket.len = 0; + } else if(send_socket.len + && (parse_phostport( + send_socket.s, &saddr.s, &saddr.len, &sport, &sproto) + != 0 + || + /* check also if it's not a MH addr. */ + saddr.len == 0 || saddr.s[0] == '(')) { rpc->fault(c, 400, "Invalid send socket \"%s\"", send_socket.s); return; - }else if (saddr.len && (ssock=grep_sock_info(&saddr, sport, sproto))==0){ + } else if(saddr.len + && (ssock = grep_sock_info(&saddr, sport, sproto)) == 0) { rpc->fault(c, 400, "No local socket for \"%s\"", send_socket.s); return; } /* check headers using the SIP parser to look in the header list */ memset(&faked_msg, 0, sizeof(struct sip_msg)); - faked_msg.len=headers.len; - faked_msg.buf=faked_msg.unparsed=headers.s; - if (parse_headers(&faked_msg, HDR_EOH_F, 0)==-1){ + faked_msg.len = headers.len; + faked_msg.buf = faked_msg.unparsed = headers.s; + if(parse_headers(&faked_msg, HDR_EOH_F, 0) == -1) { rpc->fault(c, 400, "Invalid headers"); return; } /* at this moment all the parameters are parsed => more sanity checks */ - if (rpc_uac_check_msg(rpc, c, &faked_msg, &method, &body, &fromtag, - &cseq_is, &cseq, &callid)<0) + if(rpc_uac_check_msg(rpc, c, &faked_msg, &method, &body, &fromtag, &cseq_is, + &cseq, &callid) + < 0) goto error; - if(get_hfblock(nexthop.len? &nexthop: &ruri, faked_msg.headers, - PROTO_NONE, ssock, &hfb)<0) { + if(get_hfblock(nexthop.len ? &nexthop : &ruri, faked_msg.headers, + PROTO_NONE, ssock, &hfb) + < 0) { rpc->fault(c, 500, "Failed to build headers block"); goto error; } /* proceed to transaction creation */ memset(&dlg, 0, sizeof(dlg_t)); /* fill call-id if call-id present or else generate a callid */ - if (callid.s && callid.len) dlg.id.call_id=callid; - else generate_callid(&dlg.id.call_id); + if(callid.s && callid.len) + dlg.id.call_id = callid; + else + generate_callid(&dlg.id.call_id); /* We will not fill in dlg->id.rem_tag because * if present it will be printed within To HF */ /* Generate fromtag if not present */ - if (fromtag.s && fromtag.len) { + if(fromtag.s && fromtag.len) { dlg.id.loc_tag = fromtag; } else { generate_fromtag(&dlg.id.loc_tag, &dlg.id.call_id, &ruri); } /* Fill in CSeq */ - if (cseq_is) dlg.loc_seq.value = cseq; - else dlg.loc_seq.value = DEFAULT_CSEQ; + if(cseq_is) + dlg.loc_seq.value = cseq; + else + dlg.loc_seq.value = DEFAULT_CSEQ; dlg.loc_seq.is_set = 1; dlg.loc_uri = get_from(&faked_msg)->uri; @@ -753,27 +767,28 @@ static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) } dlg.rem_target = ruri; dlg.dst_uri = nexthop; - dlg.send_sock=ssock; + dlg.send_sock = ssock; memset(&uac_req, 0, sizeof(uac_req)); - uac_req.method=&method; - if(hfb.s!=NULL && hfb.len>0) uac_req.headers=&hfb; - uac_req.body=body.len?&body:0; - uac_req.dialog=&dlg; - if (reply_wait==1){ - dctx=rpc->delayed_ctx_new(c); - if (dctx==0){ + uac_req.method = &method; + if(hfb.s != NULL && hfb.len > 0) + uac_req.headers = &hfb; + uac_req.body = body.len ? &body : 0; + uac_req.dialog = &dlg; + if(reply_wait == 1) { + dctx = rpc->delayed_ctx_new(c); + if(dctx == 0) { rpc->fault(c, 500, "internal error: failed to create context"); return; } - uac_req.cb=rpc_uac_callback; - uac_req.cbp=dctx; - uac_req.cb_flags=TMCB_LOCAL_COMPLETED; + uac_req.cb = rpc_uac_callback; + uac_req.cbp = dctx; + uac_req.cb_flags = TMCB_LOCAL_COMPLETED; /* switch to dctx, in case adding the callback fails and we want to still send a reply */ - rpc=&dctx->rpc; - c=dctx->reply_ctx; - } else if (reply_wait==2) { + rpc = &dctx->rpc; + c = dctx->reply_ctx; + } else if(reply_wait == 2) { sruid_next(&_tm_rpc_sruid); uac_req.cb = rpc_uac_block_callback; ruid = shm_str_dup_block(&_tm_rpc_sruid.uid); @@ -783,15 +798,15 @@ static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) ret = t_uac(&uac_req); - if (ret <= 0) { - err_ret = err2reason_phrase(ret, &sip_error, err_buf, - sizeof(err_buf), "RPC/UAC") ; - if (err_ret > 0 ) { + if(ret <= 0) { + err_ret = err2reason_phrase( + ret, &sip_error, err_buf, sizeof(err_buf), "RPC/UAC"); + if(err_ret > 0) { rpc->fault(c, sip_error, "%s", err_buf); } else { rpc->fault(c, 500, "RPC/UAC error"); } - if (dctx) { + if(dctx) { rpc->delayed_ctx_close(dctx); } if(ruid) { @@ -800,8 +815,8 @@ static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) goto error01; } - if(reply_wait==2) { - while(ritem==NULL && rcount<800) { + if(reply_wait == 2) { + while(ritem == NULL && rcount < 800) { sleep_us(100000); rcount++; ritem = tm_rpc_response_list_get(&_tm_rpc_sruid.uid); @@ -810,12 +825,12 @@ static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) rpc->fault(c, 500, "No response"); } else { /* add structure node */ - if (rpc->add(c, "{", &th) < 0) { + if(rpc->add(c, "{", &th) < 0) { rpc->fault(c, 500, "Structure error"); } else { - if(rpc->struct_add(th, "dS", - "code", ritem->rcode, - "text", &ritem->rtext)<0) { + if(rpc->struct_add(th, "dS", "code", ritem->rcode, "text", + &ritem->rtext) + < 0) { rpc->fault(c, 500, "Fields error"); return; } @@ -825,16 +840,18 @@ static void rpc_t_uac(rpc_t* rpc, void* c, int reply_wait) } error01: - if (hfb.s) pkg_free(hfb.s); + if(hfb.s) + pkg_free(hfb.s); error: - if (faked_msg.headers) free_hdr_field_lst(faked_msg.headers); + if(faked_msg.headers) + free_hdr_field_lst(faked_msg.headers); } /** t_uac with no reply waiting. * @see rpc_t_uac. */ -void rpc_t_uac_start(rpc_t* rpc, void* c) +void rpc_t_uac_start(rpc_t *rpc, void *c) { rpc_t_uac(rpc, c, 0); } @@ -842,7 +859,7 @@ void rpc_t_uac_start(rpc_t* rpc, void* c) /** t_uac with reply waiting. * @see rpc_t_uac. */ -void rpc_t_uac_wait(rpc_t* rpc, void* c) +void rpc_t_uac_wait(rpc_t *rpc, void *c) { rpc_t_uac(rpc, c, 1); } @@ -850,49 +867,47 @@ void rpc_t_uac_wait(rpc_t* rpc, void* c) /** t_uac with blocking for reply waiting. * @see rpc_t_uac. */ -void rpc_t_uac_wait_block(rpc_t* rpc, void* c) +void rpc_t_uac_wait_block(rpc_t *rpc, void *c) { rpc_t_uac(rpc, c, 2); } -static int t_uac_check_msg(struct sip_msg* msg, - str* method, str* body, - str *fromtag, int *cseq_is, int* cseq, - str* callid) +static int t_uac_check_msg(struct sip_msg *msg, str *method, str *body, + str *fromtag, int *cseq_is, int *cseq, str *callid) { - struct to_body* parsed_from; + struct to_body *parsed_from; struct cseq_body *parsed_cseq; int i; char ch; - if (body->len && !msg->content_type) { + if(body->len && !msg->content_type) { LM_ERR("Content-Type missing\n"); goto err; } - if (body->len && msg->content_length) { + if(body->len && msg->content_length) { LM_ERR("Content-Length disallowed\n"); goto err; } - if (!msg->to) { + if(!msg->to) { LM_ERR("To missing\n"); goto err; } - if (!msg->from) { + if(!msg->from) { LM_ERR("From missing\n"); goto err; } /* we also need to know if there is from-tag and add it otherwise */ - if (parse_from_header(msg) < 0) { + if(parse_from_header(msg) < 0) { LM_ERR("Error in From\n"); goto err; } - parsed_from = (struct to_body*)msg->from->parsed; + parsed_from = (struct to_body *)msg->from->parsed; if(parsed_from->tag_value.s && parsed_from->tag_value.len) { fromtag->s = parsed_from->tag_value.s; fromtag->len = parsed_from->tag_value.len; @@ -902,11 +917,11 @@ static int t_uac_check_msg(struct sip_msg* msg, } *cseq = 0; - if (msg->cseq && (parsed_cseq = get_cseq(msg))) { + if(msg->cseq && (parsed_cseq = get_cseq(msg))) { *cseq_is = 1; - for (i = 0; i < parsed_cseq->number.len; i++) { + for(i = 0; i < parsed_cseq->number.len; i++) { ch = parsed_cseq->number.s[i]; - if (ch >= '0' && ch <= '9' ) { + if(ch >= '0' && ch <= '9') { *cseq = (*cseq) * 10 + ch - '0'; } else { DBG("check_msg: Found non-numerical in CSeq: <%i>='%c'\n", @@ -916,8 +931,8 @@ static int t_uac_check_msg(struct sip_msg* msg, } } - if (parsed_cseq->method.len != method->len || - memcmp(parsed_cseq->method.s, method->s, method->len) !=0 ) { + if(parsed_cseq->method.len != method->len + || memcmp(parsed_cseq->method.s, method->s, method->len) != 0) { LM_ERR("CSeq method mismatch\n"); goto err; } @@ -925,7 +940,7 @@ static int t_uac_check_msg(struct sip_msg* msg, *cseq_is = 0; } - if (msg->callid) { + if(msg->callid) { callid->s = msg->callid->body.s; callid->len = msg->callid->body.len; } else { @@ -944,7 +959,7 @@ int t_uac_send(str *method, str *ruri, str *nexthop, str *send_socket, str hfb, callid; struct sip_uri p_uri, pnexthop; struct sip_msg faked_msg; - struct socket_info* ssock; + struct socket_info *ssock; str saddr; int sport, sproto; int ret, cseq_is, cseq; @@ -955,81 +970,89 @@ int t_uac_send(str *method, str *ruri, str *nexthop, str *send_socket, ret = -1; /* check and parse parameters */ - if (method->len<=0){ + if(method->len <= 0) { LM_ERR("Empty method\n"); return -1; } - if (parse_uri(ruri->s, ruri->len, &p_uri)<0){ + if(parse_uri(ruri->s, ruri->len, &p_uri) < 0) { LM_ERR("Invalid request uri \"%s\"", ruri->s); return -1; } - if (nexthop->len==1 && nexthop->s[0]=='.'){ + if(nexthop->len == 1 && nexthop->s[0] == '.') { /* empty nextop */ - nexthop->len=0; - nexthop->s=0; - }else if (nexthop->len==0){ - nexthop->s=0; - }else if (parse_uri(nexthop->s, nexthop->len, &pnexthop)<0){ + nexthop->len = 0; + nexthop->s = 0; + } else if(nexthop->len == 0) { + nexthop->s = 0; + } else if(parse_uri(nexthop->s, nexthop->len, &pnexthop) < 0) { LM_ERR("Invalid next-hop uri \"%s\"", nexthop->s); return -1; } - ssock=0; - saddr.s=0; - saddr.len=0; - if (send_socket->len==1 && send_socket->s[0]=='.'){ + ssock = 0; + saddr.s = 0; + saddr.len = 0; + if(send_socket->len == 1 && send_socket->s[0] == '.') { /* empty send socket */ - send_socket->len=0; - }else if (send_socket->len && - (parse_phostport(send_socket->s, &saddr.s, &saddr.len, - &sport, &sproto)!=0 || - /* check also if it's not a MH addr. */ - saddr.len==0 || saddr.s[0]=='(') - ){ + send_socket->len = 0; + } else if(send_socket->len + && (parse_phostport( + send_socket->s, &saddr.s, &saddr.len, &sport, &sproto) + != 0 + || + /* check also if it's not a MH addr. */ + saddr.len == 0 || saddr.s[0] == '(')) { LM_ERR("Invalid send socket \"%s\"", send_socket->s); return -1; - }else if (saddr.len && (ssock=grep_sock_info(&saddr, sport, sproto))==0){ + } else if(saddr.len + && (ssock = grep_sock_info(&saddr, sport, sproto)) == 0) { LM_ERR("No local socket for \"%s\"", send_socket->s); return -1; } /* check headers using the SIP parser to look in the header list */ memset(&faked_msg, 0, sizeof(struct sip_msg)); - faked_msg.len=headers->len; - faked_msg.buf=faked_msg.unparsed=headers->s; - if (parse_headers(&faked_msg, HDR_EOH_F, 0)==-1){ + faked_msg.len = headers->len; + faked_msg.buf = faked_msg.unparsed = headers->s; + if(parse_headers(&faked_msg, HDR_EOH_F, 0) == -1) { LM_ERR("Invalid headers\n"); return -1; } /* at this moment all the parameters are parsed => more sanity checks */ - if (t_uac_check_msg(&faked_msg, method, body, &fromtag, - &cseq_is, &cseq, &callid)<0) { + if(t_uac_check_msg( + &faked_msg, method, body, &fromtag, &cseq_is, &cseq, &callid) + < 0) { LM_ERR("checking values failed\n"); goto error; } - if(get_hfblock(nexthop->len? nexthop: ruri, faked_msg.headers, - PROTO_NONE, ssock, &hfb)<0) { + if(get_hfblock(nexthop->len ? nexthop : ruri, faked_msg.headers, PROTO_NONE, + ssock, &hfb) + < 0) { LM_ERR("failed to get the block of headers\n"); goto error; } /* proceed to transaction creation */ memset(&dlg, 0, sizeof(dlg_t)); /* fill call-id if call-id present or else generate a callid */ - if (callid.s && callid.len) dlg.id.call_id=callid; - else generate_callid(&dlg.id.call_id); + if(callid.s && callid.len) + dlg.id.call_id = callid; + else + generate_callid(&dlg.id.call_id); /* We will not fill in dlg->id.rem_tag because * if present it will be printed within To HF */ /* Generate fromtag if not present */ - if (fromtag.s && fromtag.len) { + if(fromtag.s && fromtag.len) { dlg.id.loc_tag = fromtag; } else { generate_fromtag(&dlg.id.loc_tag, &dlg.id.call_id, ruri); } /* Fill in CSeq */ - if (cseq_is) dlg.loc_seq.value = cseq; - else dlg.loc_seq.value = DEFAULT_CSEQ; + if(cseq_is) + dlg.loc_seq.value = cseq; + else + dlg.loc_seq.value = DEFAULT_CSEQ; dlg.loc_seq.is_set = 1; dlg.loc_uri = get_from(&faked_msg)->uri; @@ -1039,24 +1062,27 @@ int t_uac_send(str *method, str *ruri, str *nexthop, str *send_socket, } dlg.rem_target = *ruri; dlg.dst_uri = *nexthop; - dlg.send_sock=ssock; + dlg.send_sock = ssock; memset(&uac_req, 0, sizeof(uac_req)); - uac_req.method=method; - if(hfb.s!=NULL && hfb.len>0) uac_req.headers=&hfb; - uac_req.body=body->len?body:0; - uac_req.dialog=&dlg; + uac_req.method = method; + if(hfb.s != NULL && hfb.len > 0) + uac_req.headers = &hfb; + uac_req.body = body->len ? body : 0; + uac_req.dialog = &dlg; ret = t_uac(&uac_req); - if (ret <= 0) { + if(ret <= 0) { LM_ERR("UAC error\n"); goto error01; } error01: - if (hfb.s) pkg_free(hfb.s); + if(hfb.s) + pkg_free(hfb.s); error: - if (faked_msg.headers) free_hdr_field_lst(faked_msg.headers); + if(faked_msg.headers) + free_hdr_field_lst(faked_msg.headers); return ret; } diff --git a/src/modules/tm/rpc_uac.h b/src/modules/tm/rpc_uac.h index 7cea70ab6cc..dccd69cb30d 100644 --- a/src/modules/tm/rpc_uac.h +++ b/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); diff --git a/src/modules/tm/select.c b/src/modules/tm/select.c index 9b448bb1b75..433124dadc9 100644 --- a/src/modules/tm/select.c +++ b/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() { diff --git a/src/modules/tm/t_append_branches.c b/src/modules/tm/t_append_branches.c index 203f67a36a3..47e05809ae1 100644 --- a/src/modules/tm/t_append_branches.c +++ b/src/modules/tm/t_append_branches.c @@ -57,7 +57,8 @@ * * If the contact parameter is given, it must be of syntax: * sip:@: (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( ¤t_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(¤t_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; iuac[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, ¤t_uri, - (dst_uri.len) ? (&dst_uri) : ¤t_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, ¤t_uri, + (dst_uri.len) ? (&dst_uri) : ¤t_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<= 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; inr_of_outgoings; i++) { - if (added_branches & (1<=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<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 @@ int t_append_branches(str * contact) { /* 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); } diff --git a/src/modules/tm/t_append_branches.h b/src/modules/tm/t_append_branches.h index 1baec4acd0d..4e71f5862e2 100644 --- a/src/modules/tm/t_append_branches.h +++ b/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 diff --git a/src/modules/tm/t_cancel.c b/src/modules/tm/t_cancel.c index 67bcc4c9144..18452a46967 100644 --- a/src/modules/tm/t_cancel.c +++ b/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 ; icancel_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 ; inr_of_outgoings ; i++ ) - if (cancel_data->cancel_bitmap & (1<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)<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; } /* */ - 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; } /* */ - 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, /* */ 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); /* */ /* */ - 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*/; /* */ /* */ 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); } /* */ diff --git a/src/modules/tm/t_cancel.h b/src/modules/tm/t_cancel.h index 1ab9bbfa39b..07c82693c9b 100644 --- a/src/modules/tm/t_cancel.h +++ b/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 diff --git a/src/modules/tm/t_fifo.c b/src/modules/tm/t_fifo.c index 8b71fcc74ac..a732407c8aa 100644 --- a/src/modules/tm/t_fifo.c +++ b/src/modules/tm/t_fifo.c @@ -62,47 +62,54 @@ /* solaris doesn't have SUN_LEN */ #ifndef SUN_LEN -#define SUN_LEN(sa) ( strlen((sa)->sun_path) + \ - (size_t)(((struct sockaddr_un*)0)->sun_path) ) +#define SUN_LEN(sa) \ + (strlen((sa)->sun_path) + (size_t)(((struct sockaddr_un *)0)->sun_path)) #endif -#define TWRITE_PARAMS 20 -#define TWRITE_VERSION_S "0.3" -#define TWRITE_VERSION_LEN (sizeof(TWRITE_VERSION_S)-1) - -#define eol_line_s(_i_) ( iov_lines_eol[2*(_i_)].iov_base ) -#define eol_line_len(_i_) ( iov_lines_eol[2*(_i_)].iov_len ) - -#define eol_line(_i_,_s_) { eol_line_s(_i_) = (_s_).s; \ - eol_line_len(_i_) = (_s_).len; } - -#define IDBUF_LEN 128 -#define ROUTE_BUFFER_MAX 512 -#define APPEND_BUFFER_MAX 4096 -#define CMD_BUFFER_MAX 128 - -#define copy_route(s,len,rs,rlen) \ - do {\ - if(rlen+len+3 >= ROUTE_BUFFER_MAX){\ - LM_ERR("buffer overflow while copying new route\n");\ - goto error;\ - }\ - if(len){\ - append_chr(s,','); len++;\ - }\ - append_chr(s,'<');len++;\ - append_str(s,rs,rlen);\ - len += rlen; \ - append_chr(s,'>');len++;\ +#define TWRITE_PARAMS 20 +#define TWRITE_VERSION_S "0.3" +#define TWRITE_VERSION_LEN (sizeof(TWRITE_VERSION_S) - 1) + +#define eol_line_s(_i_) (iov_lines_eol[2 * (_i_)].iov_base) +#define eol_line_len(_i_) (iov_lines_eol[2 * (_i_)].iov_len) + +#define eol_line(_i_, _s_) \ + { \ + eol_line_s(_i_) = (_s_).s; \ + eol_line_len(_i_) = (_s_).len; \ + } + +#define IDBUF_LEN 128 +#define ROUTE_BUFFER_MAX 512 +#define APPEND_BUFFER_MAX 4096 +#define CMD_BUFFER_MAX 128 + +#define copy_route(s, len, rs, rlen) \ + do { \ + if(rlen + len + 3 >= ROUTE_BUFFER_MAX) { \ + LM_ERR("buffer overflow while copying new route\n"); \ + goto error; \ + } \ + if(len) { \ + append_chr(s, ','); \ + len++; \ + } \ + append_chr(s, '<'); \ + len++; \ + append_str(s, rs, rlen); \ + len += rlen; \ + append_chr(s, '>'); \ + len++; \ } while(0) -static struct iovec iov_lines_eol[2*TWRITE_PARAMS]; -static struct iovec eol={"\n",1}; +static struct iovec iov_lines_eol[2 * TWRITE_PARAMS]; +static struct iovec eol = {"\n", 1}; static int sock; -struct hdr_avp { +struct hdr_avp +{ str title; int type; str sval; @@ -110,49 +117,50 @@ struct hdr_avp { struct hdr_avp *next; }; -struct tw_append { +struct tw_append +{ str name; int add_body; struct hdr_avp *elems; struct tw_append *next; }; -struct tw_info { +struct tw_info +{ str action; struct tw_append *append; }; -#define ELEM_TYPE_AVP "avp" -#define ELEM_TYPE_AVP_LEN (sizeof(ELEM_TYPE_AVP)-1) -#define ELEM_TYPE_HDR "hdr" -#define ELEM_TYPE_HDR_LEN (sizeof(ELEM_TYPE_HDR)-1) -#define ELEM_TYPE_MSG "msg" -#define ELEM_TYPE_MSG_LEN (sizeof(ELEM_TYPE_MSG)-1) -#define ELEM_IS_AVP (1<<0) -#define ELEM_IS_HDR (1<<1) -#define ELEM_IS_MSG (1<<2) +#define ELEM_TYPE_AVP "avp" +#define ELEM_TYPE_AVP_LEN (sizeof(ELEM_TYPE_AVP) - 1) +#define ELEM_TYPE_HDR "hdr" +#define ELEM_TYPE_HDR_LEN (sizeof(ELEM_TYPE_HDR) - 1) +#define ELEM_TYPE_MSG "msg" +#define ELEM_TYPE_MSG_LEN (sizeof(ELEM_TYPE_MSG) - 1) +#define ELEM_IS_AVP (1 << 0) +#define ELEM_IS_HDR (1 << 1) +#define ELEM_IS_MSG (1 << 2) -#define ELEM_VAL_BODY "body" -#define ELEM_VAL_BODY_LEN (sizeof(ELEM_VAL_BODY)-1) +#define ELEM_VAL_BODY "body" +#define ELEM_VAL_BODY_LEN (sizeof(ELEM_VAL_BODY) - 1) static struct tw_append *tw_appends; -static void print_tw_append( struct tw_append *append) +static void print_tw_append(struct tw_append *append) { struct hdr_avp *ha; - if (!append) + if(!append) return; - LM_DBG("tw_append name=<%.*s>\n", - append->name.len,append->name.s); - for( ha=append->elems ; ha ; ha=ha->next ) { - LM_DBG("\ttitle=<%.*s>\n",ha->title.len,ha->title.s); - LM_DBG("\t\tttype=<%d>\n",ha->type); - LM_DBG("\t\tsval=<%.*s>\n",ha->sval.len,ha->sval.s); - LM_DBG("\t\tival=<%d>\n",ha->ival); + LM_DBG("tw_append name=<%.*s>\n", append->name.len, append->name.s); + for(ha = append->elems; ha; ha = ha->next) { + LM_DBG("\ttitle=<%.*s>\n", ha->title.len, ha->title.s); + LM_DBG("\t\tttype=<%d>\n", ha->type); + LM_DBG("\t\tsval=<%.*s>\n", ha->sval.len, ha->sval.s); + LM_DBG("\t\tival=<%d>\n", ha->ival); } } @@ -161,11 +169,11 @@ static void print_tw_append( struct tw_append *append) * tw_append = name:element[;element] * element = [title=]value * value = avp[avp_spec] | hdr[hdr_name] | msg[body] */ -int parse_tw_append( modparam_t type, void* val) +int parse_tw_append(modparam_t type, void *val) { struct hdr_field hdr; struct hdr_avp *last; - struct hdr_avp *ha=NULL; + struct hdr_avp *ha = NULL; struct tw_append *app; int_str avp_name; char *s; @@ -174,48 +182,53 @@ int parse_tw_append( modparam_t type, void* val) int n; int index; - if (val==0 || ((char*)val)[0]==0) + if(val == 0 || ((char *)val)[0] == 0) return 0; - s = (char*)val; + s = (char *)val; /* start parsing - first the name */ - while( *s && isspace((int)*s) ) s++; - if ( !*s || *s==':') + while(*s && isspace((int)*s)) + s++; + if(!*s || *s == ':') goto parse_error; foo.s = s; - while ( *s && *s!=':' && !isspace((int)*s) ) s++; - if ( !*s || foo.s==s ) + while(*s && *s != ':' && !isspace((int)*s)) + s++; + if(!*s || foo.s == s) goto parse_error; foo.len = s - foo.s; /* parse separator */ - while( *s && isspace((int)*s) ) s++; - if ( !*s || *s!=':') + while(*s && isspace((int)*s)) + s++; + if(!*s || *s != ':') goto parse_error; s++; - while( *s && isspace((int)*s) ) s++; - if ( !*s ) + while(*s && isspace((int)*s)) + s++; + if(!*s) goto parse_error; /* check for name duplication */ - for(app=tw_appends;app;app=app->next) - if (app->name.len==foo.len && !strncasecmp(app->name.s,foo.s,foo.len)){ - LM_ERR("duplicated tw_append name <%.*s>\n",foo.len,foo.s); + for(app = tw_appends; app; app = app->next) + if(app->name.len == foo.len + && !strncasecmp(app->name.s, foo.s, foo.len)) { + LM_ERR("duplicated tw_append name <%.*s>\n", foo.len, foo.s); goto error; } /* new tw_append structure */ - app = (struct tw_append*)pkg_malloc( sizeof(struct tw_append) ); - if (app==0) { + app = (struct tw_append *)pkg_malloc(sizeof(struct tw_append)); + if(app == 0) { PKG_MEM_ERROR; goto error; } - app->name.s = (char*)pkg_malloc( foo.len+1 ); - if (app->name.s==0) { + app->name.s = (char *)pkg_malloc(foo.len + 1); + if(app->name.s == 0) { PKG_MEM_ERROR; pkg_free(app); goto error; } - memcpy( app->name.s, foo.s, foo.len); + memcpy(app->name.s, foo.s, foo.len); app->name.len = foo.len; app->name.s[app->name.len] = 0; last = app->elems = 0; @@ -223,55 +236,59 @@ int parse_tw_append( modparam_t type, void* val) tw_appends = app; /* parse the elements */ - while (*s) { + while(*s) { /* parse element title or element type */ foo.s = s; - while( *s && *s!='[' && *s!='=' && *s!=';' && !isspace((int)*s) ) s++; - if ( !*s || foo.s==s) + while(*s && *s != '[' && *s != '=' && *s != ';' && !isspace((int)*s)) + s++; + if(!*s || foo.s == s) goto parse_error; foo.len = s - foo.s; /* new hdr_avp structure */ - ha = (struct hdr_avp*)pkg_malloc( sizeof(struct hdr_avp) ); - if (ha==0) { + ha = (struct hdr_avp *)pkg_malloc(sizeof(struct hdr_avp)); + if(ha == 0) { PKG_MEM_ERROR; goto error; } - memset( ha, 0, sizeof(struct hdr_avp)); - if (*s!='[') { + memset(ha, 0, sizeof(struct hdr_avp)); + if(*s != '[') { /* foo must by title or some error -> parse separator */ - while( *s && isspace((int)*s) ) s++; - if ( !*s || *s!='=') + while(*s && isspace((int)*s)) + s++; + if(!*s || *s != '=') goto parse_error; s++; - while( *s && isspace((int)*s) ) s++; - if ( !*s ) + while(*s && isspace((int)*s)) + s++; + if(!*s) goto parse_error; /* set the title */ - ha->title.s = (char*)pkg_malloc( foo.len+1 ); - if (ha->title.s==0) { + ha->title.s = (char *)pkg_malloc(foo.len + 1); + if(ha->title.s == 0) { PKG_MEM_ERROR; goto error; } - memcpy( ha->title.s, foo.s, foo.len); + memcpy(ha->title.s, foo.s, foo.len); ha->title.len = foo.len; ha->title.s[ha->title.len] = 0; /* parse the type now */ foo.s = s; - while( *s && *s!='[' && *s!=']' && *s!=';' && !isspace((int)*s) ) + while(*s && *s != '[' && *s != ']' && *s != ';' + && !isspace((int)*s)) s++; - if ( *s!='[' || foo.s==s) + if(*s != '[' || foo.s == s) goto parse_error; foo.len = s - foo.s; } /* foo containes the elemet type */ - if ( foo.len==ELEM_TYPE_AVP_LEN && - !strncasecmp( foo.s, ELEM_TYPE_AVP, foo.len) ) { + if(foo.len == ELEM_TYPE_AVP_LEN + && !strncasecmp(foo.s, ELEM_TYPE_AVP, foo.len)) { ha->type = ELEM_IS_AVP; - } else if ( foo.len==ELEM_TYPE_HDR_LEN && - !strncasecmp( foo.s, ELEM_TYPE_HDR, foo.len) ) { + } else if(foo.len == ELEM_TYPE_HDR_LEN + && !strncasecmp(foo.s, ELEM_TYPE_HDR, foo.len)) { ha->type = ELEM_IS_HDR; - } else if ( foo.len==ELEM_TYPE_MSG_LEN && - !strncasecmp( foo.s, ELEM_TYPE_MSG, foo.len) ) { + } else if(foo.len == ELEM_TYPE_MSG_LEN + && !strncasecmp(foo.s, ELEM_TYPE_MSG, foo.len)) { ha->type = ELEM_IS_MSG; } else { LM_ERR("unknown type <%.*s>\n", foo.len, foo.s); @@ -280,96 +297,100 @@ int parse_tw_append( modparam_t type, void* val) /* parse the element name */ s++; foo.s = s; - while( *s && *s!=']' && *s!=';' && !isspace((int)*s) ) s++; - if ( *s!=']' || foo.s==s ) + while(*s && *s != ']' && *s != ';' && !isspace((int)*s)) + s++; + if(*s != ']' || foo.s == s) goto parse_error; foo.len = s - foo.s; s++; /* process and optimize the element name */ - if (ha->type==ELEM_IS_AVP) { + if(ha->type == ELEM_IS_AVP) { /* element is AVP */ - if ( parse_avp_spec( &foo, &n, &avp_name, &index)!=0 ) { - LM_ERR("bad alias spec <%.*s>\n",foo.len, foo.s); + if(parse_avp_spec(&foo, &n, &avp_name, &index) != 0) { + LM_ERR("bad alias spec <%.*s>\n", foo.len, foo.s); goto error; } - if (n&AVP_NAME_STR) { + if(n & AVP_NAME_STR) { /* string name */ - ha->sval.s = (char*)pkg_malloc(avp_name.s.len+1); - if (ha->sval.s==0) { + ha->sval.s = (char *)pkg_malloc(avp_name.s.len + 1); + if(ha->sval.s == 0) { PKG_MEM_ERROR; goto error; } - memcpy( ha->sval.s, avp_name.s.s, avp_name.s.len); + memcpy(ha->sval.s, avp_name.s.s, avp_name.s.len); ha->sval.len = avp_name.s.len; ha->sval.s[ha->sval.len] = 0; - if (ha->title.s==0) + if(ha->title.s == 0) ha->title = ha->sval; } else { /* ID name - if title is missing, convert the ID to * string and us it a title */ ha->ival = avp_name.n; - if (ha->title.s==0) { - foo.s=int2str((unsigned long)ha->ival, &foo.len); - ha->title.s = (char*)pkg_malloc( n+1 ); - if (ha->title.s==0) { + if(ha->title.s == 0) { + foo.s = int2str((unsigned long)ha->ival, &foo.len); + ha->title.s = (char *)pkg_malloc(n + 1); + if(ha->title.s == 0) { PKG_MEM_ERROR; goto error; } - memcpy( ha->title.s, foo.s, foo.len); + memcpy(ha->title.s, foo.s, foo.len); ha->title.len = foo.len; ha->title.s[ha->title.len] = 0; } } - } else if (ha->type==ELEM_IS_HDR) { + } else if(ha->type == ELEM_IS_HDR) { /* element is HDR - try to get it's coded type if defined */ bar = foo.s[foo.len]; foo.s[foo.len] = ':'; /* parse header name */ - if (parse_hname2( foo.s, foo.s+foo.len+1, &hdr)==0) { + if(parse_hname2(foo.s, foo.s + foo.len + 1, &hdr) == 0) { LM_ERR("BUG: parse header failed\n"); goto error; } foo.s[foo.len] = bar; ha->ival = hdr.type; - if (hdr.type==HDR_OTHER_T || ha->title.s==0) { + if(hdr.type == HDR_OTHER_T || ha->title.s == 0) { /* duplicate hdr name */ - ha->sval.s = (char*)pkg_malloc(foo.len+1); - if (ha->sval.s==0) { + ha->sval.s = (char *)pkg_malloc(foo.len + 1); + if(ha->sval.s == 0) { PKG_MEM_ERROR; goto error; } - memcpy( ha->sval.s, foo.s, foo.len); + memcpy(ha->sval.s, foo.s, foo.len); ha->sval.len = foo.len; ha->sval.s[ha->sval.len] = 0; - if (ha->title.s==0) + if(ha->title.s == 0) ha->title = ha->sval; } } else { /* element is MSG */ - if ( !(foo.len==ELEM_VAL_BODY_LEN && - !strncasecmp(ELEM_VAL_BODY,foo.s,foo.len)) ) { - LM_ERR("unsupported value <%.*s> for msg type\n",foo.len,foo.s); + if(!(foo.len == ELEM_VAL_BODY_LEN + && !strncasecmp(ELEM_VAL_BODY, foo.s, foo.len))) { + LM_ERR("unsupported value <%.*s> for msg type\n", foo.len, + foo.s); goto error; } app->add_body = 1; - pkg_free( ha ); + pkg_free(ha); ha = 0; } /* parse the element separator, if present */ - while( *s && isspace((int)*s) ) s++; - if ( *s && *s!=';') + while(*s && isspace((int)*s)) + s++; + if(*s && *s != ';') goto parse_error; - if (*s==';') { + if(*s == ';') { s++; - while( *s && isspace((int)*s) ) s++; - if (!*s) + while(*s && isspace((int)*s)) + s++; + if(!*s) goto parse_error; } /* link the element to tw_append structure */ - if (ha) { - if (last==0) { + if(ha) { + if(last == 0) { last = app->elems = ha; } else { last->next = ha; @@ -380,67 +401,68 @@ int parse_tw_append( modparam_t type, void* val) } /* end while */ - print_tw_append( app ); + print_tw_append(app); /* free the old string */ pkg_free(val); return 0; parse_error: - LM_ERR("parse error in <%s> around position %ld\n", - (char*)val, (long)(s-(char*)val)); + LM_ERR("parse error in <%s> around position %ld\n", (char *)val, + (long)(s - (char *)val)); error: - if(ha) pkg_free(ha); + if(ha) + pkg_free(ha); return -1; } static struct tw_append *search_tw_append(char *name, int len) { - struct tw_append * app; + struct tw_append *app; - for( app=tw_appends ; app ; app=app->next ) - if (app->name.len==len && !strncasecmp(app->name.s,name,len) ) + for(app = tw_appends; app; app = app->next) + if(app->name.len == len && !strncasecmp(app->name.s, name, len)) return app; return 0; } -int fixup_t_write( void** param, int param_no) +int fixup_t_write(void **param, int param_no) { struct tw_info *twi; char *s; - if (param_no==2) { - twi = (struct tw_info*)pkg_malloc( sizeof(struct tw_info) ); - if (twi==0) { + if(param_no == 2) { + twi = (struct tw_info *)pkg_malloc(sizeof(struct tw_info)); + if(twi == 0) { PKG_MEM_ERROR; return E_OUT_OF_MEM; } - memset( twi, 0 , sizeof(struct tw_info)); - s = (char*)*param; + memset(twi, 0, sizeof(struct tw_info)); + s = (char *)*param; twi->action.s = s; - if ( (s=strchr(s,'/'))!=0) { + if((s = strchr(s, '/')) != 0) { twi->action.len = s - twi->action.s; - if (twi->action.len==0) { + if(twi->action.len == 0) { LM_ERR("empty action name\n"); pkg_free(twi); return E_CFG; } s++; - if (*s==0) { + if(*s == 0) { LM_ERR("empty append name\n"); pkg_free(twi); return E_CFG; } - twi->append = search_tw_append( s, strlen(s)); - if (twi->append==0) { - LM_ERR("unknown append name <%s>\n",s); + twi->append = search_tw_append(s, strlen(s)); + if(twi->append == 0) { + LM_ERR("unknown append name <%s>\n", s); pkg_free(twi); return E_CFG; } } else { twi->action.len = strlen(twi->action.s); } - *param=(void*)twi; + *param = (void *)twi; } return 0; @@ -452,20 +474,20 @@ int init_twrite_sock(void) int flags; sock = socket(PF_LOCAL, SOCK_DGRAM, 0); - if (sock == -1) { + if(sock == -1) { LM_ERR("unable to create socket: %s\n", strerror(errno)); return -1; } /* Turn non-blocking mode on */ flags = fcntl(sock, F_GETFL); - if (flags == -1){ + if(flags == -1) { LM_ERR("fcntl failed: %s\n", strerror(errno)); close(sock); return -1; } - if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) { + if(fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) { LM_ERR("fcntl: set non-blocking failed: %s\n", strerror(errno)); close(sock); return -1; @@ -479,30 +501,31 @@ int init_twrite_lines() int i; /* init the line table */ - for(i=0;i=end) + if(buf + title_len + value_len + 2 + 1 >= end) return 0; - memcpy( buf, title, title_len); + memcpy(buf, title, title_len); buf += title_len; *(buf++) = ':'; *(buf++) = ' '; - memcpy( buf, value, value_len); + memcpy(buf, value, value_len); buf += value_len; *(buf++) = '\n'; return buf; } -static inline char* append2buf( char *buf, int len, struct sip_msg *req, - struct hdr_avp *ha) +static inline char *append2buf( + char *buf, int len, struct sip_msg *req, struct hdr_avp *ha) { struct hdr_field *hdr; - struct usr_avp *avp; - int_str avp_val; - int_str avp_name; - char *end; - str foo; - int msg_parsed; - - end = buf+len; + struct usr_avp *avp; + int_str avp_val; + int_str avp_name; + char *end; + str foo; + int msg_parsed; + + end = buf + len; msg_parsed = 0; while(ha) { - if (ha->type==ELEM_IS_AVP) { + if(ha->type == ELEM_IS_AVP) { /* search for the AVP */ - if (ha->sval.s) { - avp_name.s=ha->sval; - avp = search_first_avp( AVP_NAME_STR, avp_name, &avp_val, 0); - LM_DBG("AVP <%.*s>: %p\n",avp_name.s.len, avp_name.s.s, avp); + if(ha->sval.s) { + avp_name.s = ha->sval; + avp = search_first_avp(AVP_NAME_STR, avp_name, &avp_val, 0); + LM_DBG("AVP <%.*s>: %p\n", avp_name.s.len, avp_name.s.s, avp); } else { - avp_name.n=ha->ival; - avp = search_first_avp( 0, avp_name, &avp_val, 0); - LM_DBG("AVP <%ld>: %p\n",avp_name.n,avp); + avp_name.n = ha->ival; + avp = search_first_avp(0, avp_name, &avp_val, 0); + LM_DBG("AVP <%ld>: %p\n", avp_name.n, avp); } - if (avp) { - if (avp->flags&AVP_VAL_STR) { - buf=add2buf( buf, end, ha->title.s, ha->title.len, - avp_val.s.s , avp_val.s.len); - if (!buf) + if(avp) { + if(avp->flags & AVP_VAL_STR) { + buf = add2buf(buf, end, ha->title.s, ha->title.len, + avp_val.s.s, avp_val.s.len); + if(!buf) goto overflow_err; } else { - foo.s=int2str( (unsigned long)avp_val.n, &foo.len); - buf=add2buf( buf, end, ha->title.s, ha->title.len, - foo.s , foo.len); - if (!buf) + foo.s = int2str((unsigned long)avp_val.n, &foo.len); + buf = add2buf(buf, end, ha->title.s, ha->title.len, foo.s, + foo.len); + if(!buf) goto overflow_err; } } - } else if (ha->type==ELEM_IS_HDR) { + } else if(ha->type == ELEM_IS_HDR) { /* parse the HDRs */ - if (!msg_parsed) { - if (parse_headers( req, HDR_EOH_F, 0)!=0) { + if(!msg_parsed) { + if(parse_headers(req, HDR_EOH_F, 0) != 0) { LM_ERR("parsing hdrs failed\n"); goto error; } msg_parsed = 1; } /* search the HDR */ - if (ha->ival==HDR_OTHER_T) { - for(hdr=req->headers;hdr;hdr=hdr->next) - if (ha->sval.len==hdr->name.len && - strncasecmp( ha->sval.s, hdr->name.s, hdr->name.len)==0) + if(ha->ival == HDR_OTHER_T) { + for(hdr = req->headers; hdr; hdr = hdr->next) + if(ha->sval.len == hdr->name.len + && strncasecmp( + ha->sval.s, hdr->name.s, hdr->name.len) + == 0) break; } else { - for(hdr=req->headers;hdr;hdr=hdr->next) - if (ha->ival==hdr->type) + for(hdr = req->headers; hdr; hdr = hdr->next) + if(ha->ival == hdr->type) break; } - if (hdr) { - trim_len( foo.len, foo.s, hdr->body); - buf=add2buf( buf, end, ha->title.s, ha->title.len, - foo.s , foo.len); - if (!buf) + if(hdr) { + trim_len(foo.len, foo.s, hdr->body); + buf = add2buf( + buf, end, ha->title.s, ha->title.len, foo.s, foo.len); + if(!buf) goto overflow_err; } } else { @@ -624,58 +649,59 @@ static inline char* append2buf( char *buf, int len, struct sip_msg *req, return buf; overflow_err: - LM_ERR("overflow -> append exceeded %d len\n",len); + LM_ERR("overflow -> append exceeded %d len\n", len); error: return 0; } -static int assemble_msg(struct sip_msg* msg, struct tw_info *twi) +static int assemble_msg(struct sip_msg *msg, struct tw_info *twi) { - static char id_buf[IDBUF_LEN]; - static char route_buffer[ROUTE_BUFFER_MAX]; - static char append_buf[APPEND_BUFFER_MAX]; - static char cmd_buf[CMD_BUFFER_MAX]; - static str empty_param = STR_STATIC_INIT("."); - unsigned int hash_index, label; - contact_body_t* cb=0; - contact_t* c=0; - name_addr_t na; - rr_t* record_route; - struct hdr_field* p_hdr; - param_hooks_t hooks; - int l; - char* s, fproxy_lr; - int first_rr; - str route, next_hop, append, tmp_s, body, str_uri; - - if(msg->first_line.type != SIP_REQUEST){ + static char id_buf[IDBUF_LEN]; + static char route_buffer[ROUTE_BUFFER_MAX]; + static char append_buf[APPEND_BUFFER_MAX]; + static char cmd_buf[CMD_BUFFER_MAX]; + static str empty_param = STR_STATIC_INIT("."); + unsigned int hash_index, label; + contact_body_t *cb = 0; + contact_t *c = 0; + name_addr_t na; + rr_t *record_route; + struct hdr_field *p_hdr; + param_hooks_t hooks; + int l; + char *s, fproxy_lr; + int first_rr; + str route, next_hop, append, tmp_s, body, str_uri; + + if(msg->first_line.type != SIP_REQUEST) { LM_ERR("called for something else thena SIP request\n"); goto error; } /* parse all -- we will need every header field for a UAS */ - if ( parse_headers(msg, HDR_EOH_F, 0)==-1) { + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { LM_ERR("parse_headers failed\n"); goto error; } /* find index and hash; (the transaction can be safely used due * to refcounting till script completes) */ - if( t_get_trans_ident(msg,&hash_index,&label) == -1 ) { + if(t_get_trans_ident(msg, &hash_index, &label) == -1) { LM_ERR("assemble_msg: t_get_trans_ident failed\n"); goto error; } /* parse from header */ - if (msg->from==0 || (msg->from->parsed==0 && parse_from_header(msg)==-1)) { + if(msg->from == 0 + || (msg->from->parsed == 0 && parse_from_header(msg) == -1)) { LM_ERR("while parsing header\n"); goto error; } /* parse the RURI (doesn't make any malloc) */ msg->parsed_uri_ok = 0; /* force parsing */ - if (parse_sip_msg_uri(msg)<0) { + if(parse_sip_msg_uri(msg) < 0) { LM_ERR("uri has not been parsed\n"); goto error; } @@ -684,15 +710,15 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi) str_uri.s = 0; str_uri.len = 0; if(msg->contact) { - if (msg->contact->parsed==0 && parse_contact(msg->contact)==-1) { + if(msg->contact->parsed == 0 && parse_contact(msg->contact) == -1) { LM_ERR("error while parsing 'Contact' header\n"); goto error; } - cb = (contact_body_t*)msg->contact->parsed; - if(cb && (c=cb->contacts)) { + cb = (contact_body_t *)msg->contact->parsed; + if(cb && (c = cb->contacts)) { str_uri = c->uri; - if (find_not_quoted(&str_uri,'<')) { - parse_nameaddr(&str_uri,&na); + if(find_not_quoted(&str_uri, '<')) { + parse_nameaddr(&str_uri, &na); str_uri = na.uri; } } @@ -704,83 +730,86 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi) str_uri = get_from(msg)->uri; /* parse Record-Route headers */ - route.s = s = route_buffer; route.len = 0; + route.s = s = route_buffer; + route.len = 0; fproxy_lr = 0; next_hop = empty_param; p_hdr = msg->record_route; if(p_hdr) { - if (p_hdr->parsed==0 && parse_rr(p_hdr)!=0 ) { + if(p_hdr->parsed == 0 && parse_rr(p_hdr) != 0) { LM_ERR("while parsing 'Record-Route' header\n"); goto error; } - record_route = (rr_t*)p_hdr->parsed; + record_route = (rr_t *)p_hdr->parsed; } else { record_route = 0; } first_rr = 1; - if( record_route ) { - if ( (tmp_s.s=find_not_quoted(&record_route->nameaddr.uri,';'))!=0 && - tmp_s.s+1!=record_route->nameaddr.uri.s+ - record_route->nameaddr.uri.len) { + if(record_route) { + if((tmp_s.s = find_not_quoted(&record_route->nameaddr.uri, ';')) != 0 + && tmp_s.s + 1 + != record_route->nameaddr.uri.s + + record_route->nameaddr.uri.len) { /* Parse all parameters */ - tmp_s.len = record_route->nameaddr.uri.len - (tmp_s.s- - record_route->nameaddr.uri.s); - if (parse_params( &tmp_s, CLASS_URI, &hooks, - &record_route->params) < 0) { + tmp_s.len = record_route->nameaddr.uri.len + - (tmp_s.s - record_route->nameaddr.uri.s); + if(parse_params(&tmp_s, CLASS_URI, &hooks, &record_route->params) + < 0) { LM_ERR("error while parsing record route uri params\n"); goto error; } fproxy_lr = (hooks.uri.lr != 0); LM_DBG("record_route->nameaddr.uri: %.*s\n", - record_route->nameaddr.uri.len,record_route->nameaddr.uri.s); - if(fproxy_lr){ + record_route->nameaddr.uri.len, + record_route->nameaddr.uri.s); + if(fproxy_lr) { first_rr = 0; LM_DBG("first proxy has loose routing.\n"); - copy_route(s,route.len,record_route->nameaddr.uri.s, - record_route->nameaddr.uri.len); + copy_route(s, route.len, record_route->nameaddr.uri.s, + record_route->nameaddr.uri.len); } } - for(;p_hdr;p_hdr = p_hdr->next) { + for(; p_hdr; p_hdr = p_hdr->next) { /* filter out non-RR hdr and empty hdrs */ - if( (p_hdr->type!=HDR_RECORDROUTE_T) || p_hdr->body.len==0) + if((p_hdr->type != HDR_RECORDROUTE_T) || p_hdr->body.len == 0) continue; - if(p_hdr->parsed==0 && parse_rr(p_hdr)!=0 ){ + if(p_hdr->parsed == 0 && parse_rr(p_hdr) != 0) { LM_ERR("while parsing 'Record-route' header\n"); goto error; } - for(record_route=p_hdr->parsed; record_route; - record_route=record_route->next){ + for(record_route = p_hdr->parsed; record_route; + record_route = record_route->next) { LM_DBG("record_route->nameaddr.uri: <%.*s>\n", record_route->nameaddr.uri.len, record_route->nameaddr.uri.s); - if (!first_rr) { - copy_route(s,route.len,record_route->nameaddr.uri.s, + if(!first_rr) { + copy_route(s, route.len, record_route->nameaddr.uri.s, record_route->nameaddr.uri.len); } - first_rr=0; + first_rr = 0; } } - if(!fproxy_lr){ - copy_route(s,route.len,str_uri.s,str_uri.len); - str_uri = ((rr_t*)msg->record_route->parsed)->nameaddr.uri; + if(!fproxy_lr) { + copy_route(s, route.len, str_uri.s, str_uri.len); + str_uri = ((rr_t *)msg->record_route->parsed)->nameaddr.uri; } else { - next_hop = ((rr_t*)msg->record_route->parsed)->nameaddr.uri; + next_hop = ((rr_t *)msg->record_route->parsed)->nameaddr.uri; } } - LM_DBG("calculated route: %.*s\n", route.len,route.len ? route.s : ""); - LM_DBG("next r-uri: %.*s\n", str_uri.len,str_uri.len ? str_uri.s : ""); + LM_DBG("calculated route: %.*s\n", route.len, route.len ? route.s : ""); + LM_DBG("next r-uri: %.*s\n", str_uri.len, str_uri.len ? str_uri.s : ""); - if ( REQ_LINE(msg).method_value==METHOD_INVITE || - REQ_LINE(msg).method_value==METHOD_INFO || - (twi->append && twi->append->add_body) ) { + if(REQ_LINE(msg).method_value == METHOD_INVITE + || REQ_LINE(msg).method_value == METHOD_INFO + || (twi->append && twi->append->add_body)) { /* get body */ - if( (body.s = get_body(msg)) == 0 ){ + if((body.s = get_body(msg)) == 0) { LM_ERR("get_body failed\n"); goto error; } @@ -791,79 +820,82 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi) /* additional headers */ append.s = s = append_buf; - if (sizeof(flag_t)*2+12+1 >= APPEND_BUFFER_MAX) { + if(sizeof(flag_t) * 2 + 12 + 1 >= APPEND_BUFFER_MAX) { LM_ERR("buffer overflow while copying optional header\n"); goto error; } - append_str(s,"P-MsgFlags: ",12); - l = APPEND_BUFFER_MAX - (12+1); /* include trailing `\n'*/ + append_str(s, "P-MsgFlags: ", 12); + l = APPEND_BUFFER_MAX - (12 + 1); /* include trailing `\n'*/ - if (int2reverse_hex(&s, &l, (int)msg->msg_flags) == -1) { + if(int2reverse_hex(&s, &l, (int)msg->msg_flags) == -1) { LM_ERR("buffer overflow while copying optional header\n"); goto error; } - append_chr(s,'\n'); + append_chr(s, '\n'); - if ( twi->append && ((s=append2buf( s, APPEND_BUFFER_MAX-(s-append.s), msg, - twi->append->elems))==0) ) + if(twi->append + && ((s = append2buf(s, APPEND_BUFFER_MAX - (s - append.s), msg, + twi->append->elems)) + == 0)) goto error; /* body separator */ - append_chr(s,'.'); - append.len = s-append.s; + append_chr(s, '.'); + append.len = s - append.s; eol_line_s(1) = s = cmd_buf; - if(twi->action.len+12 >= CMD_BUFFER_MAX){ + if(twi->action.len + 12 >= CMD_BUFFER_MAX) { LM_ERR("buffer overflow while copying command name\n"); goto error; } - append_str(s,"sip_request.",12); - append_str(s,twi->action.s, twi->action.len); - eol_line_len(1) = s - (char*)eol_line_s(1); + append_str(s, "sip_request.", 12); + append_str(s, twi->action.s, twi->action.len); + eol_line_len(1) = s - (char *)eol_line_s(1); - eol_line(2,REQ_LINE(msg).method); /* method type */ - eol_line(3,msg->parsed_uri.user); /* user from r-uri */ - eol_line(4,msg->parsed_uri.host); /* domain */ + eol_line(2, REQ_LINE(msg).method); /* method type */ + eol_line(3, msg->parsed_uri.user); /* user from r-uri */ + eol_line(4, msg->parsed_uri.host); /* domain */ - eol_line(5,msg->rcv.bind_address->address_str); /* dst ip */ + eol_line(5, msg->rcv.bind_address->address_str); /* dst ip */ - eol_line(6,msg->rcv.dst_port==SIP_PORT ? - empty_param : msg->rcv.bind_address->port_no_str); /* port */ + eol_line(6, msg->rcv.dst_port == SIP_PORT + ? empty_param + : msg->rcv.bind_address->port_no_str); /* port */ /* r_uri ('Contact:' for next requests) */ - eol_line(7,msg->first_line.u.request.uri); + eol_line(7, msg->first_line.u.request.uri); /* r_uri for subsequent requests */ - eol_line(8,str_uri.len?str_uri:empty_param); + eol_line(8, str_uri.len ? str_uri : empty_param); - eol_line(9,get_from(msg)->body); /* from */ - eol_line(10,msg->to->body); /* to */ - eol_line(11,msg->callid->body); /* callid */ - eol_line(12,get_from(msg)->tag_value); /* from tag */ - eol_line(13,get_to(msg)->tag_value); /* to tag */ - eol_line(14,get_cseq(msg)->number); /* cseq number */ + eol_line(9, get_from(msg)->body); /* from */ + eol_line(10, msg->to->body); /* to */ + eol_line(11, msg->callid->body); /* callid */ + eol_line(12, get_from(msg)->tag_value); /* from tag */ + eol_line(13, get_to(msg)->tag_value); /* to tag */ + eol_line(14, get_cseq(msg)->number); /* cseq number */ - eol_line_s(15)=id_buf; /* hash:label */ + eol_line_s(15) = id_buf; /* hash:label */ s = int2str(hash_index, &l); - if (l+1>=IDBUF_LEN) { + if(l + 1 >= IDBUF_LEN) { LM_ERR("too big hash\n"); goto error; } memcpy(id_buf, s, l); - id_buf[l]=':'; - eol_line_len(15)=l+1; + id_buf[l] = ':'; + eol_line_len(15) = l + 1; s = int2str(label, &l); - if (l+1+eol_line_len(15)>=IDBUF_LEN) { + if(l + 1 + eol_line_len(15) >= IDBUF_LEN) { LM_ERR("too big label\n"); goto error; } - memcpy(id_buf+eol_line_len(15), s, l); + memcpy(id_buf + eol_line_len(15), s, l); eol_line_len(15) += l; - eol_line(16, route.len ? route : empty_param ); - eol_line(17, next_hop ); - eol_line(18, append ); - eol_line(19, body ); + eol_line(16, route.len ? route : empty_param); + eol_line(17, next_hop); + eol_line(18, append); + eol_line(19, body); /* success */ return 1; @@ -874,21 +906,21 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi) } -static int write_to_unixsock(char* sockname, int cnt) +static int write_to_unixsock(char *sockname, int cnt) { int len, e; struct sockaddr_un dest; - if (!sockname) { + if(!sockname) { LM_ERR("Invalid parameter\n"); return E_UNSPEC; } len = strlen(sockname); - if (len == 0) { + if(len == 0) { LM_DBG("Error - empty socket name\n"); return -1; - } else if (len > 107) { + } else if(len > 107) { LM_ERR("Socket name too long\n"); return -1; } @@ -900,7 +932,7 @@ static int write_to_unixsock(char* sockname, int cnt) dest.sun_len = len; #endif - e = connect(sock, (struct sockaddr*)&dest, SUN_LEN(&dest)); + e = connect(sock, (struct sockaddr *)&dest, SUN_LEN(&dest)); #ifdef HAVE_CONNECT_ECONNRESET_BUG /* * Workaround for a nasty bug in BSD kernels dated back @@ -908,16 +940,17 @@ static int write_to_unixsock(char* sockname, int cnt) * BSD-derived kernels. Workaround should be pretty harmless since * in normal conditions connect(2) can never return ECONNRESET. */ - if ((e == -1) && (errno == ECONNRESET)) + if((e == -1) && (errno == ECONNRESET)) e = 0; #endif - if (e == -1) { + if(e == -1) { LM_ERR("error in connect: %s\n", strerror(errno)); return -1; } - if (tsend_dgram_ev(sock, iov_lines_eol, 2 * cnt, - cfg_get(tm, tm_cfg, tm_unix_tx_timeout)) < 0) { + if(tsend_dgram_ev(sock, iov_lines_eol, 2 * cnt, + cfg_get(tm, tm_cfg, tm_unix_tx_timeout)) + < 0) { LM_ERR("writev failed: %s\n", strerror(errno)); return -1; } @@ -926,21 +959,21 @@ static int write_to_unixsock(char* sockname, int cnt) } -int t_write_req(struct sip_msg* msg, char* vm_fifo, char* info) +int t_write_req(struct sip_msg *msg, char *vm_fifo, char *info) { - if (assemble_msg(msg, (struct tw_info*)info) < 0) { + if(assemble_msg(msg, (struct tw_info *)info) < 0) { LM_ERR("error int assemble_msg\n"); return -1; } - if (write_to_fifo(vm_fifo, TWRITE_PARAMS) == -1) { + if(write_to_fifo(vm_fifo, TWRITE_PARAMS) == -1) { LM_ERR("write_to_fifo failed\n"); return -1; } /* make sure that if voicemail does not initiate a reply * timely, a SIP timeout will be sent out */ - if (add_blind_uac() == -1) { + if(add_blind_uac() == -1) { LM_ERR("add_blind failed\n"); return -1; } @@ -948,21 +981,21 @@ int t_write_req(struct sip_msg* msg, char* vm_fifo, char* info) } -int t_write_unix(struct sip_msg* msg, char* socket, char* info) +int t_write_unix(struct sip_msg *msg, char *socket, char *info) { - if (assemble_msg(msg, (struct tw_info*)info) < 0) { + if(assemble_msg(msg, (struct tw_info *)info) < 0) { LM_ERR("error in assemble_msg\n"); return -1; } - if (write_to_unixsock(socket, TWRITE_PARAMS) == -1) { + if(write_to_unixsock(socket, TWRITE_PARAMS) == -1) { LM_ERR("write_to_unixsock failed\n"); return -1; } /* make sure that if voicemail does not initiate a reply * timely, a SIP timeout will be sent out */ - if (add_blind_uac() == -1) { + if(add_blind_uac() == -1) { LM_ERR("add_blind failed\n"); return -1; } diff --git a/src/modules/tm/t_fifo.h b/src/modules/tm/t_fifo.h index 88c33f25b92..142bb48b5b0 100644 --- a/src/modules/tm/t_fifo.h +++ b/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 diff --git a/src/modules/tm/t_funcs.c b/src/modules/tm/t_funcs.c index e8b84a5ac92..40f7ce35e63 100644 --- a/src/modules/tm/t_funcs.c +++ b/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 @@ int t_relay_to( struct sip_msg *p_msg , struct proxy_l *proxy, int proto, } - /* * 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; } diff --git a/src/modules/tm/t_funcs.h b/src/modules/tm/t_funcs.h index dbbdc1960a4..e63af34d0f1 100644 --- a/src/modules/tm/t_funcs.h +++ b/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 - diff --git a/src/modules/tm/t_fwd.c b/src/modules/tm/t_fwd.c index be435925e65..c19d97c746c 100644 --- a/src/modules/tm/t_fwd.c +++ b/src/modules/tm/t_fwd.c @@ -64,15 +64,15 @@ extern int tm_dns_reuse_rcv_socket; static int goto_on_branch = 0, branch_route = 0; -void t_on_branch( unsigned int go_to ) +void t_on_branch(unsigned int go_to) { struct cell *t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variable */ - if (!t || t==T_UNDEFINED ) { - goto_on_branch=go_to; + if(!t || t == T_UNDEFINED) { + goto_on_branch = go_to; } else { t->on_branch = go_to; } @@ -83,14 +83,12 @@ unsigned int get_on_branch(void) return goto_on_branch; } -void set_branch_route( unsigned int on_branch) +void set_branch_route(unsigned int on_branch) { branch_route = on_branch; } - - /** prepares a new branch "buffer". * Creates the buffer used in the branch rb, fills everything needed ( * the sending information: t->uac[branch].request.dst, branch buffer, uri @@ -118,17 +116,13 @@ void set_branch_route( unsigned int on_branch) * * @return 0 on success, < 0 (ser_errror E***) on failure. */ -static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, - int branch, str *uri, str* path, - str* next_hop, - struct socket_info* fsocket, - snd_flags_t snd_flags, - int fproto, int flags, - str *instance, str *ruid, +static int prepare_new_uac(struct cell *t, struct sip_msg *i_req, int branch, + str *uri, str *path, str *next_hop, struct socket_info *fsocket, + snd_flags_t snd_flags, int fproto, int flags, str *instance, str *ruid, str *location_ua) { char *shbuf; - struct lump* add_rm_backup, *body_lumps_backup; + struct lump *add_rm_backup, *body_lumps_backup; struct sip_uri parsed_uri_bak; int ret; unsigned int len; @@ -154,35 +148,34 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, struct run_act_ctx *bctx; sr_kemi_eng_t *keng; - shbuf=0; - ret=E_UNSPEC; - msg_uri_bak.s=0; /* kill warnings */ - msg_uri_bak.len=0; - parsed_uri_ok_bak=0; - free_new_uri=0; - dst_uri_bak.s=0; - dst_uri_bak.len=0; - dst_uri_backed_up=0; - path_bak.s=0; - path_bak.len=0; - free_path=0; - instance_bak.s=0; - instance_bak.len=0; - free_instance=0; - ruid_bak.s=0; - ruid_bak.len=0; - free_ruid=0; - ua_bak.s=0; - ua_bak.len=0; - free_ua=0; - dst=&t->uac[branch].request.dst; + shbuf = 0; + ret = E_UNSPEC; + msg_uri_bak.s = 0; /* kill warnings */ + msg_uri_bak.len = 0; + parsed_uri_ok_bak = 0; + free_new_uri = 0; + dst_uri_bak.s = 0; + dst_uri_bak.len = 0; + dst_uri_backed_up = 0; + path_bak.s = 0; + path_bak.len = 0; + free_path = 0; + instance_bak.s = 0; + instance_bak.len = 0; + free_instance = 0; + ruid_bak.s = 0; + ruid_bak.len = 0; + free_ruid = 0; + ua_bak.s = 0; + ua_bak.len = 0; + free_ua = 0; + dst = &t->uac[branch].request.dst; /* ... we calculate branch ... */ - if (!t_calc_branch(t, branch, i_req->add_to_branch_s, - &i_req->add_to_branch_len )) - { + if(!t_calc_branch( + t, branch, i_req->add_to_branch_s, &i_req->add_to_branch_len)) { LM_ERR("branch computation failed\n"); - ret=E_UNSPEC; + ret = E_UNSPEC; goto error00; } @@ -193,17 +186,17 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, membar_depends(); add_rm_backup = i_req->add_rm; body_lumps_backup = i_req->body_lumps; - if (unlikely(i_req->add_rm)){ + if(unlikely(i_req->add_rm)) { i_req->add_rm = dup_lump_list(i_req->add_rm); - if (unlikely(i_req->add_rm==0)){ - ret=E_OUT_OF_MEM; + if(unlikely(i_req->add_rm == 0)) { + ret = E_OUT_OF_MEM; goto error05; } } - if (unlikely(i_req->body_lumps)){ + if(unlikely(i_req->body_lumps)) { i_req->body_lumps = dup_lump_list(i_req->body_lumps); - if (unlikely(i_req->body_lumps==0)){ - ret=E_OUT_OF_MEM; + if(unlikely(i_req->body_lumps == 0)) { + ret = E_OUT_OF_MEM; goto error04; } } @@ -211,116 +204,116 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, * will use uri & path and not the ones in the original msg (i_req) * => we must back them up so that we can restore them to the original * value after building the send buffer */ - msg_uri_bak=i_req->new_uri; - parsed_uri_bak=i_req->parsed_uri; - parsed_uri_ok_bak=i_req->parsed_uri_ok; - path_bak=i_req->path_vec; - instance_bak=i_req->instance; - ruid_bak=i_req->ruid; - ua_bak=i_req->location_ua; - - if (unlikely(branch_route || has_tran_tmcbs(t, TMCB_REQUEST_FWDED))){ + msg_uri_bak = i_req->new_uri; + parsed_uri_bak = i_req->parsed_uri; + parsed_uri_ok_bak = i_req->parsed_uri_ok; + path_bak = i_req->path_vec; + instance_bak = i_req->instance; + ruid_bak = i_req->ruid; + ua_bak = i_req->location_ua; + + if(unlikely(branch_route || has_tran_tmcbs(t, TMCB_REQUEST_FWDED))) { /* dup uris, path a.s.o. if we have a branch route or callback */ /* ... set ruri ... */ /* if uri points to new_uri, it needs to be "fixed" so that we can * change msg->new_uri */ - if (uri==&i_req->new_uri) - uri=&msg_uri_bak; - i_req->parsed_uri_ok=0; - i_req->new_uri.s=pkg_malloc(uri->len); - if (unlikely(i_req->new_uri.s==0)){ + if(uri == &i_req->new_uri) + uri = &msg_uri_bak; + i_req->parsed_uri_ok = 0; + i_req->new_uri.s = pkg_malloc(uri->len); + if(unlikely(i_req->new_uri.s == 0)) { PKG_MEM_ERROR; - ret=E_OUT_OF_MEM; + ret = E_OUT_OF_MEM; goto error03; } - free_new_uri=1; + free_new_uri = 1; memcpy(i_req->new_uri.s, uri->s, uri->len); - i_req->new_uri.len=uri->len; + i_req->new_uri.len = uri->len; /* update path_vec */ /* if path points to msg path_vec, it needs to be "fixed" so that we * can change/update msg->path_vec */ - if (path==&i_req->path_vec) - path=&path_bak; + if(path == &i_req->path_vec) + path = &path_bak; /* zero it first so that set_path_vector will work */ - i_req->path_vec.s=0; - i_req->path_vec.len=0; - if (unlikely(path)){ - if (unlikely(set_path_vector(i_req, path)<0)){ - ret=E_OUT_OF_MEM; + i_req->path_vec.s = 0; + i_req->path_vec.len = 0; + if(unlikely(path)) { + if(unlikely(set_path_vector(i_req, path) < 0)) { + ret = E_OUT_OF_MEM; goto error03; } - free_path=1; + free_path = 1; } /* update instance */ /* if instance points to msg instance, it needs to be "fixed" so that we * can change/update msg->instance */ - if (instance==&i_req->instance) - instance=&instance_bak; + if(instance == &i_req->instance) + instance = &instance_bak; /* zero it first so that set_instance will work */ - i_req->instance.s=0; - i_req->instance.len=0; - if (unlikely(instance)){ - if (unlikely(set_instance(i_req, instance)<0)){ - ret=E_OUT_OF_MEM; + i_req->instance.s = 0; + i_req->instance.len = 0; + if(unlikely(instance)) { + if(unlikely(set_instance(i_req, instance) < 0)) { + ret = E_OUT_OF_MEM; goto error03; } - free_instance=1; + free_instance = 1; } /* update ruid */ /* if ruid points to msg ruid, it needs to be "fixed" so that we * can change/update msg->ruid */ - if (ruid==&i_req->ruid) - ruid=&ruid_bak; + if(ruid == &i_req->ruid) + ruid = &ruid_bak; /* zero it first so that set_ruid will work */ - i_req->ruid.s=0; - i_req->ruid.len=0; - if (unlikely(ruid)){ - if (unlikely(set_ruid(i_req, ruid)<0)){ - ret=E_OUT_OF_MEM; + i_req->ruid.s = 0; + i_req->ruid.len = 0; + if(unlikely(ruid)) { + if(unlikely(set_ruid(i_req, ruid) < 0)) { + ret = E_OUT_OF_MEM; goto error03; } - free_ruid=1; + free_ruid = 1; } /* update location_ua */ /* if location_ua points to msg location_ua, it needs to be "fixed" * so that we can change/update msg->location_ua */ - if (location_ua==&i_req->location_ua) - location_ua=&ua_bak; + if(location_ua == &i_req->location_ua) + location_ua = &ua_bak; /* zero it first so that set_ua will work */ - i_req->location_ua.s=0; - i_req->location_ua.len=0; - if (unlikely(location_ua)){ - if (unlikely(set_ua(i_req, location_ua)<0)){ - ret=E_OUT_OF_MEM; + i_req->location_ua.s = 0; + i_req->location_ua.len = 0; + if(unlikely(location_ua)) { + if(unlikely(set_ua(i_req, location_ua) < 0)) { + ret = E_OUT_OF_MEM; goto error03; } - free_ua=1; + free_ua = 1; } /* backup dst uri & zero it*/ - dst_uri_bak=i_req->dst_uri; - dst_uri_backed_up=1; + dst_uri_bak = i_req->dst_uri; + dst_uri_backed_up = 1; /* if next_hop points to dst_uri, it needs to be "fixed" so that we * can change msg->dst_uri */ - if (next_hop==&i_req->dst_uri) - next_hop=&dst_uri_bak; + if(next_hop == &i_req->dst_uri) + next_hop = &dst_uri_bak; /* zero it first so that set_dst_uri will work */ - i_req->dst_uri.s=0; - i_req->dst_uri.len=0; - if (likely(next_hop)){ - if(unlikely((flags & UAC_SKIP_BR_DST_F)==0)){ + i_req->dst_uri.s = 0; + i_req->dst_uri.len = 0; + if(likely(next_hop)) { + if(unlikely((flags & UAC_SKIP_BR_DST_F) == 0)) { /* set dst uri to next_hop for the on_branch route */ - if (unlikely(set_dst_uri(i_req, next_hop)<0)){ - ret=E_OUT_OF_MEM; + if(unlikely(set_dst_uri(i_req, next_hop) < 0)) { + ret = E_OUT_OF_MEM; goto error03; } } } - if (likely(branch_route)) { + if(likely(branch_route)) { /* run branch_route actions if provided */ backup_route_type = get_route_type(); set_route_type(BRANCH_ROUTE); @@ -333,126 +326,136 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, * (for that to work one would have to set branch_route prior to * calling add_uac(...) and then reset it afterwards). */ - if (exec_pre_script_cb(i_req, BRANCH_CB_TYPE)>0) { + if(exec_pre_script_cb(i_req, BRANCH_CB_TYPE) > 0) { /* backup ireq msg send flags and force_send_socket*/ - fwd_snd_flags_bak=i_req->fwd_send_flags;; - rpl_snd_flags_bak=i_req->rpl_send_flags; - force_send_socket_bak=i_req->force_send_socket; + fwd_snd_flags_bak = i_req->fwd_send_flags; + ; + rpl_snd_flags_bak = i_req->rpl_send_flags; + force_send_socket_bak = i_req->force_send_socket; /* set the new values */ - i_req->fwd_send_flags=snd_flags /* intial value */; + i_req->fwd_send_flags = snd_flags /* intial value */; set_force_socket(i_req, fsocket); keng = sr_kemi_eng_get(); - if(unlikely(keng!=NULL)) { + if(unlikely(keng != NULL)) { bctx = sr_kemi_act_ctx_get(); init_run_actions_ctx(&ctx); sr_kemi_act_ctx_set(&ctx); if(sr_kemi_route(keng, i_req, BRANCH_ROUTE, - sr_kemi_cbname_lookup_idx(branch_route), NULL)<0) { + sr_kemi_cbname_lookup_idx(branch_route), NULL) + < 0) { LM_ERR("error running branch route kemi callback\n"); } sr_kemi_act_ctx_set(bctx); } else { - if (run_top_route(branch_rt.rlist[branch_route], - i_req, &ctx) < 0) { + if(run_top_route(branch_rt.rlist[branch_route], i_req, &ctx) + < 0) { LM_DBG("negative return code in run_top_route\n"); } } /* update dst send_flags and send socket*/ - snd_flags=i_req->fwd_send_flags; - fsocket=i_req->force_send_socket; + snd_flags = i_req->fwd_send_flags; + fsocket = i_req->force_send_socket; /* restore ireq_msg force_send_socket & flags */ set_force_socket(i_req, force_send_socket_bak); - i_req->fwd_send_flags=fwd_snd_flags_bak; - i_req->rpl_send_flags=rpl_snd_flags_bak; + i_req->fwd_send_flags = fwd_snd_flags_bak; + i_req->rpl_send_flags = rpl_snd_flags_bak; exec_post_script_cb(i_req, BRANCH_CB_TYPE); /* if DROP was called in cfg, don't forward, jump to end */ - if (unlikely(ctx.run_flags&DROP_R_F)) - { + if(unlikely(ctx.run_flags & DROP_R_F)) { tm_ctx_set_branch_index(T_BR_UNDEFINED); set_route_type(backup_route_type); /* triggered by drop in CFG */ - ret=E_CFG; + ret = E_CFG; goto error03; } } /* run the specific callbacks for this transaction */ - if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_FWDED))) - run_trans_callbacks( TMCB_REQUEST_FWDED , t, i_req, 0, - -i_req->REQ_METHOD); + if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_FWDED))) + run_trans_callbacks( + TMCB_REQUEST_FWDED, t, i_req, 0, -i_req->REQ_METHOD); tm_ctx_set_branch_index(T_BR_UNDEFINED); set_route_type(backup_route_type); } else { /* run the specific callbacks for this transaction */ - if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_FWDED))) - run_trans_callbacks( TMCB_REQUEST_FWDED , t, i_req, 0, - -i_req->REQ_METHOD); + if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_FWDED))) + run_trans_callbacks( + TMCB_REQUEST_FWDED, t, i_req, 0, -i_req->REQ_METHOD); } - if (likely( !(flags & UAC_DNS_FAILOVER_F) && i_req->dst_uri.s && - i_req->dst_uri.len)){ + if(likely(!(flags & UAC_DNS_FAILOVER_F) && i_req->dst_uri.s + && i_req->dst_uri.len)) { /* no dns failover and non-empty dst_uri => use it as dst * (on dns failover dns_h will be non-empty => next_hop will be * ignored) */ - next_hop=&i_req->dst_uri; + next_hop = &i_req->dst_uri; } /* no path vector initially, but now is set after branch route and * callbacks execution */ - if(i_req->path_vec.s!=0 && free_path==0) - free_path=1; - }else{ + if(i_req->path_vec.s != 0 && free_path == 0) + free_path = 1; + } else { /* no branch route and no TMCB_REQUEST_FWDED callback => set * msg uri and path to the new values (if needed) */ - if (unlikely((uri->s!=i_req->new_uri.s || uri->len!=i_req->new_uri.len) - && (i_req->new_uri.s!=0 || - uri->s!=i_req->first_line.u.request.uri.s || - uri->len!=i_req->first_line.u.request.uri.len) )){ + if(unlikely((uri->s != i_req->new_uri.s + || uri->len != i_req->new_uri.len) + && (i_req->new_uri.s != 0 + || uri->s != i_req->first_line.u.request.uri.s + || uri->len + != i_req->first_line.u.request.uri + .len))) { /* uri is different from i_req uri => replace i_req uri and force * uri re-parsing */ - i_req->new_uri=*uri; - i_req->parsed_uri_ok=0; + i_req->new_uri = *uri; + i_req->parsed_uri_ok = 0; } - if (unlikely(path && (i_req->path_vec.s!=path->s || - i_req->path_vec.len!=path->len))){ - i_req->path_vec=*path; - }else if (unlikely(path==0 && i_req->path_vec.len!=0)){ - i_req->path_vec.s=0; - i_req->path_vec.len=0; + if(unlikely(path + && (i_req->path_vec.s != path->s + || i_req->path_vec.len != path->len))) { + i_req->path_vec = *path; + } else if(unlikely(path == 0 && i_req->path_vec.len != 0)) { + i_req->path_vec.s = 0; + i_req->path_vec.len = 0; } - if (unlikely(instance && (i_req->instance.s!=instance->s || - i_req->instance.len!=instance->len))){ - i_req->instance=*instance; - }else if (unlikely(instance==0 && i_req->instance.len!=0)){ - i_req->instance.s=0; - i_req->instance.len=0; + if(unlikely(instance + && (i_req->instance.s != instance->s + || i_req->instance.len != instance->len))) { + i_req->instance = *instance; + } else if(unlikely(instance == 0 && i_req->instance.len != 0)) { + i_req->instance.s = 0; + i_req->instance.len = 0; } - if (unlikely(ruid && (i_req->ruid.s!=ruid->s || - i_req->ruid.len!=ruid->len))){ - i_req->ruid=*ruid; - }else if (unlikely(ruid==0 && i_req->ruid.len!=0)){ - i_req->ruid.s=0; - i_req->ruid.len=0; + if(unlikely(ruid + && (i_req->ruid.s != ruid->s + || i_req->ruid.len != ruid->len))) { + i_req->ruid = *ruid; + } else if(unlikely(ruid == 0 && i_req->ruid.len != 0)) { + i_req->ruid.s = 0; + i_req->ruid.len = 0; } - if (unlikely(location_ua && (i_req->location_ua.s!=location_ua->s || - i_req->location_ua.len!=location_ua->len))){ - i_req->location_ua=*location_ua; - }else if (unlikely(location_ua==0 && i_req->location_ua.len!=0)){ - i_req->location_ua.s=0; - i_req->location_ua.len=0; + if(unlikely(location_ua + && (i_req->location_ua.s != location_ua->s + || i_req->location_ua.len != location_ua->len))) { + i_req->location_ua = *location_ua; + } else if(unlikely(location_ua == 0 && i_req->location_ua.len != 0)) { + i_req->location_ua.s = 0; + i_req->location_ua.len = 0; } } - if (likely(next_hop!=0 || (flags & UAC_DNS_FAILOVER_F))){ + if(likely(next_hop != 0 || (flags & UAC_DNS_FAILOVER_F))) { /* next_hop present => use it for dns resolution */ #ifdef USE_DNS_FAILOVER test_dst = (uri2dst2(&t->uac[branch].dns_h, dst, fsocket, snd_flags, - next_hop?next_hop:uri, fproto) == 0); + next_hop ? next_hop : uri, fproto) + == 0); #else /* dst filled from the uri & request (send_socket) */ - test_dst = (uri2dst2(dst, fsocket, snd_flags, - next_hop?next_hop:uri, fproto)==0); + test_dst = (uri2dst2(dst, fsocket, snd_flags, next_hop ? next_hop : uri, + fproto) + == 0); #endif - if (test_dst){ - ret=E_BAD_ADDRESS; + if(test_dst) { + ret = E_BAD_ADDRESS; goto error01; } } @@ -466,140 +469,141 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, t->uac[branch].on_branch_failure = t->on_branch_failure; /* check if send_sock is ok */ - if (t->uac[branch].request.dst.send_sock==0) { + if(t->uac[branch].request.dst.send_sock == 0) { LM_ERR("can't fwd to af %d, proto %d " - " (no corresponding listening socket)\n", - dst->to.s.sa_family, dst->proto ); - ret=E_NO_SOCKET; + " (no corresponding listening socket)\n", + dst->to.s.sa_family, dst->proto); + ret = E_NO_SOCKET; goto error01; } /* ... and build it now */ - shbuf=build_req_buf_from_sip_req( i_req, &len, dst, BUILD_IN_SHM); - if (!shbuf || len<=0) { + shbuf = build_req_buf_from_sip_req(i_req, &len, dst, BUILD_IN_SHM); + if(!shbuf || len <= 0) { LM_ERR("could not build request\n"); if(shbuf) { shm_free(shbuf); shbuf = NULL; } - ret=E_OUT_OF_MEM; + ret = E_OUT_OF_MEM; goto error01; } #ifdef DBG_MSG_QA - if (shbuf[len-1]==0) { + if(shbuf[len - 1] == 0) { LM_ERR("sanity check failed\n"); abort(); } #endif /* things went well, move ahead and install new buffer! */ - t->uac[branch].request.buffer=shbuf; - t->uac[branch].request.buffer_len=len; - t->uac[branch].uri.s=t->uac[branch].request.buffer+ - i_req->first_line.u.request.method.len+1; - t->uac[branch].uri.len=GET_RURI(i_req)->len; - if (unlikely(i_req->path_vec.s && i_req->path_vec.len)){ - t->uac[branch].path.s=shm_malloc(i_req->path_vec.len+1); - if (unlikely(t->uac[branch].path.s==0)) { + t->uac[branch].request.buffer = shbuf; + t->uac[branch].request.buffer_len = len; + t->uac[branch].uri.s = t->uac[branch].request.buffer + + i_req->first_line.u.request.method.len + 1; + t->uac[branch].uri.len = GET_RURI(i_req)->len; + if(unlikely(i_req->path_vec.s && i_req->path_vec.len)) { + t->uac[branch].path.s = shm_malloc(i_req->path_vec.len + 1); + if(unlikely(t->uac[branch].path.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = E_OUT_OF_MEM; goto error01; } - t->uac[branch].path.len=i_req->path_vec.len; - t->uac[branch].path.s[i_req->path_vec.len]=0; - memcpy( t->uac[branch].path.s, i_req->path_vec.s, i_req->path_vec.len); + t->uac[branch].path.len = i_req->path_vec.len; + t->uac[branch].path.s[i_req->path_vec.len] = 0; + memcpy(t->uac[branch].path.s, i_req->path_vec.s, i_req->path_vec.len); } - if (unlikely(i_req->instance.s && i_req->instance.len)){ - t->uac[branch].instance.s=shm_malloc(i_req->instance.len+1); - if (unlikely(t->uac[branch].instance.s==0)) { + if(unlikely(i_req->instance.s && i_req->instance.len)) { + t->uac[branch].instance.s = shm_malloc(i_req->instance.len + 1); + if(unlikely(t->uac[branch].instance.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = E_OUT_OF_MEM; goto error01; } - t->uac[branch].instance.len=i_req->instance.len; - t->uac[branch].instance.s[i_req->instance.len]=0; - memcpy( t->uac[branch].instance.s, i_req->instance.s, i_req->instance.len); - } - if (unlikely(i_req->ruid.s && i_req->ruid.len)){ - t->uac[branch].ruid.s=shm_malloc(i_req->ruid.len+1); - if (unlikely(t->uac[branch].ruid.s==0)) { + t->uac[branch].instance.len = i_req->instance.len; + t->uac[branch].instance.s[i_req->instance.len] = 0; + memcpy(t->uac[branch].instance.s, i_req->instance.s, + i_req->instance.len); + } + if(unlikely(i_req->ruid.s && i_req->ruid.len)) { + t->uac[branch].ruid.s = shm_malloc(i_req->ruid.len + 1); + if(unlikely(t->uac[branch].ruid.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = E_OUT_OF_MEM; goto error01; } - t->uac[branch].ruid.len=i_req->ruid.len; - t->uac[branch].ruid.s[i_req->ruid.len]=0; - memcpy( t->uac[branch].ruid.s, i_req->ruid.s, i_req->ruid.len); + t->uac[branch].ruid.len = i_req->ruid.len; + t->uac[branch].ruid.s[i_req->ruid.len] = 0; + memcpy(t->uac[branch].ruid.s, i_req->ruid.s, i_req->ruid.len); } - if (unlikely(i_req->location_ua.s && i_req->location_ua.len)){ - t->uac[branch].location_ua.s=shm_malloc(i_req->location_ua.len+1); - if (unlikely(t->uac[branch].location_ua.s==0)) { + if(unlikely(i_req->location_ua.s && i_req->location_ua.len)) { + t->uac[branch].location_ua.s = shm_malloc(i_req->location_ua.len + 1); + if(unlikely(t->uac[branch].location_ua.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = E_OUT_OF_MEM; goto error01; } - t->uac[branch].location_ua.len=i_req->location_ua.len; - t->uac[branch].location_ua.s[i_req->location_ua.len]=0; - memcpy( t->uac[branch].location_ua.s, i_req->location_ua.s, + t->uac[branch].location_ua.len = i_req->location_ua.len; + t->uac[branch].location_ua.s[i_req->location_ua.len] = 0; + memcpy(t->uac[branch].location_ua.s, i_req->location_ua.s, i_req->location_ua.len); } len = count_applied_lumps(i_req->add_rm, HDR_RECORDROUTE_T); - if(len==1) + if(len == 1) t->uac[branch].flags = TM_UAC_FLAG_RR; - else if(len==2) - t->uac[branch].flags = TM_UAC_FLAG_RR|TM_UAC_FLAG_R2; + else if(len == 2) + t->uac[branch].flags = TM_UAC_FLAG_RR | TM_UAC_FLAG_R2; - ret=0; + ret = 0; error01: error03: /* restore the new_uri & path from the backup */ - if (unlikely(free_new_uri && i_req->new_uri.s)){ + if(unlikely(free_new_uri && i_req->new_uri.s)) { pkg_free(i_req->new_uri.s); } - if (unlikely(free_path)){ + if(unlikely(free_path)) { reset_path_vector(i_req); } - if (unlikely(free_instance)){ + if(unlikely(free_instance)) { reset_instance(i_req); } - if (unlikely(free_ruid)){ + if(unlikely(free_ruid)) { reset_ruid(i_req); } - if (unlikely(free_ua)){ + if(unlikely(free_ua)) { reset_ua(i_req); } - if (dst_uri_backed_up){ + if(dst_uri_backed_up) { reset_dst_uri(i_req); /* free dst_uri */ - i_req->dst_uri=dst_uri_bak; + i_req->dst_uri = dst_uri_bak; } /* restore original new_uri and path values */ - i_req->new_uri=msg_uri_bak; - i_req->parsed_uri=parsed_uri_bak; - i_req->parsed_uri_ok=parsed_uri_ok_bak; - i_req->path_vec=path_bak; - i_req->instance=instance_bak; - i_req->ruid=ruid_bak; - i_req->location_ua=ua_bak; + i_req->new_uri = msg_uri_bak; + i_req->parsed_uri = parsed_uri_bak; + i_req->parsed_uri_ok = parsed_uri_ok_bak; + i_req->path_vec = path_bak; + i_req->instance = instance_bak; + i_req->ruid = ruid_bak; + i_req->location_ua = ua_bak; /* Delete the duplicated lump lists, this will also delete * all lumps created here, such as lumps created in per-branch @@ -629,8 +633,8 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req, * of the message is untouched, thus, the send socket is corrected only in the * VIA HF. */ -static char *print_uac_request_from_buf( struct cell *t, struct sip_msg *i_req, - int branch, str *uri, unsigned int *len, struct dest_info* dst, +static char *print_uac_request_from_buf(struct cell *t, struct sip_msg *i_req, + int branch, str *uri, unsigned int *len, struct dest_info *dst, char *buf, short buf_len) { char *shbuf; @@ -638,12 +642,11 @@ static char *print_uac_request_from_buf( struct cell *t, struct sip_msg *i_req, char *via, *old_via_begin, *old_via_end; unsigned int via_len; - shbuf=0; + shbuf = 0; /* ... we calculate branch ... */ - if (!t_calc_branch(t, branch, i_req->add_to_branch_s, - &i_req->add_to_branch_len )) - { + if(!t_calc_branch( + t, branch, i_req->add_to_branch_s, &i_req->add_to_branch_len)) { LM_ERR("branch computation failed\n"); goto error00; } @@ -651,41 +654,42 @@ static char *print_uac_request_from_buf( struct cell *t, struct sip_msg *i_req, branch_str.len = i_req->add_to_branch_len; /* find the beginning of the first via header in the buffer */ - old_via_begin = lw_find_via(buf, buf+buf_len); - if (!old_via_begin) { + old_via_begin = lw_find_via(buf, buf + buf_len); + if(!old_via_begin) { LM_ERR("beginning of via header not found\n"); goto error00; } /* find the end of the first via header in the buffer */ - old_via_end = lw_next_line(old_via_begin, buf+buf_len); - if (!old_via_end) { + old_via_end = lw_next_line(old_via_begin, buf + buf_len); + if(!old_via_end) { LM_ERR("end of via header not found\n"); goto error00; } /* create the new VIA HF */ via = create_via_hf(&via_len, i_req, dst, &branch_str); - if (!via) { + if(!via) { LM_ERR("via building failed\n"); goto error00; } /* allocate memory for the new buffer */ *len = buf_len + via_len - (old_via_end - old_via_begin); - shbuf=(char *)shm_malloc(*len); - if (!shbuf) { - ser_error=E_OUT_OF_MEM; + shbuf = (char *)shm_malloc(*len); + if(!shbuf) { + ser_error = E_OUT_OF_MEM; SHM_MEM_ERROR; goto error01; } /* construct the new buffer */ - memcpy(shbuf, buf, old_via_begin-buf); - memcpy(shbuf+(old_via_begin-buf), via, via_len); - memcpy(shbuf+(old_via_begin-buf)+via_len, old_via_end, (buf+buf_len)-old_via_end); + memcpy(shbuf, buf, old_via_begin - buf); + memcpy(shbuf + (old_via_begin - buf), via, via_len); + memcpy(shbuf + (old_via_begin - buf) + via_len, old_via_end, + (buf + buf_len) - old_via_end); #ifdef DBG_MSG_QA - if (shbuf[*len-1]==0) { + if(shbuf[*len - 1] == 0) { LM_ERR("sanity check failed\n"); abort(); } @@ -705,19 +709,19 @@ static char *print_uac_request_from_buf( struct cell *t, struct sip_msg *i_req, * and FR must be ticking, whereas the request is "forwarded" * using a non-SIP way and will be replied the same way */ -int add_blind_uac( /*struct cell *t*/ ) +int add_blind_uac(/*struct cell *t*/) { unsigned short branch; struct cell *t; - t=get_t(); - if (t==T_UNDEFINED || !t ) { + t = get_t(); + if(t == T_UNDEFINED || !t) { LM_ERR("no transaction context\n"); return -1; } - branch=t->nr_of_outgoings; - if (branch==sr_dst_max_branches) { + branch = t->nr_of_outgoings; + if(branch == sr_dst_max_branches) { LM_ERR("maximum number of branches exceeded\n"); return -1; } @@ -727,7 +731,7 @@ int add_blind_uac( /*struct cell *t*/ ) * all the writes finished before updating branch number*/ t->uac[branch].flags |= TM_UAC_FLAG_BLIND; - t->nr_of_outgoings=(branch+1); + t->nr_of_outgoings = (branch + 1); t->async_backup.blind_uac = branch; /* ^^^ whenever we create a blind UAC, lets save the current branch * this is used in async tm processing specifically to be able to route replies @@ -737,7 +741,7 @@ int add_blind_uac( /*struct cell *t*/ ) /* start FR timer -- protocol set by default to PROTO_NONE, * which means retransmission timer will not be started */ - if (start_retr(&t->uac[branch].request)!=0) + if(start_retr(&t->uac[branch].request) != 0) LM_CRIT("start retr failed for %p\n", &t->uac[branch].request); /* we are on a timer -- don't need to put on wait on script clean-up */ set_kr(REQ_FWDED); @@ -767,69 +771,68 @@ int add_blind_uac( /*struct cell *t*/ ) * @see prepare_new_uac(). * @returns branch id (>=0) or error (<0) */ -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, +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 ret; unsigned short branch; - branch=t->nr_of_outgoings; - if (branch==sr_dst_max_branches) { + branch = t->nr_of_outgoings; + if(branch == sr_dst_max_branches) { LM_ERR("maximum number of branches exceeded\n"); - ret=ser_error=E_TOO_MANY_BRANCHES; + ret = ser_error = E_TOO_MANY_BRANCHES; goto error; } /* check existing buffer -- rewriting should never occur */ - if (t->uac[branch].request.buffer) { + if(t->uac[branch].request.buffer) { LM_CRIT("buffer rewrite attempt\n"); - ret=ser_error=E_BUG; + ret = ser_error = E_BUG; goto error; } /* check DNS resolution */ - if (proxy){ + if(proxy) { /* dst filled from the proxy */ init_dest_info(&t->uac[branch].request.dst); - t->uac[branch].request.dst.proto=get_proto(proto, proxy->proto); + t->uac[branch].request.dst.proto = get_proto(proto, proxy->proto); proxy2su(&t->uac[branch].request.dst.to, proxy); /* fill dst send_sock */ t->uac[branch].request.dst.send_sock = - get_send_socket( request, &t->uac[branch].request.dst.to, - t->uac[branch].request.dst.proto); - if (request) - t->uac[branch].request.dst.send_flags=request->fwd_send_flags; + get_send_socket(request, &t->uac[branch].request.dst.to, + t->uac[branch].request.dst.proto); + if(request) + t->uac[branch].request.dst.send_flags = request->fwd_send_flags; else SND_FLAGS_INIT(&t->uac[branch].request.dst.send_flags); - next_hop=0; - }else { - next_hop= next_hop?next_hop:uri; + next_hop = 0; + } else { + next_hop = next_hop ? next_hop : uri; } /* now message printing starts ... */ - if (unlikely( (ret=prepare_new_uac(t, request, branch, uri, path, - next_hop, fsocket, snd_flags, - proto, flags, instance, ruid, - location_ua)) < 0)){ - ser_error=ret; + if(unlikely((ret = prepare_new_uac(t, request, branch, uri, path, next_hop, + fsocket, snd_flags, proto, flags, instance, ruid, + location_ua)) + < 0)) { + ser_error = ret; goto error01; } getbflagsval(0, &t->uac[branch].branch_flags); membar_write(); /* to allow lockless ops (e.g. prepare_to_cancel()) we want * to be sure everything above is fully written before * updating branches no. */ - t->nr_of_outgoings=(branch+1); + t->nr_of_outgoings = (branch + 1); /* update stats */ - if (proxy){ + if(proxy) { proxy_mark(proxy, 1); } /* done! */ - ret=branch; + ret = branch; error01: error: @@ -837,18 +840,13 @@ int add_uac( struct cell *t, struct sip_msg *request, str *uri, } - #ifdef USE_DNS_FAILOVER /* Similar to add_uac(), but this function uses the outgoing message buffer * of the failed branch to construct the new message in case of DNS failover. */ -static int add_uac_from_buf( struct cell *t, struct sip_msg *request, - str *uri, str* path, - struct socket_info* fsocket, - snd_flags_t send_flags, - int proto, - char *buf, short buf_len, - str *instance, str *ruid, +static int add_uac_from_buf(struct cell *t, struct sip_msg *request, str *uri, + str *path, struct socket_info *fsocket, snd_flags_t send_flags, + int proto, char *buf, short buf_len, str *instance, str *ruid, str *location_ua) { @@ -857,123 +855,122 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request, char *shbuf; unsigned int len; - branch=t->nr_of_outgoings; - if (branch==sr_dst_max_branches) { + branch = t->nr_of_outgoings; + if(branch == sr_dst_max_branches) { LM_ERR("maximum number of branches exceeded\n"); - ret=ser_error=E_TOO_MANY_BRANCHES; + ret = ser_error = E_TOO_MANY_BRANCHES; goto error; } /* check existing buffer -- rewriting should never occur */ - if (t->uac[branch].request.buffer) { + if(t->uac[branch].request.buffer) { LM_CRIT("buffer rewrite attempt\n"); - ret=ser_error=E_BUG; + ret = ser_error = E_BUG; goto error; } - if (uri2dst2(&t->uac[branch].dns_h, &t->uac[branch].request.dst, - fsocket, send_flags, uri, proto) == 0) - { - ret=ser_error=E_BAD_ADDRESS; + if(uri2dst2(&t->uac[branch].dns_h, &t->uac[branch].request.dst, fsocket, + send_flags, uri, proto) + == 0) { + ret = ser_error = E_BAD_ADDRESS; goto error; } /* check if send_sock is ok */ - if (t->uac[branch].request.dst.send_sock==0) { + if(t->uac[branch].request.dst.send_sock == 0) { LM_ERR("can't fwd to af %d, proto %d" - " (no corresponding listening socket)\n", + " (no corresponding listening socket)\n", t->uac[branch].request.dst.to.s.sa_family, - t->uac[branch].request.dst.proto ); - ret=ser_error=E_NO_SOCKET; + t->uac[branch].request.dst.proto); + ret = ser_error = E_NO_SOCKET; goto error; } /* now message printing starts ... */ - shbuf=print_uac_request_from_buf( t, request, branch, uri, - &len, &t->uac[branch].request.dst, - buf, buf_len); - if (!shbuf || len<=0) { + shbuf = print_uac_request_from_buf(t, request, branch, uri, &len, + &t->uac[branch].request.dst, buf, buf_len); + if(!shbuf || len <= 0) { if(shbuf) { shm_free(shbuf); shbuf = NULL; } - ret=ser_error=E_OUT_OF_MEM; + ret = ser_error = E_OUT_OF_MEM; goto error; } /* things went well, move ahead and install new buffer! */ - t->uac[branch].request.buffer=shbuf; - t->uac[branch].request.buffer_len=len; - t->uac[branch].uri.s=t->uac[branch].request.buffer+ - request->first_line.u.request.method.len+1; - t->uac[branch].uri.len=uri->len; + t->uac[branch].request.buffer = shbuf; + t->uac[branch].request.buffer_len = len; + t->uac[branch].uri.s = t->uac[branch].request.buffer + + request->first_line.u.request.method.len + 1; + t->uac[branch].uri.len = uri->len; /* copy the path */ - if (unlikely(path && path->s)){ - t->uac[branch].path.s=shm_malloc(path->len+1); - if (unlikely(t->uac[branch].path.s==0)) { + if(unlikely(path && path->s)) { + t->uac[branch].path.s = shm_malloc(path->len + 1); + if(unlikely(t->uac[branch].path.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=ser_error=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = ser_error = E_OUT_OF_MEM; goto error; } - t->uac[branch].path.len=path->len; - t->uac[branch].path.s[path->len]=0; - memcpy( t->uac[branch].path.s, path->s, path->len); + t->uac[branch].path.len = path->len; + t->uac[branch].path.s[path->len] = 0; + memcpy(t->uac[branch].path.s, path->s, path->len); } /* copy the instance */ - if (unlikely(instance && instance->s)){ - t->uac[branch].instance.s=shm_malloc(instance->len+1); - if (unlikely(t->uac[branch].instance.s==0)) { + if(unlikely(instance && instance->s)) { + t->uac[branch].instance.s = shm_malloc(instance->len + 1); + if(unlikely(t->uac[branch].instance.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=ser_error=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = ser_error = E_OUT_OF_MEM; goto error; } - t->uac[branch].instance.len=instance->len; - t->uac[branch].instance.s[instance->len]=0; - memcpy( t->uac[branch].instance.s, instance->s, instance->len); + t->uac[branch].instance.len = instance->len; + t->uac[branch].instance.s[instance->len] = 0; + memcpy(t->uac[branch].instance.s, instance->s, instance->len); } /* copy the ruid */ - if (unlikely(ruid && ruid->s)){ - t->uac[branch].ruid.s=shm_malloc(ruid->len+1); - if (unlikely(t->uac[branch].ruid.s==0)) { + if(unlikely(ruid && ruid->s)) { + t->uac[branch].ruid.s = shm_malloc(ruid->len + 1); + if(unlikely(t->uac[branch].ruid.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=ser_error=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = ser_error = E_OUT_OF_MEM; goto error; } - t->uac[branch].ruid.len=ruid->len; - t->uac[branch].ruid.s[ruid->len]=0; - memcpy( t->uac[branch].ruid.s, ruid->s, ruid->len); + t->uac[branch].ruid.len = ruid->len; + t->uac[branch].ruid.s[ruid->len] = 0; + memcpy(t->uac[branch].ruid.s, ruid->s, ruid->len); } /* copy the location_ua */ - if (unlikely(location_ua && location_ua->s)){ - t->uac[branch].location_ua.s=shm_malloc(location_ua->len+1); - if (unlikely(t->uac[branch].location_ua.s==0)) { + if(unlikely(location_ua && location_ua->s)) { + t->uac[branch].location_ua.s = shm_malloc(location_ua->len + 1); + if(unlikely(t->uac[branch].location_ua.s == 0)) { SHM_MEM_ERROR; shm_free(shbuf); - t->uac[branch].request.buffer=0; - t->uac[branch].request.buffer_len=0; - t->uac[branch].uri.s=0; - t->uac[branch].uri.len=0; - ret=ser_error=E_OUT_OF_MEM; + t->uac[branch].request.buffer = 0; + t->uac[branch].request.buffer_len = 0; + t->uac[branch].uri.s = 0; + t->uac[branch].uri.len = 0; + ret = ser_error = E_OUT_OF_MEM; goto error; } - t->uac[branch].location_ua.len=location_ua->len; - t->uac[branch].location_ua.s[location_ua->len]=0; - memcpy( t->uac[branch].location_ua.s, location_ua->s, location_ua->len); + t->uac[branch].location_ua.len = location_ua->len; + t->uac[branch].location_ua.s[location_ua->len] = 0; + memcpy(t->uac[branch].location_ua.s, location_ua->s, location_ua->len); } t->uac[branch].on_reply = t->on_reply; @@ -983,10 +980,10 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request, membar_write(); /* to allow lockless ops (e.g. prepare_to_cancel()) we want * to be sure everything above is fully written before * updating branches no. */ - t->nr_of_outgoings=(branch+1); + t->nr_of_outgoings = (branch + 1); /* done! */ - ret=branch; + ret = branch; error: return ret; @@ -1004,80 +1001,76 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request, * already held, e.g. in failure route/handlers (WARNING: using 1 in a * failure route will cause a deadlock). */ -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) { int ret; - ret=-1; - if (cfg_get(core, core_cfg, use_dns_failover) && - !((t->flags & (T_DONT_FORK|T_DISABLE_FAILOVER)) || - uac_dont_fork(old_uac)) && - dns_srv_handle_next(&old_uac->dns_h, 0)){ - if (lock_replies){ + ret = -1; + if(cfg_get(core, core_cfg, use_dns_failover) + && !((t->flags & (T_DONT_FORK | T_DISABLE_FAILOVER)) + || uac_dont_fork(old_uac)) + && dns_srv_handle_next(&old_uac->dns_h, 0)) { + if(lock_replies) { /* use reply lock to guarantee nobody is adding a branch * in the same time */ LOCK_REPLIES(t); /* check again that we can fork */ - if ((t->flags & T_DONT_FORK) || uac_dont_fork(old_uac)){ + if((t->flags & T_DONT_FORK) || uac_dont_fork(old_uac)) { UNLOCK_REPLIES(t); LM_DBG("no forking on => no new branches\n"); return ret; } } - if (t->nr_of_outgoings >= sr_dst_max_branches){ + if(t->nr_of_outgoings >= sr_dst_max_branches) { LM_ERR("maximum number of branches exceeded\n"); - if (lock_replies) + if(lock_replies) UNLOCK_REPLIES(t); - ret=ser_error=E_TOO_MANY_BRANCHES; + ret = ser_error = E_TOO_MANY_BRANCHES; return ret; } /* copy the dns handle into the new uac */ - dns_srv_handle_cpy(&t->uac[t->nr_of_outgoings].dns_h, - &old_uac->dns_h); + dns_srv_handle_cpy(&t->uac[t->nr_of_outgoings].dns_h, &old_uac->dns_h); /* copy the onreply and onfailure routes */ t->uac[t->nr_of_outgoings].on_failure = old_uac->on_failure; t->uac[t->nr_of_outgoings].on_reply = old_uac->on_reply; - t->uac[t->nr_of_outgoings].on_branch_failure = old_uac->on_branch_failure; + t->uac[t->nr_of_outgoings].on_branch_failure = + old_uac->on_branch_failure; /* copy branch flags */ t->uac[t->nr_of_outgoings].branch_flags = old_uac->branch_flags; - if (cfg_get(tm, tm_cfg, reparse_on_dns_failover)){ + if(cfg_get(tm, tm_cfg, reparse_on_dns_failover)) { /* Reuse the old buffer and only replace the via header. * The drawback is that the send_socket is not corrected * in the rest of the message, only in the VIA HF (Miklos) */ - ret=add_uac_from_buf(t, msg, &old_uac->uri, - &old_uac->path, - (old_uac->request.dst.send_flags.f & SND_F_FORCE_SOCKET)? - old_uac->request.dst.send_sock: - ((tm_dns_reuse_rcv_socket)?msg->rcv.bind_address:0), - old_uac->request.dst.send_flags, - old_uac->request.dst.proto, - old_uac->request.buffer, - old_uac->request.buffer_len, - &old_uac->instance, &old_uac->ruid, - &old_uac->location_ua); + ret = add_uac_from_buf(t, msg, &old_uac->uri, &old_uac->path, + (old_uac->request.dst.send_flags.f & SND_F_FORCE_SOCKET) + ? old_uac->request.dst.send_sock + : ((tm_dns_reuse_rcv_socket) ? msg->rcv.bind_address + : 0), + old_uac->request.dst.send_flags, old_uac->request.dst.proto, + old_uac->request.buffer, old_uac->request.buffer_len, + &old_uac->instance, &old_uac->ruid, &old_uac->location_ua); } else { /* add_uac will use dns_h => next_hop will be ignored. * Unfortunately we can't reuse the old buffer, the branch id * must be changed and the send_socket might be different => * re-create the whole uac */ - ret=add_uac(t, msg, &old_uac->uri, 0, &old_uac->path, 0, - (old_uac->request.dst.send_flags.f & SND_F_FORCE_SOCKET)? - old_uac->request.dst.send_sock: - ((tm_dns_reuse_rcv_socket)?msg->rcv.bind_address:0), - old_uac->request.dst.send_flags, - old_uac->request.dst.proto, UAC_DNS_FAILOVER_F, - &old_uac->instance, &old_uac->ruid, + ret = add_uac(t, msg, &old_uac->uri, 0, &old_uac->path, 0, + (old_uac->request.dst.send_flags.f & SND_F_FORCE_SOCKET) + ? old_uac->request.dst.send_sock + : ((tm_dns_reuse_rcv_socket) ? msg->rcv.bind_address + : 0), + old_uac->request.dst.send_flags, old_uac->request.dst.proto, + UAC_DNS_FAILOVER_F, &old_uac->instance, &old_uac->ruid, &old_uac->location_ua); } - if (ret<0){ + if(ret < 0) { /* failed, delete the copied dns_h */ dns_srv_handle_put(&t->uac[t->nr_of_outgoings].dns_h); } - if (lock_replies){ + if(lock_replies) { UNLOCK_REPLIES(t); } } @@ -1086,81 +1079,81 @@ int add_uac_dns_fallback(struct cell *t, struct sip_msg* msg, #endif -int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel, - struct cell *t_invite, int branch ) +int e2e_cancel_branch(struct sip_msg *cancel_msg, struct cell *t_cancel, + struct cell *t_invite, int branch) { int ret; char *shbuf; unsigned int len; snd_flags_t snd_flags; - ret=-1; - if (t_cancel->uac[branch].request.buffer) { + ret = -1; + if(t_cancel->uac[branch].request.buffer) { LM_CRIT("buffer rewrite attempt\n"); - ret=ser_error=E_BUG; + ret = ser_error = E_BUG; goto error; } - if (t_invite->uac[branch].request.buffer==0){ + if(t_invite->uac[branch].request.buffer == 0) { /* inactive / deleted branch */ goto error; } - t_invite->uac[branch].request.flags|=F_RB_CANCELED; + t_invite->uac[branch].request.flags |= F_RB_CANCELED; /* note -- there is a gap in proxy stats -- we don't update * proxy stats with CANCEL (proxy->ok, proxy->tx, etc.) */ /* set same dst as the invite */ - t_cancel->uac[branch].request.dst=t_invite->uac[branch].request.dst; + t_cancel->uac[branch].request.dst = t_invite->uac[branch].request.dst; /* print */ - if (cfg_get(tm, tm_cfg, reparse_invite)) { + if(cfg_get(tm, tm_cfg, reparse_invite)) { /* buffer is built localy from the INVITE which was sent out */ /* lumps can be set outside of the lock, make sure that we read * the up-to-date values */ membar_depends(); - if (cancel_msg->add_rm || cancel_msg->body_lumps) { + if(cancel_msg->add_rm || cancel_msg->body_lumps) { LM_WARN("CANCEL is built locally," " thus lumps are not applied to the message!\n"); } - shbuf=build_local_reparse(t_invite, branch, &len, CANCEL, - CANCEL_LEN, &t_invite->to_hdr, 0); - if (unlikely(!shbuf) || len<=0) { + shbuf = build_local_reparse(t_invite, branch, &len, CANCEL, CANCEL_LEN, + &t_invite->to_hdr, 0); + if(unlikely(!shbuf) || len <= 0) { if(shbuf) { shm_free(shbuf); shbuf = NULL; } LM_ERR("printing e2e cancel failed\n"); - ret=ser_error=E_OUT_OF_MEM; + ret = ser_error = E_OUT_OF_MEM; goto error; } /* install buffer */ - t_cancel->uac[branch].request.buffer=shbuf; - t_cancel->uac[branch].request.buffer_len=len; - t_cancel->uac[branch].uri.s=t_cancel->uac[branch].request.buffer+ - cancel_msg->first_line.u.request.method.len+1; - t_cancel->uac[branch].uri.len=t_invite->uac[branch].uri.len; + t_cancel->uac[branch].request.buffer = shbuf; + t_cancel->uac[branch].request.buffer_len = len; + t_cancel->uac[branch].uri.s = + t_cancel->uac[branch].request.buffer + + cancel_msg->first_line.u.request.method.len + 1; + t_cancel->uac[branch].uri.len = t_invite->uac[branch].uri.len; } else { SND_FLAGS_INIT(&snd_flags); /* buffer is constructed from the received CANCEL with lumps applied */ /* t_cancel...request.dst is already filled (see above) */ - if (unlikely((ret=prepare_new_uac( t_cancel, cancel_msg, branch, - &t_invite->uac[branch].uri, - &t_invite->uac[branch].path, - 0, 0, snd_flags, PROTO_NONE, 0, - NULL, NULL, NULL)) <0)){ - ser_error=ret; + if(unlikely((ret = prepare_new_uac(t_cancel, cancel_msg, branch, + &t_invite->uac[branch].uri, + &t_invite->uac[branch].path, 0, 0, snd_flags, + PROTO_NONE, 0, NULL, NULL, NULL)) + < 0)) { + ser_error = ret; goto error; } } /* success */ - ret=1; + ret = 1; error: return ret; } - /** create a cancel reason structure packed into a single shm. block. * From a cause and a pointer to a str or cancel_msg, build a * packed cancel reason structure (CANCEL_REAS_PACKED_HDRS), using a @@ -1170,91 +1163,94 @@ int e2e_cancel_branch( struct sip_msg *cancel_msg, struct cell *t_cancel, * @return pointer to shm. packed cancel reason struct. on success, * 0 on error */ -static struct cancel_reason* cancel_reason_pack(short cause, void* data, - struct cell* t) +static struct cancel_reason *cancel_reason_pack( + short cause, void *data, struct cell *t) { - char* d; - struct cancel_reason* cr; + char *d; + struct cancel_reason *cr; int reason_len; int code_len; struct hdr_field *reas1, *reas_last, *hdr; - str* txt; - struct sip_msg* e2e_cancel; + str *txt; + struct sip_msg *e2e_cancel; - if (likely(cause != CANCEL_REAS_UNKNOWN)){ + if(likely(cause != CANCEL_REAS_UNKNOWN)) { reason_len = 0; txt = 0; e2e_cancel = 0; reas1 = 0; reas_last = 0; - if (likely(cause == CANCEL_REAS_RCVD_CANCEL && - data && !(t->flags & T_NO_E2E_CANCEL_REASON))) { + if(likely(cause == CANCEL_REAS_RCVD_CANCEL && data + && !(t->flags & T_NO_E2E_CANCEL_REASON))) { /* parse the entire cancel, to get all the Reason headers */ e2e_cancel = data; - if(parse_headers(e2e_cancel, HDR_EOH_F, 0)==-1) { + if(parse_headers(e2e_cancel, HDR_EOH_F, 0) == -1) { LM_ERR("failed to parse headers\n"); goto error; } - for(hdr=get_hdr(e2e_cancel, HDR_REASON_T), reas1=hdr; - hdr; hdr=next_sibling_hdr(hdr)) { + for(hdr = get_hdr(e2e_cancel, HDR_REASON_T), reas1 = hdr; hdr; + hdr = next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ reason_len += hdr->len; - reas_last=hdr; + reas_last = hdr; } - } else if (likely(cause > 0 && - cfg_get(tm, tm_cfg, local_cancel_reason))){ - txt = (str*) data; + } else if(likely(cause > 0 + && cfg_get(tm, tm_cfg, local_cancel_reason))) { + txt = (str *)data; /* Reason: SIP;cause=cause>[;text=u.text.s>] */ - reason_len = REASON_PREFIX_LEN + USHORT2SBUF_MAX_LEN + - ((txt && txt->s)?REASON_TEXT_LEN + 1 + txt->len + 1 : 0) + reason_len = + REASON_PREFIX_LEN + USHORT2SBUF_MAX_LEN + + ((txt && txt->s) ? REASON_TEXT_LEN + 1 + txt->len + 1 : 0) + CRLF_LEN; - } else if (cause == CANCEL_REAS_PACKED_HDRS && - !(t->flags & T_NO_E2E_CANCEL_REASON) && data) { - txt = (str*) data; + } else if(cause == CANCEL_REAS_PACKED_HDRS + && !(t->flags & T_NO_E2E_CANCEL_REASON) && data) { + txt = (str *)data; reason_len = txt->len; - } else if (unlikely(cause < CANCEL_REAS_MIN)) { + } else if(unlikely(cause < CANCEL_REAS_MIN)) { LM_CRIT("unhandled reason cause %d\n", cause); goto error; } - if (unlikely(reason_len == 0)) + if(unlikely(reason_len == 0)) return 0; /* nothing to do, no reason */ cr = shm_malloc(sizeof(struct cancel_reason) + reason_len); - if (unlikely(cr == 0)) { + if(unlikely(cr == 0)) { SHM_MEM_ERROR; goto error; } - d = (char*)cr +sizeof(*cr); + d = (char *)cr + sizeof(*cr); cr->cause = CANCEL_REAS_PACKED_HDRS; cr->u.packed_hdrs.s = d; cr->u.packed_hdrs.len = reason_len; - if (cause == CANCEL_REAS_RCVD_CANCEL) { - for(hdr=reas1; hdr; hdr=next_sibling_hdr(hdr)) { + if(cause == CANCEL_REAS_RCVD_CANCEL) { + for(hdr = reas1; hdr; hdr = next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ append_str(d, hdr->name.s, hdr->len); - if (likely(hdr==reas_last)) + if(likely(hdr == reas_last)) break; } - } else if (likely(cause > 0)) { + } else if(likely(cause > 0)) { append_str(d, REASON_PREFIX, REASON_PREFIX_LEN); - code_len=ushort2sbuf(cause, d, reason_len - - (int)(d - (char*)cr - sizeof(*cr))); - if (unlikely(code_len==0)) { + code_len = ushort2sbuf( + cause, d, reason_len - (int)(d - (char *)cr - sizeof(*cr))); + if(unlikely(code_len == 0)) { shm_free(cr); cr = 0; LM_CRIT("not enough space to write reason code\n"); goto error; } - d+=code_len; - if (txt && txt->s){ + d += code_len; + if(txt && txt->s) { append_str(d, REASON_TEXT, REASON_TEXT_LEN); - *d='"'; d++; + *d = '"'; + d++; append_str(d, txt->s, txt->len); - *d='"'; d++; + *d = '"'; + d++; } append_str(d, CRLF, CRLF_LEN); - } else if (cause == CANCEL_REAS_PACKED_HDRS) { + } else if(cause == CANCEL_REAS_PACKED_HDRS) { append_str(d, txt->s, txt->len); } return cr; @@ -1264,29 +1260,28 @@ static struct cancel_reason* cancel_reason_pack(short cause, void* data, } - -void e2e_cancel( struct sip_msg *cancel_msg, - struct cell *t_cancel, struct cell *t_invite ) +void e2e_cancel(struct sip_msg *cancel_msg, struct cell *t_cancel, + struct cell *t_invite) { branch_bm_t cancel_bm; #ifndef E2E_CANCEL_HOP_BY_HOP branch_bm_t tmp_bm; int reply_status; #endif /* E2E_CANCEL_HOP_BY_HOP */ - struct cancel_reason* reason; + struct cancel_reason *reason; int free_reason; int i; int lowest_error; int ret; struct tmcb_params tmcb; - cancel_bm=0; - lowest_error=0; + cancel_bm = 0; + lowest_error = 0; - if (unlikely(has_tran_tmcbs(t_invite, TMCB_E2ECANCEL_IN))){ + if(unlikely(has_tran_tmcbs(t_invite, TMCB_E2ECANCEL_IN))) { INIT_TMCB_PARAMS(tmcb, cancel_msg, 0, cancel_msg->REQ_METHOD); - run_trans_callbacks_internal(&t_invite->tmcb_hl, TMCB_E2ECANCEL_IN, - t_invite, &tmcb); + run_trans_callbacks_internal( + &t_invite->tmcb_hl, TMCB_E2ECANCEL_IN, t_invite, &tmcb); } /* mark transaction as canceled, so that no new message are forwarded * on it and t_is_canceled() returns true @@ -1294,13 +1289,13 @@ void e2e_cancel( struct sip_msg *cancel_msg, * event even if a flag is unwillingly reset nothing bad will happen), * however this should be rechecked for any future new flags use. */ - t_invite->flags|=T_CANCELED; + t_invite->flags |= T_CANCELED; /* first check if there are any branches */ - if (t_invite->nr_of_outgoings==0){ + if(t_invite->nr_of_outgoings == 0) { /* no branches yet => force a reply to the invite */ - t_reply( t_invite, t_invite->uas.request, 487, CANCELED ); + t_reply(t_invite, t_invite->uas.request, 487, CANCELED); LM_DBG("e2e cancel -- no more pending branches\n"); - t_reply( t_cancel, cancel_msg, 200, CANCEL_DONE ); + t_reply(t_cancel, cancel_msg, 200, CANCEL_DONE); return; } @@ -1308,11 +1303,11 @@ void e2e_cancel( struct sip_msg *cancel_msg, prepare_to_cancel(t_invite, &cancel_bm, 0); /* no branches to cancel (e.g., a suspended transaction with blind uac) */ - if (cancel_bm==0){ + if(cancel_bm == 0) { /* no outgoing branches yet => force a reply to the invite */ - t_reply( t_invite, t_invite->uas.request, 487, CANCELED ); + t_reply(t_invite, t_invite->uas.request, 487, CANCELED); LM_DBG("e2e cancel -- no active branches\n"); - t_reply( t_cancel, cancel_msg, 200, CANCEL_DONE ); + t_reply(t_cancel, cancel_msg, 200, CANCEL_DONE); return; } @@ -1331,89 +1326,92 @@ void e2e_cancel( struct sip_msg *cancel_msg, */ free_reason = 0; reason = 0; - if (likely(t_invite->uas.cancel_reas == 0)){ - reason = cancel_reason_pack(CANCEL_REAS_RCVD_CANCEL, cancel_msg, - t_invite); + if(likely(t_invite->uas.cancel_reas == 0)) { + reason = cancel_reason_pack( + CANCEL_REAS_RCVD_CANCEL, cancel_msg, t_invite); /* set if not already set */ - if (unlikely(reason && - atomic_cmpxchg_long((void*)&t_invite->uas.cancel_reas, - 0, (long)reason) != 0)) { + if(unlikely(reason + && atomic_cmpxchg_long((void *)&t_invite->uas.cancel_reas, + 0, (long)reason) + != 0)) { /* already set, failed to re-set it */ free_reason = 1; } } - for (i=0; inr_of_outgoings; i++) { - if (cancel_bm & (1<nr_of_outgoings; i++) { + if(cancel_bm & (1 << i)) { /* it's safe to get the reply lock since e2e_cancel is * called with the cancel as the "current" transaction so * at most t_cancel REPLY_LOCK is held in this process => * no deadlock possibility */ - ret=cancel_branch( - t_invite, - i, - reason, - cfg_get(tm,tm_cfg, cancel_b_flags) - | ((t_invite->uac[i].request.buffer==NULL)? - F_CANCEL_B_FAKE_REPLY:0) /* blind UAC? */ - ); - if (ret<0) cancel_bm &= ~(1<uac[i].request.buffer == NULL) + ? F_CANCEL_B_FAKE_REPLY + : 0) /* blind UAC? */ + ); + if(ret < 0) + cancel_bm &= ~(1 << i); + if(ret < lowest_error) + lowest_error = ret; } } - if (unlikely(free_reason)) { + if(unlikely(free_reason)) { /* reason was not set as the global reason => free it */ shm_free(reason); } -#else /* ! E2E_CANCEL_HOP_BY_HOP */ +#else /* ! E2E_CANCEL_HOP_BY_HOP */ /* fix label -- it must be same for reply matching (the label is part of * the generated via branch for the cancels sent upstream and if it * would be different form the one in the INVITE the transactions would not * match */ - t_cancel->label=t_invite->label; - t_cancel->nr_of_outgoings=t_invite->nr_of_outgoings; + t_cancel->label = t_invite->label; + t_cancel->nr_of_outgoings = t_invite->nr_of_outgoings; /* ... and install CANCEL UACs */ - for (i=0; inr_of_outgoings; i++) - if ((cancel_bm & (1<uac[i].last_received>=100)) { - ret=e2e_cancel_branch(cancel_msg, t_cancel, t_invite, i); - if (ret<0) cancel_bm &= ~(1<nr_of_outgoings; i++) + if((cancel_bm & (1 << i)) && (t_invite->uac[i].last_received >= 100)) { + ret = e2e_cancel_branch(cancel_msg, t_cancel, t_invite, i); + if(ret < 0) + cancel_bm &= ~(1 << i); + if(ret < lowest_error) + lowest_error = ret; } /* send them out */ - for (i = 0; i < t_cancel->nr_of_outgoings; i++) { - if (cancel_bm & (1 << i)) { - if (t_invite->uac[i].last_received>=100){ + for(i = 0; i < t_cancel->nr_of_outgoings; i++) { + if(cancel_bm & (1 << i)) { + if(t_invite->uac[i].last_received >= 100) { /* Provisional reply received on this branch, send CANCEL */ /* we do need to stop the retr. timers if the request is not * an invite and since the stop_rb_retr() cost is lower then * the invite check we do it always --andrei */ stop_rb_retr(&t_invite->uac[i].request); - if (SEND_BUFFER(&t_cancel->uac[i].request) == -1) { + if(SEND_BUFFER(&t_cancel->uac[i].request) == -1) { LM_ERR("e2e cancel - send failed\n"); - } - else{ - if (unlikely(has_tran_tmcbs(t_cancel, TMCB_REQUEST_SENT))) + } else { + if(unlikely(has_tran_tmcbs(t_cancel, TMCB_REQUEST_SENT))) run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, - &t_cancel->uac[i].request, - cancel_msg, 0, TMCB_LOCAL_F); + &t_cancel->uac[i].request, cancel_msg, 0, + TMCB_LOCAL_F); } - if (start_retr( &t_cancel->uac[i].request )!=0) + if(start_retr(&t_cancel->uac[i].request) != 0) LM_CRIT("BUG: failed to start retr." - " for %p\n", &t_cancel->uac[i].request); + " for %p\n", + &t_cancel->uac[i].request); } else { /* No provisional response received, stop * retransmission timers */ - if (!(cfg_get(tm, tm_cfg, cancel_b_flags) - & F_CANCEL_B_FORCE_RETR)) + if(!(cfg_get(tm, tm_cfg, cancel_b_flags) + & F_CANCEL_B_FORCE_RETR)) stop_rb_retr(&t_invite->uac[i].request); /* no need to stop fr, it will be stopped by relay_reply * put_on_wait -- andrei */ /* Generate faked reply */ - if (cfg_get(tm, tm_cfg, cancel_b_flags) & - F_CANCEL_B_FAKE_REPLY){ + if(cfg_get(tm, tm_cfg, cancel_b_flags) + & F_CANCEL_B_FAKE_REPLY) { LOCK_REPLIES(t_invite); - reply_status = relay_reply(t_invite, FAKED_REPLY, i, - 487, &tmp_bm, 1); + reply_status = relay_reply( + t_invite, FAKED_REPLY, i, 487, &tmp_bm, 1); if(reply_status == RPS_ERROR) { lowest_error = -1; } else if(reply_status == RPS_TGONE) { @@ -1428,17 +1426,17 @@ void e2e_cancel( struct sip_msg *cancel_msg, /* if error occurred, let it know upstream (final reply * will also move the transaction on wait state */ - if (lowest_error<0) { + if(lowest_error < 0) { LM_ERR("cancel error\n"); /* if called from failure_route, make sure that the unsafe version * is called (we are already holding the reply mutex for the cancel * transaction). */ - if ((is_route_type(FAILURE_ROUTE)) && (t_cancel==get_t())) - t_reply_unsafe( t_cancel, cancel_msg, 500, "cancel error"); + if((is_route_type(FAILURE_ROUTE)) && (t_cancel == get_t())) + t_reply_unsafe(t_cancel, cancel_msg, 500, "cancel error"); else - t_reply( t_cancel, cancel_msg, 500, "cancel error"); - } else if (cancel_bm) { + t_reply(t_cancel, cancel_msg, 500, "cancel error"); + } else if(cancel_bm) { /* if there are pending branches, let upstream know we * are working on it */ @@ -1447,10 +1445,10 @@ void e2e_cancel( struct sip_msg *cancel_msg, * is called (we are already hold the reply mutex for the cancel * transaction). */ - if ((is_route_type(FAILURE_ROUTE)) && (t_cancel==get_t())) - t_reply_unsafe( t_cancel, cancel_msg, 200, CANCELING ); + if((is_route_type(FAILURE_ROUTE)) && (t_cancel == get_t())) + t_reply_unsafe(t_cancel, cancel_msg, 200, CANCELING); else - t_reply( t_cancel, cancel_msg, 200, CANCELING ); + t_reply(t_cancel, cancel_msg, 200, CANCELING); } else { /* if the transaction exists, but there are no more pending * branches, tell upstream we're done @@ -1460,15 +1458,14 @@ void e2e_cancel( struct sip_msg *cancel_msg, * is called (we are already hold the reply mutex for the cancel * transaction). */ - if ((is_route_type(FAILURE_ROUTE)) && (t_cancel==get_t())) - t_reply_unsafe( t_cancel, cancel_msg, 200, CANCEL_DONE ); + if((is_route_type(FAILURE_ROUTE)) && (t_cancel == get_t())) + t_reply_unsafe(t_cancel, cancel_msg, 200, CANCEL_DONE); else - t_reply( t_cancel, cancel_msg, 200, CANCEL_DONE ); + t_reply(t_cancel, cancel_msg, 200, CANCEL_DONE); } } - /* sends one uac/branch buffer and fallbacks to other ips if * the destination resolves to several addresses * Takes care of starting timers a.s.o. (on send success) @@ -1478,36 +1475,36 @@ void e2e_cancel( struct sip_msg *cancel_msg, * if lock_replies is 1, the replies for t will be locked when adding * new branches (to prevent races). Use 0 from failure routes or other * places where the reply lock is already held, to avoid deadlocks. */ -int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg , - struct proxy_l * proxy, int lock_replies) +int t_send_branch(struct cell *t, int branch, struct sip_msg *p_msg, + struct proxy_l *proxy, int lock_replies) { struct ip_addr ip; /* debugging */ int ret; - struct ua_client* uac; + struct ua_client *uac; - uac=&t->uac[branch]; - ret=branch; - if (run_onsend(p_msg, &uac->request.dst, uac->request.buffer, - uac->request.buffer_len)==0){ + uac = &t->uac[branch]; + ret = branch; + if(run_onsend(p_msg, &uac->request.dst, uac->request.buffer, + uac->request.buffer_len) + == 0) { /* disable the current branch: set a "fake" timeout * reply code but don't set uac->reply, to avoid overriding * a higly unlikely, perfectly timed fake reply (to a message * we never sent). * (code=final reply && reply==0 => t_pick_branch won't ever pick it)*/ - uac->last_received=408; + uac->last_received = 408; su2ip_addr(&ip, &uac->request.dst.to); - LM_DBG("onsend_route dropped msg. to %s:%d (%d)\n", - ip_addr2a(&ip), su_getport(&uac->request.dst.to), - uac->request.dst.proto); + LM_DBG("onsend_route dropped msg. to %s:%d (%d)\n", ip_addr2a(&ip), + su_getport(&uac->request.dst.to), uac->request.dst.proto); #ifdef USE_DNS_FAILOVER /* if the destination resolves to more ips, add another * branch/uac */ - if (cfg_get(core, core_cfg, use_dns_failover)){ - ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies); - if (ret>=0){ + if(cfg_get(core, core_cfg, use_dns_failover)) { + ret = add_uac_dns_fallback(t, p_msg, uac, lock_replies); + if(ret >= 0) { su2ip_addr(&ip, &uac->request.dst.to); LM_DBG("send on branch %d failed " - "(onsend_route), trying another ip %s:%d (%d)\n", + "(onsend_route), trying another ip %s:%d (%d)\n", branch, ip_addr2a(&ip), su_getport(&uac->request.dst.to), uac->request.dst.proto); @@ -1515,85 +1512,86 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg , return ret; } } -#endif /* USE_DNS_FAILOVER*/ +#endif /* USE_DNS_FAILOVER*/ return -1; /* drop, try next branch */ } #ifdef USE_DST_BLOCKLIST - if (cfg_get(core, core_cfg, use_dst_blocklist) - && p_msg + if(cfg_get(core, core_cfg, use_dst_blocklist) && p_msg && (p_msg->REQ_METHOD - & cfg_get(tm, tm_cfg, tm_blst_methods_lookup)) - ){ - if (dst_is_blocklisted(&uac->request.dst, p_msg)){ + & cfg_get(tm, tm_cfg, tm_blst_methods_lookup))) { + if(dst_is_blocklisted(&uac->request.dst, p_msg)) { su2ip_addr(&ip, &uac->request.dst.to); - LM_DBG("blocklisted destination: %s:%d (%d)\n", - ip_addr2a(&ip), su_getport(&uac->request.dst.to), - uac->request.dst.proto); + LM_DBG("blocklisted destination: %s:%d (%d)\n", ip_addr2a(&ip), + su_getport(&uac->request.dst.to), uac->request.dst.proto); /* disable the current branch: set a "fake" timeout * reply code but don't set uac->reply, to avoid overriding * a higly unlikely, perfectly timed fake reply (to a message * we never sent). (code=final reply && reply==0 => * t_pick_branch won't ever pick it)*/ - uac->last_received=408; + uac->last_received = 408; #ifdef USE_DNS_FAILOVER /* if the destination resolves to more ips, add another * branch/uac */ - if (cfg_get(core, core_cfg, use_dns_failover)){ - ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies); - if (ret>=0){ + if(cfg_get(core, core_cfg, use_dns_failover)) { + ret = add_uac_dns_fallback(t, p_msg, uac, lock_replies); + if(ret >= 0) { su2ip_addr(&ip, &uac->request.dst.to); LM_DBG("send on branch %d failed (blocklist)," - " trying another ip %s:%d (%d)\n", branch, - ip_addr2a(&ip), su_getport(&uac->request.dst.to), + " trying another ip %s:%d (%d)\n", + branch, ip_addr2a(&ip), + su_getport(&uac->request.dst.to), uac->request.dst.proto); /* success, return new branch */ return ret; } } -#endif /* USE_DNS_FAILOVER*/ +#endif /* USE_DNS_FAILOVER*/ return -1; /* don't send */ } } #endif /* USE_DST_BLOCKLIST */ - if (SEND_BUFFER( &uac->request)==-1) { + if(SEND_BUFFER(&uac->request) == -1) { /* disable the current branch: set a "fake" timeout * reply code but don't set uac->reply, to avoid overriding * a highly unlikely, perfectly timed fake reply (to a message * we never sent). * (code=final reply && reply==0 => t_pick_branch won't ever pick it)*/ - uac->last_received=408; + uac->last_received = 408; su2ip_addr(&ip, &uac->request.dst.to); - LM_DBG("send to %s:%d (%d) failed\n", - ip_addr2a(&ip), su_getport(&uac->request.dst.to), - uac->request.dst.proto); + LM_DBG("send to %s:%d (%d) failed\n", ip_addr2a(&ip), + su_getport(&uac->request.dst.to), uac->request.dst.proto); #ifdef USE_DST_BLOCKLIST dst_blocklist_add(BLST_ERR_SEND, &uac->request.dst, p_msg); #endif #ifdef USE_DNS_FAILOVER /* if the destination resolves to more ips, add another * branch/uac */ - if (cfg_get(core, core_cfg, use_dns_failover)){ - ret=add_uac_dns_fallback(t, p_msg, uac, lock_replies); - if (ret>=0){ + if(cfg_get(core, core_cfg, use_dns_failover)) { + ret = add_uac_dns_fallback(t, p_msg, uac, lock_replies); + if(ret >= 0) { /* success, return new branch */ LM_DBG("send on branch %d failed, adding another" - " branch with another ip\n", branch); + " branch with another ip\n", + branch); return ret; } } #endif uac->icode = 908; /* internal code set to delivery failure */ LM_WARN("sending request on branch %d failed\n", branch); - if (proxy) { proxy->errors++; proxy->ok=0; } - if(tm_failure_exec_mode==1) { + if(proxy) { + proxy->errors++; + proxy->ok = 0; + } + if(tm_failure_exec_mode == 1) { LM_DBG("putting branch %d on hold \n", branch); /* put on retransmission timer, * but set proto to NONE, so actually it is not trying to resend */ uac->request.dst.proto = PROTO_NONE; /* reset last_received, 408 reply is faked by timer */ - uac->last_received=0; + uac->last_received = 0; /* add to retransmission timer */ - if (start_retr( &uac->request )!=0){ + if(start_retr(&uac->request) != 0) { LM_CRIT("BUG: retransmission already started for %p\n", &uac->request); return -2; @@ -1602,11 +1600,11 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg , } return -2; } else { - if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))) - run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, &uac->request, - p_msg, 0, TMCB_NONE_F); + if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))) + run_trans_callbacks_with_buf( + TMCB_REQUEST_SENT, &uac->request, p_msg, 0, TMCB_NONE_F); /* start retr. only if the send succeeded */ - if (start_retr( &uac->request )!=0){ + if(start_retr(&uac->request) != 0) { LM_CRIT("BUG: retransmission already started for: %p\n", &uac->request); return -2; @@ -1616,16 +1614,15 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg , } - /* function returns: * 1 - forward successful * -1 - error during forward */ -int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, - struct proxy_l * proxy, int proto) +int t_forward_nonack( + struct cell *t, struct sip_msg *p_msg, struct proxy_l *proxy, int proto) { int branch_ret, lowest_ret; - branch_bm_t added_branches; + branch_bm_t added_branches; int first_branch; int i; struct cell *t_invite; @@ -1637,12 +1634,13 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, getbflagsval(0, &backup_bflags); - if (t->flags & T_CANCELED) goto canceled; + if(t->flags & T_CANCELED) + goto canceled; - if (p_msg->REQ_METHOD==METHOD_CANCEL) { - t_invite=t_lookupOriginalT( p_msg ); - if (t_invite!=T_NULL_CELL) { - e2e_cancel( p_msg, t, t_invite ); + if(p_msg->REQ_METHOD == METHOD_CANCEL) { + t_invite = t_lookupOriginalT(p_msg); + if(t_invite != T_NULL_CELL) { + e2e_cancel(p_msg, t, t_invite); UNREF(t_invite); /* it should be set to REQ_RPLD by e2e_cancel, which should * send a final reply */ @@ -1652,13 +1650,13 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, } /* if no more specific error code is known, use this */ - lowest_ret=E_UNSPEC; + lowest_ret = E_UNSPEC; /* branches added */ - added_branches=0; + added_branches = 0; /* branch to begin with */ - first_branch=t->nr_of_outgoings; + first_branch = t->nr_of_outgoings; - if (t->on_branch) { + if(t->on_branch) { /* tell add_uac that it should run branch route actions */ branch_route = t->on_branch; /* save the branch route so that it @@ -1674,10 +1672,10 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, } /* on first-time forwarding, update the lumps */ - if (first_branch==0) { + if(first_branch == 0) { /* update the shmem-ized msg with the lumps */ - if ((is_route_type(REQUEST_ROUTE)) && - save_msg_lumps(t->uas.request, p_msg)) { + if((is_route_type(REQUEST_ROUTE)) + && save_msg_lumps(t->uas.request, p_msg)) { LM_ERR("failed to save the message lumps\n"); return -1; } @@ -1687,51 +1685,54 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, * uri too. Else add only additional branches (which may be continuously * refilled). */ - if (ruri_get_forking_state()) { - try_new=1; - branch_ret=add_uac(t, p_msg, GET_RURI(p_msg), GET_NEXT_HOP(p_msg), + if(ruri_get_forking_state()) { + try_new = 1; + branch_ret = add_uac(t, p_msg, GET_RURI(p_msg), GET_NEXT_HOP(p_msg), &p_msg->path_vec, proxy, p_msg->force_send_socket, p_msg->fwd_send_flags, proto, - (p_msg->dst_uri.len)?0:UAC_SKIP_BR_DST_F, &p_msg->instance, + (p_msg->dst_uri.len) ? 0 : UAC_SKIP_BR_DST_F, &p_msg->instance, &p_msg->ruid, &p_msg->location_ua); /* test if cancel was received meanwhile */ - if (t->flags & T_CANCELED) goto canceled; - if (branch_ret>=0) { - added_branches |= 1<flags & T_CANCELED) + goto canceled; + if(branch_ret >= 0) { + added_branches |= 1 << branch_ret; if(p_msg->msg_flags & FL_USE_OTCPID) { t->uac[branch_ret].request.dst.id = p_msg->otcpid; } } else { - lowest_ret=MIN_int(lowest_ret, branch_ret); + lowest_ret = MIN_int(lowest_ret, branch_ret); } } else { - try_new=0; + try_new = 0; } memset(&obranch, 0, sizeof(branch_data_t)); init_branch_iterator(); - while(next_branch_data(&obranch)==1) { + while(next_branch_data(&obranch) == 1) { try_new++; setbflagsval(0, obranch.flags); - branch_ret=add_uac(t, p_msg, &obranch.uri, - (obranch.dst_uri.len>0) ? &obranch.dst_uri : &obranch.uri, - &obranch.path, proxy, obranch.force_socket, p_msg->fwd_send_flags, - proto, (obranch.dst_uri.len>0)?0:UAC_SKIP_BR_DST_F, + branch_ret = add_uac(t, p_msg, &obranch.uri, + (obranch.dst_uri.len > 0) ? &obranch.dst_uri : &obranch.uri, + &obranch.path, proxy, obranch.force_socket, + p_msg->fwd_send_flags, proto, + (obranch.dst_uri.len > 0) ? 0 : UAC_SKIP_BR_DST_F, &obranch.instance, &obranch.ruid, &obranch.location_ua); /* test if cancel was received meanwhile */ - if (t->flags & T_CANCELED) goto canceled; + if(t->flags & T_CANCELED) + goto canceled; /* pick some of the errors in case things go wrong; * note that picking lowest error is just as good as * any other algorithm which picks any other negative * branch result */ - if (branch_ret>=0) { - added_branches |= 1<= 0) { + added_branches |= 1 << branch_ret; if(p_msg->msg_flags & FL_USE_OTCPID) { t->uac[branch_ret].request.dst.id = p_msg->otcpid; } } else { - lowest_ret=MIN_int(lowest_ret, branch_ret); + lowest_ret = MIN_int(lowest_ret, branch_ret); } } /* consume processed branches */ @@ -1740,60 +1741,59 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, setbflagsval(0, backup_bflags); /* update message flags, if changed in branch route */ - if(t->uas.request) t->uas.request->flags = p_msg->flags; + if(t->uas.request) + t->uas.request->flags = p_msg->flags; /* don't forget to clear all branches processed so far */ /* things went wrong ... no new branch has been fwd-ed at all */ - if (added_branches==0) { - if (try_new==0) { + if(added_branches == 0) { + if(try_new == 0) { LM_ERR("no branches for forwarding\n"); /* either failed to add branches, or there were no more branches */ - ser_error=MIN_int(lowest_ret, E_CFG); + ser_error = MIN_int(lowest_ret, E_CFG); return -1; } - if(lowest_ret!=E_CFG) + if(lowest_ret != E_CFG) LM_ERR("failure to add branches\n"); - ser_error=lowest_ret; + ser_error = lowest_ret; return lowest_ret; } /* mark the fist branch in this fwd step */ t->uac[first_branch].flags |= TM_UAC_FLAG_FB; - ser_error=0; /* clear branch adding errors */ + ser_error = 0; /* clear branch adding errors */ /* send them out now */ - success_branch=0; - lock_replies= ! ((is_route_type(FAILURE_ROUTE)) && (t==get_t())); - for (i=first_branch; inr_of_outgoings; i++) { - if (added_branches & (1<=0){ /* some kind of success */ - if (branch_ret==i) { /* success */ + success_branch = 0; + lock_replies = !((is_route_type(FAILURE_ROUTE)) && (t == get_t())); + for(i = first_branch; i < t->nr_of_outgoings; i++) { + if(added_branches & (1 << i)) { + + branch_ret = t_send_branch(t, i, p_msg, proxy, lock_replies); + 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[i].request, - p_msg, 0, TMCB_NONE_F); - } - else /* new branch added */ - added_branches |= 1<uac[i].request, p_msg, 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 (?) */ /* the caller should take care and delete the transaction */ return -1; } - 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); return 1; @@ -1804,13 +1804,13 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, /* restore backup flags from initial env */ setbflagsval(0, backup_bflags); /* update message flags, if changed in branch route */ - if(t->uas.request) t->uas.request->flags = p_msg->flags; - ser_error=E_CANCELED; + if(t->uas.request) + t->uas.request->flags = p_msg->flags; + ser_error = E_CANCELED; return -1; } - /* cancel handling/forwarding function * CANCELs with no matching transaction are handled in function of * the unmatched_cancel config var: they are either forwarded statefully, @@ -1821,11 +1821,11 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg, * <0 - error during forward * it also sets *tran if a transaction was created */ -int t_forward_cancel(struct sip_msg* p_msg , struct proxy_l * proxy, int proto, - struct cell** tran) +int t_forward_cancel(struct sip_msg *p_msg, struct proxy_l *proxy, int proto, + struct cell **tran) { - struct cell* t_invite; - struct cell* t; + struct cell *t_invite; + struct cell *t; int ret; int new_tran; struct dest_info dst; @@ -1833,80 +1833,81 @@ int t_forward_cancel(struct sip_msg* p_msg , struct proxy_l * proxy, int proto, unsigned short port; short comp; - t=0; + t = 0; /* handle cancels for which no transaction was created yet */ - if (cfg_get(tm, tm_cfg, unmatched_cancel)==UM_CANCEL_STATEFULL){ + if(cfg_get(tm, tm_cfg, unmatched_cancel) == UM_CANCEL_STATEFULL) { /* create cancel transaction */ - new_tran=t_newtran(p_msg); - if (new_tran<=0 && new_tran!=E_SCRIPT){ - if (new_tran==0) + new_tran = t_newtran(p_msg); + if(new_tran <= 0 && new_tran != E_SCRIPT) { + if(new_tran == 0) /* retransmission => do nothing */ - ret=1; + ret = 1; else /* some error => return it or DROP */ - ret=(ser_error==E_BAD_VIA && reply_to_via) ? 0: new_tran; + ret = (ser_error == E_BAD_VIA && reply_to_via) ? 0 : new_tran; goto end; } - t=get_t(); - ret=t_forward_nonack(t, p_msg, proxy, proto); + t = get_t(); + ret = t_forward_nonack(t, p_msg, proxy, proto); goto end; } - t_invite=t_lookupOriginalT( p_msg ); - if (t_invite!=T_NULL_CELL) { + t_invite = t_lookupOriginalT(p_msg); + if(t_invite != T_NULL_CELL) { /* create cancel transaction */ - new_tran=t_newtran(p_msg); - if (new_tran<=0 && new_tran!=E_SCRIPT){ - if (new_tran==0) + new_tran = t_newtran(p_msg); + if(new_tran <= 0 && new_tran != E_SCRIPT) { + if(new_tran == 0) /* retransmission => do nothing */ - ret=1; + ret = 1; else /* some error => return it or DROP */ - ret=(ser_error==E_BAD_VIA && reply_to_via) ? 0: new_tran; + ret = (ser_error == E_BAD_VIA && reply_to_via) ? 0 : new_tran; UNREF(t_invite); goto end; } - t=get_t(); - e2e_cancel( p_msg, t, t_invite ); + t = get_t(); + e2e_cancel(p_msg, t, t_invite); UNREF(t_invite); - ret=1; + ret = 1; goto end; - }else /* no coresponding INVITE transaction */ - if (cfg_get(tm, tm_cfg, unmatched_cancel)==UM_CANCEL_DROP){ + } else /* no coresponding INVITE transaction */ + if(cfg_get(tm, tm_cfg, unmatched_cancel) == UM_CANCEL_DROP) { LM_DBG("non matching cancel dropped\n"); - ret=1; /* do nothing -> drop */ + ret = 1; /* do nothing -> drop */ goto end; - }else{ + } else { /* UM_CANCEL_STATELESS -> stateless forward */ LM_DBG("forwarding CANCEL statelessly \n"); - if (proxy==0) { + if(proxy == 0) { init_dest_info(&dst); - dst.proto=proto; - if (get_uri_send_info(GET_NEXT_HOP(p_msg), &host, - &port, &dst.proto, &comp)!=0){ - ret=E_BAD_ADDRESS; + dst.proto = proto; + if(get_uri_send_info( + GET_NEXT_HOP(p_msg), &host, &port, &dst.proto, &comp) + != 0) { + ret = E_BAD_ADDRESS; goto end; } #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); goto end; } else { init_dest_info(&dst); - 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); goto end; } } end: - if (tran) - *tran=t; + if(tran) + *tran = t; return ret; } @@ -1920,37 +1921,37 @@ int t_forward_cancel(struct sip_msg* p_msg , struct proxy_l * proxy, int proto, * 1: no corresponding INVITE transaction exisis * <0: corresponding INVITE transaction exisis but error occurred */ -int t_relay_cancel(struct sip_msg* p_msg) +int t_relay_cancel(struct sip_msg *p_msg) { - struct cell* t_invite; - struct cell* t; + struct cell *t_invite; + struct cell *t; int ret; int new_tran; - t_invite=t_lookupOriginalT( p_msg ); - if (t_invite!=T_NULL_CELL) { + t_invite = t_lookupOriginalT(p_msg); + if(t_invite != T_NULL_CELL) { /* create cancel transaction */ - new_tran=t_newtran(p_msg); - if (new_tran<=0 && new_tran!=E_SCRIPT){ - if (new_tran==0) + new_tran = t_newtran(p_msg); + if(new_tran <= 0 && new_tran != E_SCRIPT) { + if(new_tran == 0) /* retransmission => DROP, t_newtran() takes care about it */ - ret=0; + ret = 0; else /* some error => return it or DROP */ - ret=(ser_error==E_BAD_VIA && reply_to_via) ? 0: new_tran; + ret = (ser_error == E_BAD_VIA && reply_to_via) ? 0 : new_tran; UNREF(t_invite); goto end; } - t=get_t(); - e2e_cancel( p_msg, t, t_invite ); + t = get_t(); + e2e_cancel(p_msg, t, t_invite); UNREF(t_invite); /* return 0 to stop the script processing */ - ret=0; + ret = 0; goto end; } else { /* no corresponding INVITE trasaction found */ - ret=1; + ret = 1; } end: return ret; @@ -1958,7 +1959,7 @@ int t_relay_cancel(struct sip_msg* p_msg) /* WARNING: doesn't work from failure route (deadlock, uses t_relay_to which * is failure route unsafe) */ -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) { /* this is a quite tricky hack -- we just take the message * as is, including Route-s, Record-route-s, and Vias , @@ -1974,10 +1975,11 @@ int t_replicate(struct sip_msg *p_msg, struct proxy_l *proxy, int proto ) } /* fixup function for reparse_on_dns_failover modparam */ -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) { #ifdef USE_DNS_FAILOVER - if ((int)(long)(*val) && mhomed) { + if((int)(long)(*val) && mhomed) { LM_WARN("reparse_on_dns_failover is enabled on" " a multihomed host -- check the readme of tm module!\n"); } diff --git a/src/modules/tm/t_fwd.h b/src/modules/tm/t_fwd.h index e44e8f57ba1..22a9ff43d42 100644 --- a/src/modules/tm/t_fwd.h +++ b/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 - - diff --git a/src/modules/tm/t_hooks.c b/src/modules/tm/t_hooks.c index b8418e5cb5e..d795272f7e0 100644 --- a/src/modules/tm/t_hooks.c +++ b/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 (¶ms, 0, sizeof(params)); + memset(¶ms, 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, ¶ms); } -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 (¶ms, 0, sizeof(params)); + memset(¶ms, 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 (¶ms, 0, sizeof(params)); + memset(¶ms, 0, sizeof(params)); params.req = req; params.code = code; diff --git a/src/modules/tm/t_hooks.h b/src/modules/tm/t_hooks.h index c13ab092dea..ff040ba20f7 100644 --- a/src/modules/tm/t_hooks.h +++ b/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_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 diff --git a/src/modules/tm/t_lookup.c b/src/modules/tm/t_lookup.c index 70574eb3237..a0d48cd7b05 100644 --- a/src/modules/tm/t_lookup.c +++ b/src/modules/tm/t_lookup.c @@ -58,32 +58,35 @@ #include "t_hooks.h" #include "t_fwd.h" #include "t_lookup.h" -#include "dlg.h" /* for t_lookup_callid */ +#include "dlg.h" /* for t_lookup_callid */ #include "t_msgbuilder.h" /* for t_lookup_callid */ -#define EQ_VIA_LEN(_via)\ - ( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\ - (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) ) - - - -#define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len) -#define EQ_REQ_URI_LEN\ - (p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len) - -#define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s,\ - p_msg->_hf->body.s, \ - p_msg->_hf->body.len)==0) -#define EQ_REQ_URI_STR\ - ( memcmp( t_msg->first_line.u.request.uri.s,\ - p_msg->first_line.u.request.uri.s,\ - p_msg->first_line.u.request.uri.len)==0) -#define EQ_VIA_STR(_via)\ - ( memcmp( t_msg->_via->name.s,\ - p_msg->_via->name.s,\ - (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\ - )==0 ) - +#define EQ_VIA_LEN(_via) \ + ((p_msg->via1->bsize \ + - (p_msg->_via->name.s \ + - (p_msg->_via->hdr.s + p_msg->_via->hdr.len))) \ + == (t_msg->via1->bsize \ + - (t_msg->_via->name.s \ + - (t_msg->_via->hdr.s + t_msg->_via->hdr.len)))) + + +#define EQ_LEN(_hf) (t_msg->_hf->body.len == p_msg->_hf->body.len) +#define EQ_REQ_URI_LEN \ + (p_msg->first_line.u.request.uri.len == t_msg->first_line.u.request.uri.len) + +#define EQ_STR(_hf) \ + (memcmp(t_msg->_hf->body.s, p_msg->_hf->body.s, p_msg->_hf->body.len) == 0) +#define EQ_REQ_URI_STR \ + (memcmp(t_msg->first_line.u.request.uri.s, \ + p_msg->first_line.u.request.uri.s, \ + p_msg->first_line.u.request.uri.len) \ + == 0) +#define EQ_VIA_STR(_via) \ + (memcmp(t_msg->_via->name.s, p_msg->_via->name.s, \ + (t_msg->via1->bsize \ + - (t_msg->_via->name.s \ + - (t_msg->_via->hdr.s + t_msg->_via->hdr.len)))) \ + == 0) #define HF_LEN(_hf) ((_hf)->len) @@ -121,7 +124,7 @@ static int T_branch = 0; * on a current transaction or a new message arrived; * don't even think of changing it. */ -msg_ctx_id_t tm_global_ctx_id = { 0 }; +msg_ctx_id_t tm_global_ctx_id = {0}; struct cell *get_t() @@ -131,13 +134,14 @@ struct cell *get_t() void set_t(struct cell *t, int branch) { - T=t; T_branch=branch; + T = t; + T_branch = branch; } void init_t() { - tm_global_ctx_id.msgid=0; - tm_global_ctx_id.pid=0; + tm_global_ctx_id.msgid = 0; + tm_global_ctx_id.pid = 0; set_t(T_UNDEFINED, T_BR_UNDEFINED); } @@ -151,7 +155,7 @@ int get_t_branch() * - if T is not set, checks the transactions table for msg, and if found, * sets T and *branch as well as *vref=1 to signal that T was ref'ed */ -struct cell* t_find(struct sip_msg *msg, int *branch, int *vref) +struct cell *t_find(struct sip_msg *msg, int *branch, int *vref) { if(vref) { *vref = 0; @@ -177,22 +181,22 @@ void t_unset(void) return; } - UNREF( T ); + UNREF(T); set_t(T_UNDEFINED, T_BR_UNDEFINED); } -static inline int parse_dlg( struct sip_msg *msg ) +static inline int parse_dlg(struct sip_msg *msg) { - if (parse_headers(msg, HDR_FROM_F | HDR_CSEQ_F | HDR_TO_F, 0)==-1) { + if(parse_headers(msg, HDR_FROM_F | HDR_CSEQ_F | HDR_TO_F, 0) == -1) { LM_ERR("From or Cseq or To invalid\n"); return 0; } - if ((msg->from==0)||(msg->cseq==0)||(msg->to==0)) { + if((msg->from == 0) || (msg->cseq == 0) || (msg->to == 0)) { LM_ERR("missing From or Cseq or To\n"); return 0; } - if (parse_from_header(msg)==-1) { + if(parse_from_header(msg) == -1) { LM_ERR("From broken\n"); return 0; } @@ -201,58 +205,62 @@ static inline int parse_dlg( struct sip_msg *msg ) /* is the ACK (p_msg) in p_msg dialog-wise equal to the INVITE (t_msg) * except to-tags? */ -static inline int partial_dlg_matching(struct sip_msg *t_msg, struct sip_msg *p_msg) +static inline int partial_dlg_matching( + struct sip_msg *t_msg, struct sip_msg *p_msg) { struct to_body *inv_from; - if (!EQ_LEN(callid)) return 0; - if (get_cseq(t_msg)->number.len!=get_cseq(p_msg)->number.len) + if(!EQ_LEN(callid)) + return 0; + if(get_cseq(t_msg)->number.len != get_cseq(p_msg)->number.len) return 0; - inv_from=get_from(t_msg); - if (!inv_from) { + inv_from = get_from(t_msg); + if(!inv_from) { LM_ERR("INV/From not parsed\n"); return 0; } - if (inv_from->tag_value.len!=get_from(p_msg)->tag_value.len) + if(inv_from->tag_value.len != get_from(p_msg)->tag_value.len) return 0; - if (!EQ_STR(callid)) + if(!EQ_STR(callid)) return 0; - if (memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, - get_cseq(p_msg)->number.len)!=0) + if(memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, + get_cseq(p_msg)->number.len) + != 0) return 0; - if (memcmp(inv_from->tag_value.s, get_from(p_msg)->tag_value.s, - get_from(p_msg)->tag_value.len)!=0) + if(memcmp(inv_from->tag_value.s, get_from(p_msg)->tag_value.s, + get_from(p_msg)->tag_value.len) + != 0) return 0; return 1; } /* are to-tags in ACK/200 same as those we sent out? */ -static inline int dlg_matching(struct cell *p_cell, struct sip_msg *ack ) +static inline int dlg_matching(struct cell *p_cell, struct sip_msg *ack) { - if (get_to(ack)->tag_value.len!=p_cell->uas.local_totag.len) + if(get_to(ack)->tag_value.len != p_cell->uas.local_totag.len) return 0; - if (memcmp(get_to(ack)->tag_value.s,p_cell->uas.local_totag.s, - p_cell->uas.local_totag.len)!=0) + if(memcmp(get_to(ack)->tag_value.s, p_cell->uas.local_totag.s, + p_cell->uas.local_totag.len) + != 0) return 0; return 1; } - /* returns 2 if one of the save totags matches the totag in the current * message (which should be an ACK) and 0 if not */ -static inline int totag_e2e_ack_matching(struct cell* p_cell, - struct sip_msg *ack) +static inline int totag_e2e_ack_matching( + struct cell *p_cell, struct sip_msg *ack) { struct totag_elem *i; str *tag; - tag=&get_to(ack)->tag_value; + tag = &get_to(ack)->tag_value; /* no locking needed for reading/searching, see update_totag_set() */ - for (i=p_cell->fwded_totags; i; i=i->next){ + for(i = p_cell->fwded_totags; i; i = i->next) { membar_depends(); /* make sure we don't see some old i content * (needed on CPUs like Alpha) */ - if (i->tag.len==tag->len && memcmp(i->tag.s, tag->s, tag->len)==0) { + if(i->tag.len == tag->len && memcmp(i->tag.s, tag->s, tag->len) == 0) { return 2; } } @@ -260,7 +268,6 @@ static inline int totag_e2e_ack_matching(struct cell* p_cell, } - /* returns: 0 - no match * 1 - full match to a local transaction * 2 - full match to a proxied transaction @@ -272,16 +279,15 @@ static inline int ack_matching(struct cell *p_cell, struct sip_msg *p_msg) { /* partial dialog matching -- no to-tag, only from-tag, * callid, cseq number ; */ - if (!partial_dlg_matching(p_cell->uas.request, p_msg)) + if(!partial_dlg_matching(p_cell->uas.request, p_msg)) return 0; /* if this transaction is proxied (as opposed to UAS) we're * done now -- we ignore to-tags; the ACK simply belongs to * this UAS part of dialog, whatever to-tag it gained */ - if (likely(p_cell->relayed_reply_branch!=-2)) { - if (likely(has_tran_tmcbs(p_cell, - TMCB_E2EACK_IN|TMCB_E2EACK_RETR_IN))) + if(likely(p_cell->relayed_reply_branch != -2)) { + if(likely(has_tran_tmcbs(p_cell, TMCB_E2EACK_IN | TMCB_E2EACK_RETR_IN))) return totag_e2e_ack_matching(p_cell, p_msg); /* 2 or 0 */ else LM_WARN("attempted on" @@ -290,50 +296,49 @@ static inline int ack_matching(struct cell *p_cell, struct sip_msg *p_msg) return 3; /* e2e proxied ACK partial match */ } /* it's a local dialog -- we wish to verify to-tags too */ - if (dlg_matching(p_cell, p_msg)) { + if(dlg_matching(p_cell, p_msg)) { return 1; } return 0; } /* branch-based transaction matching */ -static inline int via_matching( struct via_body *inv_via, - struct via_body *ack_via ) +static inline int via_matching( + struct via_body *inv_via, struct via_body *ack_via) { - if (inv_via->tid.len!=ack_via->tid.len) + if(inv_via->tid.len != ack_via->tid.len) return 0; - if (memcmp(inv_via->tid.s, ack_via->tid.s, - ack_via->tid.len)!=0) + if(memcmp(inv_via->tid.s, ack_via->tid.s, ack_via->tid.len) != 0) return 0; /* ok, tid matches -- now make sure that the * originator matches too to avoid confusion with * different senders generating the same tid */ - if (inv_via->host.len!=ack_via->host.len) + if(inv_via->host.len != ack_via->host.len) return 0; - if (memcmp(inv_via->host.s, ack_via->host.s, - ack_via->host.len)!=0) + if(memcmp(inv_via->host.s, ack_via->host.s, ack_via->host.len) != 0) return 0; - if (inv_via->port!=ack_via->port) { - if(inv_via->port==0 - && ack_via->port!=SIP_PORT && ack_via->port!=SIPS_PORT) + if(inv_via->port != ack_via->port) { + if(inv_via->port == 0 && ack_via->port != SIP_PORT + && ack_via->port != SIPS_PORT) return 0; - if(ack_via->port==0 - && inv_via->port!=SIP_PORT && inv_via->port!=SIPS_PORT) + if(ack_via->port == 0 && inv_via->port != SIP_PORT + && inv_via->port != SIPS_PORT) return 0; } - if (inv_via->transport.len!=ack_via->transport.len) + if(inv_via->transport.len != ack_via->transport.len) return 0; - if (memcmp(inv_via->transport.s, ack_via->transport.s, - ack_via->transport.len)!=0) + if(memcmp(inv_via->transport.s, ack_via->transport.s, + ack_via->transport.len) + != 0) return 0; - if (inv_via->port!=ack_via->port - && (inv_via->port==0 || ack_via->port==0)) { + if(inv_via->port != ack_via->port + && (inv_via->port == 0 || ack_via->port == 0)) { /* test SIPS_PORT (5061) is used with TLS transport */ - if(inv_via->port==SIPS_PORT || ack_via->port==SIPS_PORT) { - if(inv_via->transport.len!=3 - || memcmp(inv_via->transport.s, "TLS", 3)!=0) { + if(inv_via->port == SIPS_PORT || ack_via->port == SIPS_PORT) { + if(inv_via->transport.len != 3 + || memcmp(inv_via->transport.s, "TLS", 3) != 0) { return 0; } } @@ -353,37 +358,39 @@ static inline int via_matching( struct via_body *inv_via, * It also sets *cancel if a cancel was found for the searched transaction */ -static int matching_3261( struct sip_msg *p_msg, struct cell **trans, - enum request_method skip_method, int* cancel) +static int matching_3261(struct sip_msg *p_msg, struct cell **trans, + enum request_method skip_method, int *cancel) { struct cell *p_cell; struct cell *e2e_ack_trans; - struct sip_msg *t_msg; + struct sip_msg *t_msg; struct via_body *via1; int is_ack; int dlg_parsed; int ret = 0; - struct entry* hash_bucket; + struct entry *hash_bucket; - *cancel=0; - e2e_ack_trans=0; - via1=p_msg->via1; - is_ack=p_msg->REQ_METHOD==METHOD_ACK; - dlg_parsed=0; + *cancel = 0; + e2e_ack_trans = 0; + via1 = p_msg->via1; + is_ack = p_msg->REQ_METHOD == METHOD_ACK; + dlg_parsed = 0; /* update parsed tid */ - via1->tid.s=via1->branch->value.s+MCOOKIE_LEN; - via1->tid.len=via1->branch->value.len-MCOOKIE_LEN; + via1->tid.s = via1->branch->value.s + MCOOKIE_LEN; + via1->tid.len = via1->branch->value.len - MCOOKIE_LEN; - hash_bucket=&(get_tm_table()->entries[p_msg->hash_index]); - clist_foreach(hash_bucket, p_cell, next_c){ + hash_bucket = &(get_tm_table()->entries[p_msg->hash_index]); + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); - t_msg=p_cell->uas.request; - if (unlikely(!t_msg)) continue;/*don't try matching UAC transactions */ + t_msg = p_cell->uas.request; + if(unlikely(!t_msg)) + continue; /*don't try matching UAC transactions */ /* we want to set *cancel for transaction for which there is * already a canceled transaction (e.g. re-ordered INV-CANCEL, or * INV blocked in dns lookup); we don't care about ACKs */ - if ((is_ack || (t_msg->REQ_METHOD!=METHOD_CANCEL)) && - (skip_method & t_msg->REQ_METHOD)) + if((is_ack || (t_msg->REQ_METHOD != METHOD_CANCEL)) + && (skip_method & t_msg->REQ_METHOD)) continue; /* here we do an exercise which will be removed from future code @@ -402,21 +409,21 @@ static int matching_3261( struct sip_msg *p_msg, struct cell **trans, /* dialog matching needs to be applied for ACK/200s but only if * this is a local transaction or its a proxied transaction interested * in e2e ACKs (has E2EACK* callbacks installed) */ - if (unlikely(is_ack && p_cell->uas.status<300)) { - if (unlikely(has_tran_tmcbs(p_cell, - TMCB_E2EACK_IN|TMCB_E2EACK_RETR_IN) || - (p_cell->relayed_reply_branch==-2) )) { + if(unlikely(is_ack && p_cell->uas.status < 300)) { + if(unlikely(has_tran_tmcbs( + p_cell, TMCB_E2EACK_IN | TMCB_E2EACK_RETR_IN) + || (p_cell->relayed_reply_branch == -2))) { /* make sure we have parsed all things we need for dialog * matching */ - if (!dlg_parsed) { - dlg_parsed=1; - if (unlikely(!parse_dlg(p_msg))) { + if(!dlg_parsed) { + dlg_parsed = 1; + if(unlikely(!parse_dlg(p_msg))) { LOG(L_INFO, "dlg parsing failed\n"); return 0; } } - ret=ack_matching(p_cell /* t w/invite */, p_msg /* ack */); - if (unlikely(ret>0)) { + ret = ack_matching(p_cell /* t w/invite */, p_msg /* ack */); + if(unlikely(ret > 0)) { /* if ret==1 => fully matching e2e ack for local trans * if ret==2 => matching e2e ack for proxied transaction. * which is interested in it (E2EACK* callbacks) @@ -424,14 +431,15 @@ static int matching_3261( struct sip_msg *p_msg, struct cell **trans, * make sure the ACK is not for a negative reply * (FIXME: ret==3 should never happen, it's a bug catch * case)*/ - if (unlikely(ret==1)) goto found; - if (unlikely(ret==3)){ - if (e2e_ack_trans==0) - e2e_ack_trans=p_cell; + if(unlikely(ret == 1)) + goto found; + if(unlikely(ret == 3)) { + if(e2e_ack_trans == 0) + e2e_ack_trans = p_cell; continue; /* maybe we get a better * match for a neg. replied trans. */ } - e2e_ack_trans=p_cell; + e2e_ack_trans = p_cell; goto e2eack_found; } /* this ACK is neither local "negative" one, nor a proxied @@ -446,35 +454,35 @@ static int matching_3261( struct sip_msg *p_msg, struct cell **trans, } /* now real tid matching occurs for negative ACKs and any * other requests */ - if (!via_matching(t_msg->via1 /* inv via */, via1 /* ack */ )) + if(!via_matching(t_msg->via1 /* inv via */, via1 /* ack */)) continue; /* check if call-id is still the same */ - if (cfg_get(tm, tm_cfg, callid_matching) - && !EQ_LEN(callid) && !EQ_STR(callid)) { + if(cfg_get(tm, tm_cfg, callid_matching) && !EQ_LEN(callid) + && !EQ_STR(callid)) { LM_ERR("matching transaction found but callids" - " don't match (received: %.*s stored: %.*s)\n", + " don't match (received: %.*s stored: %.*s)\n", p_msg->callid->body.len, p_msg->callid->body.s, t_msg->callid->body.len, t_msg->callid->body.s); continue; } - if (t_msg->REQ_METHOD==METHOD_CANCEL){ - if ((p_msg->REQ_METHOD!=METHOD_CANCEL) && !is_ack){ + if(t_msg->REQ_METHOD == METHOD_CANCEL) { + if((p_msg->REQ_METHOD != METHOD_CANCEL) && !is_ack) { /* found an existing cancel for the searched transaction */ - *cancel=1; + *cancel = 1; } - if (skip_method & t_msg->REQ_METHOD) { + if(skip_method & t_msg->REQ_METHOD) { LM_DBG("matched skip method - s:0x%x t:0x%x m:0x%x -" - " continue searching\n", + " continue searching\n", skip_method, t_msg->REQ_METHOD, p_msg->REQ_METHOD); continue; } } -found: + found: prefetch_w(p_cell); /* great chance of modifiying it */ /* all matched -- we found the transaction ! */ - LM_DBG("RFC3261 transaction matched, tid=%.*s\n", - via1->tid.len, via1->tid.s); - *trans=p_cell; + LM_DBG("RFC3261 transaction matched, tid=%.*s\n", via1->tid.len, + via1->tid.s); + *trans = p_cell; return 1; } /* ... we didn't find any */ @@ -483,9 +491,9 @@ static int matching_3261( struct sip_msg *p_msg, struct cell **trans, * (Note: this is not very reliable, since we match e2e proxy ACKs * w/o totag => for a pre-forked invite it might match the wrong * transaction) */ - if (e2e_ack_trans) { -e2eack_found: - *trans=e2e_ack_trans; + if(e2e_ack_trans) { + e2eack_found: + *trans = e2e_ack_trans; return 2; } LM_DBG("RFC3261 transaction matching failed - via branch [%.*s]\n", @@ -499,34 +507,33 @@ static int matching_3261( struct sip_msg *p_msg, struct cell **trans, * 0 - transaction found (and referenced) */ -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) { - struct cell *p_cell; - unsigned int isACK; - struct sip_msg *t_msg; + struct cell *p_cell; + unsigned int isACK; + struct sip_msg *t_msg; struct via_param *branch; int match_status; struct cell *e2e_ack_trans; - struct entry* hash_bucket; + struct entry *hash_bucket; int cancel; *r_cell = NULL; /* parse all*/ - if (unlikely(check_transaction_quadruple(p_msg)==0)) { + if(unlikely(check_transaction_quadruple(p_msg) == 0)) { LM_ERR("too few headers\n"); /* stop processing */ return 0; } /* start searching into the table */ - if (!(p_msg->msg_flags & FL_HASH_INDEX)){ - p_msg->hash_index=hash( p_msg->callid->body , get_cseq(p_msg)->number); - p_msg->msg_flags|=FL_HASH_INDEX; + if(!(p_msg->msg_flags & FL_HASH_INDEX)) { + p_msg->hash_index = hash(p_msg->callid->body, get_cseq(p_msg)->number); + p_msg->msg_flags |= FL_HASH_INDEX; } - isACK = p_msg->REQ_METHOD==METHOD_ACK; - LM_DBG("start searching: hash=%d, isACK=%d\n", - p_msg->hash_index,isACK); + isACK = p_msg->REQ_METHOD == METHOD_ACK; + LM_DBG("start searching: hash=%d, isACK=%d\n", p_msg->hash_index, isACK); /* assume not found */ @@ -536,24 +543,26 @@ int t_request_search( struct sip_msg* p_msg, struct cell **r_cell) * so, we can do very quick matching and skip the old-RFC bizzar * comparison of many header fields */ - if (!p_msg->via1) { + if(!p_msg->via1) { LM_ERR("no via\n"); return 0; } - branch=p_msg->via1->branch; - if (branch && branch->value.s && branch->value.len>MCOOKIE_LEN - && memcmp(branch->value.s, MCOOKIE,MCOOKIE_LEN)==0) { + branch = p_msg->via1->branch; + if(branch && branch->value.s && branch->value.len > MCOOKIE_LEN + && memcmp(branch->value.s, MCOOKIE, MCOOKIE_LEN) == 0) { /* huhuhu! the cookie is there -- let's proceed fast */ LOCK_HASH(p_msg->hash_index); - match_status=matching_3261(p_msg,&p_cell, + match_status = matching_3261(p_msg, &p_cell, /* skip transactions with different method; otherwise CANCEL * would match the previous INVITE trans. */ - isACK ? ~METHOD_INVITE: ~p_msg->REQ_METHOD, - &cancel); + isACK ? ~METHOD_INVITE : ~p_msg->REQ_METHOD, &cancel); switch(match_status) { - case 0: goto notfound; /* no match */ - case 1: goto found; /* match */ - case 2: goto e2e_ack; /* e2e proxy ACK */ + case 0: + goto notfound; /* no match */ + case 1: + goto found; /* match */ + case 2: + goto e2e_ack; /* e2e proxy ACK */ } } @@ -564,44 +573,54 @@ int t_request_search( struct sip_msg* p_msg, struct cell **r_cell) /* lock the whole entry*/ LOCK_HASH(p_msg->hash_index); - hash_bucket=&(get_tm_table()->entries[p_msg->hash_index]); + hash_bucket = &(get_tm_table()->entries[p_msg->hash_index]); - if (likely(!isACK)) { + if(likely(!isACK)) { /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); t_msg = p_cell->uas.request; - if (!t_msg) continue; /* skip UAC transactions */ + if(!t_msg) + continue; /* skip UAC transactions */ /* for non-ACKs we want same method matching, we * make an exception for pre-exisiting CANCELs because we * want to set *cancel */ - if ((t_msg->REQ_METHOD!=p_msg->REQ_METHOD) && - (t_msg->REQ_METHOD!=METHOD_CANCEL)) + if((t_msg->REQ_METHOD != p_msg->REQ_METHOD) + && (t_msg->REQ_METHOD != METHOD_CANCEL)) continue; /* compare lengths first */ - if (!EQ_LEN(callid)) continue; + if(!EQ_LEN(callid)) + continue; /* CSeq only the number without method ! */ - if (get_cseq(t_msg)->number.len!=get_cseq(p_msg)->number.len) + if(get_cseq(t_msg)->number.len != get_cseq(p_msg)->number.len) continue; - if (!EQ_LEN(from)) continue; - if (!EQ_LEN(to)) continue; - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) + if(!EQ_LEN(from)) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) + if(!EQ_LEN(to)) + continue; + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) + continue; + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) continue; /* length ok -- move on */ - if (!EQ_STR(callid)) continue; - if (memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, - get_cseq(p_msg)->number.len)!=0) continue; - if (!EQ_STR(from)) continue; - if (!EQ_STR(to)) continue; - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) + if(!EQ_STR(callid)) + continue; + if(memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, + get_cseq(p_msg)->number.len) + != 0) + continue; + if(!EQ_STR(from)) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) + if(!EQ_STR(to)) + continue; + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) + continue; + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) continue; - if ((t_msg->REQ_METHOD==METHOD_CANCEL) && - (p_msg->REQ_METHOD!=METHOD_CANCEL)){ + if((t_msg->REQ_METHOD == METHOD_CANCEL) + && (p_msg->REQ_METHOD != METHOD_CANCEL)) { /* we've matched an existing CANCEL */ continue; } @@ -609,63 +628,74 @@ int t_request_search( struct sip_msg* p_msg, struct cell **r_cell) /* request matched ! */ LM_DBG("non-ACK matched\n"); goto found; - } /* synonym loop */ + } /* synonym loop */ } else { /* it's an ACK request*/ /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); t_msg = p_cell->uas.request; - if (!t_msg) continue; /* skip UAC transactions */ + if(!t_msg) + continue; /* skip UAC transactions */ /* ACK's relate only to INVITEs */ - if (t_msg->REQ_METHOD!=METHOD_INVITE) continue; + if(t_msg->REQ_METHOD != METHOD_INVITE) + continue; /* From|To URI , CallID, CSeq # must be always there */ /* compare lengths now */ - if (!EQ_LEN(callid)) continue; + if(!EQ_LEN(callid)) + continue; /* CSeq only the number without method ! */ - if (get_cseq(t_msg)->number.len!=get_cseq(p_msg)->number.len) + if(get_cseq(t_msg)->number.len != get_cseq(p_msg)->number.len) continue; /* To only the uri -- to many UACs screw up tags */ - if (get_to(t_msg)->uri.len!=get_to(p_msg)->uri.len) + if(get_to(t_msg)->uri.len != get_to(p_msg)->uri.len) + continue; + if(!EQ_STR(callid)) + continue; + if(memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, + get_cseq(p_msg)->number.len) + != 0) + continue; + if(memcmp(get_to(t_msg)->uri.s, get_to(p_msg)->uri.s, + get_to(t_msg)->uri.len) + != 0) continue; - if (!EQ_STR(callid)) continue; - if (memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, - get_cseq(p_msg)->number.len)!=0) continue; - if (memcmp(get_to(t_msg)->uri.s, get_to(p_msg)->uri.s, - get_to(t_msg)->uri.len)!=0) continue; /* it is e2e ACK/200 */ - if (p_cell->uas.status<300) { + if(p_cell->uas.status < 300) { /* For e2e ACKs, From's tag 'MUST' equal INVITE's, while use * of the URI in this case is to be deprecated (Sec. 12.2.1.1). * Comparing entire From body is dangerous, since some UAs * screw the display name up. */ - if (parse_from_header(p_msg) < 0) { + if(parse_from_header(p_msg) < 0) { LM_ERR("failed to parse From HF; ACK might not match.\n"); continue; } - if (! STR_EQ(get_from(t_msg)->tag_value, - get_from(p_msg)->tag_value)) + if(!STR_EQ(get_from(t_msg)->tag_value, + get_from(p_msg)->tag_value)) continue; /* all criteria for proxied ACK are ok */ - if (likely(p_cell->relayed_reply_branch!=-2)) { - if (unlikely(has_tran_tmcbs(p_cell, - TMCB_E2EACK_IN|TMCB_E2EACK_RETR_IN))){ - if (likely(totag_e2e_ack_matching(p_cell, p_msg)==2)) + if(likely(p_cell->relayed_reply_branch != -2)) { + if(unlikely(has_tran_tmcbs( + p_cell, TMCB_E2EACK_IN | TMCB_E2EACK_RETR_IN))) { + if(likely(totag_e2e_ack_matching(p_cell, p_msg) == 2)) goto e2e_ack; - else if (e2e_ack_trans==0) - e2e_ack_trans=p_cell; + else if(e2e_ack_trans == 0) + e2e_ack_trans = p_cell; } continue; } /* it's a local UAS transaction */ - if (dlg_matching(p_cell, p_msg)) + if(dlg_matching(p_cell, p_msg)) goto found; continue; } else { /* for hbh ACKs, From HF 'MUST' equal INVITE's one */ - if (! EQ_LEN(from)) continue; - if (! EQ_STR(from)) continue; + if(!EQ_LEN(from)) + continue; + if(!EQ_STR(from)) + continue; } /* it is not an e2e ACK/200 -- perhaps it is @@ -673,25 +703,25 @@ int t_request_search( struct sip_msg* p_msg, struct cell **r_cell) * more elements to match: r-uri and via; allow * mismatching r-uri as an config option for broken * UACs */ - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN ) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) continue; - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) continue; /* wow -- we survived all the check! we matched! */ LM_DBG("non-2xx ACK matched\n"); goto found; } /* synonym loop */ - } /* ACK */ + } /* ACK */ notfound: - if (e2e_ack_trans) { - p_cell=e2e_ack_trans; + if(e2e_ack_trans) { + p_cell = e2e_ack_trans; goto e2e_ack; } @@ -714,7 +744,6 @@ int t_request_search( struct sip_msg* p_msg, struct cell **r_cell) } - /** find the transaction corresponding to a request. * @return - negative - transaction wasn't found (-1) or * possible e2eACK match (-2). @@ -725,20 +754,18 @@ int t_request_search( struct sip_msg* p_msg, struct cell **r_cell) * (T_branch is always set to T_BR_UNDEFINED). */ -int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked, - int* cancel) +int t_lookup_request(struct sip_msg *p_msg, int leave_new_locked, int *cancel) { - struct cell *p_cell; - unsigned int isACK; - struct sip_msg *t_msg; + struct cell *p_cell; + unsigned int isACK; + struct sip_msg *t_msg; struct via_param *branch; int match_status; struct cell *e2e_ack_trans; - struct entry* hash_bucket; + struct entry *hash_bucket; /* parse all*/ - if (unlikely(check_transaction_quadruple(p_msg)==0)) - { + if(unlikely(check_transaction_quadruple(p_msg) == 0)) { LM_ERR("too few headers\n"); set_t(0, T_BR_UNDEFINED); /* stop processing */ @@ -746,13 +773,12 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked, } /* start searching into the table */ - if (!(p_msg->msg_flags & FL_HASH_INDEX)){ - p_msg->hash_index=hash( p_msg->callid->body , get_cseq(p_msg)->number); - p_msg->msg_flags|=FL_HASH_INDEX; + if(!(p_msg->msg_flags & FL_HASH_INDEX)) { + p_msg->hash_index = hash(p_msg->callid->body, get_cseq(p_msg)->number); + p_msg->msg_flags |= FL_HASH_INDEX; } - isACK = p_msg->REQ_METHOD==METHOD_ACK; - LM_DBG("start searching: hash=%d, isACK=%d\n", - p_msg->hash_index,isACK); + isACK = p_msg->REQ_METHOD == METHOD_ACK; + LM_DBG("start searching: hash=%d, isACK=%d\n", p_msg->hash_index, isACK); /* assume not found */ @@ -762,25 +788,27 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked, * so, we can do very quick matching and skip the old-RFC bizzar * comparison of many header fields */ - if (!p_msg->via1) { + if(!p_msg->via1) { LM_ERR("no via\n"); set_t(0, T_BR_UNDEFINED); return 0; } - branch=p_msg->via1->branch; - if (branch && branch->value.s && branch->value.len>MCOOKIE_LEN - && memcmp(branch->value.s,MCOOKIE,MCOOKIE_LEN)==0) { + branch = p_msg->via1->branch; + if(branch && branch->value.s && branch->value.len > MCOOKIE_LEN + && memcmp(branch->value.s, MCOOKIE, MCOOKIE_LEN) == 0) { /* huhuhu! the cookie is there -- let's proceed fast */ LOCK_HASH(p_msg->hash_index); - match_status=matching_3261(p_msg,&p_cell, + match_status = matching_3261(p_msg, &p_cell, /* skip transactions with different method; otherwise CANCEL * would match the previous INVITE trans. */ - isACK ? ~METHOD_INVITE: ~p_msg->REQ_METHOD, - cancel); + isACK ? ~METHOD_INVITE : ~p_msg->REQ_METHOD, cancel); switch(match_status) { - case 0: goto notfound; /* no match */ - case 1: goto found; /* match */ - case 2: goto e2e_ack; /* e2e proxy ACK */ + case 0: + goto notfound; /* no match */ + case 1: + goto found; /* match */ + case 2: + goto e2e_ack; /* e2e proxy ACK */ } } @@ -788,113 +816,134 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked, * a bit simplified to be fast -- we don't do all the comparisons * of parsed uri, which was simply too bloated */ LM_DBG("proceeding to pre-RFC3261 transaction matching\n"); - *cancel=0; + *cancel = 0; /* lock the whole entry*/ LOCK_HASH(p_msg->hash_index); - hash_bucket=&(get_tm_table()->entries[p_msg->hash_index]); + hash_bucket = &(get_tm_table()->entries[p_msg->hash_index]); - if (likely(!isACK)) { + if(likely(!isACK)) { /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); t_msg = p_cell->uas.request; - if (!t_msg) continue; /* skip UAC transactions */ + if(!t_msg) + continue; /* skip UAC transactions */ /* for non-ACKs we want same method matching, we * make an exception for pre-exisiting CANCELs because we * want to set *cancel */ - if ((t_msg->REQ_METHOD!=p_msg->REQ_METHOD) && - (t_msg->REQ_METHOD!=METHOD_CANCEL)) + if((t_msg->REQ_METHOD != p_msg->REQ_METHOD) + && (t_msg->REQ_METHOD != METHOD_CANCEL)) continue; /* compare lengths first */ - if (!EQ_LEN(callid)) continue; + if(!EQ_LEN(callid)) + continue; /* CSeq only the number without method ! */ - if (get_cseq(t_msg)->number.len!=get_cseq(p_msg)->number.len) + if(get_cseq(t_msg)->number.len != get_cseq(p_msg)->number.len) + continue; + if(!EQ_LEN(from)) continue; - if (!EQ_LEN(from)) continue; - if (!EQ_LEN(to)) continue; - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) + if(!EQ_LEN(to)) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) + continue; + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) continue; /* length ok -- move on */ - if (!EQ_STR(callid)) continue; - if (memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, - get_cseq(p_msg)->number.len)!=0) continue; - if (!EQ_STR(from)) continue; - if (!EQ_STR(to)) continue; - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) + if(!EQ_STR(callid)) + continue; + if(memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, + get_cseq(p_msg)->number.len) + != 0) + continue; + if(!EQ_STR(from)) + continue; + if(!EQ_STR(to)) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) + continue; + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) continue; - if ((t_msg->REQ_METHOD==METHOD_CANCEL) && - (p_msg->REQ_METHOD!=METHOD_CANCEL)){ + if((t_msg->REQ_METHOD == METHOD_CANCEL) + && (p_msg->REQ_METHOD != METHOD_CANCEL)) { /* we've matched an existing CANCEL */ - *cancel=1; + *cancel = 1; continue; } /* request matched ! */ LM_DBG("non-ACK matched\n"); goto found; - } /* synonym loop */ + } /* synonym loop */ } else { /* it's an ACK request*/ /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); t_msg = p_cell->uas.request; - if (!t_msg) continue; /* skip UAC transactions */ + if(!t_msg) + continue; /* skip UAC transactions */ /* ACK's relate only to INVITEs */ - if (t_msg->REQ_METHOD!=METHOD_INVITE) continue; + if(t_msg->REQ_METHOD != METHOD_INVITE) + continue; /* From|To URI , CallID, CSeq # must be always there */ /* compare lengths now */ - if (!EQ_LEN(callid)) continue; + if(!EQ_LEN(callid)) + continue; /* CSeq only the number without method ! */ - if (get_cseq(t_msg)->number.len!=get_cseq(p_msg)->number.len) + if(get_cseq(t_msg)->number.len != get_cseq(p_msg)->number.len) continue; /* To only the uri -- to many UACs screw up tags */ - if (get_to(t_msg)->uri.len!=get_to(p_msg)->uri.len) + if(get_to(t_msg)->uri.len != get_to(p_msg)->uri.len) + continue; + if(!EQ_STR(callid)) + continue; + if(memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, + get_cseq(p_msg)->number.len) + != 0) + continue; + if(memcmp(get_to(t_msg)->uri.s, get_to(p_msg)->uri.s, + get_to(t_msg)->uri.len) + != 0) continue; - if (!EQ_STR(callid)) continue; - if (memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, - get_cseq(p_msg)->number.len)!=0) continue; - if (memcmp(get_to(t_msg)->uri.s, get_to(p_msg)->uri.s, - get_to(t_msg)->uri.len)!=0) continue; /* it is e2e ACK/200 */ - if (p_cell->uas.status<300) { + if(p_cell->uas.status < 300) { /* For e2e ACKs, From's tag 'MUST' equal INVITE's, while use * of the URI in this case is to be deprecated (Sec. 12.2.1.1). * Comparing entire From body is dangerous, since some UAs * screw the display name up. */ - if (parse_from_header(p_msg) < 0) { + if(parse_from_header(p_msg) < 0) { LM_ERR("failed to parse From HF; ACK might not match.\n"); continue; } - if (! STR_EQ(get_from(t_msg)->tag_value, - get_from(p_msg)->tag_value)) + if(!STR_EQ(get_from(t_msg)->tag_value, + get_from(p_msg)->tag_value)) continue; /* all criteria for proxied ACK are ok */ - if (likely(p_cell->relayed_reply_branch!=-2)) { - if (unlikely(has_tran_tmcbs(p_cell, - TMCB_E2EACK_IN|TMCB_E2EACK_RETR_IN))){ - if (likely(totag_e2e_ack_matching(p_cell, p_msg)==2)) + if(likely(p_cell->relayed_reply_branch != -2)) { + if(unlikely(has_tran_tmcbs( + p_cell, TMCB_E2EACK_IN | TMCB_E2EACK_RETR_IN))) { + if(likely(totag_e2e_ack_matching(p_cell, p_msg) == 2)) goto e2e_ack; - else if (e2e_ack_trans==0) - e2e_ack_trans=p_cell; + else if(e2e_ack_trans == 0) + e2e_ack_trans = p_cell; } continue; } /* it's a local UAS transaction */ - if (dlg_matching(p_cell, p_msg)) + if(dlg_matching(p_cell, p_msg)) goto found; continue; } else { /* for hbh ACKs, From HF 'MUST' equal INVITE's one */ - if (! EQ_LEN(from)) continue; - if (! EQ_STR(from)) continue; + if(!EQ_LEN(from)) + continue; + if(!EQ_STR(from)) + continue; } /* it is not an e2e ACK/200 -- perhaps it is @@ -902,40 +951,40 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked, * more elements to match: r-uri and via; allow * mismatching r-uri as a config option for broken * UACs */ - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN ) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) continue; - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) continue; /* wow -- we survived all the check! we matched! */ LM_DBG("non-2xx ACK matched\n"); goto found; } /* synonym loop */ - } /* ACK */ + } /* ACK */ notfound: - if (e2e_ack_trans) { - p_cell=e2e_ack_trans; + if(e2e_ack_trans) { + p_cell = e2e_ack_trans; goto e2e_ack; } /* no transaction found */ set_t(0, T_BR_UNDEFINED); - if (!leave_new_locked) { + if(!leave_new_locked) { UNLOCK_HASH(p_msg->hash_index); } LM_DBG("no transaction found\n"); return -1; e2e_ack: - t_ack=p_cell; /* e2e proxied ACK */ + t_ack = p_cell; /* e2e proxied ACK */ set_t(0, T_BR_UNDEFINED); - if (!leave_new_locked) { + if(!leave_new_locked) { UNLOCK_HASH(p_msg->hash_index); } LM_DBG("e2e proxy ACK found\n"); @@ -943,126 +992,131 @@ int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked, found: set_t(p_cell, T_BR_UNDEFINED); - REF_UNSAFE( T ); + REF_UNSAFE(T); set_kr(REQ_EXIST); - UNLOCK_HASH( p_msg->hash_index ); - LM_DBG("transaction found (T=%p)\n",T); + UNLOCK_HASH(p_msg->hash_index); + LM_DBG("transaction found (T=%p)\n", T); return 1; } - /* function lookups transaction being canceled by CANCEL in p_msg; * it returns: * 0 - transaction wasn't found * T - transaction found */ -struct cell* t_lookupOriginalT( struct sip_msg* p_msg ) +struct cell *t_lookupOriginalT(struct sip_msg *p_msg) { - struct cell *p_cell; - unsigned int hash_index; - struct sip_msg *t_msg; + struct cell *p_cell; + unsigned int hash_index; + struct sip_msg *t_msg; struct via_param *branch; - struct entry* hash_bucket; + struct entry *hash_bucket; int foo; int ret; /* start searching in the table */ - if (!(p_msg->msg_flags & FL_HASH_INDEX)){ + if(!(p_msg->msg_flags & FL_HASH_INDEX)) { /* parse all*/ - if (check_transaction_quadruple(p_msg)==0) - { + if(check_transaction_quadruple(p_msg) == 0) { LM_ERR("too few headers\n"); /* stop processing */ return 0; } - p_msg->hash_index=hash( p_msg->callid->body , get_cseq(p_msg)->number); - p_msg->msg_flags|=FL_HASH_INDEX; + p_msg->hash_index = hash(p_msg->callid->body, get_cseq(p_msg)->number); + p_msg->msg_flags |= FL_HASH_INDEX; } hash_index = p_msg->hash_index; - LM_DBG("searching on hash entry %d\n",hash_index ); + LM_DBG("searching on hash entry %d\n", hash_index); /* first of all, look if there is RFC3261 magic cookie in branch; if * so, we can do very quick matching and skip the old-RFC bizzar * comparison of many header fields */ - if (!p_msg->via1) { + if(!p_msg->via1) { LM_ERR("no via\n"); return 0; } - branch=p_msg->via1->branch; - if (branch && branch->value.s && branch->value.len>MCOOKIE_LEN - && memcmp(branch->value.s,MCOOKIE,MCOOKIE_LEN)==0) { + branch = p_msg->via1->branch; + if(branch && branch->value.s && branch->value.len > MCOOKIE_LEN + && memcmp(branch->value.s, MCOOKIE, MCOOKIE_LEN) == 0) { /* huhuhu! the cookie is there -- let's proceed fast */ LOCK_HASH(hash_index); - ret=matching_3261(p_msg, &p_cell, + ret = matching_3261(p_msg, &p_cell, /* we are seeking the original transaction -- * skip CANCEL transactions during search */ METHOD_CANCEL, &foo); - if (ret==1) goto found; else goto notfound; + if(ret == 1) + goto found; + else + goto notfound; } /* no cookies --proceed to old-fashioned pre-3261 t-matching */ LOCK_HASH(hash_index); - hash_bucket=&(get_tm_table()->entries[hash_index]); + hash_bucket = &(get_tm_table()->entries[hash_index]); /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); t_msg = p_cell->uas.request; - if (!t_msg) continue; /* skip UAC transactions */ + if(!t_msg) + continue; /* skip UAC transactions */ /* we don't cancel CANCELs ;-) */ - if (unlikely(t_msg->REQ_METHOD==METHOD_CANCEL)) + if(unlikely(t_msg->REQ_METHOD == METHOD_CANCEL)) continue; /* check lengths now */ - if (!EQ_LEN(callid)) + if(!EQ_LEN(callid)) continue; - if (get_cseq(t_msg)->number.len!=get_cseq(p_msg)->number.len) + if(get_cseq(t_msg)->number.len != get_cseq(p_msg)->number.len) continue; - if (!EQ_LEN(from)) + if(!EQ_LEN(from)) continue; #ifdef CANCEL_TAG - if (!EQ_LEN(to)) + if(!EQ_LEN(to)) continue; #else /* relaxed matching -- we don't care about to-tags anymore, * many broken UACs screw them up and ignoring them does not * actually hurt */ - if (get_to(t_msg)->uri.len!=get_to(p_msg)->uri.len) + if(get_to(t_msg)->uri.len != get_to(p_msg)->uri.len) continue; #endif - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_LEN) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_LEN(via1)) continue; /* check the content now */ - if (!EQ_STR(callid)) + if(!EQ_STR(callid)) continue; - if (memcmp(get_cseq(t_msg)->number.s, - get_cseq(p_msg)->number.s,get_cseq(p_msg)->number.len)!=0) + if(memcmp(get_cseq(t_msg)->number.s, get_cseq(p_msg)->number.s, + get_cseq(p_msg)->number.len) + != 0) continue; - if (!EQ_STR(from)) + if(!EQ_STR(from)) continue; #ifdef CANCEL_TAG - if (!EQ_STR(to)) + if(!EQ_STR(to)) continue; #else - if (memcmp(get_to(t_msg)->uri.s, get_to(p_msg)->uri.s, - get_to(t_msg)->uri.len)!=0) + if(memcmp(get_to(t_msg)->uri.s, get_to(p_msg)->uri.s, + get_to(t_msg)->uri.len) + != 0) continue; #endif - if (cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) + if(cfg_get(tm, tm_cfg, ruri_matching) && !EQ_REQ_URI_STR) continue; - if (cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) + if(cfg_get(tm, tm_cfg, via1_matching) && !EQ_VIA_STR(via1)) continue; /* found */ @@ -1071,14 +1125,14 @@ struct cell* t_lookupOriginalT( struct sip_msg* p_msg ) notfound: /* no transaction found */ - LM_DBG(" no CANCEL matching found! \n" ); + LM_DBG(" no CANCEL matching found! \n"); UNLOCK_HASH(hash_index); LM_DBG("lookup completed\n"); return 0; found: - LM_DBG("canceled transaction found (%p)! \n",p_cell ); - REF_UNSAFE( p_cell ); + LM_DBG("canceled transaction found (%p)! \n", p_cell); + REF_UNSAFE(p_cell); UNLOCK_HASH(hash_index); LM_DBG("found - lookup completed\n"); return p_cell; @@ -1090,12 +1144,12 @@ struct cell* t_lookupOriginalT( struct sip_msg* p_msg ) */ int t_reply_search(struct sip_msg *p_msg, struct cell **r_cell, int *r_branch) { - struct cell* p_cell; - unsigned int hash_index = 0; - unsigned int entry_label = 0; - unsigned int branch_id = 0; - char *hashi, *branchi, *p, *n; - struct entry* hash_bucket; + struct cell *p_cell; + unsigned int hash_index = 0; + unsigned int entry_label = 0; + unsigned int branch_id = 0; + char *hashi, *branchi, *p, *n; + struct entry *hash_bucket; int hashl, branchl; int scan_space; str cseq_method; @@ -1110,137 +1164,153 @@ int t_reply_search(struct sip_msg *p_msg, struct cell **r_cell, int *r_branch) *r_branch = T_BR_UNDEFINED; /* make compiler warnings happy */ - loopi=0; - loopl=0; + loopi = 0; + loopl = 0; /* split the branch into pieces: loop_detection_check(ignored), * hash_table_id, synonym_id, branch_id */ - if (!(p_msg->via1 && p_msg->via1->branch && p_msg->via1->branch->value.s)) + if(!(p_msg->via1 && p_msg->via1->branch && p_msg->via1->branch->value.s)) goto nomatch2; /* we do RFC 3261 tid matching and want to see first if there is * magic cookie in branch */ - if (p_msg->via1->branch->value.len<=MCOOKIE_LEN) + if(p_msg->via1->branch->value.len <= MCOOKIE_LEN) goto nomatch2; - if (memcmp(p_msg->via1->branch->value.s, MCOOKIE, MCOOKIE_LEN)!=0) + if(memcmp(p_msg->via1->branch->value.s, MCOOKIE, MCOOKIE_LEN) != 0) goto nomatch2; - p=p_msg->via1->branch->value.s+MCOOKIE_LEN; - scan_space=p_msg->via1->branch->value.len-MCOOKIE_LEN; + p = p_msg->via1->branch->value.s + MCOOKIE_LEN; + scan_space = p_msg->via1->branch->value.len - MCOOKIE_LEN; /* hash_id */ - n=eat_token2_end( p, p+scan_space, BRANCH_SEPARATOR); - hashl=n-p; - scan_space-=hashl; - if (!hashl || scan_space<2 || *n!=BRANCH_SEPARATOR) goto nomatch2; - hashi=p; - p=n+1;scan_space--; + n = eat_token2_end(p, p + scan_space, BRANCH_SEPARATOR); + hashl = n - p; + scan_space -= hashl; + if(!hashl || scan_space < 2 || *n != BRANCH_SEPARATOR) + goto nomatch2; + hashi = p; + p = n + 1; + scan_space--; /* md5 value */ - n=eat_token2_end( p, p+scan_space, BRANCH_SEPARATOR ); - loopl = n-p; - scan_space-= loopl; - if (n==p || scan_space<2 || *n!=BRANCH_SEPARATOR) + n = eat_token2_end(p, p + scan_space, BRANCH_SEPARATOR); + loopl = n - p; + scan_space -= loopl; + if(n == p || scan_space < 2 || *n != BRANCH_SEPARATOR) goto nomatch2; - loopi=p; - p=n+1; scan_space--; + loopi = p; + p = n + 1; + scan_space--; /* branch id - should exceed the scan_space */ - n=eat_token_end( p, p+scan_space ); - branchl=n-p; - if (!branchl ) goto nomatch2; - branchi=p; + n = eat_token_end(p, p + scan_space); + branchl = n - p; + if(!branchl) + goto nomatch2; + branchi = p; /* sanity check */ - if (unlikely(reverse_hex2int(hashi, hashl, &hash_index)<0 - || hash_index>=TABLE_ENTRIES - || reverse_hex2int(branchi, branchl, &branch_id)<0 - || branch_id>=sr_dst_max_branches - || loopl!=MD5_LEN) - ) { + if(unlikely(reverse_hex2int(hashi, hashl, &hash_index) < 0 + || hash_index >= TABLE_ENTRIES + || reverse_hex2int(branchi, branchl, &branch_id) < 0 + || branch_id >= sr_dst_max_branches || loopl != MD5_LEN)) { LM_DBG("poor reply ids - index %d label %d branch %d loopl %d/%d\n", hash_index, entry_label, branch_id, loopl, MD5_LEN); goto nomatch2; } - LM_DBG("t_reply_matching: hash %d label %d branch %d\n", - hash_index, entry_label, branch_id ); + LM_DBG("t_reply_matching: hash %d label %d branch %d\n", hash_index, + entry_label, branch_id); /* search the hash table list at entry 'hash_index'; lock the entry first */ - cseq_method=get_cseq(p_msg)->method; - is_cancel=cseq_method.len==CANCEL_LEN - && memcmp(cseq_method.s, CANCEL, CANCEL_LEN)==0; + cseq_method = get_cseq(p_msg)->method; + is_cancel = cseq_method.len == CANCEL_LEN + && memcmp(cseq_method.s, CANCEL, CANCEL_LEN) == 0; LOCK_HASH(hash_index); - hash_bucket=&(get_tm_table()->entries[hash_index]); + hash_bucket = &(get_tm_table()->entries[hash_index]); /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); - if (cfg_get(tm, tm_cfg, callid_cseq_matching)) { - if (memcmp(p_cell->callid_hdr.s + strlen("Call-ID: "), p_msg->callid->body.s, p_msg->callid->body.len) != 0) { - LM_ERR("t_reply_matching: failed callid matching (instead of md5): %d p_cell=%.*s p_msg=%.*s", - p_msg->first_line.u.reply.statuscode, - p_cell->callid_hdr.len, p_cell->callid_hdr.s, - p_msg->callid->body.len, p_msg->callid->body.s); + if(cfg_get(tm, tm_cfg, callid_cseq_matching)) { + if(memcmp(p_cell->callid_hdr.s + strlen("Call-ID: "), + p_msg->callid->body.s, p_msg->callid->body.len) + != 0) { + LM_ERR("t_reply_matching: failed callid matching (instead of " + "md5): %d p_cell=%.*s p_msg=%.*s", + p_msg->first_line.u.reply.statuscode, + p_cell->callid_hdr.len, p_cell->callid_hdr.s, + p_msg->callid->body.len, p_msg->callid->body.s); continue; } - if (memcmp(p_cell->cseq_hdr_n.s + strlen("CSeq: "), get_cseq(p_msg)->number.s, get_cseq(p_msg)->number.len) != 0) { - LM_ERR("t_reply_matching: failed cseq matching (instead of md5): %d p_cell=%.*s p_msg=%.*s", - p_msg->first_line.u.reply.statuscode, - p_cell->cseq_hdr_n.len, p_cell->cseq_hdr_n.s, - get_cseq(p_msg)->number.len, get_cseq(p_msg)->number.s); + if(memcmp(p_cell->cseq_hdr_n.s + strlen("CSeq: "), + get_cseq(p_msg)->number.s, get_cseq(p_msg)->number.len) + != 0) { + LM_ERR("t_reply_matching: failed cseq matching (instead of " + "md5): %d p_cell=%.*s p_msg=%.*s", + p_msg->first_line.u.reply.statuscode, + p_cell->cseq_hdr_n.len, p_cell->cseq_hdr_n.s, + get_cseq(p_msg)->number.len, get_cseq(p_msg)->number.s); continue; } } else { - if ( memcmp(p_cell->md5, loopi,MD5_LEN)!=0) + if(memcmp(p_cell->md5, loopi, MD5_LEN) != 0) continue; } /* sanity check ... too high branch ? */ - if (unlikely(branch_id>=p_cell->nr_of_outgoings)) + if(unlikely(branch_id >= p_cell->nr_of_outgoings)) continue; /* does method match ? (remember -- CANCELs have the same branch * as canceled transactions) */ - req_method=p_cell->method; - if ( /* method match */ - ! ((cseq_method.len==req_method.len - && memcmp( cseq_method.s, req_method.s, cseq_method.len )==0) - /* or it is a local cancel */ - || (is_cancel && is_invite(p_cell) - /* commented out -- should_cancel_branch set it to + req_method = p_cell->method; + if(/* method match */ + !((cseq_method.len == req_method.len + && memcmp(cseq_method.s, req_method.s, + cseq_method.len) + == 0) + /* or it is a local cancel */ + || (is_cancel + && is_invite(p_cell) + /* commented out -- should_cancel_branch set it to * BUSY_BUFFER to avoid collisions with replies; * thus, we test here by buffer size */ - /* && p_cell->uac[branch_id].local_cancel.buffer ))) */ - && p_cell->uac[branch_id].local_cancel.buffer_len ))) - continue; + /* && p_cell->uac[branch_id].local_cancel.buffer ))) */ + && p_cell->uac[branch_id] + .local_cancel.buffer_len))) + continue; - if (cfg_get(tm, tm_cfg, callid_matching) && - p_cell->uas.request && p_cell->uas.request->callid - && (p_msg->callid->body.len != p_cell->uas.request->callid->body.len - || memcmp(p_msg->callid->body.s, - p_cell->uas.request->callid->body.s, - p_msg->callid->body.len) != 0) - ) { + if(cfg_get(tm, tm_cfg, callid_matching) && p_cell->uas.request + && p_cell->uas.request->callid + && (p_msg->callid->body.len + != p_cell->uas.request->callid->body.len + || memcmp(p_msg->callid->body.s, + p_cell->uas.request->callid->body.s, + p_msg->callid->body.len) + != 0)) { LM_ERR("matching transaction found but callids" - " don't match (received: %.*s stored: %.*s)\n", + " don't match (received: %.*s stored: %.*s)\n", p_msg->callid->body.len, p_msg->callid->body.s, - p_cell->uas.request->callid->body.len, p_cell->uas.request->callid->body.s); + p_cell->uas.request->callid->body.len, + p_cell->uas.request->callid->body.s); continue; } /* passed all disqualifying factors - the transaction has been matched */ *r_cell = p_cell; - *r_branch =(int) branch_id; - REF_UNSAFE( p_cell ); + *r_branch = (int)branch_id; + REF_UNSAFE(p_cell); UNLOCK_HASH(hash_index); - LM_DBG("reply (%p) matched an active transaction (T=%p)!\n", p_msg, p_cell); + LM_DBG("reply (%p) matched an active transaction (T=%p)!\n", p_msg, + p_cell); return 0; } /* for cycle */ @@ -1260,14 +1330,14 @@ int t_reply_search(struct sip_msg *p_msg, struct cell **r_cell, int *r_branch) * @return -1 - nothing found, 1 - T found * Side-effects: sets T and T_branch on success. */ -int t_reply_matching( struct sip_msg *p_msg , int *p_branch ) +int t_reply_matching(struct sip_msg *p_msg, int *p_branch) { - struct cell* p_cell; - unsigned int hash_index = 0; - unsigned int entry_label = 0; - unsigned int branch_id = 0; - char *hashi, *branchi, *p, *n; - struct entry* hash_bucket; + struct cell *p_cell; + unsigned int hash_index = 0; + unsigned int entry_label = 0; + unsigned int branch_id = 0; + char *hashi, *branchi, *p, *n; + struct entry *hash_bucket; int hashl, branchl; int scan_space; str cseq_method; @@ -1279,164 +1349,182 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch ) short is_cancel; /* make compiler warnings happy */ - loopi=0; - loopl=0; + loopi = 0; + loopl = 0; /* split the branch into pieces: loop_detection_check(ignored), * hash_table_id, synonym_id, branch_id */ - if (!(p_msg->via1 && p_msg->via1->branch && p_msg->via1->branch->value.s)) + if(!(p_msg->via1 && p_msg->via1->branch && p_msg->via1->branch->value.s)) goto nomatch2; /* we do RFC 3261 tid matching and want to see first if there is * magic cookie in branch */ - if (p_msg->via1->branch->value.len<=MCOOKIE_LEN) + if(p_msg->via1->branch->value.len <= MCOOKIE_LEN) goto nomatch2; - if (memcmp(p_msg->via1->branch->value.s, MCOOKIE, MCOOKIE_LEN)!=0) + if(memcmp(p_msg->via1->branch->value.s, MCOOKIE, MCOOKIE_LEN) != 0) goto nomatch2; - p=p_msg->via1->branch->value.s+MCOOKIE_LEN; - scan_space=p_msg->via1->branch->value.len-MCOOKIE_LEN; + p = p_msg->via1->branch->value.s + MCOOKIE_LEN; + scan_space = p_msg->via1->branch->value.len - MCOOKIE_LEN; /* hash_id */ - n=eat_token2_end( p, p+scan_space, BRANCH_SEPARATOR); - hashl=n-p; - scan_space-=hashl; - if (!hashl || scan_space<2 || *n!=BRANCH_SEPARATOR) goto nomatch2; - hashi=p; - p=n+1;scan_space--; + n = eat_token2_end(p, p + scan_space, BRANCH_SEPARATOR); + hashl = n - p; + scan_space -= hashl; + if(!hashl || scan_space < 2 || *n != BRANCH_SEPARATOR) + goto nomatch2; + hashi = p; + p = n + 1; + scan_space--; /* md5 value */ - n=eat_token2_end( p, p+scan_space, BRANCH_SEPARATOR ); - loopl = n-p; - scan_space-= loopl; - if (n==p || scan_space<2 || *n!=BRANCH_SEPARATOR) + n = eat_token2_end(p, p + scan_space, BRANCH_SEPARATOR); + loopl = n - p; + scan_space -= loopl; + if(n == p || scan_space < 2 || *n != BRANCH_SEPARATOR) goto nomatch2; - loopi=p; - p=n+1; scan_space--; + loopi = p; + p = n + 1; + scan_space--; /* branch id - should exceed the scan_space */ - n=eat_token_end( p, p+scan_space ); - branchl=n-p; - if (!branchl ) goto nomatch2; - branchi=p; + n = eat_token_end(p, p + scan_space); + branchl = n - p; + if(!branchl) + goto nomatch2; + branchi = p; /* sanity check */ - if (unlikely(reverse_hex2int(hashi, hashl, &hash_index)<0 - || hash_index>=TABLE_ENTRIES - || reverse_hex2int(branchi, branchl, &branch_id)<0 - || branch_id>=sr_dst_max_branches - || loopl!=MD5_LEN) - ) { + if(unlikely(reverse_hex2int(hashi, hashl, &hash_index) < 0 + || hash_index >= TABLE_ENTRIES + || reverse_hex2int(branchi, branchl, &branch_id) < 0 + || branch_id >= sr_dst_max_branches || loopl != MD5_LEN)) { LM_DBG("poor reply ids - index %d label %d branch %d loopl %d/%d\n", hash_index, entry_label, branch_id, loopl, MD5_LEN); goto nomatch2; } - LM_DBG("t_reply_matching: hash %d label %d branch %d\n", - hash_index, entry_label, branch_id ); + LM_DBG("t_reply_matching: hash %d label %d branch %d\n", hash_index, + entry_label, branch_id); /* search the hash table list at entry 'hash_index'; lock the entry first */ - cseq_method=get_cseq(p_msg)->method; - is_cancel=cseq_method.len==CANCEL_LEN - && memcmp(cseq_method.s, CANCEL, CANCEL_LEN)==0; + cseq_method = get_cseq(p_msg)->method; + is_cancel = cseq_method.len == CANCEL_LEN + && memcmp(cseq_method.s, CANCEL, CANCEL_LEN) == 0; LOCK_HASH(hash_index); - hash_bucket=&(get_tm_table()->entries[hash_index]); + hash_bucket = &(get_tm_table()->entries[hash_index]); /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); - if (cfg_get(tm, tm_cfg, callid_cseq_matching)) { - if (memcmp(p_cell->callid_hdr.s + strlen("Call-ID: "), p_msg->callid->body.s, p_msg->callid->body.len) != 0) { - LM_ERR("t_reply_matching: failed callid matching (instead of md5): %d p_cell=%.*s p_msg=%.*s", - p_msg->first_line.u.reply.statuscode, - p_cell->callid_hdr.len, p_cell->callid_hdr.s, - p_msg->callid->body.len, p_msg->callid->body.s); + if(cfg_get(tm, tm_cfg, callid_cseq_matching)) { + if(memcmp(p_cell->callid_hdr.s + strlen("Call-ID: "), + p_msg->callid->body.s, p_msg->callid->body.len) + != 0) { + LM_ERR("t_reply_matching: failed callid matching (instead of " + "md5): %d p_cell=%.*s p_msg=%.*s", + p_msg->first_line.u.reply.statuscode, + p_cell->callid_hdr.len, p_cell->callid_hdr.s, + p_msg->callid->body.len, p_msg->callid->body.s); continue; } - if (memcmp(p_cell->cseq_hdr_n.s + strlen("CSeq: "), get_cseq(p_msg)->number.s, get_cseq(p_msg)->number.len) != 0) { - LM_ERR("t_reply_matching: failed cseq matching (instead of md5): %d p_cell=%.*s p_msg=%.*s", - p_msg->first_line.u.reply.statuscode, - p_cell->cseq_hdr_n.len, p_cell->cseq_hdr_n.s, - get_cseq(p_msg)->number.len, get_cseq(p_msg)->number.s); + if(memcmp(p_cell->cseq_hdr_n.s + strlen("CSeq: "), + get_cseq(p_msg)->number.s, get_cseq(p_msg)->number.len) + != 0) { + LM_ERR("t_reply_matching: failed cseq matching (instead of " + "md5): %d p_cell=%.*s p_msg=%.*s", + p_msg->first_line.u.reply.statuscode, + p_cell->cseq_hdr_n.len, p_cell->cseq_hdr_n.s, + get_cseq(p_msg)->number.len, get_cseq(p_msg)->number.s); continue; } } else { - if ( memcmp(p_cell->md5, loopi,MD5_LEN)!=0) + if(memcmp(p_cell->md5, loopi, MD5_LEN) != 0) continue; } /* sanity check ... too high branch ? */ - if (unlikely(branch_id>=p_cell->nr_of_outgoings)) + if(unlikely(branch_id >= p_cell->nr_of_outgoings)) continue; /* does method match ? (remember -- CANCELs have the same branch * as canceled transactions) */ - req_method=p_cell->method; - if ( /* method match */ - ! ((cseq_method.len==req_method.len - && memcmp( cseq_method.s, req_method.s, cseq_method.len )==0) - /* or it is a local cancel */ - || (is_cancel && is_invite(p_cell) - /* commented out -- should_cancel_branch set it to + req_method = p_cell->method; + if(/* method match */ + !((cseq_method.len == req_method.len + && memcmp(cseq_method.s, req_method.s, + cseq_method.len) + == 0) + /* or it is a local cancel */ + || (is_cancel + && is_invite(p_cell) + /* commented out -- should_cancel_branch set it to * BUSY_BUFFER to avoid collisions with replies; * thus, we test here by buffer size */ - /* && p_cell->uac[branch_id].local_cancel.buffer ))) */ - && p_cell->uac[branch_id].local_cancel.buffer_len ))) - continue; + /* && p_cell->uac[branch_id].local_cancel.buffer ))) */ + && p_cell->uac[branch_id] + .local_cancel.buffer_len))) + continue; - if (cfg_get(tm, tm_cfg, callid_matching) && - p_cell->uas.request && p_cell->uas.request->callid - && (p_msg->callid->body.len != p_cell->uas.request->callid->body.len - || memcmp(p_msg->callid->body.s, - p_cell->uas.request->callid->body.s, - p_msg->callid->body.len) != 0) - ) { + if(cfg_get(tm, tm_cfg, callid_matching) && p_cell->uas.request + && p_cell->uas.request->callid + && (p_msg->callid->body.len + != p_cell->uas.request->callid->body.len + || memcmp(p_msg->callid->body.s, + p_cell->uas.request->callid->body.s, + p_msg->callid->body.len) + != 0)) { LM_ERR("matching transaction found but callids" - " don't match (received: %.*s stored: %.*s)\n", + " don't match (received: %.*s stored: %.*s)\n", p_msg->callid->body.len, p_msg->callid->body.s, - p_cell->uas.request->callid->body.len, p_cell->uas.request->callid->body.s); + p_cell->uas.request->callid->body.len, + p_cell->uas.request->callid->body.s); continue; } /* passed all disqualifying factors - the transaction has been matched */ set_t(p_cell, (int)branch_id); - *p_branch =(int) branch_id; - REF_UNSAFE( T ); + *p_branch = (int)branch_id; + REF_UNSAFE(T); UNLOCK_HASH(hash_index); LM_DBG("reply (%p) matched an active transaction (T=%p)!\n", p_msg, T); - if(likely(!(p_msg->msg_flags&FL_TM_RPL_MATCHED))) { + if(likely(!(p_msg->msg_flags & FL_TM_RPL_MATCHED))) { /* if this is a 200 for INVITE, we will wish to store to-tags to be * able to distinguish retransmissions later and not to call * TMCB_RESPONSE_OUT uselessly; we do it only if callbacks are * enabled -- except callback customers, nobody cares about * retransmissions of multiple 200/INV or ACK/200s */ - if (unlikely( is_invite(p_cell) && p_msg->REPLY_STATUS>=200 - && p_msg->REPLY_STATUS<300 - && ((!is_local(p_cell) && - has_tran_tmcbs(p_cell, - TMCB_RESPONSE_OUT|TMCB_RESPONSE_READY - |TMCB_E2EACK_IN|TMCB_E2EACK_RETR_IN) ) - || (is_local(p_cell)&&has_tran_tmcbs(p_cell, TMCB_LOCAL_COMPLETED)) - )) ) { - if (parse_headers(p_msg, HDR_TO_F, 0)==-1) { + if(unlikely(is_invite(p_cell) && p_msg->REPLY_STATUS >= 200 + && p_msg->REPLY_STATUS < 300 + && ((!is_local(p_cell) + && has_tran_tmcbs(p_cell, + TMCB_RESPONSE_OUT + | TMCB_RESPONSE_READY + | TMCB_E2EACK_IN + | TMCB_E2EACK_RETR_IN)) + || (is_local(p_cell) + && has_tran_tmcbs(p_cell, + TMCB_LOCAL_COMPLETED))))) { + if(parse_headers(p_msg, HDR_TO_F, 0) == -1) { LM_ERR("to parsing failed\n"); } } - if (unlikely(has_tran_tmcbs(T, TMCB_RESPONSE_IN | - TMCB_LOCAL_RESPONSE_IN))){ - if (!is_local(p_cell)) { - run_trans_callbacks( TMCB_RESPONSE_IN, T, T->uas.request, - p_msg, p_msg->REPLY_STATUS); - }else{ - run_trans_callbacks( TMCB_LOCAL_RESPONSE_IN, T, T->uas.request, + if(unlikely(has_tran_tmcbs( + T, TMCB_RESPONSE_IN | TMCB_LOCAL_RESPONSE_IN))) { + if(!is_local(p_cell)) { + run_trans_callbacks(TMCB_RESPONSE_IN, T, T->uas.request, p_msg, p_msg->REPLY_STATUS); + } else { + run_trans_callbacks(TMCB_LOCAL_RESPONSE_IN, T, + T->uas.request, p_msg, p_msg->REPLY_STATUS); } } p_msg->msg_flags |= FL_TM_RPL_MATCHED; @@ -1458,8 +1546,6 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch ) } - - /** Determine current transaction (w/ e2eack support). * * script/t_lookup_request return convention: @@ -1468,26 +1554,24 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch ) * T ptr 0 T_UNDEFINED| 0 0 * Side-effects: sets T and T_branch. */ -int t_check_msg( struct sip_msg* p_msg , int *param_branch ) +int t_check_msg(struct sip_msg *p_msg, int *param_branch) { int local_branch; int canceled; int ret; - ret=0; + ret = 0; /* is T still up-to-date ? */ - LM_DBG("msg (%p) id=%u/%d global id=%u/%d T start=%p\n", - p_msg, p_msg->id, p_msg->pid, tm_global_ctx_id.msgid, - tm_global_ctx_id.pid, T); - if ( msg_ctx_id_match(p_msg, &tm_global_ctx_id)!=1 || T==T_UNDEFINED ) - { + LM_DBG("msg (%p) id=%u/%d global id=%u/%d T start=%p\n", p_msg, p_msg->id, + p_msg->pid, tm_global_ctx_id.msgid, tm_global_ctx_id.pid, T); + if(msg_ctx_id_match(p_msg, &tm_global_ctx_id) != 1 || T == T_UNDEFINED) { msg_ctx_id_set(p_msg, &tm_global_ctx_id); set_t(T_UNDEFINED, T_BR_UNDEFINED); /* transaction lookup */ - if ( p_msg->first_line.type==SIP_REQUEST ) { + if(p_msg->first_line.type == SIP_REQUEST) { /* force parsing all the needed headers*/ - prefetch_loc_r(p_msg->unparsed+64, 1); - if (parse_headers(p_msg, HDR_EOH_F, 0 )==-1) { + prefetch_loc_r(p_msg->unparsed + 64, 1); + if(parse_headers(p_msg, HDR_EOH_F, 0) == -1) { LM_ERR("parsing error\n"); goto error; } @@ -1496,68 +1580,72 @@ int t_check_msg( struct sip_msg* p_msg , int *param_branch ) * ACK, for which we need From-tag; We also need from-tag * in case people want to have proxied e2e ACKs accounted */ - if (p_msg->REQ_METHOD==METHOD_INVITE - && parse_from_header(p_msg)==-1) { + if(p_msg->REQ_METHOD == METHOD_INVITE + && parse_from_header(p_msg) == -1) { LM_ERR("from parsing failed\n"); goto error; } - ret=t_lookup_request( p_msg , 0 /* unlock before returning */, - &canceled); + ret = t_lookup_request( + p_msg, 0 /* unlock before returning */, &canceled); } else { /* we need Via for branch and Cseq method to distinguish * replies with the same branch/cseqNr (CANCEL) * and we need all the WWW/Proxy Authenticate headers for * 401 & 407 replies */ - if (cfg_get(tm, tm_cfg, tm_aggregate_auth) && - (p_msg->REPLY_STATUS==401 || p_msg->REPLY_STATUS==407)){ - if (parse_headers(p_msg, HDR_EOH_F,0)==-1){ + if(cfg_get(tm, tm_cfg, tm_aggregate_auth) + && (p_msg->REPLY_STATUS == 401 + || p_msg->REPLY_STATUS == 407)) { + if(parse_headers(p_msg, HDR_EOH_F, 0) == -1) { LM_WARN("the reply cannot be completely parsed\n"); /* try to continue, via1 & cseq are checked below */ } - }else if ( parse_headers(p_msg, HDR_VIA1_F|HDR_CSEQ_F|HDR_CALLID_F, - 0 )==-1) { + } else if(parse_headers( + p_msg, HDR_VIA1_F | HDR_CSEQ_F | HDR_CALLID_F, 0) + == -1) { LM_ERR("reply cannot be parsed\n"); goto error; } - if ((p_msg->via1==0) || (p_msg->cseq==0) || (p_msg->callid==0)){ + if((p_msg->via1 == 0) || (p_msg->cseq == 0) + || (p_msg->callid == 0)) { LM_ERR("reply doesn't have a via, cseq or call-id header\n"); goto error; } /* if that is an INVITE, we will also need to-tag * for later ACK matching */ - if ( get_cseq(p_msg)->method.len==INVITE_LEN - && memcmp( get_cseq(p_msg)->method.s, INVITE, INVITE_LEN )==0) - { - if (parse_headers(p_msg, HDR_TO_F, 0)==-1 || !p_msg->to) { + if(get_cseq(p_msg)->method.len == INVITE_LEN + && memcmp(get_cseq(p_msg)->method.s, INVITE, INVITE_LEN) + == 0) { + if(parse_headers(p_msg, HDR_TO_F, 0) == -1 || !p_msg->to) { LM_ERR("INVITE reply cannot be parsed\n"); goto error; } } - ret=t_reply_matching( p_msg , - param_branch!=0?param_branch:&local_branch ); + ret = t_reply_matching( + p_msg, param_branch != 0 ? param_branch : &local_branch); } #ifdef EXTRA_DEBUG - if ( T && T!=T_UNDEFINED && T->flags & (T_IN_AGONY)) { + if(T && T != T_UNDEFINED && T->flags & (T_IN_AGONY)) { LM_WARN("transaction %p scheduled for deletion " - "and called from t_check_msg (flags=%x) (but it might be ok)" - " (msg %p)\n", T, T->flags, p_msg); + "and called from t_check_msg (flags=%x) (but it might be " + "ok)" + " (msg %p)\n", + T, T->flags, p_msg); } #endif - LM_DBG("msg (%p) id=%u/%d global id=%u/%d T end=%p\n", - p_msg, p_msg->id, p_msg->pid, tm_global_ctx_id.msgid, - tm_global_ctx_id.pid, T); + LM_DBG("msg (%p) id=%u/%d global id=%u/%d T end=%p\n", p_msg, p_msg->id, + p_msg->pid, tm_global_ctx_id.msgid, tm_global_ctx_id.pid, T); } else { /* (msg_ctx_id_match(p_msg, &tm_global_ctx_id)!=1 || && T!=T_UNDEFINED ) */ - if (T){ + if(T) { LM_DBG("T (%p) already found for msg (%p)!\n", T, p_msg); - ret=1; - }else{ + ret = 1; + } else { LM_DBG("T previously sought and not found for msg (%p)\n", p_msg); - ret=-1; + ret = -1; } - if (likely(param_branch)) - *param_branch=T_branch; + if(likely(param_branch)) + *param_branch = T_branch; } return ret; error: @@ -1565,7 +1653,6 @@ int t_check_msg( struct sip_msg* p_msg , int *param_branch ) } - /** Determine current transaction (old version). * * Found Not Found Error (e.g. parsing) @@ -1574,54 +1661,57 @@ int t_check_msg( struct sip_msg* p_msg , int *param_branch ) * * Side-effects: sets T and T_branch. */ -int t_check( struct sip_msg* p_msg , int *param_branch ) +int t_check(struct sip_msg *p_msg, int *param_branch) { int ret; - ret=t_check_msg(p_msg, param_branch); + ret = t_check_msg(p_msg, param_branch); /* fix t_check_msg return */ - switch(ret){ - case -2: /* e2e ack */ return 0; /* => not found */ - case -1: /* not found */ return 0; /* => not found */ - case 0: /* parse error */ return -1; /* => error */ - case 1: /* found */ return ret; /* => found */ + switch(ret) { + case -2: /* e2e ack */ + return 0; /* => not found */ + case -1: /* not found */ + return 0; /* => not found */ + case 0: /* parse error */ + return -1; /* => error */ + case 1: /* found */ + return ret; /* => found */ }; return ret; } - -int init_rb( struct retr_buf *rb, struct sip_msg *msg) +int init_rb(struct retr_buf *rb, struct sip_msg *msg) { /*struct socket_info* send_sock;*/ - struct via_body* via; + struct via_body *via; int proto; /* rb. timers are init. init_t()/new_cell() */ - via=msg->via1; + via = msg->via1; /* rb->dst is already init (0) by new_t()/build_cell() */ - if (!reply_to_via) { - update_sock_struct_from_ip( &rb->dst.to, msg ); - proto=msg->rcv.proto; + if(!reply_to_via) { + update_sock_struct_from_ip(&rb->dst.to, msg); + proto = msg->rcv.proto; } else { /*init retrans buffer*/ - if (update_sock_struct_from_via( &(rb->dst.to), msg, via )==-1) { - LM_ERR("cannot lookup reply dst: %.*s\n", - via->host.len, via->host.s ); - ser_error=E_BAD_VIA; + if(update_sock_struct_from_via(&(rb->dst.to), msg, via) == -1) { + LM_ERR("cannot lookup reply dst: %.*s\n", via->host.len, + via->host.s); + ser_error = E_BAD_VIA; return 0; } - proto=via->proto; + proto = via->proto; } - rb->dst.proto=proto; - rb->dst.id=msg->rcv.proto_reserved1; + rb->dst.proto = proto; + rb->dst.id = msg->rcv.proto_reserved1; #ifdef USE_COMP - rb->dst.comp=via->comp_no; + rb->dst.comp = via->comp_no; #endif - rb->dst.send_flags=msg->rpl_send_flags; + rb->dst.send_flags = msg->rpl_send_flags; membar_write(); - rb->dst.send_sock=msg->rcv.bind_address; + rb->dst.send_sock = msg->rcv.bind_address; return 1; } @@ -1632,17 +1722,17 @@ static inline void init_new_t(struct cell *new_cell, struct sip_msg *p_msg) unsigned int timeout; /* avp timeout gets stored here (in s) */ ticks_t lifetime; - shm_msg=new_cell->uas.request; - new_cell->from_hdr.s=shm_msg->from->name.s; - new_cell->from_hdr.len=HF_LEN(shm_msg->from); - new_cell->to_hdr.s=shm_msg->to->name.s; - new_cell->to_hdr.len=HF_LEN(shm_msg->to); - new_cell->callid_hdr.s=shm_msg->callid->name.s; - new_cell->callid_hdr.len=HF_LEN(shm_msg->callid); - new_cell->cseq_hdr_n.s=shm_msg->cseq->name.s; - new_cell->cseq_hdr_n.len=get_cseq(shm_msg)->number.s - +get_cseq(shm_msg)->number.len - -shm_msg->cseq->name.s; + shm_msg = new_cell->uas.request; + new_cell->from_hdr.s = shm_msg->from->name.s; + new_cell->from_hdr.len = HF_LEN(shm_msg->from); + new_cell->to_hdr.s = shm_msg->to->name.s; + new_cell->to_hdr.len = HF_LEN(shm_msg->to); + new_cell->callid_hdr.s = shm_msg->callid->name.s; + new_cell->callid_hdr.len = HF_LEN(shm_msg->callid); + new_cell->cseq_hdr_n.s = shm_msg->cseq->name.s; + new_cell->cseq_hdr_n.len = get_cseq(shm_msg)->number.s + + get_cseq(shm_msg)->number.len + - shm_msg->cseq->name.s; new_cell->callid_val.s = shm_msg->callid->body.s; new_cell->callid_val.len = shm_msg->callid->body.len; trim(&new_cell->callid_val); @@ -1653,71 +1743,69 @@ static inline void init_new_t(struct cell *new_cell, struct sip_msg *p_msg) new_cell->cseq_met.len = get_cseq(shm_msg)->method.len; trim(&new_cell->cseq_met); - new_cell->method=new_cell->uas.request->first_line.u.request.method; - if (p_msg->REQ_METHOD==METHOD_INVITE){ + new_cell->method = new_cell->uas.request->first_line.u.request.method; + if(p_msg->REQ_METHOD == METHOD_INVITE) { /* set flags */ - new_cell->flags |= T_IS_INVITE_FLAG | - get_msgid_val(user_cell_set_flags, p_msg->id, int); - new_cell->flags|=T_AUTO_INV_100 & - (!cfg_get(tm, tm_cfg, tm_auto_inv_100) -1); - new_cell->flags|=T_DISABLE_6xx & - (!cfg_get(tm, tm_cfg, disable_6xx) -1); - new_cell->flags|=T_NO_E2E_CANCEL_REASON & - (!!cfg_get(tm, tm_cfg, e2e_cancel_reason) -1); + new_cell->flags |= T_IS_INVITE_FLAG + | get_msgid_val(user_cell_set_flags, p_msg->id, int); + new_cell->flags |= + T_AUTO_INV_100 & (!cfg_get(tm, tm_cfg, tm_auto_inv_100) - 1); + new_cell->flags |= + T_DISABLE_6xx & (!cfg_get(tm, tm_cfg, disable_6xx) - 1); + new_cell->flags |= T_NO_E2E_CANCEL_REASON + & (!!cfg_get(tm, tm_cfg, e2e_cancel_reason) - 1); /* reset flags */ new_cell->flags &= - (~ get_msgid_val(user_cell_reset_flags, p_msg->id, int)); - - lifetime=(ticks_t)get_msgid_val(user_inv_max_lifetime, - p_msg->id, int); - if (likely(lifetime==0)) - lifetime=cfg_get(tm, tm_cfg, tm_max_inv_lifetime); - }else{ - lifetime=(ticks_t)get_msgid_val(user_noninv_max_lifetime, - p_msg->id, int); - if (likely(lifetime==0)) - lifetime=cfg_get(tm, tm_cfg, tm_max_noninv_lifetime); - } - new_cell->on_failure=get_on_failure(); - new_cell->on_branch_failure=get_on_branch_failure(); - new_cell->on_reply=get_on_reply(); - new_cell->end_of_life=get_ticks_raw()+lifetime;; - new_cell->fr_timeout=(ticks_t)get_msgid_val(user_fr_timeout, - p_msg->id, int); - new_cell->fr_inv_timeout=(ticks_t)get_msgid_val(user_fr_inv_timeout, - p_msg->id, int); - if (likely(new_cell->fr_timeout==0)){ - if (unlikely(!fr_avp2timer(&timeout))) { + (~get_msgid_val(user_cell_reset_flags, p_msg->id, int)); + + lifetime = + (ticks_t)get_msgid_val(user_inv_max_lifetime, p_msg->id, int); + if(likely(lifetime == 0)) + lifetime = cfg_get(tm, tm_cfg, tm_max_inv_lifetime); + } else { + lifetime = (ticks_t)get_msgid_val( + user_noninv_max_lifetime, p_msg->id, int); + if(likely(lifetime == 0)) + lifetime = cfg_get(tm, tm_cfg, tm_max_noninv_lifetime); + } + new_cell->on_failure = get_on_failure(); + new_cell->on_branch_failure = get_on_branch_failure(); + new_cell->on_reply = get_on_reply(); + new_cell->end_of_life = get_ticks_raw() + lifetime; + ; + new_cell->fr_timeout = + (ticks_t)get_msgid_val(user_fr_timeout, p_msg->id, int); + new_cell->fr_inv_timeout = + (ticks_t)get_msgid_val(user_fr_inv_timeout, p_msg->id, int); + if(likely(new_cell->fr_timeout == 0)) { + if(unlikely(!fr_avp2timer(&timeout))) { LM_DBG("init_new_t: FR__TIMER = %d s\n", timeout); - new_cell->fr_timeout=S_TO_TICKS((ticks_t)timeout); - }else{ - new_cell->fr_timeout=cfg_get(tm, tm_cfg, fr_timeout); + new_cell->fr_timeout = S_TO_TICKS((ticks_t)timeout); + } else { + new_cell->fr_timeout = cfg_get(tm, tm_cfg, fr_timeout); } } - if (likely(new_cell->fr_inv_timeout==0)){ - if (unlikely(!fr_inv_avp2timer(&timeout))) { + if(likely(new_cell->fr_inv_timeout == 0)) { + if(unlikely(!fr_inv_avp2timer(&timeout))) { LM_DBG("init_new_t: FR_INV_TIMER = %d s\n", timeout); - new_cell->fr_inv_timeout=S_TO_TICKS((ticks_t)timeout); + new_cell->fr_inv_timeout = S_TO_TICKS((ticks_t)timeout); new_cell->flags |= T_NOISY_CTIMER_FLAG; - }else{ - new_cell->fr_inv_timeout=cfg_get(tm, tm_cfg, fr_inv_timeout); + } else { + new_cell->fr_inv_timeout = cfg_get(tm, tm_cfg, fr_inv_timeout); } } - new_cell->rt_t1_timeout_ms = (retr_timeout_t) get_msgid_val( - user_rt_t1_timeout_ms, - p_msg->id, int); - if (likely(new_cell->rt_t1_timeout_ms == 0)) + new_cell->rt_t1_timeout_ms = (retr_timeout_t)get_msgid_val( + user_rt_t1_timeout_ms, p_msg->id, int); + if(likely(new_cell->rt_t1_timeout_ms == 0)) new_cell->rt_t1_timeout_ms = cfg_get(tm, tm_cfg, rt_t1_timeout_ms); - new_cell->rt_t2_timeout_ms = (retr_timeout_t) get_msgid_val( - user_rt_t2_timeout_ms, - p_msg->id, int); - if (likely(new_cell->rt_t2_timeout_ms == 0)) + new_cell->rt_t2_timeout_ms = (retr_timeout_t)get_msgid_val( + user_rt_t2_timeout_ms, p_msg->id, int); + if(likely(new_cell->rt_t2_timeout_ms == 0)) new_cell->rt_t2_timeout_ms = cfg_get(tm, tm_cfg, rt_t2_timeout_ms); - new_cell->on_branch=get_on_branch(); + new_cell->on_branch = get_on_branch(); } - /** creates a new transaction from a message. * No checks are made if the transaction exists. It is created and * added to the tm hashes. T is set to the new transaction. @@ -1730,26 +1818,26 @@ static inline int new_t(struct sip_msg *p_msg) struct cell *new_cell; /* for ACK-dlw-wise matching, we want From-tags */ - if (p_msg->REQ_METHOD==METHOD_INVITE && parse_from_header(p_msg)<0) { + if(p_msg->REQ_METHOD == METHOD_INVITE && parse_from_header(p_msg) < 0) { LM_ERR("no valid From in INVITE\n"); return E_BAD_REQ; } /* make sure uri will be parsed before cloning */ - if (parse_sip_msg_uri(p_msg)<0) { + if(parse_sip_msg_uri(p_msg) < 0) { LM_ERR("uri invalid\n"); return E_BAD_REQ; } /* add new transaction */ - new_cell = build_cell( p_msg ) ; - if ( !new_cell ){ + new_cell = build_cell(p_msg); + if(!new_cell) { LM_ERR("out of mem:\n"); return E_OUT_OF_MEM; } INIT_REF(new_cell, 2); /* 1 because it will be ref'ed from the * hash and +1 because we set T to it */ - insert_into_hash_table_unsafe( new_cell, p_msg->hash_index ); + insert_into_hash_table_unsafe(new_cell, p_msg->hash_index); set_t(new_cell, T_BR_UNDEFINED); /* init pointers to headers needed to construct local * requests such as CANCEL/ACK @@ -1759,7 +1847,6 @@ static inline int new_t(struct sip_msg *p_msg) } - /** if no transaction already exists for the message, create a new one. * atomic "new_tran" construct; it returns: * @@ -1771,29 +1858,28 @@ static inline int new_t(struct sip_msg *p_msg) * introduced and the calling function shall reply/relay/whatever_appropriate. * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED). */ -int t_newtran( struct sip_msg* p_msg ) +int t_newtran(struct sip_msg *p_msg) { int lret, my_err; int canceled; /* is T still up-to-date ? */ - LM_DBG("msg (%p) id=%u/%d global id=%u/%d T start=%p\n", - p_msg, p_msg->id, p_msg->pid, tm_global_ctx_id.msgid, - tm_global_ctx_id.pid, T); + LM_DBG("msg (%p) id=%u/%d global id=%u/%d T start=%p\n", p_msg, p_msg->id, + p_msg->pid, tm_global_ctx_id.msgid, tm_global_ctx_id.pid, T); if(faked_msg_match(p_msg)) { LM_INFO("attempt to create transaction for a faked request" " - try to avoid it\n"); } - if ( T && T!=T_UNDEFINED ) { + if(T && T != T_UNDEFINED) { /* ERROR message moved to w_t_newtran */ - LM_DBG("transaction already in process %p\n", T ); + LM_DBG("transaction already in process %p\n", T); /* t_newtran() has been already called, and the script * might changed the flags after it, so we must update the flags * in shm memory -- Miklos */ - if (T->uas.request) { + if(T->uas.request) { T->uas.request->flags = p_msg->flags; memcpy(T->uas.request->xflags, p_msg->xflags, KSR_XFLAGS_SIZE * sizeof(flag_t)); @@ -1811,11 +1897,11 @@ int t_newtran( struct sip_msg* p_msg ) * shmem with pkg_mem */ - if (parse_headers(p_msg, HDR_EOH_F, 0 )) { + if(parse_headers(p_msg, HDR_EOH_F, 0)) { LM_ERR("parse_headers failed\n"); return E_BAD_REQ; } - if ((p_msg->parsed_flag & HDR_EOH_F)!=HDR_EOH_F) { + if((p_msg->parsed_flag & HDR_EOH_F) != HDR_EOH_F) { LM_ERR("EoH not parsed\n"); return E_OUT_OF_MEM; } @@ -1823,28 +1909,29 @@ int t_newtran( struct sip_msg* p_msg ) * it also calls check_transaction_quadruple -> it is * safe to assume we have from/callid/cseq/to */ - lret = t_lookup_request( p_msg, 1 /* leave locked if not found */, - &canceled ); + lret = t_lookup_request( + p_msg, 1 /* leave locked if not found */, &canceled); /* on error, pass the error in the stack ... nothing is locked yet * if 0 is returned */ - if (lret==0) return E_BAD_TUPEL; + if(lret == 0) + return E_BAD_TUPEL; /* transaction found, it's a retransmission */ - if (lret>0) { - if ( T==NULL || T==T_UNDEFINED ) { + if(lret > 0) { + if(T == NULL || T == T_UNDEFINED) { LM_ERR("BUG: transaction is gone\n"); return 0; } - if (p_msg->REQ_METHOD==METHOD_ACK) { - 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); + if(p_msg->REQ_METHOD == METHOD_ACK) { + 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); } else { - if (unlikely(has_tran_tmcbs(T, TMCB_REQ_RETR_IN))) - run_trans_callbacks(TMCB_REQ_RETR_IN, T, p_msg, 0, - p_msg->REQ_METHOD); + if(unlikely(has_tran_tmcbs(T, TMCB_REQ_RETR_IN))) + run_trans_callbacks( + TMCB_REQ_RETR_IN, T, p_msg, 0, p_msg->REQ_METHOD); t_retransmit_reply(T); } /* things are done -- return from script */ @@ -1853,10 +1940,10 @@ int t_newtran( struct sip_msg* p_msg ) /* from now on, be careful -- hash table is locked */ - if (lret==-2) { /* was it an e2e ACK ? if so, trigger a callback */ + if(lret == -2) { /* was it an e2e ACK ? if so, trigger a callback */ /* no callbacks? complete quickly */ - if (likely( !has_tran_tmcbs(t_ack, - TMCB_E2EACK_IN|TMCB_E2EACK_RETR_IN) )) { + if(likely(!has_tran_tmcbs( + t_ack, TMCB_E2EACK_IN | TMCB_E2EACK_RETR_IN))) { UNLOCK_HASH(p_msg->hash_index); return 1; } @@ -1867,13 +1954,13 @@ int t_newtran( struct sip_msg* p_msg ) * impact is so small (callback called multiple times of * multiple ACK/200s received in parallel), that we do not * better waste time in locks */ - if (unmatched_totag(t_ack, p_msg)) { - if (likely (has_tran_tmcbs(t_ack, TMCB_E2EACK_IN))) - run_trans_callbacks( TMCB_E2EACK_IN , t_ack, p_msg, 0, - -p_msg->REQ_METHOD ); - }else if (unlikely(has_tran_tmcbs(t_ack, TMCB_E2EACK_RETR_IN))){ - run_trans_callbacks( TMCB_E2EACK_RETR_IN , t_ack, p_msg, 0, - -p_msg->REQ_METHOD ); + if(unmatched_totag(t_ack, p_msg)) { + if(likely(has_tran_tmcbs(t_ack, TMCB_E2EACK_IN))) + run_trans_callbacks( + TMCB_E2EACK_IN, t_ack, p_msg, 0, -p_msg->REQ_METHOD); + } else if(unlikely(has_tran_tmcbs(t_ack, TMCB_E2EACK_RETR_IN))) { + run_trans_callbacks( + TMCB_E2EACK_RETR_IN, t_ack, p_msg, 0, -p_msg->REQ_METHOD); } UNREF(t_ack); return 1; @@ -1882,17 +1969,18 @@ int t_newtran( struct sip_msg* p_msg ) /* transaction not found, it's a new request (lret<0, lret!=-2); * establish a new transaction ... */ - if (p_msg->REQ_METHOD==METHOD_ACK) { /* ... unless it is in ACK */ - my_err=1; + if(p_msg->REQ_METHOD == METHOD_ACK) { /* ... unless it is in ACK */ + my_err = 1; goto new_err; } - my_err=new_t(p_msg); - if (my_err<0) { + my_err = new_t(p_msg); + if(my_err < 0) { LM_ERR("new_t failed\n"); goto new_err; } - if (canceled) T->flags|=T_CANCELED; /* mark it for future ref. */ + if(canceled) + T->flags |= T_CANCELED; /* mark it for future ref. */ UNLOCK_HASH(p_msg->hash_index); @@ -1905,9 +1993,9 @@ int t_newtran( struct sip_msg* p_msg ) * error, we cannot relay later whatever comes out of the * the transaction * */ - if (!init_rb( &T->uas.response, p_msg)) { + if(!init_rb(&T->uas.response, p_msg)) { LM_ERR("unresolvable via1\n"); - put_on_wait( T ); + put_on_wait(T); t_unref(p_msg); return E_BAD_VIA; } @@ -1918,11 +2006,9 @@ int t_newtran( struct sip_msg* p_msg ) new_err: UNLOCK_HASH(p_msg->hash_index); return my_err; - } - /** releases the current transaction (corresp. to p_msg). * The current transaction (T) corresponding to the sip message being * processed is released. Delayed replies are sent (if no other reply @@ -1934,53 +2020,58 @@ int t_newtran( struct sip_msg* p_msg ) * Side-effects: resets T and T_branch to T_UNDEFINED, T_BR_UNDEFINED, * resets tm_error. */ -int t_unref( struct sip_msg* p_msg ) +int t_unref(struct sip_msg *p_msg) { enum kill_reason kr; - if (T==T_UNDEFINED || T==T_NULL_CELL) + if(T == T_UNDEFINED || T == T_NULL_CELL) return -1; - if (p_msg->first_line.type==SIP_REQUEST){ - kr=get_kr(); - if (unlikely(kr == REQ_ERR_DELAYED)){ + if(p_msg->first_line.type == SIP_REQUEST) { + kr = get_kr(); + if(unlikely(kr == REQ_ERR_DELAYED)) { LM_DBG("delayed error reply generation(%d)\n", tm_error); - if (unlikely(is_route_type(FAILURE_ROUTE))){ + if(unlikely(is_route_type(FAILURE_ROUTE))) { LM_BUG("called w/ kr=REQ_ERR_DELAYED in failure" - " route for %p\n", T); - }else if (unlikely( kill_transaction(T, tm_error)<=0 )){ + " route for %p\n", + T); + } else if(unlikely(kill_transaction(T, tm_error) <= 0)) { // could be a valid error, or due to an immediate CANCEL LM_WARN("generation of a delayed stateful reply" " failed\n"); t_release_transaction(T); } - }else if ( unlikely (kr==0 ||(p_msg->REQ_METHOD==METHOD_ACK && - !(kr & REQ_RLSD)))) { + } else if(unlikely(kr == 0 + || (p_msg->REQ_METHOD == METHOD_ACK + && !(kr & REQ_RLSD)))) { LM_WARN("script writer didn't release transaction\n"); t_release_transaction(T); - }else if (unlikely((kr & REQ_ERR_DELAYED) && - (kr & ~(REQ_RLSD|REQ_RPLD|REQ_ERR_DELAYED|REQ_FWDED)))){ + } else if(unlikely((kr & REQ_ERR_DELAYED) + && (kr + & ~(REQ_RLSD | REQ_RPLD | REQ_ERR_DELAYED + | REQ_FWDED)))) { LM_BUG("REQ_ERR DELAYED should have been caught much" - " earlier for %p: %d (hex %x)\n",T, kr, kr); + " earlier for %p: %d (hex %x)\n", + T, kr, kr); t_release_transaction(T); } } - tm_error=0; /* clear it */ - UNREF( T ); + tm_error = 0; /* clear it */ + UNREF(T); set_t(T_UNDEFINED, T_BR_UNDEFINED); return 1; } - -int t_get_trans_ident(struct sip_msg* p_msg, unsigned int* hash_index, unsigned int* label) +int t_get_trans_ident( + struct sip_msg *p_msg, unsigned int *hash_index, unsigned int *label) { - struct cell* t; - if(t_check(p_msg,0) != 1){ + struct cell *t; + if(t_check(p_msg, 0) != 1) { LM_ERR("no transaction found\n"); return -1; } t = get_t(); - if(!t){ + if(!t) { LM_ERR("transaction found is NULL\n"); return -1; } @@ -1994,17 +2085,17 @@ int t_get_trans_ident(struct sip_msg* p_msg, unsigned int* hash_index, unsigned /** * 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) +int t_get_canceled_ident( + struct sip_msg *msg, unsigned int *hash_index, unsigned int *label) { struct cell *orig; - if (msg->REQ_METHOD != METHOD_CANCEL) { + if(msg->REQ_METHOD != METHOD_CANCEL) { LM_WARN("looking up original transaction for non-CANCEL method (%d).\n", msg->REQ_METHOD); return -1; } orig = t_lookupOriginalT(msg); - if ((orig == T_NULL_CELL) || (orig == T_UNDEFINED)) + if((orig == T_NULL_CELL) || (orig == T_UNDEFINED)) return -1; *hash_index = orig->hash_index; *label = orig->label; @@ -2015,7 +2106,6 @@ int t_get_canceled_ident(struct sip_msg* msg, unsigned int* hash_index, } - /** lookup a transaction based on its identifier (hash_index:label). * @param trans - double pointer to cell structure, that will be filled * with the result (a pointer to an existing transaction or @@ -2026,14 +2116,14 @@ int t_get_canceled_ident(struct sip_msg* msg, unsigned int* hash_index, * @return -1 on error/not found, 1 on success (found) * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED). */ -int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index, +int t_lookup_ident_filter(struct cell **trans, unsigned int hash_index, unsigned int label, int filter) { - struct cell* p_cell; - struct entry* hash_bucket; + struct cell *p_cell; + struct entry *hash_bucket; - if(unlikely(hash_index >= TABLE_ENTRIES)){ - LM_ERR("invalid hash_index=%u\n",hash_index); + if(unlikely(hash_index >= TABLE_ENTRIES)) { + LM_ERR("invalid hash_index=%u\n", hash_index); return -1; } @@ -2043,17 +2133,18 @@ int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index, #warning "t_lookup_ident() can only reliably match INVITE transactions in " \ "E2E_CANCEL_HOP_BY_HOP mode" #endif - hash_bucket=&(get_tm_table()->entries[hash_index]); + hash_bucket = &(get_tm_table()->entries[hash_index]); /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c) { + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); if(p_cell->label == label) { - if(filter==1) { + if(filter == 1) { if(t_on_wait(p_cell)) { /* transaction in terminated state */ UNLOCK_HASH(hash_index); set_t(0, T_BR_UNDEFINED); - *trans=NULL; + *trans = NULL; LM_DBG("transaction in terminated phase - skipping\n"); return -1; } @@ -2061,7 +2152,7 @@ int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index, REF_UNSAFE(p_cell); UNLOCK_HASH(hash_index); set_t(p_cell, T_BR_UNDEFINED); - *trans=p_cell; + *trans = p_cell; LM_DBG("transaction found\n"); return 1; } @@ -2069,7 +2160,7 @@ int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index, UNLOCK_HASH(hash_index); set_t(0, T_BR_UNDEFINED); - *trans=NULL; + *trans = NULL; LM_DBG("transaction not found\n"); @@ -2085,8 +2176,8 @@ int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index, * @return -1 on error/not found, 1 on success (found) * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED). */ -int t_lookup_ident(struct cell ** trans, unsigned int hash_index, - unsigned int label) +int t_lookup_ident( + struct cell **trans, unsigned int hash_index, unsigned int label) { return t_lookup_ident_filter(trans, hash_index, label, 0); } @@ -2102,25 +2193,26 @@ int t_lookup_ident(struct cell ** trans, unsigned int hash_index, * Note: it does not sets T and T_branch, nor reference the transaction, * useful to quickly check if a transaction still exists */ -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) { tm_cell_t *p_cell; tm_entry_t *hash_bucket; - if(unlikely(hash_index >= TABLE_ENTRIES)){ + if(unlikely(hash_index >= TABLE_ENTRIES)) { LM_ERR("invalid hash_index=%u\n", hash_index); return NULL; } LOCK_HASH(hash_index); - hash_bucket=&(get_tm_table()->entries[hash_index]); + hash_bucket = &(get_tm_table()->entries[hash_index]); /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c) { + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); if(p_cell->label == label) { - if(filter==1) { + if(filter == 1) { if(t_on_wait(p_cell)) { /* transaction in terminated state */ UNLOCK_HASH(hash_index); @@ -2147,15 +2239,15 @@ tm_cell_t *t_find_ident_filter(unsigned int hash_index, unsigned int label, * @return -1 on error, 0 if the transaction is not local, 1 if it is local. * Side-effects: sets T and T_branch. */ -int t_is_local(struct sip_msg* p_msg) +int t_is_local(struct sip_msg *p_msg) { - struct cell* t; - if(t_check(p_msg,0) != 1){ + struct cell *t; + if(t_check(p_msg, 0) != 1) { LM_ERR("no transaction found\n"); return -1; } t = get_t(); - if(!t){ + if(!t) { LM_ERR("transaction found is NULL\n"); return -1; } @@ -2174,16 +2266,17 @@ int t_is_local(struct sip_msg* p_msg) * @return -1 on error/not found, 1 if found. * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED). */ -int t_lookup_callid(struct cell ** trans, str callid, str cseq) { - struct cell* p_cell; +int t_lookup_callid(struct cell **trans, str callid, str cseq) +{ + struct cell *p_cell; unsigned hash_index; - struct entry* hash_bucket; + struct entry *hash_bucket; /* lookup the hash index where the transaction is stored */ - hash_index=hash(callid, cseq); + hash_index = hash(callid, cseq); - if(unlikely(hash_index >= TABLE_ENTRIES)){ - LM_ERR("invalid hash_index=%u\n",hash_index); + if(unlikely(hash_index >= TABLE_ENTRIES)) { + LM_ERR("invalid hash_index=%u\n", hash_index); return -1; } @@ -2191,37 +2284,41 @@ int t_lookup_callid(struct cell ** trans, str callid, str cseq) { LM_DBG("just locked hash index %u, looking for transactions there:\n", hash_index); - hash_bucket=&(get_tm_table()->entries[hash_index]); + hash_bucket = &(get_tm_table()->entries[hash_index]); /* all the transactions from the entry are compared */ - clist_foreach(hash_bucket, p_cell, next_c){ + clist_foreach(hash_bucket, p_cell, next_c) + { prefetch_loc_r(p_cell->next_c, 1); - if(p_cell->callid_val.s==NULL || p_cell->cseq_num.s==NULL - || p_cell->cseq_met.s==NULL) { - LM_CRIT("null shortcuts for matching attributes - t:%p cid:%p csn:%p csm:%p\n", - p_cell, p_cell->callid_val.s, p_cell->cseq_num.s, p_cell->cseq_met.s); + if(p_cell->callid_val.s == NULL || p_cell->cseq_num.s == NULL + || p_cell->cseq_met.s == NULL) { + LM_CRIT("null shortcuts for matching attributes - t:%p cid:%p " + "csn:%p csm:%p\n", + p_cell, p_cell->callid_val.s, p_cell->cseq_num.s, + p_cell->cseq_met.s); continue; } /* compare complete header fields, casecmp to make sure invite=INVITE*/ - if((callid.len==p_cell->callid_val.len) && (cseq.len==p_cell->cseq_num.len) - && (INVITE_LEN==p_cell->cseq_met.len) - && (strncmp(callid.s, p_cell->callid_val.s, callid.len)==0) - && (strncmp(cseq.s, p_cell->cseq_num.s, cseq.len)==0) - && (strncasecmp(INVITE, p_cell->cseq_met.s, INVITE_LEN)==0)) { + if((callid.len == p_cell->callid_val.len) + && (cseq.len == p_cell->cseq_num.len) + && (INVITE_LEN == p_cell->cseq_met.len) + && (strncmp(callid.s, p_cell->callid_val.s, callid.len) == 0) + && (strncmp(cseq.s, p_cell->cseq_num.s, cseq.len) == 0) + && (strncasecmp(INVITE, p_cell->cseq_met.s, INVITE_LEN) == 0)) { LM_DBG("we have a match: callid=>>%.*s<< cseq=>>%.*s<<\n", p_cell->callid_hdr.len, p_cell->callid_hdr.s, p_cell->cseq_hdr_n.len, p_cell->cseq_hdr_n.s); REF_UNSAFE(p_cell); UNLOCK_HASH(hash_index); set_t(p_cell, T_BR_UNDEFINED); - *trans=p_cell; + *trans = p_cell; LM_DBG("t_lookup_callid: transaction found.\n"); return 1; } LM_DBG("NO match: callid=%.*s cseq=%.*s\n", p_cell->callid_hdr.len, - p_cell->callid_hdr.s, p_cell->cseq_hdr_n.len, p_cell->cseq_hdr_n.s); - + p_cell->callid_hdr.s, p_cell->cseq_hdr_n.len, + p_cell->cseq_hdr_n.s); } UNLOCK_HASH(hash_index); @@ -2231,35 +2328,36 @@ int t_lookup_callid(struct cell ** trans, str callid, str cseq) { } - /* params: fr_inv & fr value in ms, 0 means "do not touch" * ret: 1 on success, -1 on error (script safe)*/ -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) { struct cell *t; ticks_t fr_inv, fr; - fr_inv=MS_TO_TICKS((ticks_t)fr_inv_to); - if ((fr_inv==0) && (fr_inv_to!=0)){ + fr_inv = MS_TO_TICKS((ticks_t)fr_inv_to); + if((fr_inv == 0) && (fr_inv_to != 0)) { LM_ERR("fr_inv_timeout too small (%d)\n", fr_inv_to); return -1; } - fr=MS_TO_TICKS((ticks_t)fr_to); - if ((fr==0) && (fr_to!=0)){ + fr = MS_TO_TICKS((ticks_t)fr_to); + if((fr == 0) && (fr_to != 0)) { LM_ERR("fr_timeout too small (%d)\n", fr_to); return -1; } - t=get_t(); + t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variables */ - if (!t || t==T_UNDEFINED ){ + if(!t || t == T_UNDEFINED) { set_msgid_val(user_fr_inv_timeout, msg->id, int, (int)fr_inv); set_msgid_val(user_fr_timeout, msg->id, int, (int)fr); - }else{ + } else { #ifdef TIMER_DEBUG - LM_DBG("changing default FR timeout values: (\"fr_inv_timeout\": %d, \"fr_timeout\": %d)\n", fr_inv, fr); + LM_DBG("changing default FR timeout values: (\"fr_inv_timeout\": %d, " + "\"fr_timeout\": %d)\n", + fr_inv, fr); #endif change_fr(t, fr_inv, fr); /* change running uac timers */ } @@ -2271,17 +2369,17 @@ int t_reset_fr() { struct cell *t; - t=get_t(); + t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variables */ - if (!t || t==T_UNDEFINED ){ + if(!t || t == T_UNDEFINED) { memset(&user_fr_inv_timeout, 0, sizeof(user_fr_inv_timeout)); memset(&user_fr_timeout, 0, sizeof(user_fr_timeout)); - }else{ - change_fr(t, - cfg_get(tm, tm_cfg, fr_inv_timeout), - cfg_get(tm, tm_cfg, fr_timeout)); /* change running uac timers */ + } else { + change_fr(t, cfg_get(tm, tm_cfg, fr_inv_timeout), + cfg_get(tm, tm_cfg, + fr_timeout)); /* change running uac timers */ } return 1; } @@ -2289,42 +2387,44 @@ int t_reset_fr() /* params: retr. t1 & retr. t2 value in ms, 0 means "do not touch" * ret: 1 on success, -1 on error (script safe)*/ -int t_set_retr(struct sip_msg* msg, unsigned int t1_ms, unsigned int t2_ms) +int t_set_retr(struct sip_msg *msg, unsigned int t1_ms, unsigned int t2_ms) { struct cell *t; ticks_t retr_t1, retr_t2; - retr_t1=MS_TO_TICKS((ticks_t)t1_ms); - if (unlikely((retr_t1==0) && (t1_ms!=0))){ + retr_t1 = MS_TO_TICKS((ticks_t)t1_ms); + if(unlikely((retr_t1 == 0) && (t1_ms != 0))) { LM_ERR("retr. t1 interval too small (%u)\n", t1_ms); return -1; } - if (unlikely(MAX_UVAR_VALUE(t->rt_t1_timeout_ms) < t1_ms)){ - LM_ERR("retr. t1 interval too big: %d (max %lu)\n", - t1_ms, MAX_UVAR_VALUE(t->rt_t1_timeout_ms)); + if(unlikely(MAX_UVAR_VALUE(t->rt_t1_timeout_ms) < t1_ms)) { + LM_ERR("retr. t1 interval too big: %d (max %lu)\n", t1_ms, + MAX_UVAR_VALUE(t->rt_t1_timeout_ms)); return -1; } - retr_t2=MS_TO_TICKS((ticks_t)t2_ms); - if (unlikely((retr_t2==0) && (t2_ms!=0))){ + retr_t2 = MS_TO_TICKS((ticks_t)t2_ms); + if(unlikely((retr_t2 == 0) && (t2_ms != 0))) { LM_ERR("retr. t2 interval too small (%d)\n", t2_ms); return -1; } - if (unlikely(MAX_UVAR_VALUE(t->rt_t2_timeout_ms) < t2_ms)){ - LM_ERR("retr. t2 interval too big: %u (max %lu)\n", - t2_ms, MAX_UVAR_VALUE(t->rt_t2_timeout_ms)); + if(unlikely(MAX_UVAR_VALUE(t->rt_t2_timeout_ms) < t2_ms)) { + LM_ERR("retr. t2 interval too big: %u (max %lu)\n", t2_ms, + MAX_UVAR_VALUE(t->rt_t2_timeout_ms)); return -1; } - t=get_t(); + t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variables */ - if (!t || t==T_UNDEFINED ){ + if(!t || t == T_UNDEFINED) { set_msgid_val(user_rt_t1_timeout_ms, msg->id, int, (int)t1_ms); set_msgid_val(user_rt_t2_timeout_ms, msg->id, int, (int)t2_ms); - }else{ + } else { #ifdef TIMER_DEBUG - LM_DBG("changing default RETR timeout values to: (\"retr_t1_interval\": %d, \"retr_t2_interval\": %d)\n", t1_ms, t2_ms); + LM_DBG("changing default RETR timeout values to: " + "(\"retr_t1_interval\": %d, \"retr_t2_interval\": %d)\n", + t1_ms, t2_ms); #endif change_retr(t, 1, t1_ms, t2_ms); /* change running uac timers */ } @@ -2336,18 +2436,16 @@ int t_reset_retr() { struct cell *t; - t=get_t(); + t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variables */ - if (!t || t==T_UNDEFINED ){ + if(!t || t == T_UNDEFINED) { memset(&user_rt_t1_timeout_ms, 0, sizeof(user_rt_t1_timeout_ms)); memset(&user_rt_t2_timeout_ms, 0, sizeof(user_rt_t2_timeout_ms)); - }else{ + } else { /* change running uac timers */ - change_retr(t, - 1, - cfg_get(tm, tm_cfg, rt_t1_timeout_ms), + change_retr(t, 1, cfg_get(tm, tm_cfg, rt_t1_timeout_ms), cfg_get(tm, tm_cfg, rt_t2_timeout_ms)); } return 1; @@ -2357,38 +2455,35 @@ int t_reset_retr() /* params: maximum transaction lifetime for inv and non-inv * 0 means do not touch" * ret: 1 on success, -1 on error (script safe)*/ -int t_set_max_lifetime(struct sip_msg* msg, - unsigned int lifetime_inv_to, +int t_set_max_lifetime(struct sip_msg *msg, unsigned int lifetime_inv_to, unsigned int lifetime_noninv_to) { struct cell *t; ticks_t max_inv_lifetime, max_noninv_lifetime; - max_noninv_lifetime=MS_TO_TICKS((ticks_t)lifetime_noninv_to); - max_inv_lifetime=MS_TO_TICKS((ticks_t)lifetime_inv_to); - if (unlikely((max_noninv_lifetime==0) && (lifetime_noninv_to!=0))){ - LM_ERR("non-inv. interval too small (%d)\n", - lifetime_noninv_to); + max_noninv_lifetime = MS_TO_TICKS((ticks_t)lifetime_noninv_to); + max_inv_lifetime = MS_TO_TICKS((ticks_t)lifetime_inv_to); + if(unlikely((max_noninv_lifetime == 0) && (lifetime_noninv_to != 0))) { + LM_ERR("non-inv. interval too small (%d)\n", lifetime_noninv_to); return -1; } - if (unlikely((max_inv_lifetime==0) && (lifetime_inv_to!=0))){ - LM_ERR("inv. interval too small (%d)\n", - lifetime_inv_to); + if(unlikely((max_inv_lifetime == 0) && (lifetime_inv_to != 0))) { + LM_ERR("inv. interval too small (%d)\n", lifetime_inv_to); return -1; } - t=get_t(); + t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variables */ - if (!t || t==T_UNDEFINED ){ + if(!t || t == T_UNDEFINED) { set_msgid_val(user_noninv_max_lifetime, msg->id, int, (int)max_noninv_lifetime); - set_msgid_val(user_inv_max_lifetime, msg->id, int, - (int)max_inv_lifetime); - }else{ - change_end_of_life(t, 1, is_invite(t)?max_inv_lifetime: - max_noninv_lifetime); + set_msgid_val( + user_inv_max_lifetime, msg->id, int, (int)max_inv_lifetime); + } else { + change_end_of_life( + t, 1, is_invite(t) ? max_inv_lifetime : max_noninv_lifetime); } return 1; } @@ -2398,20 +2493,17 @@ int t_reset_max_lifetime() { struct cell *t; - t=get_t(); + t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variables */ - if (!t || t==T_UNDEFINED ){ + if(!t || t == T_UNDEFINED) { memset(&user_inv_max_lifetime, 0, sizeof(user_inv_max_lifetime)); memset(&user_noninv_max_lifetime, 0, sizeof(user_noninv_max_lifetime)); - }else{ - change_end_of_life(t, - 1, - is_invite(t)? - cfg_get(tm, tm_cfg, tm_max_inv_lifetime): - cfg_get(tm, tm_cfg, tm_max_noninv_lifetime) - ); + } else { + change_end_of_life(t, 1, + is_invite(t) ? cfg_get(tm, tm_cfg, tm_max_inv_lifetime) + : cfg_get(tm, tm_cfg, tm_max_noninv_lifetime)); } return 1; } @@ -2420,7 +2512,7 @@ int t_reset_max_lifetime() tm_ctx_t _tm_ctx; -tm_ctx_t* tm_ctx_get(void) +tm_ctx_t *tm_ctx_get(void) { return &_tm_ctx; } @@ -2437,4 +2529,3 @@ void tm_ctx_set_branch_index(int v) } #endif - diff --git a/src/modules/tm/t_lookup.h b/src/modules/tm/t_lookup.h index a4e160eb2a5..f3957351a0c 100644 --- a/src/modules/tm/t_lookup.h +++ b/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); diff --git a/src/modules/tm/t_msgbuilder.c b/src/modules/tm/t_msgbuilder.c index 9240e551764..22289830df9 100644 --- a/src/modules/tm/t_msgbuilder.c +++ b/src/modules/tm/t_msgbuilder.c @@ -48,40 +48,38 @@ #define CSEQ "CSeq: " -#define CSEQ_LEN (sizeof(CSEQ)-1) +#define CSEQ_LEN (sizeof(CSEQ) - 1) #define TO "To: " -#define TO_LEN (sizeof(TO)-1) +#define TO_LEN (sizeof(TO) - 1) #define CALLID "Call-ID: " -#define CALLID_LEN (sizeof(CALLID)-1) +#define CALLID_LEN (sizeof(CALLID) - 1) #define FROM "From: " -#define FROM_LEN (sizeof(FROM)-1) +#define FROM_LEN (sizeof(FROM) - 1) #define FROMTAG ";tag=" -#define FROMTAG_LEN (sizeof(FROMTAG)-1) +#define FROMTAG_LEN (sizeof(FROMTAG) - 1) #define TOTAG ";tag=" -#define TOTAG_LEN (sizeof(TOTAG)-1) +#define TOTAG_LEN (sizeof(TOTAG) - 1) #define MAXFWD_VALUE "70" #define MAXFWD_HEADER "Max-Forwards: " MAXFWD_VALUE CRLF #define MAXFWD_HEADER_LEN (sizeof(MAXFWD_HEADER) - 1) /* convenience macros */ -#define memapp(_d,_s,_len) \ - do{\ - memcpy((_d),(_s),(_len));\ - (_d) += (_len);\ - }while(0) +#define memapp(_d, _s, _len) \ + do { \ + memcpy((_d), (_s), (_len)); \ + (_d) += (_len); \ + } while(0) /* Build a local request based on a previous request; main * customers of this function are local ACK and local CANCEL */ -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 *cancel_buf, *p, *via; - unsigned int via_len; - struct hdr_field *hdr; + char *cancel_buf, *p, *via; + unsigned int via_len; + struct hdr_field *hdr; char branch_buf[MAX_BRANCH_PARAM_LEN]; int branch_len; str branch_str; @@ -91,169 +89,174 @@ char *build_local(struct cell *Trans,unsigned int branch, struct hdr_field *reas1, *reas_last; /* init */ - via_id.s=0; - via_id.len=0; + via_id.s = 0; + via_id.len = 0; /* method, separators, version: "CANCEL sip:p2@iptel.org SIP/2.0" */ - *len=SIP_VERSION_LEN + method_len + 2 /* spaces */ + CRLF_LEN; - *len+=Trans->uac[branch].uri.len; + *len = SIP_VERSION_LEN + method_len + 2 /* spaces */ + CRLF_LEN; + *len += Trans->uac[branch].uri.len; /*via*/ - if (!t_calc_branch(Trans, branch, - branch_buf, &branch_len )) + if(!t_calc_branch(Trans, branch, branch_buf, &branch_len)) goto error; - branch_str.s=branch_buf; - branch_str.len=branch_len; - set_hostport(&hp, (is_local(Trans))?0:(Trans->uas.request)); + branch_str.s = branch_buf; + branch_str.len = branch_len; + set_hostport(&hp, (is_local(Trans)) ? 0 : (Trans->uas.request)); #ifdef USE_TCP - if (!is_local(Trans) && ((Trans->uas.request->rcv.proto==PROTO_TCP) + if(!is_local(Trans) + && ((Trans->uas.request->rcv.proto == PROTO_TCP) #ifdef USE_TLS - || (Trans->uas.request->rcv.proto==PROTO_TLS) + || (Trans->uas.request->rcv.proto == PROTO_TLS) #endif /* USE_TLS */ - )){ - if ((via_id.s=id_builder(Trans->uas.request, - (unsigned int*)&via_id.len))==0){ + )) { + if((via_id.s = id_builder( + Trans->uas.request, (unsigned int *)&via_id.len)) + == 0) { LM_ERR("id builder failed\n"); /* try to continue without id */ } } #endif /* USE_TCP */ - via=via_builder(&via_len, NULL, &Trans->uac[branch].request.dst, - &branch_str, via_id.s?&via_id:0 , &hp ); + via = via_builder(&via_len, NULL, &Trans->uac[branch].request.dst, + &branch_str, via_id.s ? &via_id : 0, &hp); /* via_id.s not needed anylonger => free it */ - if (via_id.s) { + if(via_id.s) { pkg_free(via_id.s); - via_id.s=0; - via_id.len=0; + via_id.s = 0; + via_id.len = 0; } - if (!via) { + if(!via) { LM_ERR("no via header got from builder\n"); goto error; } - *len+= via_len; + *len += via_len; /*headers*/ - *len+=Trans->from_hdr.len+Trans->callid_hdr.len+to->len+ - +Trans->cseq_hdr_n.len+1+method_len+CRLF_LEN+MAXFWD_HEADER_LEN; + *len += Trans->from_hdr.len + Trans->callid_hdr.len + to->len + + +Trans->cseq_hdr_n.len + 1 + method_len + CRLF_LEN + + MAXFWD_HEADER_LEN; /* copy'n'paste Route headers */ - if (!is_local(Trans)) { - for ( hdr=Trans->uas.request->headers ; hdr ; hdr=hdr->next ) - if (hdr->type==HDR_ROUTE_T) - *len+=hdr->len; + if(!is_local(Trans)) { + for(hdr = Trans->uas.request->headers; hdr; hdr = hdr->next) + if(hdr->type == HDR_ROUTE_T) + *len += hdr->len; } /* User Agent */ - if (server_signature) { + if(server_signature) { *len += user_agent_hdr.len + CRLF_LEN; } /* Content Length, EoM */ - *len+=CONTENT_LENGTH_LEN+1 + CRLF_LEN; + *len += CONTENT_LENGTH_LEN + 1 + CRLF_LEN; reason_len = 0; reas1 = 0; reas_last = 0; /* compute reason size (if no reason or disabled => reason_len == 0)*/ - if (reason && reason->cause != CANCEL_REAS_UNKNOWN){ - if (likely(reason->cause > 0 && - cfg_get(tm, tm_cfg, local_cancel_reason))){ + if(reason && reason->cause != CANCEL_REAS_UNKNOWN) { + if(likely(reason->cause > 0 + && cfg_get(tm, tm_cfg, local_cancel_reason))) { /* Reason: SIP;cause=cause>[;text=u.text.s>] */ - reason_len = REASON_PREFIX_LEN + USHORT2SBUF_MAX_LEN + - (reason->u.text.s? - REASON_TEXT_LEN + 1 + reason->u.text.len + 1 : 0) + - CRLF_LEN; - } else if (likely(reason->cause == CANCEL_REAS_PACKED_HDRS && - !(Trans->flags & T_NO_E2E_CANCEL_REASON))) { + reason_len = REASON_PREFIX_LEN + USHORT2SBUF_MAX_LEN + + (reason->u.text.s ? REASON_TEXT_LEN + 1 + + reason->u.text.len + 1 + : 0) + + CRLF_LEN; + } else if(likely(reason->cause == CANCEL_REAS_PACKED_HDRS + && !(Trans->flags & T_NO_E2E_CANCEL_REASON))) { reason_len = reason->u.packed_hdrs.len; - } else if (reason->cause == CANCEL_REAS_RCVD_CANCEL && - reason->u.e2e_cancel && - !(Trans->flags & T_NO_E2E_CANCEL_REASON)) { + } else if(reason->cause == CANCEL_REAS_RCVD_CANCEL + && reason->u.e2e_cancel + && !(Trans->flags & T_NO_E2E_CANCEL_REASON)) { /* parse the entire cancel, to get all the Reason headers */ - if(parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0)<0) { + if(parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0) < 0) { LM_WARN("failed to parse headers\n"); } - for(hdr=get_hdr(reason->u.e2e_cancel, HDR_REASON_T), reas1=hdr; - hdr; hdr=next_sibling_hdr(hdr)) { + for(hdr = get_hdr(reason->u.e2e_cancel, HDR_REASON_T), reas1 = hdr; + hdr; hdr = next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ reason_len += hdr->len; - reas_last=hdr; + reas_last = hdr; } - } else if (unlikely(reason->cause < CANCEL_REAS_MIN)) + } else if(unlikely(reason->cause < CANCEL_REAS_MIN)) LM_BUG("unhandled reason cause %d\n", reason->cause); } - *len+= reason_len; - *len+= CRLF_LEN; /* end of msg. */ + *len += reason_len; + *len += CRLF_LEN; /* end of msg. */ - cancel_buf=shm_malloc( *len+1 ); - if (!cancel_buf) { + cancel_buf = shm_malloc(*len + 1); + if(!cancel_buf) { SHM_MEM_ERROR; goto error01; } p = cancel_buf; - append_str( p, method, method_len ); - append_str( p, " ", 1 ); - append_str( p, Trans->uac[branch].uri.s, Trans->uac[branch].uri.len); - append_str( p, " " SIP_VERSION CRLF, 1+SIP_VERSION_LEN+CRLF_LEN ); + append_str(p, method, method_len); + append_str(p, " ", 1); + append_str(p, Trans->uac[branch].uri.s, Trans->uac[branch].uri.len); + append_str(p, " " SIP_VERSION CRLF, 1 + SIP_VERSION_LEN + CRLF_LEN); /* insert our via */ - append_str(p,via,via_len); + append_str(p, via, via_len); /*other headers*/ - append_str( p, Trans->from_hdr.s, Trans->from_hdr.len ); - append_str( p, Trans->callid_hdr.s, Trans->callid_hdr.len ); - append_str( p, to->s, to->len ); - - append_str( p, Trans->cseq_hdr_n.s, Trans->cseq_hdr_n.len ); - append_str( p, " ", 1 ); - append_str( p, method, method_len ); - append_str( p, CRLF, CRLF_LEN ); - append_str( p, MAXFWD_HEADER, MAXFWD_HEADER_LEN ); - - if (!is_local(Trans)) { - for ( hdr=Trans->uas.request->headers ; hdr ; hdr=hdr->next ) - if(hdr->type==HDR_ROUTE_T) { - append_str(p, hdr->name.s, hdr->len ); + append_str(p, Trans->from_hdr.s, Trans->from_hdr.len); + append_str(p, Trans->callid_hdr.s, Trans->callid_hdr.len); + append_str(p, to->s, to->len); + + append_str(p, Trans->cseq_hdr_n.s, Trans->cseq_hdr_n.len); + append_str(p, " ", 1); + append_str(p, method, method_len); + append_str(p, CRLF, CRLF_LEN); + append_str(p, MAXFWD_HEADER, MAXFWD_HEADER_LEN); + + if(!is_local(Trans)) { + for(hdr = Trans->uas.request->headers; hdr; hdr = hdr->next) + if(hdr->type == HDR_ROUTE_T) { + append_str(p, hdr->name.s, hdr->len); } } /* User Agent header */ - if (server_signature) { - append_str(p, user_agent_hdr.s, user_agent_hdr.len ); - append_str(p, CRLF, CRLF_LEN ); + if(server_signature) { + append_str(p, user_agent_hdr.s, user_agent_hdr.len); + append_str(p, CRLF, CRLF_LEN); } /* Content Length */ append_str(p, CONTENT_LENGTH "0" CRLF, CONTENT_LENGTH_LEN + 1 + CRLF_LEN); /* add reason if needed */ - if (reason_len) { - if (likely(reason->cause > 0)) { + if(reason_len) { + if(likely(reason->cause > 0)) { append_str(p, REASON_PREFIX, REASON_PREFIX_LEN); - code_len=ushort2sbuf(reason->cause, p, - *len-(int)(p-cancel_buf)); - if (unlikely(code_len==0)) + code_len = + ushort2sbuf(reason->cause, p, *len - (int)(p - cancel_buf)); + if(unlikely(code_len == 0)) LM_BUG("not enough space to write reason code"); - p+=code_len; - if (reason->u.text.s){ + p += code_len; + if(reason->u.text.s) { append_str(p, REASON_TEXT, REASON_TEXT_LEN); - *p='"'; p++; + *p = '"'; + p++; append_str(p, reason->u.text.s, reason->u.text.len); - *p='"'; p++; + *p = '"'; + p++; } append_str(p, CRLF, CRLF_LEN); - } else if (likely(reason->cause == CANCEL_REAS_PACKED_HDRS)) { + } else if(likely(reason->cause == CANCEL_REAS_PACKED_HDRS)) { append_str(p, reason->u.packed_hdrs.s, reason->u.packed_hdrs.len); - } else if (reason->cause == CANCEL_REAS_RCVD_CANCEL) { - for(hdr=reas1; hdr; hdr=next_sibling_hdr(hdr)) { + } else if(reason->cause == CANCEL_REAS_RCVD_CANCEL) { + for(hdr = reas1; hdr; hdr = next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ append_str(p, hdr->name.s, hdr->len); - if (likely(hdr==reas_last)) + if(likely(hdr == reas_last)) break; } } } append_str(p, CRLF, CRLF_LEN); /* msg. end */ - *p=0; + *p = 0; pkg_free(via); return cancel_buf; @@ -269,17 +272,16 @@ char *build_local(struct cell *Trans,unsigned int branch, * * Can not be used to build other type of requests! */ -char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, - unsigned int *len, char *method, int method_len, str *to - , struct cancel_reason *reason - ) +char *build_local_reparse(tm_cell_t *Trans, unsigned int branch, + unsigned int *len, char *method, int method_len, str *to, + struct cancel_reason *reason) { - char *invite_buf, *invite_buf_end; - char *cancel_buf; - char *s, *s1, *d; /* source and destination buffers */ - short invite_len; - enum _hdr_types_t hf_type; - int first_via, to_len; + char *invite_buf, *invite_buf_end; + char *cancel_buf; + char *s, *s1, *d; /* source and destination buffers */ + short invite_len; + enum _hdr_types_t hf_type; + int first_via, to_len; int cancel_buf_len; int reason_len, code_len; struct hdr_field *reas1, *reas_last, *hdr; @@ -290,13 +292,13 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, invite_buf = Trans->uac[branch].request.buffer; invite_len = Trans->uac[branch].request.buffer_len; - if (!invite_buf || invite_len<=0) { + if(!invite_buf || invite_len <= 0) { LM_ERR("INVITE is missing\n"); goto error; } - if ((*invite_buf != 'I') && (*invite_buf != 'i')) { + if((*invite_buf != 'I') && (*invite_buf != 'i')) { LM_ERR("trying to build with local reparse" - " for a non-INVITE request?\n"); + " for a non-INVITE request?\n"); goto error; } @@ -304,31 +306,32 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, reas1 = 0; reas_last = 0; /* compute reason size (if no reason or disabled => reason_len == 0)*/ - if (reason && reason->cause != CANCEL_REAS_UNKNOWN){ - if (likely(reason->cause > 0 && - cfg_get(tm, tm_cfg, local_cancel_reason))){ + if(reason && reason->cause != CANCEL_REAS_UNKNOWN) { + if(likely(reason->cause > 0 + && cfg_get(tm, tm_cfg, local_cancel_reason))) { /* Reason: SIP;cause=cause>[;text=u.text.s>] */ - reason_len = REASON_PREFIX_LEN + USHORT2SBUF_MAX_LEN + - (reason->u.text.s? - REASON_TEXT_LEN + 1 + reason->u.text.len + 1 : 0) + - CRLF_LEN; - } else if (likely(reason->cause == CANCEL_REAS_PACKED_HDRS && - !(Trans->flags & T_NO_E2E_CANCEL_REASON))) { + reason_len = REASON_PREFIX_LEN + USHORT2SBUF_MAX_LEN + + (reason->u.text.s ? REASON_TEXT_LEN + 1 + + reason->u.text.len + 1 + : 0) + + CRLF_LEN; + } else if(likely(reason->cause == CANCEL_REAS_PACKED_HDRS + && !(Trans->flags & T_NO_E2E_CANCEL_REASON))) { reason_len = reason->u.packed_hdrs.len; - } else if (reason->cause == CANCEL_REAS_RCVD_CANCEL && - reason->u.e2e_cancel && - !(Trans->flags & T_NO_E2E_CANCEL_REASON)) { + } else if(reason->cause == CANCEL_REAS_RCVD_CANCEL + && reason->u.e2e_cancel + && !(Trans->flags & T_NO_E2E_CANCEL_REASON)) { /* parse the entire cancel, to get all the Reason headers */ - if(parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0)<0) { + if(parse_headers(reason->u.e2e_cancel, HDR_EOH_F, 0) < 0) { LM_WARN("failed to parse headers\n"); } - for(hdr=get_hdr(reason->u.e2e_cancel, HDR_REASON_T), reas1=hdr; - hdr; hdr=next_sibling_hdr(hdr)) { + for(hdr = get_hdr(reason->u.e2e_cancel, HDR_REASON_T), reas1 = hdr; + hdr; hdr = next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ reason_len += hdr->len; - reas_last=hdr; + reas_last = hdr; } - } else if (unlikely(reason->cause < CANCEL_REAS_MIN)) + } else if(unlikely(reason->cause < CANCEL_REAS_MIN)) LM_BUG("unhandled reason cause %d\n", reason->cause); } @@ -342,9 +345,8 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, to_len = to ? to->len : 0; cancel_buf_len = invite_len + to_len + reason_len; - cancel_buf = shm_malloc(sizeof(char)*cancel_buf_len); - if (!cancel_buf) - { + cancel_buf = shm_malloc(sizeof(char) * cancel_buf_len); + if(!cancel_buf) { SHM_MEM_ERROR; goto error; } @@ -365,29 +367,28 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, /* check every header field name, we must exclude and modify some of the headers */ first_via = 1; - while (s < invite_buf_end) { + while(s < invite_buf_end) { s1 = s; - if ((*s == '\n') || (*s == '\r')) { + if((*s == '\n') || (*s == '\r')) { /* end of SIP msg */ hf_type = HDR_EOH_T; } else { /* parse HF name */ - s = lw_get_hf_name(s, invite_buf_end, - &hf_type); + s = lw_get_hf_name(s, invite_buf_end, &hf_type); } switch(hf_type) { case HDR_CSEQ_T: /* find the method name and replace it */ - if(hdr_flags & HDR_CSEQ_F) { + if(hdr_flags & HDR_CSEQ_F) { LM_DBG("duplicate CSeq header\n"); goto errorhdr; } - hdr_flags |= HDR_CSEQ_F; - while ((s < invite_buf_end) - && ((*s == ':') || (*s == ' ') || (*s == '\t') || - ((*s >= '0') && (*s <= '9'))) - ) s++; + hdr_flags |= HDR_CSEQ_F; + while((s < invite_buf_end) + && ((*s == ':') || (*s == ' ') || (*s == '\t') + || ((*s >= '0') && (*s <= '9')))) + s++; append_str(d, s1, s - s1); append_str(d, method, method_len); append_str(d, CRLF, CRLF_LEN); @@ -396,7 +397,7 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, case HDR_VIA_T: s = lw_next_line(s, invite_buf_end); - if (first_via) { + if(first_via) { /* copy hf */ append_str(d, s1, s - s1); first_via = 0; @@ -404,13 +405,13 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, break; case HDR_TO_T: - if(hdr_flags & HDR_TO_F) { + if(hdr_flags & HDR_TO_F) { LM_DBG("duplicate To header\n"); goto errorhdr; } - hdr_flags |= HDR_TO_F; + hdr_flags |= HDR_TO_F; - if (to_len == 0) { + if(to_len == 0) { /* there is no To tag required, just copy paste * the header */ s = lw_next_line(s, invite_buf_end); @@ -425,21 +426,21 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, case HDR_FROM_T: /* copy hf */ - if(hdr_flags & HDR_FROM_F) { + if(hdr_flags & HDR_FROM_F) { LM_DBG("duplicate From header\n"); goto errorhdr; } - hdr_flags |= HDR_FROM_F; + hdr_flags |= HDR_FROM_F; s = lw_next_line(s, invite_buf_end); append_str(d, s1, s - s1); break; case HDR_CALLID_T: /* copy hf */ - if(hdr_flags & HDR_CALLID_F) { + if(hdr_flags & HDR_CALLID_F) { LM_DBG("duplicate Call-Id header\n"); goto errorhdr; } - hdr_flags |= HDR_CALLID_F; + hdr_flags |= HDR_CALLID_F; s = lw_next_line(s, invite_buf_end); append_str(d, s1, s - s1); break; @@ -467,33 +468,34 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, case HDR_EOH_T: /* end of SIP message found */ /* add reason if needed */ - if (reason_len) { + if(reason_len) { /* if reason_len !=0, no need for any reason enabled * checks */ - if (likely(reason->cause > 0)) { + if(likely(reason->cause > 0)) { append_str(d, REASON_PREFIX, REASON_PREFIX_LEN); - code_len=ushort2sbuf(reason->cause, d, - cancel_buf_len-(int)(d-cancel_buf)); - if (unlikely(code_len==0)) + code_len = ushort2sbuf(reason->cause, d, + cancel_buf_len - (int)(d - cancel_buf)); + if(unlikely(code_len == 0)) LM_BUG("not enough space to write reason code"); - d+=code_len; - if (reason->u.text.s){ + d += code_len; + if(reason->u.text.s) { append_str(d, REASON_TEXT, REASON_TEXT_LEN); - *d='"'; d++; - append_str(d, reason->u.text.s, - reason->u.text.len); - *d='"'; d++; + *d = '"'; + d++; + append_str(d, reason->u.text.s, reason->u.text.len); + *d = '"'; + d++; } append_str(d, CRLF, CRLF_LEN); - } else if (likely(reason->cause == - CANCEL_REAS_PACKED_HDRS)) { - append_str(d, reason->u.packed_hdrs.s, - reason->u.packed_hdrs.len); - } else if (reason->cause == CANCEL_REAS_RCVD_CANCEL) { - for(hdr=reas1; hdr; hdr=next_sibling_hdr(hdr)) { + } else if(likely(reason->cause + == CANCEL_REAS_PACKED_HDRS)) { + append_str(d, reason->u.packed_hdrs.s, + reason->u.packed_hdrs.len); + } else if(reason->cause == CANCEL_REAS_RCVD_CANCEL) { + for(hdr = reas1; hdr; hdr = next_sibling_hdr(hdr)) { /* hdr->len includes CRLF */ append_str(d, hdr->name.s, hdr->len); - if (likely(hdr==reas_last)) + if(likely(hdr == reas_last)) break; } } @@ -509,29 +511,33 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, hadded = 0; /* uac auth headers */ - if(Trans->uas.request && - (Trans->uas.request->msg_flags & FL_UAC_AUTH)) { + if(Trans->uas.request + && (Trans->uas.request->msg_flags & FL_UAC_AUTH)) { if(s1 + cenv->uac_cseq_auth.len + 2 < invite_buf_end) { - if(s1[cenv->uac_cseq_auth.len]==':' + if(s1[cenv->uac_cseq_auth.len] == ':' && strncmp(s1, cenv->uac_cseq_auth.s, - cenv->uac_cseq_auth.len)==0) { + cenv->uac_cseq_auth.len) + == 0) { hadded = 1; append_str(d, s1, s - s1); - } else if(s1[cenv->uac_cseq_refresh.len]==':' - && strncmp(s1, cenv->uac_cseq_refresh.s, - cenv->uac_cseq_refresh.len)==0) { + } else if(s1[cenv->uac_cseq_refresh.len] == ':' + && strncmp(s1, cenv->uac_cseq_refresh.s, + cenv->uac_cseq_refresh.len) + == 0) { hadded = 1; append_str(d, s1, s - s1); } } } - if(likely(hadded==0)) { - if (cfg_get(tm, tm_cfg, ac_extra_hdrs).len - && (s1 + cfg_get(tm, tm_cfg, ac_extra_hdrs).len < invite_buf_end) + if(likely(hadded == 0)) { + if(cfg_get(tm, tm_cfg, ac_extra_hdrs).len + && (s1 + cfg_get(tm, tm_cfg, ac_extra_hdrs).len + < invite_buf_end) && (strncasecmp(s1, - cfg_get(tm, tm_cfg, ac_extra_hdrs).s, - cfg_get(tm, tm_cfg, ac_extra_hdrs).len) == 0)) { + cfg_get(tm, tm_cfg, ac_extra_hdrs).s, + cfg_get(tm, tm_cfg, ac_extra_hdrs).len) + == 0)) { append_str(d, s1, s - s1); } } @@ -547,39 +553,39 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, error: LM_ERR("cannot build %.*s request\n", method_len, method); return NULL; - } -typedef struct rte { - rr_t* ptr; +typedef struct rte +{ + rr_t *ptr; /* 'ptr' above doesn't point to a mem chunk linked to a sip_msg, so it * won't be free'd along with it => it must be free'd "manually" */ int free_rr; - struct rte* next; + struct rte *next; } rte_t; -static inline void free_rte_list(struct rte* list) +static inline void free_rte_list(struct rte *list) { - struct rte* ptr; + struct rte *ptr; while(list) { ptr = list; list = list->next; - if (ptr->free_rr) + if(ptr->free_rr) free_rr(&ptr->ptr); pkg_free(ptr); } } -static inline int calc_routeset_len(struct rte* list, str* contact) +static inline int calc_routeset_len(struct rte *list, str *contact) { - struct rte* ptr; + struct rte *ptr; int ret; - if (list || contact) { + if(list || contact) { ret = ROUTE_PREFIX_LEN + CRLF_LEN; } else { return 0; @@ -587,15 +593,16 @@ static inline int calc_routeset_len(struct rte* list, str* contact) ptr = list; while(ptr) { - if (ptr != list) { + if(ptr != list) { ret += ROUTE_SEPARATOR_LEN; } ret += ptr->ptr->len; ptr = ptr->next; } - if (contact) { - if (list) ret += ROUTE_SEPARATOR_LEN; + if(contact) { + if(list) + ret += ROUTE_SEPARATOR_LEN; ret += 2 + contact->len; } @@ -606,11 +613,11 @@ static inline int calc_routeset_len(struct rte* list, str* contact) /* * Print the route set */ -static inline char* print_rs(char* p, struct rte* list, str* contact) +static inline char *print_rs(char *p, struct rte *list, str *contact) { - struct rte* ptr; + struct rte *ptr; - if (list || contact) { + if(list || contact) { memapp(p, ROUTE_PREFIX, ROUTE_PREFIX_LEN); } else { return p; @@ -618,7 +625,7 @@ static inline char* print_rs(char* p, struct rte* list, str* contact) ptr = list; while(ptr) { - if (ptr != list) { + if(ptr != list) { memapp(p, ROUTE_SEPARATOR, ROUTE_SEPARATOR_LEN); } @@ -626,8 +633,9 @@ static inline char* print_rs(char* p, struct rte* list, str* contact) ptr = ptr->next; } - if (contact) { - if (list) memapp(p, ROUTE_SEPARATOR, ROUTE_SEPARATOR_LEN); + if(contact) { + if(list) + memapp(p, ROUTE_SEPARATOR, ROUTE_SEPARATOR_LEN); *p++ = '<'; append_str(p, contact->s, contact->len); *p++ = '>'; @@ -642,21 +650,22 @@ static inline char* print_rs(char* p, struct rte* list, str* contact) * Parse Contact header field body and extract URI * Does not parse headers ! */ -static inline int get_contact_uri(struct sip_msg* msg, str* uri) +static inline int get_contact_uri(struct sip_msg *msg, str *uri) { - contact_t* c; + contact_t *c; uri->len = 0; - if (!msg->contact) return 1; + if(!msg->contact) + return 1; - if (parse_contact(msg->contact) < 0) { + if(parse_contact(msg->contact) < 0) { LM_ERR("error while parsing Contact body\n"); return -1; } - c = ((contact_body_t*)msg->contact->parsed)->contacts; + c = ((contact_body_t *)msg->contact->parsed)->contacts; - if (!c) { + if(!c) { LM_ERR("empty body or * contact\n"); return -2; } @@ -673,40 +682,40 @@ static inline int get_contact_uri(struct sip_msg* msg, str* uri) */ static inline int get_uac_rs(sip_msg_t *msg, int is_req, struct rte **rtset) { - struct hdr_field* ptr; + struct hdr_field *ptr; rr_t *p, *new_p; struct rte *t, *head, *old_head; head = 0; - for (ptr = is_req ? msg->route : msg->record_route; ptr; ptr = ptr->next) { - switch (ptr->type) { + for(ptr = is_req ? msg->route : msg->record_route; ptr; ptr = ptr->next) { + switch(ptr->type) { case HDR_RECORDROUTE_T: - if (is_req) + if(is_req) continue; break; case HDR_ROUTE_T: - if (! is_req) + if(!is_req) continue; break; default: continue; } - if (parse_rr(ptr) < 0) { + if(parse_rr(ptr) < 0) { LM_ERR("failed to parse Record-/Route HF (%d).\n", ptr->type); goto err; } - p = (rr_t*)ptr->parsed; + p = (rr_t *)ptr->parsed; while(p) { - if (! (t = pkg_malloc(sizeof(struct rte)))) { - PKG_MEM_ERROR_FMT("(asked for: %d).\n", - (int)sizeof(struct rte)); + if(!(t = pkg_malloc(sizeof(struct rte)))) { + PKG_MEM_ERROR_FMT( + "(asked for: %d).\n", (int)sizeof(struct rte)); goto err; } - if (is_req) { + if(is_req) { /* in case of requests, the sip_msg structure is free'd before * rte list is evaluated => must do a copy of it */ - if (duplicate_rr(&new_p, p) < 0) { + if(duplicate_rr(&new_p, p) < 0) { pkg_free(t); LM_ERR("failed to duplicate RR\n"); goto err; @@ -722,12 +731,12 @@ static inline int get_uac_rs(sip_msg_t *msg, int is_req, struct rte **rtset) } } - if (is_req) { + if(is_req) { /* harvesting the R/RR HF above inserts at head, which suites RRs (as * they must be reversed, anyway), but not Rs => reverse once more */ old_head = head; head = 0; - while (old_head) { + while(old_head) { t = old_head; old_head = old_head->next; t->next = head; @@ -745,26 +754,29 @@ static inline int get_uac_rs(sip_msg_t *msg, int is_req, struct rte **rtset) static inline unsigned short uri2port(const struct sip_uri *puri) { - if (puri->port.s) { + if(puri->port.s) { return puri->port_no; - } else switch (puri->type) { - case SIP_URI_T: - case TEL_URI_T: - if (puri->transport_val.len == sizeof("TLS") - 1) { - unsigned trans; - trans = puri->transport_val.s[0] | 0x20; trans <<= 8; - trans |= puri->transport_val.s[1] | 0x20; trans <<= 8; - trans |= puri->transport_val.s[2] | 0x20; - if (trans == 0x746C73) /* t l s */ - return SIPS_PORT; - } - return SIP_PORT; - case SIPS_URI_T: - case TELS_URI_T: - return SIPS_PORT; - default: - LM_BUG("unexpected URI type %d.\n", puri->type); - } + } else + switch(puri->type) { + case SIP_URI_T: + case TEL_URI_T: + if(puri->transport_val.len == sizeof("TLS") - 1) { + unsigned trans; + trans = puri->transport_val.s[0] | 0x20; + trans <<= 8; + trans |= puri->transport_val.s[1] | 0x20; + trans <<= 8; + trans |= puri->transport_val.s[2] | 0x20; + if(trans == 0x746C73) /* t l s */ + return SIPS_PORT; + } + return SIP_PORT; + case SIPS_URI_T: + case TELS_URI_T: + return SIPS_PORT; + default: + LM_BUG("unexpected URI type %d.\n", puri->type); + } return 0; } @@ -793,60 +805,58 @@ static unsigned long nhop_type(sip_msg_t *orig_inv, rte_t *rtset, char **alias; #endif -#define PARSE_URI(_str_, _uri_) \ - do { \ - /* parse_uri() 0z the puri */ \ - if (parse_uri((_str_)->s, \ - (_str_)->len, _uri_) < 0) { \ +#define PARSE_URI(_str_, _uri_) \ + do { \ + /* parse_uri() 0z the puri */ \ + if(parse_uri((_str_)->s, (_str_)->len, _uri_) < 0) { \ LM_ERR("failed to parse route body '%.*s'.\n", STR_FMT(_str_)); \ - return 0; \ - } \ - } while (0) + return 0; \ + } \ + } while(0) -#define HAS_LR(_rte_) \ - ({ \ +#define HAS_LR(_rte_) \ + ({ \ PARSE_URI(&(_rte_)->ptr->nameaddr.uri, &puri); \ - puri.lr.s; \ + puri.lr.s; \ }) -#define URI_PORT(_puri_, _port) \ - do { \ - if (! (_port = uri2port(_puri_))) \ - return 0; \ - } while (0) +#define URI_PORT(_puri_, _port) \ + do { \ + if(!(_port = uri2port(_puri_))) \ + return 0; \ + } while(0) /* examine the easy/fast & positive cases foremost */ /* [1] check if 1st route lacks ;lr */ LM_DBG("checking lack of ';lr' in 1st route.\n"); - if (! HAS_LR(rtset)) + if(!HAS_LR(rtset)) return F_RB_NH_STRICT; topr_uri = puri; /* save 1st route's URI */ /* [2] check if last route shows ;lr */ LM_DBG("checking presence of ';lr' in last route.\n"); - for (last_r = rtset; last_r->next; last_r = last_r->next) + for(last_r = rtset; last_r->next; last_r = last_r->next) /* scroll down to last route */ ; - if (HAS_LR(last_r)) + if(HAS_LR(last_r)) return F_RB_NH_LOOSE; /* [3] 1st route has ;lr -> check if the destination of original INV * equals the address provided by this route; if does -> loose */ LM_DBG("checking INVITE's destination against its first route.\n"); URI_PORT(&topr_uri, uri_port); - if (! (dst_port = su_getport(&dst_inv->to))) + if(!(dst_port = su_getport(&dst_inv->to))) return 0; /* not really expected */ - if (dst_port != uri_port) + if(dst_port != uri_port) return F_RB_NH_STRICT; /* if 1st route contains an IP address, comparing it against .dst */ - if ((uri_ia = str2ip(&topr_uri.host)) - || (uri_ia = str2ip6(&topr_uri.host)) - ) { + if((uri_ia = str2ip(&topr_uri.host)) + || (uri_ia = str2ip6(&topr_uri.host))) { /* we have an IP address in route -> comparison can go swiftly */ - if (init_su(&uri_sau, uri_ia, uri_port) < 0) + if(init_su(&uri_sau, uri_ia, uri_port) < 0) return 0; /* not really expected */ - if (su_cmp(&uri_sau, &dst_inv->to)) + if(su_cmp(&uri_sau, &dst_inv->to)) /* ;lr and sent there */ return F_RB_NH_LOOSE; else @@ -855,23 +865,24 @@ static unsigned long nhop_type(sip_msg_t *orig_inv, rte_t *rtset, } else { /*if 1st route contains a name, rev resolve the .dst and compare*/ LM_INFO("Failed to decode string '%.*s' in route set element as IP" - " address. Trying name resolution.\n",STR_FMT(&topr_uri.host)); + " address. Trying name resolution.\n", + STR_FMT(&topr_uri.host)); - /* TODO: alternatively, rev name and compare against dest. IP. */ + /* TODO: alternatively, rev name and compare against dest. IP. */ #ifdef TM_LOC_ACK_DO_REV_DNS ia.af = 0; su2ip_addr(&ia, (void *)&dst_inv->to); - if (! ia.af) + if(!ia.af) return 0; /* not really expected */ - if ((he = rev_resolvehost(&ia))) { - if ((strlen(he->h_name) == topr_uri.host.len) && - (memcmp(he->h_name, topr_uri.host.s, - topr_uri.host.len) == 0)) + if((he = rev_resolvehost(&ia))) { + if((strlen(he->h_name) == topr_uri.host.len) + && (memcmp(he->h_name, topr_uri.host.s, topr_uri.host.len) + == 0)) return F_RB_NH_LOOSE; - for (alias = he->h_aliases; *alias; alias ++) - if ((strlen(*alias) == topr_uri.host.len) && - (memcmp(*alias, topr_uri.host.s, - topr_uri.host.len) == 0)) + for(alias = he->h_aliases; *alias; alias++) + if((strlen(*alias) == topr_uri.host.len) + && (memcmp(*alias, topr_uri.host.s, topr_uri.host.len) + == 0)) return F_RB_NH_LOOSE; return F_RB_NH_STRICT; } else { @@ -891,8 +902,9 @@ static unsigned long nhop_type(sip_msg_t *orig_inv, rte_t *rtset, PARSE_URI(GET_RURI(orig_inv), &inv_ruri); URI_PORT(&cont_uri, cont_port); URI_PORT(&inv_ruri, inv_port); - if ((cont_port == inv_port) && (cont_uri.host.len == inv_ruri.host.len) && - (memcmp(cont_uri.host.s, inv_ruri.host.s, cont_uri.host.len) == 0)) + if((cont_port == inv_port) && (cont_uri.host.len == inv_ruri.host.len) + && (memcmp(cont_uri.host.s, inv_ruri.host.s, cont_uri.host.len) + == 0)) return F_RB_NH_LOOSE; /* [5] compare (possibly updated) remote target to last route; if equal, @@ -901,10 +913,9 @@ static unsigned long nhop_type(sip_msg_t *orig_inv, rte_t *rtset, LM_DBG("checking remote target against INVITE's last route.\n"); PARSE_URI(&last_r->ptr->nameaddr.uri, &lastr_uri); URI_PORT(&lastr_uri, lastr_port); - if ((cont_port == lastr_port) && - (cont_uri.host.len == lastr_uri.host.len) && - (memcmp(cont_uri.host.s, lastr_uri.host.s, - lastr_uri.host.len) == 0)) + if((cont_port == lastr_port) && (cont_uri.host.len == lastr_uri.host.len) + && (memcmp(cont_uri.host.s, lastr_uri.host.s, lastr_uri.host.len) + == 0)) return F_RB_NH_STRICT; LM_WARN("failed to establish the type of next hop;" @@ -933,7 +944,7 @@ static unsigned long nhop_type(sip_msg_t *orig_inv, rte_t *rtset, * */ static int eval_uac_routing(sip_msg_t *rpl, const struct retr_buf *inv_rb, - str* contact, struct rte **list, str *ruri, str *next_hop) + str *contact, struct rte **list, str *ruri, str *next_hop) { sip_msg_t orig_inv, *sipmsg; /* reparse original INVITE */ rte_t *t, *prev_t, *rtset = NULL; @@ -947,24 +958,26 @@ static int eval_uac_routing(sip_msg_t *rpl, const struct retr_buf *inv_rb, orig_inv.len = inv_rb->buffer_len; LM_DBG("reparsing retransmission buffer of original INVITE:\n%.*s\n", (int)orig_inv.len, orig_inv.buf); - if (parse_msg(orig_inv.buf, orig_inv.len, &orig_inv) != 0) { + if(parse_msg(orig_inv.buf, orig_inv.len, &orig_inv) != 0) { LM_ERR("failed to parse retr buffer (weird!): \n%.*s\n", (int)orig_inv.len, orig_inv.buf); return -1; } /* check if we need to look at request or reply */ - if ((parse_headers(&orig_inv, HDR_TO_F, 0) < 0) || (! orig_inv.to)) { + if((parse_headers(&orig_inv, HDR_TO_F, 0) < 0) || (!orig_inv.to)) { /* the bug is at message assembly */ LM_BUG("failed to parse INVITE retr. buffer and/or extract 'To' HF:" - "\n%.*s\n", (int)orig_inv.len, orig_inv.buf); + "\n%.*s\n", + (int)orig_inv.len, orig_inv.buf); goto error; } - if (((struct to_body *)orig_inv.to->parsed)->tag_value.len) { + if(((struct to_body *)orig_inv.to->parsed)->tag_value.len) { LM_DBG("building ACK for in-dialog INVITE (using RS in orig. INV.)\n"); - if (parse_headers(&orig_inv, HDR_EOH_F, 0) < 0) { + if(parse_headers(&orig_inv, HDR_EOH_F, 0) < 0) { LM_BUG("failed to parse INVITE retr. buffer to EOH:" - "\n%.*s\n", (int)orig_inv.len, orig_inv.buf); + "\n%.*s\n", + (int)orig_inv.len, orig_inv.buf); goto error; } sipmsg = &orig_inv; @@ -976,22 +989,23 @@ static int eval_uac_routing(sip_msg_t *rpl, const struct retr_buf *inv_rb, } /* extract the route set */ - if (get_uac_rs(sipmsg, is_req, &rtset) < 0) { + if(get_uac_rs(sipmsg, is_req, &rtset) < 0) { LM_ERR("failed to extract route set.\n"); goto error; } - if (! rtset) { /* No routes */ + if(!rtset) { /* No routes */ *ruri = *contact; *next_hop = *contact; - } else if (! is_req) { /* out of dialog req. */ - if (parse_uri(rtset->ptr->nameaddr.uri.s, rtset->ptr->nameaddr.uri.len, - &puri) < 0) { + } else if(!is_req) { /* out of dialog req. */ + if(parse_uri(rtset->ptr->nameaddr.uri.s, rtset->ptr->nameaddr.uri.len, + &puri) + < 0) { LM_ERR("failed to parse first route in set.\n"); goto error; } - if (puri.lr.s) { /* Next hop is loose router */ + if(puri.lr.s) { /* Next hop is loose router */ *ruri = *contact; *next_hop = rtset->ptr->nameaddr.uri; } else { /* Next hop is strict router */ @@ -1005,82 +1019,85 @@ static int eval_uac_routing(sip_msg_t *rpl, const struct retr_buf *inv_rb, } else { unsigned long route_flags = inv_rb->flags; LM_DBG("UAC rb flags: 0x%x.\n", (unsigned int)route_flags); -eval_flags: - switch (route_flags & (F_RB_NH_LOOSE|F_RB_NH_STRICT)) { - case 0: - LM_WARN("calculate_hooks() not called when built the local UAC of " - "in-dialog request, or called with empty route set.\n"); - /* try to figure out what kind of hop is the next one + eval_flags: + switch(route_flags & (F_RB_NH_LOOSE | F_RB_NH_STRICT)) { + case 0: + LM_WARN("calculate_hooks() not called when built the local UAC " + "of " + "in-dialog request, or called with empty route set.\n"); + /* try to figure out what kind of hop is the next one * (strict/loose) by reading the original invite */ - if ((route_flags = nhop_type(&orig_inv, rtset, &inv_rb->dst, - contact))) { - LM_DBG("original request's next hop type evaluated to: 0x%x.\n", - (unsigned int)route_flags); - goto eval_flags; - } else { - LM_ERR("failed to establish what kind of router the next " - "hop is.\n"); - goto error; - } - break; - case F_RB_NH_LOOSE: - *ruri = *contact; - *next_hop = rtset->ptr->nameaddr.uri; - break; - case F_RB_NH_STRICT: - /* find ptr to last route body that contains the (possibly) old + if((route_flags = nhop_type( + &orig_inv, rtset, &inv_rb->dst, contact))) { + LM_DBG("original request's next hop type evaluated to: " + "0x%x.\n", + (unsigned int)route_flags); + goto eval_flags; + } else { + LM_ERR("failed to establish what kind of router the next " + "hop is.\n"); + goto error; + } + break; + case F_RB_NH_LOOSE: + *ruri = *contact; + *next_hop = rtset->ptr->nameaddr.uri; + break; + case F_RB_NH_STRICT: + /* find ptr to last route body that contains the (possibly) old * remote target */ - for (t = rtset, prev_t = NULL; t->next; prev_t = t, t = t->next) - ; - if ((t->ptr->len == contact->len) && - (memcmp(t->ptr->nameaddr.name.s, contact->s, - contact->len) == 0)){ - /* the remote target didn't update -> keep the whole route set, + for(t = rtset, prev_t = NULL; t->next; prev_t = t, t = t->next) + ; + if((t->ptr->len == contact->len) + && (memcmp(t->ptr->nameaddr.name.s, contact->s, + contact->len) + == 0)) { + /* the remote target didn't update -> keep the whole route set, * including the last entry */ - /* do nothing */ - } else { - /* trash last entry and replace with new remote target */ - free_rte_list(t); - /* compact the rr_t struct along with rte. this way, free'ing + /* do nothing */ + } else { + /* trash last entry and replace with new remote target */ + free_rte_list(t); + /* compact the rr_t struct along with rte. this way, free'ing * it can be done along with rte chunk, independent of Route * header parser's allocator (using pkg/shm) */ - chklen = sizeof(struct rte) + sizeof(rr_t); - if (! (t = pkg_malloc(chklen))) { - PKG_MEM_ERROR_FMT("(%d required)\n", (int)chklen); - /* last element was freed, unlink it */ - if(prev_t == NULL) { - /* there is only one elem in route set: the remote target */ - rtset = NULL; - } else { - prev_t->next = NULL; + chklen = sizeof(struct rte) + sizeof(rr_t); + if(!(t = pkg_malloc(chklen))) { + PKG_MEM_ERROR_FMT("(%d required)\n", (int)chklen); + /* last element was freed, unlink it */ + if(prev_t == NULL) { + /* there is only one elem in route set: the remote target */ + rtset = NULL; + } else { + prev_t->next = NULL; + } + goto error; } - goto error; + /* this way, .free_rr is also set to 0 (!!!) */ + memset(t, 0, chklen); + ((rr_t *)&t[1])->nameaddr.name = *contact; + ((rr_t *)&t[1])->len = contact->len; + /* chain the new route elem in set */ + if(prev_t == NULL) + /* there is only one elem in route set: the remote target */ + rtset = t; + else + prev_t->next = t; } - /* this way, .free_rr is also set to 0 (!!!) */ - memset(t, 0, chklen); - ((rr_t *)&t[1])->nameaddr.name = *contact; - ((rr_t *)&t[1])->len = contact->len; - /* chain the new route elem in set */ - if (prev_t == NULL) - /* there is only one elem in route set: the remote target */ - rtset = t; - else - prev_t->next = t; - } - *ruri = *GET_RURI(&orig_inv); /* reuse original RURI */ - *next_hop = *ruri; - break; - default: - /* probably a mem corruption */ - LM_BUG("next hop of original request marked as both loose" - " and strict router (buffer: %.*s).\n", - inv_rb->buffer_len, inv_rb->buffer); + *ruri = *GET_RURI(&orig_inv); /* reuse original RURI */ + *next_hop = *ruri; + break; + default: + /* probably a mem corruption */ + LM_BUG("next hop of original request marked as both loose" + " and strict router (buffer: %.*s).\n", + inv_rb->buffer_len, inv_rb->buffer); #ifdef EXTRA_DEBUG - abort(); + abort(); #else - goto error; + goto error; #endif } } @@ -1092,7 +1109,7 @@ static int eval_uac_routing(sip_msg_t *rpl, const struct retr_buf *inv_rb, error: free_sip_msg(&orig_inv); - if (rtset) + if(rtset) free_rte_list(rtset); return -1; } @@ -1103,9 +1120,9 @@ static int eval_uac_routing(sip_msg_t *rpl, const struct retr_buf *inv_rb, * the 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) { char *req_buf, *p, *via; unsigned int via_len; @@ -1113,7 +1130,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, int branch_len; str branch_str; struct hostport hp; - struct rte* list; + struct rte *list; str contact, ruri, *cont; str next_hop; str body_len; @@ -1135,7 +1152,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, */ unsigned offset = *len; - if (parse_headers(rpl, HDR_EOH_F, 0) == -1 || !rpl->to) { + if(parse_headers(rpl, HDR_EOH_F, 0) == -1 || !rpl->to) { LM_ERR("Error while parsing headers.\n"); return 0; } else { @@ -1143,19 +1160,20 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, _to.len = rpl->to->len; } - if (get_contact_uri(rpl, &contact) < 0) { + if(get_contact_uri(rpl, &contact) < 0) { return 0; } - if (eval_uac_routing(rpl, &Trans->uac[branch].request, &contact, - &list, &ruri, &next_hop) < 0) { + if(eval_uac_routing(rpl, &Trans->uac[branch].request, &contact, &list, + &ruri, &next_hop) + < 0) { LM_ERR("failed to evaluate routing elements.\n"); return 0; } LM_DBG("ACK RURI: `%.*s', NH: `%.*s'.\n", STR_FMT(&ruri), STR_FMT(&next_hop)); - if ((contact.s != ruri.s) || (contact.len != ruri.len)) { + if((contact.s != ruri.s) || (contact.len != ruri.len)) { /* contact != ruri means that the next * hop is a strict router, cont will be non-zero * and print_routeset will append it at the end @@ -1172,96 +1190,98 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, *len += ruri.len; /* dst */ - switch(cfg_get(tm, tm_cfg, local_ack_mode)){ + switch(cfg_get(tm, tm_cfg, local_ack_mode)) { case 1: /* send the local 200 ack to the same dst as the corresp. invite*/ - *dst=Trans->uac[branch].request.dst; + *dst = Trans->uac[branch].request.dst; break; case 2: /* send the local 200 ack to the same dst as the 200 reply source*/ init_dst_from_rcv(dst, &rpl->rcv); - dst->send_flags=rpl->fwd_send_flags; + dst->send_flags = rpl->fwd_send_flags; break; case 0: default: /* rfc conformant behaviour: use the next_hop determined from the * contact and the route set */ #ifdef USE_DNS_FAILOVER - if (cfg_get(core, core_cfg, use_dns_failover)){ - dns_srv_handle_init(&dns_h); - if ((uri2dst(&dns_h , dst, rpl, &next_hop, PROTO_NONE)==0) || - (dst->send_sock==0)){ - dns_srv_handle_put(&dns_h); - LM_ERR("no socket found\n"); - goto error; + if(cfg_get(core, core_cfg, use_dns_failover)) { + dns_srv_handle_init(&dns_h); + if((uri2dst(&dns_h, dst, rpl, &next_hop, PROTO_NONE) == 0) + || (dst->send_sock == 0)) { + dns_srv_handle_put(&dns_h); + LM_ERR("no socket found\n"); + goto error; + } + dns_srv_handle_put(&dns_h); /* not needed any more */ + } else { + if((uri2dst(0, dst, rpl, &next_hop, PROTO_NONE) == 0) + || (dst->send_sock == 0)) { + LM_ERR("no socket found\n"); + goto error; + } } - dns_srv_handle_put(&dns_h); /* not needed any more */ - }else{ - if ((uri2dst(0 , dst, rpl, &next_hop, PROTO_NONE)==0) || - (dst->send_sock==0)){ +#else /* USE_DNS_FAILOVER */ + if((uri2dst(dst, rpl, &next_hop, PROTO_NONE) == 0) + || (dst->send_sock == 0)) { LM_ERR("no socket found\n"); goto error; } - } -#else /* USE_DNS_FAILOVER */ - if ( (uri2dst( dst, rpl, &next_hop, PROTO_NONE)==0) || - (dst->send_sock==0)){ - LM_ERR("no socket found\n"); - goto error; - } #endif /* USE_DNS_FAILOVER */ - break; + break; } /* via */ - if (!t_calc_branch(Trans, branch, branch_buf, &branch_len)) goto error; + if(!t_calc_branch(Trans, branch, branch_buf, &branch_len)) + goto error; branch_str.s = branch_buf; branch_str.len = branch_len; set_hostport(&hp, 0); via = via_builder(&via_len, NULL, dst, &branch_str, 0, &hp); - if (!via) { + if(!via) { LM_ERR("No via header got from builder\n"); goto error; } - *len+= via_len; + *len += via_len; /* headers */ *len += Trans->from_hdr.len + Trans->callid_hdr.len + to->len - + Trans->cseq_hdr_n.len + 1 + ACK_LEN + CRLF_LEN; + + Trans->cseq_hdr_n.len + 1 + ACK_LEN + CRLF_LEN; /* copy'n'paste Route headers */ *len += calc_routeset_len(list, cont); /* User Agent */ - if (server_signature) *len += user_agent_hdr.len + CRLF_LEN; + if(server_signature) + *len += user_agent_hdr.len + CRLF_LEN; /* extra headers */ - if (hdrs) + if(hdrs) *len += hdrs->len; /* body */ - if (body) { + if(body) { body_len.s = int2str(body->len, &body_len.len); *len += body->len; } else { body_len.len = 0; body_len.s = NULL; /*4gcc*/ - *len += 1; /* for the (Cont-Len:) `0' */ + *len += 1; /* for the (Cont-Len:) `0' */ } /* Content Length, EoM */ *len += CONTENT_LENGTH_LEN + body_len.len + CRLF_LEN + CRLF_LEN; req_buf = shm_malloc(offset + *len + 1); req_buf += offset; - if (!req_buf) { + if(!req_buf) { SHM_MEM_ERROR_FMT("required (%u+1)\n", *len); goto error01; } p = req_buf; - append_str( p, ACK, ACK_LEN ); - append_str( p, " ", 1 ); + append_str(p, ACK, ACK_LEN); + append_str(p, " ", 1); append_str(p, ruri.s, ruri.len); - append_str( p, " " SIP_VERSION CRLF, 1 + SIP_VERSION_LEN + CRLF_LEN); + append_str(p, " " SIP_VERSION CRLF, 1 + SIP_VERSION_LEN + CRLF_LEN); /* insert our via */ append_str(p, via, via_len); @@ -1272,29 +1292,29 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, append_str(p, to->s, to->len); append_str(p, Trans->cseq_hdr_n.s, Trans->cseq_hdr_n.len); - append_str( p, " ", 1 ); - append_str( p, ACK, ACK_LEN); + append_str(p, " ", 1); + append_str(p, ACK, ACK_LEN); append_str(p, CRLF, CRLF_LEN); /* Routeset */ p = print_rs(p, list, cont); /* User Agent header */ - if (server_signature) { + if(server_signature) { append_str(p, user_agent_hdr.s, user_agent_hdr.len); append_str(p, CRLF, CRLF_LEN); } /* extra headers */ - if (hdrs) + if(hdrs) append_str(p, hdrs->s, hdrs->len); /* Content Length, EoH, (body) */ - if (body) { + if(body) { append_str(p, CONTENT_LENGTH, CONTENT_LENGTH_LEN); append_str(p, body_len.s, body_len.len); - append_str(p, /*end crr. header*/CRLF /*EoH*/CRLF, CRLF_LEN + - CRLF_LEN); + append_str( + p, /*end crr. header*/ CRLF /*EoH*/ CRLF, CRLF_LEN + CRLF_LEN); append_str(p, body->s, body->len); } else { append_str(p, CONTENT_LENGTH "0" CRLF CRLF, @@ -1319,17 +1339,17 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans, /* * Convert length of body into asciiz */ -static inline int print_content_length(str* dest, str* body) +static inline int print_content_length(str *dest, str *body) { static char content_length[10]; int len; int b_len; - char* tmp; + char *tmp; /* Print Content-Length */ - b_len=body?body->len:0; + b_len = body ? body->len : 0; tmp = int2str(b_len, &len); - if (len >= sizeof(content_length)) { + if(len >= sizeof(content_length)) { LM_ERR("content_len too big\n"); dest->s = 0; dest->len = 0; @@ -1345,14 +1365,14 @@ static inline int print_content_length(str* dest, str* body) /* * Convert CSeq number into asciiz */ -static inline int print_cseq_num(str* _s, dlg_t* _d) +static inline int print_cseq_num(str *_s, dlg_t *_d) { static char cseq[INT2STR_MAX_LEN]; - char* tmp; + char *tmp; int len; tmp = int2str(_d->loc_seq.value, &len); - if (len > sizeof(cseq)) { + if(len > sizeof(cseq)) { LM_ERR("cseq too big\n"); return -1; } @@ -1367,18 +1387,18 @@ static inline int print_cseq_num(str* _s, dlg_t* _d) /* * Create Via header */ -static inline int assemble_via(str* dest, struct cell* t, - struct dest_info* dst, int branch) +static inline int assemble_via( + str *dest, struct cell *t, struct dest_info *dst, int branch) { static char branch_buf[MAX_BRANCH_PARAM_LEN]; - char* via; + char *via; int len; unsigned int via_len; str branch_str; struct hostport hp; str rport = str_init(";rport"); - if (!t_calc_branch(t, branch, branch_buf, &len)) { + if(!t_calc_branch(t, branch, branch_buf, &len)) { LM_ERR("branch calculation failed\n"); return -1; } @@ -1396,7 +1416,7 @@ static inline int assemble_via(str* dest, struct cell* t, } else { via = via_builder(&via_len, NULL, dst, &branch_str, 0, &hp); } - if (!via) { + if(!via) { LM_ERR("via building failed\n"); return -2; } @@ -1410,8 +1430,8 @@ static inline int assemble_via(str* dest, struct cell* t, /* * Print Request-URI */ -static inline char* print_request_uri(char* w, str* method, dlg_t* dialog, - struct cell* t, int branch) +static inline char *print_request_uri( + char *w, str *method, dlg_t *dialog, struct cell *t, int branch) { memapp(w, method->s, method->len); memapp(w, " ", 1); @@ -1429,19 +1449,23 @@ static inline char* print_request_uri(char* w, str* method, dlg_t* dialog, /* * Print To header field */ -static inline char* print_to(char* w, dlg_t* dialog, struct cell* t, int bracket) +static inline char *print_to( + char *w, dlg_t *dialog, struct cell *t, int bracket) { t->to_hdr.s = w; - t->to_hdr.len = TO_LEN + dialog->rem_uri.len + CRLF_LEN - + (((dialog->rem_uri.s[dialog->rem_uri.len - 1]!='>'))?2:0); + t->to_hdr.len = + TO_LEN + dialog->rem_uri.len + CRLF_LEN + + (((dialog->rem_uri.s[dialog->rem_uri.len - 1] != '>')) ? 2 : 0); memapp(w, TO, TO_LEN); - if(bracket) memapp(w, "<", 1); + if(bracket) + memapp(w, "<", 1); memapp(w, dialog->rem_uri.s, dialog->rem_uri.len); - if(bracket) memapp(w, ">", 1); + if(bracket) + memapp(w, ">", 1); - if (dialog->id.rem_tag.len) { - t->to_hdr.len += TOTAG_LEN + dialog->id.rem_tag.len ; + if(dialog->id.rem_tag.len) { + t->to_hdr.len += TOTAG_LEN + dialog->id.rem_tag.len; memapp(w, TOTAG, TOTAG_LEN); memapp(w, dialog->id.rem_tag.s, dialog->id.rem_tag.len); } @@ -1454,18 +1478,22 @@ static inline char* print_to(char* w, dlg_t* dialog, struct cell* t, int bracket /* * Print From header field */ -static inline char* print_from(char* w, dlg_t* dialog, struct cell* t, int bracket) +static inline char *print_from( + char *w, dlg_t *dialog, struct cell *t, int bracket) { t->from_hdr.s = w; - t->from_hdr.len = FROM_LEN + dialog->loc_uri.len + CRLF_LEN - + ((dialog->loc_uri.s[dialog->loc_uri.len - 1]!='>')?2:0); + t->from_hdr.len = + FROM_LEN + dialog->loc_uri.len + CRLF_LEN + + ((dialog->loc_uri.s[dialog->loc_uri.len - 1] != '>') ? 2 : 0); memapp(w, FROM, FROM_LEN); - if(bracket) memapp(w, "<", 1); + if(bracket) + memapp(w, "<", 1); memapp(w, dialog->loc_uri.s, dialog->loc_uri.len); - if(bracket) memapp(w, ">", 1); + if(bracket) + memapp(w, ">", 1); - if (dialog->id.loc_tag.len) { + if(dialog->id.loc_tag.len) { t->from_hdr.len += FROMTAG_LEN + dialog->id.loc_tag.len; memapp(w, FROMTAG, FROMTAG_LEN); memapp(w, dialog->id.loc_tag.s, dialog->id.loc_tag.len); @@ -1479,7 +1507,8 @@ static inline char* print_from(char* w, dlg_t* dialog, struct cell* t, int brack /* * Print CSeq header field */ -char* print_cseq_mini(char* target, str* cseq, str* method) { +char *print_cseq_mini(char *target, str *cseq, str *method) +{ memapp(target, CSEQ, CSEQ_LEN); memapp(target, cseq->s, cseq->len); memapp(target, " ", 1); @@ -1487,7 +1516,7 @@ char* print_cseq_mini(char* target, str* cseq, str* method) { return target; } -static inline char* print_cseq(char* w, str* cseq, str* method, struct cell* t) +static inline char *print_cseq(char *w, str *cseq, str *method, struct cell *t) { t->cseq_hdr_n.s = w; /* don't include method name and CRLF -- subsequent @@ -1510,14 +1539,15 @@ static inline char* print_cseq(char* w, str* cseq, str* method, struct cell* t) * created an extra function for pure header field creation, * that is used by t_cancel for t_uac_cancel FIFO function. */ -char* print_callid_mini(char* target, str callid) { +char *print_callid_mini(char *target, str callid) +{ memapp(target, CALLID, CALLID_LEN); memapp(target, callid.s, callid.len); memapp(target, CRLF, CRLF_LEN); return target; } -static inline char* print_callid(char* w, dlg_t* dialog, struct cell* t) +static inline char *print_callid(char *w, dlg_t *dialog, struct cell *t) { /* begins with CRLF, not included in t->callid, don`t know why...?!? */ memapp(w, CRLF, CRLF_LEN); @@ -1537,55 +1567,55 @@ static inline char* print_callid(char* w, dlg_t* dialog, struct cell* t) /* * 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) { - char* buf, *w, *p; + char *buf, *w, *p; str content_length, cseq, via; unsigned int maxfwd_len; int tbracket, fbracket; str fromtag = STR_NULL; str loc_tag = STR_NULL; - if (!method || !dialog) { + if(!method || !dialog) { LM_ERR("invalid parameter value\n"); return 0; } - if (dialog->id.loc_tag.len<=0) { + if(dialog->id.loc_tag.len <= 0) { /* From Tag is mandatory in RFC3261 - generate one if not provided */ generate_fromtag(&fromtag, &dialog->id.call_id, &(dialog->rem_uri)); loc_tag = dialog->id.loc_tag; dialog->id.loc_tag = fromtag; } - if (print_content_length(&content_length, body) < 0) { + if(print_content_length(&content_length, body) < 0) { LM_ERR("error while printing content-length\n"); return 0; } - if (print_cseq_num(&cseq, dialog) < 0) { + if(print_cseq_num(&cseq, dialog) < 0) { LM_ERR("error while printing CSeq number\n"); return 0; } - if(headers==NULL || headers->len<15 - || _strnstr(headers->s, "Max-Forwards:", headers->len)==NULL) { + if(headers == NULL || headers->len < 15 + || _strnstr(headers->s, "Max-Forwards:", headers->len) == NULL) { maxfwd_len = MAXFWD_HEADER_LEN; } else { maxfwd_len = 0; } *len = method->len + 1 + dialog->hooks.request_uri->len + 1 - + SIP_VERSION_LEN + CRLF_LEN; + + SIP_VERSION_LEN + CRLF_LEN; - if (assemble_via(&via, t, dst, branch) < 0) { + if(assemble_via(&via, t, dst, branch) < 0) { LM_ERR("error while assembling Via\n"); return 0; } *len += via.len; - if((p=q_memrchr(dialog->rem_uri.s, '>', dialog->rem_uri.len))!=NULL) { - if((p==dialog->rem_uri.s + dialog->rem_uri.len - 1) - || *(p+1)==';') { + if((p = q_memrchr(dialog->rem_uri.s, '>', dialog->rem_uri.len)) != NULL) { + if((p == dialog->rem_uri.s + dialog->rem_uri.len - 1) + || *(p + 1) == ';') { tbracket = 0; } else { tbracket = 1; @@ -1593,9 +1623,9 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, } else { tbracket = 1; } - if((p=q_memrchr(dialog->loc_uri.s, '>', dialog->loc_uri.len))!=NULL) { - if((p==dialog->loc_uri.s + dialog->loc_uri.len - 1) - || *(p+1)==';') { + if((p = q_memrchr(dialog->loc_uri.s, '>', dialog->loc_uri.len)) != NULL) { + if((p == dialog->loc_uri.s + dialog->loc_uri.len - 1) + || *(p + 1) == ';') { fbracket = 0; } else { fbracket = 1; @@ -1605,52 +1635,57 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, } *len += TO_LEN + dialog->rem_uri.len - + (dialog->id.rem_tag.len ? (TOTAG_LEN + dialog->id.rem_tag.len) : 0) - + CRLF_LEN; /* To */ - if(tbracket) *len += 2; /* To-URI < > */ + + (dialog->id.rem_tag.len ? (TOTAG_LEN + dialog->id.rem_tag.len) + : 0) + + CRLF_LEN; /* To */ + if(tbracket) + *len += 2; /* To-URI < > */ *len += FROM_LEN + dialog->loc_uri.len - + (dialog->id.loc_tag.len ? (FROMTAG_LEN + dialog->id.loc_tag.len) : 0) - + CRLF_LEN; /* From */ - if(fbracket) *len += 2; /* From-URI < > */ - *len += CALLID_LEN + dialog->id.call_id.len + CRLF_LEN; /* Call-ID */ + + (dialog->id.loc_tag.len ? (FROMTAG_LEN + dialog->id.loc_tag.len) + : 0) + + CRLF_LEN; /* From */ + if(fbracket) + *len += 2; /* From-URI < > */ + *len += CALLID_LEN + dialog->id.call_id.len + CRLF_LEN; /* Call-ID */ *len += CSEQ_LEN + cseq.len + 1 + method->len + CRLF_LEN; /* CSeq */ - *len += calculate_routeset_length(dialog); /* Route set */ - *len += maxfwd_len; /* Max-forwards */ + *len += calculate_routeset_length(dialog); /* Route set */ + *len += maxfwd_len; /* Max-forwards */ *len += CONTENT_LENGTH_LEN + content_length.len - + CRLF_LEN; /* Content-Length */ - *len += ((server_signature && user_agent_hdr.len>0) - ? (user_agent_hdr.len + CRLF_LEN) : 0); /* Signature */ - if(headers && headers->len>2) { + + CRLF_LEN; /* Content-Length */ + *len += ((server_signature && user_agent_hdr.len > 0) + ? (user_agent_hdr.len + CRLF_LEN) + : 0); /* Signature */ + if(headers && headers->len > 2) { /* Additional headers */ *len += headers->len; /* End of header if missing */ if(headers->s[headers->len - 1] != '\n') *len += CRLF_LEN; } - *len += (body ? body->len : 0); /* Message body */ - *len += CRLF_LEN; /* End of Header */ + *len += (body ? body->len : 0); /* Message body */ + *len += CRLF_LEN; /* End of Header */ buf = shm_malloc(*len + 1); - if (!buf) { + if(!buf) { SHM_MEM_ERROR_FMT("required (%d)\n", *len); goto error; } w = buf; - w = print_request_uri(w, method, dialog, t, branch); /* Request-URI */ - memapp(w, via.s, via.len); /* Top-most Via */ - w = print_to(w, dialog, t, tbracket); /* To */ - w = print_from(w, dialog, t, fbracket); /* From */ - if(fromtag.len>0) { + w = print_request_uri(w, method, dialog, t, branch); /* Request-URI */ + memapp(w, via.s, via.len); /* Top-most Via */ + w = print_to(w, dialog, t, tbracket); /* To */ + w = print_from(w, dialog, t, fbracket); /* From */ + if(fromtag.len > 0) { dialog->id.loc_tag = loc_tag; } - w = print_cseq(w, &cseq, method, t); /* CSeq */ - w = print_callid(w, dialog, t); /* Call-ID */ - w = print_routeset(w, dialog); /* Route set */ + w = print_cseq(w, &cseq, method, t); /* CSeq */ + w = print_callid(w, dialog, t); /* Call-ID */ + w = print_routeset(w, dialog); /* Route set */ - if(maxfwd_len>0) - memapp(w, MAXFWD_HEADER, MAXFWD_HEADER_LEN); /* Max-forwards */ + if(maxfwd_len > 0) + memapp(w, MAXFWD_HEADER, MAXFWD_HEADER_LEN); /* Max-forwards */ /* Content-Length */ memapp(w, CONTENT_LENGTH, CONTENT_LENGTH_LEN); @@ -1658,20 +1693,21 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, memapp(w, CRLF, CRLF_LEN); /* Server signature */ - if (server_signature && user_agent_hdr.len>0) { + if(server_signature && user_agent_hdr.len > 0) { memapp(w, user_agent_hdr.s, user_agent_hdr.len); memapp(w, CRLF, CRLF_LEN); } - if(headers && headers->len>2) { + if(headers && headers->len > 2) { memapp(w, headers->s, headers->len); if(headers->s[headers->len - 1] != '\n') memapp(w, CRLF, CRLF_LEN); } memapp(w, CRLF, CRLF_LEN); - if (body && body->s && body->len>0) memapp(w, body->s, body->len); + if(body && body->s && body->len > 0) + memapp(w, body->s, body->len); #ifdef EXTRA_DEBUG - assert(w-buf == *len); + assert(w - buf == *len); #endif memapp(w, "\0", 1); @@ -1685,19 +1721,16 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, } -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) { - return branch_builder( t->hash_index, - 0, t->md5, - b, branch, branch_len ); + return branch_builder(t->hash_index, 0, t->md5, b, branch, branch_len); } /** * build CANCEL from UAC side */ -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) { char *cancel_buf, *p; char branch_buf[MAX_BRANCH_PARAM_LEN]; @@ -1706,40 +1739,41 @@ char *build_uac_cancel(str *headers,str *body,struct cell *cancelledT, str content_length, via; LM_DBG("sing FROM=<%.*s>, TO=<%.*s>, CSEQ_N=<%.*s>\n", - cancelledT->from_hdr.len, cancelledT->from_hdr.s, cancelledT->to_hdr.len, - cancelledT->to_hdr.s, cancelledT->cseq_hdr_n.len, cancelledT->cseq_hdr_n.s); + cancelledT->from_hdr.len, cancelledT->from_hdr.s, + cancelledT->to_hdr.len, cancelledT->to_hdr.s, + cancelledT->cseq_hdr_n.len, cancelledT->cseq_hdr_n.s); - branch_str.s=branch_buf; - if (!t_calc_branch(cancelledT, branch, branch_str.s, &branch_str.len )){ + branch_str.s = branch_buf; + if(!t_calc_branch(cancelledT, branch, branch_str.s, &branch_str.len)) { LM_ERR("failed to create branch !\n"); goto error; } - set_hostport(&hp,0); + set_hostport(&hp, 0); - if (assemble_via(&via, cancelledT, dst, branch) < 0) { + if(assemble_via(&via, cancelledT, dst, branch) < 0) { LM_ERR("Error while assembling Via\n"); return 0; } /* method, separators, version */ - *len=CANCEL_LEN + 2 /* spaces */ +SIP_VERSION_LEN + CRLF_LEN; - *len+=cancelledT->uac[branch].uri.len; + *len = CANCEL_LEN + 2 /* spaces */ + SIP_VERSION_LEN + CRLF_LEN; + *len += cancelledT->uac[branch].uri.len; /*via*/ - *len+= via.len; + *len += via.len; /*From*/ - *len+=cancelledT->from_hdr.len; + *len += cancelledT->from_hdr.len; /*To*/ - *len+=cancelledT->to_hdr.len; + *len += cancelledT->to_hdr.len; /*CallId*/ - *len+=cancelledT->callid_hdr.len; + *len += cancelledT->callid_hdr.len; /*CSeq*/ - *len+=cancelledT->cseq_hdr_n.len+1+CANCEL_LEN+CRLF_LEN; + *len += cancelledT->cseq_hdr_n.len + 1 + CANCEL_LEN + CRLF_LEN; /* User Agent */ - if (server_signature) { + if(server_signature) { *len += USER_AGENT_LEN + CRLF_LEN; } /* Content Length */ - if (print_content_length(&content_length, body) < 0) { + if(print_content_length(&content_length, body) < 0) { LM_ERR("failed to print content-length\n"); return 0; } @@ -1748,57 +1782,55 @@ char *build_uac_cancel(str *headers,str *body,struct cell *cancelledT, /*Additional headers*/ *len += (headers ? headers->len : 0); /*EoM*/ - *len+= CRLF_LEN; + *len += CRLF_LEN; /* Message body */ *len += (body ? body->len : 0); - cancel_buf=shm_malloc( *len+1 ); - if (!cancel_buf) - { + cancel_buf = shm_malloc(*len + 1); + if(!cancel_buf) { SHM_MEM_ERROR; goto error01; } p = cancel_buf; - memapp( p, CANCEL, CANCEL_LEN ); + memapp(p, CANCEL, CANCEL_LEN); *(p++) = ' '; - memapp( p, cancelledT->uac[branch].uri.s, - cancelledT->uac[branch].uri.len); - memapp( p, " " SIP_VERSION CRLF, 1+SIP_VERSION_LEN+CRLF_LEN ); + memapp(p, cancelledT->uac[branch].uri.s, cancelledT->uac[branch].uri.len); + memapp(p, " " SIP_VERSION CRLF, 1 + SIP_VERSION_LEN + CRLF_LEN); /* insert our via */ - memapp(p,via.s,via.len); + memapp(p, via.s, via.len); /*other headers*/ - memapp( p, cancelledT->from_hdr.s, cancelledT->from_hdr.len ); - memapp( p, cancelledT->callid_hdr.s, cancelledT->callid_hdr.len ); - memapp( p, cancelledT->to_hdr.s, cancelledT->to_hdr.len ); + memapp(p, cancelledT->from_hdr.s, cancelledT->from_hdr.len); + memapp(p, cancelledT->callid_hdr.s, cancelledT->callid_hdr.len); + memapp(p, cancelledT->to_hdr.s, cancelledT->to_hdr.len); - memapp( p, cancelledT->cseq_hdr_n.s, cancelledT->cseq_hdr_n.len ); + memapp(p, cancelledT->cseq_hdr_n.s, cancelledT->cseq_hdr_n.len); *(p++) = ' '; - memapp( p, CANCEL, CANCEL_LEN ); - memapp( p, CRLF, CRLF_LEN ); + memapp(p, CANCEL, CANCEL_LEN); + memapp(p, CRLF, CRLF_LEN); /* User Agent header */ - if (server_signature) { - memapp(p,USER_AGENT CRLF, USER_AGENT_LEN+CRLF_LEN ); + if(server_signature) { + memapp(p, USER_AGENT CRLF, USER_AGENT_LEN + CRLF_LEN); } /* Content Length*/ - if (body) { + if(body) { memapp(p, CONTENT_LENGTH, CONTENT_LENGTH_LEN); memapp(p, content_length.s, content_length.len); memapp(p, CRLF, CRLF_LEN); } - if(headers && headers->len){ - memapp(p,headers->s,headers->len); + if(headers && headers->len) { + memapp(p, headers->s, headers->len); } /*EoM*/ - memapp(p,CRLF,CRLF_LEN); - if(body && body->len){ - memapp(p,body->s,body->len); + memapp(p, CRLF, CRLF_LEN); + if(body && body->len) { + memapp(p, body->s, body->len); } - *p=0; + *p = 0; pkg_free(via.s); return cancel_buf; error01: @@ -1816,7 +1848,7 @@ void t_uas_request_clean_parsed(tm_cell_t *t) void *mstart; void *mend; - if (!t || !t->uas.request) { + if(!t || !t->uas.request) { return; } @@ -1824,18 +1856,18 @@ void t_uas_request_clean_parsed(tm_cell_t *t) mend = t->uas.end_request; /* free header's parsed structures that were added by failure handlers */ - for (hdr=t->uas.request->headers; hdr; hdr=hdr->next ) { - if (hdr->parsed && hdr_allocs_parse(hdr) - && (hdr->parsedparsed>=mend)) { + for(hdr = t->uas.request->headers; hdr; hdr = hdr->next) { + if(hdr->parsed && hdr_allocs_parse(hdr) + && (hdr->parsed < mstart || hdr->parsed >= mend)) { /* header parsed filed doesn't point inside fake memory * chunck -> it was added by failure funcs.-> free it as pkg */ - LM_DBG("removing hdr->parsed %d\n", hdr->type); + LM_DBG("removing hdr->parsed %d\n", hdr->type); clean_hdr_field(hdr); hdr->parsed = 0; } } /* free parsed body added by failure handlers */ - if (t->uas.request->body) { + if(t->uas.request->body) { if(t->uas.request->body->free) t->uas.request->body->free(&t->uas.request->body); t->uas.request->body = 0; diff --git a/src/modules/tm/t_msgbuilder.h b/src/modules/tm/t_msgbuilder.h index a97c1f94510..78ee09e6e33 100644 --- a/src/modules/tm/t_msgbuilder.h +++ b/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); diff --git a/src/modules/tm/t_reply.c b/src/modules/tm/t_reply.c index 5c4d4fcb379..dc4bf8cffe3 100644 --- a/src/modules/tm/t_reply.c +++ b/src/modules/tm/t_reply.c @@ -86,17 +86,17 @@ char tm_tags[TOTAG_VALUE_LEN]; /* bogdan: pack tm_tag buffer and len into a str to pass them to * build_res_buf_from_sip_req() */ -static str tm_tag = {tm_tags,TOTAG_VALUE_LEN}; +static str tm_tag = {tm_tags, TOTAG_VALUE_LEN}; char *tm_tag_suffix; /* where to go if there is no positive reply (>=300) */ -static int goto_on_failure=0; +static int goto_on_failure = 0; /* where to go if a failure is returned on a branch */ -static int goto_on_branch_failure=0; +static int goto_on_branch_failure = 0; /* where to go on receipt of reply */ -static int goto_on_reply=0; +static int goto_on_reply = 0; /* where to go on receipt of reply without transaction context */ -int goto_on_sl_reply=0; +int goto_on_sl_reply = 0; extern str on_sl_reply_name; extern str _tm_event_callback_lres_sent; @@ -130,16 +130,16 @@ int failure_reply_mode = 3; /* responses priority (used by t_pick_branch) * 0xx is used only for the initial value (=> should have no chance to be * selected => the highest value); 1xx is not used */ -static unsigned short resp_class_prio[]={ - 32000, /* 0-99, special */ - 11000, /* 1xx, special, should never be used */ - 0, /* 2xx, high priority (not used, 2xx are immediately +static unsigned short resp_class_prio[] = { + 32000, /* 0-99, special */ + 11000, /* 1xx, special, should never be used */ + 0, /* 2xx, high priority (not used, 2xx are immediately * forwarded and t_pick_branch will never be called if * a 2xx was received) */ - 3000, /* 3xx */ - 4000, /* 4xx */ - 5000, /* 5xx */ - 1000 /* 6xx, highest priority */ + 3000, /* 3xx */ + 4000, /* 4xx */ + 5000, /* 5xx */ + 1000 /* 6xx, highest priority */ }; /* How to prioritize faked replies @@ -153,7 +153,7 @@ int faked_reply_prio = 0; int t_get_reply_totag(struct sip_msg *msg, str *totag) { - if(msg==NULL || totag==NULL) { + if(msg == NULL || totag == NULL) { return -1; } @@ -172,8 +172,6 @@ int t_get_picked_branch(void) } - - /* we store the reply_route # in private memory which is * then processed during t_relay; we cannot set this value * before t_relay creates transaction context or after @@ -184,43 +182,43 @@ int t_get_picked_branch(void) */ -void t_on_failure( unsigned int go_to ) +void t_on_failure(unsigned int go_to) { struct cell *t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variable */ - if (!t || t==T_UNDEFINED ) - goto_on_failure=go_to; + if(!t || t == T_UNDEFINED) + goto_on_failure = go_to; else t->on_failure = go_to; } -void t_on_branch_failure( unsigned int go_to ) +void t_on_branch_failure(unsigned int go_to) { struct cell *t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variable */ - if (!t || t==T_UNDEFINED ) - goto_on_branch_failure=go_to; + if(!t || t == T_UNDEFINED) + goto_on_branch_failure = go_to; else t->on_branch_failure = go_to; } -void t_on_reply( unsigned int go_to ) +void t_on_reply(unsigned int go_to) { struct cell *t = get_t(); /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; * in REQUEST_ROUTE T will be set only if the transaction was already * created; if not -> use the static variable */ - if (!t || t==T_UNDEFINED ) - goto_on_reply=go_to; + if(!t || t == T_UNDEFINED) + goto_on_reply = go_to; else t->on_reply = go_to; } @@ -243,8 +241,7 @@ unsigned int get_on_reply() void tm_init_tags() { - init_tags(tm_tags, &tm_tag_suffix, - "SER-TM/tags", TM_TAG_SEPARATOR ); + init_tags(tm_tags, &tm_tag_suffix, "SER-TM/tags", TM_TAG_SEPARATOR); } /* returns 0 if the message was previously acknowledged @@ -255,36 +252,33 @@ int unmatched_totag(struct cell *t, struct sip_msg *ack) struct totag_elem *i; str *tag; - if (parse_headers(ack, HDR_TO_F,0)==-1 || - !ack->to ) { + if(parse_headers(ack, HDR_TO_F, 0) == -1 || !ack->to) { LM_ERR("To header is invalid\n"); return 1; } - tag=&get_to(ack)->tag_value; - i=t->fwded_totags; - while(i){ + tag = &get_to(ack)->tag_value; + i = t->fwded_totags; + while(i) { membar_depends(); /* make sure we don't see some old i content (needed on CPUs like Alpha) */ - if (i->tag.len==tag->len - && memcmp(i->tag.s, tag->s, tag->len)==0) { + if(i->tag.len == tag->len && memcmp(i->tag.s, tag->s, tag->len) == 0) { LM_DBG("totag for e2e ACK found: %d\n", i->acked); /* mark totag as acked and return 1 if this was the first ack * and 0 otherwise */ - return (atomic_get_and_set_int(&i->acked, 1)==0); + return (atomic_get_and_set_int(&i->acked, 1) == 0); } - i=i->next; + i = i->next; } /* surprising: to-tag never sighted before */ return 1; } -static inline void update_local_tags(struct cell *trans, - struct bookmark *bm, char *dst_buffer, - char *src_buffer /* to which bm refers */) +static inline void update_local_tags(struct cell *trans, struct bookmark *bm, + char *dst_buffer, char *src_buffer /* to which bm refers */) { - if (bm->to_tag_val.s) { - trans->uas.local_totag.s=bm->to_tag_val.s-src_buffer+dst_buffer; - trans->uas.local_totag.len=bm->to_tag_val.len; + if(bm->to_tag_val.s) { + trans->uas.local_totag.s = bm->to_tag_val.s - src_buffer + dst_buffer; + trans->uas.local_totag.len = bm->to_tag_val.len; } } @@ -300,38 +294,40 @@ inline static int update_totag_set(struct cell *t, struct sip_msg *ok) str *tag; char *s; - if (!ok->to || !ok->to->parsed) { + if(!ok->to || !ok->to->parsed) { LM_ERR("to header not parsed\n"); return 0; } - tag=&get_to(ok)->tag_value; - if (!tag->s) { + tag = &get_to(ok)->tag_value; + if(!tag->s) { LM_DBG("no tag in to header\n"); return 0; } - for (i=t->fwded_totags; i; i=i->next) { - if (i->tag.len==tag->len - && i->tag.s - && memcmp(i->tag.s, tag->s, tag->len) ==0 ){ + for(i = t->fwded_totags; i; i = i->next) { + if(i->tag.len == tag->len && i->tag.s + && memcmp(i->tag.s, tag->s, tag->len) == 0) { /* to tag already recorded */ LM_DBG("to-tag retransmission\n"); return 1; } } /* that's a new to-tag -- record it */ - n=(struct totag_elem*) shm_malloc(sizeof(struct totag_elem)); - s=(char *)shm_malloc(tag->len); - if (!s || !n) { + n = (struct totag_elem *)shm_malloc(sizeof(struct totag_elem)); + s = (char *)shm_malloc(tag->len); + if(!s || !n) { SHM_MEM_ERROR; - if (n) shm_free(n); - if (s) shm_free(s); + if(n) + shm_free(n); + if(s) + shm_free(s); return 0; } memset(n, 0, sizeof(struct totag_elem)); memcpy(s, tag->s, tag->len); - n->tag.s=s;n->tag.len=tag->len; - n->next=t->fwded_totags; + n->tag.s = s; + n->tag.len = tag->len; + n->next = t->fwded_totags; membar_write(); /* make sure all the changes to n are visible on all cpus * before we update t->fwded_totags. This is needed for * three reasons: the compiler might reorder some of the @@ -341,7 +337,7 @@ inline static int update_totag_set(struct cell *t, struct sip_msg *ok) * another cpu _after_ seeing t->fwded_totags=n) and * the "readers" (unmatched_tags()) do not use locks and * can be called simultaneously on another cpu.*/ - t->fwded_totags=n; + t->fwded_totags = n; LM_DBG("new totag [%.*s]\n", tag->len, tag->s); return 0; } @@ -350,30 +346,25 @@ inline static int update_totag_set(struct cell *t, struct sip_msg *ok) /* * Build an ACK to a negative reply */ -static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch, - unsigned int *ret_len) +static char *build_ack(struct sip_msg *rpl, struct cell *trans, int branch, + unsigned int *ret_len) { str to; - if (parse_headers(rpl,HDR_TO_F, 0)==-1 || !rpl->to ) { + if(parse_headers(rpl, HDR_TO_F, 0) == -1 || !rpl->to) { LM_ERR("cannot generate a HBH ACK if key HFs in reply missing\n"); return NULL; } - to.s=rpl->to->name.s; - to.len=rpl->to->len; + to.s = rpl->to->name.s; + to.len = rpl->to->len; - if (cfg_get(tm, tm_cfg, reparse_invite)) { + if(cfg_get(tm, tm_cfg, reparse_invite)) { /* build the ACK from the INVITE which was sent out */ - return build_local_reparse( trans, branch, ret_len, - ACK, ACK_LEN, &to - , 0 - ); + return build_local_reparse( + trans, branch, ret_len, ACK, ACK_LEN, &to, 0); } else { /* build the ACK from the reveived INVITE */ - return build_local( trans, branch, ret_len, - ACK, ACK_LEN, &to - , 0 - ); + return build_local(trans, branch, ret_len, ACK, ACK_LEN, &to, 0); } } @@ -386,14 +377,13 @@ static char *build_ack(struct sip_msg* rpl,struct cell *trans,int branch, * returns 0 on error and a pkg_malloc'ed buffer with length in ret_len * and intended destination in dst on success. */ -static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, - int branch, unsigned int *ret_len, - struct dest_info* dst) +static char *build_local_ack(struct sip_msg *rpl, struct cell *trans, + int branch, unsigned int *ret_len, struct dest_info *dst) { struct retr_buf *local_ack, *old_lack; /* do we have the ACK cache, previously build? */ - if ((local_ack = trans->uac[0].local_ack) && local_ack->buffer_len) { + if((local_ack = trans->uac[0].local_ack) && local_ack->buffer_len) { LM_DBG("reusing ACK retr. buffer.\n"); *ret_len = local_ack->buffer_len; *dst = local_ack->dst; @@ -401,11 +391,11 @@ static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, } /* the ACK will be built (and cached) by the AS (ack_local_uac()) */ - if (trans->flags & T_NO_AUTO_ACK) + if(trans->flags & T_NO_AUTO_ACK) return NULL; - if (! (local_ack = local_ack_rb(rpl, trans, branch, /*hdrs*/NULL, - /*body*/NULL))) { + if(!(local_ack = local_ack_rb(rpl, trans, branch, /*hdrs*/ NULL, + /*body*/ NULL))) { LM_ERR("failed to build local ACK retransmission buffer (T@%p).\n", trans); return NULL; @@ -416,8 +406,8 @@ static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, * content is fully written, before we try to add it to the transaction * -- andrei */ membar_write_atomic_op(); - if ((old_lack = (struct retr_buf *)atomic_cmpxchg_long( - (void *)&trans->uac[0].local_ack, 0, (long)local_ack))) { + if((old_lack = (struct retr_buf *)atomic_cmpxchg_long( + (void *)&trans->uac[0].local_ack, 0, (long)local_ack))) { /* buffer already set: trash current and use the winning one */ LM_INFO("concurrent 2xx to local INVITE detected (T@%p).\n", trans); free_local_ack(local_ack); @@ -430,22 +420,22 @@ static char *build_local_ack(struct sip_msg* rpl, struct cell *trans, } -inline static void start_final_repl_retr( struct cell *t ) +inline static void start_final_repl_retr(struct cell *t) { - if (unlikely(!is_local(t) && t->uas.request->REQ_METHOD==METHOD_INVITE )){ + if(unlikely(!is_local(t) && t->uas.request->REQ_METHOD == METHOD_INVITE)) { /* crank timers for negative replies */ - if (t->uas.status>=300) { - if (start_retr(&t->uas.response)!=0) + if(t->uas.status >= 300) { + if(start_retr(&t->uas.response) != 0) LM_CRIT("BUG: start retr failed for %p\n", &t->uas.response); return; } /* local UAS retransmits too */ - if (t->relayed_reply_branch==-2 && t->uas.status>=200) { + if(t->relayed_reply_branch == -2 && t->uas.status >= 200) { /* we retransmit 200/INVs regardless of transport -- * even if TCP used, UDP could be used upstream and * loose the 200, which is not retransmitted by proxies */ - if (force_retr( &t->uas.response )!=0) + if(force_retr(&t->uas.response) != 0) LM_CRIT("BUG: force retr failed for %p\n", &t->uas.response); return; } @@ -453,13 +443,11 @@ inline static void start_final_repl_retr( struct cell *t ) } - static int _tm_local_response_sent_lookup = 0; -static int _reply_light( struct cell *trans, char* buf, unsigned int len, - unsigned int code, - char *to_tag, unsigned int to_tag_len, int lock, - struct bookmark *bm ) +static int _reply_light(struct cell *trans, char *buf, unsigned int len, + unsigned int code, char *to_tag, unsigned int to_tag_len, int lock, + struct bookmark *bm) { struct retr_buf *rb; unsigned int buf_len; @@ -473,75 +461,76 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len, str evname = str_init("tm:local-response-sent"); init_cancel_info(&cancel_data); - if (!buf) - { + if(!buf) { LM_ERR("response building failed\n"); /* determine if there are some branches to be canceled */ - if ( is_invite(trans) ) { + if(is_invite(trans)) { prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0); } /* and clean-up, including cancellations, if needed */ goto error; } - if (lock) LOCK_REPLIES( trans ); - if (trans->uas.status>=200) { - LM_INFO("can't generate %d reply when a final %d was sent out\n", - code, trans->uas.status); + if(lock) + LOCK_REPLIES(trans); + if(trans->uas.status >= 200) { + LM_INFO("can't generate %d reply when a final %d was sent out\n", code, + trans->uas.status); goto error2; } - rb = & trans->uas.response; - rb->rbtype=code; + rb = &trans->uas.response; + rb->rbtype = code; trans->uas.status = code; - if(len<=0) { + if(len <= 0) { LM_ERR("invalid new buffer len\n"); goto error3; } buf_len = rb->buffer ? len : len + REPLY_OVERBUFFER_LEN; - rb->buffer = (char*)shm_resize( rb->buffer, buf_len ); + rb->buffer = (char *)shm_resize(rb->buffer, buf_len); /* puts the reply's buffer to uas.response */ - if (! rb->buffer ) { + if(!rb->buffer) { LM_ERR("cannot allocate shmem buffer\n"); goto error3; } update_local_tags(trans, bm, rb->buffer, buf); - rb->buffer_len = len ; - memcpy( rb->buffer , buf , len ); + rb->buffer_len = len; + memcpy(rb->buffer, buf, len); /* needs to be protected too because what timers are set depends * on current transactions status */ /* t_update_timers_after_sending_reply( rb ); */ - update_reply_stats( code ); - trans->relayed_reply_branch=-2; + update_reply_stats(code); + trans->relayed_reply_branch = -2; t_stats_rpl_generated(); t_stats_rpl_sent(); - if (lock) UNLOCK_REPLIES( trans ); + if(lock) + UNLOCK_REPLIES(trans); /* do UAC cleanup procedures in case we generated * a final answer whereas there are pending UACs */ - if (code>=200) { - if (unlikely(is_local(trans))) { + if(code >= 200) { + if(unlikely(is_local(trans))) { if(unlikely(has_tran_tmcbs(trans, TMCB_LOCAL_COMPLETED))) - run_trans_callbacks(TMCB_LOCAL_COMPLETED, trans, - 0, FAKED_REPLY, code); + run_trans_callbacks( + TMCB_LOCAL_COMPLETED, trans, 0, FAKED_REPLY, code); } else { if(unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_READY))) { run_trans_callbacks_with_buf(TMCB_RESPONSE_READY, rb, - trans->uas.request, FAKED_REPLY, TMCB_NONE_F); + trans->uas.request, FAKED_REPLY, TMCB_NONE_F); } } - cleanup_uac_timers( trans ); - if (is_invite(trans)){ + cleanup_uac_timers(trans); + if(is_invite(trans)) { prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0); - cancel_data.reason.cause=code; - cancel_uacs( trans, &cancel_data, F_CANCEL_B_KILL ); + cancel_data.reason.cause = code; + cancel_uacs(trans, &cancel_data, F_CANCEL_B_KILL); } - start_final_repl_retr( trans ); + start_final_repl_retr(trans); } - if (code==100) { + if(code == 100) { if(unlikely(has_tran_tmcbs(trans, TMCB_REQUEST_PENDING))) run_trans_callbacks_with_buf(TMCB_REQUEST_PENDING, rb, trans->uas.request, FAKED_REPLY, TMCB_NONE_F); @@ -558,47 +547,47 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len, * If reply_to_via is set and via contains a host name (and not an ip) * the chances for this increase a lot. */ - if (unlikely(!trans->uas.response.dst.send_sock)) { + if(unlikely(!trans->uas.response.dst.send_sock)) { LM_ERR("no resolved dst to send reply to\n"); } else { - if (likely(SEND_PR_BUFFER( rb, buf, len )>=0)){ - if (unlikely(code>=200 && !is_local(trans) && - has_tran_tmcbs(trans, TMCB_RESPONSE_OUT)) ){ + if(likely(SEND_PR_BUFFER(rb, buf, len) >= 0)) { + if(unlikely(code >= 200 && !is_local(trans) + && has_tran_tmcbs(trans, TMCB_RESPONSE_OUT))) { INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request, - FAKED_REPLY, rb, &rb->dst, - buf, len, TMCB_LOCAL_F, rb->branch, code); - run_trans_callbacks_off_params(TMCB_RESPONSE_OUT, trans, - &onsend_params); + FAKED_REPLY, rb, &rb->dst, buf, len, TMCB_LOCAL_F, + rb->branch, code); + run_trans_callbacks_off_params( + TMCB_RESPONSE_OUT, trans, &onsend_params); } - if (unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_SENT))){ + if(unlikely(has_tran_tmcbs(trans, TMCB_RESPONSE_SENT))) { INIT_TMCB_ONSEND_PARAMS(onsend_params, trans->uas.request, - FAKED_REPLY, rb, &rb->dst, - buf, len, TMCB_LOCAL_F, rb->branch, code); - run_trans_callbacks_off_params(TMCB_RESPONSE_SENT, trans, - &onsend_params); + FAKED_REPLY, rb, &rb->dst, buf, len, TMCB_LOCAL_F, + rb->branch, code); + run_trans_callbacks_off_params( + TMCB_RESPONSE_SENT, trans, &onsend_params); } - if(_tm_event_callback_lres_sent.len>0 - && _tm_event_callback_lres_sent.s!=NULL) { + if(_tm_event_callback_lres_sent.len > 0 + && _tm_event_callback_lres_sent.s != NULL) { keng = sr_kemi_eng_get(); } rt = -1; - if(likely(keng==NULL)) { + if(likely(keng == NULL)) { if(_tm_local_response_sent_lookup == 0) { rt = route_lookup(&event_rt, "tm:local-response"); _tm_local_response_sent_lookup = 1; } } - if ((rt >= 0 && event_rt.rlist[rt] != NULL) || (keng != NULL) + if((rt >= 0 && event_rt.rlist[rt] != NULL) || (keng != NULL) || sr_event_enabled(SREV_SIP_REPLY_OUT)) { - if (likely(build_sip_msg_from_buf(&pmsg, buf, len, - inc_msg_no()) == 0)) { + if(likely(build_sip_msg_from_buf(&pmsg, buf, len, inc_msg_no()) + == 0)) { struct onsend_info onsnd_info; - onsnd_info.to=&(trans->uas.response.dst.to); - onsnd_info.send_sock=trans->uas.response.dst.send_sock; - onsnd_info.buf=buf; - onsnd_info.len=len; + onsnd_info.to = &(trans->uas.response.dst.to); + onsnd_info.send_sock = trans->uas.response.dst.send_sock; + onsnd_info.buf = buf; + onsnd_info.len = len; if(sr_event_enabled(SREV_SIP_REPLY_OUT)) { sr_event_param_t evp; @@ -614,7 +603,7 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len, sr_event_exec(SREV_SIP_REPLY_OUT, &evp); } - p_onsend=&onsnd_info; + p_onsend = &onsnd_info; backup_rt = get_route_type(); set_route_type(LOCAL_ROUTE); init_run_actions_ctx(&ctx); @@ -624,43 +613,43 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len, bctx = sr_kemi_act_ctx_get(); sr_kemi_act_ctx_set(&ctx); (void)sr_kemi_route(keng, &pmsg, EVENT_ROUTE, - &_tm_event_callback_lres_sent, &evname); + &_tm_event_callback_lres_sent, &evname); sr_kemi_act_ctx_set(bctx); } set_route_type(backup_rt); - p_onsend=0; + p_onsend = 0; free_sip_msg(&pmsg); } else { LM_ERR("failed to build sip msg structure\n"); } } - } - LM_DBG("reply sent out - buf=%p: %.20s... shmem=%p: %.20s\n", - buf, buf, rb->buffer, rb->buffer ); + LM_DBG("reply sent out - buf=%p: %.20s... shmem=%p: %.20s\n", buf, buf, + rb->buffer, rb->buffer); } - if (code>=200) { + if(code >= 200) { /* start wait timer after finishing with t so that this function can * be safely called from a fr_timer which allows quick timer dels * (timer_allow_del()) (there's no chance of having the wait handler * executed while we still need t) --andrei */ put_on_wait(trans); } - pkg_free( buf ) ; + pkg_free(buf); LM_DBG("finished\n"); return 1; error3: prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0); error2: - if (lock) UNLOCK_REPLIES( trans ); - pkg_free ( buf ); + if(lock) + UNLOCK_REPLIES(trans); + pkg_free(buf); error: /* do UAC cleanup */ - cleanup_uac_timers( trans ); - if ( is_invite(trans) && cancel_data.cancel_bitmap ) - cancel_uacs( trans, &cancel_data, F_CANCEL_B_KILL); + cleanup_uac_timers(trans); + if(is_invite(trans) && cancel_data.cancel_bitmap) + cancel_uacs(trans, &cancel_data, F_CANCEL_B_KILL); /* we did not succeed -- put the transaction on wait */ put_on_wait(trans); return -1; @@ -670,66 +659,68 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len, /* send a UAS reply * returns 1 if everything was OK or -1 for error */ -static int _reply( struct cell *trans, struct sip_msg* p_msg, - unsigned int code, str *reason, int lock ) +static int _reply(struct cell *trans, struct sip_msg *p_msg, unsigned int code, + str *reason, int lock) { unsigned int len; - char * buf, *dset; + char *buf, *dset; struct bookmark bm; int dset_len; - if (code>=200) set_kr(REQ_RPLD); + if(code >= 200) + set_kr(REQ_RPLD); /* compute the buffer in private memory prior to entering lock; * create to-tag if needed */ /* if that is a redirection message, dump current message set to it */ - if (code>=300 && code<400) { - dset=print_dset(p_msg, &dset_len, tm_rich_redirect); - if (dset) { + if(code >= 300 && code < 400) { + dset = print_dset(p_msg, &dset_len, tm_rich_redirect); + if(dset) { add_lump_rpl(p_msg, dset, dset_len, LUMP_RPL_HDR); } } - if (code>=180 && p_msg->to - && (get_to(p_msg)->tag_value.s==0 - || get_to(p_msg)->tag_value.len==0)) { - calc_crc_suffix( p_msg, tm_tag_suffix ); - buf = build_res_buf_from_sip_req(code, reason, &tm_tag, p_msg, - &len, &bm); - return _reply_light( trans, buf, len, code, - tm_tag.s, TOTAG_VALUE_LEN, lock, &bm); + if(code >= 180 && p_msg->to + && (get_to(p_msg)->tag_value.s == 0 + || get_to(p_msg)->tag_value.len == 0)) { + calc_crc_suffix(p_msg, tm_tag_suffix); + buf = build_res_buf_from_sip_req( + code, reason, &tm_tag, p_msg, &len, &bm); + return _reply_light( + trans, buf, len, code, tm_tag.s, TOTAG_VALUE_LEN, lock, &bm); } else { - buf = build_res_buf_from_sip_req(code, reason, 0 /*no to-tag*/, - p_msg, &len, &bm); - return _reply_light(trans,buf,len,code, - 0, 0, /* no to-tag */lock, &bm); + buf = build_res_buf_from_sip_req( + code, reason, 0 /*no to-tag*/, p_msg, &len, &bm); + return _reply_light( + trans, buf, len, code, 0, 0, /* no to-tag */ lock, &bm); } } /** * structure to backup attributes for faked env */ -typedef struct tm_faked_env { +typedef struct tm_faked_env +{ int backup_route_type; struct cell *backup_t; int backup_branch; msg_ctx_id_t ctxid; - avp_list_t* backup_user_from; - avp_list_t* backup_user_to; - avp_list_t* backup_domain_from; - avp_list_t* backup_domain_to; - avp_list_t* backup_uri_from; - avp_list_t* backup_uri_to; + avp_list_t *backup_user_from; + avp_list_t *backup_user_to; + avp_list_t *backup_domain_from; + avp_list_t *backup_domain_to; + avp_list_t *backup_uri_from; + avp_list_t *backup_uri_to; sr_xavp_t **backup_xavps; sr_xavp_t **backup_xavus; sr_xavp_t **backup_xavis; - struct socket_info* backup_si; + struct socket_info *backup_si; struct lump *backup_add_rm; struct lump *backup_body_lumps; struct lump_rpl *backup_reply_lump; } tm_faked_env_t; -#define TM_FAKED_ENV_SIZE 8 +#define TM_FAKED_ENV_SIZE 8 /** * stack of faked environments */ @@ -744,8 +735,8 @@ static int _tm_faked_env_idx = -1; */ int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env) { - if (msg) { - if(_tm_faked_env_idx+1>=TM_FAKED_ENV_SIZE) { + if(msg) { + if(_tm_faked_env_idx + 1 >= TM_FAKED_ENV_SIZE) { LM_ERR("too many faked environments on stack\n"); return -1; } @@ -756,9 +747,9 @@ int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env) */ _tm_faked_env[_tm_faked_env_idx].backup_route_type = get_route_type(); - if (is_async_env) { + if(is_async_env) { set_route_type(t->async_backup.backup_route); - if (t->async_backup.ruri_new) { + if(t->async_backup.ruri_new) { ruri_mark_new(); } } else { @@ -766,7 +757,7 @@ int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env) /* don't bother backing up ruri state, since failure route * is called either on reply or on timer and in both cases * the ruri should not be used again for forking */ - ruri_mark_consumed(); /* in failure route we assume ruri + ruri_mark_consumed(); /* in failure route we assume ruri * should not be used again for forking */ } /* also, tm actions look in beginning whether transaction is @@ -785,49 +776,42 @@ int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env) tm_global_ctx_id.msgid = msg->id; tm_global_ctx_id.pid = msg->pid; - if (is_async_env) { + if(is_async_env) { set_t(t, t->async_backup.backup_branch); } else { set_t(t, T_BR_UNDEFINED); } /* make available the avp list from transaction */ - _tm_faked_env[_tm_faked_env_idx].backup_uri_from - = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, - &t->uri_avps_from); - _tm_faked_env[_tm_faked_env_idx].backup_uri_to - = set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, - &t->uri_avps_to); - _tm_faked_env[_tm_faked_env_idx].backup_user_from - = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, - &t->user_avps_from); - _tm_faked_env[_tm_faked_env_idx].backup_user_to - = set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, - &t->user_avps_to); - _tm_faked_env[_tm_faked_env_idx].backup_domain_from - = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_DOMAIN, - &t->domain_avps_from); - _tm_faked_env[_tm_faked_env_idx].backup_domain_to - = set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, - &t->domain_avps_to); - _tm_faked_env[_tm_faked_env_idx].backup_xavps - = xavp_set_list(&t->xavps_list); - _tm_faked_env[_tm_faked_env_idx].backup_xavus - = xavu_set_list(&t->xavus_list); - _tm_faked_env[_tm_faked_env_idx].backup_xavis - = xavi_set_list(&t->xavis_list); + _tm_faked_env[_tm_faked_env_idx].backup_uri_from = + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, &t->uri_avps_from); + _tm_faked_env[_tm_faked_env_idx].backup_uri_to = + set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, &t->uri_avps_to); + _tm_faked_env[_tm_faked_env_idx].backup_user_from = set_avp_list( + AVP_TRACK_FROM | AVP_CLASS_USER, &t->user_avps_from); + _tm_faked_env[_tm_faked_env_idx].backup_user_to = + set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, &t->user_avps_to); + _tm_faked_env[_tm_faked_env_idx].backup_domain_from = set_avp_list( + AVP_TRACK_FROM | AVP_CLASS_DOMAIN, &t->domain_avps_from); + _tm_faked_env[_tm_faked_env_idx].backup_domain_to = set_avp_list( + AVP_TRACK_TO | AVP_CLASS_DOMAIN, &t->domain_avps_to); + _tm_faked_env[_tm_faked_env_idx].backup_xavps = + xavp_set_list(&t->xavps_list); + _tm_faked_env[_tm_faked_env_idx].backup_xavus = + xavu_set_list(&t->xavus_list); + _tm_faked_env[_tm_faked_env_idx].backup_xavis = + xavi_set_list(&t->xavis_list); /* set default send address to the saved value */ _tm_faked_env[_tm_faked_env_idx].backup_si = bind_address; bind_address = t->uac[0].request.dst.send_sock; /* backup lump lists */ - _tm_faked_env[_tm_faked_env_idx].backup_add_rm - = t->uas.request->add_rm; - _tm_faked_env[_tm_faked_env_idx].backup_body_lumps - = t->uas.request->body_lumps; - _tm_faked_env[_tm_faked_env_idx].backup_reply_lump - = t->uas.request->reply_lump; + _tm_faked_env[_tm_faked_env_idx].backup_add_rm = t->uas.request->add_rm; + _tm_faked_env[_tm_faked_env_idx].backup_body_lumps = + t->uas.request->body_lumps; + _tm_faked_env[_tm_faked_env_idx].backup_reply_lump = + t->uas.request->reply_lump; } else { - if(_tm_faked_env_idx<0) { + if(_tm_faked_env_idx < 0) { LM_ERR("no faked environments on stack\n"); return -1; } @@ -855,13 +839,13 @@ int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env) xavi_set_list(_tm_faked_env[_tm_faked_env_idx].backup_xavis); bind_address = _tm_faked_env[_tm_faked_env_idx].backup_si; /* restore lump lists */ - if(t!=NULL) { - t->uas.request->add_rm - = _tm_faked_env[_tm_faked_env_idx].backup_add_rm; - t->uas.request->body_lumps - = _tm_faked_env[_tm_faked_env_idx].backup_body_lumps; - t->uas.request->reply_lump - = _tm_faked_env[_tm_faked_env_idx].backup_reply_lump; + if(t != NULL) { + t->uas.request->add_rm = + _tm_faked_env[_tm_faked_env_idx].backup_add_rm; + t->uas.request->body_lumps = + _tm_faked_env[_tm_faked_env_idx].backup_body_lumps; + t->uas.request->reply_lump = + _tm_faked_env[_tm_faked_env_idx].backup_reply_lump; } _tm_faked_env_idx--; } @@ -874,16 +858,16 @@ int faked_env(struct cell *t, struct sip_msg *msg, int is_async_env) int fake_req_clone_str_helper(str *src, str *dst, char *txt) { /* src string can change -- make a private copy */ - if (src->s!=0 && src->len!=0) { - dst->s=pkg_malloc(src->len+1); - if (!dst->s) { + if(src->s != 0 && src->len != 0) { + dst->s = pkg_malloc(src->len + 1); + if(!dst->s) { PKG_MEM_ERROR; return -1; } - dst->len=src->len; + dst->len = src->len; memcpy(dst->s, src->s, dst->len); - dst->s[dst->len]=0; - }else{ + dst->s[dst->len] = 0; + } else { /* in case src->len==0, but src->s!=0 (extra safety) */ dst->s = 0; } @@ -893,57 +877,62 @@ int fake_req_clone_str_helper(str *src, str *dst, char *txt) /** * fake a private sip message using transaction's shared memory message */ -struct sip_msg * fake_req(struct sip_msg *shmem_msg, int extra_flags, - struct ua_client *uac, int *len) +struct sip_msg *fake_req(struct sip_msg *shmem_msg, int extra_flags, + struct ua_client *uac, int *len) { struct sip_msg *faked_req; /* make a clone so eventual new parsed headers in pkg are not visible * to other processes -- other attributes should be already parsed, * available in the req structure and propagated by cloning */ faked_req = sip_msg_shm_clone(shmem_msg, len, 1); - if(faked_req==NULL) { + if(faked_req == NULL) { LM_ERR("failed to clone the request\n"); return NULL; } /* if we set msg_id to something different from current's message * id, the first t_fork will properly clean new branch URIs */ - faked_req->id=shmem_msg->id-1; + faked_req->id = shmem_msg->id - 1; /* msg->parsed_uri_ok must be reset since msg_parsed_uri is * not cloned (and cannot be cloned) */ faked_req->parsed_uri_ok = 0; - faked_req->msg_flags|=extra_flags; /* set the extra tm flags */ + faked_req->msg_flags |= extra_flags; /* set the extra tm flags */ /* path_vec was cloned in shm and can change -- make a private copy */ - if(fake_req_clone_str_helper(&shmem_msg->path_vec, &faked_req->path_vec, - "path_vec")<0) { + if(fake_req_clone_str_helper( + &shmem_msg->path_vec, &faked_req->path_vec, "path_vec") + < 0) { goto error00; } /* dst_uri was cloned in shm and can change -- make a private copy */ - if(fake_req_clone_str_helper(&shmem_msg->dst_uri, &faked_req->dst_uri, - "dst_uri")<0) { + if(fake_req_clone_str_helper( + &shmem_msg->dst_uri, &faked_req->dst_uri, "dst_uri") + < 0) { goto error01; } /* new_uri was cloned in shm and can change -- make a private copy */ - if(fake_req_clone_str_helper(&shmem_msg->new_uri, &faked_req->new_uri, - "new_uri")<0) { + if(fake_req_clone_str_helper( + &shmem_msg->new_uri, &faked_req->new_uri, "new_uri") + < 0) { goto error02; } - if(uac) setbflagsval(0, uac->branch_flags); - else setbflagsval(0, 0); + if(uac) + setbflagsval(0, uac->branch_flags); + else + setbflagsval(0, 0); return faked_req; error02: - if (faked_req->dst_uri.s) { + if(faked_req->dst_uri.s) { pkg_free(faked_req->dst_uri.s); faked_req->dst_uri.s = 0; faked_req->dst_uri.len = 0; } error01: - if (faked_req->path_vec.s) { + if(faked_req->path_vec.s) { pkg_free(faked_req->path_vec.s); faked_req->path_vec.s = 0; faked_req->path_vec.len = 0; @@ -957,29 +946,29 @@ void free_faked_req(struct sip_msg *faked_req, int len) { struct hdr_field *hdr; void *mstart = faked_req; - void *mend =((char *) faked_req) + len; + void *mend = ((char *)faked_req) + len; reset_new_uri(faked_req); reset_dst_uri(faked_req); /* free all types of lump that were added in failure handlers */ - del_nonshm_lump( &(faked_req->add_rm) ); - del_nonshm_lump( &(faked_req->body_lumps) ); - del_nonshm_lump_rpl( &(faked_req->reply_lump) ); + del_nonshm_lump(&(faked_req->add_rm)); + del_nonshm_lump(&(faked_req->body_lumps)); + del_nonshm_lump_rpl(&(faked_req->reply_lump)); /* free header's parsed structures that were added by failure handlers */ - for( hdr=faked_req->headers ; hdr ; hdr=hdr->next ) { - if ( hdr->parsed && hdr_allocs_parse(hdr) && - (hdr->parsedparsed>=mend)) { + for(hdr = faked_req->headers; hdr; hdr = hdr->next) { + if(hdr->parsed && hdr_allocs_parse(hdr) + && (hdr->parsed < mstart || hdr->parsed >= mend)) { /* header parsed filed doesn't point inside fake memory * chunck -> it was added by failure funcs.-> free it as pkg */ - LM_DBG("removing hdr->parsed %d\n", hdr->type); + LM_DBG("removing hdr->parsed %d\n", hdr->type); clean_hdr_field(hdr); hdr->parsed = 0; } } /* free parsed body added by failure handlers */ - if (faked_req->body) { + if(faked_req->body) { if(faked_req->body->free) faked_req->body->free(&faked_req->body); faked_req->body = 0; @@ -1000,8 +989,8 @@ void free_faked_req(struct sip_msg *faked_req, int len) * 0 - if unable to process failure_route * -1 - if execution was long and transaction is gone */ -int run_failure_handlers(tm_cell_t *t, struct sip_msg *rpl, - int code, int extra_flags) +int run_failure_handlers( + tm_cell_t *t, struct sip_msg *rpl, int code, int extra_flags) { struct sip_msg *faked_req; int faked_req_len = 0; @@ -1020,28 +1009,28 @@ int run_failure_handlers(tm_cell_t *t, struct sip_msg *rpl, t_label = t->label; /* failure_route for a local UAC? */ - if (!shmem_msg) { + if(!shmem_msg) { LM_WARN("no UAC support (%d, %d) \n", on_failure, t->tmcb_hl.reg_types); return 0; } /* don't start faking anything if we don't have to */ - if (unlikely(!on_failure && !has_tran_tmcbs( t, TMCB_ON_FAILURE))) { + if(unlikely(!on_failure && !has_tran_tmcbs(t, TMCB_ON_FAILURE))) { LM_WARN("no failure handler (%d, %d)\n", on_failure, t->tmcb_hl.reg_types); return 1; } - faked_req = fake_req(shmem_msg, extra_flags, &t->uac[picked_branch], - &faked_req_len); - if (faked_req==NULL) { + faked_req = fake_req( + shmem_msg, extra_flags, &t->uac[picked_branch], &faked_req_len); + if(faked_req == NULL) { LM_ERR("fake_req failed\n"); return 0; } /* 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 */ - if (unlikely(has_tran_tmcbs(t, TMCB_ON_FAILURE))) { + if(unlikely(has_tran_tmcbs(t, TMCB_ON_FAILURE))) { if(tm_exec_time_check > 0) { gettimeofday(&tvb, NULL); } @@ -1049,38 +1038,41 @@ int run_failure_handlers(tm_cell_t *t, struct sip_msg *rpl, if(tm_exec_time_check > 0) { gettimeofday(&tve, NULL); tvd = ((unsigned long)(tve.tv_sec - tvb.tv_sec)) * 1000000 - + (tve.tv_usec - tvb.tv_usec); + + (tve.tv_usec - tvb.tv_usec); if(tvd >= tm_exec_time_check) { - LM_WARN("failure callbacks execution took too long: %lu us\n", tvd); + LM_WARN("failure callbacks execution took too long: %lu us\n", + tvd); t0 = t_find_ident_filter(t_hash_index, t_label, 0); - if(t0==NULL || t0 != t) { + if(t0 == NULL || t0 != t) { LM_WARN("transaction %p missing - found %p\n", t, t0); goto tgone; } } } } - if (on_failure) { + if(on_failure) { /* avoid recursion -- if failure_route forwards, and does not * set next failure route, failure_route will not be reentered * on failure */ - t->on_failure=0; + t->on_failure = 0; /* if continuing on timeout of a suspended transaction, reset the flag */ t->flags &= ~T_ASYNC_SUSPENDED; if(tm_exec_time_check > 0) { gettimeofday(&tvb, NULL); } log_prefix_set(faked_req); - if (exec_pre_script_cb(faked_req, FAILURE_CB_TYPE)>0) { + if(exec_pre_script_cb(faked_req, FAILURE_CB_TYPE) > 0) { /* run a failure_route action if some was marked */ keng = sr_kemi_eng_get(); - if(unlikely(keng!=NULL)) { + if(unlikely(keng != NULL)) { if(sr_kemi_route(keng, faked_req, FAILURE_ROUTE, - sr_kemi_cbname_lookup_idx(on_failure), NULL)<0) { + sr_kemi_cbname_lookup_idx(on_failure), NULL) + < 0) { LM_ERR("error running failure route kemi callback\n"); } } else { - if (run_top_route(failure_rt.rlist[on_failure], faked_req, 0)<0) + if(run_top_route(failure_rt.rlist[on_failure], faked_req, 0) + < 0) LM_ERR("error running run_top_route for failure handler\n"); } exec_post_script_cb(faked_req, FAILURE_CB_TYPE); @@ -1089,11 +1081,11 @@ int run_failure_handlers(tm_cell_t *t, struct sip_msg *rpl, if(tm_exec_time_check > 0) { gettimeofday(&tve, NULL); tvd = ((unsigned long)(tve.tv_sec - tvb.tv_sec)) * 1000000 - + (tve.tv_usec - tvb.tv_usec); + + (tve.tv_usec - tvb.tv_usec); if(tvd >= tm_exec_time_check) { LM_WARN("failure route execution took too long: %lu us\n", tvd); t0 = t_find_ident_filter(t_hash_index, t_label, 0); - if(t0==NULL || t0 != t) { + if(t0 == NULL || t0 != t) { LM_WARN("transaction %p missing - found %p\n", t, t0); goto tgone; } @@ -1121,8 +1113,8 @@ int run_failure_handlers(tm_cell_t *t, struct sip_msg *rpl, /* return 1 if a failure_route processes */ -int run_branch_failure_handlers(struct cell *t, struct sip_msg *rpl, - int code, int extra_flags) +int run_branch_failure_handlers( + struct cell *t, struct sip_msg *rpl, int code, int extra_flags) { struct sip_msg *faked_req; int faked_req_len = 0; @@ -1133,48 +1125,51 @@ int run_branch_failure_handlers(struct cell *t, struct sip_msg *rpl, on_branch_failure = t->uac[picked_branch].on_branch_failure; /* failure_route for a local UAC? */ - if (!shmem_msg) { - LM_WARN("no UAC support (%d, %d) \n", - on_branch_failure, t->tmcb_hl.reg_types); + if(!shmem_msg) { + LM_WARN("no UAC support (%d, %d) \n", on_branch_failure, + t->tmcb_hl.reg_types); return 0; } /* don't start faking anything if we don't have to */ - if (unlikely((on_branch_failure < 0) - && !has_tran_tmcbs( t, TMCB_ON_BRANCH_FAILURE))) { - LM_WARN("no branch_failure handler (%d, %d)\n", - on_branch_failure, t->tmcb_hl.reg_types); + if(unlikely((on_branch_failure < 0) + && !has_tran_tmcbs(t, TMCB_ON_BRANCH_FAILURE))) { + LM_WARN("no branch_failure handler (%d, %d)\n", on_branch_failure, + t->tmcb_hl.reg_types); return 1; } - faked_req = fake_req(shmem_msg, extra_flags, &t->uac[picked_branch], - &faked_req_len); - if (faked_req==NULL) { + faked_req = fake_req( + shmem_msg, extra_flags, &t->uac[picked_branch], &faked_req_len); + if(faked_req == NULL) { LM_ERR("fake_req failed\n"); return 0; } /* fake also the env. conforming to the fake msg */ - faked_env( t, faked_req, 0); + faked_env(t, faked_req, 0); set_route_type(BRANCH_FAILURE_ROUTE); set_t(t, picked_branch); /* DONE with faking ;-) -> run the branch_failure handlers */ - if (unlikely(has_tran_tmcbs( t, TMCB_ON_BRANCH_FAILURE)) ) { - run_trans_callbacks( TMCB_ON_BRANCH_FAILURE, t, faked_req, rpl, code); + if(unlikely(has_tran_tmcbs(t, TMCB_ON_BRANCH_FAILURE))) { + run_trans_callbacks(TMCB_ON_BRANCH_FAILURE, t, faked_req, rpl, code); } - if (on_branch_failure >= 0) { + if(on_branch_failure >= 0) { t->on_branch_failure = 0; - if (exec_pre_script_cb(faked_req, BRANCH_FAILURE_CB_TYPE)>0) { + if(exec_pre_script_cb(faked_req, BRANCH_FAILURE_CB_TYPE) > 0) { /* run a branch_failure_route action if some was marked */ keng = sr_kemi_eng_get(); - if(unlikely(keng!=NULL)) { + if(unlikely(keng != NULL)) { if(sr_kemi_route(keng, faked_req, BRANCH_FAILURE_ROUTE, - sr_kemi_cbname_lookup_idx(on_branch_failure), NULL)<0) { - LM_ERR("error running branch failure route kemi callback\n"); + sr_kemi_cbname_lookup_idx(on_branch_failure), NULL) + < 0) { + LM_ERR("error running branch failure route kemi " + "callback\n"); } } else { - if (run_top_route(event_rt.rlist[on_branch_failure], - faked_req, 0)<0) + if(run_top_route( + event_rt.rlist[on_branch_failure], faked_req, 0) + < 0) LM_ERR("error in run_top_route\n"); } exec_post_script_cb(faked_req, BRANCH_FAILURE_CB_TYPE); @@ -1184,7 +1179,7 @@ int run_branch_failure_handlers(struct cell *t, struct sip_msg *rpl, } /* restore original environment */ - faked_env( t, 0, 0); + faked_env(t, 0, 0); /* if branch_failure handler changed flag, update transaction context */ shmem_msg->flags = faked_req->flags; /* free the fake msg */ @@ -1194,24 +1189,22 @@ int run_branch_failure_handlers(struct cell *t, struct sip_msg *rpl, } - /* 401, 407, 415, 420, and 484 have priority over the other 4xx*/ inline static short int get_4xx_prio(unsigned char xx) { - switch(xx){ - case 1: - case 7: + switch(xx) { + case 1: + case 7: case 15: case 20: case 84: return xx; break; } - return 100+xx; + return 100 + xx; } - /* returns response priority, lower number => highest prio * * responses priority val @@ -1230,15 +1223,16 @@ inline static short int get_prio(unsigned int resp, struct sip_msg *rpl) int xx; int prio; - class=resp/100; + class = resp / 100; - if (class<7){ - xx=resp%100; - prio = resp_class_prio[class]+((class==4)?get_4xx_prio(xx):xx); + if(class < 7) { + xx = resp % 100; + prio = resp_class_prio[class] + ((class == 4) ? get_4xx_prio(xx) : xx); } else { - prio = 10000+resp; /* unknown response class => return very low prio */ + prio = 10000 + + resp; /* unknown response class => return very low prio */ } - if (rpl == FAKED_REPLY) { + if(rpl == FAKED_REPLY) { /* Add faked_reply penalty */ return prio + faked_reply_prio; } else { @@ -1247,7 +1241,6 @@ inline static short int get_prio(unsigned int resp, struct sip_msg *rpl) } - /* select a branch for forwarding; returns: * 0..X ... branch number * -1 ... error @@ -1258,40 +1251,43 @@ int t_pick_branch(int inc_branch, int inc_code, struct cell *t, int *res_code) int best_b, best_s, b; sip_msg_t *rpl, *best_rpl; - best_b=-1; best_s=0; - best_rpl=NULL; - for ( b=0; bnr_of_outgoings ; b++ ) { + best_b = -1; + best_s = 0; + best_rpl = NULL; + for(b = 0; b < t->nr_of_outgoings; b++) { rpl = t->uac[b].reply; /* "fake" for the currently processed branch */ - if (b==inc_branch) { - if (get_prio(inc_code, rpl)uac[b].request.buffer) && (t->uac[b].last_received>=200)) + if((!t->uac[b].request.buffer) && (t->uac[b].last_received >= 200)) continue; /* there is still an unfinished UAC transaction (we ignore unfinished * blind UACs) wait now! */ - if ( t->uac[b].last_received<200 && !((t->flags&T_ASYNC_CONTINUE) - && b==t->async_backup.blind_uac)) + if(t->uac[b].last_received < 200 + && !((t->flags & T_ASYNC_CONTINUE) + && b == t->async_backup.blind_uac)) return -2; /* if reply is null => t_send_branch "faked" reply, skip over it */ - if ( rpl && - get_prio(t->uac[b].last_received, rpl)uac[b].last_received, rpl) + < get_prio(best_s, best_rpl)) { + best_b = b; best_s = t->uac[b].last_received; - best_rpl=rpl; + best_rpl = rpl; } } /* find lowest branch */ - *res_code=best_s; + *res_code = best_s; return best_b; } @@ -1310,21 +1306,23 @@ int t_pick_branch_blind(struct cell *t, int *res_code) int best_b, best_s, b; sip_msg_t *rpl; - best_b=-1; best_s=0; - for ( b=0; bnr_of_outgoings ; b++ ) { + best_b = -1; + best_s = 0; + for(b = 0; b < t->nr_of_outgoings; b++) { /* there is still an unfinished UAC transaction; wait now! */ - if ( t->uac[b].last_received<200 ) + if(t->uac[b].last_received < 200) return -2; /* if reply is null => t_send_branch "faked" reply, skip over it */ rpl = t->uac[b].reply; - if ( rpl && - get_prio(t->uac[b].last_received, rpl)uac[b].last_received, rpl) + < get_prio(best_s, rpl)) { best_b = b; best_s = t->uac[b].last_received; } } /* find lowest branch */ - *res_code=best_s; + *res_code = best_s; return best_b; } @@ -1346,9 +1344,9 @@ static unsigned char drop_replies; * -1 if nothing to be relayed * WARNING: cancel_data should be initialized prior to calling this function. */ -static enum rps t_should_relay_response( struct cell *Trans , int new_code, - int branch , int *should_store, int *should_relay, - struct cancel_info *cancel_data, struct sip_msg *reply ) +static enum rps t_should_relay_response(struct cell *Trans, int new_code, + int branch, int *should_store, int *should_relay, + struct cancel_info *cancel_data, struct sip_msg *reply) { int branch_cnt; int picked_code; @@ -1363,15 +1361,15 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, * not relayed because it's not an INVITE transaction; * >= 300 are not relayed because 200 was already sent out */ - LM_DBG("->>>>>>>>> T_code=%d, new_code=%d\n", Trans->uas.status,new_code); - inv_through=new_code>=200 && new_code<300 && is_invite(Trans); + LM_DBG("->>>>>>>>> T_code=%d, new_code=%d\n", Trans->uas.status, new_code); + inv_through = new_code >= 200 && new_code < 300 && is_invite(Trans); /* if final response sent out, allow only INVITE 2xx */ - if ( Trans->uas.status >= 200 ) { - if (inv_through) { + if(Trans->uas.status >= 200) { + if(inv_through) { LM_DBG("200 INV after final sent\n"); - *should_store=0; - Trans->uac[branch].last_received=new_code; - *should_relay=branch; + *should_store = 0; + Trans->uac[branch].last_received = new_code; + *should_relay = branch; return RPS_PUSHED_AFTER_COMPLETION; } else { LM_DBG("final reply already sent\n"); @@ -1381,77 +1379,79 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, } /* if final response received at this branch, allow only INVITE 2xx */ - if (Trans->uac[branch].last_received>=200 - && !(inv_through && Trans->uac[branch].last_received<300)) { + if(Trans->uac[branch].last_received >= 200 + && !(inv_through && Trans->uac[branch].last_received < 300)) { /* don't report on retransmissions */ - if (Trans->uac[branch].last_received==new_code) { + if(Trans->uac[branch].last_received == new_code) { LM_DBG("final reply retransmission\n"); goto discard; } /* if you FR-timed-out, faked a local 408 and 487 came or * faked a CANCEL on a non-replied branch don't * report on it either */ - if ((Trans->uac[branch].last_received==487) || - (Trans->uac[branch].last_received==408 && new_code==487)) { - LM_DBG("%d came for a %d branch (ignored)\n", - new_code, Trans->uac[branch].last_received); + if((Trans->uac[branch].last_received == 487) + || (Trans->uac[branch].last_received == 408 + && new_code == 487)) { + LM_DBG("%d came for a %d branch (ignored)\n", new_code, + Trans->uac[branch].last_received); goto discard; } /* this looks however how a very strange status rewrite attempt; * report on it */ LM_WARN("status rewrite by UAS: stored: %d, received: %d\n", - Trans->uac[branch].last_received, new_code); + Trans->uac[branch].last_received, new_code); goto discard; } /* no final response sent yet */ /* negative replies subject to fork picking */ - if (new_code >=300 ) { + if(new_code >= 300) { - Trans->uac[branch].last_received=new_code; + Trans->uac[branch].last_received = new_code; /* also append the current reply to the transaction to * make it available in failure routes - a kind of "fake" * save of the final reply per branch */ - if (unlikely(has_tran_tmcbs(Trans, - TMCB_ON_BRANCH_FAILURE_RO|TMCB_ON_BRANCH_FAILURE) - || (Trans->uac[branch].on_branch_failure) )) { + if(unlikely(has_tran_tmcbs(Trans, + TMCB_ON_BRANCH_FAILURE_RO | TMCB_ON_BRANCH_FAILURE) + || (Trans->uac[branch].on_branch_failure))) { Trans->uac[branch].reply = reply; - extra_flags= - ((Trans->uac[branch].request.flags & F_RB_TIMEOUT)? - FL_TIMEOUT:0) | - ((Trans->uac[branch].request.flags & F_RB_REPLIED)? - FL_REPLIED:0); + extra_flags = ((Trans->uac[branch].request.flags & F_RB_TIMEOUT) + ? FL_TIMEOUT + : 0) + | ((Trans->uac[branch].request.flags & F_RB_REPLIED) + ? FL_REPLIED + : 0); tm_ctx_set_branch_index(branch); picked_branch = branch; - run_branch_failure_handlers( Trans, Trans->uac[branch].reply, - new_code, extra_flags); + run_branch_failure_handlers( + Trans, Trans->uac[branch].reply, new_code, extra_flags); /* Don't do reset the reply if we are in a resume route, * we need to free it at the end of the continue processing */ - if (!(Trans->flags&T_ASYNC_CONTINUE)) + if(!(Trans->flags & T_ASYNC_CONTINUE)) Trans->uac[branch].reply = 0; } /* if all_final return lowest */ - picked_branch=t_pick_branch(branch,new_code, Trans, &picked_code); - if (picked_branch==-2) { /* branches open yet */ - *should_store=1; - *should_relay=-1; - if (new_code>=600 && new_code<=699){ - if (!(Trans->flags & (T_6xx | T_DISABLE_6xx))){ + picked_branch = t_pick_branch(branch, new_code, Trans, &picked_code); + if(picked_branch == -2) { /* branches open yet */ + *should_store = 1; + *should_relay = -1; + if(new_code >= 600 && new_code <= 699) { + if(!(Trans->flags & (T_6xx | T_DISABLE_6xx))) { /* cancel only the first time we get a 6xx and only * if the 6xx handling is not disabled */ prepare_to_cancel(Trans, &cancel_data->cancel_bitmap, 0); - Trans->flags|=T_6xx; - cancel_data->reason.cause=new_code; + Trans->flags |= T_6xx; + cancel_data->reason.cause = new_code; } } LM_DBG("store - other branches still active\n"); return RPS_STORE; } - if (picked_branch==-1) { + if(picked_branch == -1) { LM_CRIT("error -- lowest==-1\n"); goto error; } @@ -1459,47 +1459,50 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, /* no more pending branches -- try if that changes after * a callback; save branch count to be able to determine * later if new branches were initiated */ - branch_cnt=Trans->nr_of_outgoings; + branch_cnt = Trans->nr_of_outgoings; /* also append the current reply to the transaction to * make it available in failure routes - a kind of "fake" * save of the final reply per branch */ Trans->uac[branch].reply = reply; - Trans->flags&=~T_6xx; /* clear the 6xx flag , we want to + Trans->flags &= ~T_6xx; /* clear the 6xx flag , we want to * allow new branches from the failure route */ drop_replies = failure_reply_mode; replies_dropped = 0; tm_ctx_set_branch_index(picked_branch); /* run ON_FAILURE handlers ( route and callbacks) */ - if (unlikely(has_tran_tmcbs( Trans, TMCB_ON_FAILURE_RO|TMCB_ON_FAILURE) - || Trans->uac[picked_branch].on_failure )) { - extra_flags= - ((Trans->uac[picked_branch].request.flags & F_RB_TIMEOUT)? - FL_TIMEOUT:0) | - ((Trans->uac[picked_branch].request.flags & F_RB_REPLIED)? - FL_REPLIED:0); + if(unlikely(has_tran_tmcbs(Trans, TMCB_ON_FAILURE_RO | TMCB_ON_FAILURE) + || Trans->uac[picked_branch].on_failure)) { + extra_flags = + ((Trans->uac[picked_branch].request.flags & F_RB_TIMEOUT) + ? FL_TIMEOUT + : 0) + | ((Trans->uac[picked_branch].request.flags & F_RB_REPLIED) + ? FL_REPLIED + : 0); tm_ctx_set_branch_index(picked_branch); if(run_failure_handlers(Trans, Trans->uac[picked_branch].reply, - picked_code, extra_flags) == -1) { + picked_code, extra_flags) + == -1) { /* transaction gone */ goto tgone; } - if (unlikely((drop_replies==3 && branch_cntnr_of_outgoings) - || (drop_replies!=0 && drop_replies!=3)) - ) { + if(unlikely((drop_replies == 3 + && branch_cnt < Trans->nr_of_outgoings) + || (drop_replies != 0 && drop_replies != 3))) { /* drop all the replies that we have already saved */ i = 0; - if(drop_replies==2) - { - for(i=branch_cnt-1; i>=0; i--) - if(Trans->uac[i].flags&TM_UAC_FLAG_FB) + if(drop_replies == 2) { + for(i = branch_cnt - 1; i >= 0; i--) + if(Trans->uac[i].flags & TM_UAC_FLAG_FB) break; - if(i<0) i=0; + if(i < 0) + i = 0; } - for (; iuac[i].reply && - (Trans->uac[i].reply != FAKED_REPLY) && - (Trans->uac[i].reply->msg_flags & FL_SHM_CLONE)) + for(; i < branch_cnt; i++) { + if(Trans->uac[i].reply + && (Trans->uac[i].reply != FAKED_REPLY) + && (Trans->uac[i].reply->msg_flags & FL_SHM_CLONE)) /* we have to drop the reply * which is already in shm mem */ sip_msg_free(Trans->uac[i].reply); @@ -1518,7 +1521,7 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, * transaction some broken reference. Don't do it if we * are in a resume route, we need to free it at the end * of the continue processing */ - if (!(Trans->flags&T_ASYNC_CONTINUE)) + if(!(Trans->flags & T_ASYNC_CONTINUE)) Trans->uac[branch].reply = 0; /* look if the callback perhaps replied transaction; it also @@ -1526,9 +1529,9 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, * on CANCEL -- then it would make no sense to proceed to * new branches below */ - if (Trans->uas.status >= 200) { - *should_store=0; - *should_relay=-1; + if(Trans->uas.status >= 200) { + *should_store = 0; + *should_relay = -1; /* this might deserve an improvement -- if something * was already replied, it was put on wait and then, * returning RPS_COMPLETED will make t_on_reply @@ -1539,32 +1542,32 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, return RPS_COMPLETED; } /* look if the callback/failure_route introduced new branches ... */ - if (branch_cntnr_of_outgoings){ + if(branch_cnt < Trans->nr_of_outgoings) { /* the new branches might be already "finished" => we * must use t_pick_branch again */ - new_branch=t_pick_branch((replies_dropped==0)? - branch : - -1, /* make sure we do not pick + new_branch = t_pick_branch((replies_dropped == 0) + ? branch + : -1, /* make sure we do not pick the current branch */ - new_code, - Trans, - &picked_code); - - if (new_branch<0){ - if (likely(replies_dropped==0)) { - if (new_branch==-2) { /* branches open yet */ - *should_store=1; - *should_relay=-1; - LM_DBG("rps store - uas status: %d\n", Trans->uas.status); + new_code, Trans, &picked_code); + + if(new_branch < 0) { + if(likely(replies_dropped == 0)) { + if(new_branch == -2) { /* branches open yet */ + *should_store = 1; + *should_relay = -1; + LM_DBG("rps store - uas status: %d\n", + Trans->uas.status); return RPS_STORE; } /* error, use the old picked_branch */ } else { - if (new_branch==-2) { /* branches open yet */ + if(new_branch == -2) { /* branches open yet */ /* we are not allowed to relay the reply */ - *should_store=0; - *should_relay=-1; - LM_DBG("rps discarded - uas status: %d\n", Trans->uas.status); + *should_store = 0; + *should_relay = -1; + LM_DBG("rps discarded - uas status: %d\n", + Trans->uas.status); return RPS_DISCARDED; } else { /* There are no open branches, @@ -1575,11 +1578,11 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, goto branches_failed; } } - }else{ + } else { /* found a new_branch */ - picked_branch=new_branch; + picked_branch = new_branch; } - } else if (unlikely(replies_dropped)) { + } else if(unlikely(replies_dropped)) { /* Either the script writer did not add new branches after calling t_drop_replies(), or tm was unable to add the new branches to the transaction. */ @@ -1587,29 +1590,33 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, } /* really no more pending branches -- return lowest code */ - *should_store=0; - *should_relay=picked_branch; + *should_store = 0; + *should_relay = picked_branch; /* we dont need 'prepare_to_cancel' here -- all branches * known to have completed */ /* prepare_to_cancel( Trans, cancel_bitmap, 0 ); */ - LM_DBG("rps completed - uas status: %d branch: %d\n", - Trans->uas.status, picked_branch); + LM_DBG("rps completed - uas status: %d branch: %d\n", Trans->uas.status, + picked_branch); return RPS_COMPLETED; } /* not >=300 ... it must be 2xx or provisional 1xx */ - if (new_code>=100) { - /* need a copy of the message for ACK generation */ - *should_store = (inv_through && is_local(Trans) && - (Trans->uac[branch].last_received < 200) && - (Trans->flags & T_NO_AUTO_ACK)) ? 1 : 0; + if(new_code >= 100) { + /* need a copy of the message for ACK generation */ + *should_store = (inv_through && is_local(Trans) + && (Trans->uac[branch].last_received < 200) + && (Trans->flags & T_NO_AUTO_ACK)) + ? 1 + : 0; /* By default, 1xx and 2xx (except 100) will be relayed. 100 relaying can be * controlled via relay_100 parameter */ - Trans->uac[branch].last_received=new_code; - *should_relay= (new_code==100 && !cfg_get(tm, tm_cfg, relay_100)) ? -1 : branch; - if (new_code>=200 ) { - prepare_to_cancel( Trans, &cancel_data->cancel_bitmap, 0); - cancel_data->reason.cause=new_code; + Trans->uac[branch].last_received = new_code; + *should_relay = (new_code == 100 && !cfg_get(tm, tm_cfg, relay_100)) + ? -1 + : branch; + if(new_code >= 200) { + prepare_to_cancel(Trans, &cancel_data->cancel_bitmap, 0); + cancel_data->reason.cause = new_code; LM_DBG("rps completed - uas status: %d\n", Trans->uas.status); return RPS_COMPLETED; } else { @@ -1620,31 +1627,30 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, error: /* reply_status didn't match -- it must be something weird */ - LM_CRIT("error - unable to decide whether to relay %d\n", - new_code); + LM_CRIT("error - unable to decide whether to relay %d\n", new_code); discard: - *should_store=0; - *should_relay=-1; + *should_store = 0; + *should_relay = -1; LM_DBG("finished with rps discarded - uas status: %d\n", Trans->uas.status); return RPS_DISCARDED; tgone: - *should_store=0; - *should_relay=-1; + *should_store = 0; + *should_relay = -1; LM_DBG("finished with transaction gone\n"); return RPS_TGONE; branches_failed: - *should_store=0; - if (is_local(Trans)){ + *should_store = 0; + if(is_local(Trans)) { /* for local transactions use the current reply */ - *should_relay=branch; - }else{ - *should_relay=-1; + *should_relay = branch; + } else { + *should_relay = -1; /* We have hopefully set tm_error in failure_route when the branches failed. If not, reply with E_UNSPEC */ - if ((kill_transaction_unsafe(Trans, - tm_error ? tm_error : E_UNSPEC)) <=0 ){ + if((kill_transaction_unsafe(Trans, tm_error ? tm_error : E_UNSPEC)) + <= 0) { LM_ERR("reply generation failed\n"); } } @@ -1657,7 +1663,7 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code, * Returns -1 - error * 1 - OK */ -int t_retransmit_reply( struct cell *t ) +int t_retransmit_reply(struct cell *t) { static char b[BUF_SIZE]; int len; @@ -1672,7 +1678,7 @@ int t_retransmit_reply( struct cell *t ) * If reply_to_via is set and via contains a host name (and not an ip) * the chances for this increase a lot. */ - if (!t->uas.response.dst.send_sock) { + if(!t->uas.response.dst.send_sock) { LOG(L_WARN, "no resolved dst to retransmit\n"); return -1; } @@ -1680,31 +1686,31 @@ int t_retransmit_reply( struct cell *t ) /* we need to lock the transaction as messages from * upstream may change it continuously */ - LOCK_REPLIES( t ); + LOCK_REPLIES(t); - if (!t->uas.response.buffer) { + if(!t->uas.response.buffer) { DBG("nothing to retransmit\n"); goto error; } - len=t->uas.response.buffer_len; - if ( len==0 || len>BUF_SIZE ) { + len = t->uas.response.buffer_len; + if(len == 0 || len > BUF_SIZE) { DBG("zero length or too big to retransmit: %d\n", len); goto error; } - memcpy( b, t->uas.response.buffer, len ); - UNLOCK_REPLIES( t ); - if(SEND_PR_BUFFER( & t->uas.response, b, len )<0) { + memcpy(b, t->uas.response.buffer, len); + UNLOCK_REPLIES(t); + if(SEND_PR_BUFFER(&t->uas.response, b, len) < 0) { LM_WARN("send pr buffer failed\n"); } - if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))){ + if(unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT))) { /* we don't know if it's a retransmission of a local reply or a * forwarded reply */ - run_trans_callbacks_with_buf(TMCB_RESPONSE_SENT, &t->uas.response, - 0, 0, TMCB_RETR_F); + run_trans_callbacks_with_buf( + TMCB_RESPONSE_SENT, &t->uas.response, 0, 0, TMCB_RETR_F); } - LM_DBG("reply retransmitted. buf=%p: %.9s..., shmem=%p: %.9s\n", - b, b, t->uas.response.buffer, t->uas.response.buffer ); + LM_DBG("reply retransmitted. buf=%p: %.9s..., shmem=%p: %.9s\n", b, b, + t->uas.response.buffer, t->uas.response.buffer); return 1; error: @@ -1713,143 +1719,143 @@ int t_retransmit_reply( struct cell *t ) } - -int t_reply( struct cell *t, struct sip_msg* p_msg, unsigned int code, - char * text ) +int t_reply( + struct cell *t, struct sip_msg *p_msg, unsigned int code, char *text) { str reason; reason.s = text; reason.len = strlen(text); - return _reply( t, p_msg, code, &reason, 1 /* lock replies */ ); + return _reply(t, p_msg, code, &reason, 1 /* lock replies */); } -int t_reply_str( struct cell *t, struct sip_msg* p_msg, unsigned int code, - str* reason) +int t_reply_str( + struct cell *t, struct sip_msg *p_msg, unsigned int code, str *reason) { - return _reply( t, p_msg, code, reason, 1 /* lock replies */ ); + return _reply(t, p_msg, code, reason, 1 /* lock replies */); } -int t_reply_unsafe( struct cell *t, struct sip_msg* p_msg, unsigned int code, - char * text ) +int t_reply_unsafe( + struct cell *t, struct sip_msg *p_msg, unsigned int code, char *text) { str reason; reason.s = text; reason.len = strlen(text); - return _reply( t, p_msg, code, &reason, 0 /* don't lock replies */ ); + return _reply(t, p_msg, code, &reason, 0 /* don't lock replies */); } -int t_reply_str_unsafe( struct cell *t, struct sip_msg* p_msg, unsigned int code, - str* reason) +int t_reply_str_unsafe( + struct cell *t, struct sip_msg *p_msg, unsigned int code, str *reason) { - return _reply( t, p_msg, code, reason, 0 /* don't lock replies */ ); + return _reply(t, p_msg, code, reason, 0 /* don't lock replies */); } -void set_final_timer( struct cell *t ) +void set_final_timer(struct cell *t) { start_final_repl_retr(t); put_on_wait(t); } -void cleanup_uac_timers( struct cell *t ) +void cleanup_uac_timers(struct cell *t) { int i; /* reset FR/retransmission timers */ - for (i=0; inr_of_outgoings; i++ ){ + for(i = 0; i < t->nr_of_outgoings; i++) { stop_rb_timers(&t->uac[i].request); } LM_DBG("RETR/FR timers reset\n"); } -static int store_reply( struct cell *trans, int branch, struct sip_msg *rpl) +static int store_reply(struct cell *trans, int branch, struct sip_msg *rpl) { -# ifdef EXTRA_DEBUG - if (trans->uac[branch].reply) { - LM_ERR("replacing stored reply; aborting\n"); - abort(); - } -# endif +#ifdef EXTRA_DEBUG + if(trans->uac[branch].reply) { + LM_ERR("replacing stored reply; aborting\n"); + abort(); + } +#endif - /* when we later do things such as challenge aggregation, + /* when we later do things such as challenge aggregation, * we should parse the message here before we conserve * it in shared memory; -jiri */ - if (rpl==FAKED_REPLY) - trans->uac[branch].reply=FAKED_REPLY; - else - trans->uac[branch].reply = sip_msg_cloner( rpl, 0 ); + if(rpl == FAKED_REPLY) + trans->uac[branch].reply = FAKED_REPLY; + else + trans->uac[branch].reply = sip_msg_cloner(rpl, 0); - if (! trans->uac[branch].reply ) { - LM_ERR("can't alloc' clone memory\n"); - return 0; - } + if(!trans->uac[branch].reply) { + LM_ERR("can't alloc' clone memory\n"); + return 0; + } - return 1; + return 1; } - /* returns the number of authenticate replies (401 and 407) received so far * (FAKED_REPLYes are excluded) * It must be called with the REPLY_LOCK held */ -inline static int auth_reply_count(struct cell *t, struct sip_msg* crt_reply) +inline static int auth_reply_count(struct cell *t, struct sip_msg *crt_reply) { int count; int r; - count=0; - if (crt_reply && (crt_reply!=FAKED_REPLY) && - (crt_reply->REPLY_STATUS ==401 || crt_reply->REPLY_STATUS ==407)) - count=1; - for (r=0; rnr_of_outgoings; r++){ - if (t->uac[r].reply && (t->uac[r].reply!=FAKED_REPLY) && - (t->uac[r].last_received==401 || t->uac[r].last_received==407)) + count = 0; + if(crt_reply && (crt_reply != FAKED_REPLY) + && (crt_reply->REPLY_STATUS == 401 + || crt_reply->REPLY_STATUS == 407)) + count = 1; + for(r = 0; r < t->nr_of_outgoings; r++) { + if(t->uac[r].reply && (t->uac[r].reply != FAKED_REPLY) + && (t->uac[r].last_received == 401 + || t->uac[r].last_received == 407)) count++; } return count; } - /* must be called with the REPY_LOCK held */ -inline static char* reply_aggregate_auth(int code, char* txt, str* new_tag, - struct cell* t, unsigned int* res_len, - struct bookmark* bm) +inline static char *reply_aggregate_auth(int code, char *txt, str *new_tag, + struct cell *t, unsigned int *res_len, struct bookmark *bm) { int r; - struct hdr_field* hdr; - struct lump_rpl** first; - struct lump_rpl** crt; - struct lump_rpl* lst; - struct lump_rpl* lst_end; - struct sip_msg* req; - char* buf; + struct hdr_field *hdr; + struct lump_rpl **first; + struct lump_rpl **crt; + struct lump_rpl *lst; + struct lump_rpl *lst_end; + struct sip_msg *req; + char *buf; str reason; - first=0; - lst_end=0; - req=t->uas.request; - - for (r=0; rnr_of_outgoings; r++){ - if (t->uac[r].reply && (t->uac[r].reply!=FAKED_REPLY) && - (t->uac[r].last_received==401 || t->uac[r].last_received==407)){ - for (hdr=t->uac[r].reply->headers; hdr; hdr=hdr->next){ - if (hdr->type==HDR_WWW_AUTHENTICATE_T || - hdr->type==HDR_PROXY_AUTHENTICATE_T){ - crt=add_lump_rpl2(req, hdr->name.s, hdr->len, - LUMP_RPL_HDR|LUMP_RPL_NODUP|LUMP_RPL_NOFREE); - if (crt==0){ + first = 0; + lst_end = 0; + req = t->uas.request; + + for(r = 0; r < t->nr_of_outgoings; r++) { + if(t->uac[r].reply && (t->uac[r].reply != FAKED_REPLY) + && (t->uac[r].last_received == 401 + || t->uac[r].last_received == 407)) { + for(hdr = t->uac[r].reply->headers; hdr; hdr = hdr->next) { + if(hdr->type == HDR_WWW_AUTHENTICATE_T + || hdr->type == HDR_PROXY_AUTHENTICATE_T) { + crt = add_lump_rpl2(req, hdr->name.s, hdr->len, + LUMP_RPL_HDR | LUMP_RPL_NODUP | LUMP_RPL_NOFREE); + if(crt == 0) { /* some kind of error, better stop */ LM_ERR("add_lump_rpl2 failed\n"); goto skip; } - lst_end=*crt; - if (first==0) first=crt; + lst_end = *crt; + if(first == 0) + first = crt; } } } @@ -1857,14 +1863,14 @@ inline static char* reply_aggregate_auth(int code, char* txt, str* new_tag, skip: reason.s = txt; reason.len = strlen(txt); - buf=build_res_buf_from_sip_req(code, &reason, new_tag, req, res_len, bm); + buf = build_res_buf_from_sip_req(code, &reason, new_tag, req, res_len, bm); /* clean the added lumps */ - if (first){ - lst=*first; - *first=lst_end->next; /* "detach" the list of added rpl_lumps */ - lst_end->next=0; /* terminate lst */ + if(first) { + lst = *first; + *first = lst_end->next; /* "detach" the list of added rpl_lumps */ + lst_end->next = 0; /* terminate lst */ del_nonshm_lump_rpl(&lst); - if (lst){ + if(lst) { LM_CRIT("rpl_lump list contains shm alloc'ed lumps\n"); abort(); } @@ -1873,7 +1879,6 @@ inline static char* reply_aggregate_auth(int code, char* txt, str* new_tag, } - /* this is the code which decides what and when shall be relayed * upstream; note well -- it assumes it is entered locked with * REPLY_LOCK and it returns unlocked! @@ -1884,9 +1889,9 @@ inline static char* reply_aggregate_auth(int code, char* txt, str* new_tag, * * WARNING: cancel_data should be initialized prior to calling this function. */ -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) { int relay; int save_clone; @@ -1901,155 +1906,158 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, enum rps reply_status; /* retransmission structure of outbound reply and request */ struct retr_buf *uas_rb; - str* to_tag; + str *to_tag; str reason; struct tmcb_params onsend_params; struct ip_addr ip; /* keep compiler warnings about use of uninit vars silent */ - res_len=0; - buf=0; - relayed_msg=0; - relayed_code=0; - totag_retr=0; + res_len = 0; + buf = 0; + relayed_msg = 0; + relayed_code = 0; + totag_retr = 0; /* remember, what was sent upstream to know whether we are * forwarding a first final reply or not */ /* *** store and relay message as needed *** */ - reply_status = t_should_relay_response(t, msg_status, branch, - &save_clone, &relay, cancel_data, p_msg); + reply_status = t_should_relay_response( + t, msg_status, branch, &save_clone, &relay, cancel_data, p_msg); if(reply_status == RPS_TGONE) { LM_DBG("reply handling failure - t is gone\n"); /* failure */ return RPS_TGONE; } - LM_DBG("reply status=%d branch=%d, save=%d, relay=%d icode=%d msg status=%u\n", - reply_status, branch, save_clone, relay, t->uac[branch].icode, msg_status); + LM_DBG("reply status=%d branch=%d, save=%d, relay=%d icode=%d msg " + "status=%u\n", + reply_status, branch, save_clone, relay, t->uac[branch].icode, + msg_status); /* store the message if needed */ - if (save_clone) { + if(save_clone) { /* save for later use, typically branch picking */ - if (!store_reply( t, branch, p_msg )) + if(!store_reply(t, branch, p_msg)) goto error01; } /* initialize for outbound reply */ uas_rb = &t->uas.response; - if (relay >= 0 ) { + if(relay >= 0) { /* only messages known to be relayed immediately will be * be called on; we do not evoke this callback on messages * stored in shmem -- they are fixed and one cannot change them * anyway */ - if (unlikely(msg_status<300 && branch==relay - && has_tran_tmcbs(t,TMCB_RESPONSE_FWDED)) ) { - run_trans_callbacks( TMCB_RESPONSE_FWDED, t, t->uas.request, - p_msg, msg_status ); + if(unlikely(msg_status < 300 && branch == relay + && has_tran_tmcbs(t, TMCB_RESPONSE_FWDED))) { + run_trans_callbacks( + TMCB_RESPONSE_FWDED, t, t->uas.request, p_msg, msg_status); } /* try building the outbound reply from either the current * or a stored message */ - relayed_msg = (branch==relay) ? p_msg : t->uac[relay].reply; - if (relayed_msg==FAKED_REPLY) { + relayed_msg = (branch == relay) ? p_msg : t->uac[relay].reply; + if(relayed_msg == FAKED_REPLY) { if(t->flags & T_CANCELED) { /* transaction canceled - send 487 */ relayed_code = 487; } else { - relayed_code = (branch==relay) - ? msg_status : t->uac[relay].last_received; + relayed_code = (branch == relay) ? msg_status + : t->uac[relay].last_received; } /* use to_tag from the original request, or if not present, * generate a new one */ - if (relayed_code>=180 && t->uas.request->to - && (get_to(t->uas.request)->tag_value.s==0 - || get_to(t->uas.request)->tag_value.len==0)) { - calc_crc_suffix( t->uas.request, tm_tag_suffix ); - to_tag=&tm_tag; + if(relayed_code >= 180 && t->uas.request->to + && (get_to(t->uas.request)->tag_value.s == 0 + || get_to(t->uas.request)->tag_value.len == 0)) { + calc_crc_suffix(t->uas.request, tm_tag_suffix); + to_tag = &tm_tag; } else { - to_tag=0; + to_tag = 0; } - if (cfg_get(tm, tm_cfg, tm_aggregate_auth) && - (relayed_code==401 || relayed_code==407) && - (auth_reply_count(t, p_msg)>1)){ + if(cfg_get(tm, tm_cfg, tm_aggregate_auth) + && (relayed_code == 401 || relayed_code == 407) + && (auth_reply_count(t, p_msg) > 1)) { /* aggregate 401 & 407 www & proxy authenticate headers in * a "FAKE" reply*/ /* temporarily "store" the current reply */ - reply_bak=t->uac[branch].reply; - t->uac[branch].reply=p_msg; - buf=reply_aggregate_auth(relayed_code, + reply_bak = t->uac[branch].reply; + t->uac[branch].reply = p_msg; + buf = reply_aggregate_auth(relayed_code, error_text(relayed_code), to_tag, t, &res_len, &bm); /* revert the temporary "store" reply above */ - t->uac[branch].reply=reply_bak; - }else{ + t->uac[branch].reply = reply_bak; + } else { reason.s = error_text(relayed_code); reason.len = strlen(reason.s); - buf = build_res_buf_from_sip_req( relayed_code, - &reason, to_tag, - t->uas.request, &res_len, &bm ); + buf = build_res_buf_from_sip_req(relayed_code, &reason, to_tag, + t->uas.request, &res_len, &bm); } } else { - relayed_code=relayed_msg->REPLY_STATUS; - if (relayed_code==503 && tm_remap_503_500){ + relayed_code = relayed_msg->REPLY_STATUS; + if(relayed_code == 503 && tm_remap_503_500) { /* replace a final 503 with a 500: * generate a "FAKE" reply and a new to_tag (for easier * debugging)*/ - relayed_msg=FAKED_REPLY; - if ((get_to(t->uas.request)->tag_value.s==0 - || get_to(t->uas.request)->tag_value.len==0)) { - calc_crc_suffix( t->uas.request, tm_tag_suffix ); - to_tag=&tm_tag; + relayed_msg = FAKED_REPLY; + if((get_to(t->uas.request)->tag_value.s == 0 + || get_to(t->uas.request)->tag_value.len == 0)) { + calc_crc_suffix(t->uas.request, tm_tag_suffix); + to_tag = &tm_tag; } else { - to_tag=0; + to_tag = 0; } /* don't relay a 503, replace it w/ 500 (rfc3261) */ reason.s = error_text(relayed_code); reason.len = strlen(reason.s); - buf=build_res_buf_from_sip_req(500, &reason, - to_tag, t->uas.request, &res_len, &bm); - relayed_code=500; - }else if (cfg_get(tm, tm_cfg, tm_aggregate_auth) && - (relayed_code==401 || relayed_code==407) && - (auth_reply_count(t, p_msg)>1)){ + buf = build_res_buf_from_sip_req( + 500, &reason, to_tag, t->uas.request, &res_len, &bm); + relayed_code = 500; + } else if(cfg_get(tm, tm_cfg, tm_aggregate_auth) + && (relayed_code == 401 || relayed_code == 407) + && (auth_reply_count(t, p_msg) > 1)) { /* aggregate 401 & 407 www & proxy authenticate headers in * a "FAKE" reply*/ - if ((get_to(t->uas.request)->tag_value.s==0 - || get_to(t->uas.request)->tag_value.len==0)) { - calc_crc_suffix( t->uas.request, tm_tag_suffix ); - to_tag=&tm_tag; + if((get_to(t->uas.request)->tag_value.s == 0 + || get_to(t->uas.request)->tag_value.len == 0)) { + calc_crc_suffix(t->uas.request, tm_tag_suffix); + to_tag = &tm_tag; } else { - to_tag=0; + to_tag = 0; } /* temporarily "store" the current reply */ - reply_bak=t->uac[branch].reply; - t->uac[branch].reply=p_msg; - buf=reply_aggregate_auth(relayed_code, + reply_bak = t->uac[branch].reply; + t->uac[branch].reply = p_msg; + buf = reply_aggregate_auth(relayed_code, error_text(relayed_code), to_tag, t, &res_len, &bm); /* revert the temporary "store" reply above */ - t->uac[branch].reply=reply_bak;; - relayed_msg=FAKED_REPLY; /* mark the relayed_msg as a "FAKE" */ - }else{ - buf = build_res_buf_from_sip_res( relayed_msg, &res_len ); + t->uac[branch].reply = reply_bak; + ; + relayed_msg = + FAKED_REPLY; /* mark the relayed_msg as a "FAKE" */ + } else { + buf = build_res_buf_from_sip_res(relayed_msg, &res_len); /* if we build a message from shmem, we need to remove * via delete lumps which are now stirred in the shmem-ed * structure */ - if (branch!=relay) { + if(branch != relay) { free_via_clen_lump(&relayed_msg->add_rm); } /* update send_flags with possible additions from the * reply route */ SND_FLAGS_OR(&uas_rb->dst.send_flags, &uas_rb->dst.send_flags, - &relayed_msg->rpl_send_flags); + &relayed_msg->rpl_send_flags); } } - update_reply_stats( relayed_code ); + update_reply_stats(relayed_code); t_stats_rpl_sent(); - if (!buf) { + if(!buf) { LM_ERR("no mem for outbound reply buffer\n"); goto error02; } - if (tm_reply_relay_mode == 0 + if(tm_reply_relay_mode == 0 || reply_status != RPS_PUSHED_AFTER_COMPLETION) { /* attempt to copy the message to UAS's shmem: * - copy to-tag for ACK matching as well @@ -2057,20 +2065,20 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, * larger messages are likely to follow and we will be * able to reuse the memory frag */ - if (res_len<=0) { + if(res_len <= 0) { LM_ERR("invalid new buffer len\n"); goto error03; } - uas_rb->buffer = (char*)shm_resize( uas_rb->buffer, res_len + - (msg_status<200 ? REPLY_OVERBUFFER_LEN : 0)); - if (!uas_rb->buffer) { + uas_rb->buffer = (char *)shm_resize(uas_rb->buffer, + res_len + (msg_status < 200 ? REPLY_OVERBUFFER_LEN : 0)); + if(!uas_rb->buffer) { LM_ERR("cannot alloc reply shmem\n"); goto error03; } uas_rb->rbtype = relayed_code; uas_rb->buffer_len = res_len; - memcpy( uas_rb->buffer, buf, res_len ); - if (relayed_msg==FAKED_REPLY) { /* to-tags for local replies */ + memcpy(uas_rb->buffer, buf, res_len); + if(relayed_msg == FAKED_REPLY) { /* to-tags for local replies */ update_local_tags(t, &bm, uas_rb->buffer, buf); t_stats_rpl_generated(); } @@ -2079,21 +2087,22 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, t->uas.status = relayed_code; t->relayed_reply_branch = relay; - if ( unlikely(is_invite(t) && relayed_msg!=FAKED_REPLY - && relayed_code>=200 && relayed_code < 300 - && has_tran_tmcbs( t, - TMCB_RESPONSE_OUT|TMCB_RESPONSE_READY - |TMCB_E2EACK_IN|TMCB_E2EACK_RETR_IN))) { - totag_retr=update_totag_set(t, relayed_msg); + if(unlikely(is_invite(t) && relayed_msg != FAKED_REPLY + && relayed_code >= 200 && relayed_code < 300 + && has_tran_tmcbs(t, TMCB_RESPONSE_OUT + | TMCB_RESPONSE_READY + | TMCB_E2EACK_IN + | TMCB_E2EACK_RETR_IN))) { + totag_retr = update_totag_set(t, relayed_msg); } } } /* if relay ... */ - UNLOCK_REPLIES( t ); + UNLOCK_REPLIES(t); /* send it now (from the private buffer) */ - if (relay >= 0) { - if (unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_READY))){ + if(relay >= 0) { + if(unlikely(!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_READY))) { run_trans_callbacks_with_buf(TMCB_RESPONSE_READY, uas_rb, t->uas.request, relayed_msg, TMCB_NONE_F); } @@ -2105,55 +2114,59 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, * failure_route or from a callback and the timer has been already * started. (Miklos) */ - if (reply_status == RPS_COMPLETED) { + if(reply_status == RPS_COMPLETED) { start_final_repl_retr(t); } - if (likely(uas_rb->dst.send_sock)) { - if (onsend_route_enabled(SIP_REPLY) && p_msg - && (p_msg != FAKED_REPLY) - && (tm_reply_relay_mode == 0 + if(likely(uas_rb->dst.send_sock)) { + if(onsend_route_enabled(SIP_REPLY) && p_msg + && (p_msg != FAKED_REPLY) + && (tm_reply_relay_mode == 0 || reply_status != RPS_PUSHED_AFTER_COMPLETION)) { - if (run_onsend(p_msg, &uas_rb->dst, buf, res_len)==0){ + if(run_onsend(p_msg, &uas_rb->dst, buf, res_len) == 0) { su2ip_addr(&ip, &(uas_rb->dst.to)); LM_ERR("reply to %s:%d(%d) dropped" - " (onsend_route)\n", ip_addr2a(&ip), - su_getport(&(uas_rb->dst.to)), uas_rb->dst.proto); + " (onsend_route)\n", + ip_addr2a(&ip), su_getport(&(uas_rb->dst.to)), + uas_rb->dst.proto); /* workaround for drop - reset send_sock to skip sending out */ uas_rb->dst.send_sock = 0; } } } - if (likely(uas_rb->dst.send_sock)) { - if (SEND_PR_BUFFER( uas_rb, buf, res_len ) >= 0){ + if(likely(uas_rb->dst.send_sock)) { + if(SEND_PR_BUFFER(uas_rb, buf, res_len) >= 0) { LM_DBG("reply buffer sent out\n"); - if (unlikely(!totag_retr - && has_tran_tmcbs(t, TMCB_RESPONSE_OUT) - && (tm_reply_relay_mode == 0 - || reply_status != RPS_PUSHED_AFTER_COMPLETION))){ - LOCK_REPLIES( t ); - if(relayed_code==uas_rb->rbtype) { - run_trans_callbacks_with_buf( TMCB_RESPONSE_OUT, uas_rb, + if(unlikely( + !totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_OUT) + && (tm_reply_relay_mode == 0 + || reply_status + != RPS_PUSHED_AFTER_COMPLETION))) { + LOCK_REPLIES(t); + if(relayed_code == uas_rb->rbtype) { + run_trans_callbacks_with_buf(TMCB_RESPONSE_OUT, uas_rb, t->uas.request, relayed_msg, TMCB_NONE_F); } else { - LM_DBG("skip tm callback %d - relay code %d active %d\n", + LM_DBG("skip tm callback %d - relay code %d active " + "%d\n", TMCB_RESPONSE_OUT, relayed_code, uas_rb->rbtype); } - UNLOCK_REPLIES( t ); + UNLOCK_REPLIES(t); } - if (unlikely(has_tran_tmcbs(t, TMCB_RESPONSE_SENT) - && (tm_reply_relay_mode == 0 - || reply_status != RPS_PUSHED_AFTER_COMPLETION))){ + if(unlikely( + has_tran_tmcbs(t, TMCB_RESPONSE_SENT) + && (tm_reply_relay_mode == 0 + || reply_status + != RPS_PUSHED_AFTER_COMPLETION))) { INIT_TMCB_ONSEND_PARAMS(onsend_params, t->uas.request, - relayed_msg, uas_rb, &uas_rb->dst, buf, - res_len, - (relayed_msg==FAKED_REPLY)?TMCB_LOCAL_F:0, - uas_rb->branch, relayed_code); - LOCK_REPLIES( t ); - run_trans_callbacks_off_params(TMCB_RESPONSE_SENT, t, - &onsend_params); - UNLOCK_REPLIES( t ); + relayed_msg, uas_rb, &uas_rb->dst, buf, res_len, + (relayed_msg == FAKED_REPLY) ? TMCB_LOCAL_F : 0, + uas_rb->branch, relayed_code); + LOCK_REPLIES(t); + run_trans_callbacks_off_params( + TMCB_RESPONSE_SENT, t, &onsend_params); + UNLOCK_REPLIES(t); } } } else { @@ -2171,26 +2184,26 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, * called from timer (fr_timer) (the timer doesn't refcnt) and the * timer allows quick dels (timer_allow_del()). --andrei */ - if (do_put_on_wait && (reply_status == RPS_COMPLETED)) { + if(do_put_on_wait && (reply_status == RPS_COMPLETED)) { put_on_wait(t); } - pkg_free( buf ); + pkg_free(buf); } /* success */ return reply_status; error03: - pkg_free( buf ); + pkg_free(buf); error02: - if (save_clone) { - if (t->uac[branch].reply!=FAKED_REPLY) - sip_msg_free( t->uac[branch].reply ); + if(save_clone) { + if(t->uac[branch].reply != FAKED_REPLY) + sip_msg_free(t->uac[branch].reply); t->uac[branch].reply = NULL; } error01: - t_reply_unsafe( t, t->uas.request, 500, "Reply processing error" ); - cancel_data->cancel_bitmap=0; /* t_reply_unsafe already canceled + t_reply_unsafe(t, t->uas.request, 500, "Reply processing error"); + cancel_data->cancel_bitmap = 0; /* t_reply_unsafe already canceled * everything needed */ UNLOCK_REPLIES(t); /* if (is_invite(t)) cancel_uacs( t, *cancel_bitmap, 0); @@ -2212,8 +2225,8 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, * * WARNING: cancel_data should be initialized prior to calling this function. */ -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) { /* how to deal with replies for local transaction */ int local_store, local_winner; @@ -2223,64 +2236,64 @@ enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch, int totag_retr; /* keep warning 'var might be used un-inited' silent */ - winning_msg=0; - winning_code=0; - totag_retr=0; + winning_msg = 0; + winning_code = 0; + totag_retr = 0; - cancel_data->cancel_bitmap=0; + cancel_data->cancel_bitmap = 0; - reply_status=t_should_relay_response(t, msg_status, branch, - &local_store, &local_winner, cancel_data, p_msg); + reply_status = t_should_relay_response(t, msg_status, branch, &local_store, + &local_winner, cancel_data, p_msg); if(reply_status == RPS_TGONE) { LM_DBG("reply handling failure - t is gone\n"); /* failure */ return RPS_TGONE; } - LM_DBG("branch=%d, save=%d, winner=%d\n", - branch, local_store, local_winner ); - if (local_store) { - if (!store_reply(t, branch, p_msg)) + LM_DBG("branch=%d, save=%d, winner=%d\n", branch, local_store, + local_winner); + if(local_store) { + if(!store_reply(t, branch, p_msg)) goto error; } - if (local_winner>=0) { - winning_msg= branch==local_winner - ? p_msg : t->uac[local_winner].reply; - if (winning_msg==FAKED_REPLY) { + if(local_winner >= 0) { + winning_msg = + branch == local_winner ? p_msg : t->uac[local_winner].reply; + if(winning_msg == FAKED_REPLY) { t_stats_rpl_generated(); - winning_code = branch==local_winner - ? msg_status : t->uac[local_winner].last_received; + winning_code = branch == local_winner + ? msg_status + : t->uac[local_winner].last_received; } else { - winning_code=winning_msg->REPLY_STATUS; + winning_code = winning_msg->REPLY_STATUS; } t->uas.status = winning_code; - update_reply_stats( winning_code ); + update_reply_stats(winning_code); t_stats_rpl_sent(); - if (unlikely(is_invite(t) && winning_msg!=FAKED_REPLY - && winning_code>=200 && winning_code <300 - && has_tran_tmcbs(t, TMCB_LOCAL_COMPLETED) )) { - totag_retr=update_totag_set(t, winning_msg); + if(unlikely(is_invite(t) && winning_msg != FAKED_REPLY + && winning_code >= 200 && winning_code < 300 + && has_tran_tmcbs(t, TMCB_LOCAL_COMPLETED))) { + totag_retr = update_totag_set(t, winning_msg); } } UNLOCK_REPLIES(t); - if (local_winner >= 0 - && cfg_get(tm, tm_cfg, pass_provisional_replies) - && winning_code < 200) { - /* no retr. detection for provisional replies & + if(local_winner >= 0 && cfg_get(tm, tm_cfg, pass_provisional_replies) + && winning_code < 200) { + /* no retr. detection for provisional replies & * TMCB_LOCAL_RESPONSE_OUT */ - if (unlikely(has_tran_tmcbs(t, TMCB_LOCAL_RESPONSE_OUT) )) { - run_trans_callbacks( TMCB_LOCAL_RESPONSE_OUT, t, 0, - winning_msg, winning_code); - } + if(unlikely(has_tran_tmcbs(t, TMCB_LOCAL_RESPONSE_OUT))) { + run_trans_callbacks( + TMCB_LOCAL_RESPONSE_OUT, t, 0, winning_msg, winning_code); + } } - if (local_winner>=0 && winning_code>=200 ) { + if(local_winner >= 0 && winning_code >= 200) { LM_DBG("local transaction completed %d/%d (totag retr: %d/%d)\n", winning_code, local_winner, totag_retr, t->tmcb_hl.reg_types); - if (!totag_retr) { - if (unlikely(has_tran_tmcbs(t,TMCB_LOCAL_COMPLETED) )) - run_trans_callbacks( TMCB_LOCAL_COMPLETED, t, 0, - winning_msg, winning_code ); + if(!totag_retr) { + if(unlikely(has_tran_tmcbs(t, TMCB_LOCAL_COMPLETED))) + run_trans_callbacks( + TMCB_LOCAL_COMPLETED, t, 0, winning_msg, winning_code); } } return reply_status; @@ -2289,25 +2302,23 @@ enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch, prepare_to_cancel(t, &cancel_data->cancel_bitmap, 0); UNLOCK_REPLIES(t); cleanup_uac_timers(t); - if (p_msg && p_msg!=FAKED_REPLY && get_cseq(p_msg)->method.len==INVITE_LEN - && memcmp( get_cseq(p_msg)->method.s, INVITE, INVITE_LEN)==0){ - cancel_uacs( t, cancel_data, F_CANCEL_B_KILL); + if(p_msg && p_msg != FAKED_REPLY + && get_cseq(p_msg)->method.len == INVITE_LEN + && memcmp(get_cseq(p_msg)->method.s, INVITE, INVITE_LEN) == 0) { + cancel_uacs(t, cancel_data, F_CANCEL_B_KILL); } - cancel_data->cancel_bitmap=0; /* we've already took care of everything */ + cancel_data->cancel_bitmap = 0; /* we've already took care of everything */ put_on_wait(t); return RPS_ERROR; } - - - /* This function is called whenever a reply for our module is received; * we need to register this function on module initialization; * 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) { int msg_status; int last_uac_status; @@ -2320,10 +2331,10 @@ int reply_received( struct sip_msg *p_msg ) struct cancel_info cancel_data; struct ua_client *uac; struct cell *t; - struct dest_info lack_dst; - avp_list_t* backup_user_from, *backup_user_to; - avp_list_t* backup_domain_from, *backup_domain_to; - avp_list_t* backup_uri_from, *backup_uri_to; + struct dest_info lack_dst; + avp_list_t *backup_user_from, *backup_user_to; + avp_list_t *backup_domain_from, *backup_domain_to; + avp_list_t *backup_uri_from, *backup_uri_to; sr_xavp_t **backup_xavps; sr_xavp_t **backup_xavus; sr_xavp_t **backup_xavis; @@ -2335,7 +2346,7 @@ int reply_received( struct sip_msg *p_msg ) #endif #ifdef USE_DST_BLOCKLIST int blst_503_timeout; - struct hdr_field* hf; + struct hdr_field *hf; #endif struct tmcb_params onsend_params; struct run_act_ctx ctx; @@ -2346,15 +2357,15 @@ int reply_received( struct sip_msg *p_msg ) /* make sure we know the associated transaction ... */ branch = T_BR_UNDEFINED; - if (t_check(p_msg , &branch)==-1) + if(t_check(p_msg, &branch) == -1) goto trans_not_found; /*... if there is none, tell the core router to fwd statelessly */ - t=get_t(); - if ( (t==0)||(t==T_UNDEFINED)) { + t = get_t(); + if((t == 0) || (t == T_UNDEFINED)) { LM_DBG("transaction not found - (branch %d)\n", branch); goto trans_not_found; } - if (unlikely(branch==T_BR_UNDEFINED)) { + if(unlikely(branch == T_BR_UNDEFINED)) { LM_CRIT("BUG: transaction found, but no branch matched\n"); /* t_check() referenced the transaction */ t_unref(p_msg); @@ -2369,38 +2380,38 @@ int reply_received( struct sip_msg *p_msg ) /* lock -- onreply_route, safe avp usage, ... */ /* - it is a recurrent mutex, so it is safe if a function executed * down here does another lock/unlock */ - LOCK_REPLIES( t ); - replies_locked=1; + LOCK_REPLIES(t); + replies_locked = 1; tm_ctx_set_branch_index(branch); init_cancel_info(&cancel_data); - msg_status=p_msg->REPLY_STATUS; + msg_status = p_msg->REPLY_STATUS; - uac=&t->uac[branch]; + uac = &t->uac[branch]; LM_DBG("original status uas=%d, uac[%d]=%d local=%d is_invite=%d)\n", - t->uas.status, branch, uac->last_received, - is_local(t), is_invite(t)); - last_uac_status=uac->last_received; + t->uas.status, branch, uac->last_received, is_local(t), + is_invite(t)); + last_uac_status = uac->last_received; /* it's a cancel ... ? */ - if (get_cseq(p_msg)->method.len==CANCEL_LEN - && memcmp( get_cseq(p_msg)->method.s, CANCEL, CANCEL_LEN)==0 - /* .. which is not e2e ? ... */ - && is_invite(t) ) { - /* ... then just stop timers */ - if ( msg_status >= 200 ) - stop_rb_timers(&uac->local_cancel); /* stop retr & fr */ - else - stop_rb_retr(&uac->local_cancel); /* stop only retr */ - LM_DBG("reply to local CANCEL processed\n"); - goto done; + if(get_cseq(p_msg)->method.len == CANCEL_LEN + && memcmp(get_cseq(p_msg)->method.s, CANCEL, CANCEL_LEN) == 0 + /* .. which is not e2e ? ... */ + && is_invite(t)) { + /* ... then just stop timers */ + if(msg_status >= 200) + stop_rb_timers(&uac->local_cancel); /* stop retr & fr */ + else + stop_rb_retr(&uac->local_cancel); /* stop only retr */ + LM_DBG("reply to local CANCEL processed\n"); + goto done; } - onreply_route=uac->on_reply; - if ( msg_status >= 200 ){ + onreply_route = uac->on_reply; + if(msg_status >= 200) { #ifdef TM_ONREPLY_FINAL_DROP_OK #warning Experimental tm onreply_route final reply DROP support active - if (onreply_route) + if(onreply_route) /* stop only retr., but leave the final reply timers on, * in case the final reply is dropped in the on_reply route */ stop_rb_retr(&uac->request); @@ -2411,116 +2422,117 @@ int reply_received( struct sip_msg *p_msg ) /* acknowledge negative INVITE replies (do it before detailed * on_reply processing, which may take very long, like if it * is attempted to establish a TCP connection to a fail-over dst */ - if (is_invite(t)) { - if (msg_status >= 300) { + if(is_invite(t)) { + if(msg_status >= 300) { ack = build_ack(p_msg, t, branch, &ack_len); - if (ack) { - if (SEND_PR_BUFFER(&uac->request, ack, ack_len)>=0) { - if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){ + if(ack) { + if(SEND_PR_BUFFER(&uac->request, ack, ack_len) >= 0) { + if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))) { INIT_TMCB_ONSEND_PARAMS(onsend_params, t->uas.request, p_msg, &uac->request, &uac->request.dst, ack, ack_len, TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK); - run_trans_callbacks_off_params(TMCB_REQUEST_SENT, - t, &onsend_params); + run_trans_callbacks_off_params( + TMCB_REQUEST_SENT, t, &onsend_params); } } shm_free(ack); } - } else if (is_local(t) /*&& 200 <= msg_status < 300*/) { + } else if(is_local(t) /*&& 200 <= msg_status < 300*/) { ack = build_local_ack(p_msg, t, branch, &ack_len, &lack_dst); - if (ack) { - if (msg_send(&lack_dst, ack, ack_len)<0) + if(ack) { + if(msg_send(&lack_dst, ack, ack_len) < 0) LM_ERR("error while sending local ACK\n"); - else if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){ - INIT_TMCB_ONSEND_PARAMS(onsend_params, - t->uas.request, p_msg, &uac->request, - &lack_dst, ack, ack_len, TMCB_LOCAL_F, - branch, TYPE_LOCAL_ACK); - run_trans_callbacks_off_params(TMCB_REQUEST_SENT, - t, &onsend_params); + else if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))) { + INIT_TMCB_ONSEND_PARAMS(onsend_params, t->uas.request, + p_msg, &uac->request, &lack_dst, ack, ack_len, + TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK); + run_trans_callbacks_off_params( + TMCB_REQUEST_SENT, t, &onsend_params); } } } } - }else{ + } else { /* if branch already canceled re-transmit or generate cancel * TODO: check if it really makes sense to do it for non-invites too */ - if (uac->request.flags & F_RB_CANCELED){ - if (uac->local_cancel.buffer_len){ + if(uac->request.flags & F_RB_CANCELED) { + if(uac->local_cancel.buffer_len) { membar_read(); /* make sure we get the current value of * local_cancel */ /* re-transmit if cancel already built */ DBG("tm: reply_received: branch CANCEL retransmit\n"); - if (SEND_BUFFER( &uac->local_cancel)>=0){ - if (unlikely (has_tran_tmcbs(t, TMCB_REQUEST_SENT))) + if(SEND_BUFFER(&uac->local_cancel) >= 0) { + if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))) run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, &uac->local_cancel, 0, 0, TMCB_LOCAL_F); } /* retrs. should be already started so do nothing */ - }else if (atomic_cmpxchg_long((void*)&uac->local_cancel.buffer, 0, - (long)BUSY_BUFFER)==0){ + } else if(atomic_cmpxchg_long((void *)&uac->local_cancel.buffer, 0, + (long)BUSY_BUFFER) + == 0) { /* try to rebuild it if empty (not set or marked as BUSY). * if BUSY or set just exit, a cancel will be (or was) sent * shortly on this branch */ LM_DBG("branch CANCEL created\n"); - if (t->uas.cancel_reas) { + if(t->uas.cancel_reas) { /* cancel reason was saved, use it */ - cancel_branch(t, branch, t->uas.cancel_reas, - F_CANCEL_B_FORCE_C); + cancel_branch( + t, branch, t->uas.cancel_reas, F_CANCEL_B_FORCE_C); } else { /* note that in this case we do not know the reason, * we only know it's a final reply (either locally * generated via script t_reply(), timeout, a received * 2xx or 6xx) => try to use t->uas.status as the reason */ - cancel_data.reason.cause = - (t->uas.status>=200)?t->uas.status:CANCEL_REAS_UNKNOWN; - cancel_branch(t, branch, &cancel_data.reason, - F_CANCEL_B_FORCE_C); + cancel_data.reason.cause = (t->uas.status >= 200) + ? t->uas.status + : CANCEL_REAS_UNKNOWN; + cancel_branch( + t, branch, &cancel_data.reason, F_CANCEL_B_FORCE_C); } } goto done; /* nothing to do */ } - if (is_invite(t)){ + if(is_invite(t)) { /* stop only retr. (and not fr) */ stop_rb_retr(&uac->request); - }else{ + } else { /* non-invite: increase retransmissions interval (slow now) */ switch_rb_retr_to_t2(&uac->request); } } /* pre-set the ignore BLST_503 flag in the message, if the * corresponding branch had it set on send */ - p_msg->fwd_send_flags.blst_imask|= - uac->request.dst.send_flags.blst_imask & BLST_503; + p_msg->fwd_send_flags.blst_imask |= + uac->request.dst.send_flags.blst_imask & BLST_503; /* processing of on_reply block */ - if (onreply_route || sr_event_enabled(SREV_SIP_REPLY_OUT)) { + if(onreply_route || sr_event_enabled(SREV_SIP_REPLY_OUT)) { set_route_type(TM_ONREPLY_ROUTE); /* transfer transaction flag to message context */ - if (t->uas.request) { - p_msg->flags=t->uas.request->flags; + if(t->uas.request) { + p_msg->flags = t->uas.request->flags; memcpy(p_msg->xflags, t->uas.request->xflags, - KSR_XFLAGS_SIZE * sizeof(flag_t)); + KSR_XFLAGS_SIZE * sizeof(flag_t)); } /* set the as avp_list the one from transaction */ - backup_uri_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, - &t->uri_avps_from ); - backup_uri_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, - &t->uri_avps_to ); - backup_user_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, - &t->user_avps_from ); - backup_user_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, - &t->user_avps_to ); - backup_domain_from = set_avp_list(AVP_TRACK_FROM | AVP_CLASS_DOMAIN, - &t->domain_avps_from ); - backup_domain_to = set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, - &t->domain_avps_to ); + backup_uri_from = + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, &t->uri_avps_from); + backup_uri_to = + set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, &t->uri_avps_to); + backup_user_from = set_avp_list( + AVP_TRACK_FROM | AVP_CLASS_USER, &t->user_avps_from); + backup_user_to = + set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, &t->user_avps_to); + backup_domain_from = set_avp_list( + AVP_TRACK_FROM | AVP_CLASS_DOMAIN, &t->domain_avps_from); + backup_domain_to = set_avp_list( + AVP_TRACK_TO | AVP_CLASS_DOMAIN, &t->domain_avps_to); backup_xavps = xavp_set_list(&t->xavps_list); backup_xavus = xavu_set_list(&t->xavus_list); backup_xavis = xavi_set_list(&t->xavis_list); setbflagsval(0, uac->branch_flags); - if(msg_status>last_uac_status) { + if(msg_status > last_uac_status) { /* current response (msg) status is higher that the last received * on the same branch - set it temporarily so functions in onreply_route * can access it (e.g., avoid sending CANCEL by forcing another t_relply() @@ -2532,12 +2544,13 @@ int reply_received( struct sip_msg *p_msg ) * been executed by the core. (Miklos) */ keng = sr_kemi_eng_get(); - if(unlikely(keng!=NULL)) { + if(unlikely(keng != NULL)) { bctx = sr_kemi_act_ctx_get(); init_run_actions_ctx(&ctx); sr_kemi_act_ctx_set(&ctx); if(sr_kemi_route(keng, p_msg, TM_ONREPLY_ROUTE, - sr_kemi_cbname_lookup_idx(onreply_route), NULL)<0) { + sr_kemi_cbname_lookup_idx(onreply_route), NULL) + < 0) { LM_DBG("negative return from on-reply kemi callback\n"); } sr_kemi_act_ctx_set(bctx); @@ -2546,12 +2559,13 @@ int reply_received( struct sip_msg *p_msg ) } - if((!(ctx.run_flags&DROP_R_F)) && sr_event_enabled(SREV_SIP_REPLY_OUT)) { + if((!(ctx.run_flags & DROP_R_F)) + && sr_event_enabled(SREV_SIP_REPLY_OUT)) { sr_event_param_t evp; memset(&evp, 0, sizeof(sr_event_param_t)); evp.obuf.s = p_msg->buf; evp.obuf.len = p_msg->len; - evp.rcv = (t->uas.request)?&t->uas.request->rcv:0; + evp.rcv = (t->uas.request) ? &t->uas.request->rcv : 0; evp.dst = &t->uas.response.dst; evp.req = t->uas.request; evp.rpl = p_msg; @@ -2563,20 +2577,20 @@ int reply_received( struct sip_msg *p_msg ) /* restore brach last_received as before executing onreply_route */ uac->last_received = last_uac_status; /* transfer current message context back to t */ - if (t->uas.request) { - t->uas.request->flags=p_msg->flags; + if(t->uas.request) { + t->uas.request->flags = p_msg->flags; memcpy(t->uas.request->xflags, p_msg->xflags, - KSR_XFLAGS_SIZE * sizeof(flag_t)); + KSR_XFLAGS_SIZE * sizeof(flag_t)); } getbflagsval(0, &uac->branch_flags); /* restore original avp list */ - set_avp_list( AVP_TRACK_FROM | AVP_CLASS_URI, backup_uri_from ); - set_avp_list( AVP_TRACK_TO | AVP_CLASS_URI, backup_uri_to ); - set_avp_list( AVP_TRACK_FROM | AVP_CLASS_USER, backup_user_from ); - set_avp_list( AVP_TRACK_TO | AVP_CLASS_USER, backup_user_to ); - set_avp_list( AVP_TRACK_FROM | AVP_CLASS_DOMAIN, backup_domain_from ); - set_avp_list( AVP_TRACK_TO | AVP_CLASS_DOMAIN, backup_domain_to ); + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_URI, backup_uri_from); + set_avp_list(AVP_TRACK_TO | AVP_CLASS_URI, backup_uri_to); + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_USER, backup_user_from); + set_avp_list(AVP_TRACK_TO | AVP_CLASS_USER, backup_user_to); + set_avp_list(AVP_TRACK_FROM | AVP_CLASS_DOMAIN, backup_domain_from); + set_avp_list(AVP_TRACK_TO | AVP_CLASS_DOMAIN, backup_domain_to); xavp_set_list(backup_xavps); xavu_set_list(backup_xavus); xavi_set_list(backup_xavis); @@ -2584,161 +2598,163 @@ int reply_received( struct sip_msg *p_msg ) * is not a final reply (final replies already stop the timers * and droping them might leave a transaction living forever) */ #ifdef TM_ONREPLY_FINAL_DROP_OK - if (unlikely(ctx.run_flags&DROP_R_F)) + if(unlikely(ctx.run_flags & DROP_R_F)) #else - if (unlikely((ctx.run_flags&DROP_R_F) && (msg_status<200))) + if(unlikely((ctx.run_flags & DROP_R_F) && (msg_status < 200))) #endif /* TM_ONREPLY_FINAL_DROP_OK */ { goto done; } #ifdef TM_ONREPLY_FINAL_DROP_OK - if (msg_status >= 200) { + if(msg_status >= 200) { /* stop final reply timers, now that we executed the onreply route * and the reply was not DROPed */ stop_rb_timers(&uac->request); } -#endif /* TM_ONREPLY_FINAL_DROP_OK */ +#endif /* TM_ONREPLY_FINAL_DROP_OK */ /* Re-read the status code, it can be changed in the route block. */ #ifdef EXTRA_DEBUG /* The class of provisional and positive final replies * cannot be changed. */ - if (((msg_status < 300) || (p_msg->REPLY_STATUS < 300)) - && (msg_status/100 != p_msg->REPLY_STATUS/100) - ) { + if(((msg_status < 300) || (p_msg->REPLY_STATUS < 300)) + && (msg_status / 100 != p_msg->REPLY_STATUS / 100)) { LM_ERR("the class of provisional and" - " positive final replies should not be changed!\n"); + " positive final replies should not be changed!\n"); } #endif /* EXTRA_DEBUG */ - msg_status=p_msg->REPLY_STATUS; + msg_status = p_msg->REPLY_STATUS; } #ifdef USE_DST_BLOCKLIST - /* add temporary to the blocklist the source of a 503 reply */ - if ( (msg_status==503) && cfg_get(tm, tm_cfg, tm_blst_503) && - /* check if the request sent on the branch had the + /* add temporary to the blocklist the source of a 503 reply */ + if((msg_status == 503) && cfg_get(tm, tm_cfg, tm_blst_503) && + /* check if the request sent on the branch had the * blst 503 ignore flags set or it was set in the onreply_r*/ - should_blocklist_su(BLST_503, &p_msg->fwd_send_flags, - p_msg->rcv.proto, &p_msg->rcv.src_su) - ){ - blst_503_timeout=cfg_get(tm, tm_cfg, tm_blst_503_default); - if ((parse_headers(p_msg, HDR_RETRY_AFTER_F, 0)==0) && - (p_msg->parsed_flag & HDR_RETRY_AFTER_F)){ - for (hf=p_msg->headers; hf; hf=hf->next) - if (hf->type==HDR_RETRY_AFTER_T){ - /* found */ - blst_503_timeout=(unsigned)(unsigned long)hf->parsed; - blst_503_timeout=MAX_unsigned(blst_503_timeout, - cfg_get(tm, tm_cfg, tm_blst_503_min)); - blst_503_timeout=MIN_unsigned(blst_503_timeout, - cfg_get(tm, tm_cfg, tm_blst_503_max)); - break; - } - } - if (blst_503_timeout){ - dst_blocklist_force_su_to(BLST_503, p_msg->rcv.proto, - &p_msg->rcv.src_su, p_msg, - S_TO_TICKS(blst_503_timeout)); - } + should_blocklist_su(BLST_503, &p_msg->fwd_send_flags, + p_msg->rcv.proto, &p_msg->rcv.src_su)) { + blst_503_timeout = cfg_get(tm, tm_cfg, tm_blst_503_default); + if((parse_headers(p_msg, HDR_RETRY_AFTER_F, 0) == 0) + && (p_msg->parsed_flag & HDR_RETRY_AFTER_F)) { + for(hf = p_msg->headers; hf; hf = hf->next) + if(hf->type == HDR_RETRY_AFTER_T) { + /* found */ + blst_503_timeout = (unsigned)(unsigned long)hf->parsed; + blst_503_timeout = MAX_unsigned(blst_503_timeout, + cfg_get(tm, tm_cfg, tm_blst_503_min)); + blst_503_timeout = MIN_unsigned(blst_503_timeout, + cfg_get(tm, tm_cfg, tm_blst_503_max)); + break; + } + } + if(blst_503_timeout) { + dst_blocklist_force_su_to(BLST_503, p_msg->rcv.proto, + &p_msg->rcv.src_su, p_msg, S_TO_TICKS(blst_503_timeout)); } + } #endif /* USE_DST_BLOCKLIST */ #ifdef USE_DNS_FAILOVER - /* if this is a 503 reply, and the destination resolves to more ips, + /* if this is a 503 reply, and the destination resolves to more ips, * add another branch/uac. * This code is out of LOCK_REPLIES() to minimize the time the * reply lock is held (the lock won't be held while sending the * message)*/ - failover_continue = (failover_reply_codes_str.s!=NULL && failover_reply_codes_str.len>0 && - t_failover_check_reply_code(msg_status)); + failover_continue = (failover_reply_codes_str.s != NULL + && failover_reply_codes_str.len > 0 + && t_failover_check_reply_code(msg_status)); - if (cfg_get(core, core_cfg, use_dns_failover) && (msg_status==503 || failover_continue)) { - branch_ret=add_uac_dns_fallback(t, t->uas.request, - uac, !replies_locked); - prev_branch=-1; - while((branch_ret>=0) &&(branch_ret!=prev_branch)){ - prev_branch=branch_ret; - branch_ret=t_send_branch(t, branch_ret, t->uas.request , 0, 1); - } + if(cfg_get(core, core_cfg, use_dns_failover) + && (msg_status == 503 || failover_continue)) { + branch_ret = + add_uac_dns_fallback(t, t->uas.request, uac, !replies_locked); + prev_branch = -1; + while((branch_ret >= 0) && (branch_ret != prev_branch)) { + prev_branch = branch_ret; + branch_ret = t_send_branch(t, branch_ret, t->uas.request, 0, 1); } + } #endif - if (t->flags & T_ASYNC_SUSPENDED) { + if(t->flags & T_ASYNC_SUSPENDED) { LM_DBG("Reply for suspended transaction, done.\n"); goto done; } - if (unlikely(p_msg->msg_flags&FL_RPL_SUSPENDED)) { + if(unlikely(p_msg->msg_flags & FL_RPL_SUSPENDED)) { /* suspended the reply (async) - no error */ goto done; } - if ( is_local(t) ) { + if(is_local(t)) { /* local_reply() does UNLOCK_REPLIES( t ) */ - reply_status=local_reply( t, p_msg, branch, msg_status, &cancel_data ); - replies_locked=0; - if (reply_status == RPS_COMPLETED) { + reply_status = local_reply(t, p_msg, branch, msg_status, &cancel_data); + replies_locked = 0; + 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 { /* relay_reply() does UNLOCK_REPLIES( t ) */ - reply_status=relay_reply( t, p_msg, branch, msg_status, - &cancel_data, 1 ); - if (reply_status == RPS_TGONE) { + reply_status = + relay_reply(t, p_msg, branch, msg_status, &cancel_data, 1); + if(reply_status == RPS_TGONE) { /* let the reply be sent out stateless */ return 1; } - replies_locked=0; - if (reply_status == RPS_COMPLETED) { + replies_locked = 0; + 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)); } } - uac->request.flags|=F_RB_REPLIED; + uac->request.flags |= F_RB_REPLIED; - if (reply_status==RPS_ERROR) + if(reply_status == RPS_ERROR) goto done; /* update FR/RETR timers on provisional replies */ - if (is_invite(t) && msg_status<200 && - ( cfg_get(tm, tm_cfg, restart_fr_on_each_reply) || - ( (last_uac_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(& uac->request, t->fr_inv_timeout); - uac->request.flags|=F_RB_FR_INV; /* mark fr_inv */ - } /* provisional replies */ + restart_rb_fr(&uac->request, t->fr_inv_timeout); + uac->request.flags |= F_RB_FR_INV; /* mark fr_inv */ + } /* provisional replies */ done: - if (unlikely(replies_locked)){ + if(unlikely(replies_locked)) { /* unlock replies if still locked coming via goto */ UNLOCK_REPLIES(t); - replies_locked=0; + replies_locked = 0; } tm_ctx_set_branch_index(T_BR_UNDEFINED); @@ -2753,16 +2769,17 @@ int reply_received( struct sip_msg *p_msg ) trans_not_found: /* transaction context was not found */ - if(on_sl_reply_name.s!=NULL && on_sl_reply_name.len>0) { + if(on_sl_reply_name.s != NULL && on_sl_reply_name.len > 0) { keng = sr_kemi_eng_get(); - if(keng==NULL) { - if (goto_on_sl_reply) { + if(keng == NULL) { + if(goto_on_sl_reply) { /* The script writer has a chance to decide whether to * forward the reply or not. * Pre- and post-script callbacks have already * been execueted by the core. (Miklos) */ - return run_top_route(onreply_rt.rlist[goto_on_sl_reply], p_msg, 0); + return run_top_route( + onreply_rt.rlist[goto_on_sl_reply], p_msg, 0); } else { /* let the core forward the reply */ return 1; @@ -2771,10 +2788,10 @@ int reply_received( struct sip_msg *p_msg ) bctx = sr_kemi_act_ctx_get(); init_run_actions_ctx(&ctx); sr_kemi_act_ctx_set(&ctx); - ret = sr_kemi_ctx_route(keng, &ctx, p_msg, EVENT_ROUTE, - &on_sl_reply_name, &evname); + ret = sr_kemi_ctx_route( + keng, &ctx, p_msg, EVENT_ROUTE, &on_sl_reply_name, &evname); sr_kemi_act_ctx_set(bctx); - if(ret<0) { + if(ret < 0) { LM_ERR("error running on sl reply callback\n"); return -1; } @@ -2790,15 +2807,14 @@ int reply_received( struct sip_msg *p_msg ) } - -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) { struct lump_rpl *hdr_lump; struct lump_rpl *body_lump; - str s_to_tag; - str rpl; - int ret; + str s_to_tag; + str rpl; + int ret; struct bookmark bm; if(to_tag) { @@ -2809,13 +2825,14 @@ int t_reply_with_body( struct cell *trans, unsigned int code, } /* mark the transaction as replied */ - if (code>=200) set_kr(REQ_RPLD); + if(code >= 200) + set_kr(REQ_RPLD); /* add the lumps for new_header and for body (by bogdan) */ - if (new_header && new_header->len) { - hdr_lump = add_lump_rpl( trans->uas.request, new_header->s, - new_header->len, LUMP_RPL_HDR ); - if ( !hdr_lump ) { + if(new_header && new_header->len) { + hdr_lump = add_lump_rpl(trans->uas.request, new_header->s, + new_header->len, LUMP_RPL_HDR); + if(!hdr_lump) { LM_ERR("cannot add hdr lump\n"); goto error; } @@ -2825,9 +2842,9 @@ int t_reply_with_body( struct cell *trans, unsigned int code, /* body lump */ if(body && body->len) { - body_lump = add_lump_rpl( trans->uas.request, body->s, body->len, - LUMP_RPL_BODY ); - if (body_lump==0) { + body_lump = add_lump_rpl( + trans->uas.request, body->s, body->len, LUMP_RPL_BODY); + if(body_lump == 0) { LM_ERR("cannot add body lump\n"); goto error_1; } @@ -2835,30 +2852,30 @@ int t_reply_with_body( struct cell *trans, unsigned int code, body_lump = 0; } - rpl.s = build_res_buf_from_sip_req( code, text, &s_to_tag, - trans->uas.request, (unsigned int*)&rpl.len, &bm); + rpl.s = build_res_buf_from_sip_req(code, text, &s_to_tag, + trans->uas.request, (unsigned int *)&rpl.len, &bm); /* since the msg (trans->uas.request) is a clone into shm memory, to avoid * memory leak or crashing (lumps are create in private memory) I will * remove the lumps by myself here (bogdan) */ - if ( hdr_lump ) { - unlink_lump_rpl( trans->uas.request, hdr_lump); - free_lump_rpl( hdr_lump ); + if(hdr_lump) { + unlink_lump_rpl(trans->uas.request, hdr_lump); + free_lump_rpl(hdr_lump); } - if( body_lump ) { - unlink_lump_rpl( trans->uas.request, body_lump); - free_lump_rpl( body_lump ); + if(body_lump) { + unlink_lump_rpl(trans->uas.request, body_lump); + free_lump_rpl(body_lump); } - if (rpl.s==0) { + if(rpl.s == 0) { LM_ERR("failed in doing build_res_buf_from_sip_req()\n"); goto error; } LM_DBG("buffer computed\n"); // frees 'res.s' ... no panic ! - ret=_reply_light( trans, rpl.s, rpl.len, code, - s_to_tag.s, s_to_tag.len, 1 /* lock replies */, &bm ); + ret = _reply_light(trans, rpl.s, rpl.len, code, s_to_tag.s, s_to_tag.len, + 1 /* lock replies */, &bm); /* this is ugly hack -- the function caller may wish to continue with * transaction and I unref; however, there is now only one use from * vm/fifo_vm_reply and I'm currently to lazy to export UNREF; -jiri @@ -2867,9 +2884,9 @@ int t_reply_with_body( struct cell *trans, unsigned int code, return ret; error_1: - if ( hdr_lump ) { - unlink_lump_rpl( trans->uas.request, hdr_lump); - free_lump_rpl( hdr_lump ); + if(hdr_lump) { + unlink_lump_rpl(trans->uas.request, hdr_lump); + free_lump_rpl(hdr_lump); } error: return -1; @@ -2891,24 +2908,23 @@ void t_drop_replies(int v) int t_get_this_branch_instance(struct sip_msg *msg, str *instance) { struct cell *t; - if (!msg || !instance) - { + if(!msg || !instance) { LM_ERR("Invalid params\n"); return -1; } - if (get_route_type() != BRANCH_FAILURE_ROUTE) - { + if(get_route_type() != BRANCH_FAILURE_ROUTE) { LM_ERR("Called t_get_this_branch_instance not in a" - " branch_failure_route\n"); + " branch_failure_route\n"); return -1; } t = 0; /* first get the transaction */ - if (t_check(msg, 0 ) == -1) return -1; - if ((t = get_t()) == 0) { + if(t_check(msg, 0) == -1) + return -1; + if((t = get_t()) == 0) { LM_ERR("cannot check status for a reply" - " which has no T-state established\n"); + " which has no T-state established\n"); return -1; } *instance = t->uac[get_t_branch()].instance; @@ -2918,23 +2934,22 @@ int t_get_this_branch_instance(struct sip_msg *msg, str *instance) int t_get_this_branch_ruid(struct sip_msg *msg, str *ruid) { struct cell *t; - if (!msg || !ruid) - { + if(!msg || !ruid) { LM_ERR("Invalid params\n"); return -1; } - if (get_route_type() != BRANCH_FAILURE_ROUTE) - { + if(get_route_type() != BRANCH_FAILURE_ROUTE) { LM_ERR("Called t_get_this_branch_ruid not in a branch_failure_route\n"); return -1; } t = 0; /* first get the transaction */ - if (t_check(msg, 0 ) == -1) return -1; - if ((t = get_t()) == 0) { + if(t_check(msg, 0) == -1) + return -1; + if((t = get_t()) == 0) { LM_ERR("cannot check status for a reply " - "which has no T-state established\n"); + "which has no T-state established\n"); return -1; } *ruid = t->uac[get_t_branch()].ruid; @@ -2956,44 +2971,46 @@ int t_get_this_branch_ruid(struct sip_msg *msg, str *ruid) * .\n * \n" */ -void rpc_reply(rpc_t* rpc, void* c) +void rpc_reply(rpc_t *rpc, void *c) { int ret; struct cell *trans; unsigned int hash_index, label, code; str ti, body, headers, tag, reason; - if (rpc->scan(c, "d", &code) < 1) { + if(rpc->scan(c, "d", &code) < 1) { rpc->fault(c, 400, "Reply code expected"); return; } - if (rpc->scan(c, "S", &reason) < 1) { + if(rpc->scan(c, "S", &reason) < 1) { rpc->fault(c, 400, "Reason phrase expected"); return; } - if (rpc->scan(c, "S", &ti) < 1) { + if(rpc->scan(c, "S", &ti) < 1) { rpc->fault(c, 400, "Transaction ID expected"); return; } - if (rpc->scan(c, "S", &tag) < 1) { + if(rpc->scan(c, "S", &tag) < 1) { rpc->fault(c, 400, "To tag expected"); return; } - if (rpc->scan(c, "S", &headers) < 0) return; - if (rpc->scan(c, "S", &body) < 0) return; + if(rpc->scan(c, "S", &headers) < 0) + return; + if(rpc->scan(c, "S", &body) < 0) + return; - if(sscanf(ti.s,"%u:%u", &hash_index, &label) != 2) { + if(sscanf(ti.s, "%u:%u", &hash_index, &label) != 2) { ERR("Invalid trans_id (%s)\n", ti.s); rpc->fault(c, 400, "Invalid transaction ID"); return; } LM_DBG("hash_index=%u label=%u\n", hash_index, label); - if( t_lookup_ident(&trans, hash_index, label) < 0 ) { + if(t_lookup_ident(&trans, hash_index, label) < 0) { ERR("Lookup failed\n"); rpc->fault(c, 481, "No such transaction"); return; @@ -3003,7 +3020,7 @@ void rpc_reply(rpc_t* rpc, void* c) * continue but may not use T anymore */ ret = t_reply_with_body(trans, code, &reason, &body, &headers, &tag); - if (ret < 0) { + if(ret < 0) { LM_ERR("Reply failed\n"); rpc->fault(c, 500, "Reply failed"); return; @@ -3020,7 +3037,7 @@ void rpc_reply(rpc_t* rpc, void* c) * new headers * [Body] */ -void rpc_reply_callid(rpc_t* rpc, void* c) +void rpc_reply_callid(rpc_t *rpc, void *c) { int code; tm_cell_t *trans; @@ -3032,51 +3049,50 @@ void rpc_reply_callid(rpc_t* rpc, void* c) str cseq = {0, 0}; int n; - if (rpc->scan(c, "d", &code) < 1) { + if(rpc->scan(c, "d", &code) < 1) { rpc->fault(c, 400, "Reply code expected"); return; } - if (rpc->scan(c, "S", &reason) < 1) { + if(rpc->scan(c, "S", &reason) < 1) { rpc->fault(c, 400, "Reason phrase expected"); return; } - if (rpc->scan(c, "S", &callid) < 1) { + if(rpc->scan(c, "S", &callid) < 1) { rpc->fault(c, 400, "Call-ID expected"); return; } - if (rpc->scan(c, "S", &cseq) < 1) { + if(rpc->scan(c, "S", &cseq) < 1) { rpc->fault(c, 400, "CSeq expected"); return; } - if (rpc->scan(c, "S", &totag) < 1) { + if(rpc->scan(c, "S", &totag) < 1) { rpc->fault(c, 400, "To tag expected"); return; } - if (rpc->scan(c, "S", &hdrs) < 0) { + if(rpc->scan(c, "S", &hdrs) < 0) { rpc->fault(c, 500, "Read error"); return; } - if (rpc->scan(c, "S", &body) < 0) { + if(rpc->scan(c, "S", &body) < 0) { rpc->fault(c, 500, "Read error"); return; } - if(t_lookup_callid( &trans, callid, cseq) < 0 ) { + if(t_lookup_callid(&trans, callid, cseq) < 0) { rpc->fault(c, 404, "Transaction not found"); return; } /* it's refcounted now, t_reply_with body unrefs for me -- I can * continue but may not use T anymore */ - n = t_reply_with_body(trans, code, &reason, &body, - &hdrs, &totag); + n = t_reply_with_body(trans, code, &reason, &body, &hdrs, &totag); - if (n<0) { + if(n < 0) { rpc->fault(c, 500, "Reply failed"); return; } @@ -3090,7 +3106,7 @@ void tm_reply_mutex_lock(tm_cell_t *t) int mypid; mypid = my_pid(); - if (likely(atomic_get(&t->reply_locker_pid) != mypid)) { + if(likely(atomic_get(&t->reply_locker_pid) != mypid)) { lock(&t->reply_mutex); atomic_set(&t->reply_locker_pid, mypid); } else { @@ -3104,10 +3120,10 @@ void tm_reply_mutex_lock(tm_cell_t *t) */ void tm_reply_mutex_unlock(tm_cell_t *t) { - if (likely(t->reply_rec_lock_level == 0)) { + if(likely(t->reply_rec_lock_level == 0)) { atomic_set(&t->reply_locker_pid, 0); unlock(&t->reply_mutex); - } else { + } else { /* recursive locked => decrease rec. lock count */ t->reply_rec_lock_level--; } diff --git a/src/modules/tm/t_reply.h b/src/modules/tm/t_reply.h index ea287411dfb..38fe67f5cd5 100644 --- a/src/modules/tm/t_reply.h +++ b/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); diff --git a/src/modules/tm/t_serial.c b/src/modules/tm/t_serial.c index d8a78611fa6..b648631edd4 100644 --- a/src/modules/tm/t_serial.c +++ b/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 @@ int ki_t_next_contacts(struct sip_msg* msg) 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); } diff --git a/src/modules/tm/t_serial.h b/src/modules/tm/t_serial.h index b6bd0ea7075..07671cf0dba 100644 --- a/src/modules/tm/t_serial.h +++ b/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 \ No newline at end of file diff --git a/src/modules/tm/t_stats.c b/src/modules/tm/t_stats.c index 954ba387731..74a1f7799ce 100644 --- a/src/modules/tm/t_stats.c +++ b/src/modules/tm/t_stats.c @@ -20,7 +20,6 @@ */ - #include #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 @@ int init_tm_stats_child(void) } - 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; rentries[r].acc_entries; - crt=_tm_table->entries[r].cur_entries; - - acc_count+=acc; - if (accacc_max) acc_max=acc; - if (acc==0) acc_zeroes++; - - crt_count+=crt; - if (crtcrt_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; rentries[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; rentries[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(); } diff --git a/src/modules/tm/t_stats.h b/src/modules/tm/t_stats.h index 2cb257a552e..65a30659d06 100644 --- a/src/modules/tm/t_stats.h +++ b/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 diff --git a/src/modules/tm/t_suspend.c b/src/modules/tm/t_suspend.c index 4e25c3c89b1..ab03c55091f 100644 --- a/src/modules/tm/t_suspend.c +++ b/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=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 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label, /* 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 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label, 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 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label, /* 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 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label, 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 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label, } /* 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 @@ static int t_continue_helper(unsigned int hash_index, unsigned int label, 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; } - diff --git a/src/modules/tm/t_suspend.h b/src/modules/tm/t_suspend.h index 07c4e7bc37e..e3297719b20 100644 --- a/src/modules/tm/t_suspend.h +++ b/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); diff --git a/src/modules/tm/timer.c b/src/modules/tm/timer.c index 222038e6817..614217ac734 100644 --- a/src/modules/tm/timer.c +++ b/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) { diff --git a/src/modules/tm/timer.h b/src/modules/tm/timer.h index fa96beb90e5..23f0ac92e4b 100644 --- a/src/modules/tm/timer.h +++ b/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; } } diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c index 470e33e663d..f8ba0f9f81b 100644 --- a/src/modules/tm/tm.c +++ b/src/modules/tm/tm.c @@ -46,7 +46,6 @@ */ - #include #include #include @@ -91,15 +90,15 @@ MODULE_VERSION /* fixup functions */ -static int fixup_hostport2proxy(void** param, int param_no); -static int fixup_proto_hostport2proxy(void** param, int param_no); -static int fixup_on_failure(void** param, int param_no); -static int fixup_on_branch_failure(void** param, int param_no); -static int fixup_on_reply(void** param, int param_no); -static int fixup_on_branch(void** param, int param_no); -static int fixup_t_reply(void** param, int param_no); -static int fixup_t_relay_to(void** param, int param_no); -static int fixup_t_is_set(void** param, int param_no); +static int fixup_hostport2proxy(void **param, int param_no); +static int fixup_proto_hostport2proxy(void **param, int param_no); +static int fixup_on_failure(void **param, int param_no); +static int fixup_on_branch_failure(void **param, int param_no); +static int fixup_on_reply(void **param, int param_no); +static int fixup_on_branch(void **param, int param_no); +static int fixup_t_reply(void **param, int param_no); +static int fixup_t_relay_to(void **param, int param_no); +static int fixup_t_is_set(void **param, int param_no); /* init functions */ static int mod_init(void); @@ -110,110 +109,108 @@ static int t_failover_parse_reply_codes(); #endif /* exported functions */ -static int w_t_check(struct sip_msg* msg, char* str, char* str2); -static int w_t_lookup_cancel(struct sip_msg* msg, char* str, char* str2); -static int w_t_reply(struct sip_msg* msg, char* str, char* str2); -static int w_t_send_reply(struct sip_msg* msg, char* p1, char* p2); -static int w_t_release(struct sip_msg* msg, char* str, char* str2); -static int w_t_retransmit_reply(struct sip_msg* p_msg, char* foo, char* bar ); -static int w_t_newtran(struct sip_msg* p_msg, char* foo, char* bar ); -static int w_t_relay( struct sip_msg *p_msg , char *_foo, char *_bar); -static int w_t_relay2( struct sip_msg *p_msg , char *proxy, char*); -static int w_t_relay_to_udp( struct sip_msg *p_msg , char *proxy, char *); -static int w_t_relay_to_udp_uri( struct sip_msg *p_msg , char*, char*); +static int w_t_check(struct sip_msg *msg, char *str, char *str2); +static int w_t_lookup_cancel(struct sip_msg *msg, char *str, char *str2); +static int w_t_reply(struct sip_msg *msg, char *str, char *str2); +static int w_t_send_reply(struct sip_msg *msg, char *p1, char *p2); +static int w_t_release(struct sip_msg *msg, char *str, char *str2); +static int w_t_retransmit_reply(struct sip_msg *p_msg, char *foo, char *bar); +static int w_t_newtran(struct sip_msg *p_msg, char *foo, char *bar); +static int w_t_relay(struct sip_msg *p_msg, char *_foo, char *_bar); +static int w_t_relay2(struct sip_msg *p_msg, char *proxy, char *); +static int w_t_relay_to_udp(struct sip_msg *p_msg, char *proxy, char *); +static int w_t_relay_to_udp_uri(struct sip_msg *p_msg, char *, char *); #ifdef USE_TCP -static int w_t_relay_to_tcp( struct sip_msg *p_msg , char *proxy, char *); -static int w_t_relay_to_tcp_uri( struct sip_msg *p_msg , char*, char*); +static int w_t_relay_to_tcp(struct sip_msg *p_msg, char *proxy, char *); +static int w_t_relay_to_tcp_uri(struct sip_msg *p_msg, char *, char *); #endif #ifdef USE_TLS -static int w_t_relay_to_tls( struct sip_msg *p_msg , char *proxy, char *); -static int w_t_relay_to_tls_uri( struct sip_msg *p_msg , char*, char*); +static int w_t_relay_to_tls(struct sip_msg *p_msg, char *proxy, char *); +static int w_t_relay_to_tls_uri(struct sip_msg *p_msg, char *, char *); #endif #ifdef USE_SCTP -static int w_t_relay_to_sctp( struct sip_msg *p_msg , char *proxy, char *); -static int w_t_relay_to_sctp_uri( struct sip_msg*, char*, char*); +static int w_t_relay_to_sctp(struct sip_msg *p_msg, char *proxy, char *); +static int w_t_relay_to_sctp_uri(struct sip_msg *, char *, char *); #endif -static int w_t_relay_to_avp(struct sip_msg* msg, char* str,char*); -static int w_t_relay_to(struct sip_msg* msg, char* str,char*); -static int w_t_replicate_uri( struct sip_msg *p_msg , - char *uri, /* sip uri as string or variable */ - char *_foo /* nothing expected */ ); -static int w_t_replicate( struct sip_msg *p_msg , +static int w_t_relay_to_avp(struct sip_msg *msg, char *str, char *); +static int w_t_relay_to(struct sip_msg *msg, char *str, char *); +static int w_t_replicate_uri(struct sip_msg *p_msg, + char *uri, /* sip uri as string or variable */ + char *_foo /* nothing expected */); +static int w_t_replicate(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ); -static int w_t_replicate_udp( struct sip_msg *p_msg , + char *_foo /* nothing expected */); +static int w_t_replicate_udp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ); + char *_foo /* nothing expected */); #ifdef USE_TCP -static int w_t_replicate_tcp( struct sip_msg *p_msg , +static int w_t_replicate_tcp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ); + char *_foo /* nothing expected */); #endif #ifdef USE_TLS -static int w_t_replicate_tls( struct sip_msg *p_msg , +static int w_t_replicate_tls(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ); + char *_foo /* nothing expected */); #endif #ifdef USE_SCTP -static int w_t_replicate_sctp( struct sip_msg *p_msg , +static int w_t_replicate_sctp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ); + char *_foo /* nothing expected */); #endif -static int w_t_replicate_to(struct sip_msg* msg, char* str,char*); -static int w_t_forward_nonack(struct sip_msg* msg, char* str, char* ); -static int w_t_forward_nonack_uri(struct sip_msg* msg, char* str,char*); -static int w_t_forward_nonack_udp(struct sip_msg* msg, char* str,char*); +static int w_t_replicate_to(struct sip_msg *msg, char *str, char *); +static int w_t_forward_nonack(struct sip_msg *msg, char *str, char *); +static int w_t_forward_nonack_uri(struct sip_msg *msg, char *str, char *); +static int w_t_forward_nonack_udp(struct sip_msg *msg, char *str, char *); #ifdef USE_TCP -static int w_t_forward_nonack_tcp(struct sip_msg*, char* str,char*); +static int w_t_forward_nonack_tcp(struct sip_msg *, char *str, char *); #endif #ifdef USE_TLS -static int w_t_forward_nonack_tls(struct sip_msg*, char* str,char*); +static int w_t_forward_nonack_tls(struct sip_msg *, char *str, char *); #endif #ifdef USE_SCTP -static int w_t_forward_nonack_sctp(struct sip_msg*, char* str,char*); +static int w_t_forward_nonack_sctp(struct sip_msg *, char *str, char *); #endif -static int w_t_forward_nonack_to(struct sip_msg* msg, char* str,char*); -static int w_t_relay_cancel(struct sip_msg *p_msg, char *_foo, - char *_bar); -static int w_t_on_failure(struct sip_msg* msg, char *go_to, char *foo); -static int w_t_on_branch_failure(struct sip_msg* msg, char *go_to, - char *foo); -static int w_t_on_branch(struct sip_msg* msg, char *go_to, char *foo); -static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo ); -static int t_check_status(struct sip_msg* msg, char *match, char *foo); -static int t_set_fr_inv(struct sip_msg* msg, char* fr_inv, char* foo); -static int t_set_fr_all(struct sip_msg* msg, char* fr_inv, char* fr); -static int w_t_reset_fr(struct sip_msg* msg, char* foo, char* bar); -static int w_t_set_retr(struct sip_msg* msg, char* retr_t1, char* retr_t2); -static int w_t_reset_retr(struct sip_msg* msg, char* foo, char* bar); -static int w_t_set_max_lifetime(struct sip_msg* msg, char* inv, char* noninv); -static int w_t_reset_max_lifetime(struct sip_msg* msg, char* foo, char* bar); -static int w_t_set_auto_inv_100(struct sip_msg* msg, char* on_off, char* foo); -static int w_t_set_disable_6xx(struct sip_msg* msg, char* on_off, char* foo); -static int w_t_set_disable_failover(struct sip_msg* msg, char* on_off, char* f); -static int w_t_set_no_e2e_cancel_reason(struct sip_msg* msg, char* on_off, - char* f); -static int w_t_set_disable_internal_reply(struct sip_msg* msg, char* on_off, - char* f); -static int w_t_branch_timeout(struct sip_msg* msg, char*, char*); -static int w_t_branch_replied(struct sip_msg* msg, char*, char*); -static int w_t_any_timeout(struct sip_msg* msg, char*, char*); -static int w_t_any_replied(struct sip_msg* msg, char*, char*); -static int w_t_is_canceled(struct sip_msg* msg, char*, char*); -static int w_t_is_expired(struct sip_msg* msg, char*, char*); -static int w_t_is_retr_async_reply(struct sip_msg* msg, char*, char*); -static int w_t_grep_status(struct sip_msg* msg, char*, char*); -static int w_t_drop_replies(struct sip_msg* msg, char* foo, char* bar); -static int w_t_save_lumps(struct sip_msg* msg, char* foo, char* bar); -static int w_t_check_trans(struct sip_msg* msg, char* foo, char* bar); -static int w_t_is_set(struct sip_msg* msg, char* target, char* bar); -static int w_t_use_uac_headers(sip_msg_t* msg, char* foo, char* bar); -static int w_t_uac_send(sip_msg_t* msg, char* pmethod, char* pruri, - char* pnexthop, char* psock, char *phdrs, char* pbody); -static int w_t_get_status_code(sip_msg_t* msg, char *p1, char *p2); - -static int t_clean(struct sip_msg* msg, char* key, char* value); -static int w_t_exists(struct sip_msg* msg, char* p1, char* p2); +static int w_t_forward_nonack_to(struct sip_msg *msg, char *str, char *); +static int w_t_relay_cancel(struct sip_msg *p_msg, char *_foo, char *_bar); +static int w_t_on_failure(struct sip_msg *msg, char *go_to, char *foo); +static int w_t_on_branch_failure(struct sip_msg *msg, char *go_to, char *foo); +static int w_t_on_branch(struct sip_msg *msg, char *go_to, char *foo); +static int w_t_on_reply(struct sip_msg *msg, char *go_to, char *foo); +static int t_check_status(struct sip_msg *msg, char *match, char *foo); +static int t_set_fr_inv(struct sip_msg *msg, char *fr_inv, char *foo); +static int t_set_fr_all(struct sip_msg *msg, char *fr_inv, char *fr); +static int w_t_reset_fr(struct sip_msg *msg, char *foo, char *bar); +static int w_t_set_retr(struct sip_msg *msg, char *retr_t1, char *retr_t2); +static int w_t_reset_retr(struct sip_msg *msg, char *foo, char *bar); +static int w_t_set_max_lifetime(struct sip_msg *msg, char *inv, char *noninv); +static int w_t_reset_max_lifetime(struct sip_msg *msg, char *foo, char *bar); +static int w_t_set_auto_inv_100(struct sip_msg *msg, char *on_off, char *foo); +static int w_t_set_disable_6xx(struct sip_msg *msg, char *on_off, char *foo); +static int w_t_set_disable_failover(struct sip_msg *msg, char *on_off, char *f); +static int w_t_set_no_e2e_cancel_reason( + struct sip_msg *msg, char *on_off, char *f); +static int w_t_set_disable_internal_reply( + struct sip_msg *msg, char *on_off, char *f); +static int w_t_branch_timeout(struct sip_msg *msg, char *, char *); +static int w_t_branch_replied(struct sip_msg *msg, char *, char *); +static int w_t_any_timeout(struct sip_msg *msg, char *, char *); +static int w_t_any_replied(struct sip_msg *msg, char *, char *); +static int w_t_is_canceled(struct sip_msg *msg, char *, char *); +static int w_t_is_expired(struct sip_msg *msg, char *, char *); +static int w_t_is_retr_async_reply(struct sip_msg *msg, char *, char *); +static int w_t_grep_status(struct sip_msg *msg, char *, char *); +static int w_t_drop_replies(struct sip_msg *msg, char *foo, char *bar); +static int w_t_save_lumps(struct sip_msg *msg, char *foo, char *bar); +static int w_t_check_trans(struct sip_msg *msg, char *foo, char *bar); +static int w_t_is_set(struct sip_msg *msg, char *target, char *bar); +static int w_t_use_uac_headers(sip_msg_t *msg, char *foo, char *bar); +static int w_t_uac_send(sip_msg_t *msg, char *pmethod, char *pruri, + char *pnexthop, char *psock, char *phdrs, char *pbody); +static int w_t_get_status_code(sip_msg_t *msg, char *p1, char *p2); + +static int t_clean(struct sip_msg *msg, char *key, char *value); +static int w_t_exists(struct sip_msg *msg, char *p1, char *p2); /* by default the fr timers avps are not set, so that the avps won't be * searched for nothing each time a new transaction is created */ @@ -229,8 +226,8 @@ str _tm_event_callback_lres_sent = {NULL, 0}; #ifdef USE_DNS_FAILOVER str failover_reply_codes_str = {NULL, 0}; -int** failover_reply_codes = NULL; -int* failover_reply_codes_cnt; +int **failover_reply_codes = NULL; +int *failover_reply_codes_cnt; #endif /* control if reply should be relayed @@ -238,7 +235,7 @@ int* failover_reply_codes_cnt; int tm_reply_relay_mode = 1; unsigned long tm_exec_time_check = 0; /* microseconds */ -int tm_exec_time_check_param = 5000; /* milliseconds */ +int tm_exec_time_check_param = 5000; /* milliseconds */ int tm_failure_exec_mode = 0; @@ -248,316 +245,325 @@ static rpc_export_t tm_rpc[]; str tm_event_callback = STR_NULL; -static int fixup_t_check_status(void** param, int param_no); - -static cmd_export_t cmds[]={ - {"t_newtran", w_t_newtran, 0, 0, 0, - REQUEST_ROUTE}, - {"t_lookup_request", w_t_check, 0, 0, 0, - REQUEST_ROUTE}, - {"t_lookup_cancel", w_t_lookup_cancel, 0, 0, 0, - REQUEST_ROUTE}, - {"t_lookup_cancel", w_t_lookup_cancel, 1, fixup_int_1, 0, - REQUEST_ROUTE}, - {"t_reply", w_t_reply, 2, fixup_t_reply, 0, - REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE }, - {"t_send_reply", w_t_send_reply, 2, fixup_t_reply, 0, - REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE }, - {"t_retransmit_reply", w_t_retransmit_reply, 0, 0, 0, - REQUEST_ROUTE}, - {"t_release", w_t_release, 0, 0, 0, - REQUEST_ROUTE}, - {"t_relay_to_udp", w_t_relay_to_udp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, - {"t_relay_to_udp", w_t_relay_to_udp_uri, 0, 0, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, +static int fixup_t_check_status(void **param, int param_no); + +static cmd_export_t cmds[] = { + {"t_newtran", w_t_newtran, 0, 0, 0, REQUEST_ROUTE}, + {"t_lookup_request", w_t_check, 0, 0, 0, REQUEST_ROUTE}, + {"t_lookup_cancel", w_t_lookup_cancel, 0, 0, 0, REQUEST_ROUTE}, + {"t_lookup_cancel", w_t_lookup_cancel, 1, fixup_int_1, 0, + REQUEST_ROUTE}, + {"t_reply", w_t_reply, 2, fixup_t_reply, 0, + REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE}, + {"t_send_reply", w_t_send_reply, 2, fixup_t_reply, 0, + REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE}, + {"t_retransmit_reply", w_t_retransmit_reply, 0, 0, 0, REQUEST_ROUTE}, + {"t_release", w_t_release, 0, 0, 0, REQUEST_ROUTE}, + {"t_relay_to_udp", w_t_relay_to_udp, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay_to_udp", w_t_relay_to_udp_uri, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, #ifdef USE_TCP - {"t_relay_to_tcp", w_t_relay_to_tcp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, - {"t_relay_to_tcp", w_t_relay_to_tcp_uri, 0, 0, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, + {"t_relay_to_tcp", w_t_relay_to_tcp, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay_to_tcp", w_t_relay_to_tcp_uri, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, #endif #ifdef USE_TLS - {"t_relay_to_tls", w_t_relay_to_tls, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, - {"t_relay_to_tls", w_t_relay_to_tls_uri, 0, 0, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, + {"t_relay_to_tls", w_t_relay_to_tls, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay_to_tls", w_t_relay_to_tls_uri, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, #endif #ifdef USE_SCTP - {"t_relay_to_sctp", w_t_relay_to_sctp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, - {"t_relay_to_sctp", w_t_relay_to_sctp_uri, 0, 0, 0, - REQUEST_ROUTE|FAILURE_ROUTE}, + {"t_relay_to_sctp", w_t_relay_to_sctp, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay_to_sctp", w_t_relay_to_sctp_uri, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, #endif - {"t_replicate", w_t_replicate_uri, 0, 0, 0, - REQUEST_ROUTE}, - {"t_replicate", w_t_replicate_uri, 1, fixup_spve_null, 0, - REQUEST_ROUTE}, - {"t_replicate", w_t_replicate, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, - {"t_replicate_udp", w_t_replicate_udp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_replicate", w_t_replicate_uri, 0, 0, 0, REQUEST_ROUTE}, + {"t_replicate", w_t_replicate_uri, 1, fixup_spve_null, 0, + REQUEST_ROUTE}, + {"t_replicate", w_t_replicate, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE}, + {"t_replicate_udp", w_t_replicate_udp, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE}, #ifdef USE_TCP - {"t_replicate_tcp", w_t_replicate_tcp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_replicate_tcp", w_t_replicate_tcp, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE}, #endif #ifdef USE_TLS - {"t_replicate_tls", w_t_replicate_tls, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_replicate_tls", w_t_replicate_tls, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE}, #endif #ifdef USE_SCTP - {"t_replicate_sctp", w_t_replicate_sctp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_replicate_sctp", w_t_replicate_sctp, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE}, #endif - {"t_replicate_to", w_t_replicate_to, 2, fixup_proto_hostport2proxy, 0, - REQUEST_ROUTE}, - {"t_relay", w_t_relay, 0, 0, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_relay", w_t_relay2, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_relay_to_avp", w_t_relay_to_avp, 2, fixup_proto_hostport2proxy, 0, - REQUEST_ROUTE}, - {"t_relay_to", w_t_relay_to, 0, 0, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_relay_to", w_t_relay_to, 1, fixup_t_relay_to, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_relay_to", w_t_relay_to, 2, fixup_t_relay_to, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_forward_nonack", w_t_forward_nonack, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, - {"t_forward_nonack_uri", w_t_forward_nonack_uri, 0, 0, 0, - REQUEST_ROUTE}, - {"t_forward_nonack_udp", w_t_forward_nonack_udp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_replicate_to", w_t_replicate_to, 2, fixup_proto_hostport2proxy, 0, + REQUEST_ROUTE}, + {"t_relay", w_t_relay, 0, 0, 0, REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay", w_t_relay2, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay_to_avp", w_t_relay_to_avp, 2, fixup_proto_hostport2proxy, 0, + REQUEST_ROUTE}, + {"t_relay_to", w_t_relay_to, 0, 0, 0, REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay_to", w_t_relay_to, 1, fixup_t_relay_to, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_relay_to", w_t_relay_to, 2, fixup_t_relay_to, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_forward_nonack", w_t_forward_nonack, 2, fixup_hostport2proxy, 0, + REQUEST_ROUTE}, + {"t_forward_nonack_uri", w_t_forward_nonack_uri, 0, 0, 0, + REQUEST_ROUTE}, + {"t_forward_nonack_udp", w_t_forward_nonack_udp, 2, + fixup_hostport2proxy, 0, REQUEST_ROUTE}, #ifdef USE_TCP - {"t_forward_nonack_tcp", w_t_forward_nonack_tcp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_forward_nonack_tcp", w_t_forward_nonack_tcp, 2, + fixup_hostport2proxy, 0, REQUEST_ROUTE}, #endif #ifdef USE_TLS - {"t_forward_nonack_tls", w_t_forward_nonack_tls, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_forward_nonack_tls", w_t_forward_nonack_tls, 2, + fixup_hostport2proxy, 0, REQUEST_ROUTE}, #endif #ifdef USE_SCTP - {"t_forward_nonack_sctp", w_t_forward_nonack_sctp, 2, fixup_hostport2proxy, 0, - REQUEST_ROUTE}, + {"t_forward_nonack_sctp", w_t_forward_nonack_sctp, 2, + fixup_hostport2proxy, 0, REQUEST_ROUTE}, #endif - {"t_forward_nonack_to", w_t_forward_nonack_to, 2, fixup_proto_hostport2proxy, 0, - REQUEST_ROUTE}, - {"t_relay_cancel", w_t_relay_cancel, 0, 0, 0, - REQUEST_ROUTE}, - {"t_on_failure", w_t_on_failure, 1, fixup_on_failure, 0, - REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE }, - {"t_on_branch_failure",w_t_on_branch_failure, 1, fixup_on_branch_failure, 0, - REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE }, - {"t_on_reply", w_t_on_reply, 1, fixup_on_reply, 0, - REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE | BRANCH_ROUTE }, - {"t_on_branch", w_t_on_branch, 1, fixup_on_branch, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_check_status", t_check_status, 1, fixup_t_check_status, 0, - REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, - {"t_write_req", t_write_req, 2, fixup_t_write, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_write_unix", t_write_unix, 2, fixup_t_write, 0, - REQUEST_ROUTE | FAILURE_ROUTE }, - {"t_set_fr", t_set_fr_inv, 1, fixup_var_int_1, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_set_fr", t_set_fr_all, 2, fixup_var_int_12, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_reset_fr", w_t_reset_fr, 0, 0, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_set_retr", w_t_set_retr, 2, fixup_var_int_12, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_reset_retr", w_t_reset_retr, 0, 0, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_set_max_lifetime", w_t_set_max_lifetime, 2, fixup_var_int_12, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_reset_max_lifetime", w_t_reset_max_lifetime, 0, 0, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_set_auto_inv_100", w_t_set_auto_inv_100, 1, fixup_var_int_1, 0, - REQUEST_ROUTE}, - {"t_set_disable_6xx", w_t_set_disable_6xx, 1, fixup_var_int_1, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_set_disable_failover", w_t_set_disable_failover, 1, fixup_var_int_1, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_set_no_e2e_cancel_reason", w_t_set_no_e2e_cancel_reason, 1, - fixup_var_int_1, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - /* alias for t_set_no_e2e_cancel_reason */ - {"t_disable_e2e_cancel_reason", w_t_set_no_e2e_cancel_reason, 1, - fixup_var_int_1, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_set_disable_internal_reply", w_t_set_disable_internal_reply, 1, - fixup_var_int_1, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_branch_timeout", w_t_branch_timeout, 0, 0, 0, - FAILURE_ROUTE|EVENT_ROUTE}, - {"t_branch_replied", w_t_branch_replied, 0, 0, 0, - FAILURE_ROUTE|EVENT_ROUTE}, - {"t_any_timeout", w_t_any_timeout, 0, 0, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_any_replied", w_t_any_replied, 0, 0, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_is_canceled", w_t_is_canceled, 0, 0, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_is_retr_async_reply", w_t_is_retr_async_reply, 0, 0, 0, - TM_ONREPLY_ROUTE}, - {"t_is_expired", w_t_is_expired, 0, 0, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_grep_status", w_t_grep_status, 1, fixup_var_int_1, 0, - REQUEST_ROUTE|TM_ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - {"t_drop_replies", w_t_drop_replies, 0, 0, 0, - FAILURE_ROUTE}, - {"t_drop_replies", w_t_drop_replies, 1, 0, 0, - FAILURE_ROUTE}, - {"t_save_lumps", w_t_save_lumps, 0, 0, 0, - REQUEST_ROUTE}, - {"t_check_trans", w_t_check_trans, 0, 0, 0, - REQUEST_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE }, - {"t_is_set", w_t_is_set, 1, fixup_t_is_set, 0, - ANY_ROUTE }, - {"t_use_uac_headers", w_t_use_uac_headers, 0, 0, 0, - ANY_ROUTE }, - {"t_uac_send", (cmd_function)w_t_uac_send, 6, fixup_spve_all, 0, - ANY_ROUTE }, - {"t_get_status_code", w_t_get_status_code, 0, 0, 0, - REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE }, - - {"t_load_contacts", t_load_contacts, 0, 0, 0, - REQUEST_ROUTE | FAILURE_ROUTE}, - {"t_load_contacts", t_load_contacts, 1, fixup_var_int_1, 0, - REQUEST_ROUTE | FAILURE_ROUTE}, - {"t_next_contacts", t_next_contacts, 0, 0, 0, - REQUEST_ROUTE | FAILURE_ROUTE}, - {"t_next_contact_flow", t_next_contact_flow, 0, 0, 0, - REQUEST_ROUTE }, - {"t_clean", t_clean, 0, 0, 0, ANY_ROUTE }, - {"t_exists", w_t_exists, 0, 0, 0, ANY_ROUTE }, - - /* not applicable from the script */ - {"load_tm", (cmd_function)load_tm, NO_SCRIPT, 0, 0, 0}, - {"load_xtm", (cmd_function)load_xtm, NO_SCRIPT, 0, 0, 0}, - {0,0,0,0,0,0} -}; - - -static param_export_t params[]={ - {"ruri_matching", PARAM_INT, &default_tm_cfg.ruri_matching }, - {"via1_matching", PARAM_INT, &default_tm_cfg.via1_matching }, - {"callid_matching", PARAM_INT, &default_tm_cfg.callid_matching }, - {"callid_cseq_matching",PARAM_INT, &default_tm_cfg.callid_cseq_matching }, - {"fr_timer", PARAM_INT, &default_tm_cfg.fr_timeout }, - {"fr_inv_timer", PARAM_INT, &default_tm_cfg.fr_inv_timeout }, - {"wt_timer", PARAM_INT, &default_tm_cfg.wait_timeout }, - {"retr_timer1", PARAM_INT, &default_tm_cfg.rt_t1_timeout_ms }, - {"retr_timer2" , PARAM_INT, &default_tm_cfg.rt_t2_timeout_ms }, - {"max_inv_lifetime", PARAM_INT, &default_tm_cfg.tm_max_inv_lifetime }, - {"max_noninv_lifetime", PARAM_INT, &default_tm_cfg.tm_max_noninv_lifetime}, - {"noisy_ctimer", PARAM_INT, &default_tm_cfg.noisy_ctimer }, - {"auto_inv_100", PARAM_INT, &default_tm_cfg.tm_auto_inv_100 }, - {"auto_inv_100_reason", PARAM_STRING, &default_tm_cfg.tm_auto_inv_100_r }, - {"unix_tx_timeout", PARAM_INT, &default_tm_cfg.tm_unix_tx_timeout }, - {"restart_fr_on_each_reply", PARAM_INT, - &default_tm_cfg.restart_fr_on_each_reply}, - {"fr_timer_avp", PARAM_STRING, &fr_timer_param }, - {"fr_inv_timer_avp", PARAM_STRING, &fr_inv_timer_param }, - {"tw_append", PARAM_STRING|PARAM_USE_FUNC, - (void*)parse_tw_append }, - {"pass_provisional_replies", PARAM_INT, - &default_tm_cfg.pass_provisional_replies }, - {"aggregate_challenges", PARAM_INT, &default_tm_cfg.tm_aggregate_auth }, - {"unmatched_cancel", PARAM_INT, &default_tm_cfg.unmatched_cancel }, - {"default_code", PARAM_INT, &default_tm_cfg.default_code }, - {"default_reason", PARAM_STRING, &default_tm_cfg.default_reason }, - {"reparse_invite", PARAM_INT, &default_tm_cfg.reparse_invite }, - {"ac_extra_hdrs", PARAM_STR, &default_tm_cfg.ac_extra_hdrs }, - {"blst_503", PARAM_INT, &default_tm_cfg.tm_blst_503 }, - {"blst_503_def_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_default }, - {"blst_503_min_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_min }, - {"blst_503_max_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_max }, - {"blst_methods_add", PARAM_INT, &default_tm_cfg.tm_blst_methods_add }, - {"blst_methods_lookup", PARAM_INT, &default_tm_cfg.tm_blst_methods_lookup}, - {"cancel_b_method", PARAM_INT, &default_tm_cfg.cancel_b_flags}, - {"reparse_on_dns_failover", PARAM_INT, - &default_tm_cfg.reparse_on_dns_failover}, - {"on_sl_reply", PARAM_STR, &on_sl_reply_name }, - {"contacts_avp", PARAM_STR, &contacts_avp }, - {"contact_flows_avp", PARAM_STR, &contact_flows_avp }, - {"disable_6xx_block", PARAM_INT, &default_tm_cfg.disable_6xx }, - {"local_ack_mode", PARAM_INT, &default_tm_cfg.local_ack_mode }, - {"failure_reply_mode", PARAM_INT, &failure_reply_mode }, - {"faked_reply_prio", PARAM_INT, &faked_reply_prio }, - {"remap_503_500", PARAM_INT, &tm_remap_503_500 }, - {"failure_exec_mode", PARAM_INT, &tm_failure_exec_mode }, - {"dns_reuse_rcv_socket",PARAM_INT, &tm_dns_reuse_rcv_socket }, - {"local_cancel_reason", PARAM_INT, &default_tm_cfg.local_cancel_reason }, - {"e2e_cancel_reason", PARAM_INT, &default_tm_cfg.e2e_cancel_reason }, - {"xavp_contact", PARAM_STR, &ulattrs_xavp_name }, - {"event_callback", PARAM_STR, &tm_event_callback }, - {"relay_100", PARAM_INT, &default_tm_cfg.relay_100 }, - {"rich_redirect" , PARAM_INT, &tm_rich_redirect }, - {"event_callback_lres_sent", PARAM_STR, &_tm_event_callback_lres_sent }, - {"exec_time_check" , PARAM_INT, &tm_exec_time_check_param }, - {"reply_relay_mode", PARAM_INT, &tm_reply_relay_mode }, - {"enable_uac_fr", PARAM_INT, &default_tm_cfg.enable_uac_fr }, + {"t_forward_nonack_to", w_t_forward_nonack_to, 2, + fixup_proto_hostport2proxy, 0, REQUEST_ROUTE}, + {"t_relay_cancel", w_t_relay_cancel, 0, 0, 0, REQUEST_ROUTE}, + {"t_on_failure", w_t_on_failure, 1, fixup_on_failure, 0, + REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE + | BRANCH_ROUTE}, + {"t_on_branch_failure", w_t_on_branch_failure, 1, + fixup_on_branch_failure, 0, + REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE + | BRANCH_ROUTE}, + {"t_on_reply", w_t_on_reply, 1, fixup_on_reply, 0, + REQUEST_ROUTE | FAILURE_ROUTE | TM_ONREPLY_ROUTE + | BRANCH_ROUTE}, + {"t_on_branch", w_t_on_branch, 1, fixup_on_branch, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_check_status", t_check_status, 1, fixup_t_check_status, 0, + REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE}, + {"t_write_req", t_write_req, 2, fixup_t_write, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_write_unix", t_write_unix, 2, fixup_t_write, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_set_fr", t_set_fr_inv, 1, fixup_var_int_1, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_set_fr", t_set_fr_all, 2, fixup_var_int_12, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_reset_fr", w_t_reset_fr, 0, 0, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_set_retr", w_t_set_retr, 2, fixup_var_int_12, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_reset_retr", w_t_reset_retr, 0, 0, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_set_max_lifetime", w_t_set_max_lifetime, 2, fixup_var_int_12, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_reset_max_lifetime", w_t_reset_max_lifetime, 0, 0, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_set_auto_inv_100", w_t_set_auto_inv_100, 1, fixup_var_int_1, 0, + REQUEST_ROUTE}, + {"t_set_disable_6xx", w_t_set_disable_6xx, 1, fixup_var_int_1, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_set_disable_failover", w_t_set_disable_failover, 1, fixup_var_int_1, + 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_set_no_e2e_cancel_reason", w_t_set_no_e2e_cancel_reason, 1, + fixup_var_int_1, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + /* alias for t_set_no_e2e_cancel_reason */ + {"t_disable_e2e_cancel_reason", w_t_set_no_e2e_cancel_reason, 1, + fixup_var_int_1, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_set_disable_internal_reply", w_t_set_disable_internal_reply, 1, + fixup_var_int_1, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_branch_timeout", w_t_branch_timeout, 0, 0, 0, + FAILURE_ROUTE | EVENT_ROUTE}, + {"t_branch_replied", w_t_branch_replied, 0, 0, 0, + FAILURE_ROUTE | EVENT_ROUTE}, + {"t_any_timeout", w_t_any_timeout, 0, 0, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_any_replied", w_t_any_replied, 0, 0, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_is_canceled", w_t_is_canceled, 0, 0, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_is_retr_async_reply", w_t_is_retr_async_reply, 0, 0, 0, + TM_ONREPLY_ROUTE}, + {"t_is_expired", w_t_is_expired, 0, 0, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_grep_status", w_t_grep_status, 1, fixup_var_int_1, 0, + REQUEST_ROUTE | TM_ONREPLY_ROUTE | FAILURE_ROUTE + | BRANCH_ROUTE}, + {"t_drop_replies", w_t_drop_replies, 0, 0, 0, FAILURE_ROUTE}, + {"t_drop_replies", w_t_drop_replies, 1, 0, 0, FAILURE_ROUTE}, + {"t_save_lumps", w_t_save_lumps, 0, 0, 0, REQUEST_ROUTE}, + {"t_check_trans", w_t_check_trans, 0, 0, 0, + REQUEST_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE}, + {"t_is_set", w_t_is_set, 1, fixup_t_is_set, 0, ANY_ROUTE}, + {"t_use_uac_headers", w_t_use_uac_headers, 0, 0, 0, ANY_ROUTE}, + {"t_uac_send", (cmd_function)w_t_uac_send, 6, fixup_spve_all, 0, + ANY_ROUTE}, + {"t_get_status_code", w_t_get_status_code, 0, 0, 0, + REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE}, + + {"t_load_contacts", t_load_contacts, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_load_contacts", t_load_contacts, 1, fixup_var_int_1, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_next_contacts", t_next_contacts, 0, 0, 0, + REQUEST_ROUTE | FAILURE_ROUTE}, + {"t_next_contact_flow", t_next_contact_flow, 0, 0, 0, REQUEST_ROUTE}, + {"t_clean", t_clean, 0, 0, 0, ANY_ROUTE}, + {"t_exists", w_t_exists, 0, 0, 0, ANY_ROUTE}, + + /* not applicable from the script */ + {"load_tm", (cmd_function)load_tm, NO_SCRIPT, 0, 0, 0}, + {"load_xtm", (cmd_function)load_xtm, NO_SCRIPT, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}}; + + +static param_export_t params[] = { + {"ruri_matching", PARAM_INT, &default_tm_cfg.ruri_matching}, + {"via1_matching", PARAM_INT, &default_tm_cfg.via1_matching}, + {"callid_matching", PARAM_INT, &default_tm_cfg.callid_matching}, + {"callid_cseq_matching", PARAM_INT, + &default_tm_cfg.callid_cseq_matching}, + {"fr_timer", PARAM_INT, &default_tm_cfg.fr_timeout}, + {"fr_inv_timer", PARAM_INT, &default_tm_cfg.fr_inv_timeout}, + {"wt_timer", PARAM_INT, &default_tm_cfg.wait_timeout}, + {"retr_timer1", PARAM_INT, &default_tm_cfg.rt_t1_timeout_ms}, + {"retr_timer2", PARAM_INT, &default_tm_cfg.rt_t2_timeout_ms}, + {"max_inv_lifetime", PARAM_INT, &default_tm_cfg.tm_max_inv_lifetime}, + {"max_noninv_lifetime", PARAM_INT, + &default_tm_cfg.tm_max_noninv_lifetime}, + {"noisy_ctimer", PARAM_INT, &default_tm_cfg.noisy_ctimer}, + {"auto_inv_100", PARAM_INT, &default_tm_cfg.tm_auto_inv_100}, + {"auto_inv_100_reason", PARAM_STRING, + &default_tm_cfg.tm_auto_inv_100_r}, + {"unix_tx_timeout", PARAM_INT, &default_tm_cfg.tm_unix_tx_timeout}, + {"restart_fr_on_each_reply", PARAM_INT, + &default_tm_cfg.restart_fr_on_each_reply}, + {"fr_timer_avp", PARAM_STRING, &fr_timer_param}, + {"fr_inv_timer_avp", PARAM_STRING, &fr_inv_timer_param}, + {"tw_append", PARAM_STRING | PARAM_USE_FUNC, (void *)parse_tw_append}, + {"pass_provisional_replies", PARAM_INT, + &default_tm_cfg.pass_provisional_replies}, + {"aggregate_challenges", PARAM_INT, &default_tm_cfg.tm_aggregate_auth}, + {"unmatched_cancel", PARAM_INT, &default_tm_cfg.unmatched_cancel}, + {"default_code", PARAM_INT, &default_tm_cfg.default_code}, + {"default_reason", PARAM_STRING, &default_tm_cfg.default_reason}, + {"reparse_invite", PARAM_INT, &default_tm_cfg.reparse_invite}, + {"ac_extra_hdrs", PARAM_STR, &default_tm_cfg.ac_extra_hdrs}, + {"blst_503", PARAM_INT, &default_tm_cfg.tm_blst_503}, + {"blst_503_def_timeout", PARAM_INT, + &default_tm_cfg.tm_blst_503_default}, + {"blst_503_min_timeout", PARAM_INT, &default_tm_cfg.tm_blst_503_min}, + {"blst_503_max_timeout", PARAM_INT, &default_tm_cfg.tm_blst_503_max}, + {"blst_methods_add", PARAM_INT, &default_tm_cfg.tm_blst_methods_add}, + {"blst_methods_lookup", PARAM_INT, + &default_tm_cfg.tm_blst_methods_lookup}, + {"cancel_b_method", PARAM_INT, &default_tm_cfg.cancel_b_flags}, + {"reparse_on_dns_failover", PARAM_INT, + &default_tm_cfg.reparse_on_dns_failover}, + {"on_sl_reply", PARAM_STR, &on_sl_reply_name}, + {"contacts_avp", PARAM_STR, &contacts_avp}, + {"contact_flows_avp", PARAM_STR, &contact_flows_avp}, + {"disable_6xx_block", PARAM_INT, &default_tm_cfg.disable_6xx}, + {"local_ack_mode", PARAM_INT, &default_tm_cfg.local_ack_mode}, + {"failure_reply_mode", PARAM_INT, &failure_reply_mode}, + {"faked_reply_prio", PARAM_INT, &faked_reply_prio}, + {"remap_503_500", PARAM_INT, &tm_remap_503_500}, + {"failure_exec_mode", PARAM_INT, &tm_failure_exec_mode}, + {"dns_reuse_rcv_socket", PARAM_INT, &tm_dns_reuse_rcv_socket}, + {"local_cancel_reason", PARAM_INT, &default_tm_cfg.local_cancel_reason}, + {"e2e_cancel_reason", PARAM_INT, &default_tm_cfg.e2e_cancel_reason}, + {"xavp_contact", PARAM_STR, &ulattrs_xavp_name}, + {"event_callback", PARAM_STR, &tm_event_callback}, + {"relay_100", PARAM_INT, &default_tm_cfg.relay_100}, + {"rich_redirect", PARAM_INT, &tm_rich_redirect}, + {"event_callback_lres_sent", PARAM_STR, &_tm_event_callback_lres_sent}, + {"exec_time_check", PARAM_INT, &tm_exec_time_check_param}, + {"reply_relay_mode", PARAM_INT, &tm_reply_relay_mode}, + {"enable_uac_fr", PARAM_INT, &default_tm_cfg.enable_uac_fr}, #ifdef USE_DNS_FAILOVER - {"failover_reply_codes",PARAM_STR, &failover_reply_codes_str }, + {"failover_reply_codes", PARAM_STR, &failover_reply_codes_str}, #endif - {0,0,0} -}; + {0, 0, 0}}; #ifdef STATIC_TM struct module_exports tm_exports = { #else -struct module_exports exports= { +struct module_exports exports = { #endif - "tm", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* cmd (cfg function) exports */ - params, /* param exports */ - tm_rpc, /* RPC method exports */ - 0, /* pv exports */ - reply_received, /* response handling function */ - mod_init, /* module init function */ - child_init, /* per-child init function */ - tm_shutdown /* module destroy function */ + "tm", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* cmd (cfg function) exports */ + params, /* param exports */ + tm_rpc, /* RPC method exports */ + 0, /* pv exports */ + reply_received, /* response handling function */ + mod_init, /* module init function */ + child_init, /* per-child init function */ + tm_shutdown /* module destroy function */ }; - /* helper for fixup_on_* */ -static int fixup_routes(char* r_type, struct route_list* rt, void** param) +static int fixup_routes(char *r_type, struct route_list *rt, void **param) { int i; - i=route_get(rt, (char*)*param); - if (i==-1){ + i = route_get(rt, (char *)*param); + if(i == -1) { LM_ERR("route_get failed\n"); return E_UNSPEC; } - if (r_type && rt->rlist[i]==0){ - LM_WARN("%s(\"%s\"): empty/non existing route\n", - r_type, (char*)*param); + if(r_type && rt->rlist[i] == 0) { + LM_WARN("%s(\"%s\"): empty/non existing route\n", r_type, + (char *)*param); } - *param=(void*)(long)i; + *param = (void *)(long)i; return 0; } -static int fixup_t_reply(void** param, int param_no) +static int fixup_t_reply(void **param, int param_no) { - if (param_no == 1) { - if (fixup_var_int_12(param, 1) != 0) return -1; - } else if (param_no == 2) { + if(param_no == 1) { + if(fixup_var_int_12(param, 1) != 0) + return -1; + } else if(param_no == 2) { return fixup_var_str_12(param, 2); } return 0; } -static int fixup_on_failure(void** param, int param_no) +static int fixup_on_failure(void **param, int param_no) { - if (param_no==1){ - if(strlen((char*)*param)<=1 - && (*(char*)(*param)==0 || *(char*)(*param)=='0')) { - *param = (void*)0; + if(param_no == 1) { + if(strlen((char *)*param) <= 1 + && (*(char *)(*param) == 0 || *(char *)(*param) == '0')) { + *param = (void *)0; return 0; } return fixup_routes("t_on_failure", &failure_rt, param); @@ -566,31 +572,32 @@ static int fixup_on_failure(void** param, int param_no) } #define BRANCH_FAILURE_ROUTE_PREFIX "tm:branch-failure" -static int fixup_on_branch_failure(void** param, int param_no) +static int fixup_on_branch_failure(void **param, int param_no) { char *full_route_name = NULL; - int blen =0; + int blen = 0; int bsize = 0; int ret = 0; - if (param_no==1) { - bsize = strlen((char*)*param); - if((bsize <=1) && (*(char*)(*param)==0 || *(char*)(*param)=='0')) { - *param = (void*)0; + if(param_no == 1) { + bsize = strlen((char *)*param); + if((bsize <= 1) + && (*(char *)(*param) == 0 || *(char *)(*param) == '0')) { + *param = (void *)0; return 0; } bsize += strlen(BRANCH_FAILURE_ROUTE_PREFIX) + 2; - if ((full_route_name = pkg_malloc(bsize)) == NULL) { + if((full_route_name = pkg_malloc(bsize)) == NULL) { LM_ERR("No memory left in branch_failure fixup\n"); return -1; } blen = snprintf(full_route_name, bsize, "%s:%s", - BRANCH_FAILURE_ROUTE_PREFIX, (char*)*param); - if(blen<0 || blen>=bsize) { + BRANCH_FAILURE_ROUTE_PREFIX, (char *)*param); + if(blen < 0 || blen >= bsize) { LM_ERR("Failure to construct route block name\n"); pkg_free(full_route_name); return -1; } - *param=(void*)full_route_name; + *param = (void *)full_route_name; ret = fixup_routes("t_on_branch_failure", &event_rt, param); pkg_free(full_route_name); } @@ -598,12 +605,12 @@ static int fixup_on_branch_failure(void** param, int param_no) } -static int fixup_on_reply(void** param, int param_no) +static int fixup_on_reply(void **param, int param_no) { - if (param_no==1){ - if(strlen((char*)*param)<=1 - && (*(char*)(*param)==0 || *(char*)(*param)=='0')) { - *param = (void*)0; + if(param_no == 1) { + if(strlen((char *)*param) <= 1 + && (*(char *)(*param) == 0 || *(char *)(*param) == '0')) { + *param = (void *)0; return 0; } return fixup_routes("t_on_reply", &onreply_rt, param); @@ -612,13 +619,12 @@ static int fixup_on_reply(void** param, int param_no) } - -static int fixup_on_branch(void** param, int param_no) +static int fixup_on_branch(void **param, int param_no) { - if (param_no==1){ - if(strlen((char*)*param)<=1 - && (*(char*)(*param)==0 || *(char*)(*param)=='0')) { - *param = (void*)0; + if(param_no == 1) { + if(strlen((char *)*param) <= 1 + && (*(char *)(*param) == 0 || *(char *)(*param) == '0')) { + *param = (void *)0; return 0; } return fixup_routes("t_on_branch", &branch_rt, param); @@ -628,7 +634,7 @@ static int fixup_on_branch(void** param, int param_no) /* (char *hostname, char *port_nr) ==> (struct proxy_l *, -) */ -static int fixup_hostport2proxy(void** param, int param_no) +static int fixup_hostport2proxy(void **param, int param_no) { unsigned int port; char *host; @@ -637,29 +643,27 @@ static int fixup_hostport2proxy(void** param, int param_no) action_u_t *a; str s; - DBG("TM module: fixup_hostport2proxy(%s, %d)\n", (char*)*param, param_no); - if (param_no==1){ + DBG("TM module: fixup_hostport2proxy(%s, %d)\n", (char *)*param, param_no); + if(param_no == 1) { return 0; - } else if (param_no==2) { + } else if(param_no == 2) { a = fixup_get_param(param, param_no, 1); - host= a->u.string; - port=str2s(*param, strlen(*param), &err); - if (err!=0) { - LM_ERR("bad port number <%s>\n", - (char*)(*param)); + host = a->u.string; + port = str2s(*param, strlen(*param), &err); + if(err != 0) { + LM_ERR("bad port number <%s>\n", (char *)(*param)); return E_UNSPEC; } s.s = host; s.len = strlen(host); - proxy=mk_proxy(&s, port, 0); /* FIXME: udp or tcp? */ - if (proxy==0) { - LM_ERR("bad host name in URI <%s>\n", - host ); + proxy = mk_proxy(&s, port, 0); /* FIXME: udp or tcp? */ + if(proxy == 0) { + LM_ERR("bad host name in URI <%s>\n", host); return E_BAD_ADDRESS; } /* success -- fix the first parameter to proxy now ! */ - a->u.data=proxy; + a->u.data = proxy; return 0; } else { LM_ERR("called with parameter number different than {1,2}\n"); @@ -668,42 +672,49 @@ static int fixup_hostport2proxy(void** param, int param_no) } /* (char *$proto, char *$host:port) ==> (fparam, fparam) */ -static int fixup_proto_hostport2proxy(void** param, int param_no) { +static int fixup_proto_hostport2proxy(void **param, int param_no) +{ int ret; ret = fix_param(FPARAM_AVP, param); - if (ret <= 0) return ret; - if (fix_param(FPARAM_STRING, param) != 0) return -1; + if(ret <= 0) + return ret; + if(fix_param(FPARAM_STRING, param) != 0) + return -1; return 0; } -static int fixup_t_check_status(void** param, int param_no) +static int fixup_t_check_status(void **param, int param_no) { int ret; ret = fix_param(FPARAM_PVS, param); - if (ret <= 0) return ret; + if(ret <= 0) + return ret; ret = fix_param(FPARAM_AVP, param); - if (ret <= 0) return ret; + if(ret <= 0) + return ret; ret = fix_param(FPARAM_SELECT, param); - if (ret <= 0) return ret; + if(ret <= 0) + return ret; - if (fix_param(FPARAM_REGEX, param) != 0) return -1; + if(fix_param(FPARAM_REGEX, param) != 0) + return -1; return 0; } /***************************** init functions *****************************/ -static int w_t_unref( struct sip_msg *foo, unsigned int flags, void *bar) +static int w_t_unref(struct sip_msg *foo, unsigned int flags, void *bar) { return t_unref(foo); } -static int script_init( struct sip_msg *foo, unsigned int flags, void *bar) +static int script_init(struct sip_msg *foo, unsigned int flags, void *bar) { /* we primarily reset all private memory here to make sure * private values left over from previous message will @@ -712,7 +723,7 @@ static int script_init( struct sip_msg *foo, unsigned int flags, void *bar) /* make sure the new message will not inherit previous message's t_on_failure value */ - t_on_failure( 0 ); + t_on_failure(0); t_on_branch_failure(0); t_on_reply(0); t_on_branch(0); @@ -730,7 +741,7 @@ static int mod_init(void) { sr_kemi_eng_t *keng = NULL; - DBG( "TM - (sizeof cell=%ld, sip_msg=%ld) initializing...\n", + DBG("TM - (sizeof cell=%ld, sip_msg=%ld) initializing...\n", (long)sizeof(struct cell), (long)sizeof(struct sip_msg)); if(tm_exec_time_check_param > 0) { @@ -739,34 +750,34 @@ static int mod_init(void) /* checking if we have sufficient bitmap capacity for given * maximum number of branches */ - if (sr_dst_max_branches+1>31) { + if(sr_dst_max_branches + 1 > 31) { LM_CRIT("Too many max UACs for UAC branch_bm_t bitmap: %d\n", - sr_dst_max_branches ); + sr_dst_max_branches); return -1; } - if(tm_rpc_response_list_init()<0) { + if(tm_rpc_response_list_init() < 0) { LM_ERR("failed to init rpc\n"); return -1; } - if(on_sl_reply_name.s!=NULL && on_sl_reply_name.len>0) { + if(on_sl_reply_name.s != NULL && on_sl_reply_name.len > 0) { keng = sr_kemi_eng_get(); - if(keng==NULL) { - goto_on_sl_reply=route_get(&onreply_rt, on_sl_reply_name.s); - if (goto_on_sl_reply==-1){ + if(keng == NULL) { + goto_on_sl_reply = route_get(&onreply_rt, on_sl_reply_name.s); + if(goto_on_sl_reply == -1) { LM_ERR("route get failed for on_sl_reply\n"); return -1; } } } - if (init_callid() < 0) { + if(init_callid() < 0) { LM_CRIT("Error while initializing Call-ID generator\n"); return -1; } /* building the hash table*/ - if (!init_hash_table()) { + if(!init_hash_table()) { LM_ERR("initializing hash_table failed\n"); return -1; } @@ -774,22 +785,23 @@ static int mod_init(void) /* init static hidden values */ init_t(); - if (tm_init_selects()==-1) { + if(tm_init_selects() == -1) { LM_ERR("select init failed\n"); return -1; } /* the default timer values must be fixed-up before * declaring the configuration (Miklos) */ - if (tm_init_timers()==-1) { + if(tm_init_timers() == -1) { LM_ERR("timer init failed\n"); return -1; } /* the cancel branch flags must be fixed before declaring the * configuration */ - if (cancel_b_flags_get(&default_tm_cfg.cancel_b_flags, - default_tm_cfg.cancel_b_flags)<0){ + if(cancel_b_flags_get( + &default_tm_cfg.cancel_b_flags, default_tm_cfg.cancel_b_flags) + < 0) { LM_ERR("bad cancel branch method\n"); return -1; } @@ -807,15 +819,15 @@ static int mod_init(void) } } - if (default_tm_cfg.reparse_on_dns_failover && mhomed) { + if(default_tm_cfg.reparse_on_dns_failover && mhomed) { LM_WARN("reparse_on_dns_failover is enabled on a" " multihomed host -- check the readme of tm module!\n"); } #endif /* declare the configuration */ - if (cfg_declare("tm", tm_cfg_def, &default_tm_cfg, cfg_sizeof(tm), - &tm_cfg)) { + if(cfg_declare( + "tm", tm_cfg_def, &default_tm_cfg, cfg_sizeof(tm), &tm_cfg)) { LM_ERR("failed to declare the configuration\n"); return -1; } @@ -825,55 +837,55 @@ static int mod_init(void) * init with init_tm_stats_child when the final value of * estimated_process_count is known */ - if (init_tm_stats() < 0) { + if(init_tm_stats() < 0) { LM_CRIT("failed to init stats\n"); return -1; } - if (uac_init()==-1) { + if(uac_init() == -1) { LM_ERR("uac_init failed\n"); return -1; } - if (init_tmcb_lists()!=1) { + if(init_tmcb_lists() != 1) { LM_CRIT("failed to init tmcb lists\n"); return -1; } tm_init_tags(); init_twrite_lines(); - if (init_twrite_sock() < 0) { + if(init_twrite_sock() < 0) { LM_ERR("Unable to create socket\n"); return -1; } /* register post-script clean-up function */ - if (register_script_cb( w_t_unref, POST_SCRIPT_CB|REQUEST_CB, 0)<0 ) { + if(register_script_cb(w_t_unref, POST_SCRIPT_CB | REQUEST_CB, 0) < 0) { LM_ERR("failed to register POST request callback\n"); return -1; } - if (register_script_cb( script_init, PRE_SCRIPT_CB|REQUEST_CB , 0)<0 ) { + if(register_script_cb(script_init, PRE_SCRIPT_CB | REQUEST_CB, 0) < 0) { LM_ERR("failed to register PRE request callback\n"); return -1; } - if (init_avp_params(fr_timer_param, fr_inv_timer_param) < 0) { + if(init_avp_params(fr_timer_param, fr_inv_timer_param) < 0) { LM_ERR("failed to process AVP params\n"); return -1; } - if ((contacts_avp.len > 0) && (contact_flows_avp.len == 0)) { + if((contacts_avp.len > 0) && (contact_flows_avp.len == 0)) { LM_ERR("contact_flows_avp param has not been defined\n"); return -1; } #ifdef WITH_EVENT_LOCAL_REQUEST - goto_on_local_req=route_lookup(&event_rt, "tm:local-request"); - if (goto_on_local_req>=0 && event_rt.rlist[goto_on_local_req]==0) - goto_on_local_req=-1; /* disable */ - if (goto_on_local_req>=0 || tm_event_callback.len>0) + goto_on_local_req = route_lookup(&event_rt, "tm:local-request"); + if(goto_on_local_req >= 0 && event_rt.rlist[goto_on_local_req] == 0) + goto_on_local_req = -1; /* disable */ + if(goto_on_local_req >= 0 || tm_event_callback.len > 0) set_child_rpc_sip_mode(); #endif /* WITH_EVENT_LOCAL_REQUEST */ - if (goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply]==0) + if(goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply] == 0) LM_WARN("empty/non existing on_sl_reply route\n"); #ifdef WITH_TM_CTX @@ -885,16 +897,16 @@ static int mod_init(void) static int child_init(int rank) { - if (rank == PROC_INIT) { + if(rank == PROC_INIT) { /* we must init stats when rank==PROC_INIT: after mod_init we know * the exact number of processes and we must init the shared structure * before any other process is starting (or else some new process * might try to use the stats before the stats array is allocated) */ - if (init_tm_stats_child() < 0) { + if(init_tm_stats_child() < 0) { LM_ERR("Error while initializing tm statistics structures\n"); return -1; } - }else if (child_init_callid(rank) < 0) { + } else if(child_init_callid(rank) < 0) { /* don't init callid for PROC_INIT*/ LM_ERR("Error while initializing Call-ID generator\n"); return -2; @@ -905,17 +917,18 @@ static int child_init(int rank) /**************************** wrapper functions ***************************/ -static int ki_t_get_status_code(sip_msg_t* msg) +static int ki_t_get_status_code(sip_msg_t *msg) { int scode = -1; int ret; tm_cell_t *t = NULL; /* first get the transaction */ - if (t_check(msg, 0 ) == -1) return -1; - if ((t = get_t()) == 0) { + if(t_check(msg, 0) == -1) + return -1; + if((t = get_t()) == 0) { LM_ERR("cannot check status for a reply" - " which has no T-state established\n"); + " which has no T-state established\n"); goto error; } @@ -933,16 +946,16 @@ static int ki_t_get_status_code(sip_msg_t* msg) case FAILURE_ROUTE: /* use the status of the winning reply */ - ret = t_pick_branch( -1, 0, t, &scode); - if (ret == -1) { + ret = t_pick_branch(-1, 0, t, &scode); + if(ret == -1) { /* t_pick_branch() retuns error also when there are only * blind UACs. Let us give it another chance including the * blind branches. */ LM_DBG("t_pick_branch returned error," - " trying t_pick_branch_blind\n"); + " trying t_pick_branch_blind\n"); ret = t_pick_branch_blind(t, &scode); } - if (ret < 0) { + if(ret < 0) { LM_CRIT("BUG: t_pick_branch failed to get" " a final response in FAILURE_ROUTE\n"); goto error; @@ -954,31 +967,30 @@ static int ki_t_get_status_code(sip_msg_t* msg) break; default: - LM_ERR("unsupported route type %d\n", - get_route_type()); + LM_ERR("unsupported route type %d\n", get_route_type()); goto error; } LM_DBG("t status code is <%d>\n", scode); - return (scode!=0)?scode:-1; + return (scode != 0) ? scode : -1; error: return -1; } -static int w_t_get_status_code(sip_msg_t* msg, char *p1, char *p2) +static int w_t_get_status_code(sip_msg_t *msg, char *p1, char *p2) { return ki_t_get_status_code(msg); } -static int ki_t_get_branch_index(sip_msg_t* msg) +static int ki_t_get_branch_index(sip_msg_t *msg) { tm_cell_t *t = 0; tm_ctx_t *tcx = 0; int idx = T_BR_UNDEFINED; - if(msg==NULL) { + if(msg == NULL) { return -1; } @@ -988,53 +1000,55 @@ static int ki_t_get_branch_index(sip_msg_t* msg) if(tcx != NULL) { idx = tcx->branch_index; } - } else switch(route_type) { - case BRANCH_ROUTE: - case BRANCH_FAILURE_ROUTE: - /* branch and branch_failure routes have their index set */ - tcx = tm_ctx_get(); - if(tcx != NULL) { - idx = tcx->branch_index; - } - break; - case REQUEST_ROUTE: - /* take the branch number from the number of added branches */ - idx = nr_branches; - break; - case FAILURE_ROUTE: - /* first get the transaction */ - t = get_t(); - if ( t == NULL || t == T_UNDEFINED ) { - return -1; - } - /* add the currently added branches to the number of + } else + switch(route_type) { + case BRANCH_ROUTE: + case BRANCH_FAILURE_ROUTE: + /* branch and branch_failure routes have their index set */ + tcx = tm_ctx_get(); + if(tcx != NULL) { + idx = tcx->branch_index; + } + break; + case REQUEST_ROUTE: + /* take the branch number from the number of added branches */ + idx = nr_branches; + break; + case FAILURE_ROUTE: + /* first get the transaction */ + t = get_t(); + if(t == NULL || t == T_UNDEFINED) { + return -1; + } + /* add the currently added branches to the number of * completed branches in the transaction */ - idx = t->nr_of_outgoings + nr_branches; - break; - } + idx = t->nr_of_outgoings + nr_branches; + break; + } return idx; } -static int t_check_status(struct sip_msg* msg, char *p1, char *foo) +static int t_check_status(struct sip_msg *msg, char *p1, char *foo) { regmatch_t pmatch; struct cell *t; char *status, *s = NULL; char backup; int lowest_status, n, ret; - fparam_t* fp; - regex_t* re0 = NULL; - regex_t* re = NULL; + fparam_t *fp; + regex_t *re0 = NULL; + regex_t *re = NULL; str tmp; - fp = (fparam_t*)p1; + fp = (fparam_t *)p1; t = 0; /* first get the transaction */ - if (t_check(msg, 0 ) == -1) return -1; - if ((t = get_t()) == 0) { + if(t_check(msg, 0) == -1) + return -1; + if((t = get_t()) == 0) { LM_ERR("cannot check status for a reply" - " which has no T-state established\n"); + " which has no T-state established\n"); goto error; } backup = 0; @@ -1046,21 +1060,22 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo) default: /* AVP or select, get the value and compile the regex */ - if (get_str_fparam(&tmp, msg, fp) < 0) goto error; + if(get_str_fparam(&tmp, msg, fp) < 0) + goto error; s = pkg_malloc(tmp.len + 1); - if (s == NULL) { + if(s == NULL) { LM_ERR("Out of memory\n"); goto error; } memcpy(s, tmp.s, tmp.len); s[tmp.len] = '\0'; - if ((re0 = pkg_malloc(sizeof(regex_t))) == 0) { + if((re0 = pkg_malloc(sizeof(regex_t))) == 0) { LM_ERR("No memory left\n"); goto error; } - if (regcomp(re0, s, REG_EXTENDED|REG_ICASE|REG_NEWLINE)) { + if(regcomp(re0, s, REG_EXTENDED | REG_ICASE | REG_NEWLINE)) { LM_ERR("Bad regular expression '%s'\n", s); pkg_free(re0); re0 = NULL; @@ -1073,7 +1088,7 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo) switch(get_route_type()) { case REQUEST_ROUTE: /* use the status of the last sent reply */ - status = int2str( t->uas.status, 0); + status = int2str(t->uas.status, 0); break; case TM_ONREPLY_ROUTE: @@ -1086,67 +1101,70 @@ static int t_check_status(struct sip_msg* msg, char *p1, char *foo) case FAILURE_ROUTE: /* use the status of the winning reply */ - ret = t_pick_branch( -1, 0, t, &lowest_status); - if (ret == -1) { + ret = t_pick_branch(-1, 0, t, &lowest_status); + if(ret == -1) { /* t_pick_branch() retuns error also when there are only * blind UACs. Let us give it another chance including the * blind branches. */ LM_DBG("t_pick_branch returned error," - " trying t_pick_branch_blind\n"); + " trying t_pick_branch_blind\n"); ret = t_pick_branch_blind(t, &lowest_status); } - if (ret < 0) { + if(ret < 0) { LM_CRIT("BUG: t_pick_branch failed to get" " a final response in FAILURE_ROUTE\n"); goto error; } - status = int2str( lowest_status , 0); + status = int2str(lowest_status, 0); break; case BRANCH_FAILURE_ROUTE: status = int2str(t->uac[get_t_branch()].last_received, 0); break; default: - LM_ERR("unsupported route type %d\n", - get_route_type()); + LM_ERR("unsupported route type %d\n", get_route_type()); goto error; } - LM_DBG("checked status is <%s>\n",status); + LM_DBG("checked status is <%s>\n", status); /* do the checking */ n = regexec(re, status, 1, &pmatch, 0); - if (backup) status[msg->first_line.u.reply.status.len] = backup; - if (s) pkg_free(s); - if (re0) { + if(backup) + status[msg->first_line.u.reply.status.len] = backup; + if(s) + pkg_free(s); + if(re0) { regfree(re0); pkg_free(re0); } - if (unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))){ + if(unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))) { /* t_check() above has the side effect of setting T and * REFerencing T => we must unref and unset it. */ - UNREF( t ); + UNREF(t); set_t(T_UNDEFINED, T_BR_UNDEFINED); } - if (n!=0) return -1; + if(n != 0) + return -1; return 1; error: - if (unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))){ + if(unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))) { /* t_check() above has the side effect of setting T and * REFerencing T => we must unref and unset it. */ - UNREF( t ); + UNREF(t); set_t(T_UNDEFINED, T_BR_UNDEFINED); } - if (s) pkg_free(s); - if (re0) { + if(s) + pkg_free(s); + if(re0) { regfree(re0); pkg_free(re0); } return -1; } -static int ki_t_check_status(sip_msg_t* msg, str *sexp) +static int ki_t_check_status(sip_msg_t *msg, str *sexp) { regmatch_t pmatch; struct cell *t; @@ -1156,17 +1174,18 @@ static int ki_t_check_status(sip_msg_t* msg, str *sexp) regex_t re; /* first get the transaction */ - if (t_check(msg, 0 ) == -1) return -1; + if(t_check(msg, 0) == -1) + return -1; backup = 0; - if ((t = get_t()) == 0) { + if((t = get_t()) == 0) { LM_ERR("cannot check status for a reply" - " which has no T-state established\n"); + " which has no T-state established\n"); goto error0; } memset(&re, 0, sizeof(regex_t)); - if (regcomp(&re, sexp->s, REG_EXTENDED|REG_ICASE|REG_NEWLINE)) { + if(regcomp(&re, sexp->s, REG_EXTENDED | REG_ICASE | REG_NEWLINE)) { LM_ERR("Bad regular expression '%s'\n", sexp->s); goto error0; } @@ -1187,16 +1206,16 @@ static int ki_t_check_status(sip_msg_t* msg, str *sexp) case FAILURE_ROUTE: /* use the status of the winning reply */ - ret = t_pick_branch( -1, 0, t, &lowest_status); - if (ret == -1) { + ret = t_pick_branch(-1, 0, t, &lowest_status); + if(ret == -1) { /* t_pick_branch() retuns error also when there are only * blind UACs. Let us give it another chance including the * blind branches. */ LM_DBG("t_pick_branch returned error," - " trying t_pick_branch_blind\n"); + " trying t_pick_branch_blind\n"); ret = t_pick_branch_blind(t, &lowest_status); } - if (ret < 0) { + if(ret < 0) { LM_CRIT("BUG: t_pick_branch failed to get" " a final response in FAILURE_ROUTE\n"); goto error; @@ -1207,60 +1226,61 @@ static int ki_t_check_status(sip_msg_t* msg, str *sexp) status = int2str(t->uac[get_t_branch()].last_received, 0); break; default: - LM_ERR("unsupported route type %d\n", - get_route_type()); + LM_ERR("unsupported route type %d\n", get_route_type()); goto error; } - LM_DBG("checked status is <%s>\n",status); + LM_DBG("checked status is <%s>\n", status); /* do the checking */ n = regexec(&re, status, 1, &pmatch, 0); - if (backup) status[msg->first_line.u.reply.status.len] = backup; + if(backup) + status[msg->first_line.u.reply.status.len] = backup; regfree(&re); - if (unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))){ + if(unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))) { /* t_check() above has the side effect of setting T and * REFerencing T => we must unref and unset it. */ - UNREF( t ); + UNREF(t); set_t(T_UNDEFINED, T_BR_UNDEFINED); } - if (n!=0) return -1; + if(n != 0) + return -1; return 1; error: regfree(&re); error0: - if (unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))){ + if(unlikely(t && is_route_type(CORE_ONREPLY_ROUTE))) { /* t_check() above has the side effect of setting T and * REFerencing T => we must unref and unset it. */ - UNREF( t ); + UNREF(t); set_t(T_UNDEFINED, T_BR_UNDEFINED); } return -1; } -static int w_t_check(struct sip_msg* msg, char* str, char* str2) +static int w_t_check(struct sip_msg *msg, char *str, char *str2) { - return (t_check_msg( msg , 0 )==1) ? 1 : -1; + return (t_check_msg(msg, 0) == 1) ? 1 : -1; } -static int ki_t_lookup_request(struct sip_msg* msg) +static int ki_t_lookup_request(struct sip_msg *msg) { - return (t_check_msg( msg , 0 )==1) ? 1 : -1; + return (t_check_msg(msg, 0) == 1) ? 1 : -1; } -static int ki_t_lookup_cancel_flags(sip_msg_t* msg, int flags) +static int ki_t_lookup_cancel_flags(sip_msg_t *msg, int flags) { struct cell *ret; - if (msg->REQ_METHOD==METHOD_CANCEL) { - ret = t_lookupOriginalT( msg ); + if(msg->REQ_METHOD == METHOD_CANCEL) { + ret = t_lookupOriginalT(msg); LM_DBG("lookup_original: t_lookupOriginalT returned: %p\n", ret); - if (ret != T_NULL_CELL) { + if(ret != T_NULL_CELL) { /* If the parameter is set to 1, overwrite the message flags of * the CANCEL with the flags of the INVITE */ - if (flags) + if(flags) msg->flags = ret->uas.request->flags; /* The cell is reffed by t_lookupOriginalT, but T is not set. @@ -1269,48 +1289,52 @@ static int ki_t_lookup_cancel_flags(sip_msg_t* msg, int flags) return 1; } } else { - LM_WARN("script error - t_lookup_cancel() called for non-CANCEL request\n"); + LM_WARN("script error - t_lookup_cancel() called for non-CANCEL " + "request\n"); } return -1; } -static int ki_t_lookup_cancel(sip_msg_t* msg) +static int ki_t_lookup_cancel(sip_msg_t *msg) { return ki_t_lookup_cancel_flags(msg, 0); } -static int w_t_lookup_cancel(struct sip_msg* msg, char* str, char* str2) +static int w_t_lookup_cancel(struct sip_msg *msg, char *str, char *str2) { int i = 0; if(str) { - if(get_int_fparam(&i, msg, (fparam_t*)str)<0) return -1; + if(get_int_fparam(&i, msg, (fparam_t *)str) < 0) + return -1; } return ki_t_lookup_cancel_flags(msg, i); } -inline static int str2proto(char *s, int len) { - if (len == 3 && !strncasecmp(s, "udp", 3)) +inline static int str2proto(char *s, int len) +{ + if(len == 3 && !strncasecmp(s, "udp", 3)) return PROTO_UDP; - else if (len == 3 && !strncasecmp(s, "tcp", 3)) /* tcp&tls checks will be + else if(len == 3 && !strncasecmp(s, "tcp", 3)) /* tcp&tls checks will be passed in getproto() */ return PROTO_TCP; - else if (len == 3 && !strncasecmp(s, "tls", 3)) + else if(len == 3 && !strncasecmp(s, "tls", 3)) return PROTO_TLS; - else if (len == 4 && !strncasecmp(s, "sctp", 4)) + else if(len == 4 && !strncasecmp(s, "sctp", 4)) return PROTO_SCTP; - else if (len == 2 && !strncasecmp(s, "ws", 2)) + else if(len == 2 && !strncasecmp(s, "ws", 2)) return PROTO_WS; - else if (len == 3 && !strncasecmp(s, "wss", 3)) { + else if(len == 3 && !strncasecmp(s, "wss", 3)) { LM_WARN("\"wss\" used somewhere...\n"); return PROTO_WS; } else return PROTO_NONE; } -inline static struct proxy_l* t_protoaddr2proxy(char *proto_par, char *addr_par) { +inline static struct proxy_l *t_protoaddr2proxy(char *proto_par, char *addr_par) +{ struct proxy_l *proxy = 0; - avp_t* avp; + avp_t *avp; avp_value_t val; int proto, port, err; str s; @@ -1318,14 +1342,13 @@ inline static struct proxy_l* t_protoaddr2proxy(char *proto_par, char *addr_par) switch(((fparam_t *)proto_par)->type) { case FPARAM_AVP: - if (!(avp = search_first_avp(((fparam_t *)proto_par)->v.avp.flags, - ((fparam_t *)proto_par)->v.avp.name, &val, 0))) { + if(!(avp = search_first_avp(((fparam_t *)proto_par)->v.avp.flags, + ((fparam_t *)proto_par)->v.avp.name, &val, 0))) { proto = PROTO_NONE; } else { - if (avp->flags & AVP_VAL_STR) { + if(avp->flags & AVP_VAL_STR) { proto = str2proto(val.s.s, val.s.len); - } - else { + } else { proto = val.n; } } @@ -1335,7 +1358,7 @@ inline static struct proxy_l* t_protoaddr2proxy(char *proto_par, char *addr_par) proto = ((fparam_t *)proto_par)->v.i; break; case FPARAM_STRING: - proto = str2proto( ((fparam_t *)proto_par)->v.asciiz, + proto = str2proto(((fparam_t *)proto_par)->v.asciiz, strlen(((fparam_t *)proto_par)->v.asciiz)); break; default: @@ -1346,11 +1369,11 @@ inline static struct proxy_l* t_protoaddr2proxy(char *proto_par, char *addr_par) switch(((fparam_t *)addr_par)->type) { case FPARAM_AVP: - if (!(avp = search_first_avp(((fparam_t *)addr_par)->v.avp.flags, - ((fparam_t *)addr_par)->v.avp.name, &val, 0))) { + if(!(avp = search_first_avp(((fparam_t *)addr_par)->v.avp.flags, + ((fparam_t *)addr_par)->v.avp.name, &val, 0))) { s.len = 0; } else { - if ((avp->flags & AVP_VAL_STR) == 0) { + if((avp->flags & AVP_VAL_STR) == 0) { LM_ERR("avp <%.*s> value is not string\n", ((fparam_t *)addr_par)->v.avp.name.s.len, ((fparam_t *)addr_par)->v.avp.name.s.s); @@ -1361,7 +1384,7 @@ inline static struct proxy_l* t_protoaddr2proxy(char *proto_par, char *addr_par) break; case FPARAM_STRING: - s.s = ((fparam_t *) addr_par)->v.asciiz; + s.s = ((fparam_t *)addr_par)->v.asciiz; s.len = strlen(s.s); break; @@ -1371,44 +1394,44 @@ inline static struct proxy_l* t_protoaddr2proxy(char *proto_par, char *addr_par) } port = 5060; - if (s.len) { + if(s.len) { c = memchr(s.s, ':', s.len); - if (c) { - port = str2s(c+1, s.len-(c-s.s+1), &err); - if (err!=0) { + if(c) { + port = str2s(c + 1, s.len - (c - s.s + 1), &err); + if(err != 0) { LM_ERR("bad port number <%.*s>\n", s.len, s.s); return 0; } - s.len = c-s.s; + s.len = c - s.s; } } - if (!s.len) { + if(!s.len) { LM_ERR("host name is empty\n"); return 0; } - proxy=mk_proxy(&s, port, proto); - if (proxy==0) { - LM_ERR("bad host name in URI <%.*s>\n", s.len, s.s ); + proxy = mk_proxy(&s, port, proto); + if(proxy == 0) { + LM_ERR("bad host name in URI <%.*s>\n", s.len, s.s); return 0; } return proxy; } -static int _w_t_forward_nonack(struct sip_msg* msg, struct proxy_l* proxy, - int proto) +static int _w_t_forward_nonack( + struct sip_msg *msg, struct proxy_l *proxy, int proto) { struct cell *t; - if (t_check( msg , 0 )==-1) { + if(t_check(msg, 0) == -1) { LM_ERR("can't forward when no transaction was set up\n"); return -1; } - t=get_t(); - if ( t && t!=T_UNDEFINED ) { - if (msg->REQ_METHOD==METHOD_ACK) { + t = get_t(); + if(t && t != T_UNDEFINED) { + if(msg->REQ_METHOD == METHOD_ACK) { LM_WARN("you don't really want to fwd hop-by-hop ACK\n"); return -1; } - return t_forward_nonack(t, msg, proxy, proto ); + return t_forward_nonack(t, msg, proxy, proto); } else { LM_DBG("no transaction found\n"); return -1; @@ -1416,62 +1439,55 @@ static int _w_t_forward_nonack(struct sip_msg* msg, struct proxy_l* proxy, } -static int w_t_forward_nonack( struct sip_msg* msg, char* proxy, - char* foo) +static int w_t_forward_nonack(struct sip_msg *msg, char *proxy, char *foo) { - return _w_t_forward_nonack(msg, ( struct proxy_l *) proxy, PROTO_NONE); + return _w_t_forward_nonack(msg, (struct proxy_l *)proxy, PROTO_NONE); } -static int w_t_forward_nonack_uri(struct sip_msg* msg, char *foo, - char *bar) +static int w_t_forward_nonack_uri(struct sip_msg *msg, char *foo, char *bar) { return _w_t_forward_nonack(msg, 0, PROTO_NONE); } -static int w_t_forward_nonack_udp( struct sip_msg* msg, char* proxy, - char* foo) +static int w_t_forward_nonack_udp(struct sip_msg *msg, char *proxy, char *foo) { - return _w_t_forward_nonack(msg, ( struct proxy_l *) proxy, PROTO_UDP); + return _w_t_forward_nonack(msg, (struct proxy_l *)proxy, PROTO_UDP); } #ifdef USE_TCP -static int w_t_forward_nonack_tcp( struct sip_msg* msg, char* proxy, - char* foo) +static int w_t_forward_nonack_tcp(struct sip_msg *msg, char *proxy, char *foo) { - return _w_t_forward_nonack(msg, ( struct proxy_l *) proxy, PROTO_TCP); + return _w_t_forward_nonack(msg, (struct proxy_l *)proxy, PROTO_TCP); } #endif #ifdef USE_TLS -static int w_t_forward_nonack_tls( struct sip_msg* msg, char* proxy, - char* foo) +static int w_t_forward_nonack_tls(struct sip_msg *msg, char *proxy, char *foo) { - return _w_t_forward_nonack(msg, ( struct proxy_l *) proxy, PROTO_TLS); + return _w_t_forward_nonack(msg, (struct proxy_l *)proxy, PROTO_TLS); } #endif #ifdef USE_SCTP -static int w_t_forward_nonack_sctp( struct sip_msg* msg, char* proxy, - char* foo) +static int w_t_forward_nonack_sctp(struct sip_msg *msg, char *proxy, char *foo) { - return _w_t_forward_nonack(msg, ( struct proxy_l *) proxy, PROTO_SCTP); + return _w_t_forward_nonack(msg, (struct proxy_l *)proxy, PROTO_SCTP); } #endif -static int w_t_forward_nonack_to( struct sip_msg *p_msg , - char *proto_par, - char *addr_par ) +static int w_t_forward_nonack_to( + struct sip_msg *p_msg, char *proto_par, char *addr_par) { struct proxy_l *proxy; int r = -1; proxy = t_protoaddr2proxy(proto_par, addr_par); - if (proxy) { + if(proxy) { r = _w_t_forward_nonack(p_msg, proxy, proxy->proto); free_proxy(proxy); pkg_free(proxy); @@ -1482,12 +1498,12 @@ static int w_t_forward_nonack_to( struct sip_msg *p_msg , /** * */ -static int ki_t_reply(sip_msg_t* msg, int code, str* reason) +static int ki_t_reply(sip_msg_t *msg, int code, str *reason) { tm_cell_t *t = NULL; int ret = -1; - if (msg->REQ_METHOD==METHOD_ACK) { + if(msg->REQ_METHOD == METHOD_ACK) { LM_DBG("ACKs are not replied\n"); return -1; } @@ -1496,11 +1512,12 @@ static int ki_t_reply(sip_msg_t* msg, int code, str* reason) return -2; } - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if (!t) { + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if(!t) { LM_ERR("cannot send a t_reply to a message" - " for which no T-state has been established\n"); + " for which no T-state has been established\n"); return -1; } @@ -1509,27 +1526,28 @@ static int ki_t_reply(sip_msg_t* msg, int code, str* reason) * the safe version would lead to a deadlock */ t->flags |= T_ADMIN_REPLY; - if (is_route_type(FAILURE_ROUTE)) { + if(is_route_type(FAILURE_ROUTE)) { LM_DBG("t_reply_unsafe called from w_t_reply\n"); ret = t_reply_str_unsafe(t, msg, (unsigned int)code, reason); - } else if (is_route_type(REQUEST_ROUTE)) { - ret = t_reply_str( t, msg, (unsigned int)code, reason); - } else if (is_route_type(ONREPLY_ROUTE)) { - if (likely(t->uas.request)){ - if (is_route_type(CORE_ONREPLY_ROUTE)) - ret=t_reply_str(t, t->uas.request, (unsigned int)code, reason); + } else if(is_route_type(REQUEST_ROUTE)) { + ret = t_reply_str(t, msg, (unsigned int)code, reason); + } else if(is_route_type(ONREPLY_ROUTE)) { + if(likely(t->uas.request)) { + if(is_route_type(CORE_ONREPLY_ROUTE)) + ret = t_reply_str( + t, t->uas.request, (unsigned int)code, reason); else - ret=t_reply_str_unsafe(t, t->uas.request, (unsigned int)code, - reason); - }else - ret=-1; + ret = t_reply_str_unsafe( + t, t->uas.request, (unsigned int)code, reason); + } else + ret = -1; /* t_check() above has the side effect of setting T and * REFerencing T => we must unref and unset it. * Note: this is needed only in the CORE_ONREPLY_ROUTE and not also in * the TM_ONREPLY_ROUTE. */ - if (is_route_type(CORE_ONREPLY_ROUTE)) { - UNREF( t ); + if(is_route_type(CORE_ONREPLY_ROUTE)) { + UNREF(t); set_t(T_UNDEFINED, T_BR_UNDEFINED); } } else { @@ -1540,21 +1558,21 @@ static int ki_t_reply(sip_msg_t* msg, int code, str* reason) return ret; } -static int w_t_reply(struct sip_msg* msg, char* p1, char* p2) +static int w_t_reply(struct sip_msg *msg, char *p1, char *p2) { int code; str reason; - if (msg->REQ_METHOD==METHOD_ACK) { + if(msg->REQ_METHOD == METHOD_ACK) { LM_DBG("ACKs are not replied\n"); return -1; } - if (get_int_fparam(&code, msg, (fparam_t*)p1) < 0) { + if(get_int_fparam(&code, msg, (fparam_t *)p1) < 0) { code = cfg_get(tm, tm_cfg, default_code); } - if (get_str_fparam(&reason, msg, (fparam_t*)p2) < 0) { + if(get_str_fparam(&reason, msg, (fparam_t *)p2) < 0) { reason.s = cfg_get(tm, tm_cfg, default_reason); reason.len = strlen(reason.s); } @@ -1576,12 +1594,12 @@ int w_t_reply_wrp(struct sip_msg *msg, unsigned int code, char *txt) /** * */ -static int ki_t_send_reply(sip_msg_t* msg, int code, str* reason) +static int ki_t_send_reply(sip_msg_t *msg, int code, str *reason) { int ret; ret = t_newtran(msg); - if (ret==0) { + if(ret == 0) { LM_NOTICE("transaction already in process %p\n", get_t()); } @@ -1591,21 +1609,21 @@ static int ki_t_send_reply(sip_msg_t* msg, int code, str* reason) /** * */ -static int w_t_send_reply(struct sip_msg* msg, char* p1, char* p2) +static int w_t_send_reply(struct sip_msg *msg, char *p1, char *p2) { int code; str reason; - if (msg->REQ_METHOD==METHOD_ACK) { + if(msg->REQ_METHOD == METHOD_ACK) { LM_DBG("ACKs are not replied\n"); return -1; } - if (get_int_fparam(&code, msg, (fparam_t*)p1) < 0) { + if(get_int_fparam(&code, msg, (fparam_t *)p1) < 0) { code = cfg_get(tm, tm_cfg, default_code); } - if (get_str_fparam(&reason, msg, (fparam_t*)p2) < 0) { + if(get_str_fparam(&reason, msg, (fparam_t *)p2) < 0) { reason.s = cfg_get(tm, tm_cfg, default_reason); reason.len = strlen(reason.s); } @@ -1616,129 +1634,131 @@ static int w_t_send_reply(struct sip_msg* msg, char* p1, char* p2) /** * */ -static int t_release(sip_msg_t* msg) +static int t_release(sip_msg_t *msg) { struct cell *t; int ret; - if(get_route_type()!=REQUEST_ROUTE) - { + if(get_route_type() != REQUEST_ROUTE) { LM_INFO("invalid usage - not in request route\n"); return -1; } - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if ( t && t!=T_UNDEFINED ) { - ret = t_release_transaction( t ); + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if(t && t != T_UNDEFINED) { + ret = t_release_transaction(t); t_unref(msg); return ret; } return 1; } -static int w_t_release(struct sip_msg* msg, char* str, char* str2) +static int w_t_release(struct sip_msg *msg, char *str, char *str2) { return t_release(msg); } -static int ki_t_retransmit_reply(struct sip_msg* p_msg) +static int ki_t_retransmit_reply(struct sip_msg *p_msg) { struct cell *t; - if (t_check( p_msg , 0 )==-1) + if(t_check(p_msg, 0) == -1) return 1; - t=get_t(); - if (t) { - if (p_msg->REQ_METHOD==METHOD_ACK) { + t = get_t(); + if(t) { + if(p_msg->REQ_METHOD == METHOD_ACK) { LM_WARN("ACKs transmit_replies not replied\n"); return -1; } - return t_retransmit_reply( t ); + return t_retransmit_reply(t); } else return -1; } -static int w_t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar) +static int w_t_retransmit_reply(struct sip_msg *p_msg, char *foo, char *bar) { return ki_t_retransmit_reply(p_msg); } -static int w_t_newtran( struct sip_msg* p_msg, char* foo, char* bar ) +static int w_t_newtran(struct sip_msg *p_msg, char *foo, char *bar) { /* t_newtran returns 0 on error (negative value means * 'transaction exists' */ int ret; - ret = t_newtran( p_msg ); - if (ret==E_SCRIPT) { - LM_NOTICE("transaction already in process %p\n", get_t() ); + ret = t_newtran(p_msg); + if(ret == E_SCRIPT) { + LM_NOTICE("transaction already in process %p\n", get_t()); } return ret; } -static int w_t_on_failure( struct sip_msg* msg, char *go_to, char *foo) +static int w_t_on_failure(struct sip_msg *msg, char *go_to, char *foo) { - t_on_failure( (unsigned int )(long) go_to ); + t_on_failure((unsigned int)(long)go_to); return 1; } -static int w_t_on_branch_failure( struct sip_msg* msg, char *go_to, char *foo) +static int w_t_on_branch_failure(struct sip_msg *msg, char *go_to, char *foo) { - t_on_branch_failure( (unsigned int )(long) go_to ); + t_on_branch_failure((unsigned int)(long)go_to); return 1; } -static int w_t_on_branch( struct sip_msg* msg, char *go_to, char *foo) +static int w_t_on_branch(struct sip_msg *msg, char *go_to, char *foo) { - t_on_branch( (unsigned int )(long) go_to ); + t_on_branch((unsigned int)(long)go_to); return 1; } -static int w_t_on_reply( struct sip_msg* msg, char *go_to, char *foo ) +static int w_t_on_reply(struct sip_msg *msg, char *go_to, char *foo) { - t_on_reply( (unsigned int )(long) go_to ); + t_on_reply((unsigned int)(long)go_to); return 1; } -static int t_is_set(sip_msg_t* msg, str *target) +static int t_is_set(sip_msg_t *msg, str *target) { int r; tm_cell_t *t = NULL; r = 0; t = get_t(); - if (t==T_UNDEFINED) t = NULL; + if(t == T_UNDEFINED) + t = NULL; switch(target->s[0]) { case 'b': - if(t==NULL) + if(t == NULL) r = get_on_branch(); else r = t->on_branch; break; case 'f': - if(t==NULL) + if(t == NULL) r = get_on_failure(); else r = t->on_failure; break; case 'o': - if(t==NULL) + if(t == NULL) r = get_on_reply(); else r = t->on_reply; break; } - if(r) return 1; + if(r) + return 1; return -1; } -static int w_t_is_set(struct sip_msg* msg, char *target, char *foo) +static int w_t_is_set(struct sip_msg *msg, char *target, char *foo) { str s = STR_NULL; @@ -1746,81 +1766,80 @@ static int w_t_is_set(struct sip_msg* msg, char *target, char *foo) return t_is_set(msg, &s); } -static int fixup_t_is_set(void** param, int param_no) +static int fixup_t_is_set(void **param, int param_no) { int len; - if (param_no==1) { - len = strlen((char*)*param); - if((len==13 && strncmp((char*)*param, "failure_route", 13)==0) - || (len==13 && strncmp((char*)*param, "onreply_route", 13)==0) - || (len==12 && strncmp((char*)*param, "branch_route", 12)==0)) { + if(param_no == 1) { + len = strlen((char *)*param); + if((len == 13 && strncmp((char *)*param, "failure_route", 13) == 0) + || (len == 13 + && strncmp((char *)*param, "onreply_route", 13) == 0) + || (len == 12 + && strncmp((char *)*param, "branch_route", 12) == 0)) { return 0; } - LM_ERR("invalid parameter value: %s\n", (char*)*param); + LM_ERR("invalid parameter value: %s\n", (char *)*param); return 1; } return 0; } -static int _w_t_relay_to(struct sip_msg *p_msg , - struct proxy_l *proxy, int force_proto) +static int _w_t_relay_to( + struct sip_msg *p_msg, struct proxy_l *proxy, int force_proto) { struct cell *t; int res; - if (is_route_type(FAILURE_ROUTE|BRANCH_FAILURE_ROUTE)) { - t=get_t(); - if (!t || t==T_UNDEFINED) { + if(is_route_type(FAILURE_ROUTE | BRANCH_FAILURE_ROUTE)) { + t = get_t(); + if(!t || t == T_UNDEFINED) { LM_CRIT("undefined T\n"); return -1; } res = t_forward_nonack(t, p_msg, proxy, force_proto); - if (res <= 0) { - if (res != E_CFG) { + if(res <= 0) { + if(res != E_CFG) { LM_ERR("t_forward_noack failed\n"); /* let us save the error code, we might need it later * when the failure_route has finished (Miklos) */ } - tm_error=ser_error; + tm_error = ser_error; return -1; } return 1; } - if (is_route_type(REQUEST_ROUTE)) - return t_relay_to( p_msg, proxy, force_proto, - 0 /* no replication */ ); + if(is_route_type(REQUEST_ROUTE)) + return t_relay_to(p_msg, proxy, force_proto, 0 /* no replication */); LM_CRIT("unsupported route type: %d\n", get_route_type()); return 0; } -static int w_t_relay_to_udp( struct sip_msg *p_msg , - char *proxy,/* struct proxy_l * expected */ - char *_foo /* nothing expected */ ) +static int w_t_relay_to_udp(struct sip_msg *p_msg, + char *proxy, /* struct proxy_l * expected */ + char *_foo /* nothing expected */) { - return _w_t_relay_to( p_msg, ( struct proxy_l *) proxy, PROTO_UDP); + return _w_t_relay_to(p_msg, (struct proxy_l *)proxy, PROTO_UDP); } /* forward to uri, but force udp as transport */ -static int w_t_relay_to_udp_uri( struct sip_msg *p_msg , - char *_foo, char *_bar ) +static int w_t_relay_to_udp_uri(struct sip_msg *p_msg, char *_foo, char *_bar) { return _w_t_relay_to(p_msg, (struct proxy_l *)0, PROTO_UDP); } #ifdef USE_TCP -static int w_t_relay_to_tcp( struct sip_msg *p_msg , +static int w_t_relay_to_tcp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l* */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return _w_t_relay_to( p_msg, ( struct proxy_l *) proxy, PROTO_TCP); + return _w_t_relay_to(p_msg, (struct proxy_l *)proxy, PROTO_TCP); } /* forward to uri, but force tcp as transport */ -static int w_t_relay_to_tcp_uri( struct sip_msg *p_msg , - char *_foo, char *_bar ) +static int w_t_relay_to_tcp_uri(struct sip_msg *p_msg, char *_foo, char *_bar) { return _w_t_relay_to(p_msg, (struct proxy_l *)0, PROTO_TCP); } @@ -1828,16 +1847,15 @@ static int w_t_relay_to_tcp_uri( struct sip_msg *p_msg , #ifdef USE_TLS -static int w_t_relay_to_tls( struct sip_msg *p_msg , +static int w_t_relay_to_tls(struct sip_msg *p_msg, char *proxy, /* struct proxy_l* expected */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return _w_t_relay_to( p_msg, ( struct proxy_l *) proxy, PROTO_TLS); + return _w_t_relay_to(p_msg, (struct proxy_l *)proxy, PROTO_TLS); } /* forward to uri, but force tls as transport */ -static int w_t_relay_to_tls_uri( struct sip_msg *p_msg , - char *_foo, char *_bar ) +static int w_t_relay_to_tls_uri(struct sip_msg *p_msg, char *_foo, char *_bar) { return _w_t_relay_to(p_msg, (struct proxy_l *)0, PROTO_TLS); } @@ -1845,31 +1863,29 @@ static int w_t_relay_to_tls_uri( struct sip_msg *p_msg , #ifdef USE_SCTP -static int w_t_relay_to_sctp( struct sip_msg *p_msg , +static int w_t_relay_to_sctp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l* */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return _w_t_relay_to( p_msg, ( struct proxy_l *) proxy, PROTO_SCTP); + return _w_t_relay_to(p_msg, (struct proxy_l *)proxy, PROTO_SCTP); } /* forward to uri, but force tcp as transport */ -static int w_t_relay_to_sctp_uri( struct sip_msg *p_msg , - char *_foo, char *_bar ) +static int w_t_relay_to_sctp_uri(struct sip_msg *p_msg, char *_foo, char *_bar) { return _w_t_relay_to(p_msg, (struct proxy_l *)0, PROTO_SCTP); } #endif -static int w_t_relay_to_avp( struct sip_msg *p_msg , - char *proto_par, - char *addr_par ) +static int w_t_relay_to_avp( + struct sip_msg *p_msg, char *proto_par, char *addr_par) { struct proxy_l *proxy; int r = -1; proxy = t_protoaddr2proxy(proto_par, addr_par); - if (proxy) { + if(proxy) { r = _w_t_relay_to(p_msg, proxy, PROTO_NONE); free_proxy(proxy); pkg_free(proxy); @@ -1883,19 +1899,16 @@ int t_replicate_uri(struct sip_msg *msg, str *suri) struct sip_uri turi; int r = -1; - if (suri != NULL && suri->s != NULL && suri->len > 0) - { + if(suri != NULL && suri->s != NULL && suri->len > 0) { memset(&turi, 0, sizeof(struct sip_uri)); - if(parse_uri(suri->s, suri->len, &turi)!=0) - { + if(parse_uri(suri->s, suri->len, &turi) != 0) { LM_ERR("bad replicate SIP address!\n"); return -1; } - proxy=mk_proxy(&turi.host, turi.port_no, turi.proto); - if (proxy==0) { - LM_ERR("cannot create proxy from URI <%.*s>\n", - suri->len, suri->s ); + proxy = mk_proxy(&turi.host, turi.port_no, turi.proto); + if(proxy == 0) { + LM_ERR("cannot create proxy from URI <%.*s>\n", suri->len, suri->s); return -1; } @@ -1908,76 +1921,74 @@ int t_replicate_uri(struct sip_msg *msg, str *suri) return r; } -static int w_t_replicate_uri(struct sip_msg *msg , - char *uri, /* sip uri as string or variable */ - char *_foo /* nothing expected */ ) +static int w_t_replicate_uri(struct sip_msg *msg, + char *uri, /* sip uri as string or variable */ + char *_foo /* nothing expected */) { str suri; - if(uri==NULL) + if(uri == NULL) return t_replicate_uri(msg, NULL); - if(fixup_get_svalue(msg, (gparam_p)uri, &suri)!=0) - { + if(fixup_get_svalue(msg, (gparam_p)uri, &suri) != 0) { LM_ERR("invalid replicate uri parameter\n"); return -1; } return t_replicate_uri(msg, &suri); } -static int w_t_replicate( struct sip_msg *p_msg , +static int w_t_replicate(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return t_replicate(p_msg, ( struct proxy_l *) proxy, p_msg->rcv.proto ); + return t_replicate(p_msg, (struct proxy_l *)proxy, p_msg->rcv.proto); } -static int w_t_replicate_udp( struct sip_msg *p_msg , +static int w_t_replicate_udp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_UDP ); + return t_replicate(p_msg, (struct proxy_l *)proxy, PROTO_UDP); } #ifdef USE_TCP -static int w_t_replicate_tcp( struct sip_msg *p_msg , +static int w_t_replicate_tcp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_TCP ); + return t_replicate(p_msg, (struct proxy_l *)proxy, PROTO_TCP); } #endif #ifdef USE_TLS -static int w_t_replicate_tls( struct sip_msg *p_msg , +static int w_t_replicate_tls(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_TLS ); + return t_replicate(p_msg, (struct proxy_l *)proxy, PROTO_TLS); } #endif #ifdef USE_SCTP -static int w_t_replicate_sctp( struct sip_msg *p_msg , +static int w_t_replicate_sctp(struct sip_msg *p_msg, char *proxy, /* struct proxy_l *proxy expected */ - char *_foo /* nothing expected */ ) + char *_foo /* nothing expected */) { - return t_replicate(p_msg, ( struct proxy_l *) proxy, PROTO_SCTP ); + return t_replicate(p_msg, (struct proxy_l *)proxy, PROTO_SCTP); } #endif -static int w_t_replicate_to( struct sip_msg *p_msg , - char *proto_par, - char *addr_par ) +static int w_t_replicate_to( + struct sip_msg *p_msg, char *proto_par, char *addr_par) { struct proxy_l *proxy; int r = -1; proxy = t_protoaddr2proxy(proto_par, addr_par); - if (proxy) { + if(proxy) { r = t_replicate(p_msg, proxy, proxy->proto); free_proxy(proxy); pkg_free(proxy); @@ -1985,8 +1996,7 @@ static int w_t_replicate_to( struct sip_msg *p_msg , return r; } -static int w_t_relay( struct sip_msg *p_msg , - char *_foo, char *_bar) +static int w_t_relay(struct sip_msg *p_msg, char *_foo, char *_bar) { return _w_t_relay_to(p_msg, (struct proxy_l *)0, PROTO_NONE); } @@ -1994,22 +2004,20 @@ static int w_t_relay( struct sip_msg *p_msg , /* like t_relay but use the specified destination and port and the same proto * as the received msg */ -static int w_t_relay2( struct sip_msg *p_msg , char *proxy, - char *_foo) +static int w_t_relay2(struct sip_msg *p_msg, char *proxy, char *_foo) { - return _w_t_relay_to(p_msg, (struct proxy_l*) proxy, p_msg->rcv.proto); + return _w_t_relay_to(p_msg, (struct proxy_l *)proxy, p_msg->rcv.proto); } /* relays CANCEL at the beginning of the script */ -static int w_t_relay_cancel( struct sip_msg *p_msg , - char *_foo, char *_bar) +static int w_t_relay_cancel(struct sip_msg *p_msg, char *_foo, char *_bar) { - if (p_msg->REQ_METHOD!=METHOD_CANCEL) + if(p_msg->REQ_METHOD != METHOD_CANCEL) return 1; /* it makes no sense to use this function without reparse_invite=1 */ - if (!cfg_get(tm, tm_cfg, reparse_invite)) + if(!cfg_get(tm, tm_cfg, reparse_invite)) LM_WARN("probably used with wrong configuration," " check the readme for details\n"); @@ -2017,13 +2025,15 @@ static int w_t_relay_cancel( struct sip_msg *p_msg , } /* set fr_inv_timeout & or fr_timeout; 0 means: use the default value */ -static int t_set_fr_all(struct sip_msg* msg, char* p1, char* p2) +static int t_set_fr_all(struct sip_msg *msg, char *p1, char *p2) { int fr, fr_inv; - if (get_int_fparam(&fr_inv, msg, (fparam_t*)p1) < 0) return -1; - if (p2) { - if (get_int_fparam(&fr, msg, (fparam_t*)p2) < 0) return -1; + if(get_int_fparam(&fr_inv, msg, (fparam_t *)p1) < 0) + return -1; + if(p2) { + if(get_int_fparam(&fr, msg, (fparam_t *)p2) < 0) + return -1; } else { fr = 0; } @@ -2031,45 +2041,47 @@ static int t_set_fr_all(struct sip_msg* msg, char* p1, char* p2) return t_set_fr(msg, fr_inv, fr); } -static int t_set_fr_inv(struct sip_msg* msg, char* fr_inv, char* foo) +static int t_set_fr_inv(struct sip_msg *msg, char *fr_inv, char *foo) { - return t_set_fr_all(msg, fr_inv, (char*)0); + return t_set_fr_all(msg, fr_inv, (char *)0); } -static int ki_t_set_fr(struct sip_msg* msg, int fr_inv, int fr) +static int ki_t_set_fr(struct sip_msg *msg, int fr_inv, int fr) { return t_set_fr(msg, fr_inv, fr); } -static int ki_t_set_fr_inv(struct sip_msg* msg, int fr_inv) +static int ki_t_set_fr_inv(struct sip_msg *msg, int fr_inv) { return t_set_fr(msg, fr_inv, 0); } /* reset fr_timer and fr_inv_timer to the default values */ -static int w_t_reset_fr(struct sip_msg* msg, char* foo, char* bar) +static int w_t_reset_fr(struct sip_msg *msg, char *foo, char *bar) { return t_reset_fr(); } -static int ki_t_reset_fr(struct sip_msg* msg) +static int ki_t_reset_fr(struct sip_msg *msg) { return t_reset_fr(); } -static int ki_t_set_retr(sip_msg_t* msg, int t1, int t2) +static int ki_t_set_retr(sip_msg_t *msg, int t1, int t2) { return t_set_retr(msg, t1, t2); } /* set retr. intervals per transaction; 0 means: use the default value */ -static int w_t_set_retr(struct sip_msg* msg, char* p1, char* p2) +static int w_t_set_retr(struct sip_msg *msg, char *p1, char *p2) { int t1, t2; - if (get_int_fparam(&t1, msg, (fparam_t*)p1) < 0) return -1; - if (p2) { - if (get_int_fparam(&t2, msg, (fparam_t*)p2) < 0) return -1; + if(get_int_fparam(&t1, msg, (fparam_t *)p1) < 0) + return -1; + if(p2) { + if(get_int_fparam(&t2, msg, (fparam_t *)p2) < 0) + return -1; } else { t2 = 0; } @@ -2077,42 +2089,44 @@ static int w_t_set_retr(struct sip_msg* msg, char* p1, char* p2) } /* reset retr. t1 and t2 to the default values */ -int ki_t_reset_retr(sip_msg_t* msg) +int ki_t_reset_retr(sip_msg_t *msg) { return t_reset_retr(); } -int w_t_reset_retr(struct sip_msg* msg, char* foo, char* bar) +int w_t_reset_retr(struct sip_msg *msg, char *foo, char *bar) { return ki_t_reset_retr(msg); } /* set maximum transaction lifetime for inv & noninv */ -static int w_t_set_max_lifetime(struct sip_msg* msg, char* p1, char* p2) +static int w_t_set_max_lifetime(struct sip_msg *msg, char *p1, char *p2) { int t1, t2; - if (get_int_fparam(&t1, msg, (fparam_t*)p1) < 0) return -1; - if (p2) { - if (get_int_fparam(&t2, msg, (fparam_t*)p2) < 0) return -1; + if(get_int_fparam(&t1, msg, (fparam_t *)p1) < 0) + return -1; + if(p2) { + if(get_int_fparam(&t2, msg, (fparam_t *)p2) < 0) + return -1; } else { t2 = 0; } return t_set_max_lifetime(msg, t1, t2); } -static int ki_t_set_max_lifetime(sip_msg_t* msg, int t1, int t2) +static int ki_t_set_max_lifetime(sip_msg_t *msg, int t1, int t2) { return t_set_max_lifetime(msg, t1, t2); } /* reset maximum invite/non-invite lifetime to the default value */ -int w_t_reset_max_lifetime(struct sip_msg* msg, char* foo, char* bar) +int w_t_reset_max_lifetime(struct sip_msg *msg, char *foo, char *bar) { return t_reset_max_lifetime(); } -int ki_t_reset_max_lifetime(sip_msg_t* msg) +int ki_t_reset_max_lifetime(sip_msg_t *msg) { return t_reset_max_lifetime(); } @@ -2124,47 +2138,48 @@ int ki_t_reset_max_lifetime(sip_msg_t* msg) * static int t_set_foo(struct sip_msg* msg, char*, char* ) * that will expect fparam as first param and will set or reset T_FOO * in the current or next to be created transaction. */ -#define T_SET_FLAG_GEN_FUNC(fname, T_FLAG_NAME) \ - static int fname(sip_msg_t* msg, int state) \ -{ \ - struct cell* t; \ - unsigned int set_flags; \ - unsigned int reset_flags; \ - \ - t=get_t(); \ - /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; \ +#define T_SET_FLAG_GEN_FUNC(fname, T_FLAG_NAME) \ + static int fname(sip_msg_t *msg, int state) \ + { \ + struct cell *t; \ + unsigned int set_flags; \ + unsigned int reset_flags; \ + \ + t = get_t(); \ + /* in REPLY_ROUTE and FAILURE_ROUTE T will be set to current transaction; \ * in REQUEST_ROUTE T will be set only if the transaction was already \ * created; if not -> use the static variables */ \ - if (!t || t==T_UNDEFINED ){ \ - set_flags=get_msgid_val(user_cell_set_flags, msg->id, int); \ - reset_flags=get_msgid_val(user_cell_reset_flags, msg->id, int); \ - if (state){ \ - /* set */ \ - set_flags|= T_FLAG_NAME; \ - reset_flags&=~T_FLAG_NAME; \ - }else{ \ - /* reset */ \ - set_flags&=~T_FLAG_NAME; \ - reset_flags|=T_FLAG_NAME; \ - } \ - set_msgid_val(user_cell_set_flags, msg->id, int, set_flags); \ - set_msgid_val(user_cell_reset_flags, msg->id, int, reset_flags); \ - }else{ \ - if (state) \ - t->flags|=T_FLAG_NAME; \ - else \ - t->flags&=~T_FLAG_NAME; \ - } \ - return 1; \ -} - -#define W_T_SET_FLAG_GEN_FUNC(fname, T_FLAG_NAME) \ - static int w_##fname(sip_msg_t* msg, char* p1, char* p2) \ -{ \ - int state; \ - if (get_int_fparam(&state, msg, (fparam_t*)p1) < 0) return -1; \ - return fname(msg, state); \ -} + if(!t || t == T_UNDEFINED) { \ + set_flags = get_msgid_val(user_cell_set_flags, msg->id, int); \ + reset_flags = get_msgid_val(user_cell_reset_flags, msg->id, int); \ + if(state) { \ + /* set */ \ + set_flags |= T_FLAG_NAME; \ + reset_flags &= ~T_FLAG_NAME; \ + } else { \ + /* reset */ \ + set_flags &= ~T_FLAG_NAME; \ + reset_flags |= T_FLAG_NAME; \ + } \ + set_msgid_val(user_cell_set_flags, msg->id, int, set_flags); \ + set_msgid_val(user_cell_reset_flags, msg->id, int, reset_flags); \ + } else { \ + if(state) \ + t->flags |= T_FLAG_NAME; \ + else \ + t->flags &= ~T_FLAG_NAME; \ + } \ + return 1; \ + } + +#define W_T_SET_FLAG_GEN_FUNC(fname, T_FLAG_NAME) \ + static int w_##fname(sip_msg_t *msg, char *p1, char *p2) \ + { \ + int state; \ + if(get_int_fparam(&state, msg, (fparam_t *)p1) < 0) \ + return -1; \ + return fname(msg, state); \ + } /* set automatically sending 100 replies on/off for the current or * next to be created transaction */ @@ -2200,12 +2215,12 @@ W_T_SET_FLAG_GEN_FUNC(t_set_disable_internal_reply, T_DISABLE_INTERNAL_REPLY) /* FAILURE_ROUTE and BRANCH_FAILURE_ROUTE only, * returns true if the choosed "failure" branch failed because of a timeout, * -1 otherwise */ -int t_branch_timeout(sip_msg_t* msg) +int t_branch_timeout(sip_msg_t *msg) { switch(get_route_type()) { case FAILURE_ROUTE: case BRANCH_FAILURE_ROUTE: - return (msg->msg_flags & FL_TIMEOUT)?1:-1; + return (msg->msg_flags & FL_TIMEOUT) ? 1 : -1; default: LM_ERR("unsupported route type %d\n", get_route_type()); } @@ -2216,7 +2231,7 @@ int t_branch_timeout(sip_msg_t* msg) /* script function, FAILURE_ROUTE and BRANCH_FAILURE_ROUTE only, * returns true if the choosed "failure" branch failed because of a timeout, * -1 otherwise */ -int w_t_branch_timeout(sip_msg_t* msg, char* foo, char* bar) +int w_t_branch_timeout(sip_msg_t *msg, char *foo, char *bar) { return t_branch_timeout(msg); } @@ -2224,12 +2239,12 @@ int w_t_branch_timeout(sip_msg_t* msg, char* foo, char* bar) /* FAILURE_ROUTE and BRANCH_FAILURE_ROUTE only, * returns true if the choosed "failure" branch ever received a reply, * -1 otherwise */ -int t_branch_replied(sip_msg_t* msg) +int t_branch_replied(sip_msg_t *msg) { switch(get_route_type()) { case FAILURE_ROUTE: case BRANCH_FAILURE_ROUTE: - return (msg->msg_flags & FL_REPLIED)?1:-1; + return (msg->msg_flags & FL_REPLIED) ? 1 : -1; default: LM_ERR("unsupported route type %d\n", get_route_type()); } @@ -2240,100 +2255,104 @@ int t_branch_replied(sip_msg_t* msg) /* script function, FAILURE_ROUTE and BRANCH_FAILURE_ROUTE only, * returns true if the choosed "failure" branch ever received a reply, * -1 otherwise */ -int w_t_branch_replied(sip_msg_t* msg, char* foo, char* bar) +int w_t_branch_replied(sip_msg_t *msg, char *foo, char *bar) { return t_branch_replied(msg); } /* script function, returns: 1 if the transaction was canceled, -1 if not */ -int t_is_canceled(struct sip_msg* msg) +int t_is_canceled(struct sip_msg *msg) { struct cell *t; int ret; - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if ((t==0) || (t==T_UNDEFINED)){ + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if((t == 0) || (t == T_UNDEFINED)) { LM_ERR("cannot check a message" - " for which no T-state has been established\n"); - ret=-1; - }else{ - ret=(t->flags & T_CANCELED)?1:-1; + " for which no T-state has been established\n"); + ret = -1; + } else { + ret = (t->flags & T_CANCELED) ? 1 : -1; } return ret; } -static int w_t_is_canceled(sip_msg_t* msg, char* foo, char* bar) +static int w_t_is_canceled(sip_msg_t *msg, char *foo, char *bar) { return t_is_canceled(msg); } /* returns: 1 if the transaction is currently suspended, -1 if not */ -int t_is_retr_async_reply(sip_msg_t* msg) +int t_is_retr_async_reply(sip_msg_t *msg) { struct cell *t; int ret; - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if ((t==0) || (t==T_UNDEFINED)){ + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if((t == 0) || (t == T_UNDEFINED)) { LM_ERR("cannot check a message" - " for which no T-state has been established\n"); - ret=-1; - }else{ + " for which no T-state has been established\n"); + ret = -1; + } else { LM_DBG("TRANSACTION FLAGS IS %d\n", t->flags); - ret=(t->flags & T_ASYNC_SUSPENDED)?1:-1; + ret = (t->flags & T_ASYNC_SUSPENDED) ? 1 : -1; } return ret; } /* script function, returns: 1 if the transaction is currently suspended, * -1 if not */ -static int w_t_is_retr_async_reply(sip_msg_t* msg, char* foo, char* bar) +static int w_t_is_retr_async_reply(sip_msg_t *msg, char *foo, char *bar) { return t_is_retr_async_reply(msg); } /* returns: 1 if the transaction lifetime interval has already elapsed, -1 if not */ -int t_is_expired(sip_msg_t* msg) +int t_is_expired(sip_msg_t *msg) { struct cell *t; int ret; - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if ((t==0) || (t==T_UNDEFINED)){ + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if((t == 0) || (t == T_UNDEFINED)) { LM_ERR("cannot check a message" - " for which no T-state has been established\n"); - ret=-1; - }else{ - ret=(TICKS_GT(t->end_of_life, get_ticks_raw()))?-1:1; + " for which no T-state has been established\n"); + ret = -1; + } else { + ret = (TICKS_GT(t->end_of_life, get_ticks_raw())) ? -1 : 1; } return ret; } /* script function, returns: 1 if the transaction lifetime interval * has already elapsed, -1 if not */ -int w_t_is_expired(sip_msg_t* msg, char* foo, char* bar) +int w_t_is_expired(sip_msg_t *msg, char *foo, char *bar) { return t_is_expired(msg); } /* returns: 1 if any of the branches did timeout, -1 if not */ -int t_any_timeout(sip_msg_t* msg) +int t_any_timeout(sip_msg_t *msg) { struct cell *t; int r; - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if ((t==0) || (t==T_UNDEFINED)){ + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if((t == 0) || (t == T_UNDEFINED)) { LM_ERR("cannot check a message" - " for which no T-state has been established\n"); + " for which no T-state has been established\n"); return -1; - }else{ - for (r=0; rnr_of_outgoings; r++){ - if (t->uac[r].request.flags & F_RB_TIMEOUT) + } else { + for(r = 0; r < t->nr_of_outgoings; r++) { + if(t->uac[r].request.flags & F_RB_TIMEOUT) return 1; } } @@ -2342,27 +2361,28 @@ int t_any_timeout(sip_msg_t* msg) /* script function, returns: 1 if any of the branches did timeout, -1 if not */ -int w_t_any_timeout(sip_msg_t* msg, char* foo, char* bar) +int w_t_any_timeout(sip_msg_t *msg, char *foo, char *bar) { return t_any_timeout(msg); } /* returns: 1 if any of the branches received at leat one * reply, -1 if not */ -int t_any_replied(sip_msg_t* msg) +int t_any_replied(sip_msg_t *msg) { struct cell *t; int r; - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if ((t==0) || (t==T_UNDEFINED)){ + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if((t == 0) || (t == T_UNDEFINED)) { LM_ERR("cannot check a message" - " for which no T-state has been established\n"); + " for which no T-state has been established\n"); return -1; - }else{ - for (r=0; rnr_of_outgoings; r++){ - if (t->uac[r].request.flags & F_RB_REPLIED) + } else { + for(r = 0; r < t->nr_of_outgoings; r++) { + if(t->uac[r].request.flags & F_RB_REPLIED) return 1; } } @@ -2372,7 +2392,7 @@ int t_any_replied(sip_msg_t* msg) /* script function, returns: 1 if any of the branches received at leat one * reply, -1 if not */ -int w_t_any_replied(sip_msg_t* msg, char* foo, char* bar) +int w_t_any_replied(sip_msg_t *msg, char *foo, char *bar) { return t_any_replied(msg); } @@ -2380,21 +2400,22 @@ int w_t_any_replied(sip_msg_t* msg, char* foo, char* bar) /* returns: 1 if any of the branches received the * reply code "status" */ -int t_grep_status(sip_msg_t* msg, int code) +int t_grep_status(sip_msg_t *msg, int code) { struct cell *t; int r; - if (t_check( msg , 0 )==-1) return -1; - t=get_t(); - if ((t==0) || (t==T_UNDEFINED)){ + if(t_check(msg, 0) == -1) + return -1; + t = get_t(); + if((t == 0) || (t == T_UNDEFINED)) { LM_ERR("cannot check a message" - " for which no T-state has been established\n"); + " for which no T-state has been established\n"); return -1; - }else{ - for (r=0; rnr_of_outgoings; r++){ - if ((t->uac[r].last_received==code) && - (t->uac[r].request.flags & F_RB_REPLIED)) + } else { + for(r = 0; r < t->nr_of_outgoings; r++) { + if((t->uac[r].last_received == code) + && (t->uac[r].request.flags & F_RB_REPLIED)) return 1; } } @@ -2404,58 +2425,59 @@ int t_grep_status(sip_msg_t* msg, int code) /* script function, returns: 1 if any of the branches received the * reply code "status" */ -int w_t_grep_status(struct sip_msg* msg, char* status, char* bar) +int w_t_grep_status(struct sip_msg *msg, char *status, char *bar) { int code; - if (get_int_fparam(&code, msg, (fparam_t*)status) < 0) return -1; + if(get_int_fparam(&code, msg, (fparam_t *)status) < 0) + return -1; return t_grep_status(msg, code); } /* drop all the existing replies in failure_route to make sure * that none of them is picked up again */ -static int t_drop_replies_helper(sip_msg_t* msg, char* mode) +static int t_drop_replies_helper(sip_msg_t *msg, char *mode) { - if(mode==NULL) + if(mode == NULL) t_drop_replies(1); - else if(*mode=='n') + else if(*mode == 'n') t_drop_replies(0); - else if(*mode=='l') + else if(*mode == 'l') t_drop_replies(2); else t_drop_replies(1); return 1; } -static int w_t_drop_replies(struct sip_msg* msg, char* mode, char* bar) +static int w_t_drop_replies(struct sip_msg *msg, char *mode, char *bar) { return t_drop_replies_helper(msg, mode); } -static int ki_t_drop_replies(sip_msg_t* msg, str* mode) +static int ki_t_drop_replies(sip_msg_t *msg, str *mode) { - return t_drop_replies_helper(msg, (mode)?mode->s:NULL); + return t_drop_replies_helper(msg, (mode) ? mode->s : NULL); } -static int ki_t_drop_replies_all(sip_msg_t* msg) +static int ki_t_drop_replies_all(sip_msg_t *msg) { return t_drop_replies_helper(msg, NULL); } /* save the message lumps after t_newtran() but before t_relay() */ -static int ki_t_save_lumps(sip_msg_t* msg) +static int ki_t_save_lumps(sip_msg_t *msg) { struct cell *t; - if (is_route_type(REQUEST_ROUTE)) { - t=get_t(); - if (!t || t==T_UNDEFINED) { + if(is_route_type(REQUEST_ROUTE)) { + t = get_t(); + if(!t || t == T_UNDEFINED) { LM_ERR("transaction has not been created yet\n"); return -1; } - if (save_msg_lumps(t->uas.request, msg)) { + if(save_msg_lumps(t->uas.request, msg)) { LM_ERR("failed to save the message lumps\n"); return -1; } @@ -2463,7 +2485,7 @@ static int ki_t_save_lumps(sip_msg_t* msg) return 1; } -static int w_t_save_lumps(struct sip_msg* msg, char* foo, char* bar) +static int w_t_save_lumps(struct sip_msg *msg, char *foo, char *bar) { return ki_t_save_lumps(msg); } @@ -2479,47 +2501,46 @@ static int w_t_save_lumps(struct sip_msg* msg, char* foo, char* bar) * reliable: if the ACK is delayed the proxied transaction might * be already deleted when it reaches the proxy (wait_timeout)) */ -int t_check_trans(struct sip_msg* msg) +int t_check_trans(struct sip_msg *msg) { - struct cell* t; + struct cell *t; int branch; int ret; /* already processing a T */ - if(is_route_type(FAILURE_ROUTE) - || is_route_type(BRANCH_ROUTE) + if(is_route_type(FAILURE_ROUTE) || is_route_type(BRANCH_ROUTE) || is_route_type(BRANCH_FAILURE_ROUTE) || is_route_type(TM_ONREPLY_ROUTE)) { return 1; } - if (msg->first_line.type==SIP_REPLY) { + if(msg->first_line.type == SIP_REPLY) { branch = 0; - ret = (t_check_msg( msg , &branch)==1) ? 1 : -1; + ret = (t_check_msg(msg, &branch) == 1) ? 1 : -1; tm_ctx_set_branch_index(branch); return ret; - } else if (msg->REQ_METHOD==METHOD_CANCEL) { + } else if(msg->REQ_METHOD == METHOD_CANCEL) { return w_t_lookup_cancel(msg, 0, 0); } else { - switch(t_check_msg(msg, 0)){ + switch(t_check_msg(msg, 0)) { case -2: /* possible e2e ack */ return 1; case 1: /* found */ - t=get_t(); - if (msg->REQ_METHOD==METHOD_ACK){ + t = get_t(); + if(msg->REQ_METHOD == METHOD_ACK) { /* ack to neg. reply or ack to local trans. * => process it and end the script */ /* FIXME: there's no way to distinguish here * between acks to local trans. and neg. acks */ - if (unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN))) - run_trans_callbacks(TMCB_ACK_NEG_IN, t, msg, - 0, msg->REQ_METHOD); + if(unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN))) + run_trans_callbacks( + TMCB_ACK_NEG_IN, t, msg, 0, msg->REQ_METHOD); t_release_transaction(t); } else { /* is a retransmission */ - if (unlikely(has_tran_tmcbs(t, TMCB_REQ_RETR_IN))) - run_trans_callbacks(TMCB_REQ_RETR_IN, t, msg, - 0, msg->REQ_METHOD); + if(unlikely(has_tran_tmcbs(t, TMCB_REQ_RETR_IN))) + run_trans_callbacks( + TMCB_REQ_RETR_IN, t, msg, 0, msg->REQ_METHOD); t_retransmit_reply(t); } /* no need for UNREF(t); set_t(0) - the end-of-script @@ -2531,26 +2552,25 @@ int t_check_trans(struct sip_msg* msg) return -1; } -static int w_t_check_trans(struct sip_msg* msg, char* foo, char* bar) +static int w_t_check_trans(struct sip_msg *msg, char *foo, char *bar) { return t_check_trans(msg); } -static int hexatoi(str *s, unsigned int* result) +static int hexatoi(str *s, unsigned int *result) { int i, xv, fact; /* more than 32bit hexa? */ - if (s->len>8) + if(s->len > 8) return -1; *result = 0; fact = 1; - for(i=s->len-1; i>=0 ;i--) - { + for(i = s->len - 1; i >= 0; i--) { xv = hex2int(s->s[i]); - if(xv<0) + if(xv < 0) return -1; *result += (xv * fact); @@ -2559,7 +2579,7 @@ static int hexatoi(str *s, unsigned int* result) return 0; } -static int fixup_t_relay_to(void** param, int param_no) +static int fixup_t_relay_to(void **param, int param_no) { int port; @@ -2570,87 +2590,82 @@ static int fixup_t_relay_to(void** param, int param_no) str s; str host; - s.s = (char*)*param; + s.s = (char *)*param; s.len = strlen(s.s); LM_DBG("fixing (%s, %d)\n", s.s, param_no); - if (param_no==1){ + if(param_no == 1) { a = fixup_get_param(param, param_no, 2); - if(a==NULL) - { - LM_CRIT("server error for parameter <%s>\n",s.s); + if(a == NULL) { + LM_CRIT("server error for parameter <%s>\n", s.s); return E_UNSPEC; } - if(a->u.string!=NULL) { + if(a->u.string != NULL) { /* second parameter set, first should be proxy addr */ - if (parse_phostport(s.s, &host.s, &host.len, &port, &proto)!=0){ - LM_CRIT("invalid proxy addr parameter <%s>\n",s.s); + if(parse_phostport(s.s, &host.s, &host.len, &port, &proto) != 0) { + LM_CRIT("invalid proxy addr parameter <%s>\n", s.s); return E_UNSPEC; } proxy = mk_proxy(&host, port, proto); - if (proxy==0) { - LM_ERR("failed to build proxy structure for <%.*s>\n", - host.len, host.s ); + if(proxy == 0) { + LM_ERR("failed to build proxy structure for <%.*s>\n", host.len, + host.s); return E_UNSPEC; } - *(param)=proxy; + *(param) = proxy; return 0; } else { /* no second parameter, then is proxy addr or flags */ flags = 0; - if (s.len>2 && s.s[0]=='0' && s.s[1]=='x') { + if(s.len > 2 && s.s[0] == '0' && s.s[1] == 'x') { s.s += 2; s.len -= 2; - if(hexatoi(&s, &flags)<0) - { + if(hexatoi(&s, &flags) < 0) { LM_CRIT("invalid hexa flags <%s>\n", s.s); return E_UNSPEC; } - a->u.data = (void*)(unsigned long int)flags; - *(param)= 0; + a->u.data = (void *)(unsigned long int)flags; + *(param) = 0; return 0; } else { - if(str2int(&s, &flags)==0) - { - a->u.data = (void*)(unsigned long int)flags; - *(param)= 0; + if(str2int(&s, &flags) == 0) { + a->u.data = (void *)(unsigned long int)flags; + *(param) = 0; return 0; } else { /* try proxy */ - if (parse_phostport(s.s, &host.s, &host.len, - &port, &proto)!=0){ - LM_CRIT("invalid proxy addr parameter <%s>\n",s.s); + if(parse_phostport(s.s, &host.s, &host.len, &port, &proto) + != 0) { + LM_CRIT("invalid proxy addr parameter <%s>\n", s.s); return E_UNSPEC; } proxy = mk_proxy(&host, port, proto); - if (proxy==0) { + if(proxy == 0) { LM_ERR("failed to build proxy structure for <%.*s>\n", - host.len, host.s ); + host.len, host.s); return E_UNSPEC; } - *(param)=proxy; + *(param) = proxy; return 0; } } } - } else if (param_no==2) { + } else if(param_no == 2) { /* flags */ flags = 0; - if (s.len>2 && s.s[0]=='0' && s.s[1]=='x') { + if(s.len > 2 && s.s[0] == '0' && s.s[1] == 'x') { s.s += 2; s.len -= 2; - if(hexatoi(&s, &flags)<0) - { + if(hexatoi(&s, &flags) < 0) { LM_CRIT("invalid hexa flags <%s>\n", s.s); return E_UNSPEC; } - *(param) = (void*)(unsigned long int)flags; + *(param) = (void *)(unsigned long int)flags; return 0; } else { - if(str2int(&s, &flags)==0) - { - *(param) = (void*)(unsigned long int)flags; + if(str2int(&s, &flags) == 0) { + *(param) = (void *)(unsigned long int)flags; return 0; } else { LM_CRIT("invalid flags <%s>\n", s.s); @@ -2670,53 +2685,52 @@ static int w_t_relay_to(struct sip_msg *msg, char *proxy, char *flags) struct proxy_l *px; fparam_t param; - fl = (unsigned int)(long)(void*)flags; - px = (struct proxy_l*)proxy; + fl = (unsigned int)(long)(void *)flags; + px = (struct proxy_l *)proxy; - if(flags!=0) - { + if(flags != 0) { memset(¶m, 0, sizeof(fparam_t)); param.type = FPARAM_INT; /* no auto 100 trying */ - if(fl&1) { + if(fl & 1) { param.v.i = 0; - w_t_set_auto_inv_100(msg, (char*)(¶m), 0); + w_t_set_auto_inv_100(msg, (char *)(¶m), 0); } /* no auto negative reply */ - if(fl&2) { + if(fl & 2) { param.v.i = 1; - w_t_set_disable_internal_reply(msg, (char*)(¶m), 0); + w_t_set_disable_internal_reply(msg, (char *)(¶m), 0); } /* no dns failover */ - if(fl&4) { + if(fl & 4) { param.v.i = 1; - w_t_set_disable_failover(msg, (char*)(¶m), 0); + w_t_set_disable_failover(msg, (char *)(¶m), 0); } } return _w_t_relay_to(msg, px, PROTO_NONE); } -static int ki_t_use_uac_headers(sip_msg_t* msg) +static int ki_t_use_uac_headers(sip_msg_t *msg) { tm_cell_t *t; - t=get_t(); - if (t!=NULL && t!=T_UNDEFINED) { - t->uas.request->msg_flags |= FL_USE_UAC_FROM|FL_USE_UAC_TO; + t = get_t(); + if(t != NULL && t != T_UNDEFINED) { + t->uas.request->msg_flags |= FL_USE_UAC_FROM | FL_USE_UAC_TO; } - msg->msg_flags |= FL_USE_UAC_FROM|FL_USE_UAC_TO; + msg->msg_flags |= FL_USE_UAC_FROM | FL_USE_UAC_TO; return 1; } -static int w_t_use_uac_headers(sip_msg_t* msg, char* foo, char* bar) +static int w_t_use_uac_headers(sip_msg_t *msg, char *foo, char *bar) { return ki_t_use_uac_headers(msg); } -static int w_t_uac_send(sip_msg_t* msg, char* pmethod, char* pruri, - char* pnexthop, char* psock, char *phdrs, char* pbody) +static int w_t_uac_send(sip_msg_t *msg, char *pmethod, char *pruri, + char *pnexthop, char *psock, char *phdrs, char *pbody) { str method = STR_NULL; str ruri = STR_NULL; @@ -2725,41 +2739,42 @@ static int w_t_uac_send(sip_msg_t* msg, char* pmethod, char* pruri, str headers = STR_NULL; str body = STR_NULL; - if(fixup_get_svalue(msg, (gparam_t*)pmethod, &method)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)pmethod, &method) != 0) { LM_ERR("invalid method parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)pruri, &ruri)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)pruri, &ruri) != 0) { LM_ERR("invalid ruri parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)pnexthop, &nexthop)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)pnexthop, &nexthop) != 0) { LM_ERR("invalid nexthop parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)psock, &send_socket)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)psock, &send_socket) != 0) { LM_ERR("invalid send socket parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)phdrs, &headers)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)phdrs, &headers) != 0) { LM_ERR("invalid headers parameter\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_t*)pbody, &body)!=0) { + if(fixup_get_svalue(msg, (gparam_t *)pbody, &body) != 0) { LM_ERR("invalid body parameter\n"); return -1; } - if(t_uac_send(&method, &ruri, &nexthop, &send_socket, &headers, &body)<0) { + if(t_uac_send(&method, &ruri, &nexthop, &send_socket, &headers, &body) + < 0) { return -1; } return 1; } -static int ki_t_uac_send(sip_msg_t* msg, str* method, str* ruri, - str* nexthop, str* ssock, str *hdrs, str* body) +static int ki_t_uac_send(sip_msg_t *msg, str *method, str *ruri, str *nexthop, + str *ssock, str *hdrs, str *body) { - if(t_uac_send(method, ruri, nexthop, ssock, hdrs, body)<0) { + if(t_uac_send(method, ruri, nexthop, ssock, hdrs, body) < 0) { return -1; } return 1; @@ -2767,77 +2782,57 @@ static int ki_t_uac_send(sip_msg_t* msg, str* method, str* ruri, /* rpc docs */ -static const char* rpc_cancel_doc[2] = { - "Cancel a pending transaction", - 0 -}; +static const char *rpc_cancel_doc[2] = {"Cancel a pending transaction", 0}; -static const char* rpc_reply_doc[2] = { - "Reply transaction", - 0 -}; +static const char *rpc_reply_doc[2] = {"Reply transaction", 0}; -static const char* rpc_reply_callid_doc[2] = { - "Reply transaction by call-id", - 0 -}; +static const char *rpc_reply_callid_doc[2] = { + "Reply transaction by call-id", 0}; -static const char* tm_rpc_stats_doc[2] = { - "Print transaction statistics.", - 0 -}; +static const char *tm_rpc_stats_doc[2] = {"Print transaction statistics.", 0}; -static const char* tm_rpc_hash_stats_doc[2] = { - "Prints hash table statistics (can be used only if tm is compiled" +static const char *tm_rpc_hash_stats_doc[2] = { + "Prints hash table statistics (can be used only if tm is compiled" " with -DTM_HASH_STATS).", - 0 -}; + 0}; -static const char* rpc_t_uac_start_doc[2] = { - "starts a tm uac using a list of string parameters: method, ruri, dst_uri" +static const char *rpc_t_uac_start_doc[2] = { + "starts a tm uac using a list of string parameters: method, ruri, " + "dst_uri" ", send_sock, headers (CRLF separated) and body (optional)", - 0 -}; + 0}; -static const char* rpc_t_uac_wait_doc[2] = { - "starts a tm uac and waits for the final reply, using a list of string " +static const char *rpc_t_uac_wait_doc[2] = { + "starts a tm uac and waits for the final reply, using a list of string " "parameters: method, ruri, dst_uri send_sock, headers (CRLF separated)" " and body (optional)", - 0 -}; + 0}; -static const char* rpc_t_uac_wait_block_doc[2] = { - "starts a tm uac and waits for the final reply in blocking mode, using a" +static const char *rpc_t_uac_wait_block_doc[2] = { + "starts a tm uac and waits for the final reply in blocking mode, using " + "a" " list of string parameters: method, ruri, dst_uri send_sock, headers" " (CRLF separated) and body (optional)", - 0 -}; + 0}; -static const char* tm_rpc_list_doc[2] = { - "List transactions.", - 0 -}; +static const char *tm_rpc_list_doc[2] = {"List transactions.", 0}; -static const char* tm_rpc_clean_doc[2] = { - "Clean expired (lifetime exceeded) transactions.", - 0 -}; +static const char *tm_rpc_clean_doc[2] = { + "Clean expired (lifetime exceeded) transactions.", 0}; /* rpc exports */ -static rpc_export_t tm_rpc[] = { - {"tm.cancel", rpc_cancel, rpc_cancel_doc, 0}, - {"tm.reply", rpc_reply, rpc_reply_doc, 0}, - {"tm.reply_callid", rpc_reply_callid, rpc_reply_callid_doc, 0}, - {"tm.stats", tm_rpc_stats, tm_rpc_stats_doc, 0}, - {"tm.hash_stats", tm_rpc_hash_stats, tm_rpc_hash_stats_doc, 0}, - {"tm.t_uac_start", rpc_t_uac_start, rpc_t_uac_start_doc, 0 }, - {"tm.t_uac_wait", rpc_t_uac_wait, rpc_t_uac_wait_doc, RET_ARRAY}, - {"tm.t_uac_wait_block", rpc_t_uac_wait_block, rpc_t_uac_wait_block_doc, 0}, - {"tm.list", tm_rpc_list, tm_rpc_list_doc, RET_ARRAY}, - {"tm.clean", tm_rpc_clean, tm_rpc_clean_doc, 0}, - {0, 0, 0, 0} -}; +static rpc_export_t tm_rpc[] = {{"tm.cancel", rpc_cancel, rpc_cancel_doc, 0}, + {"tm.reply", rpc_reply, rpc_reply_doc, 0}, + {"tm.reply_callid", rpc_reply_callid, rpc_reply_callid_doc, 0}, + {"tm.stats", tm_rpc_stats, tm_rpc_stats_doc, 0}, + {"tm.hash_stats", tm_rpc_hash_stats, tm_rpc_hash_stats_doc, 0}, + {"tm.t_uac_start", rpc_t_uac_start, rpc_t_uac_start_doc, 0}, + {"tm.t_uac_wait", rpc_t_uac_wait, rpc_t_uac_wait_doc, RET_ARRAY}, + {"tm.t_uac_wait_block", rpc_t_uac_wait_block, rpc_t_uac_wait_block_doc, + 0}, + {"tm.list", tm_rpc_list, tm_rpc_list_doc, RET_ARRAY}, + {"tm.clean", tm_rpc_clean, tm_rpc_clean_doc, 0}, {0, 0, 0, 0}}; /** * @@ -2847,17 +2842,20 @@ static int ki_t_on_failure(sip_msg_t *msg, str *rname) int ridx; sr_kemi_eng_t *keng; - if(rname==NULL || rname->s==NULL || rname->len<=0 || rname->s[0]=='\0') { + if(rname == NULL || rname->s == NULL || rname->len <= 0 + || rname->s[0] == '\0') { ridx = 0; } else { keng = sr_kemi_eng_get(); - if(keng==NULL) { + if(keng == NULL) { ridx = route_get(&failure_rt, rname->s); } else { ridx = sr_kemi_cbname_lookup_name(rname); } } - if(ridx<0) { ridx = 0; } + if(ridx < 0) { + ridx = 0; + } t_on_failure(ridx); return 1; @@ -2871,17 +2869,20 @@ static int ki_t_on_branch_failure(sip_msg_t *msg, str *rname) int ridx; sr_kemi_eng_t *keng; - if(rname==NULL || rname->s==NULL || rname->len<=0 || rname->s[0]=='\0') { + if(rname == NULL || rname->s == NULL || rname->len <= 0 + || rname->s[0] == '\0') { ridx = 0; } else { keng = sr_kemi_eng_get(); - if(keng==NULL) { + if(keng == NULL) { ridx = route_get(&event_rt, rname->s); } else { ridx = sr_kemi_cbname_lookup_name(rname); } } - if(ridx<0) { ridx = 0; } + if(ridx < 0) { + ridx = 0; + } t_on_branch_failure(ridx); return 1; @@ -2896,17 +2897,20 @@ static int ki_t_on_branch(sip_msg_t *msg, str *rname) int ridx; sr_kemi_eng_t *keng; - if(rname==NULL || rname->s==NULL || rname->len<=0 || rname->s[0]=='\0') { + if(rname == NULL || rname->s == NULL || rname->len <= 0 + || rname->s[0] == '\0') { ridx = 0; } else { keng = sr_kemi_eng_get(); - if(keng==NULL) { + if(keng == NULL) { ridx = route_get(&branch_rt, rname->s); } else { ridx = sr_kemi_cbname_lookup_name(rname); } } - if(ridx<0) { ridx = 0; } + if(ridx < 0) { + ridx = 0; + } t_on_branch(ridx); return 1; @@ -2920,17 +2924,20 @@ static int ki_t_on_reply(sip_msg_t *msg, str *rname) int ridx; sr_kemi_eng_t *keng; - if(rname==NULL || rname->s==NULL || rname->len<=0 || rname->s[0]=='\0') { + if(rname == NULL || rname->s == NULL || rname->len <= 0 + || rname->s[0] == '\0') { ridx = 0; } else { keng = sr_kemi_eng_get(); - if(keng==NULL) { + if(keng == NULL) { ridx = route_get(&onreply_rt, rname->s); } else { ridx = sr_kemi_cbname_lookup_name(rname); } } - if(ridx<0) { ridx = 0; } + if(ridx < 0) { + ridx = 0; + } t_on_reply(ridx); return 1; @@ -2952,12 +2959,12 @@ static int ki_t_relay_to_proto(sip_msg_t *msg, str *sproto) int proto = PROTO_NONE; - if (sproto != NULL && sproto->s != NULL && sproto->len == 3) { - if (strncasecmp(sproto->s, "UDP", 3) == 0) { + if(sproto != NULL && sproto->s != NULL && sproto->len == 3) { + if(strncasecmp(sproto->s, "UDP", 3) == 0) { proto = PROTO_UDP; - } else if (strncasecmp(sproto->s, "TCP", 3) == 0) { + } else if(strncasecmp(sproto->s, "TCP", 3) == 0) { proto = PROTO_TCP; - } else if (strncasecmp(sproto->s, "TLS", 3) == 0) { + } else if(strncasecmp(sproto->s, "TLS", 3) == 0) { proto = PROTO_TLS; } else { LM_ERR("bad protocol specified <%s>\n", sproto->s); @@ -2970,19 +2977,20 @@ static int ki_t_relay_to_proto(sip_msg_t *msg, str *sproto) /** * */ -static int ki_t_relay_to_proto_addr(sip_msg_t *msg, str *sproto, str *host, int port) +static int ki_t_relay_to_proto_addr( + sip_msg_t *msg, str *sproto, str *host, int port) { int proto = PROTO_NONE; proxy_l_t *proxy = NULL; int ret = -1; - if (sproto != NULL && sproto->s != NULL && sproto->len == 3) { - if (strncasecmp(sproto->s, "UDP", 3) == 0) { + if(sproto != NULL && sproto->s != NULL && sproto->len == 3) { + if(strncasecmp(sproto->s, "UDP", 3) == 0) { proto = PROTO_UDP; - } else if (strncasecmp(sproto->s, "TCP", 3) == 0) { + } else if(strncasecmp(sproto->s, "TCP", 3) == 0) { proto = PROTO_TCP; - } else if (strncasecmp(sproto->s, "TLS", 3) == 0) { + } else if(strncasecmp(sproto->s, "TLS", 3) == 0) { proto = PROTO_TLS; } else { LM_ERR("bad protocol specified <%s>\n", sproto->s); @@ -2990,9 +2998,8 @@ static int ki_t_relay_to_proto_addr(sip_msg_t *msg, str *sproto, str *host, int } } proxy = mk_proxy(host, (unsigned short)port, 0); - if (proxy == 0) { - LM_ERR("bad host:port provided <%s:%d>\n", - host->s, port ); + if(proxy == 0) { + LM_ERR("bad host:port provided <%s:%d>\n", host->s, port); return E_BAD_ADDRESS; } ret = _w_t_relay_to(msg, proxy, proto); @@ -3012,30 +3019,30 @@ static int ki_t_relay_to_proxy_flags(sip_msg_t *msg, str *sproxy, int rflags) str host; int port; - if (sproxy != NULL && sproxy->s != NULL && sproxy->len > 0) { - if (parse_phostport(sproxy->s, &host.s, &host.len, &port, &proto)!=0) { + if(sproxy != NULL && sproxy->s != NULL && sproxy->len > 0) { + if(parse_phostport(sproxy->s, &host.s, &host.len, &port, &proto) != 0) { LM_CRIT("invalid proxy addr parameter <%s>\n", sproxy->s); return E_UNSPEC; } proxy = mk_proxy(&host, port, proto); - if (proxy==0) { - LM_ERR("failed to build proxy structure for <%.*s>\n", - sproxy->len, sproxy->s ); + if(proxy == 0) { + LM_ERR("failed to build proxy structure for <%.*s>\n", sproxy->len, + sproxy->s); return E_UNSPEC; } } - if(rflags!=0) { + if(rflags != 0) { /* no auto 100 trying */ - if(rflags&1) { + if(rflags & 1) { t_set_auto_inv_100(msg, 0); } /* no auto negative reply */ - if(rflags&2) { + if(rflags & 2) { t_set_disable_internal_reply(msg, 1); } /* no dns failover */ - if(rflags&4) { + if(rflags & 4) { t_set_disable_failover(msg, 1); } } @@ -3067,38 +3074,40 @@ static int ki_t_relay_to_flags(sip_msg_t *msg, int rflags) } /* script function to clean active but very old transactions */ -static int t_clean(struct sip_msg* msg, char* key, char* value) +static int t_clean(struct sip_msg *msg, char *key, char *value) { tm_clean_lifetime(); return 1; } /* kemi function to clean active but very old transactions */ -static int ki_t_clean(sip_msg_t* msg) +static int ki_t_clean(sip_msg_t *msg) { tm_clean_lifetime(); return 1; } -static int ki_t_exists(sip_msg_t* msg) +static int ki_t_exists(sip_msg_t *msg) { tm_cell_t *t = NULL; int br = -1; - if (parse_headers(msg, HDR_EOH_F, 0 )==-1) { + if(parse_headers(msg, HDR_EOH_F, 0) == -1) { LM_ERR("parsing error\n"); - return -1;; + return -1; + ; } - if (parse_headers(msg, HDR_VIA1_F|HDR_CSEQ_F|HDR_CALLID_F|HDR_TO_F, 0)==-1) { + if(parse_headers(msg, HDR_VIA1_F | HDR_CSEQ_F | HDR_CALLID_F | HDR_TO_F, 0) + == -1) { LM_ERR("required headers cannot be parsed\n"); return -1; } - if(parse_from_header(msg)==-1) { + if(parse_from_header(msg) == -1) { LM_ERR("from header parsing failed\n"); return -1; } - if (msg->first_line.type==SIP_REQUEST) { + if(msg->first_line.type == SIP_REQUEST) { t_request_search(msg, &t); } else { t_reply_search(msg, &t, &br); @@ -3112,7 +3121,7 @@ static int ki_t_exists(sip_msg_t* msg) return 1; } -static int w_t_exists(struct sip_msg* msg, char* p1, char* p2) +static int w_t_exists(struct sip_msg *msg, char *p1, char *p2) { return ki_t_exists(msg); } @@ -3204,7 +3213,7 @@ static int t_failover_parse_reply_codes() /* Print the list as INFO: */ for(i = 0; i < *failover_reply_codes_cnt; i++) { LM_DBG("accepting reply %s %d (%d/%d) as valid\n", - ((*failover_reply_codes)[i]/10)?"code":"class", + ((*failover_reply_codes)[i] / 10) ? "code" : "class", (*failover_reply_codes)[i], (i + 1), *failover_reply_codes_cnt); } return 0; diff --git a/src/modules/tm/tm_load.c b/src/modules/tm/tm_load.c index d5fc6e78848..dced3edbeef 100644 --- a/src/modules/tm/tm_load.c +++ b/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; diff --git a/src/modules/tm/tm_load.h b/src/modules/tm/tm_load.h index 130d01503a1..f13c04cde6f 100644 --- a/src/modules/tm/tm_load.h +++ b/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; } diff --git a/src/modules/tm/uac.c b/src/modules/tm/uac.c index f35bf345f8e..e0b3bfff805 100644 --- a/src/modules/tm/uac.c +++ b/src/modules/tm/uac.c @@ -65,8 +65,8 @@ #ifdef WITH_EVENT_LOCAL_REQUEST /* where to go for the local request route ("tm:local-request") */ -int goto_on_local_req=-1; /* default disabled */ -#endif /* WITH_EVEN_LOCAL_REQuEST */ +int goto_on_local_req = -1; /* default disabled */ +#endif /* WITH_EVEN_LOCAL_REQuEST */ static char from_tag[FROM_TAG_LEN + 1]; @@ -79,13 +79,13 @@ int uac_init(void) str src[3]; struct socket_info *si; - if (KAM_RAND_MAX < TABLE_ENTRIES) { + if(KAM_RAND_MAX < TABLE_ENTRIES) { LM_WARN("uac does not spread across the whole hash table\n"); } /* on tcp/tls bind_address is 0 so try to get the first address we listen * on no matter the protocol */ - si=bind_address?bind_address:get_first_socket(); - if (si==0){ + si = bind_address ? bind_address : get_first_socket(); + if(si == 0) { LM_CRIT("BUG - null socket list\n"); return -1; } @@ -107,7 +107,7 @@ int uac_init(void) /* * Generate a From tag */ -void generate_fromtag(str* tag, str* callid, str* ruri) +void generate_fromtag(str *tag, str *callid, str *ruri) { /* calculate from tag from callid and request uri */ crcitt_string_array(&from_tag[MD5_LEN + 1], callid, 1); @@ -125,37 +125,37 @@ void generate_fromtag(str* tag, str* callid, str* ruri) /* * Check value of parameters */ -static inline int check_params(uac_req_t *uac_r, str* to, str* from) +static inline int check_params(uac_req_t *uac_r, str *to, str *from) { - if (!uac_r || !uac_r->method || !to || !from) { + if(!uac_r || !uac_r->method || !to || !from) { LM_ERR("Invalid parameter value\n"); return -1; } - if (!uac_r->method->s || !uac_r->method->len) { + if(!uac_r->method->s || !uac_r->method->len) { LM_ERR("Invalid request method\n"); return -2; } - if (!to->s || !to->len) { + if(!to->s || !to->len) { LM_ERR("Invalid To URI\n"); return -4; } - if (!from->s || !from->len) { + if(!from->s || !from->len) { LM_ERR("Invalid From URI\n"); return -5; } return 0; } -static inline unsigned int dlg2hash( dlg_t* dlg ) +static inline unsigned int dlg2hash(dlg_t *dlg) { str cseq_nr; unsigned int hashid; - cseq_nr.s=int2str(dlg->loc_seq.value, &cseq_nr.len); - hashid=hash(dlg->id.call_id, cseq_nr); + cseq_nr.s = int2str(dlg->loc_seq.value, &cseq_nr.len); + hashid = hash(dlg->id.call_id, cseq_nr); LM_DBG("hashid %d\n", hashid); return hashid; } @@ -168,11 +168,13 @@ int uac_refresh_shortcuts(tm_cell_t *tcell, int branch, char *buf, int buf_len) sip_msg_t lreq; struct cseq_body *cs; - if(likely(build_sip_msg_from_buf(&lreq, buf, buf_len, inc_msg_no())<0)) { + if(likely(build_sip_msg_from_buf(&lreq, buf, buf_len, inc_msg_no()) < 0)) { LM_ERR("failed to parse msg buffer\n"); return -1; } - if(parse_headers(&lreq,HDR_CSEQ_F|HDR_CALLID_F|HDR_FROM_F|HDR_TO_F,0)<0) { + if(parse_headers( + &lreq, HDR_CSEQ_F | HDR_CALLID_F | HDR_FROM_F | HDR_TO_F, 0) + < 0) { LM_ERR("failed to parse headers in new message\n"); goto error; } @@ -189,7 +191,8 @@ int uac_refresh_shortcuts(tm_cell_t *tcell, int branch, char *buf, int buf_len) cs = get_cseq(&lreq); tcell->cseq_hdr_n.s = lreq.cseq->name.s; - tcell->cseq_hdr_n.len = (int)(cs->number.s + cs->number.len - lreq.cseq->name.s); + tcell->cseq_hdr_n.len = + (int)(cs->number.s + cs->number.len - lreq.cseq->name.s); tcell->cseq_num.s = cs->number.s; tcell->cseq_num.len = cs->number.len; trim(&tcell->cseq_num); @@ -198,23 +201,22 @@ int uac_refresh_shortcuts(tm_cell_t *tcell, int branch, char *buf, int buf_len) trim(&tcell->cseq_met); LM_DBG("cseq: [%.*s]\n", tcell->cseq_hdr_n.len, tcell->cseq_hdr_n.s); - lreq.buf=0; + lreq.buf = 0; free_sip_msg(&lreq); return 0; error: - lreq.buf=0; + lreq.buf = 0; free_sip_msg(&lreq); return -1; } #if defined(USE_DNS_FAILOVER) || defined(WITH_EVENT_LOCAL_REQUEST) -static inline int t_build_msg_from_buf( - struct sip_msg *msg, char *buf, int buf_len, - uac_req_t *uac_r, struct dest_info *dst) +static inline int t_build_msg_from_buf(struct sip_msg *msg, char *buf, + int buf_len, uac_req_t *uac_r, struct dest_info *dst) { - if (unlikely(build_sip_msg_from_buf(msg, buf, buf_len, inc_msg_no()) != 0)) { + if(unlikely(build_sip_msg_from_buf(msg, buf, buf_len, inc_msg_no()) != 0)) { return -1; } msg->force_send_socket = uac_r->dialog->send_sock; @@ -223,19 +225,17 @@ static inline int t_build_msg_from_buf( su2ip_addr(&msg->rcv.dst_ip, &dst->to); msg->rcv.src_port = dst->send_sock->port_no; msg->rcv.dst_port = su_getport(&dst->to); - msg->rcv.src_su=dst->send_sock->su; - msg->rcv.bind_address=dst->send_sock; + msg->rcv.src_su = dst->send_sock->su; + msg->rcv.bind_address = dst->send_sock; #ifdef USE_COMP - msg->rcv.comp=dst->comp; + msg->rcv.comp = dst->comp; #endif /* USE_COMP */ return 0; } #ifdef WITH_EVENT_LOCAL_REQUEST -static inline int t_run_local_req( - char **buf, int *buf_len, - uac_req_t *uac_r, +static inline int t_run_local_req(char **buf, int *buf_len, uac_req_t *uac_r, struct cell *new_cell, struct retr_buf *request) { struct sip_msg lreq = {0}; @@ -255,10 +255,11 @@ static inline int t_run_local_req( str evname = str_init("tm:local-request"); LM_DBG("executing event_route[tm:local-request]\n"); - if (unlikely(t_build_msg_from_buf(&lreq, *buf, *buf_len, uac_r, &request->dst))) { + if(unlikely(t_build_msg_from_buf( + &lreq, *buf, *buf_len, uac_r, &request->dst))) { return -1; } - if (unlikely(set_dst_uri(&lreq, uac_r->dialog->hooks.next_hop))) { + if(unlikely(set_dst_uri(&lreq, uac_r->dialog->hooks.next_hop))) { LM_ERR("failed to set dst_uri\n"); free_sip_msg(&lreq); return -1; @@ -266,39 +267,40 @@ static inline int t_run_local_req( sflag_bk = getsflags(); tm_xdata_swap(new_cell, &backup_xd, 0); - onsnd_info.to=&request->dst.to; - onsnd_info.send_sock=request->dst.send_sock; - onsnd_info.buf=*buf; - onsnd_info.len=*buf_len; - p_onsend=&onsnd_info; + onsnd_info.to = &request->dst.to; + onsnd_info.send_sock = request->dst.send_sock; + onsnd_info.buf = *buf; + onsnd_info.len = *buf_len; + p_onsend = &onsnd_info; /* run the route */ backup_route_type = get_route_type(); set_route_type(LOCAL_ROUTE); /* set T to the current transaction */ - backup_t=get_t(); - backup_branch=get_t_branch(); - backup_ctxid.msgid=tm_global_ctx_id.msgid; - backup_ctxid.pid=tm_global_ctx_id.pid; + backup_t = get_t(); + backup_branch = get_t_branch(); + backup_ctxid.msgid = tm_global_ctx_id.msgid; + backup_ctxid.pid = tm_global_ctx_id.pid; /* fake transaction and message id */ - tm_global_ctx_id.msgid=lreq.id; - tm_global_ctx_id.pid=lreq.pid; + tm_global_ctx_id.msgid = lreq.id; + tm_global_ctx_id.pid = lreq.pid; set_t(new_cell, T_BR_UNDEFINED); - + init_run_actions_ctx(&ra_ctx); - - if(goto_on_local_req>=0) { + + if(goto_on_local_req >= 0) { run_top_route(event_rt.rlist[goto_on_local_req], &lreq, &ra_ctx); } else { keng = sr_kemi_eng_get(); - if(keng==NULL) { + if(keng == NULL) { LM_WARN("event callback (%s) set, but no cfg engine\n", tm_event_callback.s); } else { bctx = sr_kemi_act_ctx_get(); sr_kemi_act_ctx_set(&ra_ctx); - if(sr_kemi_route(keng, &lreq, EVENT_ROUTE, - &tm_event_callback, &evname)<0) { + if(sr_kemi_route( + keng, &lreq, EVENT_ROUTE, &tm_event_callback, &evname) + < 0) { LM_ERR("error running event route kemi callback\n"); } sr_kemi_act_ctx_set(bctx); @@ -306,31 +308,36 @@ static inline int t_run_local_req( } /* restore original environment */ set_t(backup_t, backup_branch); - tm_global_ctx_id.msgid=backup_ctxid.msgid; - tm_global_ctx_id.pid=backup_ctxid.pid; - set_route_type( backup_route_type ); - p_onsend=0; - - if (unlikely(ra_ctx.run_flags&DROP_R_F)) { - LM_DBG("tm:local-request dropped msg. to %.*s\n", - lreq.dst_uri.len, lreq.dst_uri.s); + tm_global_ctx_id.msgid = backup_ctxid.msgid; + tm_global_ctx_id.pid = backup_ctxid.pid; + set_route_type(backup_route_type); + p_onsend = 0; + + if(unlikely(ra_ctx.run_flags & DROP_R_F)) { + LM_DBG("tm:local-request dropped msg. to %.*s\n", lreq.dst_uri.len, + lreq.dst_uri.s); refresh_shortcuts = E_DROP; goto clean; } /* rebuild the new message content */ if((lreq.force_send_socket != uac_r->dialog->send_sock) - || (lreq.msg_flags&(FL_ADD_LOCAL_RPORT|FL_ADD_SRVID - |FL_ADD_XAVP_VIA_PARAMS|FL_USE_XAVP_VIA_FIELDS))) { + || (lreq.msg_flags + & (FL_ADD_LOCAL_RPORT | FL_ADD_SRVID + | FL_ADD_XAVP_VIA_PARAMS + | FL_USE_XAVP_VIA_FIELDS))) { LM_DBG("local Via update - new socket: [%.*s] - msg-flags: %u", - (lreq.force_send_socket)?lreq.force_send_socket->address_str.len:4, - (lreq.force_send_socket)?lreq.force_send_socket->address_str.s:"none", - lreq.msg_flags); + (lreq.force_send_socket) + ? lreq.force_send_socket->address_str.len + : 4, + (lreq.force_send_socket) ? lreq.force_send_socket->address_str.s + : "none", + lreq.msg_flags); /* rebuild local Via - remove previous value * and add the one for the new send socket */ - if (!del_lump(&lreq, lreq.h_via1->name.s - lreq.buf, - lreq.h_via1->len, 0)) { + if(!del_lump(&lreq, lreq.h_via1->name.s - lreq.buf, lreq.h_via1->len, + 0)) { LM_ERR("Failed to remove previous local Via\n"); /* attempt a normal update to give it a chance */ goto normal_update; @@ -343,16 +350,15 @@ static inline int t_run_local_req( /* update also info about new destination and send sock */ if(lreq.force_send_socket) { - uac_r->dialog->send_sock=lreq.force_send_socket; + uac_r->dialog->send_sock = lreq.force_send_socket; request->dst.send_sock = lreq.force_send_socket; request->dst.proto = lreq.force_send_socket->proto; } LM_DBG("apply new updates with Via to sip msg\n"); - buf1 = build_req_buf_from_sip_req(&lreq, - (unsigned int*)&buf_len1, &request->dst, - BUILD_NEW_LOCAL_VIA|BUILD_IN_SHM); - if (likely(buf1)){ + buf1 = build_req_buf_from_sip_req(&lreq, (unsigned int *)&buf_len1, + &request->dst, BUILD_NEW_LOCAL_VIA | BUILD_IN_SHM); + if(likely(buf1)) { shm_free(*buf); *buf = buf1; *buf_len = buf_len1; @@ -361,14 +367,13 @@ static inline int t_run_local_req( } } else { -normal_update: - if (unlikely(lreq.add_rm || lreq.body_lumps || lreq.new_uri.s)) { + normal_update: + if(unlikely(lreq.add_rm || lreq.body_lumps || lreq.new_uri.s)) { LM_DBG("apply new updates without Via to sip msg\n"); - buf1 = build_req_buf_from_sip_req(&lreq, - (unsigned int*)&buf_len1, - &request->dst, BUILD_NO_LOCAL_VIA|BUILD_NO_VIA1_UPDATE| - BUILD_IN_SHM); - if (likely(buf1)){ + buf1 = build_req_buf_from_sip_req(&lreq, (unsigned int *)&buf_len1, + &request->dst, + BUILD_NO_LOCAL_VIA | BUILD_NO_VIA1_UPDATE | BUILD_IN_SHM); + if(likely(buf1)) { shm_free(*buf); *buf = buf1; *buf_len = buf_len1; @@ -384,19 +389,17 @@ static inline int t_run_local_req( setsflagsval(sflag_bk); /* clean local msg structure */ - if (unlikely(lreq.new_uri.s)) - { + if(unlikely(lreq.new_uri.s)) { pkg_free(lreq.new_uri.s); - lreq.new_uri.s=0; - lreq.new_uri.len=0; + lreq.new_uri.s = 0; + lreq.new_uri.len = 0; } - if (unlikely(lreq.dst_uri.s)) - { + if(unlikely(lreq.dst_uri.s)) { pkg_free(lreq.dst_uri.s); - lreq.dst_uri.s=0; - lreq.dst_uri.len=0; + lreq.dst_uri.s = 0; + lreq.dst_uri.len = 0; } - lreq.buf=0; + lreq.buf = 0; free_sip_msg(&lreq); return refresh_shortcuts; } @@ -410,9 +413,8 @@ static inline int t_run_local_req( * be added in the hash table (should be either deleted by the * caller) */ -static inline int t_uac_prepare(uac_req_t *uac_r, - struct retr_buf **dst_req, - struct cell **dst_cell) +static inline int t_uac_prepare( + uac_req_t *uac_r, struct retr_buf **dst_req, struct cell **dst_cell) { struct dest_info dst; struct cell *new_cell; @@ -432,20 +434,22 @@ static inline int t_uac_prepare(uac_req_t *uac_r, static struct sip_msg lreq; #endif /* USE_DNS_FAILOVER */ - ret=-1; - hi=0; /* make gcc happy */ + ret = -1; + hi = 0; /* make gcc happy */ /*if (dst_req) *dst_req = NULL;*/ - is_ack = (((uac_r->method->len == 3) && (memcmp("ACK", - uac_r->method->s, 3)==0)) ? 1 : 0); + is_ack = (((uac_r->method->len == 3) + && (memcmp("ACK", uac_r->method->s, 3) == 0)) + ? 1 + : 0); /*** added by dcm * - needed by external ua to send a request within a dlg */ - if ((nhtype = w_calculate_hooks(uac_r->dialog)) < 0) + if((nhtype = w_calculate_hooks(uac_r->dialog)) < 0) /* if err's returned, the message is incorrect */ goto error3; - if (!uac_r->dialog->loc_seq.is_set) { + if(!uac_r->dialog->loc_seq.is_set) { /* this is the first request in the dialog, set cseq to default value now - Miklos */ uac_r->dialog->loc_seq.value = DEFAULT_CSEQ; @@ -459,57 +463,61 @@ static inline int t_uac_prepare(uac_req_t *uac_r, new_cell = build_cell(0); tm_xdata_replace(0, &backup_xd); - if (!new_cell) { - ret=E_OUT_OF_MEM; + if(!new_cell) { + ret = E_OUT_OF_MEM; LM_ERR("short of cell shmem\n"); goto error3; } - LM_DBG("next_hop=<%.*s>\n",uac_r->dialog->hooks.next_hop->len, + LM_DBG("next_hop=<%.*s>\n", uac_r->dialog->hooks.next_hop->len, uac_r->dialog->hooks.next_hop->s); /* new message => take the dialog send_socket if set, or the default send_socket if not*/ SND_FLAGS_INIT(&snd_flags); - if (uac_r->dialog->send_sock != NULL) - { + if(uac_r->dialog->send_sock != NULL) { snd_flags.f |= SND_F_FORCE_SOCKET; } #ifdef USE_DNS_FAILOVER - if ((uri2dst2(cfg_get(core, core_cfg, use_dns_failover) ? &new_cell->uac[0].dns_h : 0, - &dst, uac_r->dialog->send_sock, snd_flags, - uac_r->dialog->hooks.next_hop, PROTO_NONE)==0) - || (dst.send_sock==0)){ -#else /* USE_DNS_FAILOVER */ - if ((uri2dst2(&dst, uac_r->dialog->send_sock, snd_flags, - uac_r->dialog->hooks.next_hop, PROTO_NONE)==0) || - (dst.send_sock==0)){ + if((uri2dst2(cfg_get(core, core_cfg, use_dns_failover) + ? &new_cell->uac[0].dns_h + : 0, + &dst, uac_r->dialog->send_sock, snd_flags, + uac_r->dialog->hooks.next_hop, PROTO_NONE) + == 0) + || (dst.send_sock == 0)) { +#else /* USE_DNS_FAILOVER */ + if((uri2dst2(&dst, uac_r->dialog->send_sock, snd_flags, + uac_r->dialog->hooks.next_hop, PROTO_NONE) + == 0) + || (dst.send_sock == 0)) { #endif /* USE_DNS_FAILOVER */ ser_error = E_NO_SOCKET; - ret=ser_error; + ret = ser_error; LM_ERR("no socket found\n"); goto error2; } - if (uac_r->method->len==INVITE_LEN && memcmp(uac_r->method->s, INVITE, INVITE_LEN)==0){ + if(uac_r->method->len == INVITE_LEN + && memcmp(uac_r->method->s, INVITE, INVITE_LEN) == 0) { new_cell->flags |= T_IS_INVITE_FLAG; - new_cell->flags|=T_AUTO_INV_100 & - (!cfg_get(tm, tm_cfg, tm_auto_inv_100) -1); - if (uac_r->cb_flags & TMCB_DONT_ACK) + new_cell->flags |= + T_AUTO_INV_100 & (!cfg_get(tm, tm_cfg, tm_auto_inv_100) - 1); + if(uac_r->cb_flags & TMCB_DONT_ACK) new_cell->flags |= T_NO_AUTO_ACK; - lifetime=cfg_get(tm, tm_cfg, tm_max_inv_lifetime); - }else - lifetime=cfg_get(tm, tm_cfg, tm_max_noninv_lifetime); + lifetime = cfg_get(tm, tm_cfg, tm_max_inv_lifetime); + } else + lifetime = cfg_get(tm, tm_cfg, tm_max_noninv_lifetime); new_cell->flags |= T_IS_LOCAL_FLAG; /* init timers hack, new_cell->fr_timer and new_cell->fr_inv_timer * must be set, or else the fr will happen immediately * we can't call init_new_t() because we don't have a sip msg * => we'll ignore t_set_fr() or avp timer value and will use directly the * module params fr_inv_timer and fr_timer -- andrei */ - new_cell->fr_timeout=cfg_get(tm, tm_cfg, fr_timeout); - new_cell->fr_inv_timeout=cfg_get(tm, tm_cfg, fr_inv_timeout); - new_cell->end_of_life=get_ticks_raw()+lifetime; + new_cell->fr_timeout = cfg_get(tm, tm_cfg, fr_timeout); + new_cell->fr_inv_timeout = cfg_get(tm, tm_cfg, fr_inv_timeout); + new_cell->end_of_life = get_ticks_raw() + lifetime; /* same as above for retransmission intervals */ new_cell->rt_t1_timeout_ms = cfg_get(tm, tm_cfg, rt_t1_timeout_ms); new_cell->rt_t2_timeout_ms = cfg_get(tm, tm_cfg, rt_t2_timeout_ms); @@ -521,36 +529,37 @@ static inline int t_uac_prepare(uac_req_t *uac_r, request->flags |= nhtype; #ifdef SO_REUSEPORT - if (cfg_get(tcp, tcp_cfg, reuse_port) - && request->dst.send_sock->proto == PROTO_TCP) { - if((uac_r->ssockname!=NULL && uac_r->ssockname->len>0) - || (uac_r->ssock!=NULL && uac_r->ssock->len>0)) { + if(cfg_get(tcp, tcp_cfg, reuse_port) + && request->dst.send_sock->proto == PROTO_TCP) { + if((uac_r->ssockname != NULL && uac_r->ssockname->len > 0) + || (uac_r->ssock != NULL && uac_r->ssock->len > 0)) { request->dst.send_flags.f |= SND_F_FORCE_SOCKET; } } #endif - if (!is_ack) { + if(!is_ack) { INIT_REF(new_cell, 1); /* ref'ed only from the hash */ - hi=dlg2hash(uac_r->dialog); + hi = dlg2hash(uac_r->dialog); LOCK_HASH(hi); insert_into_hash_table_unsafe(new_cell, hi); UNLOCK_HASH(hi); } - buf = build_uac_req(uac_r->method, uac_r->headers, uac_r->body, uac_r->dialog, 0, new_cell, - &buf_len, &dst); - if (!buf || buf_len<=0) { + buf = build_uac_req(uac_r->method, uac_r->headers, uac_r->body, + uac_r->dialog, 0, new_cell, &buf_len, &dst); + if(!buf || buf_len <= 0) { LM_ERR("Error while building message\n"); - ret=E_OUT_OF_MEM; + ret = E_OUT_OF_MEM; goto error1; } #ifdef WITH_EVENT_LOCAL_REQUEST - if (unlikely(goto_on_local_req>=0 || tm_event_callback.len>0)) { - refresh_shortcuts = t_run_local_req(&buf, &buf_len, uac_r, new_cell, request); - if (unlikely(refresh_shortcuts==E_DROP)) { - ret=E_DROP; + if(unlikely(goto_on_local_req >= 0 || tm_event_callback.len > 0)) { + refresh_shortcuts = + t_run_local_req(&buf, &buf_len, uac_r, new_cell, request); + if(unlikely(refresh_shortcuts == E_DROP)) { + ret = E_DROP; goto error1; } } @@ -558,19 +567,22 @@ static inline int t_uac_prepare(uac_req_t *uac_r, #ifdef USE_DNS_FAILOVER /* Set the outgoing message as UAS, so the failover code has something to work with */ - if(cfg_get(core, core_cfg, use_dns_failover) || cfg_get(tm, tm_cfg, enable_uac_fr)) { - if(likely(t_build_msg_from_buf(&lreq, buf, buf_len, uac_r, &dst) == 0)) { - if (parse_headers(&lreq, HDR_EOH_F, 0) == -1) { + if(cfg_get(core, core_cfg, use_dns_failover) + || cfg_get(tm, tm_cfg, enable_uac_fr)) { + if(likely(t_build_msg_from_buf(&lreq, buf, buf_len, uac_r, &dst) + == 0)) { + if(parse_headers(&lreq, HDR_EOH_F, 0) == -1) { LM_ERR("failed to parse headers on uas for failover\n"); } else { new_cell->uas.request = sip_msg_cloner(&lreq, &sip_msg_len); - lreq.buf=0; + lreq.buf = 0; free_sip_msg(&lreq); - if (!new_cell->uas.request) { + if(!new_cell->uas.request) { LM_ERR("no more shmem\n"); goto error1; } - new_cell->uas.end_request=((char*)new_cell->uas.request)+sip_msg_len; + new_cell->uas.end_request = + ((char *)new_cell->uas.request) + sip_msg_len; } } else { LM_WARN("failed to build uas for failover\n"); @@ -586,8 +598,8 @@ static inline int t_uac_prepare(uac_req_t *uac_r, request->buffer = buf; request->buffer_len = buf_len; - if(unlikely(refresh_shortcuts==1)) { - if(uac_refresh_shortcuts(new_cell, 0, buf, buf_len)<0) { + if(unlikely(refresh_shortcuts == 1)) { + if(uac_refresh_shortcuts(new_cell, 0, buf, buf_len) < 0) { LM_ERR("failed to refresh header shortcuts\n"); goto error1; } @@ -597,38 +609,42 @@ static inline int t_uac_prepare(uac_req_t *uac_r, /* Register the callbacks after everything is successful and nothing can fail. Otherwise the callback parameter would be freed twise, once from TMCB_DESTROY, and again because of the negative return code. */ - if(uac_r->cb && insert_tmcb(&(new_cell->tmcb_hl), uac_r->cb_flags, - *(uac_r->cb), uac_r->cbp, NULL)!=1){ - ret=E_OUT_OF_MEM; + if(uac_r->cb + && insert_tmcb(&(new_cell->tmcb_hl), uac_r->cb_flags, *(uac_r->cb), + uac_r->cbp, NULL) + != 1) { + ret = E_OUT_OF_MEM; LM_ERR("short of tmcb shmem\n"); goto error1; } - if (has_local_reqin_tmcbs()) - run_local_reqin_callbacks(new_cell, 0, 0); + if(has_local_reqin_tmcbs()) + run_local_reqin_callbacks(new_cell, 0, 0); #ifdef DIALOG_CALLBACKS run_trans_dlg_callbacks(uac_r->dialog, new_cell, request); #endif /* DIALOG_CALLBACKS */ - if (dst_req) *dst_req = request; - if (dst_cell) *dst_cell = new_cell; - else if(is_ack && dst_req==0){ + if(dst_req) + *dst_req = request; + if(dst_cell) + *dst_cell = new_cell; + else if(is_ack && dst_req == 0) { free_cell(new_cell); } return 1; - error1: - if (!is_ack) { +error1: + if(!is_ack) { LOCK_HASH(hi); remove_from_hash_table_unsafe(new_cell); UNLOCK_HASH(hi); } error2: - if (is_ack) { + if(is_ack) { free_cell(new_cell); } else { if((new_cell->next_c == 0 && new_cell->prev_c == 0) - || (atomic_get_int(&new_cell->ref_count)==0)) { + || (atomic_get_int(&new_cell->ref_count) == 0)) { free_cell(new_cell); } else { UNREF_FREE(new_cell, 0); @@ -641,38 +657,40 @@ static inline int t_uac_prepare(uac_req_t *uac_r, /* * Prepare a message within a dialog */ -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) { int ret = -1; - if (!uac_r || !uac_r->method || !uac_r->dialog) { + if(!uac_r || !uac_r->method || !uac_r->dialog) { LM_ERR("Invalid parameter value\n"); goto err; } - if (uac_r->dialog->state != DLG_CONFIRMED) { + if(uac_r->dialog->state != DLG_CONFIRMED) { LM_ERR("Dialog is not confirmed yet\n"); goto err; } - if ((uac_r->method->len == 3) && (!memcmp("ACK", uac_r->method->s, 3))) goto send; - if ((uac_r->method->len == 6) && (!memcmp("CANCEL", uac_r->method->s, 6))) goto send; + if((uac_r->method->len == 3) && (!memcmp("ACK", uac_r->method->s, 3))) + goto send; + if((uac_r->method->len == 6) && (!memcmp("CANCEL", uac_r->method->s, 6))) + goto send; uac_r->dialog->loc_seq.value++; /* Increment CSeq */ - send: +send: ret = t_uac_prepare(uac_r, dst_req, 0); - - if (unlikely(ret < 0 && ret == E_DROP)) { + + if(unlikely(ret < 0 && ret == E_DROP)) { ret = 0; } - err: +err: /* if (cbp) shm_free(cbp); */ /* !! never free cbp here because if t_uac_prepare fails, cbp is not freed * and thus caller has no chance to discover if it is freed or not !! */ return ret; } -static inline int send_prepared_request_impl(struct retr_buf *request, int retransmit, int branch) +static inline int send_prepared_request_impl( + struct retr_buf *request, int retransmit, int branch) { struct cell *t; struct sip_msg *p_msg; @@ -684,35 +702,33 @@ static inline int send_prepared_request_impl(struct retr_buf *request, int retra uac = &t->uac[branch]; p_msg = t->uas.request; - if (SEND_BUFFER(request) == -1) { + if(SEND_BUFFER(request) == -1) { LM_ERR("Attempt to send to precreated request failed\n"); - } - else if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))) + } else if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))) /* we don't know the method here */ - run_trans_callbacks_with_buf(TMCB_REQUEST_SENT, &uac->request, 0, 0, - TMCB_LOCAL_F); + run_trans_callbacks_with_buf( + TMCB_REQUEST_SENT, &uac->request, 0, 0, TMCB_LOCAL_F); su2ip_addr(&ip, &uac->request.dst.to); - LM_DBG("uac: %p branch: %d to %s:%d\n", - uac, branch, ip_addr2a(&ip), su_getport(&uac->request.dst.to)); + LM_DBG("uac: %p branch: %d to %s:%d\n", uac, branch, ip_addr2a(&ip), + su_getport(&uac->request.dst.to)); - if (run_onsend(p_msg, &uac->request.dst, uac->request.buffer, - uac->request.buffer_len)==0){ - uac->last_received=408; + if(run_onsend(p_msg, &uac->request.dst, uac->request.buffer, + uac->request.buffer_len) + == 0) { + uac->last_received = 408; su2ip_addr(&ip, &uac->request.dst.to); - LM_DBG("onsend_route dropped msg. to %s:%d (%d)\n", - ip_addr2a(&ip), su_getport(&uac->request.dst.to), - uac->request.dst.proto); + LM_DBG("onsend_route dropped msg. to %s:%d (%d)\n", ip_addr2a(&ip), + su_getport(&uac->request.dst.to), uac->request.dst.proto); #ifdef USE_DNS_FAILOVER /* if the destination resolves to more ips, add another * branch/uac */ ret = add_uac_dns_fallback(t, p_msg, uac, retransmit); - if (ret > 0) { + if(ret > 0) { su2ip_addr(&ip, &uac->request.dst.to); LM_DBG("send on branch %d failed " - "(onsend_route), trying another ip %s:%d (%d)\n", - branch, ip_addr2a(&ip), - su_getport(&uac->request.dst.to), + "(onsend_route), trying another ip %s:%d (%d)\n", + branch, ip_addr2a(&ip), su_getport(&uac->request.dst.to), uac->request.dst.proto); /* success, return new branch */ return ret; @@ -721,7 +737,7 @@ static inline int send_prepared_request_impl(struct retr_buf *request, int retra return -1; } - if (retransmit && (start_retr(&uac->request)!=0)) + if(retransmit && (start_retr(&uac->request) != 0)) LM_CRIT("BUG: failed to start retr. for %p\n", &uac->request); return 0; } @@ -743,8 +759,8 @@ int t_uac(uac_req_t *uac_r) * Send a request using data from the dialog structure * 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) { struct retr_buf *request; struct cell *cell; @@ -755,35 +771,39 @@ int t_uac_with_ids(uac_req_t *uac_r, branch_bm_t added_branches = 1; ret = t_uac_prepare(uac_r, &request, &cell); - - if (ret < 0) { - if (unlikely(ret == E_DROP)) { + + if(ret < 0) { + if(unlikely(ret == E_DROP)) { ret = 0; } return ret; } - is_ack = (uac_r->method->len == 3) && (memcmp("ACK", uac_r->method->s, 3)==0) ? 1 : 0; + is_ack = (uac_r->method->len == 3) + && (memcmp("ACK", uac_r->method->s, 3) == 0) + ? 1 + : 0; /* equivalent loop to the one in t_forward_nonack */ - for (i=0; inr_of_outgoings; i++) { - if (added_branches & (1<=0){ /* some kind of success */ - if (branch_ret>i) { + for(i = 0; i < cell->nr_of_outgoings; i++) { + if(added_branches & (1 << i)) { + branch_ret = send_prepared_request_impl( + request, !is_ack /* retransmit */, i); + if(branch_ret >= 0) { /* some kind of success */ + if(branch_ret > i) { /* new branch added */ - added_branches |= 1<hash_index; *ret_label = cell->label; } @@ -792,7 +812,7 @@ int t_uac_with_ids(uac_req_t *uac_r, } 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) { struct retr_buf *lack; unsigned int buf_len; @@ -800,9 +820,8 @@ struct retr_buf *local_ack_rb(sip_msg_t *rpl_2xx, struct cell *trans, struct dest_info dst; buf_len = (unsigned)sizeof(struct retr_buf); - buffer = build_dlg_ack(rpl_2xx, trans, branch, hdrs, body, - &buf_len, &dst); - if (!buffer || buf_len<=0) { + buffer = build_dlg_ack(rpl_2xx, trans, branch, hdrs, body, &buf_len, &dst); + if(!buffer || buf_len <= 0) { if(buffer) { shm_free(buffer); } @@ -850,67 +869,69 @@ int ack_local_uac(struct cell *trans, str *hdrs, str *body) /* sanity checks */ #ifdef EXTRA_DEBUG - if (! trans) { + if(!trans) { LM_BUG("no transaction to ACK.\n"); abort(); } #endif #define RET_INVALID \ - ret = -2; \ - goto fin + ret = -2; \ + goto fin - if (! is_local(trans)) { + if(!is_local(trans)) { LM_ERR("trying to ACK non local transaction (T@%p).\n", trans); RET_INVALID; } - if (! is_invite(trans)) { + if(!is_invite(trans)) { LM_ERR("trying to ACK non INVITE local transaction (T@%p).\n", trans); RET_INVALID; } - if (! trans->uac[0].reply) { - LM_ERR("trying to ACK un-completed INVITE transaction (T@%p).\n", trans); + if(!trans->uac[0].reply) { + LM_ERR("trying to ACK un-completed INVITE transaction (T@%p).\n", + trans); RET_INVALID; } - if (! (trans->flags & T_NO_AUTO_ACK)) { + if(!(trans->flags & T_NO_AUTO_ACK)) { LM_ERR("trying to ACK an auto-ACK transaction (T@%p).\n", trans); RET_INVALID; } - if (trans->uac[0].local_ack) { + if(trans->uac[0].local_ack) { LM_ERR("trying to rebuild ACK retransmission buffer (T@%p).\n", trans); RET_INVALID; } /* looks sane: build the retransmission buffer */ - if (! (local_ack = local_ack_rb(trans->uac[0].reply, trans, /*branch*/0, - hdrs, body))) { + if(!(local_ack = local_ack_rb( + trans->uac[0].reply, trans, /*branch*/ 0, hdrs, body))) { LM_ERR("failed to build ACK retransmission buffer\n"); RET_INVALID; } else { /* set the new buffer, but only if not already set (conc. invok.) */ - if ((old_lack = (struct retr_buf *)atomic_cmpxchg_long( - (void *)&trans->uac[0].local_ack, 0, (long)local_ack))) { + if((old_lack = (struct retr_buf *)atomic_cmpxchg_long( + (void *)&trans->uac[0].local_ack, 0, (long)local_ack))) { /* buffer already set: deny current attempt */ - LM_ERR("concurrent ACKing for local INVITE detected (T@%p).\n",trans); + LM_ERR("concurrent ACKing for local INVITE detected (T@%p).\n", + trans); free_local_ack(local_ack); RET_INVALID; } } - if (msg_send(&local_ack->dst, local_ack->buffer, local_ack->buffer_len)<0){ + if(msg_send(&local_ack->dst, local_ack->buffer, local_ack->buffer_len) + < 0) { /* hopefully will succeed on next 2xx retransmission */ LM_ERR("failed to send local ACK (T@%p).\n", trans); ret = -1; goto fin; - } - else { + } else { INIT_TMCB_ONSEND_PARAMS(onsend_params, 0, 0, &trans->uac[0].request, - &local_ack->dst, - local_ack->buffer, local_ack->buffer_len, - TMCB_LOCAL_F, 0 /* branch */, TYPE_LOCAL_ACK); - run_trans_callbacks_off_params(TMCB_REQUEST_SENT, trans, &onsend_params); + &local_ack->dst, local_ack->buffer, local_ack->buffer_len, + TMCB_LOCAL_F, 0 /* branch */, TYPE_LOCAL_ACK); + run_trans_callbacks_off_params( + TMCB_REQUEST_SENT, trans, &onsend_params); } ret = 0; @@ -921,7 +942,7 @@ int ack_local_uac(struct cell *trans, str *hdrs, str *body) * message (all available might be the reply, but if AS goes wrong and * tries to ACK before the final reply is received, we still have to * lookup the T to find this out). */ - UNREF( trans ); + UNREF(trans); return ret; #undef RET_INVALID @@ -935,22 +956,22 @@ int req_within(uac_req_t *uac_r) { int ret; char nbuf[MAX_URI_SIZE]; -#define REQ_DST_URI_SIZE 80 +#define REQ_DST_URI_SIZE 80 char dbuf[REQ_DST_URI_SIZE]; str ouri = {0, 0}; str nuri = {0, 0}; str duri = {0, 0}; - if (!uac_r || !uac_r->method || !uac_r->dialog) { + if(!uac_r || !uac_r->method || !uac_r->dialog) { LM_ERR("Invalid parameter value\n"); goto err; } - if(uac_r->dialog->send_sock==NULL) { - if(uac_r->ssockname!=NULL && uac_r->ssockname->len>0) { + if(uac_r->dialog->send_sock == NULL) { + if(uac_r->ssockname != NULL && uac_r->ssockname->len > 0) { /* set local send socket by name */ uac_r->dialog->send_sock = ksr_get_socket_by_name(uac_r->ssockname); - } else if(uac_r->ssock!=NULL && uac_r->ssock->len>0) { + } else if(uac_r->ssock != NULL && uac_r->ssock->len > 0) { /* set local send socket by address */ uac_r->dialog->send_sock = lookup_local_socket(uac_r->ssock); } @@ -958,43 +979,45 @@ int req_within(uac_req_t *uac_r) /* handle alias parameter in uri * - only if no dst uri and no route set - */ - if(uac_r->dialog && uac_r->dialog->rem_target.len>0 - && uac_r->dialog->dst_uri.len==0 - && uac_r->dialog->route_set==NULL) { + if(uac_r->dialog && uac_r->dialog->rem_target.len > 0 + && uac_r->dialog->dst_uri.len == 0 + && uac_r->dialog->route_set == NULL) { ouri = uac_r->dialog->rem_target; /*restore alias parameter*/ nuri.s = nbuf; nuri.len = MAX_URI_SIZE; duri.s = dbuf; duri.len = REQ_DST_URI_SIZE; - if(uri_restore_rcv_alias(&ouri, &nuri, &duri)<0) { + if(uri_restore_rcv_alias(&ouri, &nuri, &duri) < 0) { nuri.len = 0; duri.len = 0; } - if(nuri.len>0 && duri.len>0) { + if(nuri.len > 0 && duri.len > 0) { uac_r->dialog->rem_target = nuri; - uac_r->dialog->dst_uri = duri; + uac_r->dialog->dst_uri = duri; } else { ouri.len = 0; } } - if ((uac_r->method->len == 3) && (!memcmp("ACK", uac_r->method->s, 3))) goto send; - if ((uac_r->method->len == 6) && (!memcmp("CANCEL", uac_r->method->s, 6))) goto send; + if((uac_r->method->len == 3) && (!memcmp("ACK", uac_r->method->s, 3))) + goto send; + if((uac_r->method->len == 6) && (!memcmp("CANCEL", uac_r->method->s, 6))) + goto send; uac_r->dialog->loc_seq.value++; /* Increment CSeq */ - send: +send: ret = t_uac(uac_r); - if(ouri.len>0) { + if(ouri.len > 0) { uac_r->dialog->rem_target = ouri; uac_r->dialog->dst_uri.s = 0; uac_r->dialog->dst_uri.len = 0; } return ret; - err: +err: /* callback parameter must be freed outside of tm module if (cbp) shm_free(cbp); */ - if(ouri.len>0) { + if(ouri.len > 0) { uac_r->dialog->rem_target = ouri; uac_r->dialog->dst_uri.s = 0; uac_r->dialog->dst_uri.len = 0; @@ -1007,34 +1030,37 @@ int req_within(uac_req_t *uac_r) * Send an initial request that will start a dialog * WARNING: writes uac_r->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) { str callid, fromtag; - if (check_params(uac_r, to, from) < 0) goto err; + if(check_params(uac_r, to, from) < 0) + goto err; generate_callid(&callid); generate_fromtag(&fromtag, &callid, ruri); - if (new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &uac_r->dialog) < 0) { + if(new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &uac_r->dialog) + < 0) { LM_ERR("Error while creating new dialog\n"); goto err; } - if (ruri) { + if(ruri) { uac_r->dialog->rem_target.s = ruri->s; uac_r->dialog->rem_target.len = ruri->len; /* hooks will be set from w_calculate_hooks */ } - if (next_hop) uac_r->dialog->dst_uri = *next_hop; + if(next_hop) + uac_r->dialog->dst_uri = *next_hop; w_calculate_hooks(uac_r->dialog); - if(uac_r->dialog->send_sock==NULL) { - if(uac_r->ssockname!=NULL && uac_r->ssockname->len>0) { + if(uac_r->dialog->send_sock == NULL) { + if(uac_r->ssockname != NULL && uac_r->ssockname->len > 0) { /* set local send socket by name */ uac_r->dialog->send_sock = ksr_get_socket_by_name(uac_r->ssockname); - } else if(uac_r->ssock!=NULL && uac_r->ssock->len>0) { + } else if(uac_r->ssock != NULL && uac_r->ssock->len > 0) { /* set local send socket by address */ uac_r->dialog->send_sock = lookup_local_socket(uac_r->ssock); } @@ -1042,7 +1068,7 @@ int req_outside(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop) return t_uac(uac_r); - err: +err: /* callback parameter must be freed outside of tm module if (cbp) shm_free(cbp); */ return -1; @@ -1053,32 +1079,34 @@ int req_outside(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop) * Send a transactional request, no dialogs involved * WARNING: writes uac_r->dialog */ -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) { str callid, fromtag; - dlg_t* dialog; + dlg_t *dialog; int res; - if (check_params(uac_r, to, from) < 0) goto err; + if(check_params(uac_r, to, from) < 0) + goto err; - if (uac_r->callid == NULL || uac_r->callid->len <= 0) - generate_callid(&callid); + if(uac_r->callid == NULL || uac_r->callid->len <= 0) + generate_callid(&callid); else - callid = *uac_r->callid; + callid = *uac_r->callid; generate_fromtag(&fromtag, &callid, ruri); - if (new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &dialog) < 0) { + if(new_dlg_uac(&callid, &fromtag, DEFAULT_CSEQ, from, to, &dialog) < 0) { LM_ERR("Error while creating temporary dialog\n"); goto err; } - if (ruri) { + if(ruri) { dialog->rem_target.s = ruri->s; dialog->rem_target.len = ruri->len; /* hooks will be set from w_calculate_hooks */ } - if (next_hop) dialog->dst_uri = *next_hop; + if(next_hop) + dialog->dst_uri = *next_hop; w_calculate_hooks(dialog); /* WARNING: @@ -1094,11 +1122,11 @@ int request(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop) */ uac_r->dialog = dialog; - if(uac_r->dialog->send_sock==NULL) { - if(uac_r->ssockname!=NULL && uac_r->ssockname->len>0) { + if(uac_r->dialog->send_sock == NULL) { + if(uac_r->ssockname != NULL && uac_r->ssockname->len > 0) { /* set local send socket by name */ uac_r->dialog->send_sock = ksr_get_socket_by_name(uac_r->ssockname); - } else if(uac_r->ssock!=NULL && uac_r->ssock->len>0) { + } else if(uac_r->ssock != NULL && uac_r->ssock->len > 0) { /* set local send socket by address */ uac_r->dialog->send_sock = lookup_local_socket(uac_r->ssock); } @@ -1111,7 +1139,7 @@ int request(uac_req_t *uac_r, str* ruri, str* to, str* from, str *next_hop) uac_r->dialog = 0; return res; - err: +err: /* callback parameter must be freed outside of tm module if (cp) shm_free(cp); */ return -1; diff --git a/src/modules/tm/uac.h b/src/modules/tm/uac.h index 3b9bd64a282..59fa7f4e9ea 100644 --- a/src/modules/tm/uac.h +++ b/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); diff --git a/src/modules/tm/ut.h b/src/modules/tm/ut.h index 41e69c407f2..308b70e1d6c 100644 --- a/src/modules/tm/ut.h +++ b/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); }