response.addHeader(Constants.MIN_EXPIRES, Integer.toString(_minExpires));
response.send();
return;
}
}
Binding binding = null;
for (int i = 0; i < bindings.size() && binding == null; i++)
{
binding = bindings.get(i);
if (!contact.getURI().equals(binding.getContact()))
binding = null;
}
if (binding != null)
{
if (callId.equals(binding.getCallId()) && cseq < binding.getCSeq())
{
_log.debug("Got lower CSeq for aor {} and call-ID {}", aor, binding.getCallId());
register.createResponse(SipServletResponse.SC_SERVER_INTERNAL_ERROR, "Lower CSeq").send();
return;
}
if (expires == 0)
{
if (_log.isDebugEnabled())
_log.debug("removing binding {} for aor {}", binding, aor);
record.removeBinding(binding);
}
else
{
if (_log.isDebugEnabled())
_log.debug("updating binding {} for aor {}", binding, aor);
record.updateBinding(binding, contact.getURI(), callId, cseq, now + expires*1000);
}
}
if (binding == null && expires != 0)
{
binding = new Binding(contact.getURI(), callId, cseq, now + expires*1000);
if (_log.isDebugEnabled())
_log.debug("adding binding {} to aor {}", binding, aor);
record.addBinding(binding);
}
}
}
bindings = record.getBindings();
}
}
finally
{
_locationService.put(record);
}
SipServletResponse ok = register.createResponse(SipServletResponse.SC_OK);
ok.addHeader(Constants.DATE, _dateFormat.format(new Date(now)));
if (bindings != null)
{
for (Binding binding : bindings)
{
Address address = _sipFactory.createAddress(binding.getContact());
address.setExpires((int) ((binding.getExpirationTime() - now) / 1000));
ok.addAddressHeader(Constants.CONTACT, address,false);
}
}
ok.send();
}