📄 callprocessing.java.svn-base
字号:
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
package net.java.sipmack.sip;
import gov.nist.javax.sip.header.CSeq;
import gov.nist.javax.sip.header.Via;
import gov.nist.javax.sip.message.SIPRequest;
import net.java.sipmack.common.Log;
import net.java.sipmack.sip.security.SipSecurityException;
import javax.sip.ClientTransaction;
import javax.sip.Dialog;
import javax.sip.InvalidArgumentException;
import javax.sip.ServerTransaction;
import javax.sip.SipException;
import javax.sip.Transaction;
import javax.sip.TransactionUnavailableException;
import javax.sip.address.Address;
import javax.sip.address.SipURI;
import javax.sip.address.URI;
import javax.sip.header.*;
import javax.sip.message.Request;
import javax.sip.message.Response;
import java.text.ParseException;
import java.util.ArrayList;
import org.jivesoftware.spark.phone.PhoneManager;
/**
* <p/>
* Title: SIP COMMUNICATOR-1.1
* </p>
* <p/>
* Description: JAIN-SIP-1.1 Audio/Video Phone Application
* </p>
* <p/>
* Copyright: Copyright (c) 2003
* </p>
* <p/>
* Company: Organisation: LSIIT Laboratory (http://lsiit.u-strasbg.fr)
* <p/>
* </p>
* Network Research Team (http://www-r2.u-strasbg.fr))
* <p/>
* </p>
* Louis Pasteur University - Strasbourg - France
* </p>
*
* @author Emil Ivov
* @version 1.1
*/
public class CallProcessing {
protected SipManager sipManCallback = null;
protected CallDispatcher callDispatcher = new CallDispatcher();
CallProcessing() {
}
CallProcessing(SipManager sipManCallback) {
this.sipManCallback = sipManCallback;
}
void setSipManagerCallBack(SipManager sipManCallback) {
this.sipManCallback = sipManCallback;
}
// ============================= Remotely Initiated Processing
// ===================================
// ----------------------------- Responses
void processTrying(ClientTransaction clientTransaction, Response response) {
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
if (call == null) {
sipManCallback.fireUnknownMessageReceived(response);
return;
}
// change status
if (!call.getState().equals(Call.MOVING_LOCALLY))
call.setState(Call.DIALING);
}
void processRinging(ClientTransaction clientTransaction, Response response) {
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
String sdp = response.getRawContent() != null ? response
.getRawContent().toString() : "";
call.setRemoteSdpDescription(sdp);
if (call == null) {
// ?maybe we should just ignore it?
sipManCallback.fireUnknownMessageReceived(response);
return;
}
// change status
call.setState(Call.RINGING);
}
void processRingingBack(ClientTransaction clientTransaction,
Response response) {
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
call.setRemoteSdpDescription(new String(response.getRawContent()));
if (call == null) {
// ?maybe we should just ignore it?
sipManCallback.fireUnknownMessageReceived(response);
return;
}
// change status
call.setState(Call.RINGING);
}
/**
* According to the RFC a UAC canceling a request cannot rely on receiving a
* 487 (Request Terminated) response for the original request, as an RFC
* 2543- compliant UAS will not generate such a response. So we are closing
* the call when sending the cancel request and here we don't do anything.
*
* @param clientTransaction
* @param response
*/
void processRequestTerminated(ClientTransaction clientTransaction,
Response response) {
try {
// add any additional code here
}
finally {
}
}
void processByeOK(ClientTransaction clientTransaction, Response response) {
try {
// add any additional code here
}
finally {
}
}
void processCancelOK(ClientTransaction clientTransaction, Response response) {
try {
// add any additional code here
}
finally {
}
}
void processInviteOK(ClientTransaction clientTransaction, Response ok) {
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
if (call == null) {
sipManCallback.fireUnknownMessageReceived(ok);
return;
}
// Send ACK
try {
// Need to use dialog generated ACKs so that the remote UA core
// sees them - Fixed by M.Ranganathan
Request ack = (Request) clientTransaction.getDialog()
.createRequest(Request.ACK);
clientTransaction.getDialog().sendAck(ack);
}
catch (SipException ex) {
call.setState(Call.DISCONNECTED);
sipManCallback
.fireCommunicationsError(new CommunicationsException(
"Failed to acknowledge call!", ex));
return;
}
call.setRemoteSdpDescription(new String(ok.getRawContent()));
// change status
if (!call.getState().equals(Call.CONNECTED)) {
call.setState(Call.CONNECTED);
}
}
void processBusyHere(ClientTransaction clientTransaction, Response busyHere) {
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
if (call == null) {
sipManCallback.fireUnknownMessageReceived(busyHere);
return;
}
// change status
call.setState(Call.BUSY);
// it is the stack that should be sending the ACK so don't do it
// here
}
void processCallError(ClientTransaction clientTransaction,
Response notAcceptable) {
// find the call
Call call = callDispatcher.findCall(clientTransaction.getDialog());
if (call == null) {
sipManCallback.fireUnknownMessageReceived(notAcceptable);
return;
}
// change status
call.setState(Call.FAILED);
sipManCallback.fireCommunicationsError(new CommunicationsException(
"Remote party returned error response: "
+ notAcceptable.getStatusCode() + " - "
+ notAcceptable.getReasonPhrase()));
return;
// it is the stack that should be sending the ACK so don't do it
// here
}
/**
* Attempts to re-ogenerate the corresponding request with the proper
* credentials and terminates the call if it fails.
*
* @param clientTransaction the corresponding transaction
* @param response the challenge
*/
void processAuthenticationChallenge(ClientTransaction clientTransaction,
Response response) {
try {
Request challengedRequest = clientTransaction.getRequest();
ClientTransaction retryTran = sipManCallback.sipSecurityManager
.handleChallenge(response, clientTransaction);
// There is a new dialog that will be started with this request. Get
// that dialog and record it into the Call objet for later use (by
// Bye-s for example).
Call call = callDispatcher.findCall(clientTransaction.getDialog());
call.setDialog(retryTran.getDialog());
call.setInitialRequest(retryTran.getRequest());
retryTran.sendRequest();
}
catch (SipSecurityException exc) {
callDispatcher.findCall(clientTransaction.getDialog()).setState(
Call.FAILED);
sipManCallback.fireCommunicationsError(new CommunicationsException(
"Authorization failed!", exc));
}
catch (Exception exc) {
callDispatcher.findCall(clientTransaction.getDialog()).setState(
Call.FAILED);
sipManCallback.fireCommunicationsError(new CommunicationsException(
"Failed to resend a request "
+ "after a security challenge!", exc));
}
}
// -------------------------- Requests ---------------------------------
void processInvite(ServerTransaction serverTransaction, Request invite) {
Dialog dialog = serverTransaction.getDialog();
if (!sipManCallback.isBusy() && !(PhoneManager.isUseStaticLocator()&&PhoneManager.isUsingMediaLocator())) {
Call call = callDispatcher.createCall(dialog, invite);
sipManCallback.fireCallReceived(call);
// change status
call.setState(Call.ALERTING);
// sdp description may be in acks - bug report Laurent Michel
ContentLengthHeader cl = invite.getContentLength();
if (cl != null && cl.getContentLength() > 0) {
call.setRemoteSdpDescription(new String(invite
.getRawContent()));
}
// Are we the one they are looking for?
URI calleeURI = ((ToHeader) invite.getHeader(ToHeader.NAME))
.getAddress().getURI();
/**
* @todo We shoud rather ask the user what to do here as some
* would add prefixes or change user URIs
*/
if (calleeURI.isSipURI()) {
boolean assertUserMatch = SIPConfig
.isFailCallInUserMismatch();
// user info is case sensitive according to rfc3261
if (assertUserMatch) {
String calleeUser = ((SipURI) calleeURI).getUser();
String localUser = sipManCallback.getLocalUser();
if (calleeUser != null && !calleeUser.equals(localUser)) {
sipManCallback
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -