📄 txhandler.java
字号:
else {
Protocol.echo("TxHandler: could not remove transaction");
}
}
/**
* getBranchTail
*
* @param seed
* ClientTransaction hashCode
* @return branch tail
*/
private String getBranchTail(int seed) {
m_random.setSeed(System.currentTimeMillis() - (long) seed);
return Integer.toString(Math.abs(m_random.nextInt()));
}
/**
* getNewClientTransaction
*
* @param sipClientConnection
* @param method
* @param branch
* @return new ClientTransaction
*/
public ClientTransaction getNewClientTransaction(
ClientConnection sipClientConnection, String method, String branch) {
ClientTransaction n1 = new ClientTransaction(this, sipClientConnection);
// Object obj = null;
if (branch == null) {
String s4 = getBranchTail(((Object) (n1)).hashCode());
n1.m_oldBranchTail = s4;
n1.m_newBranchTail = getBranchTail(((Object) (n1)).hashCode() + 1);
n1.m_clientTransactionID = method + m_localAddress + ":"
+ m_listener.getPort() + "z9hG4bK" + s4;
}
else {
n1.m_clientTransactionID = method + m_localAddress + ":"
+ m_listener.getPort() + branch;
}
Protocol.echo("TxHandler: new client transaction: "
+ n1.m_clientTransactionID);
m_clientTransactions.put(((Object) (n1.m_clientTransactionID)),
((Object) (n1)));
return n1;
}
/**
* getSipDialog
*
* @param sipServerConnection
* @return SipDialog
*/
protected Dialog getSipServerDialog(ServerConnection sipServerConnection) {
Dialog f1 = null;
int l = 0;
l = sipServerConnection.getStatusCode();
if (l == 0) {
Protocol.echo("TxHandler: internal error getting status code");
return null;
}
if (l < 101 || l > 299)
return null;
try {
f1 = new Dialog(sipServerConnection);
}
catch (Exception exception) {
Protocol.echo("TxHandler: ServerConnection no dialog for '"
+ sipServerConnection.getMethod() + "'");
return null;
}
f1.setSipConnectionNotifier(sipServerConnection.m_sipConnectionNotifier);
Dialog f2 = (Dialog) m_sipDialogs.get(((Object) (f1.getDialogID())));
if (f2 != null) {
Protocol.echo("TxHandler: using existing dialog with ID: "
+ f2.getDialogID());
return f2;
}
else {
Protocol.echo("TxHandler: created new dialog with ID: "
+ f1.getDialogID());
m_sipDialogs.put(((Object) (f1.getDialogID())), ((Object) (f1)));
return f1;
}
}
/**
* getSipDialog
*
* @param sipClientConnection
* @return SipDialog
*/
protected synchronized Dialog getSipClientDialog(
ClientConnection sipClientConnection) {
Dialog f1 = null;
int j = 0;
j = sipClientConnection.getStatusCode();
if (j == 0) {
Protocol.echo("TxHandler: internal error getting status code");
return null;
}
if (j < 101 || j > 299)
return null;
try {
f1 = new Dialog(sipClientConnection);
}
catch (Exception exception) {
Protocol.echo("TxHandler: ClientConnection no dialog for '"
+ sipClientConnection.getMethod() + "'");
return null;
}
Protocol.echo("TxHandler: created new dialog with ID: " + f1.getDialogID());
m_sipDialogs.put(((Object) (f1.getDialogID())), ((Object) (f1)));
return f1;
}
/**
* getSipDialog
*
* @param sipServerConnection
* @return SipDialog
*/
protected synchronized Dialog getSipDialog(
ServerConnection sipServerConnection) {
// Object obj = null;
String s1 = sipServerConnection.getHeader("Call-ID");
for (Enumeration enumeration = m_clientTransactions.elements(); enumeration
.hasMoreElements();) {
Object obj1 = enumeration.nextElement();
if (obj1 instanceof ClientTransaction) {
ClientConnection s2 = ((ClientTransaction) obj1).m_sipClientConnection;
SipHeader sipheader = new SipHeader("To", sipServerConnection
.getHeader("To"));
SipHeader sipheader1 = new SipHeader("From", s2.getHeader("From"));
String s3 = sipheader.getParameter("tag");
String s4 = sipheader1.getParameter("tag");
String s5 = s2.m_sipResponse.getHeaderValue("Event");
String s6 = sipServerConnection.getHeader("Event");
if (s5 != null && s6 != null && s3 != null && s4 != null) {
SipHeader sipheader2 = new SipHeader("Event", s5);
SipHeader sipheader3 = new SipHeader("Event", s6);
String s7 = sipheader2.getParameter("id");
String s8 = sipheader3.getParameter("id");
boolean flag = false;
if (s7 == null && s8 == null)
flag = true;
else if (s7 != null && s8 != null && s7.equals(((Object) (s8))))
flag = true;
if (s2.m_sipResponse.getHeaderValue("Call-ID")
.equals(((Object) (s1)))
&& s2.getMethod().equals("SUBSCRIBE")
&& sipheader2.getValue().equals(
((Object) (sipheader3.getValue())))
&& flag
&& s3.equals(((Object) (s4)))) {
Dialog f1;
try {
f1 = new Dialog(sipServerConnection, s2);
}
catch (Exception exception) {
Protocol.echo("TxHandler: ServerConnection no dialog for '"
+ sipServerConnection.getMethod() + "'");
return null;
}
Dialog f2 = (Dialog) m_sipDialogs
.get(((Object) (f1.getDialogID())));
if (f2 != null) {
Protocol.echo("TxHandler: using existing dialog with ID: "
+ f2.getDialogID());
return f2;
}
else {
s2.m_sipDialog = f1;
m_sipDialogs.put(((Object) (f1.getDialogID())), ((Object) (f1)));
Protocol
.echo("TxHandler: createDialogFromNotify: created new dialog with ID: "
+ f1.getDialogID());
return f1;
}
}
}
}
}
return null;
}
/**
* findSipDialog
*
* @param sipMessage
* @return SipDialog
*/
protected Dialog findSipDialog(SipMessage sipMessage) {
String s1 = Dialog.makeSipDialogID(sipMessage);
Dialog f1 = (Dialog) m_sipDialogs.get(((Object) (s1)));
return f1;
}
/**
* removeSipDialog
*
* @param id
*/
protected void removeSipDialog(String id) {
Dialog f1 = (Dialog) m_sipDialogs.remove(((Object) (id)));
if (f1 != null)
Protocol.echo("TxHandler: removed dialog with ID: " + f1.getDialogID());
else
Protocol.echo("TxHandler: can not remove dialog with ID: "
+ f1.getDialogID());
}
/**
* sendClientTx
*
* @param clientTransaction
* @param sipRequest
*/
public void sendClientTx(ClientTransaction clientTransaction,
SipRequest sipRequest) {
if (sipRequest.getMethod().equals("ACK")) {
Protocol
.echo("TxHandler.sendClientTx: passing ACK directly to transport");
// ClientTransaction _tmp = clientTransaction;
ClientTransaction.routeRequest(((SipMessage) (sipRequest)));
resendSipMessage(((SipMessage) (sipRequest)), false);
return;
}
else {
TimerTaskImpl.createTryingTask(((BaseTransaction) (clientTransaction)),
((SipMessage) (sipRequest))).run();
return;
}
}
/**
* startTryingTask
*
* @param serverTransaction
* @param sipResponse
*/
public void startTryingTask(ServerTransaction serverTransaction,
SipResponse sipResponse) {
TimerTaskImpl.createTryingTask(((BaseTransaction) (serverTransaction)),
((SipMessage) (sipResponse))).run();
}
/**
* resendSipMessage
*
* @param sipMessage
* @param needResend
*/
public void resendSipMessage(SipMessage sipMessage, boolean needResend) {
try {
if (needResend) {
Protocol.echo("Resending to: " + sipMessage.m_host + ":"
+ sipMessage.m_port);
}
else {
Protocol.echo("Sending to: " + sipMessage.m_host + ":"
+ sipMessage.m_port);
Protocol.echo("\n->->->-----------------------------------\n"
+ sipMessage.toString()
+ "\n-----------------------------------------");
}
m_listener.getDatagramController().sendSipMessage(sipMessage.m_host,
sipMessage.m_port, sipMessage.toString());
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* makeTransactionID, Server
*
* @param method
* @param viaValue
* @return transactionID
*/
private String makeTransactionID(String method, String viaValue) {
method = method.trim();
SipHeader sipheader = new SipHeader("Via", viaValue);
String s3 = sipheader.getValue();
String s4 = s3.substring(s3.indexOf(' ') + 1);
String s5 = sipheader.getParameter("branch");
s3 = method + s4 + s5;
return s3;
}
/**
* dispatch
*
* @param sipMessage
*/
public void dispatch(SipMessage sipMessage) {
Object obj = null;
String s1 = null;
if (sipMessage.isResponse())
s1 = makeTransactionID(((SipResponse) sipMessage).getMethod(), sipMessage
.getHeaderValue("Via"));
if (sipMessage.isRequest()) {
String s2 = sipMessage.getHeaderValue("Via");
if (s2 != null) {
String s4 = ((SipRequest) sipMessage).getMethod();
if (s4.equals("ACK"))
s4 = "INVITE";
s1 = makeTransactionID(s4, sipMessage.getHeaderValue("Via"));
}
}
if (sipMessage.isRequest()) {
String s3 = ((SipRequest) sipMessage).getMethod();
if (!s3.equals("ACK")) {
if (m_serverTransactions.get(((Object) (s1))) != null) {
Protocol.echo("TxHandler: " + s3 + " handled already, just ignore!");
return;
}
if (m_autoTrying && s3.equals("INVITE")) {
SipResponse c1 = ((SipRequest) sipMessage).getSipResponse();
c1.setStatusCode(100);
BaseTransaction.routeResponse(((SipMessage) (c1)), sipMessage);
m_txHandler.resendSipMessage(((SipMessage) (c1)), false);
}
}
Listener w1 = (Listener) m_listeners.get(((Object) (new Integer(
sipMessage.m_localPort))));
String s5 = Dialog.makeSipDialogID(sipMessage);
Protocol.echo("TxHandler: Dialog ID=" + s5);
Dialog f1 = (Dialog) m_sipDialogs.get(((Object) (s5)));
Notifier m1 = null;
if (f1 != null) {
Protocol.echo("TxHandler: Associate the Notifier to the Dialog");
m1 = f1.getSipConnectionNotifier();
if (m1 != null)
Protocol.echo("TxHandler: Notifier found from Dialog " + s5);
}
if (m1 == null) {
Protocol
.echo("TxHandler: Associate the Notifier to the ListeningPoint (e.g. Accept-Contact)");
m1 = w1.getNotifier(sipMessage);
if (m1 != null)
Protocol.echo("TxHandler: Notifier found from ListeningPoint port:"
+ w1.getPort());
}
if (s3.equals("ACK")) {
obj = ((Object) ((BaseTransaction) m_serverTransactions
.get(((Object) (s1)))));
if (obj != null) {
Protocol.echo("TxHandler.dispatch: trans id " + s1 + " found for "
+ s3);
TimerTaskImpl.createProceedingTask(((BaseTransaction) (obj)),
sipMessage).run();
return;
}
if (m1 != null) {
Protocol
.echo("TxHandler.dispatch: passing ACK up without new transaction object, id is: "
+ s1);
m1.addSipServerConnectionNotifier(((BaseTransaction) (null)),
(SipRequest) sipMessage);
return;
}
else {
Protocol
.echo("TxHandler.dispatch: ACK without Dialog and Notifier, just dropped");
return;
}
}
if (w1 != null && m1 != null) {
Protocol.echo("TxHandler.dispatch: new server transaction: " + s1);
obj = ((Object) (new ServerTransaction(this, m1)));
((ServerTransaction) obj).m_clientTransactionID = s1;
m_serverTransactions.put(((Object) (s1)), obj);
if (obj != null)
TimerTaskImpl.createProceedingTask(((BaseTransaction) (obj)),
sipMessage).run();
}
else {
if (w1 == null)
Protocol.echo("TxHandler: no listening point on "
+ sipMessage.m_localPort);
else
Protocol.echo("TxHandler: no associated listener on "
+ sipMessage.m_localPort);
SipResponse c2 = ((SipRequest) sipMessage).getSipResponse();
c2.setStatusCode(480);
BaseTransaction.routeResponse(((SipMessage) (c2)), sipMessage);
m_txHandler.resendSipMessage(((SipMessage) (c2)), false);
}
return;
}
Protocol.echo("TxHandler.dispatch: response in " + s1);
obj = ((Object) ((BaseTransaction) m_clientTransactions
.get(((Object) (s1)))));
if (obj == null)
Protocol.echo("TxHandler.dispatch: unable to find transcation " + s1);
else
TimerTaskImpl.createProceedingTask(((BaseTransaction) (obj)), sipMessage)
.run();
}
/**
* removeListener
*
* @param port
* listenerID
*/
public void removeListener(int port) {
Listener w1 = (Listener) m_listeners.remove(((Object) (new Integer(port))));
if (w1 != null)
Protocol.echo("TxHandler: removed listening point " + w1.getPort());
if (m_listeners.isEmpty())
m_useable = false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -