From b0b4d5d41b8ff0e6afb429a91d16c07f8e6efffb Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 17 May 2023 16:37:39 +0200 Subject: [PATCH] tmx: clang-format for coherent indentation and coding style --- src/modules/tmx/api.h | 10 +- src/modules/tmx/t_var.c | 393 +++++++++++++------------- src/modules/tmx/t_var.h | 35 +-- src/modules/tmx/tmx_mod.c | 514 ++++++++++++++++------------------ src/modules/tmx/tmx_pretran.c | 139 ++++----- 5 files changed, 534 insertions(+), 557 deletions(-) diff --git a/src/modules/tmx/api.h b/src/modules/tmx/api.h index 83c38f6ed08..994215a1012 100644 --- a/src/modules/tmx/api.h +++ b/src/modules/tmx/api.h @@ -1,12 +1,13 @@ #ifndef _TMX_API_H_ #define _TMX_API_H_ -typedef int (*tmx_t_suspend_f)(struct sip_msg*, char*, char*); -typedef struct tmx_api { +typedef int (*tmx_t_suspend_f)(struct sip_msg *, char *, char *); +typedef struct tmx_api +{ tmx_t_suspend_f t_suspend; } tmx_api_t; -typedef int (*bind_tmx_f)(tmx_api_t* api); +typedef int (*bind_tmx_f)(tmx_api_t *api); static inline int load_tmx_api(tmx_api_t *api) { @@ -17,8 +18,7 @@ static inline int load_tmx_api(tmx_api_t *api) LM_ERR("cannot find bind_tmx\n"); return -1; } - if(bindtmx(api)<0) - { + if(bindtmx(api) < 0) { LM_ERR("cannot bind tmx api\n"); return -1; } diff --git a/src/modules/tmx/t_var.c b/src/modules/tmx/t_var.c index 64a81e591b0..5e3bda67910 100644 --- a/src/modules/tmx/t_var.c +++ b/src/modules/tmx/t_var.c @@ -31,7 +31,8 @@ #include "tmx_mod.h" #include "t_var.h" -struct _pv_tmx_data { +struct _pv_tmx_data +{ unsigned int index; unsigned int label; int branch; @@ -56,15 +57,14 @@ int pv_t_copy_msg(struct sip_msg *src, struct sip_msg *dst) { dst->id = src->id; dst->rcv = src->rcv; - dst->set_global_address=src->set_global_address; - dst->set_global_port=src->set_global_port; + dst->set_global_address = src->set_global_address; + dst->set_global_port = src->set_global_port; dst->flags = src->flags; dst->fwd_send_flags = src->fwd_send_flags; dst->rpl_send_flags = src->rpl_send_flags; dst->force_send_socket = src->force_send_socket; - if (parse_msg(dst->buf, dst->len, dst)!=0) - { + if(parse_msg(dst->buf, dst->len, dst) != 0) { LM_ERR("parse msg failed\n"); return -1; } @@ -73,50 +73,46 @@ int pv_t_copy_msg(struct sip_msg *src, struct sip_msg *dst) int pv_t_update_req(struct sip_msg *msg) { - struct cell * t; + struct cell *t; int branch; - if(msg==NULL) + if(msg == NULL) return 1; - if(msg!=FAKED_REPLY && msg->first_line.type!=SIP_REPLY) + if(msg != FAKED_REPLY && msg->first_line.type != SIP_REPLY) return 1; t = _tmx_tmb.t_gett(); - if(t==NULL || t==T_UNDEFINED) - { - if(msg==FAKED_REPLY) + if(t == NULL || t == T_UNDEFINED) { + if(msg == FAKED_REPLY) return 1; - branch=-1; - if (_tmx_tmb.t_check(msg, &branch ) == -1) + branch = -1; + if(_tmx_tmb.t_check(msg, &branch) == -1) return 1; t = _tmx_tmb.t_gett(); - if ((t == 0) || (t == T_UNDEFINED)) + if((t == 0) || (t == T_UNDEFINED)) return 1; - } - if(t->uas.request==NULL) + if(t->uas.request == NULL) return 1; - if (_pv_treq.label == t->label && _pv_treq.index == t->hash_index) + if(_pv_treq.label == t->label && _pv_treq.index == t->hash_index) return 0; /* make a copy */ - if(_pv_treq.buf==NULL || _pv_treq.buf_sizeuas.request->len+1) - { - if(_pv_treq.buf!=NULL) + if(_pv_treq.buf == NULL || _pv_treq.buf_size < t->uas.request->len + 1) { + if(_pv_treq.buf != NULL) pkg_free(_pv_treq.buf); if(_pv_treq.tmsgp) free_sip_msg(&_pv_treq.msg); _pv_treq.tmsgp = NULL; _pv_treq.index = 0; _pv_treq.label = 0; - _pv_treq.buf_size = t->uas.request->len+1; - _pv_treq.buf = (char*)pkg_malloc(_pv_treq.buf_size*sizeof(char)); - if(_pv_treq.buf==NULL) - { + _pv_treq.buf_size = t->uas.request->len + 1; + _pv_treq.buf = (char *)pkg_malloc(_pv_treq.buf_size * sizeof(char)); + if(_pv_treq.buf == NULL) { PKG_MEM_ERROR; _pv_treq.buf_size = 0; return -1; @@ -134,8 +130,7 @@ int pv_t_update_req(struct sip_msg *msg) _pv_treq.label = t->label; - if(pv_t_copy_msg(t->uas.request, &_pv_treq.msg)!=0) - { + if(pv_t_copy_msg(t->uas.request, &_pv_treq.msg) != 0) { pkg_free(_pv_treq.buf); _pv_treq.buf_size = 0; _pv_treq.buf = NULL; @@ -150,40 +145,39 @@ int pv_t_update_req(struct sip_msg *msg) int pv_t_update_rpl(struct sip_msg *msg) { - struct cell * t; + struct cell *t; int branch; int cancel; - if(msg==NULL) + if(msg == NULL) return 1; - if(msg==FAKED_REPLY || msg->first_line.type!=SIP_REQUEST) + if(msg == FAKED_REPLY || msg->first_line.type != SIP_REQUEST) return 1; t = _tmx_tmb.t_gett(); - if(t==NULL || t==T_UNDEFINED) - { - if(_tmx_tmb.t_lookup_request(msg, 0, &cancel)<=0) + if(t == NULL || t == T_UNDEFINED) { + if(_tmx_tmb.t_lookup_request(msg, 0, &cancel) <= 0) return 1; t = _tmx_tmb.t_gett(); - if(t==NULL || t==T_UNDEFINED) + if(t == NULL || t == T_UNDEFINED) return 1; } - if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) + if((branch = _tmx_tmb.t_get_picked_branch()) < 0) return 1; - if(t->uac[branch].reply==NULL || t->uac[branch].reply==FAKED_REPLY) + if(t->uac[branch].reply == NULL || t->uac[branch].reply == FAKED_REPLY) return 1; - if (_pv_trpl.label == t->label && _pv_trpl.index == t->hash_index + if(_pv_trpl.label == t->label && _pv_trpl.index == t->hash_index && _pv_trpl.branch == branch) return 0; /* make a copy */ - if(_pv_trpl.buf==NULL || _pv_trpl.buf_sizeuac[branch].reply->len+1) - { - if(_pv_trpl.buf!=NULL) + if(_pv_trpl.buf == NULL + || _pv_trpl.buf_size < t->uac[branch].reply->len + 1) { + if(_pv_trpl.buf != NULL) pkg_free(_pv_trpl.buf); if(_pv_trpl.tmsgp) free_sip_msg(&_pv_trpl.msg); @@ -191,10 +185,9 @@ int pv_t_update_rpl(struct sip_msg *msg) _pv_trpl.index = 0; _pv_trpl.label = 0; _pv_trpl.branch = 0; - _pv_trpl.buf_size = t->uac[branch].reply->len+1; - _pv_trpl.buf = (char*)pkg_malloc(_pv_trpl.buf_size*sizeof(char)); - if(_pv_trpl.buf==NULL) - { + _pv_trpl.buf_size = t->uac[branch].reply->len + 1; + _pv_trpl.buf = (char *)pkg_malloc(_pv_trpl.buf_size * sizeof(char)); + if(_pv_trpl.buf == NULL) { PKG_MEM_ERROR; _pv_trpl.buf_size = 0; return -1; @@ -212,8 +205,7 @@ int pv_t_update_rpl(struct sip_msg *msg) _pv_trpl.label = t->label; _pv_trpl.branch = branch; - if(pv_t_copy_msg(t->uac[branch].reply, &_pv_trpl.msg)!=0) - { + if(pv_t_copy_msg(t->uac[branch].reply, &_pv_trpl.msg) != 0) { pkg_free(_pv_trpl.buf); _pv_trpl.buf_size = 0; _pv_trpl.buf = NULL; @@ -229,40 +221,38 @@ int pv_t_update_rpl(struct sip_msg *msg) int pv_t_update_inv(struct sip_msg *msg) { - struct cell * t; + struct cell *t; - if(msg==NULL) + if(msg == NULL) return 1; - if (msg->REQ_METHOD!=METHOD_CANCEL) + if(msg->REQ_METHOD != METHOD_CANCEL) return 1; t = _tmx_tmb.t_lookup_original(msg); - if(t==NULL || t==T_UNDEFINED) + if(t == NULL || t == T_UNDEFINED) return 1; - if(t->uas.request==NULL) { + if(t->uas.request == NULL) { _tmx_tmb.unref_cell(t); return 1; } - if (_pv_tinv.label == t->label && _pv_tinv.index == t->hash_index) + if(_pv_tinv.label == t->label && _pv_tinv.index == t->hash_index) goto done; /* make a copy */ - if(_pv_tinv.buf==NULL || _pv_tinv.buf_sizeuas.request->len+1) - { - if(_pv_tinv.buf!=NULL) + if(_pv_tinv.buf == NULL || _pv_tinv.buf_size < t->uas.request->len + 1) { + if(_pv_tinv.buf != NULL) pkg_free(_pv_tinv.buf); if(_pv_tinv.tmsgp) free_sip_msg(&_pv_tinv.msg); _pv_tinv.tmsgp = NULL; _pv_tinv.index = 0; _pv_tinv.label = 0; - _pv_tinv.buf_size = t->uas.request->len+1; - _pv_tinv.buf = (char*)pkg_malloc(_pv_tinv.buf_size*sizeof(char)); - if(_pv_tinv.buf==NULL) - { + _pv_tinv.buf_size = t->uas.request->len + 1; + _pv_tinv.buf = (char *)pkg_malloc(_pv_tinv.buf_size * sizeof(char)); + if(_pv_tinv.buf == NULL) { PKG_MEM_ERROR; _pv_tinv.buf_size = 0; goto error; @@ -280,8 +270,7 @@ int pv_t_update_inv(struct sip_msg *msg) _pv_tinv.label = t->label; - if(pv_t_copy_msg(t->uas.request, &_pv_tinv.msg)!=0) - { + if(pv_t_copy_msg(t->uas.request, &_pv_tinv.msg) != 0) { pkg_free(_pv_tinv.buf); _pv_tinv.buf_size = 0; _pv_tinv.buf = NULL; @@ -300,12 +289,11 @@ int pv_t_update_inv(struct sip_msg *msg) return -1; } -int pv_get_t_var_req(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_t_var_req(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { - pv_spec_t *pv=NULL; + pv_spec_t *pv = NULL; - if(!is_route_type(CORE_ONREPLY_ROUTE|TM_ONREPLY_ROUTE)) { + if(!is_route_type(CORE_ONREPLY_ROUTE | TM_ONREPLY_ROUTE)) { LM_DBG("used in unsupported route block - type %d\n", get_route_type()); return pv_get_null(msg, param, res); } @@ -313,19 +301,18 @@ int pv_get_t_var_req(struct sip_msg *msg, pv_param_t *param, if(pv_t_update_req(msg)) return pv_get_null(msg, param, res); - pv = (pv_spec_t*)param->pvn.u.dname; - if(pv==NULL || pv_alter_context(pv)) + pv = (pv_spec_t *)param->pvn.u.dname; + if(pv == NULL || pv_alter_context(pv)) return pv_get_null(msg, param, res); return pv_get_spec_value(&_pv_treq.msg, pv, res); } -int pv_get_t_var_rpl(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_t_var_rpl(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { - pv_spec_t *pv=NULL; + pv_spec_t *pv = NULL; - if(!is_route_type(FAILURE_ROUTE|BRANCH_FAILURE_ROUTE)) { + if(!is_route_type(FAILURE_ROUTE | BRANCH_FAILURE_ROUTE)) { LM_DBG("used in unsupported route block - type %d\n", get_route_type()); return pv_get_null(msg, param, res); } @@ -333,19 +320,19 @@ int pv_get_t_var_rpl(struct sip_msg *msg, pv_param_t *param, if(pv_t_update_rpl(msg)) return pv_get_null(msg, param, res); - pv = (pv_spec_t*)param->pvn.u.dname; - if(pv==NULL || pv_alter_context(pv)) + pv = (pv_spec_t *)param->pvn.u.dname; + if(pv == NULL || pv_alter_context(pv)) return pv_get_null(msg, param, res); return pv_get_spec_value(&_pv_trpl.msg, pv, res); } -int pv_get_t_var_branch(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_t_var_branch(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { - pv_spec_t *pv=NULL; + pv_spec_t *pv = NULL; - if(!is_route_type(FAILURE_ROUTE|BRANCH_FAILURE_ROUTE|TM_ONREPLY_ROUTE)) { + if(!is_route_type( + FAILURE_ROUTE | BRANCH_FAILURE_ROUTE | TM_ONREPLY_ROUTE)) { LM_DBG("used in unsupported route block - type %d\n", get_route_type()); return pv_get_null(msg, param, res); } @@ -353,17 +340,16 @@ int pv_get_t_var_branch(struct sip_msg *msg, pv_param_t *param, if(pv_t_update_rpl(msg)) return pv_get_null(msg, param, res); - pv = (pv_spec_t*)param->pvn.u.dname; - if(pv==NULL || pv_alter_context(pv)) + pv = (pv_spec_t *)param->pvn.u.dname; + if(pv == NULL || pv_alter_context(pv)) return pv_get_null(msg, param, res); return pv_get_spec_value(&_pv_trpl.msg, pv, res); } -int pv_get_t_var_inv(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_t_var_inv(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { - pv_spec_t *pv=NULL; + pv_spec_t *pv = NULL; if(!is_route_type(REQUEST_ROUTE)) { LM_DBG("used in unsupported route block - type %d\n", get_route_type()); @@ -373,8 +359,8 @@ int pv_get_t_var_inv(struct sip_msg *msg, pv_param_t *param, if(pv_t_update_inv(msg)) return pv_get_null(msg, param, res); - pv = (pv_spec_t*)param->pvn.u.dname; - if(pv==NULL || pv_alter_context(pv)) + pv = (pv_spec_t *)param->pvn.u.dname; + if(pv == NULL || pv_alter_context(pv)) return pv_get_null(msg, param, res); return pv_get_spec_value(&_pv_tinv.msg, pv, res); @@ -382,36 +368,36 @@ int pv_get_t_var_inv(struct sip_msg *msg, pv_param_t *param, int pv_parse_t_var_name(pv_spec_p sp, str *in) { - pv_spec_t *pv=NULL; + pv_spec_t *pv = NULL; - if(in->s==NULL || in->len<=0) + if(in->s == NULL || in->len <= 0) return -1; - pv = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t)); - if(pv==NULL) { + pv = (pv_spec_t *)pkg_malloc(sizeof(pv_spec_t)); + if(pv == NULL) { PKG_MEM_ERROR; return -1; } memset(pv, 0, sizeof(pv_spec_t)); - if(pv_parse_spec(in, pv)==NULL) + if(pv_parse_spec(in, pv) == NULL) goto error; - sp->pvp.pvn.u.dname = (void*)pv; + sp->pvp.pvn.u.dname = (void *)pv; sp->pvp.pvn.type = PV_NAME_PVAR; return 0; error: LM_ERR("invalid pv name [%.*s]\n", in->len, in->s); - if(pv!=NULL) + if(pv != NULL) pkg_free(pv); return -1; } /* item functions */ -int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_tm_branch_idx( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { int l = 0; char *ch = NULL; @@ -419,7 +405,7 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param, tm_ctx_t *tcx = 0; int idx = T_BR_UNDEFINED; - if(msg==NULL || res==NULL) + if(msg == NULL || res == NULL) return -1; /* statefull replies have the branch_index set */ @@ -427,30 +413,31 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param, tcx = _tmx_tmb.tm_ctx_get(); 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 = _tmx_tmb.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 = _tmx_tmb.t_gett(); - 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 = _tmx_tmb.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 = _tmx_tmb.t_gett(); + 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; + } ch = sint2str(idx, &l); @@ -458,37 +445,40 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param, res->rs.len = l; res->ri = idx; - res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT; + res->flags = PV_VAL_STR | PV_VAL_INT | PV_TYPE_INT; return 0; } -int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_tm_reply_ruid( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct cell *t; tm_ctx_t *tcx = 0; int branch; - if(msg==NULL || res==NULL) + if(msg == NULL || res == NULL) return -1; /* first get the transaction */ - if (_tmx_tmb.t_check( msg , 0 )==-1) return -1; - if ( (t=_tmx_tmb.t_gett())==0) { + if(_tmx_tmb.t_check(msg, 0) == -1) + return -1; + if((t = _tmx_tmb.t_gett()) == 0) { /* no T */ return pv_get_strempty(msg, param, res); } else { - switch (get_route_type()) { + switch(get_route_type()) { case FAILURE_ROUTE: case BRANCH_FAILURE_ROUTE: /* use the reason of the winning reply */ - if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) { + if((branch = _tmx_tmb.t_get_picked_branch()) < 0) { LM_CRIT("no picked branch (%d) for a final response" - " in MODE_ONFAILURE\n", branch); + " in MODE_ONFAILURE\n", + branch); return pv_get_strempty(msg, param, res); } - LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, t->uac[branch].ruid.s); + LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, + t->uac[branch].ruid.s); return pv_get_strval(msg, param, res, &t->uac[branch].ruid); break; case TM_ONREPLY_ROUTE: @@ -497,10 +487,11 @@ int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param, return pv_get_strempty(msg, param, res); } branch = tcx->branch_index; - if(branch<0 || branch>=t->nr_of_outgoings) { + if(branch < 0 || branch >= t->nr_of_outgoings) { return pv_get_strempty(msg, param, res); } - LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, t->uac[branch].ruid.s); + LM_DBG("reply ruid is [%.*s]\n", t->uac[branch].ruid.len, + t->uac[branch].ruid.s); return pv_get_strval(msg, param, res, &t->uac[branch].ruid); default: LM_ERR("unsupported route_type %d\n", get_route_type()); @@ -509,17 +500,17 @@ int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param, } } -int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_tm_reply_code( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct cell *t; int code; int branch; - if(msg==NULL || res==NULL) + if(msg == NULL || res == NULL) return -1; - switch (get_route_type()) { + switch(get_route_type()) { case CORE_ONREPLY_ROUTE: case TM_ONREPLY_ROUTE: /* use the status of the current reply */ @@ -528,12 +519,13 @@ int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param, } /* first get the transaction */ - if (_tmx_tmb.t_check( msg , 0 )==-1) return -1; - if ( (t=_tmx_tmb.t_gett())==0) { + if(_tmx_tmb.t_check(msg, 0) == -1) + return -1; + if((t = _tmx_tmb.t_gett()) == 0) { /* no T */ code = 0; } else { - switch (get_route_type()) { + switch(get_route_type()) { case REQUEST_ROUTE: case BRANCH_ROUTE: /* use the status of the last sent reply */ @@ -542,9 +534,10 @@ int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param, case FAILURE_ROUTE: case BRANCH_FAILURE_ROUTE: /* use the status of the winning reply */ - if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) { + if((branch = _tmx_tmb.t_get_picked_branch()) < 0) { LM_CRIT("no picked branch (%d) for a final response" - " in MODE_ONFAILURE\n", branch); + " in MODE_ONFAILURE\n", + branch); code = 0; } else { code = t->uac[branch].last_received; @@ -564,24 +557,24 @@ int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param, return 0; } -int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_tm_reply_reason( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct cell *t; struct sip_msg *reply; int branch = -1; int vref = 0; - if(msg==NULL || res==NULL) + if(msg == NULL || res == NULL) return -1; /* first get the transaction */ t = _tmx_tmb.t_find(msg, &branch, &vref); - if (t==T_NULL_CELL || t==T_UNDEFINED) { + if(t == T_NULL_CELL || t == T_UNDEFINED) { /* no T */ return pv_get_strempty(msg, param, res); } else { - switch (get_route_type()) { + switch(get_route_type()) { case CORE_ONREPLY_ROUTE: if(vref) { /* t_find() above has the side effect of setting T and @@ -597,13 +590,14 @@ int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param, break; case FAILURE_ROUTE: /* use the reason of the winning reply */ - if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) { + if((branch = _tmx_tmb.t_get_picked_branch()) < 0) { LM_CRIT("no picked branch (%d) for a final response" - " in MODE_ONFAILURE\n", branch); + " in MODE_ONFAILURE\n", + branch); return -1; } reply = t->uac[branch].reply; - if (reply == FAKED_REPLY) { + if(reply == FAKED_REPLY) { res->rs.s = error_text(t->uac[branch].last_received); res->rs.len = strlen(res->rs.s); } else { @@ -621,25 +615,26 @@ int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param, return 0; } -int pv_get_tm_reply_last_received(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_tm_reply_last_received( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { struct cell *t; tm_ctx_t *tcx = 0; int code; - if(msg==NULL || res==NULL) + if(msg == NULL || res == NULL) return -1; /* Only for TM reply route */ - if (get_route_type() != TM_ONREPLY_ROUTE) { + if(get_route_type() != TM_ONREPLY_ROUTE) { LM_ERR("unsupported route_type %d\n", get_route_type()); return -1; } /* first get the transaction */ - if (_tmx_tmb.t_check( msg , 0 )==-1) return -1; - if ( (t=_tmx_tmb.t_gett())==0) { + if(_tmx_tmb.t_check(msg, 0) == -1) + return -1; + if((t = _tmx_tmb.t_gett()) == 0) { /* no T */ LM_ERR("could not get transaction\n"); return -1; @@ -655,61 +650,66 @@ int pv_get_tm_reply_last_received(struct sip_msg *msg, pv_param_t *param, /* get the last received reply code */ code = t->uac[tcx->branch_index].last_received; - LM_DBG("reply code is <%d>\n",code); + LM_DBG("reply code is <%d>\n", code); - res->rs.s = int2str( code, &res->rs.len); + res->rs.s = int2str(code, &res->rs.len); res->ri = code; - res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT; + res->flags = PV_VAL_STR | PV_VAL_INT | PV_TYPE_INT; return 0; } int pv_parse_t_name(pv_spec_p sp, str *in) { - if(sp==NULL || in==NULL || in->len<=0) + if(sp == NULL || in == NULL || in->len <= 0) return -1; - switch(in->len) - { + switch(in->len) { case 3: if(strncmp(in->s, "uri", 3) == 0) sp->pvp.pvn.u.isname.name.n = 6; - else goto error; + else + goto error; break; case 4: if(strncmp(in->s, "ruid", 4) == 0) sp->pvp.pvn.u.isname.name.n = 7; - else goto error; + else + goto error; break; case 5: if(strncmp(in->s, "flags", 5) == 0) sp->pvp.pvn.u.isname.name.n = 5; - else goto error; + else + goto error; break; case 8: - if(strncmp(in->s, "id_label", 8)==0) + if(strncmp(in->s, "id_label", 8) == 0) sp->pvp.pvn.u.isname.name.n = 0; - else if(strncmp(in->s, "id_index", 8)==0) + else if(strncmp(in->s, "id_index", 8) == 0) sp->pvp.pvn.u.isname.name.n = 1; - else goto error; + else + goto error; break; case 10: - if(strncmp(in->s, "reply_code", 10)==0) + if(strncmp(in->s, "reply_code", 10) == 0) sp->pvp.pvn.u.isname.name.n = 2; - else if(strncmp(in->s, "reply_type", 10)==0) + else if(strncmp(in->s, "reply_type", 10) == 0) sp->pvp.pvn.u.isname.name.n = 3; - else if(strncmp(in->s, "id_label_n", 10)==0) + else if(strncmp(in->s, "id_label_n", 10) == 0) sp->pvp.pvn.u.isname.name.n = 8; - else if(strncmp(in->s, "id_index_n", 10)==0) + else if(strncmp(in->s, "id_index_n", 10) == 0) sp->pvp.pvn.u.isname.name.n = 9; - else goto error; + else + goto error; break; case 12: - if(strncmp(in->s, "branch_index", 12)==0) + if(strncmp(in->s, "branch_index", 12) == 0) sp->pvp.pvn.u.isname.name.n = 4; - else if(strncmp(in->s, "reply_reason", 12)==0) + else if(strncmp(in->s, "reply_reason", 12) == 0) sp->pvp.pvn.u.isname.name.n = 10; - else goto error; + else + goto error; break; default: goto error; @@ -722,20 +722,17 @@ int pv_parse_t_name(pv_spec_p sp, str *in) error: LM_ERR("unknown PV name %.*s\n", in->len, in->s); return -1; - } -int pv_get_t(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_t(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { tm_cell_t *t; - if(msg==NULL || param==NULL) + if(msg == NULL || param == NULL) return -1; /* aliases to old TM pvs */ - switch(param->pvn.u.isname.name.n) - { + switch(param->pvn.u.isname.name.n) { case 2: return pv_get_tm_reply_code(msg, param, res); case 4: @@ -745,31 +742,30 @@ int pv_get_t(struct sip_msg *msg, pv_param_t *param, } t = _tmx_tmb.t_gett(); - if(t==NULL || t==T_UNDEFINED) { + if(t == NULL || t == T_UNDEFINED) { /* no T */ - if(param->pvn.u.isname.name.n==8 || param->pvn.u.isname.name.n==9) { + if(param->pvn.u.isname.name.n == 8 || param->pvn.u.isname.name.n == 9) { /* id_label_n or id_index_n - attempt to create transaction */ - if(_tmx_tmb.t_newtran(msg)<0) { + if(_tmx_tmb.t_newtran(msg) < 0) { LM_ERR("cannot create the transaction\n"); return pv_get_null(msg, param, res); } t = _tmx_tmb.t_gett(); - if (t==NULL || t==T_UNDEFINED) { + if(t == NULL || t == T_UNDEFINED) { return pv_get_null(msg, param, res); } } else { return pv_get_null(msg, param, res); } } - switch(param->pvn.u.isname.name.n) - { + switch(param->pvn.u.isname.name.n) { case 1: return pv_get_uintval(msg, param, res, t->hash_index); case 3: - if(get_route_type()==FAILURE_ROUTE) { - if(_tmx_tmb.t_get_picked_branch()<0 ) + if(get_route_type() == FAILURE_ROUTE) { + if(_tmx_tmb.t_get_picked_branch() < 0) return pv_get_uintval(msg, param, res, 0); - if(t->uac[_tmx_tmb.t_get_picked_branch()].reply==FAKED_REPLY) + if(t->uac[_tmx_tmb.t_get_picked_branch()].reply == FAKED_REPLY) return pv_get_uintval(msg, param, res, 1); } return pv_get_uintval(msg, param, res, 0); @@ -782,30 +778,31 @@ int pv_get_t(struct sip_msg *msg, pv_param_t *param, } } -int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res) +int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) { tm_ctx_t *tcx = 0; tm_cell_t *t; int branch; - if ((msg == NULL) || (param == NULL)) return -1; + if((msg == NULL) || (param == NULL)) + return -1; t = _tmx_tmb.t_gett(); - if ((t == NULL) || (t == T_UNDEFINED)) { + if((t == NULL) || (t == T_UNDEFINED)) { /* no T */ return pv_get_null(msg, param, res); } switch(param->pvn.u.isname.name.n) { case 5: /* $T_branch(flags) */ - switch (get_route_type()) { + switch(get_route_type()) { case FAILURE_ROUTE: case BRANCH_FAILURE_ROUTE: /* use the reason of the winning reply */ - if ((branch=_tmx_tmb.t_get_picked_branch()) < 0) { + if((branch = _tmx_tmb.t_get_picked_branch()) < 0) { LM_CRIT("no picked branch (%d) for a final response" - " in MODE_ONFAILURE\n", branch); + " in MODE_ONFAILURE\n", + branch); return pv_get_null(msg, param, res); } break; @@ -821,14 +818,14 @@ int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, LM_ERR("unsupported route_type %d\n", get_route_type()); return pv_get_null(msg, param, res); } - if(branch<0 || branch>=t->nr_of_outgoings) { + if(branch < 0 || branch >= t->nr_of_outgoings) { return pv_get_null(msg, param, res); } LM_DBG("branch flags is [%u]\n", t->uac[branch].branch_flags); return pv_get_uintval(msg, param, res, t->uac[branch].branch_flags); break; case 6: /* $T_branch(uri) */ - if (get_route_type() != TM_ONREPLY_ROUTE) { + if(get_route_type() != TM_ONREPLY_ROUTE) { LM_ERR("$T_branch(uri) - unsupported route_type %d\n", get_route_type()); return pv_get_null(msg, param, res); @@ -838,7 +835,7 @@ int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, return pv_get_null(msg, param, res); } branch = tcx->branch_index; - if(branch<0 || branch>=t->nr_of_outgoings) { + if(branch < 0 || branch >= t->nr_of_outgoings) { return pv_get_null(msg, param, res); } return pv_get_strval(msg, param, res, &t->uac[branch].uri); @@ -849,12 +846,12 @@ int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, tcx = _tmx_tmb.tm_ctx_get(); if(tcx == NULL) return pv_get_null(msg, param, res); - return pv_get_strval(msg, param, res, &t->uac[tcx->branch_index].ruid); - break; + return pv_get_strval( + msg, param, res, &t->uac[tcx->branch_index].ruid); + break; default: return pv_get_tm_reply_ruid(msg, param, res); } - } return 0; } diff --git a/src/modules/tmx/t_var.h b/src/modules/tmx/t_var.h index b1f3591a02b..0ecb6a60588 100644 --- a/src/modules/tmx/t_var.h +++ b/src/modules/tmx/t_var.h @@ -31,29 +31,24 @@ void pv_tmx_data_init(void); -int pv_get_t_var_inv(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); -int pv_get_t_var_req(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); -int pv_get_t_var_rpl(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); +int pv_get_t_var_inv(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_t_var_req(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_t_var_rpl(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); int pv_parse_t_var_name(pv_spec_p sp, str *in); -int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); -int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); -int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); -int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); -int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); -int pv_get_tm_reply_last_received(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); +int pv_get_tm_branch_idx( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_tm_reply_ruid( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_t_branch(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_tm_reply_code( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_tm_reply_reason( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res); +int pv_get_tm_reply_last_received( + struct sip_msg *msg, pv_param_t *param, pv_value_t *res); -int pv_get_t(struct sip_msg *msg, pv_param_t *param, - pv_value_t *res); +int pv_get_t(struct sip_msg *msg, pv_param_t *param, pv_value_t *res); int pv_parse_t_name(pv_spec_p sp, str *in); #endif diff --git a/src/modules/tmx/tmx_mod.c b/src/modules/tmx/tmx_mod.c index 0d5e34627b1..25e2cddbac8 100644 --- a/src/modules/tmx/tmx_mod.c +++ b/src/modules/tmx/tmx_mod.c @@ -56,35 +56,35 @@ static int mod_init(void); static int child_init(int rank); static void destroy(void); -static int t_cancel_branches(sip_msg_t* msg, char *k, char *s2); -static int fixup_cancel_branches(void** param, int param_no); -static int w_t_cancel_callid_3(sip_msg_t* msg, char *cid, char *cseq, - char *flag); -static int w_t_cancel_callid_4(sip_msg_t* msg, char *cid, char *cseq, - char *flag, char *creason); -static int fixup_cancel_callid(void** param, int param_no); -static int t_reply_callid(sip_msg_t* msg, char *cid, char *cseq, - char *rc, char *rs); -static int fixup_reply_callid(void** param, int param_no); - -static int t_flush_flags(sip_msg_t* msg, char*, char* ); -static int t_flush_xflags(sip_msg_t* msg, char *, char *); -static int w_t_is_failure_route(sip_msg_t* msg, char*, char* ); -static int w_t_is_branch_route(sip_msg_t* msg, char*, char* ); -static int w_t_is_reply_route(sip_msg_t* msg, char*, char*); -static int w_t_is_request_route(sip_msg_t* msg, char*, char*); - -static int w_t_drop0(sip_msg_t* msg, char*, char*); -static int w_t_drop1(sip_msg_t* msg, char*, char*); -static int w_t_suspend(sip_msg_t* msg, char*, char*); -static int w_t_continue(sip_msg_t* msg, char *idx, char *lbl, char *rtn); -static int w_t_reuse_branch(sip_msg_t* msg, char*, char*); -static int fixup_t_continue(void** param, int param_no); -static int w_t_precheck_trans(sip_msg_t*, char*, char*); +static int t_cancel_branches(sip_msg_t *msg, char *k, char *s2); +static int fixup_cancel_branches(void **param, int param_no); +static int w_t_cancel_callid_3( + sip_msg_t *msg, char *cid, char *cseq, char *flag); +static int w_t_cancel_callid_4( + sip_msg_t *msg, char *cid, char *cseq, char *flag, char *creason); +static int fixup_cancel_callid(void **param, int param_no); +static int t_reply_callid( + sip_msg_t *msg, char *cid, char *cseq, char *rc, char *rs); +static int fixup_reply_callid(void **param, int param_no); + +static int t_flush_flags(sip_msg_t *msg, char *, char *); +static int t_flush_xflags(sip_msg_t *msg, char *, char *); +static int w_t_is_failure_route(sip_msg_t *msg, char *, char *); +static int w_t_is_branch_route(sip_msg_t *msg, char *, char *); +static int w_t_is_reply_route(sip_msg_t *msg, char *, char *); +static int w_t_is_request_route(sip_msg_t *msg, char *, char *); + +static int w_t_drop0(sip_msg_t *msg, char *, char *); +static int w_t_drop1(sip_msg_t *msg, char *, char *); +static int w_t_suspend(sip_msg_t *msg, char *, char *); +static int w_t_continue(sip_msg_t *msg, char *idx, char *lbl, char *rtn); +static int w_t_reuse_branch(sip_msg_t *msg, char *, char *); +static int fixup_t_continue(void **param, int param_no); +static int w_t_precheck_trans(sip_msg_t *, char *, char *); static int tmx_cfg_callback(sip_msg_t *msg, unsigned int flags, void *cbp); -static int bind_tmx(tmx_api_t* api); +static int bind_tmx(tmx_api_t *api); static int _tmx_precheck_trans = 1; @@ -119,110 +119,98 @@ unsigned long tmx_stats_rld_loc_rpls(void); unsigned long tmx_stats_rld_tot_rpls(void); static stat_export_t mod_stats[] = { - {"UAS_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_uas_trans }, - {"UAC_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_uac_trans }, - {"2xx_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_trans_2xx }, - {"3xx_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_trans_3xx }, - {"4xx_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_trans_4xx }, - {"5xx_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_trans_5xx }, - {"6xx_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_trans_6xx }, - {"inuse_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_trans_inuse }, - {"active_transactions", STAT_IS_FUNC, (stat_var**)tmx_stats_trans_active}, - {"rpl_received", STAT_IS_FUNC, (stat_var**)tmx_stats_rcv_rpls }, - {"rpl_absorbed", STAT_IS_FUNC, (stat_var**)tmx_stats_abs_rpls }, - {"rpl_generated", STAT_IS_FUNC, (stat_var**)tmx_stats_rld_loc_rpls}, - {"rpl_relayed", STAT_IS_FUNC, (stat_var**)tmx_stats_rld_rcv_rpls}, - {"rpl_sent", STAT_IS_FUNC, (stat_var**)tmx_stats_rld_tot_rpls}, - {0, 0, 0} -}; + {"UAS_transactions", STAT_IS_FUNC, (stat_var **)tmx_stats_uas_trans}, + {"UAC_transactions", STAT_IS_FUNC, (stat_var **)tmx_stats_uac_trans}, + {"2xx_transactions", STAT_IS_FUNC, (stat_var **)tmx_stats_trans_2xx}, + {"3xx_transactions", STAT_IS_FUNC, (stat_var **)tmx_stats_trans_3xx}, + {"4xx_transactions", STAT_IS_FUNC, (stat_var **)tmx_stats_trans_4xx}, + {"5xx_transactions", STAT_IS_FUNC, (stat_var **)tmx_stats_trans_5xx}, + {"6xx_transactions", STAT_IS_FUNC, (stat_var **)tmx_stats_trans_6xx}, + {"inuse_transactions", STAT_IS_FUNC, + (stat_var **)tmx_stats_trans_inuse}, + {"active_transactions", STAT_IS_FUNC, + (stat_var **)tmx_stats_trans_active}, + {"rpl_received", STAT_IS_FUNC, (stat_var **)tmx_stats_rcv_rpls}, + {"rpl_absorbed", STAT_IS_FUNC, (stat_var **)tmx_stats_abs_rpls}, + {"rpl_generated", STAT_IS_FUNC, (stat_var **)tmx_stats_rld_loc_rpls}, + {"rpl_relayed", STAT_IS_FUNC, (stat_var **)tmx_stats_rld_rcv_rpls}, + {"rpl_sent", STAT_IS_FUNC, (stat_var **)tmx_stats_rld_tot_rpls}, + {0, 0, 0}}; #endif /** * pseudo-variables exported by TM module */ static pv_export_t mod_pvs[] = { - { {"T_branch_idx", sizeof("T_branch_idx")-1}, PVT_OTHER, - pv_get_tm_branch_idx, 0, - 0, 0, 0, 0 }, - { {"T_reply_ruid", sizeof("T_reply_ruid")-1}, PVT_OTHER, - pv_get_tm_reply_ruid, 0, - 0, 0, 0, 0 }, - { {"T_reply_code", sizeof("T_reply_code")-1}, PVT_OTHER, - pv_get_tm_reply_code, 0, - 0, 0, 0, 0 }, - { {"T_reply_reason", sizeof("T_reply_reason")-1}, PVT_OTHER, - pv_get_tm_reply_reason, 0, - 0, 0, 0, 0 }, - { {"T_reply_last", sizeof("T_reply_last")-1}, PVT_OTHER, - pv_get_tm_reply_last_received, 0, - 0, 0, 0, 0 }, - { {"T_inv", sizeof("T_inv")-1}, PVT_OTHER, pv_get_t_var_inv, 0, - pv_parse_t_var_name, 0, 0, 0 }, - { {"T_req", sizeof("T_req")-1}, PVT_OTHER, pv_get_t_var_req, 0, - pv_parse_t_var_name, 0, 0, 0 }, - { {"T_rpl", sizeof("T_rpl")-1}, PVT_OTHER, pv_get_t_var_rpl, 0, - pv_parse_t_var_name, 0, 0, 0 }, - { {"T", sizeof("T")-1}, PVT_OTHER, pv_get_t, 0, - pv_parse_t_name, 0, 0, 0 }, - { {"T_branch", sizeof("T_branch")-1}, PVT_OTHER, pv_get_t_branch, 0, - pv_parse_t_name, 0, 0, 0 }, - { {0, 0}, 0, 0, 0, 0, 0, 0, 0 } -}; - -static cmd_export_t cmds[]={ - {"t_cancel_branches", (cmd_function)t_cancel_branches, 1, - fixup_cancel_branches, 0, ONREPLY_ROUTE }, - {"t_cancel_callid", (cmd_function)w_t_cancel_callid_3, 3, - fixup_cancel_callid, 0, ANY_ROUTE }, - {"t_cancel_callid", (cmd_function)w_t_cancel_callid_4, 4, - fixup_cancel_callid, 0, ANY_ROUTE }, - {"t_reply_callid", (cmd_function)t_reply_callid, 4, - fixup_reply_callid, 0, ANY_ROUTE }, - {"t_flush_flags", (cmd_function)t_flush_flags, 0, 0, - 0, ANY_ROUTE }, - {"t_flush_xflags", (cmd_function)t_flush_xflags, 0, 0, - 0, ANY_ROUTE }, - {"t_is_failure_route", (cmd_function)w_t_is_failure_route, 0, 0, - 0, ANY_ROUTE }, - {"t_is_branch_route", (cmd_function)w_t_is_branch_route, 0, 0, - 0, ANY_ROUTE }, - {"t_is_reply_route", (cmd_function)w_t_is_reply_route, 0, 0, - 0, ANY_ROUTE }, - {"t_is_request_route", (cmd_function)w_t_is_request_route, 0, 0, - 0, ANY_ROUTE }, - {"t_suspend", (cmd_function)w_t_suspend, 0, 0, - 0, ANY_ROUTE }, - {"t_continue", (cmd_function)w_t_continue, 3, - fixup_t_continue, 0, ANY_ROUTE }, - {"t_reuse_branch", (cmd_function)w_t_reuse_branch, 0, 0, 0, - EVENT_ROUTE }, - {"t_precheck_trans", (cmd_function)w_t_precheck_trans, 0, 0, 0, - REQUEST_ROUTE }, - {"bind_tmx", (cmd_function)bind_tmx, 1, - 0, 0, ANY_ROUTE }, - {"t_drop", (cmd_function)w_t_drop0, 0, 0, 0, ANY_ROUTE}, - {"t_drop", (cmd_function)w_t_drop1, 1, fixup_igp_null, 0, ANY_ROUTE}, - {0,0,0,0,0,0} -}; - -static param_export_t params[]={ - {"precheck_trans", PARAM_INT, &_tmx_precheck_trans}, - {0,0,0} -}; + {{"T_branch_idx", sizeof("T_branch_idx") - 1}, PVT_OTHER, + pv_get_tm_branch_idx, 0, 0, 0, 0, 0}, + {{"T_reply_ruid", sizeof("T_reply_ruid") - 1}, PVT_OTHER, + pv_get_tm_reply_ruid, 0, 0, 0, 0, 0}, + {{"T_reply_code", sizeof("T_reply_code") - 1}, PVT_OTHER, + pv_get_tm_reply_code, 0, 0, 0, 0, 0}, + {{"T_reply_reason", sizeof("T_reply_reason") - 1}, PVT_OTHER, + pv_get_tm_reply_reason, 0, 0, 0, 0, 0}, + {{"T_reply_last", sizeof("T_reply_last") - 1}, PVT_OTHER, + pv_get_tm_reply_last_received, 0, 0, 0, 0, 0}, + {{"T_inv", sizeof("T_inv") - 1}, PVT_OTHER, pv_get_t_var_inv, 0, + pv_parse_t_var_name, 0, 0, 0}, + {{"T_req", sizeof("T_req") - 1}, PVT_OTHER, pv_get_t_var_req, 0, + pv_parse_t_var_name, 0, 0, 0}, + {{"T_rpl", sizeof("T_rpl") - 1}, PVT_OTHER, pv_get_t_var_rpl, 0, + pv_parse_t_var_name, 0, 0, 0}, + {{"T", sizeof("T") - 1}, PVT_OTHER, pv_get_t, 0, pv_parse_t_name, 0, 0, + 0}, + {{"T_branch", sizeof("T_branch") - 1}, PVT_OTHER, pv_get_t_branch, 0, + pv_parse_t_name, 0, 0, 0}, + {{0, 0}, 0, 0, 0, 0, 0, 0, 0}}; + +static cmd_export_t cmds[] = { + {"t_cancel_branches", (cmd_function)t_cancel_branches, 1, + fixup_cancel_branches, 0, ONREPLY_ROUTE}, + {"t_cancel_callid", (cmd_function)w_t_cancel_callid_3, 3, + fixup_cancel_callid, 0, ANY_ROUTE}, + {"t_cancel_callid", (cmd_function)w_t_cancel_callid_4, 4, + fixup_cancel_callid, 0, ANY_ROUTE}, + {"t_reply_callid", (cmd_function)t_reply_callid, 4, fixup_reply_callid, + 0, ANY_ROUTE}, + {"t_flush_flags", (cmd_function)t_flush_flags, 0, 0, 0, ANY_ROUTE}, + {"t_flush_xflags", (cmd_function)t_flush_xflags, 0, 0, 0, ANY_ROUTE}, + {"t_is_failure_route", (cmd_function)w_t_is_failure_route, 0, 0, 0, + ANY_ROUTE}, + {"t_is_branch_route", (cmd_function)w_t_is_branch_route, 0, 0, 0, + ANY_ROUTE}, + {"t_is_reply_route", (cmd_function)w_t_is_reply_route, 0, 0, 0, + ANY_ROUTE}, + {"t_is_request_route", (cmd_function)w_t_is_request_route, 0, 0, 0, + ANY_ROUTE}, + {"t_suspend", (cmd_function)w_t_suspend, 0, 0, 0, ANY_ROUTE}, + {"t_continue", (cmd_function)w_t_continue, 3, fixup_t_continue, 0, + ANY_ROUTE}, + {"t_reuse_branch", (cmd_function)w_t_reuse_branch, 0, 0, 0, + EVENT_ROUTE}, + {"t_precheck_trans", (cmd_function)w_t_precheck_trans, 0, 0, 0, + REQUEST_ROUTE}, + {"bind_tmx", (cmd_function)bind_tmx, 1, 0, 0, ANY_ROUTE}, + {"t_drop", (cmd_function)w_t_drop0, 0, 0, 0, ANY_ROUTE}, + {"t_drop", (cmd_function)w_t_drop1, 1, fixup_igp_null, 0, ANY_ROUTE}, + {0, 0, 0, 0, 0, 0}}; + +static param_export_t params[] = { + {"precheck_trans", PARAM_INT, &_tmx_precheck_trans}, {0, 0, 0}}; /** module exports */ -struct module_exports exports= { - "tmx", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* cmd (cfg function) exports */ - params, /* param exports */ - 0, /* RPC method exports */ - mod_pvs, /* pv exports */ - 0, /* response handling function */ - mod_init, /* module init function */ - child_init, /* per-child init function */ - destroy /* module destroy function */ +struct module_exports exports = { + "tmx", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* cmd (cfg function) exports */ + params, /* param exports */ + 0, /* RPC method exports */ + mod_pvs, /* pv exports */ + 0, /* response handling function */ + mod_init, /* module init function */ + child_init, /* per-child init function */ + destroy /* module destroy function */ }; /** @@ -231,22 +219,22 @@ struct module_exports exports= { static int mod_init(void) { /* load the TM API */ - if (load_tm_api(&_tmx_tmb)!=0) { + if(load_tm_api(&_tmx_tmb) != 0) { LM_ERR("can't load TM API\n"); return -1; } #ifdef STATISTICS /* register statistics */ - if (register_module_stats( exports.name, mod_stats)!=0 ) { + if(register_module_stats(exports.name, mod_stats) != 0) { LM_ERR("failed to register statistics\n"); return -1; } #endif pv_tmx_data_init(); - if (register_script_cb(tmx_cfg_callback, - POST_SCRIPT_CB|REQUEST_CB,0)<0) { + if(register_script_cb(tmx_cfg_callback, POST_SCRIPT_CB | REQUEST_CB, 0) + < 0) { LM_ERR("cannot register post-script callback\n"); return -1; } @@ -260,8 +248,8 @@ static int mod_init(void) static int child_init(int rank) { LM_DBG("rank is (%d)\n", rank); - if (rank==PROC_INIT) { - if(_tmx_precheck_trans!=0) + if(rank == PROC_INIT) { + if(_tmx_precheck_trans != 0) return tmx_init_pretran_table(); } return 0; @@ -278,25 +266,25 @@ static void destroy(void) /** * */ -static int fixup_cancel_branches(void** param, int param_no) +static int fixup_cancel_branches(void **param, int param_no) { char *val; int n = 0; - if (param_no==1) { - val = (char*)*param; - if (strcasecmp(val,"all")==0) { + if(param_no == 1) { + val = (char *)*param; + if(strcasecmp(val, "all") == 0) { n = 0; - } else if (strcasecmp(val,"others")==0) { + } else if(strcasecmp(val, "others") == 0) { n = 1; - } else if (strcasecmp(val,"this")==0) { + } else if(strcasecmp(val, "this") == 0) { n = 2; } else { LM_ERR("invalid param \"%s\"\n", val); return E_CFG; } pkg_free(*param); - *param=(void*)(long)n; + *param = (void *)(long)n; } else { LM_ERR("called with parameter != 1\n"); return E_BUG; @@ -307,14 +295,14 @@ static int fixup_cancel_branches(void** param, int param_no) /** * */ -static int t_cancel_branches_helper(sip_msg_t* msg, int n) +static int t_cancel_branches_helper(sip_msg_t *msg, int n) { struct cancel_info cancel_data; tm_cell_t *t = 0; tm_ctx_t *tcx = 0; int idx = 0; - t=_tmx_tmb.t_gett(); - if (t==NULL || t==T_UNDEFINED || !is_invite(t)) + t = _tmx_tmb.t_gett(); + if(t == NULL || t == T_UNDEFINED || !is_invite(t)) return -1; tcx = _tmx_tmb.tm_ctx_get(); if(tcx != NULL) @@ -325,28 +313,26 @@ static int t_cancel_branches_helper(sip_msg_t* msg, int n) switch(n) { case 1: /* prepare cancel for every branch except idx (others) */ - _tmx_tmb.prepare_to_cancel(t, - &cancel_data.cancel_bitmap, 1<first_line.u.reply.statuscode>=200) + if(msg->first_line.u.reply.statuscode >= 200) break; - cancel_data.cancel_bitmap = 1<first_line.u.reply.statuscode>=200) + if(msg->first_line.u.reply.statuscode >= 200) /* prepare cancel for every branch except idx */ - _tmx_tmb.prepare_to_cancel(t, - &cancel_data.cancel_bitmap, 1<len==3 && strncasecmp(mode->s, "all", 3)==0) { + if(mode->len == 3 && strncasecmp(mode->s, "all", 3) == 0) { n = 0; - } else if (mode->len==6 && strncasecmp(mode->s, "others", 6)==0) { + } else if(mode->len == 6 && strncasecmp(mode->s, "others", 6) == 0) { n = 1; - } else if (mode->len==4 && strncasecmp(mode->s, "this", 4)==0) { + } else if(mode->len == 4 && strncasecmp(mode->s, "this", 4) == 0) { n = 2; } else { LM_ERR("invalid param \"%.*s\"\n", mode->len, mode->s); @@ -384,12 +370,12 @@ static int ki_t_cancel_branches(sip_msg_t* msg, str *mode) /** * */ -static int fixup_cancel_callid(void** param, int param_no) +static int fixup_cancel_callid(void **param, int param_no) { - if (param_no==1 || param_no==2) { + if(param_no == 1 || param_no == 2) { return fixup_spve_null(param, 1); } - if (param_no==3 || param_no==4) { + if(param_no == 3 || param_no == 4) { return fixup_igp_null(param, 1); } return 0; @@ -398,26 +384,26 @@ static int fixup_cancel_callid(void** param, int param_no) /** * */ -static int ki_t_cancel_callid_reason(sip_msg_t* msg, str *callid_s, str *cseq_s, - int fl, int rcode) +static int ki_t_cancel_callid_reason( + sip_msg_t *msg, str *callid_s, str *cseq_s, int fl, int rcode) { tm_cell_t *trans; tm_cell_t *bkt; int bkb; struct cancel_info cancel_data; - if(rcode<100 || rcode>699) + if(rcode < 100 || rcode > 699) rcode = 0; bkt = _tmx_tmb.t_gett(); bkb = _tmx_tmb.t_gett_branch(); - if( _tmx_tmb.t_lookup_callid(&trans, *callid_s, *cseq_s) < 0 ) { + if(_tmx_tmb.t_lookup_callid(&trans, *callid_s, *cseq_s) < 0) { DBG("Lookup failed - no transaction\n"); return -1; } DBG("Now calling cancel_uacs\n"); - if(trans->uas.request && fl>0 && fl<32) + if(trans->uas.request && fl > 0 && fl < 32) setflag(trans->uas.request, fl); init_cancel_info(&cancel_data); cancel_data.reason.cause = rcode; @@ -434,8 +420,8 @@ static int ki_t_cancel_callid_reason(sip_msg_t* msg, str *callid_s, str *cseq_s, /** * */ -static int ki_t_cancel_callid(sip_msg_t* msg, str *callid_s, str *cseq_s, - int fl) +static int ki_t_cancel_callid( + sip_msg_t *msg, str *callid_s, str *cseq_s, int fl) { return ki_t_cancel_callid_reason(msg, callid_s, cseq_s, fl, 0); } @@ -443,7 +429,8 @@ static int ki_t_cancel_callid(sip_msg_t* msg, str *callid_s, str *cseq_s, /** * */ -static int t_cancel_callid(sip_msg_t* msg, char *cid, char *cseq, char *flag, char *creason) +static int t_cancel_callid( + sip_msg_t *msg, char *cid, char *cseq, char *flag, char *creason) { str cseq_s; str callid_s; @@ -453,25 +440,22 @@ static int t_cancel_callid(sip_msg_t* msg, char *cid, char *cseq, char *flag, ch rcode = 0; fl = -1; - if(fixup_get_svalue(msg, (gparam_p)cid, &callid_s)<0) - { + if(fixup_get_svalue(msg, (gparam_p)cid, &callid_s) < 0) { LM_ERR("cannot get callid\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_p)cseq, &cseq_s)<0) - { + if(fixup_get_svalue(msg, (gparam_p)cseq, &cseq_s) < 0) { LM_ERR("cannot get cseq\n"); return -1; } - if(fixup_get_ivalue(msg, (gparam_p)flag, &fl)<0) - { + if(fixup_get_ivalue(msg, (gparam_p)flag, &fl) < 0) { LM_ERR("cannot get flag\n"); return -1; } - if(creason!=NULL && fixup_get_ivalue(msg, (gparam_p)creason, &rcode)<0) - { + if(creason != NULL + && fixup_get_ivalue(msg, (gparam_p)creason, &rcode) < 0) { LM_ERR("cannot get flag\n"); return -1; } @@ -482,7 +466,8 @@ static int t_cancel_callid(sip_msg_t* msg, char *cid, char *cseq, char *flag, ch /** * */ -static int w_t_cancel_callid_3(sip_msg_t* msg, char *cid, char *cseq, char *flag) +static int w_t_cancel_callid_3( + sip_msg_t *msg, char *cid, char *cseq, char *flag) { return t_cancel_callid(msg, cid, cseq, flag, NULL); } @@ -490,7 +475,8 @@ static int w_t_cancel_callid_3(sip_msg_t* msg, char *cid, char *cseq, char *flag /** * */ -static int w_t_cancel_callid_4(sip_msg_t* msg, char *cid, char *cseq, char *flag, char *creason) +static int w_t_cancel_callid_4( + sip_msg_t *msg, char *cid, char *cseq, char *flag, char *creason) { return t_cancel_callid(msg, cid, cseq, flag, creason); } @@ -498,12 +484,12 @@ static int w_t_cancel_callid_4(sip_msg_t* msg, char *cid, char *cseq, char *flag /** * */ -static int fixup_reply_callid(void** param, int param_no) +static int fixup_reply_callid(void **param, int param_no) { - if (param_no==1 || param_no==2 || param_no==4) { + if(param_no == 1 || param_no == 2 || param_no == 4) { return fixup_spve_null(param, 1); } - if (param_no==3) { + if(param_no == 3) { return fixup_igp_null(param, 1); } return 0; @@ -512,20 +498,20 @@ static int fixup_reply_callid(void** param, int param_no) /** * */ -static int ki_t_reply_callid(sip_msg_t* msg, str *callid_s, str *cseq_s, - int code, str *status_s) +static int ki_t_reply_callid( + sip_msg_t *msg, str *callid_s, str *cseq_s, int code, str *status_s) { tm_cell_t *trans; - if(_tmx_tmb.t_lookup_callid(&trans, *callid_s, *cseq_s) < 0 ) - { + if(_tmx_tmb.t_lookup_callid(&trans, *callid_s, *cseq_s) < 0) { LM_DBG("Lookup failed - no transaction\n"); return -1; } LM_DBG("now calling internal tm reply\n"); - if(_tmx_tmb.t_reply_trans(trans, trans->uas.request, - (unsigned int)code, status_s->s)>0) + if(_tmx_tmb.t_reply_trans( + trans, trans->uas.request, (unsigned int)code, status_s->s) + > 0) return 1; return -1; @@ -534,34 +520,30 @@ static int ki_t_reply_callid(sip_msg_t* msg, str *callid_s, str *cseq_s, /** * */ -static int t_reply_callid(sip_msg_t* msg, char *cid, char *cseq, - char *rc, char *rs) +static int t_reply_callid( + sip_msg_t *msg, char *cid, char *cseq, char *rc, char *rs) { str cseq_s; str callid_s; str status_s; int code; - if(fixup_get_svalue(msg, (gparam_p)cid, &callid_s)<0) - { + if(fixup_get_svalue(msg, (gparam_p)cid, &callid_s) < 0) { LM_ERR("cannot get callid\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_p)cseq, &cseq_s)<0) - { + if(fixup_get_svalue(msg, (gparam_p)cseq, &cseq_s) < 0) { LM_ERR("cannot get cseq\n"); return -1; } - if(fixup_get_ivalue(msg, (gparam_p)rc, &code)<0) - { + if(fixup_get_ivalue(msg, (gparam_p)rc, &code) < 0) { LM_ERR("cannot get reply code\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_p)rs, &status_s)<0) - { + if(fixup_get_svalue(msg, (gparam_p)rs, &status_s) < 0) { LM_ERR("cannot get reply status\n"); return -1; } @@ -572,12 +554,12 @@ static int t_reply_callid(sip_msg_t* msg, char *cid, char *cseq, /** * */ -static int ki_t_flush_flags(sip_msg_t* msg) +static int ki_t_flush_flags(sip_msg_t *msg) { tm_cell_t *t; - t=_tmx_tmb.t_gett(); - if ( t==0 || t==T_UNDEFINED) { + t = _tmx_tmb.t_gett(); + if(t == 0 || t == T_UNDEFINED) { LM_ERR("failed to flush flags - no transaction found\n"); return -1; } @@ -589,7 +571,7 @@ static int ki_t_flush_flags(sip_msg_t* msg) /** * */ -static int t_flush_flags(sip_msg_t* msg, char *foo, char *bar) +static int t_flush_flags(sip_msg_t *msg, char *foo, char *bar) { return ki_t_flush_flags(msg); } @@ -597,12 +579,12 @@ static int t_flush_flags(sip_msg_t* msg, char *foo, char *bar) /** * */ -static int ki_t_flush_xflags(sip_msg_t* msg) +static int ki_t_flush_xflags(sip_msg_t *msg) { tm_cell_t *t; - t=_tmx_tmb.t_gett(); - if ( t==0 || t==T_UNDEFINED) { + t = _tmx_tmb.t_gett(); + if(t == 0 || t == T_UNDEFINED) { LM_ERR("failed to flush flags - no transaction found\n"); return -1; } @@ -615,7 +597,7 @@ static int ki_t_flush_xflags(sip_msg_t* msg) /** * */ -static int t_flush_xflags(sip_msg_t* msg, char *foo, char *bar) +static int t_flush_xflags(sip_msg_t *msg, char *foo, char *bar) { return ki_t_flush_xflags(msg); } @@ -624,9 +606,9 @@ static int t_flush_xflags(sip_msg_t* msg, char *foo, char *bar) /** * */ -static int w_t_is_failure_route(sip_msg_t* msg, char *foo, char *bar) +static int w_t_is_failure_route(sip_msg_t *msg, char *foo, char *bar) { - if(route_type==FAILURE_ROUTE) + if(route_type == FAILURE_ROUTE) return 1; return -1; } @@ -634,9 +616,9 @@ static int w_t_is_failure_route(sip_msg_t* msg, char *foo, char *bar) /** * */ -static int t_is_failure_route(sip_msg_t* msg) +static int t_is_failure_route(sip_msg_t *msg) { - if(route_type==FAILURE_ROUTE) + if(route_type == FAILURE_ROUTE) return 1; return -1; } @@ -644,9 +626,9 @@ static int t_is_failure_route(sip_msg_t* msg) /** * */ -static int w_t_is_branch_route(sip_msg_t* msg, char *foo, char *bar) +static int w_t_is_branch_route(sip_msg_t *msg, char *foo, char *bar) { - if(route_type==BRANCH_ROUTE) + if(route_type == BRANCH_ROUTE) return 1; return -1; } @@ -654,9 +636,9 @@ static int w_t_is_branch_route(sip_msg_t* msg, char *foo, char *bar) /** * */ -static int t_is_branch_route(sip_msg_t* msg) +static int t_is_branch_route(sip_msg_t *msg) { - if(route_type==BRANCH_ROUTE) + if(route_type == BRANCH_ROUTE) return 1; return -1; } @@ -664,7 +646,7 @@ static int t_is_branch_route(sip_msg_t* msg) /** * */ -static int w_t_is_reply_route(sip_msg_t* msg, char *foo, char *bar) +static int w_t_is_reply_route(sip_msg_t *msg, char *foo, char *bar) { if(route_type & ONREPLY_ROUTE) return 1; @@ -674,7 +656,7 @@ static int w_t_is_reply_route(sip_msg_t* msg, char *foo, char *bar) /** * */ -static int t_is_reply_route(sip_msg_t* msg) +static int t_is_reply_route(sip_msg_t *msg) { if(route_type & ONREPLY_ROUTE) return 1; @@ -684,7 +666,7 @@ static int t_is_reply_route(sip_msg_t* msg) /** * */ -static int w_t_is_request_route(sip_msg_t* msg, char *foo, char *bar) +static int w_t_is_request_route(sip_msg_t *msg, char *foo, char *bar) { if(route_type == REQUEST_ROUTE) return 1; @@ -694,7 +676,7 @@ static int w_t_is_request_route(sip_msg_t* msg, char *foo, char *bar) /** * */ -static int t_is_request_route(sip_msg_t* msg) +static int t_is_request_route(sip_msg_t *msg) { if(route_type == REQUEST_ROUTE) return 1; @@ -704,12 +686,12 @@ static int t_is_request_route(sip_msg_t* msg) /** * */ -static int ki_t_drop_rcode(sip_msg_t* msg, int rcode) +static int ki_t_drop_rcode(sip_msg_t *msg, int rcode) { tm_cell_t *t = 0; - t=_tmx_tmb.t_gett(); - if (t==NULL || t==T_UNDEFINED) { + t = _tmx_tmb.t_gett(); + if(t == NULL || t == T_UNDEFINED) { LM_ERR("no transaction\n"); return -1; } @@ -722,7 +704,7 @@ static int ki_t_drop_rcode(sip_msg_t* msg, int rcode) /** * */ -static int ki_t_drop(sip_msg_t* msg) +static int ki_t_drop(sip_msg_t *msg) { return ki_t_drop_rcode(msg, 500); } @@ -730,12 +712,12 @@ static int ki_t_drop(sip_msg_t* msg) /** * */ -static int w_t_drop1(sip_msg_t* msg, char *p1, char *p2) +static int w_t_drop1(sip_msg_t *msg, char *p1, char *p2) { int uas_status = 500; if(p1) { - if(fixup_get_ivalue(msg, (gparam_t*)p1, &uas_status)<0) { + if(fixup_get_ivalue(msg, (gparam_t *)p1, &uas_status) < 0) { uas_status = 500; } } @@ -745,7 +727,7 @@ static int w_t_drop1(sip_msg_t* msg, char *p1, char *p2) /** * */ -static int w_t_drop0(sip_msg_t* msg, char *p1, char *p2) +static int w_t_drop0(sip_msg_t *msg, char *p1, char *p2) { return ki_t_drop_rcode(msg, 500); } @@ -754,7 +736,7 @@ static int w_t_drop0(sip_msg_t* msg, char *p1, char *p2) /** * */ -static int ki_t_suspend(sip_msg_t* msg) +static int ki_t_suspend(sip_msg_t *msg) { unsigned int tindex; unsigned int tlabel; @@ -765,23 +747,19 @@ static int ki_t_suspend(sip_msg_t* msg) return -1; } - t=_tmx_tmb.t_gett(); - if (t==NULL || t==T_UNDEFINED) - { - if(_tmx_tmb.t_newtran(msg)<0) - { + t = _tmx_tmb.t_gett(); + if(t == NULL || t == T_UNDEFINED) { + if(_tmx_tmb.t_newtran(msg) < 0) { LM_ERR("cannot create the transaction\n"); return -1; } t = _tmx_tmb.t_gett(); - if (t==NULL || t==T_UNDEFINED) - { + if(t == NULL || t == T_UNDEFINED) { LM_ERR("cannot lookup the transaction\n"); return -1; } } - if(_tmx_tmb.t_suspend(msg, &tindex, &tlabel)<0) - { + if(_tmx_tmb.t_suspend(msg, &tindex, &tlabel) < 0) { LM_ERR("failed to suppend the processing\n"); return -1; } @@ -793,7 +771,7 @@ static int ki_t_suspend(sip_msg_t* msg) /** * */ -static int w_t_suspend(sip_msg_t* msg, char *p1, char *p2) +static int w_t_suspend(sip_msg_t *msg, char *p1, char *p2) { return ki_t_suspend(msg); } @@ -801,7 +779,7 @@ static int w_t_suspend(sip_msg_t* msg, char *p1, char *p2) /** * */ -static int w_t_continue(sip_msg_t* msg, char *idx, char *lbl, char *rtn) +static int w_t_continue(sip_msg_t *msg, char *idx, char *lbl, char *rtn) { unsigned int tindex; unsigned int tlabel; @@ -809,40 +787,34 @@ static int w_t_continue(sip_msg_t* msg, char *idx, char *lbl, char *rtn) cfg_action_t *act; int ri; - if(fixup_get_ivalue(msg, (gparam_p)idx, (int*)&tindex)<0) - { + if(fixup_get_ivalue(msg, (gparam_p)idx, (int *)&tindex) < 0) { LM_ERR("cannot get transaction index\n"); return -1; } - if(fixup_get_ivalue(msg, (gparam_p)lbl, (int*)&tlabel)<0) - { + if(fixup_get_ivalue(msg, (gparam_p)lbl, (int *)&tlabel) < 0) { LM_ERR("cannot get transaction label\n"); return -1; } - if(fixup_get_svalue(msg, (gparam_p)rtn, &rtname)<0) - { + if(fixup_get_svalue(msg, (gparam_p)rtn, &rtname) < 0) { LM_ERR("cannot get route block name\n"); return -1; } ri = route_get(&main_rt, rtname.s); - if(ri<0) - { + if(ri < 0) { LM_ERR("unable to find route block [%.*s]\n", rtname.len, rtname.s); return -1; } act = main_rt.rlist[ri]; - if(act==NULL) - { - LM_ERR("empty action lists in route block [%.*s]\n", - rtname.len, rtname.s); + if(act == NULL) { + LM_ERR("empty action lists in route block [%.*s]\n", rtname.len, + rtname.s); return -1; } - if(_tmx_tmb.t_continue(tindex, tlabel, act)<0) - { + if(_tmx_tmb.t_continue(tindex, tlabel, act) < 0) { LM_WARN("resuming the processing of transaction [%u:%u] failed\n", tindex, tlabel); return -1; @@ -853,12 +825,13 @@ static int w_t_continue(sip_msg_t* msg, char *idx, char *lbl, char *rtn) /** * */ -static int ki_t_continue(sip_msg_t* msg, int tindex, int tlabel, str *cbname) +static int ki_t_continue(sip_msg_t *msg, int tindex, int tlabel, str *cbname) { str evname = str_init("tmx:continue"); - if(_tmx_tmb.t_continue_cb((unsigned int)tindex, (unsigned int)tlabel, - cbname, &evname)<0) { + if(_tmx_tmb.t_continue_cb( + (unsigned int)tindex, (unsigned int)tlabel, cbname, &evname) + < 0) { LM_WARN("resuming the processing of transaction [%u:%u] failed\n", tindex, tlabel); return -1; @@ -871,33 +844,36 @@ static int ki_t_continue(sip_msg_t* msg, int tindex, int tlabel, str *cbname) * Currently the following branch attributes are included: * request-uri, ruid, path, instance, and branch flags. */ -static int ki_t_reuse_branch(sip_msg_t* msg) +static int ki_t_reuse_branch(sip_msg_t *msg) { tm_cell_t *t; int branch; - if (msg == NULL) return -1; + if(msg == NULL) + return -1; /* first get the transaction */ - if (_tmx_tmb.t_check(msg, 0) == -1) return -1; - if ((t = _tmx_tmb.t_gett()) == 0) { + if(_tmx_tmb.t_check(msg, 0) == -1) + return -1; + if((t = _tmx_tmb.t_gett()) == 0) { LM_ERR("no transaction\n"); return -1; } - switch (get_route_type()) { + switch(get_route_type()) { case BRANCH_FAILURE_ROUTE: /* use the reason of the winning reply */ - if ((branch = _tmx_tmb.t_get_picked_branch()) < 0) { + if((branch = _tmx_tmb.t_get_picked_branch()) < 0) { LM_CRIT("no picked branch (%d) for a final response" - " in MODE_ONFAILURE\n", branch); + " in MODE_ONFAILURE\n", + branch); return -1; } - if(rewrite_uri(msg, &(t->uac[branch].uri))<0) { + if(rewrite_uri(msg, &(t->uac[branch].uri)) < 0) { LM_WARN("failed to rewrite the r-uri\n"); } set_ruid(msg, &(t->uac[branch].ruid)); - if (t->uac[branch].path.len) { - if(set_path_vector(msg, &(t->uac[branch].path))<0) { + if(t->uac[branch].path.len) { + if(set_path_vector(msg, &(t->uac[branch].path)) < 0) { LM_WARN("failed to set the path vector\n"); } } else { @@ -915,7 +891,7 @@ static int ki_t_reuse_branch(sip_msg_t* msg) /** * */ -static int w_t_reuse_branch(sip_msg_t* msg, char *p1, char *p2) +static int w_t_reuse_branch(sip_msg_t *msg, char *p1, char *p2) { return ki_t_reuse_branch(msg); } @@ -923,12 +899,12 @@ static int w_t_reuse_branch(sip_msg_t* msg, char *p1, char *p2) /** * */ -static int fixup_t_continue(void** param, int param_no) +static int fixup_t_continue(void **param, int param_no) { - if (param_no==1 || param_no==2) { + if(param_no == 1 || param_no == 2) { return fixup_igp_null(param, 1); } - if (param_no==3) { + if(param_no == 3) { return fixup_spve_null(param, 1); } @@ -943,9 +919,9 @@ static int t_precheck_trans(sip_msg_t *msg) int ret; ret = tmx_check_pretran(msg); - if(ret>0) + if(ret > 0) return 1; - return (ret-1); + return (ret - 1); } /** @@ -961,16 +937,16 @@ static int w_t_precheck_trans(sip_msg_t *msg, char *p1, char *p2) */ static int tmx_cfg_callback(sip_msg_t *msg, unsigned int flags, void *cbp) { - if(flags&POST_SCRIPT_CB) { + if(flags & POST_SCRIPT_CB) { tmx_pretran_unlink(); } return 1; } -static int bind_tmx(tmx_api_t* api) +static int bind_tmx(tmx_api_t *api) { - if (!api) + if(!api) return -1; api->t_suspend = w_t_suspend; @@ -987,7 +963,7 @@ void tmx_stats_update(void) { ticks_t t; t = get_ticks(); - if(t>_tmx_stats_tm+1) { + if(t > _tmx_stats_tm + 1) { _tmx_tmb.get_stats(&_tmx_stats_all); _tmx_stats_tm = t; } diff --git a/src/modules/tmx/tmx_pretran.c b/src/modules/tmx/tmx_pretran.c index 7bb2315fd3d..027681f9886 100644 --- a/src/modules/tmx/tmx_pretran.c +++ b/src/modules/tmx/tmx_pretran.c @@ -41,7 +41,8 @@ #include "tmx_pretran.h" -typedef struct _pretran { +typedef struct _pretran +{ unsigned int hid; unsigned int linked; str callid; @@ -56,7 +57,8 @@ typedef struct _pretran { struct _pretran *prev; } pretran_t; -typedef struct pretran_slot { +typedef struct pretran_slot +{ pretran_t *plist; gen_lock_t lock; } pretran_slot_t; @@ -75,30 +77,33 @@ int tmx_init_pretran_table(void) pn = get_max_procs(); - if(pn<=0) + if(pn <= 0) return -1; - if(_tmx_ptran_table!=NULL) + if(_tmx_ptran_table != NULL) return -1; /* get the highest power of two less than number of processes */ n = -1; - while (pn >> ++n > 0); + while(pn >> ++n > 0) + ; n--; - if(n<=1) n = 2; - if(n>8) n = 8; - _tmx_ptran_size = 1< 8) + n = 8; + _tmx_ptran_size = 1 << n; - _tmx_ptran_table = (pretran_slot_t*)shm_malloc(_tmx_ptran_size*sizeof(pretran_slot_t)); + _tmx_ptran_table = (pretran_slot_t *)shm_malloc( + _tmx_ptran_size * sizeof(pretran_slot_t)); if(_tmx_ptran_table == NULL) { SHM_MEM_ERROR; return -1; } - memset(_tmx_ptran_table, 0, _tmx_ptran_size*sizeof(pretran_slot_t)); - for(n=0; n<_tmx_ptran_size; n++) { - if(lock_init(&_tmx_ptran_table[n].lock)==NULL) - { + memset(_tmx_ptran_table, 0, _tmx_ptran_size * sizeof(pretran_slot_t)); + for(n = 0; n < _tmx_ptran_size; n++) { + if(lock_init(&_tmx_ptran_table[n].lock) == NULL) { LM_ERR("cannot init the lock %d\n", n); n--; - while(n>=0) { + while(n >= 0) { lock_destroy(&_tmx_ptran_table[n].lock); n--; } @@ -116,10 +121,10 @@ int tmx_init_pretran_table(void) */ void tmx_pretran_link_safe(int slotid) { - if(_tmx_proc_ptran==NULL) + if(_tmx_proc_ptran == NULL) return; - if(_tmx_ptran_table[slotid].plist==NULL) { + if(_tmx_ptran_table[slotid].plist == NULL) { _tmx_ptran_table[slotid].plist = _tmx_proc_ptran; _tmx_proc_ptran->linked = 1; return; @@ -136,18 +141,18 @@ void tmx_pretran_link_safe(int slotid) */ void tmx_pretran_unlink_safe(int slotid) { - if(_tmx_proc_ptran==NULL) + if(_tmx_proc_ptran == NULL) return; if(_tmx_proc_ptran->linked == 0) return; - if(_tmx_ptran_table[slotid].plist==NULL) { + if(_tmx_ptran_table[slotid].plist == NULL) { _tmx_proc_ptran->prev = _tmx_proc_ptran->next = NULL; _tmx_proc_ptran->linked = 0; return; } - if(_tmx_proc_ptran->prev==NULL) { + if(_tmx_proc_ptran->prev == NULL) { _tmx_ptran_table[slotid].plist = _tmx_proc_ptran->next; - if(_tmx_ptran_table[slotid].plist!=NULL) + if(_tmx_ptran_table[slotid].plist != NULL) _tmx_ptran_table[slotid].plist->prev = NULL; } else { _tmx_proc_ptran->prev->next = _tmx_proc_ptran->next; @@ -166,10 +171,10 @@ void tmx_pretran_unlink(void) { int slotid; - if(_tmx_proc_ptran==NULL) + if(_tmx_proc_ptran == NULL) return; - slotid = _tmx_proc_ptran->hid & (_tmx_ptran_size-1); + slotid = _tmx_proc_ptran->hid & (_tmx_ptran_size - 1); lock_get(&_tmx_ptran_table[slotid].lock); tmx_pretran_unlink_safe(slotid); lock_release(&_tmx_ptran_table[slotid].lock); @@ -194,40 +199,42 @@ int tmx_check_pretran(sip_msg_t *msg) str svbranch = {NULL, 0}; pretran_t *it; - if(_tmx_ptran_table==NULL) { + if(_tmx_ptran_table == NULL) { LM_ERR("pretran hash table not initialized yet\n"); return -1; } - if(get_route_type()!=REQUEST_ROUTE) { + if(get_route_type() != REQUEST_ROUTE) { LM_ERR("invalid usage - not in request route\n"); return -1; } - if(msg->first_line.type!=SIP_REQUEST) { + if(msg->first_line.type != SIP_REQUEST) { LM_ERR("invalid usage - not a sip request\n"); return -1; } - if(parse_headers(msg, HDR_FROM_F|HDR_VIA1_F|HDR_CALLID_F|HDR_CSEQ_F, 0)<0) { + if(parse_headers( + msg, HDR_FROM_F | HDR_VIA1_F | HDR_CALLID_F | HDR_CSEQ_F, 0) + < 0) { LM_ERR("failed to parse required headers\n"); return -1; } - if(msg->cseq==NULL || msg->cseq->parsed==NULL) { + if(msg->cseq == NULL || msg->cseq->parsed == NULL) { LM_ERR("failed to parse cseq headers\n"); return -1; } - if(get_cseq(msg)->method_id==METHOD_ACK - || get_cseq(msg)->method_id==METHOD_CANCEL) { + if(get_cseq(msg)->method_id == METHOD_ACK + || get_cseq(msg)->method_id == METHOD_CANCEL) { LM_DBG("no pre-transaction management for ACK or CANCEL\n"); return -1; } - if (msg->via1==0) { + if(msg->via1 == 0) { LM_ERR("failed to get Via header\n"); return -1; } - if (parse_from_header(msg)<0 || get_from(msg)->tag_value.len==0) { + if(parse_from_header(msg) < 0 || get_from(msg)->tag_value.len == 0) { LM_ERR("failed to get From header\n"); return -1; } - if (msg->callid==NULL || msg->callid->body.s==NULL) { + if(msg->callid == NULL || msg->callid->body.s == NULL) { LM_ERR("failed to parse callid headers\n"); return -1; } @@ -244,10 +251,10 @@ int tmx_check_pretran(sip_msg_t *msg) trim(&sftag); chid = get_hash1_raw(scallid.s, scallid.len); - slotid = chid & (_tmx_ptran_size-1); + slotid = chid & (_tmx_ptran_size - 1); if(unlikely(_tmx_proc_ptran == NULL)) { - _tmx_proc_ptran = (pretran_t*)shm_malloc(sizeof(pretran_t)); + _tmx_proc_ptran = (pretran_t *)shm_malloc(sizeof(pretran_t)); if(_tmx_proc_ptran == NULL) { SHM_MEM_ERROR_FMT("pretran structure\n"); return -1; @@ -255,21 +262,22 @@ int tmx_check_pretran(sip_msg_t *msg) memset(_tmx_proc_ptran, 0, sizeof(pretran_t)); _tmx_proc_ptran->pid = my_pid(); } - dsize = scallid.len + scseqnum.len + scseqmet.len - + sftag.len + 4; - if(likely(vbr!=NULL)) { + dsize = scallid.len + scseqnum.len + scseqmet.len + sftag.len + 4; + if(likely(vbr != NULL)) { svbranch = vbr->value; trim(&svbranch); dsize += svbranch.len + 1; } - if(dsize<256) dsize = 256; + if(dsize < 256) + dsize = 256; tmx_pretran_unlink(); if(dsize > _tmx_proc_ptran->dbuf.len) { - if(_tmx_proc_ptran->dbuf.s) shm_free(_tmx_proc_ptran->dbuf.s); - _tmx_proc_ptran->dbuf.s = (char*)shm_malloc(dsize); - if(_tmx_proc_ptran->dbuf.s==NULL) { + if(_tmx_proc_ptran->dbuf.s) + shm_free(_tmx_proc_ptran->dbuf.s); + _tmx_proc_ptran->dbuf.s = (char *)shm_malloc(dsize); + if(_tmx_proc_ptran->dbuf.s == NULL) { SHM_MEM_ERROR_FMT("pretran data\n"); return -1; } @@ -283,27 +291,27 @@ int tmx_check_pretran(sip_msg_t *msg) _tmx_proc_ptran->callid.len = scallid.len; _tmx_proc_ptran->callid.s[_tmx_proc_ptran->callid.len] = '\0'; - _tmx_proc_ptran->ftag.s = _tmx_proc_ptran->callid.s - + _tmx_proc_ptran->callid.len + 1; + _tmx_proc_ptran->ftag.s = + _tmx_proc_ptran->callid.s + _tmx_proc_ptran->callid.len + 1; memcpy(_tmx_proc_ptran->ftag.s, sftag.s, sftag.len); _tmx_proc_ptran->ftag.len = sftag.len; _tmx_proc_ptran->ftag.s[_tmx_proc_ptran->ftag.len] = '\0'; - _tmx_proc_ptran->cseqnum.s = _tmx_proc_ptran->ftag.s - + _tmx_proc_ptran->ftag.len + 1; + _tmx_proc_ptran->cseqnum.s = + _tmx_proc_ptran->ftag.s + _tmx_proc_ptran->ftag.len + 1; memcpy(_tmx_proc_ptran->cseqnum.s, scseqnum.s, scseqnum.len); _tmx_proc_ptran->cseqnum.len = scseqnum.len; _tmx_proc_ptran->cseqnum.s[_tmx_proc_ptran->cseqnum.len] = '\0'; - _tmx_proc_ptran->cseqmet.s = _tmx_proc_ptran->cseqnum.s - + _tmx_proc_ptran->cseqnum.len + 1; + _tmx_proc_ptran->cseqmet.s = + _tmx_proc_ptran->cseqnum.s + _tmx_proc_ptran->cseqnum.len + 1; memcpy(_tmx_proc_ptran->cseqmet.s, scseqmet.s, scseqmet.len); _tmx_proc_ptran->cseqmet.len = scseqmet.len; _tmx_proc_ptran->cseqmet.s[_tmx_proc_ptran->cseqmet.len] = '\0'; - if(likely(vbr!=NULL)) { - _tmx_proc_ptran->vbranch.s = _tmx_proc_ptran->cseqmet.s - + _tmx_proc_ptran->cseqmet.len + 1; + if(likely(vbr != NULL)) { + _tmx_proc_ptran->vbranch.s = + _tmx_proc_ptran->cseqmet.s + _tmx_proc_ptran->cseqmet.len + 1; memcpy(_tmx_proc_ptran->vbranch.s, svbranch.s, svbranch.len); _tmx_proc_ptran->vbranch.len = svbranch.len; _tmx_proc_ptran->vbranch.s[_tmx_proc_ptran->vbranch.len] = '\0'; @@ -315,7 +323,7 @@ int tmx_check_pretran(sip_msg_t *msg) lock_get(&_tmx_ptran_table[slotid].lock); it = _tmx_ptran_table[slotid].plist; tmx_pretran_link_safe(slotid); - for(; it!=NULL; it=it->next) { + for(; it != NULL; it = it->next) { if(_tmx_proc_ptran->hid != it->hid || _tmx_proc_ptran->cseqmetid != it->cseqmetid || _tmx_proc_ptran->callid.len != it->callid.len @@ -329,11 +337,12 @@ int tmx_check_pretran(sip_msg_t *msg) /* shortcut - check last char in Via branch * - kamailio/ser adds there branch index => in case of paralel * forking by previous hop, catch it here quickly */ - if(_tmx_proc_ptran->vbranch.s[it->vbranch.len-1] - != it->vbranch.s[it->vbranch.len-1]) + if(_tmx_proc_ptran->vbranch.s[it->vbranch.len - 1] + != it->vbranch.s[it->vbranch.len - 1]) continue; - if(memcmp(_tmx_proc_ptran->vbranch.s, - it->vbranch.s, it->vbranch.len)!=0) + if(memcmp(_tmx_proc_ptran->vbranch.s, it->vbranch.s, + it->vbranch.len) + != 0) continue; /* shall stop by matching magic cookie? * if (vbr && vbr->value.s && vbr->value.len > MCOOKIE_LEN @@ -342,16 +351,17 @@ int tmx_check_pretran(sip_msg_t *msg) * } */ } - if(memcmp(_tmx_proc_ptran->callid.s, - it->callid.s, it->callid.len)!=0 - || memcmp(_tmx_proc_ptran->ftag.s, - it->ftag.s, it->ftag.len)!=0 - || memcmp(_tmx_proc_ptran->cseqnum.s, - it->cseqnum.s, it->cseqnum.len)!=0) + if(memcmp(_tmx_proc_ptran->callid.s, it->callid.s, it->callid.len) != 0 + || memcmp(_tmx_proc_ptran->ftag.s, it->ftag.s, it->ftag.len) + != 0 + || memcmp(_tmx_proc_ptran->cseqnum.s, it->cseqnum.s, + it->cseqnum.len) + != 0) continue; - if((it->cseqmetid==METHOD_OTHER || it->cseqmetid==METHOD_UNDEF) - && memcmp(_tmx_proc_ptran->cseqmet.s, - it->cseqmet.s, it->cseqmet.len)!=0) + if((it->cseqmetid == METHOD_OTHER || it->cseqmetid == METHOD_UNDEF) + && memcmp(_tmx_proc_ptran->cseqmet.s, it->cseqmet.s, + it->cseqmet.len) + != 0) continue; LM_DBG("matched another pre-transaction by pid %d for [%.*s]\n", it->pid, it->callid.len, it->callid.s); @@ -361,4 +371,3 @@ int tmx_check_pretran(sip_msg_t *msg) lock_release(&_tmx_ptran_table[slotid].lock); return 0; } -