Skip to content

Commit

Permalink
Improved PUA DialogInfo.
Browse files Browse the repository at this point in the history
Several fixes here:
  - Dialog callbacks are now correctly setup after a restart of
    OpenSIPS. In other words, restarting OpenSIPS will not lead to ghost BLFs
    anymore.
  - Added an option allowing not to publish state change in case of reINVITE.
  - Added an option allowing not to publish state change in trying state.
    In other words, a PUBLISH will be sent only when OpenSIPS has received a
    18x response type and not before.
  • Loading branch information
dsandras committed Jul 16, 2013
1 parent 34c5852 commit f7dae1d
Showing 1 changed file with 59 additions and 12 deletions.
71 changes: 59 additions & 12 deletions modules/pua_dialoginfo/pua_dialoginfo.c
Expand Up @@ -87,6 +87,8 @@ static str callee_spec_param= {0, 0};
static pv_spec_t caller_spec;
static pv_spec_t callee_spec;
static int osips_ps = 1;
static int publish_on_trying = 0;
static int publish_on_reinvite = 0;


/** module functions */
Expand All @@ -108,6 +110,8 @@ static param_export_t params[]={
{"include_localremote", INT_PARAM, &include_localremote },
{"include_tags", INT_PARAM, &include_tags },
{"caller_confirmed", INT_PARAM, &caller_confirmed },
{"publish_on_reinvite", INT_PARAM, &publish_on_reinvite },
{"publish_on_trying", INT_PARAM, &publish_on_trying },
{"presence_server", STR_PARAM, &presence_server.s },
{"caller_spec_param", STR_PARAM, &caller_spec_param.s },
{"callee_spec_param", STR_PARAM, &callee_spec_param.s },
Expand Down Expand Up @@ -308,8 +312,8 @@ __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_para
if(flag == DLG_PUB_AB || flag == DLG_PUB_B)
dialog_publish("terminated", &peer_to_body, &from, &(dlg->callid), 0, 0, 0, 0);
break;
case DLGCB_CONFIRMED:
case DLGCB_REQ_WITHIN:
case DLGCB_CONFIRMED:
LM_DBG("dialog confirmed, from=%.*s\n", dlg->from_uri.len, dlg->from_uri.s);
if(flag == DLG_PUB_AB || flag == DLG_PUB_A)
dialog_publish("confirmed", &from, &peer_to_body, &(dlg->callid), 1, dlg->lifetime, 0, 0);
Expand Down Expand Up @@ -384,6 +388,31 @@ __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_para
free_to_params(&from);
}


static void
__dialog_loaded(struct dlg_cell *dlg, int type, struct dlg_cb_params *_params)
{
/* register dialog callbacks which triggers sending PUBLISH */
if (publish_on_reinvite) {
if (dlg_api.register_dlgcb(dlg,
DLGCB_FAILED| DLGCB_CONFIRMED | DLGCB_TERMINATED | DLGCB_EXPIRED |
DLGCB_REQ_WITHIN | DLGCB_EARLY,
__dialog_sendpublish, 0, 0) != 0) {
LM_ERR("cannot register callback for interesting dialog types\n");
}
}
else {
if (dlg_api.register_dlgcb(dlg,
DLGCB_FAILED| DLGCB_CONFIRMED | DLGCB_TERMINATED | DLGCB_EXPIRED |
DLGCB_EARLY,
__dialog_sendpublish, 0, 0) != 0) {
LM_ERR("cannot register callback for interesting dialog types\n");
}
}
LM_ERR("ici: LOADED DB CB\n");
}


int dialoginfo_process_body(struct publ_info* publ, str** fin_body,
int ver, str* tuple)
{
Expand Down Expand Up @@ -484,6 +513,11 @@ static int mod_init(void)
return -1;
}

// register dialog loading callback
if (dlg_api.register_dlgcb(NULL, DLGCB_LOADED, __dialog_loaded, NULL, NULL) != 0) {
LM_CRIT("cannot register callback for dialogs loaded from the database\n");
}

if(presence_server.s)
presence_server.len = strlen(presence_server.s);

Expand Down Expand Up @@ -724,13 +758,24 @@ int dialoginfo_set(struct sip_msg* msg, char* flag_pv, char* str2)
}

/* register dialog callbacks which triggers sending PUBLISH */
if (dlg_api.register_dlgcb(dlg,
DLGCB_FAILED| DLGCB_CONFIRMED | DLGCB_TERMINATED | DLGCB_EXPIRED |
DLGCB_REQ_WITHIN | DLGCB_EARLY,
__dialog_sendpublish, 0, 0) != 0) {
LM_ERR("cannot register callback for interesting dialog types\n");
goto end;
}
if (publish_on_reinvite) {
if (dlg_api.register_dlgcb(dlg,
DLGCB_FAILED| DLGCB_CONFIRMED | DLGCB_TERMINATED | DLGCB_EXPIRED |
DLGCB_REQ_WITHIN | DLGCB_EARLY,
__dialog_sendpublish, 0, 0) != 0) {
LM_ERR("cannot register callback for interesting dialog types\n");
goto end;
}
}
else {
if (dlg_api.register_dlgcb(dlg,
DLGCB_FAILED| DLGCB_CONFIRMED | DLGCB_TERMINATED | DLGCB_EXPIRED |
DLGCB_EARLY,
__dialog_sendpublish, 0, 0) != 0) {
LM_ERR("cannot register callback for interesting dialog types\n");
goto end;
}
}

#ifdef PUA_DIALOGINFO_DEBUG
/* dialog callback testing (registered last to be executed first) */
Expand All @@ -744,11 +789,13 @@ int dialoginfo_set(struct sip_msg* msg, char* flag_pv, char* str2)
}
#endif

if(flag == DLG_PUB_A || flag == DLG_PUB_AB)
dialog_publish("trying", from, &peer_to_body, &(dlg->callid), 1, DEFAULT_CREATED_LIFETIME, 0, 0);
if(publish_on_trying) {
if(flag == DLG_PUB_A || flag == DLG_PUB_AB)
dialog_publish("trying", from, &peer_to_body, &(dlg->callid), 1, DEFAULT_CREATED_LIFETIME, 0, 0);

if(flag == DLG_PUB_B || flag == DLG_PUB_AB)
dialog_publish("trying", &peer_to_body, from, &(dlg->callid), 0, DEFAULT_CREATED_LIFETIME, 0, 0);
if(flag == DLG_PUB_B || flag == DLG_PUB_AB)
dialog_publish("trying", &peer_to_body, from, &(dlg->callid), 0, DEFAULT_CREATED_LIFETIME, 0, 0);
}

ret=1;
end:
Expand Down

0 comments on commit f7dae1d

Please sign in to comment.