Package gov.nist.javax.sip.header

Examples of gov.nist.javax.sip.header.Via


     */
    public SIPTransaction findTransaction(SIPMessage sipMessage, boolean isServer) {
        SIPTransaction retval = null;

        if (isServer) {
            Via via = sipMessage.getTopmostVia();
            if (via.getBranch() != null) {
                String key = sipMessage.getTransactionId();

                retval = (SIPTransaction) serverTransactionTable.get(key);
                if (logWriter.isLoggingEnabled())
                    getLogWriter().logDebug(
                            "serverTx: looking for key " + key + " existing="
                                    + serverTransactionTable);
                if (key.startsWith(SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE))
                    return retval;

            }
            // Need to scan the table for old style transactions (RFC 2543
            // style)
            Iterator<SIPServerTransaction> it = serverTransactionTable.values().iterator();
            while (it.hasNext()) {
                SIPServerTransaction sipServerTransaction = (SIPServerTransaction) it.next();
                if (sipServerTransaction.isMessagePartOfTransaction(sipMessage))
                    return sipServerTransaction;
            }

        } else {
            Via via = sipMessage.getTopmostVia();
            if (via.getBranch() != null) {
                String key = sipMessage.getTransactionId();
                if (logWriter.isLoggingEnabled())
                    getLogWriter().logDebug("clientTx: looking for key " + key);
                retval = (SIPTransaction) clientTransactionTable.get(key);
                if (key.startsWith(SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE))
View Full Code Here


   * underlying message channel, and adds a branch parameter to it for this
   * transaction.
   */
  public Via getViaHeader() {
    // Via header of the encapulated channel
    Via channelViaHeader;

    // Add the branch parameter to the underlying
    // channel's Via header
    channelViaHeader = super.getViaHeader();
    try {
      channelViaHeader.setBranch(branch);
    } catch (java.text.ParseException ex) {
    }
    return channelViaHeader;

  }
View Full Code Here

  public boolean doesCancelMatchTransaction(SIPRequest requestToTest) {

    // List of Via headers in the message to test
    ViaList viaHeaders;
    // Topmost Via header in the list
    Via topViaHeader;
    // Branch code in the topmost Via header
    String messageBranch;
    // Flags whether the select message is part of this transaction
    boolean transactionMatches;

    transactionMatches = false;

    if (this.getOriginalRequest() == null
        || this.getOriginalRequest().getMethod().equals(Request.CANCEL))
      return false;
    // Get the topmost Via header and its branch parameter
    viaHeaders = requestToTest.getViaHeaders();
    if (viaHeaders != null) {

      topViaHeader = (Via) viaHeaders.getFirst();
      messageBranch = topViaHeader.getBranch();
      if (messageBranch != null) {

        // If the branch parameter exists but
        // does not start with the magic cookie,
        if (!messageBranch.startsWith(SIPConstants.BRANCH_MAGIC_COOKIE)) {

          // Flags this as old
          // (RFC2543-compatible) client
          // version
          messageBranch = null;

        }

      }

      // If a new branch parameter exists,
      if (messageBranch != null && this.getBranch() != null) {

        // If the branch equals the branch in
        // this message,
        if (getBranch().equalsIgnoreCase(messageBranch)
            && topViaHeader.getSentBy().equals(
                ((Via) getOriginalRequest().getViaHeaders()
                    .getFirst()).getSentBy())) {
          transactionMatches = true;
          if (sipStack.isLoggingEnabled())
            sipStack.logWriter.logDebug("returning  true");
        }

      } else {
        // If this is an RFC2543-compliant message,
        // If RequestURI, To tag, From tag,
        // CallID, CSeq number, and top Via
        // headers are the same,
        if (sipStack.isLoggingEnabled())
          sipStack.logWriter.logDebug("testing against "
              + getOriginalRequest());

        if (getOriginalRequest().getRequestURI().equals(
            requestToTest.getRequestURI())
            && getOriginalRequest().getTo().equals(
                requestToTest.getTo())
            && getOriginalRequest().getFrom().equals(
                requestToTest.getFrom())
            && getOriginalRequest().getCallId().getCallId().equals(
                requestToTest.getCallId().getCallId())
            && getOriginalRequest().getCSeq().getSeqNumber() == requestToTest
                .getCSeq().getSeqNumber()
            && topViaHeader.equals(getOriginalRequest()
                .getViaHeaders().getFirst())) {

          transactionMatches = true;
        }
View Full Code Here

            SIPRequest transactionRequest;

            transactionRequest = (SIPRequest) messageToSend;

            // Set the branch id for the top via header.
            Via topVia = (Via) transactionRequest.getViaHeaders().getFirst();
            // Tack on a branch identifier to match responses.
            try {
                topVia.setBranch(getBranch());
            } catch (java.text.ParseException ex) {
            }

            if (sipStack.getLogWriter().isLoggingEnabled()) {
                sipStack.getLogWriter().logDebug("Sending Message " + messageToSend);
View Full Code Here

                // use SRV 3263 procedures
                // for servers in order to determine the IP address
                // and port to open the connection and send the response to.

            } else {
                Via via = transactionResponse.getTopmostVia();
                String transport = via.getTransport();
                if (transport == null)
                    throw new IOException("missing transport!");
                // @@@ hagai Symmetric NAT support
                int port = via.getRPort();
                if (port == -1)
                    port = via.getPort();
                if (port == -1) {
                    if (transport.equalsIgnoreCase("TLS"))
                        port = 5061;
                    else
                        port = 5060;
                }

                // Otherwise, if the Via header field value contains a
                // "maddr" parameter, the response MUST be forwarded to
                // the address listed there, using the port indicated in
                // "sent-by",
                // or port 5060 if none is present. If the address is a
                // multicast
                // address, the response SHOULD be sent using
                // the TTL indicated in the "ttl" parameter, or with a
                // TTL of 1 if that parameter is not present.
                String host = null;
                if (via.getMAddr() != null) {
                    host = via.getMAddr();
                } else {
                    // Otherwise (for unreliable unicast transports),
                    // if the top Via has a "received" parameter, the response
                    // MUST
                    // be sent to the
                    // address in the "received" parameter, using the port
                    // indicated
                    // in the
                    // "sent-by" value, or using port 5060 if none is specified
                    // explicitly.
                    host = via.getParameter(Via.RECEIVED);
                    if (host == null) {
                        // Otherwise, if it is not receiver-tagged, the response
                        // MUST be
                        // sent to the address indicated by the "sent-by" value,
                        // using the procedures in Section 5
                        // RFC 3263 PROCEDURE TO BE DONE HERE
                        host = via.getHost();
                    }
                }

                Hop hop = sipStack.addressResolver.resolveAddress(new HopImpl(host, port,
                        transport));
View Full Code Here

    public boolean isMessagePartOfTransaction(SIPMessage messageToTest) {

        // List of Via headers in the message to test
        ViaList viaHeaders;
        // Topmost Via header in the list
        Via topViaHeader;
        // Branch code in the topmost Via header
        String messageBranch;
        // Flags whether the select message is part of this transaction
        boolean transactionMatches;

        transactionMatches = false;

        String method = messageToTest.getCSeq().getMethod();
        // Invite Server transactions linger in the terminated state in the
        // transaction
        // table and are matched to compensate for
        // http://bugs.sipit.net/show_bug.cgi?id=769
        if ((method.equals(Request.INVITE) || !isTerminated())) {

            // Get the topmost Via header and its branch parameter
            viaHeaders = messageToTest.getViaHeaders();
            if (viaHeaders != null) {

                topViaHeader = (Via) viaHeaders.getFirst();
                messageBranch = topViaHeader.getBranch();
                if (messageBranch != null) {

                    // If the branch parameter exists but
                    // does not start with the magic cookie,
                    if (!messageBranch.toLowerCase().startsWith(
                            SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE)) {

                        // Flags this as old
                        // (RFC2543-compatible) client
                        // version
                        messageBranch = null;

                    }

                }

                // If a new branch parameter exists,
                if (messageBranch != null && this.getBranch() != null) {
                    if (method.equals(Request.CANCEL)) {
                        // Cancel is handled as a special case because it
                        // shares the same same branch id of the invite
                        // that it is trying to cancel.
                        transactionMatches = this.getMethod().equals(Request.CANCEL)
                                && getBranch().equalsIgnoreCase(messageBranch)
                                && topViaHeader.getSentBy().equals(
                                        ((Via) getOriginalRequest().getViaHeaders().getFirst())
                                                .getSentBy());

                    } else {
                        // Matching server side transaction with only the
                        // branch parameter.
                        transactionMatches = getBranch().equalsIgnoreCase(messageBranch)
                                && topViaHeader.getSentBy().equals(
                                        ((Via) getOriginalRequest().getViaHeaders().getFirst())
                                                .getSentBy());

                    }

                } else {
                    // This is an RFC2543-compliant message; this code is here
                    // for backwards compatibility.
                    // It is a weak check.
                    // If RequestURI, To tag, From tag, CallID, CSeq number, and
                    // top Via headers are the same, the
                    // SIPMessage matches this transaction. An exception is for
                    // a CANCEL request, which is not deemed
                    // to be part of an otherwise-matching INVITE transaction.
                    String originalFromTag = super.fromTag;

                    String thisFromTag = messageToTest.getFrom().getTag();

                    boolean skipFrom = (originalFromTag == null || thisFromTag == null);

                    String originalToTag = super.toTag;

                    String thisToTag = messageToTest.getTo().getTag();

                    boolean skipTo = (originalToTag == null || thisToTag == null);
                    boolean isResponse = (messageToTest instanceof SIPResponse);
                    // Issue #96: special case handling for a CANCEL request -
                    // the CSeq method of the original request must
                    // be CANCEL for it to have a chance at matching.
                    if (messageToTest.getCSeq().getMethod().equalsIgnoreCase(Request.CANCEL)
                            && !getOriginalRequest().getCSeq().getMethod().equalsIgnoreCase(
                                    Request.CANCEL)) {
                        transactionMatches = false;
                    } else if ((isResponse || getOriginalRequest().getRequestURI().equals(
                            ((SIPRequest) messageToTest).getRequestURI()))
                            && (skipFrom || originalFromTag.equalsIgnoreCase(thisFromTag))
                            && (skipTo || originalToTag.equalsIgnoreCase(thisToTag))
                            && getOriginalRequest().getCallId().getCallId().equalsIgnoreCase(
                                    messageToTest.getCallId().getCallId())
                            && getOriginalRequest().getCSeq().getSeqNumber() == messageToTest
                                    .getCSeq().getSeqNumber()
                            && ((!messageToTest.getCSeq().getMethod().equals(Request.CANCEL)) || getOriginalRequest()
                                    .getMethod().equals(messageToTest.getCSeq().getMethod()))
                            && topViaHeader.equals(getOriginalRequest().getViaHeaders()
                                    .getFirst())) {

                        transactionMatches = true;
                    }
View Full Code Here

            SIPRequest transactionRequest;

            transactionRequest = (SIPRequest) messageToSend;

            // Set the branch id for the top via header.
            Via topVia = (Via) transactionRequest.getViaHeaders().getFirst();
            // Tack on a branch identifier to match responses.
            try {
                topVia.setBranch(getBranch());
            } catch (java.text.ParseException ex) {
            }

            if (sipStack.isLoggingEnabled()) {
                sipStack.getStackLogger().logDebug("Sending Message " + messageToSend);
View Full Code Here

     * underlying message channel, and adds a branch parameter to it for this
     * transaction.
     */
    public Via getViaHeader() {
        // Via header of the encapulated channel
        Via channelViaHeader;

        // Add the branch parameter to the underlying
        // channel's Via header
        channelViaHeader = super.getViaHeader();
        try {
            channelViaHeader.setBranch(branch);
        } catch (java.text.ParseException ex) {
        }
        return channelViaHeader;

    }
View Full Code Here

    public boolean doesCancelMatchTransaction(SIPRequest requestToTest) {

        // List of Via headers in the message to test
        ViaList viaHeaders;
        // Topmost Via header in the list
        Via topViaHeader;
        // Branch code in the topmost Via header
        String messageBranch;
        // Flags whether the select message is part of this transaction
        boolean transactionMatches;

        transactionMatches = false;

        if (this.getOriginalRequest() == null
                || this.getOriginalRequest().getMethod().equals(Request.CANCEL))
            return false;
        // Get the topmost Via header and its branch parameter
        viaHeaders = requestToTest.getViaHeaders();
        if (viaHeaders != null) {

            topViaHeader = (Via) viaHeaders.getFirst();
            messageBranch = topViaHeader.getBranch();
            if (messageBranch != null) {

                // If the branch parameter exists but
                // does not start with the magic cookie,
                if (!messageBranch.toLowerCase().startsWith(SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE)) {

                    // Flags this as old
                    // (RFC2543-compatible) client
                    // version
                    messageBranch = null;

                }

            }

            // If a new branch parameter exists,
            if (messageBranch != null && this.getBranch() != null) {

                // If the branch equals the branch in
                // this message,
                if (getBranch().equalsIgnoreCase(messageBranch)
                        && topViaHeader.getSentBy().equals(
                                ((Via) getOriginalRequest().getViaHeaders()
                                        .getFirst()).getSentBy())) {
                    transactionMatches = true;
                    if (sipStack.isLoggingEnabled())
                        sipStack.getStackLogger().logDebug("returning  true");
                }

            } else {
                // If this is an RFC2543-compliant message,
                // If RequestURI, To tag, From tag,
                // CallID, CSeq number, and top Via
                // headers are the same,
                if (sipStack.isLoggingEnabled())
                    sipStack.getStackLogger().logDebug("testing against "
                            + getOriginalRequest());

                if (getOriginalRequest().getRequestURI().equals(
                        requestToTest.getRequestURI())
                        && getOriginalRequest().getTo().equals(
                                requestToTest.getTo())
                        && getOriginalRequest().getFrom().equals(
                                requestToTest.getFrom())
                        && getOriginalRequest().getCallId().getCallId().equals(
                                requestToTest.getCallId().getCallId())
                        && getOriginalRequest().getCSeq().getSeqNumber() == requestToTest
                                .getCSeq().getSeqNumber()
                        && topViaHeader.equals(getOriginalRequest()
                                .getViaHeaders().getFirst())) {

                    transactionMatches = true;
                }
View Full Code Here

     */
    public void sendResponse(Response response) throws SipException {
        if (!sipStack.isAlive())
            throw new SipException("Stack is stopped");
        SIPResponse sipResponse = (SIPResponse) response;
        Via via = sipResponse.getTopmostVia();
        if (via == null)
            throw new SipException("No via header in response!");
        SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage)response, true);
        if ( st != null   && st.getInternalState() != TransactionState._TERMINATED && this.isAutomaticDialogSupportEnabled()) {
            throw new SipException("Transaction exists -- cannot send response statelessly");
        }
        String transport = via.getTransport();

        // check to see if Via has "received paramaeter". If so
        // set the host to the via parameter. Else set it to the
        // Via host.
        String host = via.getReceived();

        if (host == null)
            host = via.getHost();

        // Symmetric nat support
        int port = via.getRPort();
        if (port == -1) {
            port = via.getPort();
            if (port == -1) {
                if (transport.equalsIgnoreCase("TLS"))
                    port = 5061;
                else
                    port = 5060;
View Full Code Here

TOP

Related Classes of gov.nist.javax.sip.header.Via

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.