public void processMessage(SIPMessage sipMessage)  throws Exception { try { if (sipMessage.getFrom() == null || sipMessage.getTo() == null || sipMessage.getCallId() == null || sipMessage.getCSeq() == null || sipMessage.getViaHeaders() == null) { String badmsg = sipMessage.encode(); if (LogWriter.needsLogging) { stack.logWriter.logMessage("bad message " + badmsg); stack.logWriter.logMessage(">>> Dropped Bad Msg"); } stack.logBadMessage(badmsg); return; }  ViaList viaList = sipMessage.getViaHeaders();     if (sipMessage instanceof SIPRequest) { Via v = (Via) viaList.first(); if (v.hasPort()) { this.peerPort = v.getPort(); } else this.peerPort = SIPMessageStack.DEFAULT_PORT; this.peerProtocol = v.getTransport(); try { this.peerAddress = mySock.getInetAddress();      if (!v .getSentBy() .getInetAddress() .equals(this.peerAddress)) v.setParameter( Via.RECEIVED, this.peerAddress.getHostAddress());  v.setParameter( Via.RPORT, new Integer(this.peerPort).toString()); } catch (java.net.UnknownHostException ex) {  if (LogWriter.needsLogging) { stack.logWriter.logMessage( "Rejecting message -- could not resolve Via Address"); } return; } catch (java.text.ParseException ex) { InternalErrorHandler.handleException(ex); }  if (! this.isCached) { ( (TCPMessageProcessor) this.messageProcessor) .cacheMessageChannel(this); this.isCached = true; String key = IOHandler.makeKey(mySock.getInetAddress(), this.peerPort); stack.ioHandler.putSocket(key, mySock); } }      long receptionTime = System.currentTimeMillis();  if (sipMessage instanceof SIPRequest) {  SIPRequest sipRequest = (SIPRequest) sipMessage;    if (LogWriter.needsLogging) { stack.logWriter.logMessage("----Processing Message---"); }    if ( stack.getMaxMessageSize() > 0 && sipRequest.getSize() + (sipRequest.getContentLength() == null? 0 : sipRequest.getContentLength().getContentLength() ) > stack.getMaxMessageSize() ) { SIPResponse sipResponse = sipRequest.createResponse(SIPResponse.MESSAGE_TOO_LARGE); byte[] resp = sipResponse.encodeAsBytes(); this.sendMessage(resp,false); throw new Exception("Message size exceeded"); }  ServerRequestInterface sipServerRequest = stack.newSIPServerRequest(sipRequest, this); sipServerRequest.processRequest(sipRequest, this); if (this .stack .serverLog .needsLogging(ServerLog.TRACE_MESSAGES)) { if (sipServerRequest.getProcessingInfo() == null) { stack.serverLog.logMessage( sipMessage, sipRequest.getViaHost() + ":" + sipRequest.getViaPort(), stack.getHostAddress() + ":" + stack.getPort(this.getTransport()), false, receptionTime); } else { this.stack.serverLog.logMessage( sipMessage, sipRequest.getViaHost() + ":" + sipRequest.getViaPort(), stack.getHostAddress() + ":" + stack.getPort(this.getTransport()), sipServerRequest.getProcessingInfo(), false, receptionTime); } } } else { SIPResponse sipResponse = (SIPResponse) sipMessage;    if ( stack.getMaxMessageSize() > 0 && sipResponse.getSize() + (sipResponse.getContentLength() == null? 0 : sipResponse.getContentLength().getContentLength() ) > stack.getMaxMessageSize() ) { if (LogWriter.needsLogging) this.stack.logWriter.logMessage("Message size exceeded"); return;  } ServerResponseInterface sipServerResponse = stack.newSIPServerResponse(sipResponse, this); sipServerResponse.processResponse(sipResponse, this); } } finally { } }
public void processMessage(SIPMessage sipMessage) throws Exception { try { if (sipMessage.getFrom() == null ||  sipMessage.getTo() == null || sipMessage.getCallId() == null || sipMessage.getCSeq() == null || sipMessage.getViaHeaders() == null) { String badmsg = sipMessage.encode(); if (sipStack.isLoggingEnabled()) { sipStack.logWriter.logDebug(">>> Dropped Bad Msg"); sipStack.logWriter.logDebug(badmsg); }  return; }  ViaList viaList = sipMessage.getViaHeaders();     if (sipMessage instanceof SIPRequest) { Via v = (Via) viaList.getFirst(); Hop hop = sipStack.addressResolver.resolveAddress(v.getHop()); this.peerPort = hop.getPort(); this.peerProtocol = v.getTransport(); try { this.peerAddress = mySock.getInetAddress();   InetAddress sentByAddress = InetAddress.getByName(hop.getHost()); if (!sentByAddress .equals(this.peerAddress)) v.setParameter(Via.RECEIVED, this.peerAddress .getHostAddress());  v.setParameter(Via.RPORT, new Integer(this.peerPort) .toString()); } catch (java.net.UnknownHostException ex) {  if (sipStack.isLoggingEnabled()) { sipStack.logWriter .logDebug("Rejecting message -- could not resolve Via Address"); } return; } catch (java.text.ParseException ex) { InternalErrorHandler .handleException(ex, sipStack.logWriter); }  if (!this.isCached) { ((TCPMessageProcessor) this.messageProcessor) .cacheMessageChannel(this); this.isCached = true; String key = IOHandler.makeKey(mySock.getInetAddress(), this.peerPort); sipStack.ioHandler.putSocket(key, mySock); } }      long receptionTime = System.currentTimeMillis();  if (sipMessage instanceof SIPRequest) {  SIPRequest sipRequest = (SIPRequest) sipMessage;    if (sipStack.isLoggingEnabled()) { sipStack.logWriter.logDebug("----Processing Message---"); }    if (sipStack.getMaxMessageSize() > 0 && sipRequest.getSize() + (sipRequest.getContentLength() == null ? 0 : sipRequest.getContentLength() .getContentLength()) > sipStack .getMaxMessageSize()) { SIPResponse sipResponse = sipRequest .createResponse(SIPResponse.MESSAGE_TOO_LARGE); byte[] resp = sipResponse.encodeAsBytes(); this.sendMessage(resp, false); throw new Exception("Message size exceeded"); }  ServerRequestInterface sipServerRequest = sipStack .newSIPServerRequest(sipRequest, this); if (sipStack.isLoggingEnabled()) { sipStack.logWriter.logDebug("---- sipServerRequest = " + sipServerRequest); }  if (sipServerRequest != null) { try { sipServerRequest.processRequest(sipRequest, this); } finally { if (sipServerRequest instanceof SIPTransaction) { SIPServerTransaction sipServerTx = (SIPServerTransaction) sipServerRequest; if (!sipServerTx.passToListener()) ((SIPTransaction) sipServerRequest) .releaseSem(); } } } else { this.sipStack.logWriter .logWarning("Dropping request -- could not acquire semaphore in 10 sec"); SIPResponse  response = sipRequest.createResponse(Response.SERVICE_UNAVAILABLE);  this.sendMessage(response); } if (this.sipStack.serverLog .needsLogging(ServerLog.TRACE_MESSAGES)) {  sipStack.serverLog.logMessage(sipMessage, this.getPeerHostPort().toString() , this .getMessageProcessor().getIPAddress() .getHostAddress() + ":" + this.getMessageProcessor().getPort(), false, receptionTime);  } } else { SIPResponse sipResponse = (SIPResponse) sipMessage; if (sipResponse.getStatusCode() == 100) sipResponse.getTo().removeParameter("tag"); try { sipResponse.checkHeaders(); } catch (ParseException ex) { if (sipStack.isLoggingEnabled()) sipStack.logWriter.logError("Dropping Badly formatted response message >>> " + sipResponse); return; }    if (sipStack.getMaxMessageSize() > 0 && sipResponse.getSize() + (sipResponse.getContentLength() == null ? 0 : sipResponse.getContentLength() .getContentLength()) > sipStack .getMaxMessageSize()) { if (sipStack.isLoggingEnabled()) this.sipStack.logWriter .logDebug("Message size exceeded"); return;  } ServerResponseInterface sipServerResponse = sipStack .newSIPServerResponse(sipResponse, this); if (sipServerResponse != null) { try { sipServerResponse.processResponse(sipResponse, this); } finally { if (sipServerResponse instanceof SIPTransaction && !((SIPTransaction) sipServerResponse) .passToListener()) ((SIPTransaction) sipServerResponse).releaseSem(); } } else { sipStack .getLogWriter() .logWarning( "Application is blocked -- could not acquire semaphore -- dropping response"); } } } finally { } }
    public void processMessage(SIPMessage sipMessage)  throws Exception {        try {            if (sipMessage.getFrom() == null            || //sipMessage.getFrom().getTag() == null ||            sipMessage.getTo()            == null            || sipMessage.getCallId() == null            || sipMessage.getCSeq() == null            || sipMessage.getViaHeaders() == null) {                String badmsg = sipMessage.encode();                if (LogWriter.needsLogging) {                    stack.logWriter.logMessage("bad message " + badmsg);                    stack.logWriter.logMessage(">>> Dropped Bad Msg");                }                stack.logBadMessage(badmsg);                return;            }                        ViaList viaList = sipMessage.getViaHeaders();            // For a request            // first via header tells where the message is coming from.            // For response, this has already been recorded in the outgoing            // message.            if (sipMessage instanceof SIPRequest) {                Via v = (Via) viaList.first();                if (v.hasPort()) {                    this.peerPort = v.getPort();                } else                    this.peerPort = SIPMessageStack.DEFAULT_PORT;                this.peerProtocol = v.getTransport();                try {                    this.peerAddress = mySock.getInetAddress();                    // Check to see if the received parameter matches                    // the peer address and tag it appropriately.                    // Bug fix by viswashanti.kadiyala@antepo.com		    // Should record host address not host name		    // bug fix by  Joost Yervante Damand                    if (!v                    .getSentBy()                    .getInetAddress()                    .equals(this.peerAddress))                        v.setParameter(                        Via.RECEIVED,                        this.peerAddress.getHostAddress());                        //@@@ hagai                        v.setParameter(                                Via.RPORT,                                new Integer(this.peerPort).toString());                } catch (java.net.UnknownHostException ex) {                    // Could not resolve the sender address.                    if (LogWriter.needsLogging) {                        stack.logWriter.logMessage(                        "Rejecting message -- could not resolve Via Address");                    }                    return;                } catch (java.text.ParseException ex) {                    InternalErrorHandler.handleException(ex);                }                // Use this for outgoing messages as well.                if (! this.isCached) {                    ( (TCPMessageProcessor)                    this.messageProcessor)                    .cacheMessageChannel(this);                    this.isCached = true;                    String key =                    IOHandler.makeKey(mySock.getInetAddress(), this.peerPort);                    stack.ioHandler.putSocket(key, mySock);                }            }                        // System.out.println("receiver address = " + receiverAddress);                        // Foreach part of the request header, fetch it and process it                        long receptionTime = System.currentTimeMillis();                        if (sipMessage instanceof SIPRequest) {                // This is a request - process the request.                SIPRequest sipRequest = (SIPRequest) sipMessage;                // Create a new sever side request processor for this                // message and let it handle the rest.                                if (LogWriter.needsLogging) {                    stack.logWriter.logMessage("----Processing Message---");                }                                // Check for reasonable size - reject message                // if it is too long.                if ( stack.getMaxMessageSize() > 0 &&                sipRequest.getSize() +                (sipRequest.getContentLength() == null? 0 :                    sipRequest.getContentLength().getContentLength() ) >                    stack.getMaxMessageSize() ) {                        SIPResponse sipResponse = sipRequest.createResponse(SIPResponse.MESSAGE_TOO_LARGE);                        byte[] resp = sipResponse.encodeAsBytes();                        this.sendMessage(resp,false);                        throw new Exception("Message size exceeded");                    }                                        ServerRequestInterface sipServerRequest =                    stack.newSIPServerRequest(sipRequest, this);                    sipServerRequest.processRequest(sipRequest, this);                    if (this                    .stack                    .serverLog                    .needsLogging(ServerLog.TRACE_MESSAGES)) {                        if (sipServerRequest.getProcessingInfo() == null) {                            stack.serverLog.logMessage(                            sipMessage,                            sipRequest.getViaHost()                            + ":"                            + sipRequest.getViaPort(),                            stack.getHostAddress()                            + ":"                            + stack.getPort(this.getTransport()),                            false,                            receptionTime);                        } else {                            this.stack.serverLog.logMessage(                            sipMessage,                            sipRequest.getViaHost()                            + ":"                            + sipRequest.getViaPort(),                            stack.getHostAddress()                            + ":"                            + stack.getPort(this.getTransport()),                            sipServerRequest.getProcessingInfo(),                            false,                            receptionTime);                        }                    }            } else {                SIPResponse sipResponse = (SIPResponse) sipMessage;                // This is a response message - process it.                // Check the size of the response.                // If it is too large dump it silently.                if ( stack.getMaxMessageSize() > 0 &&                sipResponse.getSize() +                (sipResponse.getContentLength() == null? 0 :                    sipResponse.getContentLength().getContentLength() ) >                    stack.getMaxMessageSize() ) {                        if (LogWriter.needsLogging)                            this.stack.logWriter.logMessage("Message size exceeded");                        return;                                            }                    ServerResponseInterface sipServerResponse =                    stack.newSIPServerResponse(sipResponse, this);                    sipServerResponse.processResponse(sipResponse, this);            }        } finally {        }    }