📄 dialog.java
字号:
package com.micromethod.sipstack.ri;
import java.util.Vector;
import com.micromethod.sipstack.i.*;
/**
* Dialog
*/
public class Dialog implements SipDialog {
/**
* m_sipDialogID
*/
private String m_sipDialogID = null;
/**
* m_toTag
*/
private String m_toTag = null;
/**
* m_toURI
*/
protected String m_toURI = null;
/**
* m_contactURI
*/
protected String m_contactURI = null;
/**
* m_fromURI
*/
protected String m_fromURI = null;
/**
* m_fromTag
*/
protected String m_fromTag = null;
/**
* m_callIDValue
*/
private String m_callIDValue = null;
/**
* m_recordRoutes
*/
protected String m_recordRoutes[] = null;
/**
* m_state
*/
private byte m_state = 0;
/**
* m_uacCSeqNum
*/
protected int m_uacCSeqNum = 0;
/**
* m_uasCSeqNum
*/
protected int m_uasCSeqNum = 0;
private boolean _fldif = false;
/**
* m_contactValue
*/
protected String m_contactValue = null;
/**
* m_firstLine
*/
private Vector a = null;
/**
* m_sipConnectionNotifier
*/
private Notifier m_sipConnectionNotifier = null;
/**
* Dialog Constructor
*
* @param protocol
* protocol
* @throws SipException
*/
protected Dialog(Protocol protocol) throws SipException {
m_state = 0;
m_uacCSeqNum = 0;
m_uasCSeqNum = 0;
_fldif = false;
a = null;
String s1 = protocol.getMethod();
if (!s1.equals("INVITE") && !s1.equals("SUBSCRIBE") && !s1.equals("REFER")) {
throw new SipException("No new dialog for method '" + s1 + "'", (byte) 0);
}
int j = protocol.getStatusCode();
m_callIDValue = protocol.m_sipResponse.getHeaderValue("Call-ID");
if (j >= 101 && j < 200) {
m_state = 1;
}
else if (j >= 200 && j < 300) {
m_state = 2;
}
else {
m_state = 0;
}
a = new Vector(3);
}
/**
* Dialog Constructor
*
* @param sipClientConnection
* @throws SipException
*/
protected Dialog(ClientConnection sipClientConnection) throws SipException {
this(((Protocol) (sipClientConnection)));
Protocol.echo("-------- Creation of a UAC Dialog ----------");
String s2 = sipClientConnection.m_sipResponse.getHeaderValue("CSeq");
try {
m_uacCSeqNum = Integer.parseInt(s2.substring(0, s2.indexOf(' ')));
}
catch (Exception exception) {
}
m_contactValue = sipClientConnection.m_sipResponse
.getHeaderValue("Contact");
SipHeader sipheader = new SipHeader("From",
sipClientConnection.m_sipResponse.getHeaderValue("From"));
m_toTag = sipheader.getParameter("tag");
m_toURI = (new SipAddress(sipheader.getValue())).getURI();
SipHeader sipheader1 = new SipHeader("To", sipClientConnection
.getHeader("To"));
m_fromTag = sipheader1.getParameter("tag");
m_fromURI = (new SipAddress(sipheader1.getValue())).getURI();
String s3 = sipClientConnection.getHeader("Contact");
if (s3 != null) {
m_contactURI = (new SipAddress(s3)).getURI();
}
else {
Protocol
.echo("WARNING Dialog: using To instead of Contact as remote target");
m_contactURI = m_fromURI;
}
StringBuffer stringbuffer = new StringBuffer(m_callIDValue);
stringbuffer.append(m_toTag);
stringbuffer.append(m_fromTag);
m_sipDialogID = stringbuffer.toString();
String as[] = sipClientConnection.getHeaders("Record-Route");
if (as != null) {
m_recordRoutes = new String[as.length];
for (short word0 = 0; word0 < as.length; word0++)
m_recordRoutes[word0] = as[as.length - 1 - word0];
}
}
/**
* Dialog Constructor
*
* @param sipServerConnection
* @throws SipException
*/
protected Dialog(ServerConnection sipServerConnection) throws SipException {
this(((Protocol) (sipServerConnection)));
Protocol.echo("-------- Creation of a UAS Dialog ----------");
String s1 = sipServerConnection.m_sipResponse.getHeaderValue("CSeq");
try {
m_uasCSeqNum = Integer.parseInt(s1.substring(0, s1.indexOf(' ')));
}
catch (Exception exception) {
}
m_contactValue = sipServerConnection.m_sipRequest.getHeaderValue("Contact");
SipHeader sipheader = new SipHeader("To", sipServerConnection
.getHeader("To"));
m_toTag = sipheader.getParameter("tag");
m_toURI = (new SipAddress(sipheader.getValue())).getURI();
SipHeader sipheader1 = new SipHeader("From",
sipServerConnection.m_sipResponse.getHeaderValue("From"));
m_fromTag = sipheader1.getParameter("tag");
m_fromURI = (new SipAddress(sipheader1.getValue())).getURI();
String s2 = sipServerConnection.m_sipResponse.getHeaderValue("Contact");
if (s2 != null) {
m_contactURI = (new SipAddress(s2)).getURI();
}
else {
Protocol
.echo("WARNING Dialog: using From instead of Contact as remote target");
m_contactURI = m_fromURI;
}
StringBuffer stringbuffer = new StringBuffer(m_callIDValue);
stringbuffer.append(m_toTag);
stringbuffer.append(m_fromTag);
m_sipDialogID = stringbuffer.toString();
m_recordRoutes = sipServerConnection.getHeaders("Record-Route");
}
/**
* Dialog Constructor
*
* @param sipServerConnection
* @param sipClientConnection
*/
protected Dialog(ServerConnection sipServerConnection,
ClientConnection sipClientConnection) {
m_state = 0;
m_uacCSeqNum = 0;
m_uasCSeqNum = 0;
_fldif = false;
a = null;
Protocol
.echo("-------- Creation of a UAS Dialog (SUBSCRIBE/NOTIFY) ----------");
m_callIDValue = sipClientConnection.m_sipResponse.getHeaderValue("Call-ID");
m_state = 2;
String s2 = sipClientConnection.m_sipResponse.getHeaderValue("CSeq");
try {
m_uasCSeqNum = Integer.parseInt(s2.substring(0, s2.indexOf(' ')));
}
catch (Exception exception) {
}
m_contactValue = sipClientConnection.m_sipResponse
.getHeaderValue("Contact");
SipHeader sipheader = new SipHeader("To", sipServerConnection
.getHeader("To"));
m_toTag = sipheader.getParameter("tag");
m_toURI = (new SipAddress(sipheader.getValue())).getURI();
SipHeader sipheader1 = new SipHeader("From",
sipServerConnection.m_sipResponse.getHeaderValue("From"));
m_fromTag = sipheader1.getParameter("tag");
m_fromURI = (new SipAddress(sipheader1.getValue())).getURI();
String s3 = sipServerConnection.m_sipResponse.getHeaderValue("Contact");
if (s3 != null) {
m_contactURI = (new SipAddress(s3)).getURI();
}
else {
Protocol
.echo("WARNING Dialog: using From instead of Contact as remote target");
m_contactURI = m_fromURI;
}
StringBuffer stringbuffer = new StringBuffer(m_callIDValue);
stringbuffer.append(m_toTag);
stringbuffer.append(m_fromTag);
m_sipDialogID = stringbuffer.toString();
String as[] = sipServerConnection.getHeaders("Record-Route");
if (as != null) {
m_recordRoutes = new String[as.length];
for (short word0 = 0; word0 < as.length; word0++)
m_recordRoutes[word0] = as[as.length - 1 - word0];
}
a = new Vector(3);
}
/**
* makeSipDialogID
*
* @param sipMessage
* @return sipDialogID
*/
protected static String makeSipDialogID(SipMessage sipMessage) {
SipHeader sipheader = new SipHeader("To", sipMessage.getHeaderValue("To"));
String s1 = sipheader.getParameter("tag");
SipHeader sipheader1 = new SipHeader("From", sipMessage
.getHeaderValue("From"));
String s2 = sipheader1.getParameter("tag");
String s3 = sipMessage.getHeaderValue("Call-ID");
StringBuffer stringbuffer = new StringBuffer(s3);
stringbuffer.append(s1);
stringbuffer.append(s2);
return stringbuffer.toString();
}
/**
* setSipConnectionNotifier
*
* @param m
*/
protected void setSipConnectionNotifier(Notifier sipConnectionNotifier) {
m_sipConnectionNotifier = sipConnectionNotifier;
}
/**
* getSipConnectionNotifier
*
* @return sipConnectionNotifier
*/
protected Notifier getSipConnectionNotifier() {
return m_sipConnectionNotifier;
}
/**
* getNewClientConnection
*
* @param method
* @return sipClientConnection
*/
public SipClientConnection getNewClientConnection(String method)
throws SipException, IllegalArgumentException {
if (m_state != 2 && m_state != 1) {
throw new SipException("Can't get new ClientConnection in this state",
(byte) 5);
}
else {
return ((SipClientConnection) (new ClientConnection(this, method)));
}
}
/**
* isSameDialog
*
* @param sipConnection
* @return equals
*/
public boolean isSameDialog(SipConnection sipConnection) {
Protocol protocol = (Protocol) sipConnection;
if (protocol.m_sipDialog == null || m_sipDialogID == null) {
return false;
}
return m_sipDialogID
.equals(((Object) (protocol.m_sipDialog.getDialogID())));
}
/**
* getState
*
* @return state
*/
public byte getState() {
return m_state;
}
/**
* setState
*
* @param state
*/
protected void setState(byte state) {
m_state = state;
}
/**
* getDialogID
*
* @return dialogID
*/
public String getDialogID() {
return m_sipDialogID;
}
/**
* getToTag
*
* @return To tag
*/
protected String getToTag() {
return m_toTag;
}
/**
* getFromTag
*
* @return From tag
*/
protected String getFromTag() {
return m_fromTag;
}
/**
* getCallIDValue
*
* @return Call-ID Value
*/
protected String getCallIDValue() {
return m_callIDValue;
}
/**
* updateOnSubscribe
*
* @param j
* statusCode
* @param c1
* sipResponse
* @param a1
* sipMessage
*/
protected void updateOnSubscribe(int j, SipResponse c1, SipMessage a1) {
Protocol.echo("Dialog: updateSubscriptions() on SUBSCRIBE-response " + j);
if (j >= 200)
if (j >= 200 && j < 299) {
SipHeader sipheader = new SipHeader("Expires", c1
.getHeaderValue("Expires"));
String s2 = sipheader.getValue();
int k = Integer.parseInt(s2);
String s3 = a1.getHeaderValue("Event");
if (k > 0) {
setEvent(s3);
}
}
else if (j >= 300) {
String s1 = a1.getHeaderValue("Event");
removeEvent(s1);
}
}
/**
* updateOnNotify
*
* @param u1
* sipRequest
*/
protected void updateOnNotify(SipRequest u1) {
Protocol.echo("Dialog: updateSubscriptions() on NOTIFY request");
SipHeader sipheader = new SipHeader("Subscription-State", u1
.getHeaderValue("Subscription-State"));
String s1 = u1.getHeaderValue("Event");
if (sipheader.getValue().equals("terminated")) {
removeEvent(s1);
if (a.isEmpty()) {
m_state = 0;
}
}
else if (sipheader.getValue().equals("active")) {
setEvent(s1);
}
else if (!sipheader.getValue().equals("pending")) {
;
}
}
/**
* getEventValueID
*
* @param eventValue
* @return Event value part
*/
private String getEventValueID(String eventValue) {
SipHeader sipheader = new SipHeader("Event", eventValue);
String s2 = sipheader.getValue();
String s3 = sipheader.getParameter("id");
String s4 = null;
if (s3 == null) {
s4 = s2;
}
else {
s4 = s2 + ";" + s3;
}
return s4;
}
/**
* setEvent
*
* @param eventValue
*/
private void setEvent(String eventValue) {
String s2 = getEventValueID(eventValue);
if (!a.contains(((Object) (s2)))) {
a.addElement(((Object) (s2)));
}
}
/**
* removeEvent
*
* @param eventValue
*/
private void removeEvent(String eventValue) {
String s2 = getEventValueID(eventValue);
if (a.contains(((Object) (s2)))) {
a.removeElement(((Object) (s2)));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -