Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions modules/presence_dialoginfo/notify_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,33 @@ void free_xml_body(char* body)
str* dlginfo_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n, int off_index)
{
str* n_body= NULL;
str *pres_uri= NULL;
char buf[MAX_URI_SIZE+1];

LM_DBG("[pres_user]=%.*s [pres_domain]= %.*s, [n]=%d\n",
pres_user->len, pres_user->s, pres_domain->len, pres_domain->s, n);
if ( (pres_user->len + pres_domain->len + 1) > MAX_URI_SIZE) {
LM_ERR("entity URI too long, maximum=%d\n", MAX_URI_SIZE);
return NULL;
}
memcpy(buf, "sip:", 4);
memcpy(buf+4, pres_user->s, pres_user->len);
buf[pres_user->len+4] = '@';
memcpy(buf + pres_user->len + 5, pres_domain->s, pres_domain->len);
buf[pres_user->len + 5 + pres_domain->len]= '\0';

pres_uri = (str*)pkg_malloc(sizeof(str));
if(pres_uri == NULL)
{
LM_ERR("while allocating memory\n");
return NULL;
}
memset(pres_uri, 0, sizeof(str));
pres_uri->s = buf;
pres_uri->len = pres_user->len + 5 + pres_domain->len;

LM_DBG("[pres_uri] %.*s, [n]=%d\n", pres_uri->len, pres_uri->s, n);

if(body_array== NULL)
return build_dialoginfo(pres_user, pres_domain);
return build_empty_dialoginfo(pres_uri, NULL);

n_body= agregate_xmls(pres_user, pres_domain, body_array, n);
LM_DBG("[n_body]=%p\n", n_body);
Expand All @@ -81,7 +102,7 @@ str* dlginfo_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n
xmlMemoryDump();

if (n_body== NULL)
n_body= build_dialoginfo(pres_user, pres_domain);
n_body= build_empty_dialoginfo(pres_uri, NULL);
return n_body;
}

Expand Down
51 changes: 45 additions & 6 deletions modules/pua_dialoginfo/pua_dialoginfo.c
Original file line number Diff line number Diff line change
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 nopublish_flag = -1;


/** module functions */
Expand All @@ -108,10 +110,12 @@ 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_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 },
{"osips_ps", INT_PARAM, &osips_ps },
{"nopublish_flag", INT_PARAM, &nopublish_flag },
{0, 0, 0 }
};

Expand Down Expand Up @@ -241,6 +245,7 @@ __dialog_sendpublish(struct dlg_cell *dlg, int type, struct dlg_cb_params *_para
struct to_body peer_to_body;
str entity_uri= {0, 0};
int buf_len = 255;
struct sip_msg* msg = _params->msg;

flag_str.s = &flag;
flag_str.len = 1;
Expand Down Expand Up @@ -308,8 +313,15 @@ __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_RESPONSE_WITHIN:
if (get_cseq(msg)->method_id==METHOD_INVITE || get_cseq(msg)->method_id==METHOD_INVITE) {
if (msg->flags & nopublish_flag) {
LM_DBG("nopublish flag was set for this INVITE\n");
break;
}
LM_DBG("nopublish flag not set for this INVITE, will publish\n");
}
case DLGCB_CONFIRMED:
case DLGCB_REQ_WITHIN:
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 +396,20 @@ __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 (dlg_api.register_dlgcb(dlg,
DLGCB_FAILED| DLGCB_CONFIRMED | DLGCB_TERMINATED | DLGCB_EXPIRED |
DLGCB_RESPONSE_WITHIN | DLGCB_EARLY,
__dialog_sendpublish, 0, 0) != 0) {
LM_ERR("cannot register callback for interesting dialog types\n");
}
}


int dialoginfo_process_body(struct publ_info* publ, str** fin_body,
int ver, str* tuple)
{
Expand Down Expand Up @@ -469,6 +495,12 @@ static int mod_init(void)
}
pua_send_publish= pua.send_publish;

if (nopublish_flag!= -1 && nopublish_flag > MAX_FLAG) {
LM_ERR("invalid nopublish flag %d!!\n", nopublish_flag);
return -1;
}
nopublish_flag = (nopublish_flag!=-1)?(1<<nopublish_flag):0;

if(!osips_ps)
evp = dialoginfo_process_body;

Expand All @@ -484,6 +516,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 @@ -726,7 +763,7 @@ 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,
DLGCB_RESPONSE_WITHIN | DLGCB_EARLY,
__dialog_sendpublish, 0, 0) != 0) {
LM_ERR("cannot register callback for interesting dialog types\n");
goto end;
Expand All @@ -744,11 +781,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