Skip to content

Commit

Permalink
dialog: Enhance DLGCB_RESPONSE_FWDED to include callee leg index
Browse files Browse the repository at this point in the history
The "callee leg index" is very difficult to compute from outside dialog,
given the fact that SIP replies arrive randomly (think parallel forked
branches) or even in random counts (e.g. extra legs from downstream).

This patch simply exposes the dialog-determined callee leg index as the
(long)params->dlg_data value, to be used by other modules.
  • Loading branch information
liviuchircu committed Nov 23, 2022
1 parent e3c74a3 commit 236b294
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion modules/dialog/dlg_cb.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ typedef int (*register_dlgcb_f)(struct dlg_cell* dlg, int cb_types,
#define DLGCB_EARLY (1<<7)

/*
* Gives access to all actually-received-from-the-network, non-100 replies
* Gives access to all replies (except 100 Trying and internal 408 Timeout)
* to the initial INVITE of the current dialog which are to be forwarded
* upstream. The decision to forward these replies has already been made
* and this is a last chance to alter their contents before they end up on
* the network.
*
* Params:
* - (long)params->dlg_data will hold the callee leg index (including legs
* from parallel forking or extra downstream legs), or -1 on a local reply
*
* SIP signaling: initial INVITE
* Registration: per-dialog, "dlg" must be given
* Trigger count: 0 - N times per dialog (e.g. this callback will not be
Expand Down
12 changes: 8 additions & 4 deletions modules/dialog/dlg_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static inline void dlg_release_cloned_leg(struct dlg_cell *dlg)
}

static inline void push_reply_in_dialog(struct sip_msg *rpl, struct cell* t,
struct dlg_cell *dlg,str *mangled_from,str *mangled_to)
struct dlg_cell *dlg,str *mangled_from,str *mangled_to, long *leg_idx)
{
str tag,contact,rr_set;
unsigned int skip_rrs, cseq_no;
Expand Down Expand Up @@ -424,6 +424,7 @@ static inline void push_reply_in_dialog(struct sip_msg *rpl, struct cell* t,
* false positivie - when tag.s = NULL, len is 0 - CID #40640 */
if ( dlg->legs[leg].tag.len==tag.len &&
strncmp(dlg->legs[leg].tag.s,tag.s,tag.len)==0 ) {
*leg_idx = leg;
/* we have a match -> branch already known... */
LM_DBG("branch with tag <%.*s> already exists\n",tag.len,tag.s);
goto routing_info;
Expand All @@ -442,9 +443,11 @@ static inline void push_reply_in_dialog(struct sip_msg *rpl, struct cell* t,
}
}

*leg_idx = leg;

/* save callee's tag and cseq */
LM_DBG("new branch with tag <%.*s>, leg_idx=%d\n", tag.len, tag.s, leg);
if (update_leg_info(leg, dlg, rpl, &tag,extract_mangled_fromuri(mangled_from),
if (update_leg_info(leg, dlg, rpl, &tag, extract_mangled_fromuri(mangled_from),
extract_mangled_touri(mangled_to)) !=0) {
LM_ERR("could not add further info to the dialog\n");
dlg_release_cloned_leg(dlg);
Expand Down Expand Up @@ -518,6 +521,7 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
req = param->req;

if (type==TMCB_RESPONSE_FWDED) {
long leg_idx = -1;
/* this callback is under transaction lock (by TM), so it is save
to operate at write level, but we need to take care on write-read
conflicts -bogdan */
Expand All @@ -540,13 +544,13 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
LM_CRIT("extract_ftc_hdrs ok but no to extracted : [%.*s]\n",req_out_buff->len,req_out_buff->s);
}
}
push_reply_in_dialog( rpl, t, dlg,&mangled_from,&mangled_to);
push_reply_in_dialog( rpl, t, dlg,&mangled_from,&mangled_to, &leg_idx);
} else {
LM_DBG("dialog replied from script - cannot get callee info\n");
}
/* The state does not change, but the msg is mutable in this callback*/
run_dlg_callbacks(DLGCB_RESPONSE_FWDED, dlg, rpl,
DLG_DIR_UPSTREAM, NULL, 0, 1);
DLG_DIR_UPSTREAM, (void *)leg_idx, 0, 1);
return;
}
if (type==TMCB_TRANS_CANCELLED) {
Expand Down

0 comments on commit 236b294

Please sign in to comment.