Commit 9a17b691 authored by Pekka Pessi's avatar Pekka Pessi

nea_server.c: avoid raporting un-SUBSCRIBE twice

darcs-hash:20071012183802-88462-98f20e3982fd314659b21634def2943853113ccf.gz
parent ba7a2c09
......@@ -201,6 +201,8 @@ struct nea_sub_s {
sip_content_type_t *s_content_type; /** Content-Type of SUBSCRIBE body. */
sip_payload_t *s_payload; /**< Body of SUBSCRIBE. */
unsigned s_reported :1 ; /**< Made watcher report upon un-SUBSCRIBE */
unsigned s_processing : 1;
unsigned s_rejected : 1;
unsigned s_pending_flush : 1;
......@@ -1384,14 +1386,18 @@ static
int nes_watcher_callback(nea_server_t *nes,
nea_event_t *ev,
nea_sub_t *s,
sip_t const *sip)
sip_t const *sip,
sip_time_t now)
{
if (!nes->nes_in_callback) {
nes->nes_in_callback = 1;
if (ev->ev_callback) {
if (ev->ev_callback && !s->s_reported) {
nea_subnode_t sn[1];
nea_subnode_init(sn, s, sip_now());
nea_subnode_init(sn, s, now);
if (sn->sn_expires == 0 || sn->sn_state == nea_terminated)
s->s_reported = 1;
ev->ev_callback(nes, ev->ev_magic, ev, sn, sip);
}
......@@ -1908,13 +1914,15 @@ int nea_sub_process_subscribe(nea_sub_t *s,
}
/* Callback for checking subscriber authorization */
if (nes_watcher_callback(nes, ev, s, sip) < 0) {
if (nes_watcher_callback(nes, ev, s, sip, now) < 0) {
if (irq) {
nta_incoming_treply(irq, SIP_503_SERVICE_UNAVAILABLE, TAG_END());
nta_incoming_destroy(irq);
}
return -1;
}
evv = s->s_view; /* Callback can change event view */
......@@ -1975,7 +1983,7 @@ int nea_sub_notify(nea_server_t *nes, nea_sub_t *s,
{
int notified = 0;
ta_list ta;
int subscription_state_change = now == 0;
int suppress = now != 0;
nea_event_t *ev = s->s_event;
nea_state_t substate = s->s_state;
......@@ -1990,7 +1998,7 @@ int nea_sub_notify(nea_server_t *nes, nea_sub_t *s,
assert(s->s_view); assert(ev);
if (!subscription_state_change && s->s_view->evv_updated == s->s_updated)
if (suppress && s->s_view->evv_updated == s->s_updated)
return 0;
if (now == 0)
......@@ -2069,7 +2077,7 @@ int nea_sub_notify(nea_server_t *nes, nea_sub_t *s,
break;
}
subscription_state_change = (s->s_view->evv_updated == s->s_updated);
suppress = (s->s_view->evv_updated == s->s_updated);
n_evq = evq->evq_payload ? evq : evv->evv_primary->evv_head;
......@@ -2083,9 +2091,9 @@ int nea_sub_notify(nea_server_t *nes, nea_sub_t *s,
SIPTAG_USER_AGENT_STR(nes->nes_server),
SIPTAG_CONTACT(s->s_local),
SIPTAG_EVENT(s->s_id),
TAG_IF(!subscription_state_change,
TAG_IF(!suppress,
SIPTAG_CONTENT_TYPE(n_evq->evq_content_type)),
TAG_IF(!subscription_state_change,
TAG_IF(!suppress,
SIPTAG_PAYLOAD(n_evq->evq_payload)),
ta_tags(ta));
......@@ -2104,7 +2112,7 @@ int nea_sub_notify(nea_server_t *nes, nea_sub_t *s,
if (callback == NULL) {
nta_outgoing_destroy(s->s_oreq), s->s_oreq = NULL;
/* Inform the application of a subscriber leaving the subscription. */
nes_watcher_callback(nes, ev, s, NULL);
nes_watcher_callback(nes, ev, s, NULL, now);
}
}
ta_end(ta);
......@@ -2127,6 +2135,7 @@ int response_to_notify(nea_sub_t *s,
{
nea_server_t *nes = s->s_nes;
int status = sip->sip_status->st_status;
sip_time_t now = sip_now();
if (status < 200)
return 0;
......@@ -2135,8 +2144,6 @@ int response_to_notify(nea_sub_t *s,
if (status < 300) {
if (s->s_view->evv_updated != s->s_updated) {
sip_time_t now = sip_now();
if (s->s_notified + s->s_throttle <= now)
nea_sub_notify(nes, s, now, TAG_END());
else
......@@ -2148,7 +2155,7 @@ int response_to_notify(nea_sub_t *s,
SU_DEBUG_5(("nea_server: removing subscriber " URL_PRINT_FORMAT "\n",
URL_PRINT_ARGS(s->s_from->a_url)));
/* Inform the application of a subscriber leaving the subscription. */
nes_watcher_callback(nes, s->s_event, s, NULL);
nes_watcher_callback(nes, s->s_event, s, NULL, now);
}
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment