boolean invokeNextFilter = true;
final WorkerThread workerThread =
((WorkerThread) Thread.currentThread());
ByteBuffer buffer = workerThread.getByteBuffer();
SipParser _parser = SipParser.getInstance();
final Protocol prot = ctx.getProtocol();
final SelectionKey key = ctx.getSelectionKey();
final SelectorHandler handler = ctx.getSelectorHandler();
final ThreadAttachment currentTA = workerThread.getAttachment();
TargetTuple remote = null;
InetSocketAddress local = null;
X509Certificate[] x509Certs = null;
switch (prot) {
case TCP:
s = ((SocketChannel) key.channel()).socket();
remoteAddress = (InetSocketAddress) s.getRemoteSocketAddress();
remote = new TargetTuple(SipTransports.TCP_PROT, remoteAddress);
local = (InetSocketAddress) s.getLocalSocketAddress();
break;
case UDP:
if (!GrizzlyNetworkManager.useDefaultUDPSelectorHandler){
buffer = (ByteBuffer) ctx.removeAttribute
(GrizzlyNetworkManager.UDP_BUFFER);
} else {
ctx.setKeyRegistrationState(Context.KeyRegistrationState.NONE);
handler.register(key, SelectionKey.OP_READ);
}
DatagramSocket d = ((DatagramChannel) key.channel()).socket();
remoteAddress =
(InetSocketAddress) ctx.getAttribute(ReadFilter.UDP_SOCKETADDRESS);
remote = new TargetTuple(SipTransports.UDP_PROT, remoteAddress);
local = (InetSocketAddress) d.getLocalSocketAddress();
break;
case TLS:
s = ((SocketChannel) key.channel()).socket();
remoteAddress = (InetSocketAddress) s.getRemoteSocketAddress();
remote = new TargetTuple(SipTransports.TLS_PROT, remoteAddress);
local = (InetSocketAddress) s.getLocalSocketAddress();
Object[] certs =
(Object[]) ctx.removeAttribute(GrizzlyNetworkManager.SIP_CERTS);
if ((certs != null) && (certs.length > 0)) {
ArrayList<X509Certificate> al =
new ArrayList<X509Certificate>();
for (int i = 0; i < certs.length; i++) {
if (certs[i] instanceof X509Certificate) {
al.add((X509Certificate) certs[i]);
} else {
logger.log(Level.WARNING,
"sip.network.grizzly.wrong.certs",
new Object[]{certs[i].getClass()});
}
}
x509Certs = al.toArray(new X509Certificate[al.size()]);
}
break;
}
try {
int initialSize = 0;
buffer.flip();
int remaining = buffer.remaining();
while (((remaining > 0) && (initialSize != remaining)) ||
(parsedMessage == null)) {
initialSize = remaining;
if (_message == null) {
skipNewLines(buffer);
}
if (!buffer.hasRemaining()) {
return invokeNextFilter;
}
parsedMessage = _parser.parseMessage(_message, buffer, local,
remote, null);
remaining = buffer.remaining();
if ((parsedMessage != null) &&
parsedMessage.isMessageComplete() && remaining > 0) {