Skip to content

Commit

Permalink
presence_dialoginfo : optionally send dummy dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
lazedo committed Jan 28, 2015
1 parent 723540b commit 5c9b3af
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
25 changes: 25 additions & 0 deletions modules/presence_dialoginfo/doc/presence_dialoginfo_admin.xml
Expand Up @@ -223,6 +223,31 @@ modparam("presence_dialoginfo", "force_single_dialog", 1)
</example>
</section>

<section>
<title><varname>force_dummy_dialog</varname> (int)</title>
<para>
By default the module returns null body
if there are no bodies to aggregate.
some sip clients like Bria expect at least one dialog.
you can activate this parameter to send a dummy dialog.
</para>
<para>
If this parameter is set and there are no dialog bodies to aggregate,
it will return a dummy dialog.
</para>
<para>
<emphasis>Default value is <quote>0</quote>.</emphasis>
</para>
<example>
<title>Set <varname></varname> parameter</title>
<programlisting format="linespecific">
...
modparam("presence_dialoginfo", "force_dummy_dialog", 1)
...
</programlisting>
</example>
</section>

</section>

<section>
Expand Down
47 changes: 46 additions & 1 deletion modules/presence_dialoginfo/notify_body.c
Expand Up @@ -56,6 +56,7 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n);
int check_relevant_state (xmlChar * dialog_id, xmlDocPtr * xml_array, int total_nodes);

extern int force_single_dialog;
extern int force_dummy_dialog;

void free_xml_body(char* body)
{
Expand All @@ -66,6 +67,47 @@ void free_xml_body(char* body)
body= NULL;
}

#define DIALOGINFO_EMPTY_BODY "<dialog-info>\
<dialog direction=\"recipient\">\
<state>terminated</state>\
</dialog>\
</dialog-info>"

#define DIALOGINFO_EMPTY_BODY_SIZE 512

str* dlginfo_agg_nbody_empty(str* pres_user, str* pres_domain)
{
str* n_body= NULL;

LM_DBG("creating empty dialog for [pres_user]=%.*s [pres_domain]= %.*s\n",
pres_user->len, pres_user->s, pres_domain->len, pres_domain->s);

str* body_array = (str*)pkg_malloc(sizeof(str));
char* body = (char*)pkg_malloc(DIALOGINFO_EMPTY_BODY_SIZE);
sprintf(body, DIALOGINFO_EMPTY_BODY);//, pres_user->len, pres_user->s, pres_domain->len, pres_domain->s);
body_array->s = body;
body_array->len = strlen(body);


n_body= agregate_xmls(pres_user, pres_domain, &body_array, 1);
LM_DBG("[n_body]=%p\n", n_body);
if(n_body) {
LM_DBG("[*n_body]=%.*s\n",n_body->len, n_body->s);
}
if(n_body== NULL)
{
LM_ERR("while aggregating body\n");
}

pkg_free(body);
pkg_free(body_array);


xmlCleanupParser();
xmlMemoryDump();

return n_body;
}

str* dlginfo_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n, int off_index)
{
Expand All @@ -74,9 +116,12 @@ str* dlginfo_agg_nbody(str* pres_user, str* pres_domain, str** body_array, int n
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(body_array== NULL)
if(body_array== NULL && (!force_dummy_dialog))
return NULL;

if(body_array== NULL)
return dlginfo_agg_nbody_empty(pres_user, pres_domain);

n_body= agregate_xmls(pres_user, pres_domain, body_array, n);
LM_DBG("[n_body]=%p\n", n_body);
if(n_body) {
Expand Down
2 changes: 2 additions & 0 deletions modules/presence_dialoginfo/presence_dialoginfo.c
Expand Up @@ -51,6 +51,7 @@ add_event_t pres_add_event;

/* module parameters */
int force_single_dialog = 0;
int force_dummy_dialog = 0;

/* module exported commands */
static cmd_export_t cmds[] =
Expand All @@ -61,6 +62,7 @@ static cmd_export_t cmds[] =
/* module exported paramaters */
static param_export_t params[] = {
{ "force_single_dialog", INT_PARAM, &force_single_dialog },
{ "force_dummy_dialog", INT_PARAM, &force_dummy_dialog },
{0, 0, 0}
};

Expand Down

0 comments on commit 5c9b3af

Please sign in to comment.