FileDocCategorySizeDatePackage
Subscription.javaAPI DocphoneME MR2 API (J2ME)4985Wed May 02 18:00:42 BST 2007gov.nist.siplite.stack

Subscription

public class Subscription extends Object
Subscription object.

Fields Summary
private Dialog
dialog
Reference to the dialog which this subscription belongs to.
private EventHeader
eventHeader
Event header defining this subscription
Constructors Summary
public Subscription(Dialog subscriptionDialog, Request request)
Constructor given a dialog and a request creating the subscription.

param
subscriptionDialog
param
request


                       
         
        // System.out.println("*** Creating a new SUBSCRIPTION, dialog = " +
        //     subscriptionDialog);

        dialog = subscriptionDialog;

        if (request.getMethod().equalsIgnoreCase(Request.REFER)) {
            // RFC 3515, p. 2:
            // A REFER request implicitly establishes a subscription
            // to the refer event.
            eventHeader = new EventHeader();
            try {
                eventHeader.setEventType(Request.REFER);
            } catch (ParseException pe) {
                // Request.REFER is a valid event type,
                // so we can't get here.
            }
        } else {
            EventHeader eh = (EventHeader)request.getHeader(Header.EVENT);
            if (eh != null) {
                eventHeader = (EventHeader)eh.clone();
            }
        }
    
Methods Summary
public booleancontainsSubscription(Message message)
Return true if the given response message or NOTIFY request matches this subscription.

param
message a response or NOTIFY request to check for matching
return
true if the given NOTIFY matches this subscription, false otherwise

        CallIdHeader hCallId = (CallIdHeader)message.getHeader(Header.CALL_ID);
        if (hCallId == null) {
            return false;
        }

        // Get callId and fromTag from the dialog.
        CallIdHeader callId = dialog.getCallId();
        if (callId == null) {
            return false;
        }

        String fromTag = dialog.isServer() ?
	    dialog.getRemoteTag() : dialog.getLocalTag();
        if (fromTag == null) {
            return false;
        }

        if (message instanceof Response) {
            /*
             * RFC3265, section 3.3.4
             * Responses are matched to such SUBSCRIBE requests if they
             * contain the same the same "Call-ID", the same "From" header
             * "tag", and the same "CSeq".
             *
             * IMPL_NOTE: compare CSeq
             */
            String fTag = message.getFromHeaderTag();
            if (fTag == null) {
                return false;
            }

            return (hCallId.equals(callId) && fTag.equalsIgnoreCase(fromTag));
        }

        /*
         * RFC 3265, section 3.3.4:
         * If an initial SUBSCRIBE request is not sent on a pre-existing dialog,
         * the subscriber will wait for a response to the SUBSCRIBE request or a
         * matching NOTIFY.
         *
         * NOTIFY requests are matched to such SUBSCRIBE requests if they
         * contain the same "Call-ID", a "To" header "tag" parameter which
         * matches the "From" header "tag" parameter of the SUBSCRIBE, and the
         * same "Event" header field.
         */
        EventHeader hEvent = (EventHeader)message.getHeader(Header.EVENT);
        if (hEvent == null) {
            String reqMethod = ((Request)message).getMethod();
            if (reqMethod.equalsIgnoreCase(Request.REFER)) {
                hEvent = eventHeader;
            } else {
                return false;
            }
        }

        String toTag = message.getToTag();
        if (toTag == null) {
            return false;
        }

        return (hEvent.match(eventHeader) && toTag.equalsIgnoreCase(fromTag) &&
            hCallId.equals(callId));