Skip to content

Commit

Permalink
For db_extra & db_extra_bye params, create dummy SIP message in case …
Browse files Browse the repository at this point in the history
…we have NULL msg, in order to allow the evaluation of PVARs that don't actually need the SIP msg ( eg. $DLG_end_reason )
  • Loading branch information
vladpaiu committed Dec 2, 2013
1 parent c631abc commit 11e393a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
29 changes: 20 additions & 9 deletions modules/acc/acc_extra.c
Expand Up @@ -281,22 +281,31 @@ int extra2strar( struct acc_extra *extra, struct sip_msg *rq,
pv_value_t value;
int n;
int r;
static struct sip_msg *req;

if (idx < 0 || idx > MAX_ACC_BUFS-2 /* last one is for legs */) {
LM_ERR("Invalid buffer index %d - maximum %d\n", idx, MAX_ACC_BUFS-2);
return 0;
}

if (!rq) {
/* no SIP message - probably internally terminated dialog
just nullify everything and skip them */
for (n=0; extra ; extra=extra->next,n++) {
val_arr[n].s = 0;
val_arr[n].len = 0;

if(rq == NULL) {
if (req == NULL) {
req = (struct sip_msg*)pkg_malloc(sizeof(struct sip_msg));
if(req == NULL)
{
LM_ERR("No more memory\n");
return -1;
}
memset(req, 0, sizeof(struct sip_msg));
req->first_line.type = SIP_REQUEST;
req->first_line.u.request.method.s= "DUMMY";
req->first_line.u.request.method.len= 5;
req->first_line.u.request.uri.s= "sip:user@domain.com";
req->first_line.u.request.uri.len= 19;
}
return n;
rq = req;
}

for( n=0,r=0 ; extra ; extra=extra->next,n++) {
/* get the value */
if (extra->use_rpl) {
Expand Down Expand Up @@ -341,6 +350,8 @@ int extra2strar( struct acc_extra *extra, struct sip_msg *rq,
}

done:
if (rq == req)
free_sip_msg(req);
return n;
}

Expand Down
5 changes: 3 additions & 2 deletions modules/dialog/dialog.c
Expand Up @@ -1490,11 +1490,12 @@ int pv_get_dlg_end_reason(struct sip_msg *msg, pv_param_t *param, pv_value_t *re
{
struct dlg_cell *dlg;

if(msg==NULL || res==NULL)
if(res==NULL)
return -1;

if ( (dlg=get_current_dialog())==NULL || dlg->terminate_reason.s == NULL)
if ( (dlg=get_current_dialog())==NULL || dlg->terminate_reason.s == NULL) {
return pv_get_null( msg, param, res);
}

res->rs = dlg->terminate_reason;
res->flags = PV_VAL_STR;
Expand Down
9 changes: 6 additions & 3 deletions modules/dialog/dlg_hash.c
Expand Up @@ -88,15 +88,18 @@ int dialog_cleanup( struct sip_msg *msg, void *param )
struct dlg_cell *get_current_dialog(void)
{
struct cell *trans;

if (route_type==REQUEST_ROUTE || route_type==LOCAL_ROUTE) {
/* use the per-process static holder */
return current_dlg_pointer;
} else {
/* use current transaction to get dialog */
trans = d_tmb.t_gett();
if (trans==NULL || trans==T_UNDEFINED)
return NULL;
if (trans==NULL || trans==T_UNDEFINED) {
/* no transaction - perhaps internally terminated
dialog - trust the module */
return current_dlg_pointer;
}
return (struct dlg_cell*)trans->dialog_ctx;
}
}
Expand Down
6 changes: 6 additions & 0 deletions modules/dialog/dlg_req_within.c
Expand Up @@ -210,6 +210,7 @@ dlg_t * build_dialog_info(struct dlg_cell * cell, int dst_leg, int src_leg)
static void dual_bye_event(struct dlg_cell* dlg, struct sip_msg *req, int extra_unref)
{
int event, old_state, new_state, unref, ret;
struct dlg_cell *curr;

event = DLG_EVENT_REQBYE;
last_dst_leg = dlg->legs_no[DLG_LEG_200OK];
Expand Down Expand Up @@ -249,8 +250,11 @@ static void dual_bye_event(struct dlg_cell* dlg, struct sip_msg *req, int extra_
unref++;
}

curr = current_dlg_pointer;
current_dlg_pointer = dlg;
/* dialog terminated (BYE) */
run_dlg_callbacks( DLGCB_TERMINATED, dlg, req, DLG_DIR_NONE, 0);
current_dlg_pointer = curr;

LM_DBG("first final reply\n");
/* derefering the dialog */
Expand Down Expand Up @@ -285,6 +289,8 @@ void bye_reply_cb(struct cell* t, int type, struct tmcb_params* ps)
}

LM_DBG("receiving a final reply %d\n",ps->code);
/* mark the transaction as belonging to this dialog */
t->dialog_ctx = *(ps->param);

dual_bye_event( (struct dlg_cell *)(*(ps->param)), ps->req, 1);
}
Expand Down

0 comments on commit 11e393a

Please sign in to comment.