Search in sources :

Example 1 with ExpiresHeader

use of javax.sip.header.ExpiresHeader in project Openfire by igniterealtime.

the class SimpleListener method processResponse.

public void processResponse(ResponseEvent responseEvent) {
    if (responseEvent.getClientTransaction() != null) {
        Log.debug("SimpleListener for " + myUsername + ":  Getting client transaction...");
        ClientTransaction clientTransaction = responseEvent.getClientTransaction();
        Dialog clientDialog = clientTransaction.getDialog();
        getSession().printDialog(clientDialog);
    }
    Log.debug("SimpleListener for " + myUsername + ":  Received a response event:  " + responseEvent.getResponse().toString());
    //		String   fromAddr = "";
    String toAddr = "";
    Response response = responseEvent.getResponse();
    //		}
    if (response.getHeader(ToHeader.NAME) != null) {
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        URI toUri = toHeader.getAddress().getURI();
        if (toUri instanceof SipUri)
            toAddr = ((SipUri) toUri).getUser() + "@" + ((SipUri) toUri).getHost();
        else
            toAddr = toUri.toString();
    }
    if (response.getHeader(CSeqHeader.NAME) != null) {
        String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
        if (method.equals(Request.REGISTER)) {
            if (response.getStatusCode() / 100 == 2) {
                int expires = 0;
                if (response.getHeader(ContactHeader.NAME) != null) {
                    expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
                } else if (response.getHeader(ExpiresHeader.NAME) != null) {
                    expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
                }
                if (expires > 0) {
                    Log.debug("SimpleListener(" + myUsername + ").processResponse:  " + getSession().getRegistration().getUsername() + " log in successful!");
                    getSession().sipUserLoggedIn();
                } else {
                    if (getSession().getLoginStatus().equals(TransportLoginStatus.LOGGING_OUT)) {
                        Log.debug("SimpleListener(" + myUsername + ").processResponse:  " + getSession().getRegistration().getUsername() + " log out successful!");
                        getSession().sipUserLoggedOut();
                        getSession().removeStack();
                    }
                }
            }
        }
        if (method.equals(Request.SUBSCRIBE)) {
            if (response.getStatusCode() / 100 == 2) {
                Log.debug("SimpleListener for " + myUsername + ":  Handling SUBSCRIBE acknowledgement!!");
                int expires = 0;
                if (response.getHeader(ContactHeader.NAME) != null) {
                    expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
                }
                if (response.getHeader(ExpiresHeader.NAME) != null) {
                    expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
                }
                if (expires > 0) {
                    // Confirm subscription of roster item
                    getSession().contactSubscribed(toAddr);
                } else {
                    // Confirm unsubscription of roster item
                    getSession().contactUnsubscribed(toAddr);
                }
                Log.debug("SimpleListener for " + myUsername + ":  Handled SUBSCRIBE acknowledgement!!");
            }
        }
    }
}
Also used : Response(javax.sip.message.Response) CSeqHeader(javax.sip.header.CSeqHeader) Dialog(javax.sip.Dialog) ClientTransaction(javax.sip.ClientTransaction) ToHeader(javax.sip.header.ToHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) SipUri(gov.nist.javax.sip.address.SipUri) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI)

Aggregations

SipUri (gov.nist.javax.sip.address.SipUri)1 ClientTransaction (javax.sip.ClientTransaction)1 Dialog (javax.sip.Dialog)1 SipURI (javax.sip.address.SipURI)1 URI (javax.sip.address.URI)1 CSeqHeader (javax.sip.header.CSeqHeader)1 ExpiresHeader (javax.sip.header.ExpiresHeader)1 ToHeader (javax.sip.header.ToHeader)1 Response (javax.sip.message.Response)1