diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-12-17 03:44:30 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-12-17 03:44:30 +0000 |
commit | 32a7ac32d8cdd2965a007a5663bc835d53845898 (patch) | |
tree | 0053e221cd87012d5da231dd42aa160a3167970a /channels | |
parent | b2ae1ff0065a3ac525f9bc01546c0b4fa3ec42cf (diff) |
forcibly expire previous subscriptions from a peer when they resubscribe (keeps them from building up and waiting for expiration, and stops us sending unwanted NOTIFY messages to devices)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2@7513 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_sip.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 5824cc054..ce642fff7 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -10793,12 +10793,40 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, ast_set_flag(p, SIP_NEEDDESTROY); return 0; } else { + struct sip_pvt *p_old; + transmit_response(p, "200 OK", req); transmit_state_notify(p, firststate, 1, 1); /* Send first notification */ append_history(p, "Subscribestatus", ast_extension_state2str(firststate)); + + /* remove any old subscription from this peer for the same exten/context, + as the peer has obviously forgotten about it and it's wasteful to wait + for it to expire and send NOTIFY messages to the peer only to have them + ignored (or generate errors) + */ + ast_mutex_lock(&iflock); + for (p_old = iflist; p_old; p_old = p_old->next) { + if (p_old == p) + continue; + if (p_old->initreq.method != SIP_SUBSCRIBE) + continue; + if (p_old->subscribed == NONE) + continue; + ast_mutex_lock(&p_old->lock); + if (!strcmp(p_old->username, p->username)) { + if (!strcmp(p_old->exten, p->exten) && + !strcmp(p_old->context, p->context)) { + ast_set_flag(p_old, SIP_NEEDDESTROY); + ast_mutex_unlock(&p_old->lock); + break; + } + } + ast_mutex_unlock(&p_old->lock); + } + ast_mutex_unlock(&iflock); } if (!p->expiry) - ast_set_flag(p, SIP_NEEDDESTROY); + ast_set_flag(p, SIP_NEEDDESTROY); } return 1; } |