Skip to content

Commit

Permalink
Merge pull request #917 from kamailio/cchance/presence
Browse files Browse the repository at this point in the history
presence: delay aux_body_processing until after subscription has been updated
  • Loading branch information
charlesrchance committed Jan 9, 2017
2 parents 0b4c045 + b429f62 commit 2c1a3d1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
42 changes: 27 additions & 15 deletions src/modules/presence/notify.c
Expand Up @@ -1278,7 +1278,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender)

int publ_notify(presentity_t* p, str pres_uri, str* body, str* offline_etag, str* rules_doc)
{
str *notify_body = NULL, *aux_body = NULL;
str *notify_body = NULL;
subs_t* subs_array= NULL, *s= NULL;
int ret_code= -1;

Expand All @@ -1305,22 +1305,13 @@ int publ_notify(presentity_t* p, str pres_uri, str* body, str* offline_etag, str
while(s)
{
s->auth_rules_doc= rules_doc;
if (p->event->aux_body_processing) {
aux_body = p->event->aux_body_processing(s, notify_body?notify_body:body);
}

if(notify(s, NULL, aux_body?aux_body:(notify_body?notify_body:body), 0)< 0 )
if(notify(s, NULL, notify_body?notify_body:body, 0, p->event->aux_body_processing)< 0 )
{
LM_ERR("Could not send notify for %.*s\n",
p->event->name.len, p->event->name.s);
}

if(aux_body!=NULL) {
if(aux_body->s) {
p->event->aux_free_body(aux_body->s);
}
pkg_free(aux_body);
}
s= s->next;
}
ret_code= 0;
Expand Down Expand Up @@ -1468,7 +1459,7 @@ int query_db_notify(str* pres_uri, pres_ev_t* event, subs_t* watcher_subs )
aux_body = event->aux_body_processing(s, notify_body);
}

if(notify(s, watcher_subs, aux_body?aux_body:notify_body, 0)< 0 )
if(notify(s, watcher_subs, aux_body?aux_body:notify_body, 0, 0)< 0 )
{
LM_ERR("Could not send notify for [event]=%.*s\n",
event->name.len, event->name.s);
Expand Down Expand Up @@ -1681,8 +1672,11 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
}


int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body)
int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body, aux_body_processing_t* aux_body_processing)
{

str* aux_body = NULL;

/* update first in hash table and the send Notify */
if(subs->expires!= 0 && subs->status != TERMINATED_STATUS)
{
Expand Down Expand Up @@ -1719,11 +1713,29 @@ int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body)
force_null_body = 1;
}

if(send_notify_request(subs, watcher_subs, n_body, force_null_body)< 0)
if (!force_null_body && aux_body_processing)
{
aux_body = aux_body_processing(subs, n_body);
}

if(send_notify_request(subs, watcher_subs, aux_body?aux_body:n_body, force_null_body)< 0)
{
LM_ERR("sending Notify not successful\n");
if(aux_body!=NULL) {
if(aux_body->s) {
subs->event->aux_free_body(aux_body->s);
}
pkg_free(aux_body);
}
return -1;
}

if(aux_body!=NULL) {
if(aux_body->s) {
subs->event->aux_free_body(aux_body->s);
}
pkg_free(aux_body);
}
return 0;
}

Expand Down Expand Up @@ -2745,7 +2757,7 @@ static int notifier_notify(subs_t *sub, int *updated, int *end_transaction)
goto done;
}

if (notify(sub, NULL, nbody, 0) < 0)
if (notify(sub, NULL, nbody, 0, 0) < 0)
{
LM_ERR("could not send notify\n");
goto error;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/presence/notify.h
Expand Up @@ -116,7 +116,7 @@ int publ_notify_notifier(str pres_uri, pres_ev_t *event);
int set_updated(subs_t *sub);
int set_wipeer_subs_updated(str *pres_uri, pres_ev_t *event, int full);

int notify(subs_t* subs, subs_t* watcher_subs, str* n_body,int force_null_body);
int notify(subs_t* subs, subs_t* watcher_subs, str* n_body,int force_null_body, aux_body_processing_t* aux_body_processing);

int send_notify_request(subs_t* subs, subs_t * watcher_subs,
str* n_body,int force_null_body);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/presence/presence.c
Expand Up @@ -1032,7 +1032,7 @@ int update_watchers_status(str pres_uri, pres_ev_t* ev, str* rules_doc)

while(s)
{
if(notify(s, NULL, NULL, 0)< 0)
if(notify(s, NULL, NULL, 0, 0)< 0)
{
LM_ERR( "sending Notify request\n");
goto done;
Expand Down
8 changes: 4 additions & 4 deletions src/modules/presence/subscribe.c
Expand Up @@ -610,7 +610,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int to_tag_gen,
*sent_reply= 1;
}

if(notify(subs, NULL, NULL, 0)< 0)
if(notify(subs, NULL, NULL, 0, 0)< 0)
{
LM_ERR("Could not send notify\n");
goto error;
Expand Down Expand Up @@ -697,7 +697,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int to_tag_gen,
}
if(subs->send_on_cback== 0)
{
if(notify(subs, NULL, NULL, 0)< 0)
if(notify(subs, NULL, NULL, 0, 0)< 0)
{
LM_ERR("Could not send notify\n");
goto error;
Expand All @@ -706,7 +706,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int to_tag_gen,
}
else
{
if(send_fast_notify && (notify(subs, NULL, NULL, 0)< 0))
if(send_fast_notify && (notify(subs, NULL, NULL, 0, 0)< 0))
{
LM_ERR("Could not send notify\n");
goto error;
Expand All @@ -724,7 +724,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, int to_tag_gen,
}
*sent_reply= 1;

if(send_fast_notify && (notify(subs, NULL, NULL, 0 )< 0))
if(send_fast_notify && (notify(subs, NULL, NULL, 0, 0)< 0))
{
LM_ERR("sending notify request\n");
goto error;
Expand Down

0 comments on commit 2c1a3d1

Please sign in to comment.