subscribe.getApplicationSession().invalidate();
return;
}
}
RegResource regResource = _regEventPackage.get(uri);
try
{
Subscription subscription = null;
if (expires == 0)
{
subscription = regResource.removeSubscription(session.getId());
if (subscription == null)
{
subscription = new Subscription(regResource, session, -1);
}
else
{
subscription.setExpirationTime(System.currentTimeMillis());
if (_log.isDebugEnabled())
_log.debug("removed reg subscription {} to registration resource {}",
subscription.getSession().getId(), regResource.getUri());
}
subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT);
}
else
{
long now = System.currentTimeMillis();
subscription = regResource.getSubscription(session.getId());
if (subscription == null)
{
subscription = new Subscription(regResource, session, now + expires*1000);
subscription.setState(State.ACTIVE, Reason.SUBSCRIBE);
regResource.addSubscription(subscription);
session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
if (_log.isDebugEnabled())
_log.debug("added reg subscription {} to registration resource {}",
subscription.getSession().getId(), regResource.getUri());
}
else
{
subscription.setExpirationTime(now + expires * 1000);
if (_log.isDebugEnabled())
_log.debug("refreshed reg subscription {} to registration resource {}",
subscription.getSession().getId(), regResource.getUri());
}
}
int code = (subscription.getState() != Subscription.State.PENDING) ?
SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;