if (optBody!=null)
{
optStat=200;
// add capabilities to msg to be sent
printLog("OPTION Request - response status="+optStat , LogLevel.HIGH);
TransactionServer ts=new TransactionServer(this,msg,null);
ts.respondWith(MessageFactory.createResponse(msg,optStat,SipResponses.reasonOf(optStat),null,null,"application/sdp",optBody));
return;
}
}
else
optStat=200; // assume available if no option handler
}
printLog("OPTION Request - response status="+optStat,LogLevel.MEDIUM );
TransactionServer ts=new TransactionServer(this,msg,null);
ts.respondWith(MessageFactory.createResponse(msg,optStat,SipResponses.reasonOf(optStat),null));
return;
}
// try to look for a transaction
Identifier key=msg.getTransactionId();
printLog("DEBUG: transaction-id: "+key,LogLevel.MEDIUM);
if (listeners.containsKey(key))
{ printLog("message passed to transaction: "+key,LogLevel.MEDIUM);
((SipProviderListener)listeners.get(key)).onReceivedMessage(this,msg);
return;
}
// try to look for a dialog
key=msg.getDialogId();
printLog("DEBUG: dialog-id: "+key,LogLevel.MEDIUM);
if (listeners.containsKey(key))
{ printLog("message passed to dialog: "+key,LogLevel.MEDIUM);
((SipProviderListener)listeners.get(key)).onReceivedMessage(this,msg);
return;
}
// try to look for a UAS
key=msg.getMethodId();
if (msg.isRequest() && msg.isInvite())
{
// need to synchronize invite requests to avoid issues
synchronized (inviteLock)
{
if (listeners.containsKey(key))
{ printLog("message passed to uas: "+key,LogLevel.MEDIUM);
((SipProviderListener)listeners.get(key)).onReceivedMessage(this,msg);
return;
}
}
}
else if (listeners.containsKey(key))
{
printLog("message passed to uas: "+key ,LogLevel.LOW);
((SipProviderListener)listeners.get(key)).onReceivedMessage(this,msg);
return;
}
// try to look for a default UA
if (listeners.containsKey(ANY))
{ printLog("message passed to uas: "+ANY,LogLevel.MEDIUM);
((SipProviderListener)listeners.get(ANY)).onReceivedMessage(this,msg);
return;
}
if (msg.isRequest() && msg.isInvite())
{
// we are busy or can't answer - Invite would have been picked up above already if we could handle it
if (sipBusyUrl!=null)
{
// redirect the call elsewhere
String targetId=msg.getToHeader().getNameAddress().toString().replaceAll("(?i).*sip:<?([^@<]+)@.*", "$1");
String redirect_Url=sipBusyUrl.replaceAll("calleeid", targetId);
printLog("Incoming SIP Call - Channel busy - Redirect to: "+redirect_Url ,LogLevel.LOW);
Message resp=MessageFactory.createResponse(msg,302,SipResponses.reasonOf(302),new NameAddress(redirect_Url));
InviteTransactionServer ts=new InviteTransactionServer(this,msg,null);
ts.respondWith(resp);
return;
}
printLog("Invite Request - Sending busy response (486)",LogLevel.MEDIUM);
InviteTransactionServer ts=new InviteTransactionServer(this,msg,null);
ts.respondWith(MessageFactory.createResponse(msg,486,SipResponses.reasonOf(486),null));
return;
}
if (msg.isRequest() && msg.isNotify())
{
// nobody handled it, just respond 405 (method not allowed) to get it to go away
printLog("Notify Request - Sending unsupported response (405)",LogLevel.MEDIUM);
TransactionServer ts=new TransactionServer(this,msg,null);
ts.respondWith(MessageFactory.createResponse(msg,405,SipResponses.reasonOf(405),null));
return;
}
// if we are here, no listener_ID matched..
printLog("No SipListener found matching that message: message DISCARDED",LogLevel.HIGH);