+ peerAddress.getHostAddress() + "/"
+ packet.getPort() + " Length = " + packetLength);
}
SIPMessage sipMessage = null;
try {
this.receptionTime = System.currentTimeMillis();
sipMessage = myParser.parseSIPMessage(msgBytes, true, false, this);
// myParser = null;
} catch (ParseException ex) {
// myParser = null; // let go of the parser reference.
if (sipStack.isLoggingEnabled()) {
this.sipStack.getStackLogger().logDebug("Rejecting message ! "
+ new String(msgBytes));
this.sipStack.getStackLogger().logDebug("error message "
+ ex.getMessage());
this.sipStack.getStackLogger().logException(ex);
}
// JvB: send a 400 response for requests (except ACK)
// Currently only UDP, @todo also other transports
String msgString = new String(msgBytes, 0, packetLength);
if (!msgString.startsWith("SIP/") && !msgString.startsWith("ACK ")) {
String badReqRes = createBadReqRes(msgString, ex);
if (badReqRes != null) {
if (sipStack.isLoggingEnabled()) {
sipStack.getStackLogger().logDebug(
"Sending automatic 400 Bad Request:");
sipStack.getStackLogger().logDebug(badReqRes);
}
try {
this.sendMessage(badReqRes.getBytes(), peerAddress,
packet.getPort(), "UDP", false);
} catch (IOException e) {
this.sipStack.getStackLogger().logException(e);
}
} else {
if (sipStack.isLoggingEnabled()) {
sipStack
.getStackLogger()
.logDebug(
"Could not formulate automatic 400 Bad Request");
}
}
}
return;
}
// No parse exception but null message - reject it and
// march on (or return).
// exit this message processor if the message did not parse.
if (sipMessage == null) {
if (sipStack.isLoggingEnabled()) {
this.sipStack.getStackLogger().logDebug("Rejecting message ! + Null message parsed.");
}
String key = packet.getAddress().getHostAddress() + ":" + packet.getPort();
if (pingBackRecord.get(key) == null && sipStack.getMinKeepAliveInterval() > 0) {
byte[] retval = "\r\n\r\n".getBytes();
DatagramPacket keepalive = new DatagramPacket(retval,0,retval.length,packet.getAddress(),packet.getPort());
PingBackTimerTask task = new PingBackTimerTask(packet.getAddress().getHostAddress(),
packet.getPort());
this.pingBackRecord.put(key, task);
this.sipStack.getTimer().schedule(task, sipStack.getMinKeepAliveInterval() * 1000);
((UDPMessageProcessor)this.messageProcessor).sock.send(keepalive);
} else {
sipStack.getStackLogger().logDebug("Not sending ping back");
}
return;
}
Via topMostVia = sipMessage.getTopmostVia();
// Check for the required headers.
if (sipMessage.getFrom() == null || sipMessage.getTo() == null
|| sipMessage.getCallId() == null
|| sipMessage.getCSeq() == null
|| topMostVia == null) {
String badmsg = new String(msgBytes);
if (sipStack.isLoggingEnabled()) {
this.sipStack.getStackLogger().logError("bad message " + badmsg);
this.sipStack.getStackLogger().logError(">>> Dropped Bad Msg "
+ "From = " + sipMessage.getFrom() + "To = "
+ sipMessage.getTo() + "CallId = "
+ sipMessage.getCallId() + "CSeq = "
+ sipMessage.getCSeq() + "Via = "
+ sipMessage.getViaHeaders());
}
return;
}
// For a request first via header tells where the message
// is coming from.