// Stop the timer that will kill the read.
this.rawInputStream.stopTimer();
inputBuffer.append(line2);
// smp.setParseExceptionListener(sipMessageListener);
// smp.setReadBody(false);
SIPMessage sipMessage = null;
try {
if (stackLogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
stackLogger.logDebug("About to parse : " + inputBuffer.toString());
}
sipMessage = smp.parseSIPMessage(inputBuffer.toString().getBytes(), false, false, sipMessageListener);
if (sipMessage == null) {
this.rawInputStream.stopTimer();
continue;
}
} catch (ParseException ex) {
// Just ignore the parse exception.
stackLogger.logError("Detected a parse error", ex);
continue;
}
if (logger.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
logger.logDebug("Completed parsing message");
}
String clString = sipMessage.getHeaderAsFormattedString(ContentLength.NAME);
if(clString.length()>30) throw new RuntimeException("Bad content lenght header " + clString);
ContentLength cl = (ContentLength) sipMessage
.getContentLength();
int contentLength = 0;
if (cl != null) {
contentLength = cl.getContentLength();
} else {
contentLength = 0;
}
if (logger.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
logger.logDebug("Content length = " + contentLength);
}
if(maxMessageSize > 0 && contentLength > maxMessageSize) throw new RuntimeException("Max content size Exceeded! :" + contentLength + " allowed max size is " + maxMessageSize);
if (contentLength == 0) {
sipMessage.removeContent();
} else if (maxMessageSize == 0
|| contentLength < this.sizeCounter) {
byte[] message_body = new byte[contentLength];
int nread = 0;
while (nread < contentLength) {
// Start my starvation timer.
// This ensures that the other end
// writes at least some data in
// or we will close the pipe from
// him. This prevents DOS attack
// that takes up all our connections.
this.rawInputStream.startTimer();
try {
int readlength = inputStream.read(message_body,
nread, contentLength - nread);
if (readlength > 0) {
nread += readlength;
} else {
break;
}
} catch (IOException ex) {
stackLogger.logError("Exception Reading Content",ex);
break;
} finally {
// Stop my starvation timer.
this.rawInputStream.stopTimer();
}
}
sipMessage.setMessageContent(message_body);
}
// Content length too large - process the message and
// return error from there.
if (sipMessageListener != null) {
try {
if(postParseExecutor == null) {
/**
* If gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is disabled
* we continue with the old logic here.
*/
if(sipStack.sipEventInterceptor != null) {
sipStack.sipEventInterceptor.beforeMessage(sipMessage);
}
sipMessageListener.processMessage(sipMessage);
if(sipStack.sipEventInterceptor != null) {
sipStack.sipEventInterceptor.afterMessage(sipMessage);
}
} else {
/**
* gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is enabled so
* we use the threadpool to execute the task.
*/
// we need to guarantee message ordering on the same socket on TCP
// so we lock and queue of messages per Call Id
final String callId = sipMessage.getCallId().getCallId();
// http://dmy999.com/article/34/correct-use-of-concurrenthashmap
CallIDOrderingStructure orderingStructure = messagesOrderingMap.get(callId);
if(orderingStructure == null) {
CallIDOrderingStructure newCallIDOrderingStructure = new CallIDOrderingStructure();
orderingStructure = messagesOrderingMap.putIfAbsent(callId, newCallIDOrderingStructure);