Skip to content
33 changes: 20 additions & 13 deletions modules/presence/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,14 +1723,7 @@ int publ_notify(presentity_t* p, str pres_uri, str* body, str* offline_etag,
int ret_code= -1;
free_body_t* free_fct = 0;

subs_array= get_subs_dialog(&pres_uri, p->event , p->sender);
if(subs_array == NULL)
{
LM_DBG("Could not find subs_dialog\n");
ret_code= 0;
goto done;
}

LM_INFO("NOTIFY for uri %.*s\n", pres_uri.len, pres_uri.s);
/* if the event does not require aggregation - we have the final body */
if(p->event->agg_nbody)
{
Expand All @@ -1739,11 +1732,19 @@ int publ_notify(presentity_t* p, str pres_uri, str* body, str* offline_etag,
p->extra_hdrs?p->extra_hdrs:&notify_extra_hdrs, &free_fct);
}

subs_array= get_subs_dialog(&pres_uri, p->event , p->sender);
if(subs_array == NULL)
{
LM_DBG("Could not find subs_dialog\n");
ret_code= 0;
goto done;
}

s= subs_array;
while(s)
{
s->auth_rules_doc= rules_doc;
LM_INFO("notify\n");
LM_INFO("will notify\n");
if(notify(s, NULL, notify_body?notify_body:body,
0, p->extra_hdrs?p->extra_hdrs:&notify_extra_hdrs)< 0 )
{
Expand Down Expand Up @@ -1998,10 +1999,16 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
goto error;
}

LM_INFO("NOTIFY %.*s via %.*s on behalf of %.*s for event %.*s, to_tag=%.*s, cseq=%d\n",
td->rem_uri.len, td->rem_uri.s, td->hooks.next_hop->len, td->hooks.next_hop->s,
td->loc_uri.len, td->loc_uri.s, subs->event->name.len, subs->event->name.s,
td->id.loc_tag.len, td->id.loc_tag.s, td->loc_seq.value);
if (notify_body)
LM_INFO("NOTIFY %.*s on behalf of %.*s for event %.*s with body %s\n",
td->rem_uri.len, td->rem_uri.s,
td->loc_uri.len, td->loc_uri.s, subs->event->name.len, subs->event->name.s,
notify_body->s);
else
LM_INFO("NOTIFY %.*s ,via %.*s on behalf of %.*s for event %.*s, to_tag=%.*s, cseq=%d\n",
td->rem_uri.len, td->rem_uri.s, td->hooks.next_hop->len, td->hooks.next_hop->s,
td->loc_uri.len, td->loc_uri.s, subs->event->name.len, subs->event->name.s,
td->id.loc_tag.len, td->id.loc_tag.s, td->loc_seq.value);

free_tm_dlg(td);

Expand Down
23 changes: 12 additions & 11 deletions modules/presence/presentity.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, int* sent_r
str *extra_hdrs = presentity->extra_hdrs;
db_res_t *result= NULL;



*sent_reply= 0;
if(presentity->event->req_auth)
{
Expand Down Expand Up @@ -551,6 +553,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, int* sent_r
if(!p)
{
lock_release(&pres_htable[hash_code].lock);

/* search also in db */
if (pa_dbf.use_table(pa_db, &presentity_table) < 0)
{
Expand Down Expand Up @@ -580,7 +583,6 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, int* sent_r
goto done;
}


pa_dbf.free_result(pa_db, result);
LM_INFO("*** found in db but not in htable [%.*s]\n",
presentity->etag.len, presentity->etag.s);
Expand All @@ -603,8 +605,8 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, int* sent_r
}
*sent_reply= 1;

if(publ_notify(presentity, pres_uri, body.s ? &body : 0,
&presentity->etag, rules_doc, NULL) < 0)
if(publ_notify(presentity, pres_uri, body.s ? &body : 0, &presentity->etag,
rules_doc, NULL) < 0)
{
LM_ERR("while sending notify\n");
goto error;
Expand Down Expand Up @@ -672,12 +674,6 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, int* sent_r
(int)time(NULL);
n_update_cols++;

update_keys[n_update_cols] = &str_received_time_col;
update_vals[n_update_cols].type = DB_INT;
update_vals[n_update_cols].nul = 0;
update_vals[n_update_cols].val.int_val= presentity->received_time;
n_update_cols++;

update_keys[n_update_cols] = &str_sender_col;
update_vals[n_update_cols].type = DB_STR;
update_vals[n_update_cols].nul = 0;
Expand All @@ -702,8 +698,13 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, int* sent_r
n_update_cols++;
}

if(body.s)
{
if(body.s) {
update_keys[n_update_cols] = &str_received_time_col;
update_vals[n_update_cols].type = DB_INT;
update_vals[n_update_cols].nul = 0;
update_vals[n_update_cols].val.int_val= presentity->received_time;
n_update_cols++;

if (fix_remote_target)
{
if (dialog_fix_remote_target(&body, &notify_body)== 0)
Expand Down
14 changes: 12 additions & 2 deletions modules/presence_xml/add_events.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* $Id$
* $Id: add_events.c 8628 2011-12-19 14:20:30Z bogdan_iancu $
*
* presence_xml module -
*
Expand Down Expand Up @@ -39,6 +39,7 @@
#include "xcap_auth.h"
#include "notify_body.h"
#include "add_events.h"
#include "../presence/utils_func.h"
#include "presence_xml.h"
#include "pidf.h"

Expand All @@ -58,8 +59,17 @@ int xml_publ_handl(struct sip_msg* msg, int* sent_reply)
LM_ERR("cannot extract body from msg\n");
return -1;
}
if (body.len == 0)
if (body.len == 0) {
/* get pres_uri from Request-URI*/
if( parse_sip_msg_uri(msg)< 0)
{
LM_ERR("parsing Request URI\n");
goto error;
}
cachedb_update_merged_presence_state (&body, &msg->parsed_uri.user);

return 1;
}

doc= xmlParseMemory( body.s, body.len );
if(doc== NULL)
Expand Down
79 changes: 79 additions & 0 deletions modules/presence_xml/doc/presence_xml_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,85 @@ modparam("presence_xml", "pidf_manipulation", 1)
...
modparam("presence_xml", "integrated_xcap_server", 1)
...
</programlisting>
</example>
</section>
<section>
<title><varname>merge</varname> (int)</title>
<para>
Some presentities can publish different (R)PIDF presence documents.
In that case, the default behavior is to notify subscribers with an
aggregated presence document. However, some UAs do not support
receiving aggregated presence documents containing different presence
states and randomly choose one to display to the user. To prevent this,
it is possible to ask the presence server to merge the various presence
documents and always notify the most up to date document to the subscribers.
</para>
<para>
For example, if a UA publishes a first document valid for 60 minutes
indicating the presentity is available, and another UA publishes a second
document for the same presentity indicating it is away, subscribers will
be notified with the away state until it expires and the available state
is valid again.
</para>
<emphasis>Default value is <quote>0</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>merge</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("presence_xml", "merge", 1)
...
</programlisting>
</example>
</section>
<section>
<title><varname>merge_primary_source</varname> (str)</title>
<para>
Allows a specific presence source to have priority over others even
if it is not the last one having been published.
The <quote>merge_primary_source</quote> string needs to appear in
the tuple id for the source to be recognized as primary.
</para>
<para>
Requires the <quote>merge</quote> parameter to be set to 1.
</para>
<emphasis>Default value is <quote>primary</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>merge_primary_source</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("presence_xml", "merge_primary_source", "calendar")
...
</programlisting>
</example>
</section>
<section>
<title><varname>cachedb_url</varname> (str)</title>
<para>
Allows caching the RPIDF activities and note elements in
the cachedb database.
If there is no RPIDF, stores the basic element or
the im element values.
</para>
<para>
It allows presence based routing.
</para>
<para>
Requires the <quote>merge</quote> parameter to be set to 1.
</para>
<emphasis>Default value is <quote>empty</quote>.
</emphasis>
</para>
<example>
<title>Set <varname>cachedb_url</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("presence_xml", "cachedb_url", "db://")
...
</programlisting>
</example>
</section>
Expand Down
Loading