diff --git a/src/modules/tm/callid.c b/src/modules/tm/callid.c index db4d5a0051a..b439f39004b 100644 --- a/src/modules/tm/callid.c +++ b/src/modules/tm/callid.c @@ -13,16 +13,16 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ /*! - * \file + * \file * \brief TM :: Fast Call-ID generator - * + * * Fast Call-ID generator. The Call-ID has the following form: \-\\@\ * - callid_nr is initialized as a random number and continually increases * - \\@\ is kept in callid_suffix @@ -47,13 +47,12 @@ /** * \brief Length of the Call-ID suffix */ -#define CALLID_SUFFIX_LEN ( 1 /* - */ + \ - 5 /* pid */ + \ - 42 /* embedded v4inv6 address can be looong '128.' */ + \ - 2 /* parenthesis [] */ + \ - 1 /* ZT 0 */ + \ - 16 /* one never knows ;-) */ \ - ) +#define CALLID_SUFFIX_LEN \ + (1 /* - */ + 5 /* pid */ \ + + 42 /* embedded v4inv6 address can be looong '128.' */ \ + + 2 /* parenthesis [] */ + 1 /* ZT 0 */ \ + + 16 /* one never knows ;-) */ \ + ) static unsigned long callid_nr; @@ -71,36 +70,40 @@ int init_callid(void) { int rand_bits, i; - /* calculate the initial call-id */ - /* how many bits and chars do we need to display the + /* calculate the initial call-id */ + /* how many bits and chars do we need to display the * whole ULONG number */ callid_prefix.len = sizeof(unsigned long) * 2; callid_prefix.s = callid_buf; - if (callid_prefix.len > CALLID_NR_LEN) { - LOG(L_ERR, "ERROR: Too small callid buffer\n"); + if(callid_prefix.len > CALLID_NR_LEN) { + LM_ERR("too small callid buffer\n"); return -1; } - - for(rand_bits = 1, i = KAM_RAND_MAX; i; i >>= 1, rand_bits++); /* how long are the rand()s ? */ - i = callid_prefix.len * 4 / rand_bits; /* how many rands() fit in the ULONG ? */ - /* now fill in the callid with as many random - * numbers as you can + 1 */ - callid_nr = kam_rand(); /* this is the + 1 */ + for(rand_bits = 1, i = KAM_RAND_MAX; i; i >>= 1, rand_bits++) + ; /* how long are the rand()s ? */ + i = callid_prefix.len * 4 + / rand_bits; /* how many rands() fit in the ULONG ? */ + + /* now fill in the callid with as many random + * numbers as you can + 1 */ + callid_nr = kam_rand(); /* this is the + 1 */ while(i--) { callid_nr <<= rand_bits; callid_nr |= kam_rand(); } - i = snprintf(callid_prefix.s, callid_prefix.len + 1, "%0*lx", callid_prefix.len, callid_nr); - if ((i == -1) || (i > callid_prefix.len)) { - LOG(L_CRIT, "BUG: SORRY, callid calculation failed\n"); + i = snprintf(callid_prefix.s, callid_prefix.len + 1, "%0*lx", + callid_prefix.len, callid_nr); + if((i == -1) || (i > callid_prefix.len)) { + LM_CRIT("callid calculation failed\n"); return -2; } - - DBG("Call-ID initialization: '%.*s'\n", callid_prefix.len, callid_prefix.s); + + LM_DBG("Call-ID initialization: '%.*s'\n", callid_prefix.len, + callid_prefix.s); return 0; } @@ -110,29 +113,28 @@ int init_callid(void) * \param rank not used * \return 0 on success, -1 on error */ -int child_init_callid(int rank) +int child_init_callid(int rank) { struct socket_info *si; - + /* 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){ - LOG(L_CRIT, "BUG: child_init_callid: null socket list\n"); + si = bind_address ? bind_address : get_first_socket(); + if(si == 0) { + LM_CRIT("null socket list\n"); return -1; } callid_suffix.s = callid_buf + callid_prefix.len; callid_suffix.len = snprintf(callid_suffix.s, CALLID_SUFFIX_LEN, - "%c%d@%.*s", '-', my_pid(), - si->address_str.len, - si->address_str.s); - if ((callid_suffix.len == -1) || (callid_suffix.len > CALLID_SUFFIX_LEN)) { - LOG(L_ERR, "ERROR: child_init_callid: buffer too small\n"); + "%c%d@%.*s", '-', my_pid(), si->address_str.len, si->address_str.s); + if((callid_suffix.len == -1) || (callid_suffix.len > CALLID_SUFFIX_LEN)) { + LM_ERR("buffer too small\n"); return -1; } - DBG("DEBUG: callid: '%.*s'\n", callid_prefix.len + callid_suffix.len, callid_prefix.s); + LM_DBG("callid: '%.*s'\n", callid_prefix.len + callid_suffix.len, + callid_prefix.s); return 0; } @@ -142,14 +144,14 @@ int child_init_callid(int rank) * \param _c input character * \return carry flag */ -static inline int inc_hexchar(char* _c) +static inline int inc_hexchar(char *_c) { - if (*_c == '9') { + if(*_c == '9') { *_c = 'a'; return 0; } - if (*_c == 'f') { + if(*_c == 'f') { *_c = '0'; return 1; } @@ -163,12 +165,13 @@ static inline int inc_hexchar(char* _c) * \brief Get a unique Call-ID * \param callid returned Call-ID */ -void tm_generate_callid(str* callid) +void tm_generate_callid(str *callid) { int i; for(i = callid_prefix.len; i; i--) { - if (!inc_hexchar(callid_prefix.s + i - 1)) break; + if(!inc_hexchar(callid_prefix.s + i - 1)) + break; } callid->s = callid_prefix.s; callid->len = callid_prefix.len + callid_suffix.len; @@ -178,10 +181,10 @@ void tm_generate_callid(str* callid) * \brief Wrapper to get a unique Call-ID based on tm or core callback * \param callid returned Call-ID */ -void generate_callid(str* callid) +void generate_callid(str *callid) { sr_generate_callid_f cf; - if((cf=sr_get_callid_func())!=NULL) { + if((cf = sr_get_callid_func()) != NULL) { cf(callid); } else { tm_generate_callid(callid); diff --git a/src/modules/tm/callid.h b/src/modules/tm/callid.h index 7ea404917e5..ebccc319999 100644 --- a/src/modules/tm/callid.h +++ b/src/modules/tm/callid.h @@ -13,17 +13,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * History: - * ---------- - * 2003-04-09 Created by janakj */ /*! - * \file + * \file * \brief TM :: Fast Call-ID generator * \ingroup tm */ @@ -53,14 +50,14 @@ int child_init_callid(int rank); /** * \brief TM API export */ -typedef void (*generate_callid_f)(str*); +typedef void (*generate_callid_f)(str *); /** * \brief Get a unique Call-ID * \param callid returned Call-ID */ -void generate_callid(str* callid); +void generate_callid(str *callid); #endif /* CALLID_H */ diff --git a/src/modules/tm/config.h b/src/modules/tm/config.h index bef4f61f728..963fea6ea01 100644 --- a/src/modules/tm/config.h +++ b/src/modules/tm/config.h @@ -13,8 +13,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -31,10 +31,10 @@ /* this is where table size is defined now -- sort of ugly, core should not be bothered by TM table size, - but on the other, core's stateless forwarding should + but on the other, core's stateless forwarding should have consistent branch generation with stateful mode and needs to calculate branch/hash, for which table size - is needed + is needed */ #include "../../core/hash_func.h" @@ -59,15 +59,15 @@ /* DELETE timer ... tells how long should the transaction persist in memory after it was removed from the hash table and before it will be deleted */ #define DEL_TIME_OUT 200 /* ms, obsoleted */ - + /* retransmission timers */ #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 - * immediately, but forced to go in the wait state or in wait for ack state - * and then wait state, so it will still be alive for either WT_TIME_OUT in + * immediately, but forced to go in the wait state or in wait for ack state + * 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 */ diff --git a/src/modules/tm/defs.h b/src/modules/tm/defs.h index b712b1d3c5d..719dba49958 100644 --- a/src/modules/tm/defs.h +++ b/src/modules/tm/defs.h @@ -14,14 +14,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ /*! - * \file + * \file * \brief TM :: Definitions * \ingroup tm */ diff --git a/src/modules/tm/dlg.c b/src/modules/tm/dlg.c index ccf690a6e5f..6d385202d96 100644 --- a/src/modules/tm/dlg.c +++ b/src/modules/tm/dlg.c @@ -20,8 +20,8 @@ */ /*! - * \file - * \brief TM :: + * \file + * \brief TM :: * \ingroup tm */ @@ -50,14 +50,15 @@ #ifdef DIALOG_CALLBACKS -struct new_dlg_cb{ +struct new_dlg_cb +{ int types; - struct new_dlg_cb* next; - dialog_cb* callback; - void* param; + struct new_dlg_cb *next; + dialog_cb *callback; + void *param; }; -static struct new_dlg_cb* new_dlg_cb_list=0; +static struct new_dlg_cb *new_dlg_cb_list = 0; /* callbacks for new dialogs (called each time a new dialog (uas or uac) is * created) * params: type - DLG_CB_UAC or DLG_CB_UAS @@ -67,56 +68,56 @@ static struct new_dlg_cb* new_dlg_cb_list=0; * returns < 0 on error * WARNING: this callbacks can be registered only before forking (in mod_init) */ -int register_new_dlg_cb(int type, dialog_cb f, void* param) +int register_new_dlg_cb(int type, dialog_cb f, void *param) { - struct new_dlg_cb* dlg_cb; - - dlg_cb=shm_malloc(sizeof(struct new_dlg_cb)); - if (dlg_cb==0) + struct new_dlg_cb *dlg_cb; + + dlg_cb = shm_malloc(sizeof(struct new_dlg_cb)); + if(dlg_cb == 0) return E_OUT_OF_MEM; - dlg_cb->types=type; - dlg_cb->callback=f; - dlg_cb->param=param; - dlg_cb->next=new_dlg_cb_list; - new_dlg_cb_list=dlg_cb; + dlg_cb->types = type; + dlg_cb->callback = f; + dlg_cb->param = param; + dlg_cb->next = new_dlg_cb_list; + new_dlg_cb_list = dlg_cb; return 0; } void destroy_new_dlg_cbs() { - struct new_dlg_cb* c; - struct new_dlg_cb* n; + struct new_dlg_cb *c; + struct new_dlg_cb *n; - c=new_dlg_cb_list; - while(c){ - n=c->next; + c = new_dlg_cb_list; + while(c) { + n = c->next; shm_free(c); - c=n; + c = n; } - new_dlg_cb_list=0; + new_dlg_cb_list = 0; } -static void run_new_dlg_callbacks(int type, dlg_t* dlg, struct sip_msg* msg) +static void run_new_dlg_callbacks(int type, dlg_t *dlg, struct sip_msg *msg) { - struct new_dlg_cb* c; - for (c=new_dlg_cb_list; c; c=c->next){ - if (c->types & type) + struct new_dlg_cb *c; + for(c = new_dlg_cb_list; c; c = c->next) { + if(c->types & type) c->callback(type, dlg, msg); } } -int register_dlg_tmcb(int types, dlg_t* dlg, transaction_cb f, void* param) +int register_dlg_tmcb(int types, dlg_t *dlg, transaction_cb f, void *param) { /* only TMCB_DLG bad TMCB_DESTROY allowed */ - if ((types&(TMCB_DLG|TMCB_DESTROY))!=types){ - LOG(L_CRIT, "BUG: tm: register_dlg_tmcb: bad types %d\n", types); + if((types & (TMCB_DLG | TMCB_DESTROY)) != types) { + LM_CRIT("bad types %d\n", types); return E_BUG; } - if (f==0){ - LOG(L_CRIT, "BUG: tm: register_dlg_tmcb: null callback function"); + if(f == 0) { + LM_CRIT("null callback function"); return E_BUG; } return insert_tmcb(&dlg->dlg_callbacks, types, f, param, NULL); @@ -125,38 +126,38 @@ int register_dlg_tmcb(int types, dlg_t* dlg, transaction_cb f, void* param) /* per dialog callbacks receive only the transaction, send buffer, destination * and the retr. buff */ -void run_trans_dlg_callbacks(dlg_t* dlg, struct cell* trans, - struct retr_buf* rbuf) +void run_trans_dlg_callbacks( + dlg_t *dlg, struct cell *trans, struct retr_buf *rbuf) { struct tmcb_params params; - - if (dlg->dlg_callbacks.first==0) + + if(dlg->dlg_callbacks.first == 0) return; memset(¶ms, 0, sizeof(params)); - if (rbuf){ - params.t_rbuf=rbuf; - params.dst=&rbuf->dst; - params.send_buf.s=rbuf->buffer; - params.send_buf.len=rbuf->buffer_len; - } - - run_trans_callbacks_internal(&dlg->dlg_callbacks, TMCB_DLG, trans, - ¶ms); + if(rbuf) { + params.t_rbuf = rbuf; + params.dst = &rbuf->dst; + params.send_buf.s = rbuf->buffer; + params.send_buf.len = rbuf->buffer_len; + } + + run_trans_callbacks_internal(&dlg->dlg_callbacks, TMCB_DLG, trans, ¶ms); } /* TMCB_DESTROY per dialog callbacks */ -static void destroy_trans_dlg_callbacks(dlg_t* dlg) +static void destroy_trans_dlg_callbacks(dlg_t *dlg) { struct tmcb_params params; - struct tm_callback* cbp; - - if ((dlg->dlg_callbacks.first==0) || - ((dlg->dlg_callbacks.reg_types&TMCB_DESTROY)==0) ) + struct tm_callback *cbp; + + if((dlg->dlg_callbacks.first == 0) + || ((dlg->dlg_callbacks.reg_types & TMCB_DESTROY) == 0)) return; memset(¶ms, 0, sizeof(params)); - for (cbp=(struct tm_callback*)dlg->dlg_callbacks.first;cbp;cbp=cbp->next){ - if (cbp->types & TMCB_DESTROY){ - params.param=&(cbp->param); + for(cbp = (struct tm_callback *)dlg->dlg_callbacks.first; cbp; + cbp = cbp->next) { + if(cbp->types & TMCB_DESTROY) { + params.param = &(cbp->param); cbp->callback(0, 0, ¶ms); } } @@ -175,29 +176,29 @@ static void destroy_trans_dlg_callbacks(dlg_t* dlg) * _s will be modified so it should be a tmp * copy */ -void get_raw_uri(str* _s) +void get_raw_uri(str *_s) { - char* aq; - - if (_s->s[_s->len - 1] == '>') { - aq = find_not_quoted(_s, '<'); - _s->len -= aq - _s->s + 2; - _s->s = aq + 1; - } + char *aq; + + if(_s->s[_s->len - 1] == '>') { + aq = find_not_quoted(_s, '<'); + _s->len -= aq - _s->s + 2; + _s->s = aq + 1; + } } /* * Make a copy of a str structure using shm_malloc */ -static inline int str_duplicate(str* _d, str* _s) +static inline int str_duplicate(str *_d, str *_s) { _d->s = shm_malloc(_s->len); - if (!_d->s) { - LOG(L_ERR, "str_duplicate(): No memory left\n"); + if(!_d->s) { + LM_ERR("no share memory left\n"); return -1; } - + memcpy(_d->s, _s->s, _s->len); _d->len = _s->len; return 0; @@ -212,25 +213,27 @@ static inline int str_duplicate(str* _d, str* _s) * F_RB_NH_LOOSE : routes present, next hop is loose router * F_RB_NH_STRICT: next hop is strict. */ -static inline int calculate_hooks(dlg_t* _d) +static inline int calculate_hooks(dlg_t *_d) { - str* uri; + str *uri; struct sip_uri puri; int nhop; /* we might re-calc. some existing hooks => * reset all the hooks to 0 */ memset(&_d->hooks, 0, sizeof(_d->hooks)); - if (_d->route_set) { + if(_d->route_set) { uri = &_d->route_set->nameaddr.uri; - if (parse_uri(uri->s, uri->len, &puri) < 0) { - LOG(L_ERR, "calculate_hooks(): Error while parsing URI\n"); + if(parse_uri(uri->s, uri->len, &puri) < 0) { + LM_ERR("error while parsing URI\n"); return -1; } - - if (puri.lr.s) { - if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target; - else _d->hooks.request_uri = &_d->rem_uri; + + if(puri.lr.s) { + if(_d->rem_target.s) + _d->hooks.request_uri = &_d->rem_target; + else + _d->hooks.request_uri = &_d->rem_uri; _d->hooks.next_hop = &_d->route_set->nameaddr.uri; _d->hooks.first_route = _d->route_set; nhop = F_RB_NH_LOOSE; @@ -238,22 +241,26 @@ static inline int calculate_hooks(dlg_t* _d) _d->hooks.request_uri = &_d->route_set->nameaddr.uri; _d->hooks.next_hop = _d->hooks.request_uri; _d->hooks.first_route = _d->route_set->next; - if (_d->rem_target.len > 0) + if(_d->rem_target.len > 0) _d->hooks.last_route = &_d->rem_target; - else + else _d->hooks.last_route = NULL; /* ? */ nhop = F_RB_NH_STRICT; } } else { - if (_d->rem_target.s) _d->hooks.request_uri = &_d->rem_target; - else _d->hooks.request_uri = &_d->rem_uri; - - if (_d->dst_uri.s) _d->hooks.next_hop = &_d->dst_uri; - else _d->hooks.next_hop = _d->hooks.request_uri; + if(_d->rem_target.s) + _d->hooks.request_uri = &_d->rem_target; + else + _d->hooks.request_uri = &_d->rem_uri; + + if(_d->dst_uri.s) + _d->hooks.next_hop = &_d->dst_uri; + else + _d->hooks.next_hop = _d->hooks.request_uri; nhop = 0; /* - * the routes in the hooks need to be reset because if the route_set + * the routes in the hooks need to be reset because if the route_set * was dropped somewhere else then these will remain set without the * actual routes existing any more */ @@ -261,13 +268,15 @@ static inline int calculate_hooks(dlg_t* _d) _d->hooks.last_route = 0; } - if ((_d->hooks.request_uri) && (_d->hooks.request_uri->s) && (_d->hooks.request_uri->len)) { + if((_d->hooks.request_uri) && (_d->hooks.request_uri->s) + && (_d->hooks.request_uri->len)) { _d->hooks.ru.s = _d->hooks.request_uri->s; _d->hooks.ru.len = _d->hooks.request_uri->len; _d->hooks.request_uri = &_d->hooks.ru; get_raw_uri(_d->hooks.request_uri); } - if ((_d->hooks.next_hop) && (_d->hooks.next_hop->s) && (_d->hooks.next_hop->len)) { + if((_d->hooks.next_hop) && (_d->hooks.next_hop->s) + && (_d->hooks.next_hop->len)) { _d->hooks.nh.s = _d->hooks.next_hop->s; _d->hooks.nh.len = _d->hooks.next_hop->len; _d->hooks.next_hop = &_d->hooks.nh; @@ -281,7 +290,7 @@ static inline int calculate_hooks(dlg_t* _d) * wrapper to calculate_hooks * added by dcm */ -int w_calculate_hooks(dlg_t* _d) +int w_calculate_hooks(dlg_t *_d) { return calculate_hooks(_d); } @@ -289,53 +298,59 @@ int w_calculate_hooks(dlg_t* _d) /* * Create a new dialog */ -int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d) +int new_dlg_uac(str *_cid, str *_ltag, unsigned int _lseq, str *_luri, + str *_ruri, dlg_t **_d) { - dlg_t* res; + dlg_t *res; str generated_cid; str generated_ltag; - if (!_cid) { /* if not given, compute new one */ + if(!_cid) { /* if not given, compute new one */ generate_callid(&generated_cid); _cid = &generated_cid; } - if (_cid && (!_ltag)) { /* if not given, compute new one */ + if(_cid && (!_ltag)) { /* if not given, compute new one */ generate_fromtag(&generated_ltag, _cid); _ltag = &generated_ltag; } - if (_lseq == 0) _lseq = DEFAULT_CSEQ; + if(_lseq == 0) + _lseq = DEFAULT_CSEQ; - if (!_cid || !_ltag || !_luri || !_ruri || !_d) { - LOG(L_ERR, "new_dlg_uac(): Invalid parameter value\n"); + if(!_cid || !_ltag || !_luri || !_ruri || !_d) { + LM_ERR("invalid parameter value\n"); return -1; } - res = (dlg_t*)shm_malloc(sizeof(dlg_t)); - if (res == 0) { - LOG(L_ERR, "new_dlg_uac(): No memory left\n"); + res = (dlg_t *)shm_malloc(sizeof(dlg_t)); + if(res == 0) { + LM_ERR("no memory left\n"); return -2; } - /* Clear everything */ + /* Clear everything */ memset(res, 0, sizeof(dlg_t)); - - /* Make a copy of Call-ID */ - if (str_duplicate(&res->id.call_id, _cid) < 0) return -3; - /* Make a copy of local tag (usually From tag) */ - if (str_duplicate(&res->id.loc_tag, _ltag) < 0) return -4; - /* Make a copy of local URI (usually From) */ - if (str_duplicate(&res->loc_uri, _luri) < 0) return -5; - /* Make a copy of remote URI (usually To) */ - if (str_duplicate(&res->rem_uri, _ruri) < 0) return -6; - /* Make a copy of local sequence (usually CSeq) */ + + /* Make a copy of Call-ID */ + if(str_duplicate(&res->id.call_id, _cid) < 0) + return -3; + /* Make a copy of local tag (usually From tag) */ + if(str_duplicate(&res->id.loc_tag, _ltag) < 0) + return -4; + /* Make a copy of local URI (usually From) */ + if(str_duplicate(&res->loc_uri, _luri) < 0) + return -5; + /* Make a copy of remote URI (usually To) */ + if(str_duplicate(&res->rem_uri, _ruri) < 0) + return -6; + /* Make a copy of local sequence (usually CSeq) */ res->loc_seq.value = _lseq; - /* And mark it as set */ + /* And mark it as set */ res->loc_seq.is_set = 1; *_d = res; - if (calculate_hooks(*_d) < 0) { - LOG(L_ERR, "new_dlg_uac(): Error while calculating hooks\n"); + if(calculate_hooks(*_d) < 0) { + LM_ERR("error while calculating hooks\n"); /* FIXME: free everything here */ shm_free(res); return -2; @@ -343,7 +358,7 @@ int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _rur #ifdef DIALOG_CALLBACKS run_new_dlg_callbacks(DLG_CB_UAC, res, 0); #endif - + return 0; } @@ -355,18 +370,19 @@ int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _rur * @return 0 on success; negative on error */ -int dlg_add_extra(dlg_t* _d, str* _ldname, str* _rdname) +int dlg_add_extra(dlg_t *_d, str *_ldname, str *_rdname) { - if(!_d || !_ldname || !_rdname) - { + if(!_d || !_ldname || !_rdname) { LM_ERR("Invalid parameters\n"); return -1; } /* Make a copy of local Display Name */ - if(shm_str_dup(&_d->loc_dname, _ldname) < 0) return -2; + if(shm_str_dup(&_d->loc_dname, _ldname) < 0) + return -2; /* Make a copy of remote Display Name */ - if(shm_str_dup(&_d->rem_dname, _rdname) < 0) return -3; + if(shm_str_dup(&_d->rem_dname, _rdname) < 0) + return -3; return 0; } @@ -375,24 +391,25 @@ int dlg_add_extra(dlg_t* _d, str* _ldname, str* _rdname) * Parse Contact header field body and extract URI * Does not parse headers !! */ -static inline int get_contact_uri(struct sip_msg* _m, str* _uri) +static inline int get_contact_uri(struct sip_msg *_m, str *_uri) { - contact_t* c; + contact_t *c; _uri->len = 0; _uri->s = 0; - if (!_m->contact) return 1; + if(!_m->contact) + return 1; - if (parse_contact(_m->contact) < 0) { - LOG(L_ERR, "get_contact_uri(): Error while parsing Contact body\n"); + if(parse_contact(_m->contact) < 0) { + LM_ERR("error while parsing Contact body\n"); return -2; } - c = ((contact_body_t*)_m->contact->parsed)->contacts; + c = ((contact_body_t *)_m->contact->parsed)->contacts; - if (!c) { - LOG(L_ERR, "get_contact_uri(): Empty body or * contact\n"); + if(!c) { + LM_ERR("empty body or * contact\n"); return -3; } @@ -406,14 +423,14 @@ static inline int get_contact_uri(struct sip_msg* _m, str* _uri) * Extract tag from To header field of a response * Doesn't parse message headers !! */ -static inline int get_to_tag(struct sip_msg* _m, str* _tag) +static inline int get_to_tag(struct sip_msg *_m, str *_tag) { - if (!_m->to) { - LOG(L_ERR, "get_to_tag(): To header field missing\n"); + if(!_m->to) { + LM_ERR("To header field missing\n"); return -1; } - if (get_to(_m)->tag_value.len) { + if(get_to(_m)->tag_value.len) { _tag->s = get_to(_m)->tag_value.s; _tag->len = get_to(_m)->tag_value.len; } else { @@ -427,14 +444,14 @@ static inline int get_to_tag(struct sip_msg* _m, str* _tag) /* * Extract tag from From header field of a request */ -static inline int get_from_tag(struct sip_msg* _m, str* _tag) +static inline int get_from_tag(struct sip_msg *_m, str *_tag) { - if (parse_from_header(_m) == -1) { - LOG(L_ERR, "get_from_tag(): Error while parsing From header\n"); + if(parse_from_header(_m) == -1) { + LM_ERR("error while parsing From header\n"); return -1; } - if (get_from(_m)->tag_value.len) { + if(get_from(_m)->tag_value.len) { _tag->s = get_from(_m)->tag_value.s; _tag->len = get_from(_m)->tag_value.len; } else { @@ -449,10 +466,10 @@ static inline int get_from_tag(struct sip_msg* _m, str* _tag) * Extract Call-ID value * Doesn't parse headers !! */ -static inline int get_callid(struct sip_msg* _m, str* _cid) +static inline int get_callid(struct sip_msg *_m, str *_cid) { - if (_m->callid == 0) { - LOG(L_ERR, "get_callid(): Call-ID not found\n"); + if(_m->callid == 0) { + LM_ERR("Call-ID not found\n"); return -1; } @@ -468,7 +485,7 @@ static rr_t *revert_route(rr_t *r) a = NULL; - while (r) { + while(r) { b = r->next; r->next = a; a = r; @@ -481,42 +498,45 @@ static rr_t *revert_route(rr_t *r) /* * Create a copy of route set either in normal or reverse order */ -static inline int get_route_set(struct sip_msg* _m, rr_t** _rs, unsigned char _order) +static inline int get_route_set( + struct sip_msg *_m, rr_t **_rs, unsigned char _order) { - struct hdr_field* ptr; - rr_t* last, *p, *t; - + struct hdr_field *ptr; + rr_t *last, *p, *t; + last = 0; ptr = _m->record_route; while(ptr) { - if (ptr->type == HDR_RECORDROUTE_T) { - if (parse_rr(ptr) < 0) { - LOG(L_ERR, "get_route_set(): Error while parsing Record-Route body\n"); + if(ptr->type == HDR_RECORDROUTE_T) { + if(parse_rr(ptr) < 0) { + LM_ERR("error while parsing Record-Route body\n"); goto error; } - p = (rr_t*)ptr->parsed; - if (shm_duplicate_rr(&t, p) < 0) { - LOG(L_ERR, "get_route_set(): Error while duplicating rr_t\n"); + p = (rr_t *)ptr->parsed; + if(shm_duplicate_rr(&t, p) < 0) { + LM_ERR("error while duplicating rr_t\n"); goto error; } - if (!*_rs) *_rs = t; - if (last) last->next = t; + if(!*_rs) + *_rs = t; + if(last) + last->next = t; last = t; - while (last->next) last = last->next; /* !!! there may be more routes in one hdr field !!! */ - + while(last->next) + last = last->next; /* !!! there may be more routes in one hdr field !!! */ } ptr = ptr->next; } - if ((*_rs) && (_order != NORMAL_ORDER)) { + if((*_rs) && (_order != NORMAL_ORDER)) { /* better to revert the route outside of cycle above */ *_rs = revert_route(*_rs); } - + return 0; - error: +error: shm_free_rr(_rs); return -1; } @@ -524,10 +544,10 @@ static inline int get_route_set(struct sip_msg* _m, rr_t** _rs, unsigned char _o /* * Extract method from CSeq header field */ -static inline int get_cseq_method(struct sip_msg* _m, str* _method) +static inline int get_cseq_method(struct sip_msg *_m, str *_method) { - if (!_m->cseq && ((parse_headers(_m, HDR_CSEQ_F, 0) == -1) || !_m->cseq)) { - LOG(L_ERR, "get_cseq_method(): Error while parsing CSeq\n"); + if(!_m->cseq && ((parse_headers(_m, HDR_CSEQ_F, 0) == -1) || !_m->cseq)) { + LM_ERR("error while parsing CSeq\n"); return -1; } @@ -537,33 +557,36 @@ static inline int get_cseq_method(struct sip_msg* _m, str* _method) } -static inline int refresh_dialog_resp(struct sip_msg* _m, - target_refresh_t is_target_refresh) +static inline int refresh_dialog_resp( + struct sip_msg *_m, target_refresh_t is_target_refresh) { str method; - - switch (is_target_refresh) { - case IS_NOT_TARGET_REFRESH: + + switch(is_target_refresh) { + case IS_NOT_TARGET_REFRESH: return 0; - case IS_TARGET_REFRESH: + case IS_TARGET_REFRESH: return 1; - case TARGET_REFRESH_UNKNOWN: - if (get_cseq_method(_m, &method) < 0) return 0; /* error */ - if ((method.len == 6) && !memcmp("INVITE", method.s, 6)) + case TARGET_REFRESH_UNKNOWN: + if(get_cseq_method(_m, &method) < 0) + return 0; /* error */ + if((method.len == 6) && !memcmp("INVITE", method.s, 6)) return 1; - else return 0; + else + return 0; } return 0; } - -static inline int refresh_dialog_req(struct sip_msg* _m, target_refresh_t is_target_refresh) + +static inline int refresh_dialog_req( + struct sip_msg *_m, target_refresh_t is_target_refresh) { - switch (is_target_refresh) { - case IS_NOT_TARGET_REFRESH: + switch(is_target_refresh) { + case IS_NOT_TARGET_REFRESH: return 0; - case IS_TARGET_REFRESH: + case IS_TARGET_REFRESH: return 1; - case TARGET_REFRESH_UNKNOWN: + case TARGET_REFRESH_UNKNOWN: return (_m->first_line.u.request.method_value == METHOD_INVITE); break; } @@ -574,42 +597,49 @@ static inline int refresh_dialog_req(struct sip_msg* _m, target_refresh_t is_tar * Extract all necessary information from a response and put it * in a dialog structure */ -static inline int response2dlg(struct sip_msg* _m, dlg_t* _d) +static inline int response2dlg(struct sip_msg *_m, dlg_t *_d) { str contact, rtag; - /* Parse the whole message, we will need all Record-Route headers */ - if (parse_headers(_m, HDR_EOH_F, 0) == -1) { - LOG(L_ERR, "response2dlg(): Error while parsing headers\n"); + /* Parse the whole message, we will need all Record-Route headers */ + if(parse_headers(_m, HDR_EOH_F, 0) == -1) { + LM_ERR("error while parsing headers\n"); return -1; } - - if (get_contact_uri(_m, &contact) < 0) return -2; - if (_d->rem_target.s) { + + if(get_contact_uri(_m, &contact) < 0) + return -2; + if(_d->rem_target.s) { shm_free(_d->rem_target.s); - _d->rem_target.s = 0; + _d->rem_target.s = 0; _d->rem_target.len = 0; } - if (_d->dst_uri.s) { + if(_d->dst_uri.s) { shm_free(_d->dst_uri.s); - _d->dst_uri.s = 0; + _d->dst_uri.s = 0; _d->dst_uri.len = 0; } - if (contact.len && str_duplicate(&_d->rem_target, &contact) < 0) return -3; - - if (get_to_tag(_m, &rtag) < 0) goto err1; - if (rtag.len && str_duplicate(&_d->id.rem_tag, &rtag) < 0) goto err1; - - if (get_route_set(_m, &_d->route_set, REVERSE_ORDER) < 0) goto err2; + if(contact.len && str_duplicate(&_d->rem_target, &contact) < 0) + return -3; + + if(get_to_tag(_m, &rtag) < 0) + goto err1; + if(rtag.len && str_duplicate(&_d->id.rem_tag, &rtag) < 0) + goto err1; + + if(get_route_set(_m, &_d->route_set, REVERSE_ORDER) < 0) + goto err2; return 0; - err2: - if (_d->id.rem_tag.s) shm_free(_d->id.rem_tag.s); +err2: + if(_d->id.rem_tag.s) + shm_free(_d->id.rem_tag.s); _d->id.rem_tag.s = 0; _d->id.rem_tag.len = 0; - err1: - if (_d->rem_target.s) shm_free(_d->rem_target.s); +err1: + if(_d->rem_target.s) + shm_free(_d->rem_target.s); _d->rem_target.s = 0; _d->rem_target.len = 0; return -4; @@ -620,48 +650,48 @@ static inline int response2dlg(struct sip_msg* _m, dlg_t* _d) * Handle dialog in DLG_NEW state, we will be processing the * first response */ -static inline int dlg_new_resp_uac(dlg_t* _d, struct sip_msg* _m) +static inline int dlg_new_resp_uac(dlg_t *_d, struct sip_msg *_m) { int code; - /* - * Dialog is in DLG_NEW state, we will copy remote - * target URI, remote tag if present, and route-set - * if present. And we will transit into DLG_CONFIRMED - * if the response was 2xx and to DLG_DESTROYED if the - * request was a negative final response. - */ + /* + * Dialog is in DLG_NEW state, we will copy remote + * target URI, remote tag if present, and route-set + * if present. And we will transit into DLG_CONFIRMED + * if the response was 2xx and to DLG_DESTROYED if the + * request was a negative final response. + */ code = _m->first_line.u.reply.statuscode; - if (code < 200) { - /* A provisional response, do nothing, we could - * update remote tag and route set but we will do that - * for a positive final response anyway and I don't want - * bet on presence of these fields in provisional responses - * - * Send a request to jan@iptel.org if you need to update - * the structures here - */ - } else if ((code >= 200) && (code < 299)) { - /* A final response, update the structures and transit - * into DLG_CONFIRMED - */ - if (response2dlg(_m, _d) < 0) return -1; + if(code < 200) { + /* A provisional response, do nothing, we could + * update remote tag and route set but we will do that + * for a positive final response anyway and I don't want + * bet on presence of these fields in provisional responses + * + * Send a request to jan@iptel.org if you need to update + * the structures here + */ + } else if((code >= 200) && (code < 299)) { + /* A final response, update the structures and transit + * into DLG_CONFIRMED + */ + if(response2dlg(_m, _d) < 0) + return -1; _d->state = DLG_CONFIRMED; - if (calculate_hooks(_d) < 0) { - LOG(L_ERR, "dlg_new_resp_uac(): Error while calculating hooks\n"); + if(calculate_hooks(_d) < 0) { + LM_ERR("error while calculating hooks\n"); return -2; } } else { - /* - * A negative final response, mark the dialog as destroyed - * Again, I do not update the structures here because it - * makes no sense to me, a dialog shouldn't be used after - * it is destroyed - */ + /* A negative final response, mark the dialog as destroyed + * Again, I do not update the structures here because it + * makes no sense to me, a dialog shouldn't be used after + * it is destroyed + */ _d->state = DLG_DESTROYED; - /* Signalize the termination with positive return value */ + /* Signalize the termination with positive return value */ return 1; } @@ -673,34 +703,34 @@ static inline int dlg_new_resp_uac(dlg_t* _d, struct sip_msg* _m) * Handle dialog in DLG_EARLY state, we will be processing either * next provisional response or a final response */ -static inline int dlg_early_resp_uac(dlg_t* _d, struct sip_msg* _m) +static inline int dlg_early_resp_uac(dlg_t *_d, struct sip_msg *_m) { int code; - code = _m->first_line.u.reply.statuscode; + code = _m->first_line.u.reply.statuscode; - if (code < 200) { - /* We are in early state already, do nothing - */ - } else if ((code >= 200) && (code <= 299)) { + if(code < 200) { + /* We are in early state already, do nothing */ + } else if((code >= 200) && (code <= 299)) { /* Warning - we can handle here response for non-initial request (for * example UPDATE within early INVITE/BYE dialog) and move into * confirmed state may be error! But this depends on dialog type... */ - - /* Same as in dlg_new_resp_uac */ - /* A final response, update the structures and transit - * into DLG_CONFIRMED - */ - if (response2dlg(_m, _d) < 0) return -1; + + /* Same as in dlg_new_resp_uac */ + /* A final response, update the structures and transit + * into DLG_CONFIRMED + */ + if(response2dlg(_m, _d) < 0) + return -1; _d->state = DLG_CONFIRMED; - if (calculate_hooks(_d) < 0) { - LOG(L_ERR, "dlg_early_resp_uac(): Error while calculating hooks\n"); + if(calculate_hooks(_d) < 0) { + LM_ERR("error while calculating hooks\n"); return -2; } } else { - /* Else terminate the dialog */ + /* Else terminate the dialog */ _d->state = DLG_DESTROYED; - /* Signalize the termination with positive return value */ + /* Signalize the termination with positive return value */ return 1; } @@ -712,57 +742,61 @@ static inline int dlg_early_resp_uac(dlg_t* _d, struct sip_msg* _m) * Handle dialog in DLG_CONFIRMED state, we will be processing * a response to a request sent within a dialog */ -static inline int dlg_confirmed_resp_uac(dlg_t* _d, struct sip_msg* _m, - target_refresh_t is_target_refresh) +static inline int dlg_confirmed_resp_uac( + dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_refresh) { int code; str contact; - code = _m->first_line.u.reply.statuscode; - - /* Dialog has been already confirmed, that means we received - * a response to a request sent within the dialog. We will - * update remote target URI if and only if the message sent was - * a target refresher. - */ + code = _m->first_line.u.reply.statuscode; - /* IF we receive a 481 response, terminate the dialog because - * the remote peer indicated that it didn't have the dialog - * state anymore, signal this termination with a positive return - * value - */ - if (code == 481) { + /* Dialog has been already confirmed, that means we received + * a response to a request sent within the dialog. We will + * update remote target URI if and only if the message sent was + * a target refresher. + */ + + /* IF we receive a 481 response, terminate the dialog because + * the remote peer indicated that it didn't have the dialog + * state anymore, signal this termination with a positive return + * value + */ + if(code == 481) { _d->state = DLG_DESTROYED; return 1; } - /* Do nothing if not 2xx */ - if ((code < 200) || (code >= 300)) return 0; - - if (refresh_dialog_resp(_m, is_target_refresh)) { - /* Get contact if any and update remote target */ - if (parse_headers(_m, HDR_CONTACT_F, 0) == -1) { - LOG(L_ERR, "dlg_confirmed_resp_uac(): Error while parsing headers\n"); + /* Do nothing if not 2xx */ + if((code < 200) || (code >= 300)) + return 0; + + if(refresh_dialog_resp(_m, is_target_refresh)) { + /* Get contact if any and update remote target */ + if(parse_headers(_m, HDR_CONTACT_F, 0) == -1) { + LM_ERR("error while parsing headers\n"); return -2; } - /* Try to extract contact URI */ - if (get_contact_uri(_m, &contact) < 0) return -3; - /* If there is a contact URI */ - if (contact.len) { - /* Free old remote target and destination uri if any */ - if (_d->rem_target.s) shm_free(_d->rem_target.s); - if (_d->dst_uri.s) { + /* Try to extract contact URI */ + if(get_contact_uri(_m, &contact) < 0) + return -3; + /* If there is a contact URI */ + if(contact.len) { + /* Free old remote target and destination uri if any */ + if(_d->rem_target.s) + shm_free(_d->rem_target.s); + if(_d->dst_uri.s) { shm_free(_d->dst_uri.s); _d->dst_uri.s = 0; _d->dst_uri.len = 0; } - - /* Duplicate new remote target */ - if (str_duplicate(&_d->rem_target, &contact) < 0) return -4; + + /* Duplicate new remote target */ + if(str_duplicate(&_d->rem_target, &contact) < 0) + return -4; } - if (calculate_hooks(_d) < 0) + if(calculate_hooks(_d) < 0) return -1; } @@ -773,31 +807,31 @@ static inline int dlg_confirmed_resp_uac(dlg_t* _d, struct sip_msg* _m, /* * A response arrived, update dialog */ -int dlg_response_uac(dlg_t* _d, struct sip_msg* _m, - target_refresh_t is_target_refresh) +int dlg_response_uac( + dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_refresh) { - if (!_d || !_m) { - LOG(L_ERR, "dlg_response_uac(): Invalid parameter value\n"); + if(!_d || !_m) { + LM_ERR("invalid parameter value\n"); return -1; } - /* The main dispatcher */ + /* The main dispatcher */ switch(_d->state) { - case DLG_NEW: - return dlg_new_resp_uac(_d, _m); + case DLG_NEW: + return dlg_new_resp_uac(_d, _m); - case DLG_EARLY: - return dlg_early_resp_uac(_d, _m); + case DLG_EARLY: + return dlg_early_resp_uac(_d, _m); - case DLG_CONFIRMED: - return dlg_confirmed_resp_uac(_d, _m, is_target_refresh); + case DLG_CONFIRMED: + return dlg_confirmed_resp_uac(_d, _m, is_target_refresh); - case DLG_DESTROYED: - LOG(L_DBG, "dlg_response_uac(): Cannot handle destroyed dialog\n"); - return -2; + case DLG_DESTROYED: + LM_DBG("cannot handle destroyed dialog\n"); + return -2; } - LOG(L_ERR, "dlg_response_uac(): Error in switch statement\n"); + LM_ERR("Error in switch statement\n"); return -3; } @@ -806,12 +840,12 @@ int dlg_response_uac(dlg_t* _d, struct sip_msg* _m, * Get CSeq number * Does not parse headers !! */ -static inline int get_cseq_value(struct sip_msg* _m, unsigned int* _cs) +static inline int get_cseq_value(struct sip_msg *_m, unsigned int *_cs) { str num; - if (_m->cseq == 0) { - LOG(L_ERR, "get_cseq_value(): CSeq header not found\n"); + if(_m->cseq == 0) { + LM_ERR("CSeq header not found\n"); return -1; } @@ -819,8 +853,8 @@ static inline int get_cseq_value(struct sip_msg* _m, unsigned int* _cs) num.len = get_cseq(_m)->number.len; trim_leading(&num); - if (str2int(&num, _cs) < 0) { - LOG(L_ERR, "get_cseq_value(): Error while converting cseq number\n"); + if(str2int(&num, _cs) < 0) { + LM_ERR("error while converting cseq number\n"); return -2; } return 0; @@ -830,41 +864,42 @@ static inline int get_cseq_value(struct sip_msg* _m, unsigned int* _cs) /* * Copy To or From URI without tag parameter */ -static inline int get_dlg_uri(struct hdr_field* _h, str* _s) +static inline int get_dlg_uri(struct hdr_field *_h, str *_s) { - struct to_param* ptr, *prev; - struct to_body* body; - char* tag = 0; /* Makes gcc happy */ + struct to_param *ptr, *prev; + struct to_body *body; + char *tag = 0; /* Makes gcc happy */ int tag_len = 0, len; - if (!_h) { - LOG(L_ERR, "get_dlg_uri(): Header field not found\n"); + if(!_h) { + LM_ERR("header field not found\n"); return -1; } - /* From was already parsed when extracting tag - * and To is parsed by default - */ - - body = (struct to_body*)_h->parsed; + /* From was already parsed when extracting tag + * and To is parsed by default + */ + + body = (struct to_body *)_h->parsed; ptr = body->param_lst; prev = 0; while(ptr) { - if (ptr->type == TAG_PARAM) break; + if(ptr->type == TAG_PARAM) + break; prev = ptr; ptr = ptr->next; } - if (ptr) { - /* Tag param found */ - if (prev) { + if(ptr) { + /* Tag param found */ + if(prev) { tag = prev->value.s + prev->value.len; } else { tag = body->body.s + body->body.len; } - - if (ptr->next) { + + if(ptr->next) { tag_len = ptr->value.s + ptr->value.len - tag; } else { tag_len = _h->body.s + _h->body.len - tag; @@ -872,12 +907,12 @@ static inline int get_dlg_uri(struct hdr_field* _h, str* _s) } _s->s = shm_malloc(_h->body.len - tag_len); - if (!_s->s) { - LOG(L_ERR, "get_dlg_uri(): No memory left\n"); + if(!_s->s) { + LM_ERR("no share memory left\n"); return -1; } - if (tag_len) { + if(tag_len) { len = tag - _h->body.s; memcpy(_s->s, _h->body.s, len); memcpy(_s->s + len, tag + tag_len, _h->body.len - len - tag_len); @@ -892,62 +927,78 @@ static inline int get_dlg_uri(struct hdr_field* _h, str* _s) /* - * Extract all information from a request + * Extract all information from a request * and update a dialog structure */ -static inline int request2dlg(struct sip_msg* _m, dlg_t* _d) +static inline int request2dlg(struct sip_msg *_m, dlg_t *_d) { str contact, rtag, callid; - if (parse_headers(_m, HDR_EOH_F, 0) == -1) { - LOG(L_ERR, "request2dlg(): Error while parsing headers"); + if(parse_headers(_m, HDR_EOH_F, 0) == -1) { + LM_ERR("error while parsing headers\n"); return -1; } - if (get_contact_uri(_m, &contact) < 0) return -2; - if (contact.len) { - if (_d->rem_target.s) shm_free(_d->rem_target.s); - if (_d->dst_uri.s) { + if(get_contact_uri(_m, &contact) < 0) + return -2; + if(contact.len) { + if(_d->rem_target.s) + shm_free(_d->rem_target.s); + if(_d->dst_uri.s) { shm_free(_d->dst_uri.s); _d->dst_uri.s = 0; _d->dst_uri.len = 0; } - if (str_duplicate(&_d->rem_target, &contact) < 0) return -3; + if(str_duplicate(&_d->rem_target, &contact) < 0) + return -3; } - - if (get_from_tag(_m, &rtag) < 0) goto err1; - if (rtag.len && str_duplicate(&_d->id.rem_tag, &rtag) < 0) goto err1; - if (get_callid(_m, &callid) < 0) goto err2; - if (callid.len && str_duplicate(&_d->id.call_id, &callid) < 0) goto err2; + if(get_from_tag(_m, &rtag) < 0) + goto err1; + if(rtag.len && str_duplicate(&_d->id.rem_tag, &rtag) < 0) + goto err1; - if (get_cseq_value(_m, &_d->rem_seq.value) < 0) goto err3; + if(get_callid(_m, &callid) < 0) + goto err2; + if(callid.len && str_duplicate(&_d->id.call_id, &callid) < 0) + goto err2; + + if(get_cseq_value(_m, &_d->rem_seq.value) < 0) + goto err3; _d->rem_seq.is_set = 1; - if (get_dlg_uri(_m->from, &_d->rem_uri) < 0) goto err3; - if (get_dlg_uri(_m->to, &_d->loc_uri) < 0) goto err4; + if(get_dlg_uri(_m->from, &_d->rem_uri) < 0) + goto err3; + if(get_dlg_uri(_m->to, &_d->loc_uri) < 0) + goto err4; - if (get_route_set(_m, &_d->route_set, NORMAL_ORDER) < 0) goto err5; + if(get_route_set(_m, &_d->route_set, NORMAL_ORDER) < 0) + goto err5; return 0; - err5: - if (_d->loc_uri.s) shm_free(_d->loc_uri.s); +err5: + if(_d->loc_uri.s) + shm_free(_d->loc_uri.s); _d->loc_uri.s = 0; _d->loc_uri.len = 0; - err4: - if (_d->rem_uri.s) shm_free(_d->rem_uri.s); +err4: + if(_d->rem_uri.s) + shm_free(_d->rem_uri.s); _d->rem_uri.s = 0; _d->rem_uri.len = 0; - err3: - if (_d->id.call_id.s) shm_free(_d->id.call_id.s); +err3: + if(_d->id.call_id.s) + shm_free(_d->id.call_id.s); _d->id.call_id.s = 0; _d->id.call_id.len = 0; - err2: - if (_d->id.rem_tag.s) shm_free(_d->id.rem_tag.s); +err2: + if(_d->id.rem_tag.s) + shm_free(_d->id.rem_tag.s); _d->id.rem_tag.s = 0; _d->id.rem_tag.len = 0; - err1: - if (_d->rem_target.s) shm_free(_d->rem_target.s); +err1: + if(_d->rem_target.s) + shm_free(_d->rem_target.s); _d->rem_target.s = 0; _d->rem_target.len = 0; return -4; @@ -957,55 +1008,55 @@ static inline int request2dlg(struct sip_msg* _m, dlg_t* _d) /* * Establishing a new dialog, UAS side */ -int new_dlg_uas(struct sip_msg* _req, int _code, /*str* _tag,*/ dlg_t** _d) +int new_dlg_uas(struct sip_msg *_req, int _code, /*str* _tag,*/ dlg_t **_d) { - dlg_t* res; + dlg_t *res; str tag; - if (!_req || /*!_tag ||*/ !_d) { - LOG(L_ERR, "new_dlg_uas(): Invalid parameter value\n"); + if(!_req || /*!_tag ||*/ !_d) { + LM_ERR("invalid parameter value\n"); return -1; } - if (_code > 299) { - DBG("new_dlg_uas(): Status code >= 300, no dialog created\n"); + if(_code > 299) { + LM_DBG("status code >= 300, no dialog created\n"); } - res = (dlg_t*)shm_malloc(sizeof(dlg_t)); - if (res == 0) { - LOG(L_ERR, "new_dlg_uac(): No memory left\n"); + res = (dlg_t *)shm_malloc(sizeof(dlg_t)); + if(res == 0) { + LM_ERR("no memory left\n"); return -3; } - /* Clear everything */ - memset(res, 0, sizeof(dlg_t)); + /* Clear everything */ + memset(res, 0, sizeof(dlg_t)); - if (request2dlg(_req, res) < 0) { - LOG(L_ERR, "new_dlg_uas(): Error while converting request to dialog\n"); + if(request2dlg(_req, res) < 0) { + LM_ERR("error while converting request to dialog\n"); free_dlg(res); return -4; } - if (_code > 100) { + if(_code > 100) { tag.s = tm_tags; tag.len = TOTAG_VALUE_LEN; calc_crc_suffix(_req, tm_tag_suffix); - if (str_duplicate(&res->id.loc_tag, &tag) < 0) { + if(str_duplicate(&res->id.loc_tag, &tag) < 0) { free_dlg(res); return -5; } } - + *_d = res; - if (_code < 100) + if(_code < 100) (*_d)->state = DLG_NEW; - else if (_code < 200) + else if(_code < 200) (*_d)->state = DLG_EARLY; else (*_d)->state = DLG_CONFIRMED; - if (calculate_hooks(*_d) < 0) { - LOG(L_ERR, "new_dlg_uas(): Error while calculating hooks\n"); + if(calculate_hooks(*_d) < 0) { + LM_ERR("error while calculating hooks\n"); free_dlg(res); return -6; } @@ -1019,36 +1070,36 @@ int new_dlg_uas(struct sip_msg* _req, int _code, /*str* _tag,*/ dlg_t** _d) /* * UAS side - update dialog state and to tag */ -int update_dlg_uas(dlg_t *_d, int _code, str* _tag) +int update_dlg_uas(dlg_t *_d, int _code, str *_tag) { - if (_d->state == DLG_CONFIRMED) { - LOG(L_ERR, "update_dlg_uas(): Dialog is already confirmed\n"); + if(_d->state == DLG_CONFIRMED) { + LM_ERR("dialog is already confirmed\n"); return -1; - } else if (_d->state == DLG_DESTROYED) { - LOG(L_ERR, "update_dlg_uas(): Dialog is already destroyed\n"); + } else if(_d->state == DLG_DESTROYED) { + LM_ERR("dialog is already destroyed\n"); return -2; } - if (_tag && _tag->s) { - if (_d->id.loc_tag.s) { - if ((_tag->len == _d->id.loc_tag.len) - && (!memcmp(_tag->s, _d->id.loc_tag.s, _tag->len))) { - LOG(L_DBG, "update_dlg_uas(): Local tag is already set\n"); + if(_tag && _tag->s) { + if(_d->id.loc_tag.s) { + if((_tag->len == _d->id.loc_tag.len) + && (!memcmp(_tag->s, _d->id.loc_tag.s, _tag->len))) { + LM_DBG("local tag is already set\n"); } else { - LOG(L_ERR, "update_dlg_uas(): ERROR: trying to rewrite local tag\n"); + LM_ERR("error trying to rewrite local tag\n"); return -3; } } else { - if (str_duplicate(&_d->id.loc_tag, _tag) < 0) { - LOG(L_ERR, "update_dlg_uas(): Not enough memory\n"); + if(str_duplicate(&_d->id.loc_tag, _tag) < 0) { + LM_ERR("not enough memory\n"); return -4; } } } - if ((100 < _code) && (_code < 200)) + if((100 < _code) && (_code < 200)) _d->state = DLG_EARLY; - else if (_code < 300) + else if(_code < 300) _d->state = DLG_CONFIRMED; else _d->state = DLG_DESTROYED; @@ -1059,53 +1110,58 @@ int update_dlg_uas(dlg_t *_d, int _code, str* _tag) /* * UAS side - update a dialog from a request */ -int dlg_request_uas(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_refresh) +int dlg_request_uas( + dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_refresh) { str contact; int cseq; - if (!_d || !_m) { - LOG(L_ERR, "dlg_request_uas(): Invalid parameter value\n"); + if(!_d || !_m) { + LM_ERR("invalid parameter value\n"); return -1; } - /* We must check if the request is not out of order or retransmission - * first, if so then we will not update anything - */ - if (parse_headers(_m, HDR_CSEQ_F, 0) == -1) { - LOG(L_ERR, "dlg_request_uas(): Error while parsing headers\n"); + /* We must check if the request is not out of order or retransmission + * first, if so then we will not update anything + */ + if(parse_headers(_m, HDR_CSEQ_F, 0) == -1) { + LM_ERR("error while parsing headers\n"); return -2; } - if (get_cseq_value(_m, (unsigned int*)&cseq) < 0) return -3; - if (_d->rem_seq.is_set && (cseq <= _d->rem_seq.value)) return 0; + if(get_cseq_value(_m, (unsigned int *)&cseq) < 0) + return -3; + if(_d->rem_seq.is_set && (cseq <= _d->rem_seq.value)) + return 0; - /* Neither out of order nor retransmission -> update */ + /* Neither out of order nor retransmission -> update */ _d->rem_seq.value = cseq; _d->rem_seq.is_set = 1; - - /* We will als update remote target URI if the message - * is target refresher - */ - if (refresh_dialog_req(_m, is_target_refresh)) { /* target refresher */ - if (parse_headers(_m, HDR_CONTACT_F, 0) == -1) { - LOG(L_ERR, "dlg_request_uas(): Error while parsing headers\n"); + + /* We will als update remote target URI if the message + * is target refresher + */ + if(refresh_dialog_req(_m, is_target_refresh)) { /* target refresher */ + if(parse_headers(_m, HDR_CONTACT_F, 0) == -1) { + LM_ERR("error while parsing headers\n"); return -4; } - - if (get_contact_uri(_m, &contact) < 0) return -5; - if (contact.len) { - if (_d->rem_target.s) shm_free(_d->rem_target.s); - if (_d->dst_uri.s) { + + if(get_contact_uri(_m, &contact) < 0) + return -5; + if(contact.len) { + if(_d->rem_target.s) + shm_free(_d->rem_target.s); + if(_d->dst_uri.s) { shm_free(_d->dst_uri.s); _d->dst_uri.s = 0; _d->dst_uri.len = 0; } - if (str_duplicate(&_d->rem_target, &contact) < 0) return -6; + if(str_duplicate(&_d->rem_target, &contact) < 0) + return -6; } - if (calculate_hooks(_d) < 0) + if(calculate_hooks(_d) < 0) return -1; - } return 0; @@ -1115,22 +1171,22 @@ int dlg_request_uas(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_re /* * Calculate length of the route set */ -int calculate_routeset_length(dlg_t* _d) +int calculate_routeset_length(dlg_t *_d) { int len; rr_t *ptr; - if (! _d->route_set) + if(!_d->route_set) return 0; len = ROUTE_PREFIX_LEN; - for (ptr = _d->hooks.first_route; ptr; ptr = ptr->next) { + for(ptr = _d->hooks.first_route; ptr; ptr = ptr->next) { len += ptr->len; len += ROUTE_SEPARATOR_LEN; } - if (_d->hooks.last_route) { - if (_d->hooks.first_route) + if(_d->hooks.last_route) { + if(_d->hooks.first_route) len += ROUTE_SEPARATOR_LEN; len += _d->hooks.last_route->len + 2; /* < > */ } else { @@ -1146,13 +1202,13 @@ int calculate_routeset_length(dlg_t* _d) * * Print the route set */ -char* print_routeset(char* buf, dlg_t* _d) +char *print_routeset(char *buf, dlg_t *_d) { - rr_t* ptr; + rr_t *ptr; ptr = _d->hooks.first_route; - if (ptr || _d->hooks.last_route) { + if(ptr || _d->hooks.last_route) { memcpy(buf, ROUTE_PREFIX, ROUTE_PREFIX_LEN); buf += ROUTE_PREFIX_LEN; } @@ -1162,14 +1218,14 @@ char* print_routeset(char* buf, dlg_t* _d) buf += ptr->len; ptr = ptr->next; - if (ptr) { + if(ptr) { memcpy(buf, ROUTE_SEPARATOR, ROUTE_SEPARATOR_LEN); buf += ROUTE_SEPARATOR_LEN; } - } + } - if (_d->hooks.last_route) { - if (_d->hooks.first_route) { + if(_d->hooks.last_route) { + if(_d->hooks.first_route) { memcpy(buf, ROUTE_SEPARATOR, ROUTE_SEPARATOR_LEN); buf += ROUTE_SEPARATOR_LEN; } @@ -1181,7 +1237,7 @@ char* print_routeset(char* buf, dlg_t* _d) buf++; } - if (_d->hooks.first_route || _d->hooks.last_route) { + if(_d->hooks.first_route || _d->hooks.last_route) { memcpy(buf, CRLF, CRLF_LEN); buf += CRLF_LEN; } @@ -1193,25 +1249,35 @@ char* print_routeset(char* buf, dlg_t* _d) /* * Destroy a dialog state */ -void free_dlg(dlg_t* _d) +void free_dlg(dlg_t *_d) { - if (!_d) return; + if(!_d) + return; #ifdef DIALOG_CALLBACKS destroy_trans_dlg_callbacks(_d); #endif - if (_d->id.call_id.s) shm_free(_d->id.call_id.s); - if (_d->id.rem_tag.s) shm_free(_d->id.rem_tag.s); - if (_d->id.loc_tag.s) shm_free(_d->id.loc_tag.s); - - if (_d->loc_uri.s) shm_free(_d->loc_uri.s); - if (_d->rem_uri.s) shm_free(_d->rem_uri.s); - if (_d->rem_target.s) shm_free(_d->rem_target.s); - if (_d->dst_uri.s) shm_free(_d->dst_uri.s); + if(_d->id.call_id.s) + shm_free(_d->id.call_id.s); + if(_d->id.rem_tag.s) + shm_free(_d->id.rem_tag.s); + if(_d->id.loc_tag.s) + shm_free(_d->id.loc_tag.s); + + if(_d->loc_uri.s) + shm_free(_d->loc_uri.s); + if(_d->rem_uri.s) + shm_free(_d->rem_uri.s); + if(_d->rem_target.s) + shm_free(_d->rem_target.s); + if(_d->dst_uri.s) + shm_free(_d->dst_uri.s); - if (_d->loc_dname.s) shm_free(_d->loc_dname.s); - if (_d->rem_dname.s) shm_free(_d->rem_dname.s); + if(_d->loc_dname.s) + shm_free(_d->loc_dname.s); + if(_d->rem_dname.s) + shm_free(_d->rem_dname.s); - /* Free all routes in the route set */ + /* Free all routes in the route set */ shm_free_rr(&_d->route_set); shm_free(_d); } @@ -1220,65 +1286,85 @@ void free_dlg(dlg_t* _d) /* * Print a dialog structure, just for debugging */ -void print_dlg(FILE* out, dlg_t* _d) +void print_dlg(FILE *out, dlg_t *_d) { fprintf(out, "====dlg_t===\n"); - fprintf(out, "id.call_id : '%.*s'\n", _d->id.call_id.len, _d->id.call_id.s); - fprintf(out, "id.rem_tag : '%.*s'\n", _d->id.rem_tag.len, _d->id.rem_tag.s); - fprintf(out, "id.loc_tag : '%.*s'\n", _d->id.loc_tag.len, _d->id.loc_tag.s); + fprintf(out, "id.call_id : '%.*s'\n", _d->id.call_id.len, + _d->id.call_id.s); + fprintf(out, "id.rem_tag : '%.*s'\n", _d->id.rem_tag.len, + _d->id.rem_tag.s); + fprintf(out, "id.loc_tag : '%.*s'\n", _d->id.loc_tag.len, + _d->id.loc_tag.s); fprintf(out, "loc_seq.value : %d\n", _d->loc_seq.value); fprintf(out, "loc_seq.is_set: %s\n", _d->loc_seq.is_set ? "YES" : "NO"); fprintf(out, "rem_seq.value : %d\n", _d->rem_seq.value); fprintf(out, "rem_seq.is_set: %s\n", _d->rem_seq.is_set ? "YES" : "NO"); fprintf(out, "loc_uri : '%.*s'\n", _d->loc_uri.len, _d->loc_uri.s); fprintf(out, "rem_uri : '%.*s'\n", _d->rem_uri.len, _d->rem_uri.s); - fprintf(out, "rem_target : '%.*s'\n", _d->rem_target.len, _d->rem_target.s); + fprintf(out, "rem_target : '%.*s'\n", _d->rem_target.len, + _d->rem_target.s); fprintf(out, "dst_uri : '%.*s'\n", _d->dst_uri.len, _d->dst_uri.s); fprintf(out, "secure: : %d\n", _d->secure); fprintf(out, "state : "); switch(_d->state) { - case DLG_NEW: fprintf(out, "DLG_NEW\n"); break; - case DLG_EARLY: fprintf(out, "DLG_EARLY\n"); break; - case DLG_CONFIRMED: fprintf(out, "DLG_CONFIRMED\n"); break; - case DLG_DESTROYED: fprintf(out, "DLG_DESTROYED\n"); break; + case DLG_NEW: + fprintf(out, "DLG_NEW\n"); + break; + case DLG_EARLY: + fprintf(out, "DLG_EARLY\n"); + break; + case DLG_CONFIRMED: + fprintf(out, "DLG_CONFIRMED\n"); + break; + case DLG_DESTROYED: + fprintf(out, "DLG_DESTROYED\n"); + break; } print_rr(out, _d->route_set); - if (_d->hooks.request_uri) - fprintf(out, "hooks.request_uri: '%.*s'\n", _d->hooks.request_uri->len, _d->hooks.request_uri->s); - if (_d->hooks.next_hop) - fprintf(out, "hooks.next_hop : '%.*s'\n", _d->hooks.next_hop->len, _d->hooks.next_hop->s); - if (_d->hooks.first_route) - fprintf(out, "hooks.first_route: '%.*s'\n", _d->hooks.first_route->len, _d->hooks.first_route->nameaddr.name.s); - if (_d->hooks.last_route) - fprintf(out, "hooks.last_route : '%.*s'\n", _d->hooks.last_route->len, _d->hooks.last_route->s); - + if(_d->hooks.request_uri) + fprintf(out, "hooks.request_uri: '%.*s'\n", _d->hooks.request_uri->len, + _d->hooks.request_uri->s); + if(_d->hooks.next_hop) + fprintf(out, "hooks.next_hop : '%.*s'\n", _d->hooks.next_hop->len, + _d->hooks.next_hop->s); + if(_d->hooks.first_route) + fprintf(out, "hooks.first_route: '%.*s'\n", _d->hooks.first_route->len, + _d->hooks.first_route->nameaddr.name.s); + if(_d->hooks.last_route) + fprintf(out, "hooks.last_route : '%.*s'\n", _d->hooks.last_route->len, + _d->hooks.last_route->s); + fprintf(out, "====dlg_t====\n"); } /* * set dialog's request uri and destination uri (optional) */ -int set_dlg_target(dlg_t* _d, str* _ruri, str* _duri) { +int set_dlg_target(dlg_t *_d, str *_ruri, str *_duri) +{ - if (!_d || !_ruri) { - LOG(L_ERR, "set_dlg_target(): Invalid parameter value\n"); + if(!_d || !_ruri) { + LM_ERR("invalid parameter value\n"); return -1; } - if (_d->rem_target.s) shm_free(_d->rem_target.s); - if (_d->dst_uri.s) { + if(_d->rem_target.s) + shm_free(_d->rem_target.s); + if(_d->dst_uri.s) { shm_free(_d->dst_uri.s); _d->dst_uri.s = 0; _d->dst_uri.len = 0; } - if (str_duplicate(&_d->rem_target, _ruri)) return -1; - if (_duri && _duri->len) { - if (str_duplicate(&_d->dst_uri, _duri)) return -1; + if(str_duplicate(&_d->rem_target, _ruri)) + return -1; + if(_duri && _duri->len) { + if(str_duplicate(&_d->dst_uri, _duri)) + return -1; } - if (calculate_hooks(_d) < 0) { - LOG(L_ERR, "set_dlg_target(): Error while calculating hooks\n"); + if(calculate_hooks(_d) < 0) { + LM_ERR("error while calculating hooks\n"); return -1; } diff --git a/src/modules/tm/dlg.h b/src/modules/tm/dlg.h index 6c00e5addeb..262f6500436 100644 --- a/src/modules/tm/dlg.h +++ b/src/modules/tm/dlg.h @@ -20,8 +20,8 @@ */ /*! - * \file - * \brief TM :: + * \file + * \brief TM :: * \ingroup tm */ @@ -53,9 +53,10 @@ /* * Dialog sequence */ -typedef struct dlg_seq { - unsigned int value; /* Sequence value */ - unsigned char is_set; /* is_set flag */ +typedef struct dlg_seq +{ + unsigned int value; /* Sequence value */ + unsigned char is_set; /* is_set flag */ } dlg_seq_t; @@ -64,7 +65,7 @@ typedef struct dlg_seq { */ 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; @@ -73,10 +74,11 @@ typedef enum dlg_state { /* * Structure describing a dialog identifier */ -typedef struct dlg_id { - str call_id; /* Call-ID */ - str rem_tag; /* Remote tag of the dialog */ - str loc_tag; /* Local tag of the dialog */ +typedef struct dlg_id +{ + str call_id; /* Call-ID */ + str rem_tag; /* Remote tag of the dialog */ + str loc_tag; /* Local tag of the dialog */ } dlg_id_t; @@ -88,37 +90,39 @@ typedef struct dlg_id { * so we don't have to calculate each time we want to send a * message within dialog */ -typedef struct dlg_hooks { +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 */ - rr_t* first_route; /* First route to be printed into the message */ - str* last_route; /* If not zero add this as the last route */ + str *request_uri; /* This should be put into Request-URI */ + 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; /* * Structure representing dialog state */ -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 */ - str loc_uri; /* Local URI */ - str rem_uri; /* Remote URI */ - str rem_target; /* Remote target URI */ - str dst_uri; /* Destination URI */ - 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 */ - rr_t* route_set; /* Route set */ - dlg_hooks_t hooks; /* Various hooks used to store information that +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 */ + str loc_uri; /* Local URI */ + str rem_uri; /* Remote URI */ + str rem_target; /* Remote target URI */ + str dst_uri; /* Destination URI */ + 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 */ + rr_t *route_set; /* Route set */ + 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 */ - struct socket_info* send_sock; + struct socket_info *send_sock; #ifdef DIALOG_CALLBACKS struct tmcb_head_list dlg_callbacks; #endif @@ -133,80 +137,86 @@ typedef enum { /* * Create a new dialog */ -int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d); -typedef int (*new_dlg_uac_f)(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d); +int new_dlg_uac(str *_cid, str *_ltag, unsigned int _lseq, str *_luri, + str *_ruri, dlg_t **_d); +typedef int (*new_dlg_uac_f)(str *_cid, str *_ltag, unsigned int _lseq, + str *_luri, str *_ruri, dlg_t **_d); /** * Function to add Display Names to an existing dialog */ -int dlg_add_extra(dlg_t* _d, str* _ldname, str* _rdname); -typedef int (*dlg_add_extra_f)(dlg_t* _d, str* _ldname, str* _rdname); +int dlg_add_extra(dlg_t *_d, str *_ldname, str *_rdname); +typedef int (*dlg_add_extra_f)(dlg_t *_d, str *_ldname, str *_rdname); /* * A response arrived, update dialog */ -int dlg_response_uac(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_refresh); -typedef int (*dlg_response_uac_f)(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_refresh); +int dlg_response_uac( + dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_refresh); +typedef int (*dlg_response_uac_f)( + dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_refresh); /* * Establishing a new dialog, UAS side */ -int new_dlg_uas(struct sip_msg* _req, int _code, /*str* _tag,*/ dlg_t** _d); -typedef int (*new_dlg_uas_f)(struct sip_msg* _req, int _code, dlg_t** _d); +int new_dlg_uas(struct sip_msg *_req, int _code, /*str* _tag,*/ dlg_t **_d); +typedef int (*new_dlg_uas_f)(struct sip_msg *_req, int _code, dlg_t **_d); /* * UAS side - update dialog state and to tag */ -int update_dlg_uas(dlg_t *_d, int _code, str* _tag); -typedef int (*update_dlg_uas_f)(dlg_t *_d, int _code, str* _tag); +int update_dlg_uas(dlg_t *_d, int _code, str *_tag); +typedef int (*update_dlg_uas_f)(dlg_t *_d, int _code, str *_tag); /* * UAS side - update a dialog from a request */ -int dlg_request_uas(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_request); -typedef int (*dlg_request_uas_f)(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_request); +int dlg_request_uas( + dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_request); +typedef int (*dlg_request_uas_f)( + dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_request); /* * Destroy a dialog state */ -void free_dlg(dlg_t* _d); -typedef void (*free_dlg_f)(dlg_t* _d); +void free_dlg(dlg_t *_d); +typedef void (*free_dlg_f)(dlg_t *_d); /* * Print a dialog structure, just for debugging */ -void print_dlg(FILE* out, dlg_t* _d); -typedef void (*print_dlg_f)(FILE* out, dlg_t* _d); +void print_dlg(FILE *out, dlg_t *_d); +typedef void (*print_dlg_f)(FILE *out, dlg_t *_d); /* * Calculate length of the route set */ -int calculate_routeset_length(dlg_t* _d); +int calculate_routeset_length(dlg_t *_d); /* * * Print the route set */ -char* print_routeset(char* buf, dlg_t* _d); +char *print_routeset(char *buf, dlg_t *_d); /* * wrapper to calculate_hooks * added by dcm */ -int w_calculate_hooks(dlg_t* _d); -typedef int (*calculate_hooks_f)(dlg_t* _d); +int w_calculate_hooks(dlg_t *_d); +typedef int (*calculate_hooks_f)(dlg_t *_d); /* * set dialog's request uri and destination uri (optional) */ -int set_dlg_target(dlg_t* _d, str* _ruri, str* _duri); -typedef int (*set_dlg_target_f)(dlg_t* _d, str* _ruri, str* _duri); +int set_dlg_target(dlg_t *_d, str *_ruri, str *_duri); +typedef int (*set_dlg_target_f)(dlg_t *_d, str *_ruri, str *_duri); #ifdef DIALOG_CALLBACKS @@ -216,21 +226,21 @@ typedef int (*set_dlg_target_f)(dlg_t* _d, str* _ruri, str* _duri); * msg - message used for creating the new dialog for the new_dlg_uas * case, 0 otherwise (new_dlg_uac) */ -typedef void (dialog_cb) (int type, dlg_t* dlg, struct sip_msg* msg); +typedef void(dialog_cb)(int type, dlg_t *dlg, struct sip_msg *msg); /* callbacks for new dialogs (called each time a new dialog (uas or uac) is * created). Can be used for installing in-dialog callbacks * returns < 0 on error*/ -int register_new_dlg_cb(int types, dialog_cb f, void* param); +int register_new_dlg_cb(int types, dialog_cb f, void *param); /* callbacks for messages sent dialogs */ -int register_dlg_tmcb(int type, dlg_t* dlg, transaction_cb f, void* param); -void run_trans_dlg_callbacks(dlg_t* dlg, struct cell* trans, - struct retr_buf* rbuf); +int register_dlg_tmcb(int type, dlg_t *dlg, transaction_cb f, void *param); +void run_trans_dlg_callbacks( + dlg_t *dlg, struct cell *trans, struct retr_buf *rbuf); /* cleanup on exit */ void destroy_new_dlg_cbs(void); -typedef int (*register_new_dlg_cb_f)(int, dialog_cb, void*); -typedef int (*register_dlg_tmcb_f)(int, dlg_t*, transaction_cb, void*); +typedef int (*register_new_dlg_cb_f)(int, dialog_cb, void *); +typedef int (*register_dlg_tmcb_f)(int, dlg_t *, transaction_cb, void *); #endif /* DIALOG_CALLBACKS */