📄 callprocessing.java
字号:
.fireCallRejectedLocally(
"The user specified by the caller did not match the local user!",
invite, call);
call.setState(Call.DISCONNECTED);
Response notFound = null;
try {
notFound = sipManCallback.messageFactory
.createResponse(Response.NOT_FOUND,
invite);
sipManCallback.attachToTag(notFound, dialog);
}
catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to create a NOT_FOUND response to an INVITE request!",
ex));
return;
}
try {
serverTransaction.sendResponse(notFound);
}
catch (SipException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a NOT_FOUND response to an INVITE request!",
ex));
return;
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a NOT_FOUND response to an INVITE request!",
e));
return;
}
return;
}
}
}
// Send RINGING
Response ringing = null;
try {
ringing = sipManCallback.messageFactory.createResponse(
Response.RINGING, invite);
sipManCallback.attachToTag(ringing, dialog);
}
catch (ParseException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to create a RINGING response to an INVITE request!",
ex));
return;
}
try {
serverTransaction.sendResponse(ringing);
}
catch (SipException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a RINGING response to an INVITE request!",
ex));
return;
} catch (InvalidArgumentException e) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a NOT_FOUND response to an INVITE request!",
e));
return;
}
} else {
// Send BUSY_HERE
Response busy = null;
try {
busy = sipManCallback.messageFactory.createResponse(
Response.BUSY_HERE, invite);
sipManCallback.attachToTag(busy, dialog);
}
catch (ParseException ex) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to create a RINGING response to an INVITE request!",
ex));
return;
}
try {
serverTransaction.sendResponse(busy);
}
catch (SipException ex) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a RINGING response to an INVITE request!",
ex));
return;
} catch (InvalidArgumentException e) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a RINGING response to an INVITE request!",
e));
return;
}
}
}
void processTimeout(Transaction transaction, Request request) {
Call call = callDispatcher.findCall(transaction.getDialog());
if (call == null) {
return;
}
sipManCallback.fireCommunicationsError(new CommunicationsException(
"The remote party has not replied!"
+ "The call will be disconnected"));
// change status
call.setState(Call.DISCONNECTED);
}
void processBye(ServerTransaction serverTransaction, Request byeRequest) {
try {
// find the call
Call call = callDispatcher.findCall(serverTransaction.getDialog());
if (call == null) {
Log.debug("No call find");
sipManCallback.fireUnknownMessageReceived(byeRequest);
return;
}
// change status
call.setState(Call.DISCONNECTED);
// Send OK
Response ok = null;
try {
ok = sipManCallback.messageFactory.createResponse(Response.OK,
byeRequest);
sipManCallback.attachToTag(ok, call.getDialog());
}
catch (ParseException ex) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to construct an OK response to a BYE request!",
ex));
return;
}
try {
serverTransaction.sendResponse(ok);
}
catch (SipException ex) {
// This is not really a problem according to the RFC
// so just dump to stdout should someone be interested
}
endCall(call.getID());
}
catch (Exception e) {
Log.error("processBye", e);
}
}
void processAck(ServerTransaction serverTransaction, Request ackRequest) {
if (!serverTransaction.getDialog().getFirstTransaction()
.getRequest().getMethod().equals(Request.INVITE)) {
return;
}
// find the call
Call call = callDispatcher.findCall(serverTransaction.getDialog());
if (call == null) {
// this is most probably the ack for a killed call - don't
// signal it
// sipManCallback.fireUnknownMessageReceived(ackRequest);
return;
}
ContentLengthHeader cl = ackRequest.getContentLength();
if (cl != null && cl.getContentLength() > 0) {
call.setRemoteSdpDescription(new String(ackRequest
.getRawContent()));
}
// change status
call.setState(Call.CONNECTED);
}
void processCancel(ServerTransaction serverTransaction,
Request cancelRequest) {
if (!serverTransaction.getDialog().getFirstTransaction()
.getRequest().getMethod().equals(Request.INVITE)) {
// For someone else
return;
}
// find the call
Call call = callDispatcher.findCall(serverTransaction.getDialog());
if (call == null) {
sipManCallback.fireUnknownMessageReceived(cancelRequest);
return;
}
// change status
call.setState(Call.DISCONNECTED);
// Cancels should be OK-ed and the initial transaction - terminated
// (report and fix by Ranga)
try {
Response ok = sipManCallback.messageFactory.createResponse(
Response.OK, cancelRequest);
sipManCallback.attachToTag(ok, call.getDialog());
serverTransaction.sendResponse(ok);
}
catch (ParseException ex) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to create an OK Response to an CANCEL request.",
ex));
}
catch (SipException ex) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send an OK Response to an CANCEL request.",
ex));
} catch (InvalidArgumentException e) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a NOT_FOUND response to an INVITE request!",
e));
}
try {
// stop the invite transaction as well
Transaction tran = call.getDialog().getFirstTransaction();
// should be server transaction and misplaced cancels should be
// filtered by the stack but it doesn't hurt checking anyway
if (!(tran instanceof ServerTransaction)) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Received a misplaced CANCEL request!"));
return;
}
ServerTransaction inviteTran = (ServerTransaction) tran;
Request invite = call.getDialog().getFirstTransaction()
.getRequest();
Response requestTerminated = sipManCallback.messageFactory
.createResponse(Response.REQUEST_TERMINATED, invite);
sipManCallback.attachToTag(requestTerminated, call.getDialog());
inviteTran.sendResponse(requestTerminated);
}
catch (ParseException ex) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to create a REQUEST_TERMINATED Response to an INVITE request.",
ex));
}
catch (SipException ex) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send an REQUEST_TERMINATED Response to an INVITE request.",
ex));
} catch (InvalidArgumentException e) {
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to send a NOT_FOUND response to an INVITE request!",
e));
}
}
// ----------------- Responses --------------------------
// NOT FOUND
void processNotFound(ClientTransaction clientTransaction, Response response) {
if (!clientTransaction.getDialog().getFirstTransaction()
.getRequest().getMethod().equals(Request.INVITE)) {
// Not for us
return;
}
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
if (call != null)
call.setState(Call.DISCONNECTED);
sipManCallback.fireCallRejectedRemotely(
"Number NOT found at the server.", response, call);
}
void processNotImplemented(ClientTransaction clientTransaction,
Response response) {
if (!clientTransaction.getDialog().getFirstTransaction()
.getRequest().getMethod().equals(Request.INVITE)) {
// Not for us
return;
}
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
call.setState(Call.DISCONNECTED);
sipManCallback.fireCallRejectedRemotely(
"Server cannot dial this number.", response, call);
}
// -------------------------------- User Initiated processing
// ---------------------------------
Call invite(String callee, String sdpContent)
throws CommunicationsException {
callee = callee.trim();
// Remove excessive characters from phone numbers such as '
// ','(',')','-'
String excessiveChars = SIPConfig.getExcessiveURIChar();
if (excessiveChars != null) {
StringBuffer calleeBuff = new StringBuffer(callee);
for (int i = 0; i < excessiveChars.length(); i++) {
String charToDeleteStr = excessiveChars.substring(i, i + 1);
int charIndex = -1;
while ((charIndex = calleeBuff.indexOf(charToDeleteStr)) != -1)
calleeBuff.delete(charIndex, charIndex + 1);
}
callee = calleeBuff.toString();
}
// Handle default domain name (i.e. transform 1234 -> 1234@sip.com
String defaultDomainName = SIPConfig.getDefaultDomain();
if (defaultDomainName != null // no sip scheme
&& !callee.trim().startsWith("tel:")
&& callee.indexOf('@') == -1 // most probably a sip uri
) {
callee = callee + "@" + defaultDomainName;
}
// Let's be uri fault tolerant
if (callee.toLowerCase().indexOf("sip:") == -1 // no sip scheme
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -