⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basetransaction.java

📁 jsr-180 (SIP) 实现源码。可以在真实手机上使用
💻 JAVA
字号:
package com.micromethod.sipstack.ri;

import java.util.Timer;
import java.util.Vector;

import com.micromethod.sipstack.i.SipAddress;
import com.micromethod.sipstack.i.SipHeader;

/**
 * BaseTransaction
 */
public abstract class BaseTransaction {

  protected short _fldint = 0;

  protected static final short _fldfor = 1;

  protected static final short _fldbyte = 2;

  protected static final short _fldnew = 3;

  protected static final short k = 4;

  protected static final short _fldif = 5;

  protected static final short m = 6;

  protected static final short f = 7;

  protected static final short _fldtry = 8;

  protected static final Object n = new Object();

  /**
   * m_clientTransactionID
   */
  public String m_clientTransactionID = null;

  /**
   * m_oldBranchTail
   */
  public String m_oldBranchTail = null;

  /**
   * m_newBranchTail
   */
  public String m_newBranchTail = null;

  /**
   * m_timer
   */
  protected Timer m_timer = null;

  /**
   * T1, 500ms
   */
  protected static final int T1 = 500;

  /**
   * T2, 4s
   */
  protected static final int T2 = 4000;

  /**
   * T4, 5s
   */
  protected static final int T4 = 5000;

  protected int _fldnull = 0;

  protected static final int c = 32000;

  protected static final int _fldvoid = 15000;

  protected static final int _fldlong = 500;

  protected static final int _fldelse = 5000;

  protected static final int _fldchar = 5000;

  protected int b = 0;

  /**
   * m_txHandler
   */
  protected static TxHandler m_txHandler = null;

  /**
   * m_lastEffectRequest
   */
  protected SipRequest m_lastEffectRequest = null;

  /**
   * m_lastRequest
   */
  protected SipRequest m_lastRequest = null;

  /**
   * m_response
   */
  protected SipResponse m_response = null;

  /**
   * m_sipMessage
   */
  protected SipMessage m_sipMessage = null;

  /**
   * abstract BaseTransaction Constructor
   */
  public BaseTransaction() {
    m_clientTransactionID = null;
    m_oldBranchTail = null;
    m_newBranchTail = null;
    m_timer = new Timer();
    _fldnull = 500;
    b = 0;
    m_lastEffectRequest = null;
    m_lastRequest = null;
    m_response = null;
    m_sipMessage = null;
    _fldint = 1;
  }

  /**
   * cancel
   */
  public void cancel() {
    m_lastEffectRequest = null;
    m_lastRequest = null;
    m_response = null;
    m_sipMessage = null;
    m_timer.cancel();
  }

  /**
   * getBranch
   * 
   * @param viaValue
   * @return branch
   */
  public static String getBranch(String viaValue) {
    String s1 = null;
    if (viaValue == null)
      return null;
    try {
      SipHeader sipheader = new SipHeader("Via", viaValue);
      s1 = sipheader.getParameter("branch");
    }
    catch (Exception exception) {
      return null;
    }
    return s1;
  }

  /**
   * routeResponse
   * 
   * @param sipMessage
   * @return 1
   */
  public static int routeRequest(SipMessage sipMessage) {
    Object obj = null;
    SipRequest u1 = (SipRequest) sipMessage;
    if (u1.hasRoute()) {
      String s = u1.getHeaderValue("Route");
      SipAddress sipaddress1 = new SipAddress(s);
      u1.m_port = sipaddress1.getPort();
      u1.m_host = sipaddress1.getHost();
      Protocol.echo("BaseTransaction.routeRequest: Loose routing to "
          + u1.m_host + ":" + u1.m_port);
    }
    else {
      SipAddress sipaddress = new SipAddress(u1.getSipAddress().toString());
      Protocol
          .echo("BaseTransaction.routeRequest using RequestURI address:\n\t"
              + sipaddress.getHost() + ":" + sipaddress.getPort());
      u1.m_port = sipaddress.getPort();
      u1.m_host = sipaddress.getHost();
    }
    return 1;
  }

  /**
   * routeResponse
   * 
   * @param sipMessage1
   * @param sipMessage2
   * @return result, 1 success, -1 error
   */
  public static int routeResponse(SipMessage sipMessage1, SipMessage sipMessage2) {
    try {
      Vector vector = sipMessage2.getHeaders("Via");
      if (vector.size() > 0) {
        PairStructure t1 = (PairStructure) vector.elementAt(0);
        String s = t1.getValue();
        Protocol.echo("BaseTransaction.routeResponse using Via:\n\t" + s);
        String s1 = "sip:" + s.substring(s.indexOf(' ') + 1);
        SipAddress sipaddress1 = new SipAddress(s1);
        sipMessage1.m_port = sipaddress1.getPort();
        sipMessage1.m_host = sipaddress1.getHost();
      }
      else {
        Vector vector1 = sipMessage2.getHeaders("Contact");
        if (vector1.size() > 0) {
          PairStructure t2 = (PairStructure) vector1.elementAt(0);
          Protocol.echo("BaseTransaction.routeResponse using Contact:\n\t"
              + t2.getValue());
          SipHeader sipheader = new SipHeader("Contact", t2.getValue());
          SipAddress sipaddress = new SipAddress(sipheader.getValue());
          sipMessage1.m_port = sipaddress.getPort();
          sipMessage1.m_host = sipaddress.getHost();
        }
        else {
          Protocol
              .echo("BaseTransaction.routeResponse missing route information ?");
        }
      }
      return 1;
    }
    catch (Exception exception) {
      exception.printStackTrace();
      return -1;
    }
  }

  /**
   * setState
   * 
   * @param state
   */
  protected void setState(short state) {
    _fldint = state;
  }

  /**
   * transactionTimer
   */
  public abstract void transactionTimer();

  /**
   * ackTimer
   * 
   * @return result, 1:set schedule, -1:not set
   */
  public abstract int ackTimer();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -