FileDocCategorySizeDatePackage
SipDialogImpl.javaAPI DocphoneME MR2 API (J2ME)12610Wed May 02 18:00:42 BST 2007gov.nist.microedition.sip

SipDialogImpl

public class SipDialogImpl extends Object implements javax.microedition.sip.SipDialog
SIP Dialog implementation. This code is in the public domain.

Fields Summary
protected static final int
INITIALIZED
Initialized, initial state of dialog. This state is initialized in this class instead of SipDialog interface as it is an internal state
private byte
state
current state of the dialog
private String
dialogID
dialogID (Call-ID + remote tag + local tag).
protected gov.nist.siplite.stack.Dialog
dialog
This implementation of dialog is linked to the Nist-Siplite dialog
private javax.microedition.sip.SipConnectionNotifier
sipConnectionNotifier
Current handle to asynchronous notifier.
private javax.microedition.sip.SipClientConnectionListener
sipClientConnectionListener
Handle for current listener.
protected gov.nist.siplite.header.ProxyAuthorizationHeader
proxyAuthorizationHeader
Proxy server autorization headers.
protected gov.nist.siplite.header.AuthorizationHeader
authorizationHeader
Authorization header key.
private com.sun.midp.security.SecurityToken
classSecurityToken
Security token for SIP/SIPS protocol class
private String
refreshID
The refresh ID of the refresh task associated with this client connection if there is any
protected boolean
isReliableProvReceived
Permission check before sending a PRACK request.
private boolean
waitForBye
True if this dialog can't be terminated until BYE is received.
Constructors Summary
protected SipDialogImpl(gov.nist.siplite.stack.Dialog dialog, javax.microedition.sip.SipConnectionNotifier sipConnectionNotifier, com.sun.midp.security.SecurityToken classSecurityToken)
Constructs this dialog based upon the Nist-Siplite dialog

param
dialog Nist-Siplite dialog
param
sipConnectionNotifier the notification handler
param
classSecurityToken Security token for SIP/SIPS protocol class with this client connection


                                      
      
             
              
        state = INITIALIZED;

        if (dialog != null) {
            dialogID = dialog.getDialogId();
            int underlyingDlgState = dialog.getState();

            if (underlyingDlgState == Dialog.CONFIRMED_STATE) {
                state = CONFIRMED;
            } else if (underlyingDlgState == Dialog.COMPLETED_STATE ||
                       underlyingDlgState == Dialog.TERMINATED_STATE) {
                state = TERMINATED;
            }
        }

        this.dialog = dialog;
        this.sipConnectionNotifier = sipConnectionNotifier;
        this.classSecurityToken = classSecurityToken;
    
Methods Summary
protected voidaddSubscription(gov.nist.siplite.stack.Subscription s)
Adds a new subscription to the list of active subscriptions.

param
s a subscription to add

        dialog.subscriptionList.addSubscription(s);
    
protected gov.nist.siplite.stack.DialoggetDialog()
Gets the curre SIP Dialog.

return
the current Dialog handle

        return dialog;
    
public java.lang.StringgetDialogID()
Returns the ID of the SIP Dialog.

return
Dialog ID (Call-ID + remote tag + local tag). Returns null if the dialog is terminated.

        if (state  ==  TERMINATED) {
            return null;
        }
        return dialogID;
    
public javax.microedition.sip.SipClientConnectiongetNewClientConnection(java.lang.String method)
Returns new SipClientConnection in this dialog. The SipClientConnection will be pre-initialized with the given method and following headers will be set at least (for details see RFC 3261 [1] 12.2.1.1 Generating the Request, p.73):
To
From
CSeq
Call-ID
Max-Forwards
Via
Contact
Route//ifthedialogrouteisnotempty

param
method - given method
return
SipClientConnection with preset headers.
throws
IllegalArgumentException - if the method is invalid
throws
SipException - INVALID_STATE if the new connection can not be established in the current state of dialog.


        // JSR180: all methods are available in CONFIRMED and EARLY states.
        if (state != SipDialog.CONFIRMED && state != SipDialog.EARLY) {
            throw new SipException("the client connection can not "
                    + "be initialized, because of wrong state.",
                    SipException.INVALID_STATE);
        }

        // Validating the method.
        if (!Lexer.isValidName(method)) {
            throw new IllegalArgumentException("Invalid method: '" +
                method + "'");
        }

        // Create the new sip client connection
        // and init the request
        SipClientConnection sipClientConnection =
                new SipClientConnectionImpl(
                    getDialog().getRemoteTarget().getURI(), this);
        // ((SipClientConnectionImpl)sipClientConnection).start();

        if ((sipConnectionNotifier != null) &&
            !((SipConnectionNotifierImpl)sipConnectionNotifier).
                isConnectionOpen()) {
            sipConnectionNotifier = null;
        }

        sipClientConnection.initRequest(method.toUpperCase().trim(),
            sipConnectionNotifier);

        // keep a trace of the connection created
        return sipClientConnection;
    
protected java.lang.StringgetRefreshID()
Gets the current refreshID.

return
the current refreshID

        return refreshID;
    
protected com.sun.midp.security.SecurityTokengetSecurityToken()
Gets the current security token.

return
the current security token

        return classSecurityToken;
    
protected javax.microedition.sip.SipClientConnectionListenergetSipClientConnectionListener()
Gets the current listener.

return
the current listener

        return sipClientConnectionListener;
    
public bytegetState()
Returns the state of the SIP Dialog.

return
dialog state byte number.

        return state;
    
protected voidhandleNotify(Request request, gov.nist.siplite.stack.Dialog newDialog, java.lang.String newDialogId)
Handles NOTIFY request.

param
request NOTIFY message
param
newDialog a new underlying dialog implementation to associate with this dialog, may be null
param
newDialogId a new dialog id to set for this dialog

        SubscriptionStateHeader ssh = (SubscriptionStateHeader)
            request.getHeader(Header.SUBSCRIPTION_STATE);

        if (ssh != null && ssh.isTerminated()) {
            Subscription s =
                dialog.subscriptionList.getMatchingSubscription(request);

            if (s != null) {
                dialog.subscriptionList.removeSubscription(s);
            }

            if (dialog.isSubscribeDialog() || dialog.isInviteDialog()) {
                // IMPL_NOTE: currently we don't handle the following scenario:
                //
                // INVITE/200OK - INVITE/200OK - SUBSCRIBE/200OK - BYE/200OK -
                // NOTIFY(terminate subscription)/200OK - (*) ...
                //
                // At the point (*) the dialog will be in TERMINATED state
                // what is incorrect.
                terminateIfNoSubscriptions();
            }
        } else {
            setState(CONFIRMED);

            if (newDialog != null) {
                setDialog(newDialog);
            } else {
                setDialogID(newDialogId);
            }
        }
    
public booleanisSameDialog(javax.microedition.sip.SipConnection sc)
Does the given SipConnection belong to this dialog.

param
sc - SipConnection to be checked, can be either SipClientConnection or SipServerConnection
return
true if the SipConnection belongs to the this dialog. Returns false if the connection is not part of this dialog or the dialog is terminated.

        if (state == SipDialog.TERMINATED || sc == null) {
            return false;
        }

        SipDialog dlg = sc.getDialog();

        if (dlg != null) {
            String id = dlg.getDialogID();
            if (id != null && id.equals(dialogID)) {
                return true;
            }
        }

        return false;
    
protected voidremoveSubscription(Message message)
Removes the subscription matching the given response or NOTIFY from the list of active subscriptions.

param
message response or NOTIFY message

        Subscription s =
            dialog.subscriptionList.getMatchingSubscription(message);
        if (s != null) {
            dialog.subscriptionList.removeSubscription(s);
        }
    
protected voidsetDialog(gov.nist.siplite.stack.Dialog newDialog)
Sets the current Dialog handler.

param
newDialog the new Dialog

        dialog = newDialog;
        setDialogID(newDialog.getDialogId());
    
protected voidsetDialogID(java.lang.String newDialogID)
Sets the Dialog identifier.

param
newDialogID dialog identifier

        dialogID = newDialogID;
    
protected voidsetRefreshID(java.lang.String newRefreshID)
Sets the current refreshID.

param
newRefreshID new refreshID value

        refreshID = newRefreshID;
    
protected voidsetSipClientConnectionListener(javax.microedition.sip.SipClientConnectionListener newSipClientConnectionListener)
Sets the current connection listener.

param
newSipClientConnectionListener the new listener

        sipClientConnectionListener = newSipClientConnectionListener;
    
protected voidsetState(byte newState)
Changes the state of this dialog

param
newState the new state of this dialog

        state = newState;
    
protected voidsetWaitForBye(boolean bye)
Accessor for 'waitForBye' field.

param
bye true if we have to wait until 'BYE' is received to terminate the dialog, false otherwise

        waitForBye = bye;
    
protected voidterminateIfNoSubscriptions()
Changes the state of this dialog to TERMINATED if there are no active subscriptions.

        if (dialog == null) {
            setState(TERMINATED);
            return;
        }

        if (dialog.subscriptionList.isEmpty() && !waitForBye) {
            // TERMINATE the dialog
            setState(TERMINATED);
        }