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

📄 serverconnection.java

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

import com.micromethod.sipstack.i.*;

/**
 * ServerConnection
 */
public class ServerConnection extends Protocol implements SipServerConnection {
  /**
   * m_listener
   */
  protected Listener m_listener = null;

  /**
   * m_sipConnectionNotifier
   */
  protected Notifier m_sipConnectionNotifier = null;

  /**
   * ServerConnection Constructor
   * 
   * @param transaction
   * @param sipRequest
   * @param listener
   * @param sipConnectionNotifier
   */
  protected ServerConnection(BaseTransaction transaction,
      SipRequest sipRequest, Listener listener, Notifier sipConnectionNotifier) {
    m_transaction = transaction;
    m_txHandler = TxHandler.getInstance();
    m_sipResponse = ((SipMessage) (sipRequest));
    m_sipRequest = ((SipMessage) (sipRequest));
    m_listener = listener;
    m_sipConnectionNotifier = sipConnectionNotifier;
    if (sipRequest.getMethod().equals("ACK")) {
      m_state = 4;
    }
    else {
      m_state = 5;
    }
    m_sipDialog = m_txHandler.findSipDialog(((SipMessage) (sipRequest)));
    if (m_sipDialog != null) {
      Protocol.echo("ServerConnection: associating " + getMethod()
          + " with existing dialog: " + m_sipDialog.getDialogID());
    }
  }

  /**
   * initResponse
   * 
   * @param statusCode
   * @throws IllegalArgumentException
   * @throws SipException
   */
  public void initResponse(int statusCode) throws IllegalArgumentException,
      SipException {
    if (m_state != 5) {
      throw new SipException("Can not init response in this state", (byte) 5);
    }
    if (statusCode < 100 || statusCode > 699) {
      throw new IllegalArgumentException("Status code out-of-range");
    }
    SipResponse c1 = ((SipRequest) m_sipResponse).getSipResponse();
    c1.setStatusCode(statusCode);
    String s = m_sipResponse.getHeaderValue("To");
    try {
      SipHeader sipheader = new SipHeader("To", s);
      if (sipheader.getParameter("tag") == null) {
        sipheader.setParameter("tag", Integer.toString(m_listener
            .getSipAddress().toString().hashCode()));
      }
      c1.setHeader("To", sipheader.getHeaderValue(), true);
    }
    catch (Exception exception) {
      throw new SipException(exception.getMessage(), (byte) 0);
    }
    String s1 = ((SipRequest) m_sipResponse).getMethod();
    if (s1.equals("INVITE") || s1.equals("SUBSCRIBE") || s1.equals("REFER")) {
      c1.addTopHeader("Contact", m_listener.getSipAddress().toString());
    }
    m_sipRequest = ((SipMessage) (c1));
    m_state = 1;
  }

  /**
   * setReasonPhrase
   * 
   * @param phrase
   * @throws IllegalArgumentException
   * @throws SipException
   */
  public void setReasonPhrase(String phrase) throws IllegalArgumentException,
      SipException {
    if (m_state != 1) {
      throw new SipException("Can not set reason phrase in this state",
          (byte) 5);
    }
    if (phrase == null) {
      throw new IllegalArgumentException("Phrase is null");
    }
    else {
      ((SipResponse) m_sipRequest).setReasonPhrase(phrase);
      return;
    }
  }

  /**
   * close
   */
  public void close() {
    m_state = -1;
    super.close();
  }

  /**
   * refresh
   */
  protected void refresh() {
    String s = getMethod();
    if (s.equals("NOTIFY")) {
      if (m_sipDialog == null) {
        m_sipDialog = m_txHandler.getSipDialog(this);
      }
      if (m_sipDialog == null) {
        Protocol.echo("Internal error: dialog == null");
        return;
      }
      try {
        m_sipDialog.updateOnNotify((SipRequest) m_sipRequest);
      }
      catch (Exception exception) {
        Protocol.echo("ServerConnection: Error updating the dialog info; "
            + exception.getMessage());
        Protocol.echo("ServerConnection: Terminate the dialog state");
        m_sipDialog.setState((byte) 0);
      }
      RefreshHelper p1 = RefreshHelper.getInstance();
      p1.startedRefresh((SipRequest) m_sipRequest);
    }
  }
}

⌨️ 快捷键说明

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