Search in sources :

Example 1 with CallIdHeader

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

the class SimpleSession method prepareRequest.

/**
     * @param requestType Type of request
	 * @param destUri    The SipURI for the destination.  Leave <code>null</code> if a loopback request (e.g. REGISTER) is being made.
	 * @param toTag      The tag for to header.  Can leave null.
	 * @param requestUri The Request URI to set in the message.  Leave null if the default destination SipURI should be used.
     * @param callId     ID of call
     * @param seqNum     Sequence number
     * @return Prepared request
	 */
private Request prepareRequest(RequestType requestType, SipURI destUri, String toTag, SipURI requestUri, String callId, long seqNum) {
    Request request = null;
    String myXMPPUsername = this.jid.getNode();
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing request packet of type '" + requestType + "'");
    try {
        // Prepare request packet first
        request = messageFactory.createRequest(null);
        request.setMethod(requestType.toString());
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing request.", e);
    }
    // Prepare "From" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"From\" header...");
    String mySipUsername = registration.getUsername();
    try {
        SipURI fromUri = addressFactory.createSipURI(mySipUsername, sipHost);
        Address fromNameAddress = addressFactory.createAddress(fromUri);
        fromNameAddress.setDisplayName(mySipUsername);
        FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, getTag());
        // Use "set" because this header is mandatory.
        request.setHeader(fromHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing FromHeader.", e);
        return null;
    }
    // Prepare "To" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"To\" header...");
    try {
        if (destUri == null)
            destUri = addressFactory.createSipURI(mySipUsername, sipHost);
        Address toNameAddress = addressFactory.createAddress(destUri);
        ToHeader toHeader = headerFactory.createToHeader(toNameAddress, toTag);
        // Use "set" because this header is mandatory.
        request.setHeader(toHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing ToHeader.", e);
        return null;
    }
    // Prepare "Via" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"Via\" header...");
    try {
        ViaHeader viaHeader = headerFactory.createViaHeader(InetAddress.getLocalHost().getHostAddress(), sipPort, ListeningPoint.UDP, null);
        // Use "set" because this header is mandatory.
        request.setHeader(viaHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing ViaHeader.", e);
        return null;
    }
    // Prepare "CallId" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"CallId\" header...");
    CallIdHeader callIdHeader;
    try {
        if (callId != null)
            callIdHeader = headerFactory.createCallIdHeader(callId);
        else
            callIdHeader = udpSipProvider.getNewCallId();
        // Use "set" because this header is mandatory.
        request.setHeader(callIdHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing CallIdHeader.", e);
        return null;
    }
    // Prepare "CSeq" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"CSeq\" header...");
    try {
        CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(seqNum, requestType.toString());
        // Use "set" because this header is mandatory.
        request.setHeader(cSeqHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing CSeqHeader.", e);
        return null;
    }
    // Prepare "MaxForwards" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"MaxForwards\" header...");
    try {
        MaxForwardsHeader maxForwardsHeader = headerFactory.createMaxForwardsHeader(70);
        // Use "set" because this header is mandatory.
        request.setHeader(maxForwardsHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing MaxForwardsHeader.", e);
        return null;
    }
    // Setting Request URI
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  setting request URI...");
    try {
        if (requestUri == null) {
            requestUri = (SipURI) destUri.clone();
            requestUri.setTransportParam(ListeningPoint.UDP);
        }
        request.setRequestURI(requestUri);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when setting request URI.", e);
        return null;
    }
    // Add "Contact" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"Contact\" header...");
    try {
        SipURI contactURI = addressFactory.createSipURI(mySipUsername, InetAddress.getLocalHost().getHostAddress());
        contactURI.setPort(sipPort);
        Address contactAddress = addressFactory.createAddress(contactURI);
        contactAddress.setDisplayName(mySipUsername);
        ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
        request.setHeader(contactHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when adding ContactHeader.", e);
        return null;
    }
    return request;
}
Also used : CSeqHeader(javax.sip.header.CSeqHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ContactHeader(javax.sip.header.ContactHeader) InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) ViaHeader(javax.sip.header.ViaHeader) FromHeader(javax.sip.header.FromHeader) Request(javax.sip.message.Request) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 2 with CallIdHeader

use of javax.sip.header.CallIdHeader in project XobotOS by xamarin.

the class SIPTransactionStack method auditDialogs.

/**
     * Audits SIP dialogs for leaks - Compares the dialogs in the dialogTable with a list of Call
     * IDs passed by the application. - Dialogs that are not known by the application are leak
     * suspects. - Kill the dialogs that are still around after the timer specified.
     *
     * @return Audit report, null if no dialog leaks were found
     */
private String auditDialogs(Set activeCallIDs, long leakedDialogTimer) {
    String auditReport = "  Leaked dialogs:\n";
    int leakedDialogs = 0;
    long currentTime = System.currentTimeMillis();
    // Make a shallow copy of the dialog list.
    // This copy will remain intact as leaked dialogs are removed by the
    // stack.
    LinkedList dialogs;
    synchronized (dialogTable) {
        dialogs = new LinkedList(dialogTable.values());
    }
    // Iterate through the dialogDialog, get the callID of each dialog and
    // check if it's in the
    // list of active calls passed by the application. If it isn't, start
    // the timer on it.
    // If the timer has expired, kill the dialog.
    Iterator it = dialogs.iterator();
    while (it.hasNext()) {
        // Get the next dialog
        SIPDialog itDialog = (SIPDialog) it.next();
        // Get the call id associated with this dialog
        CallIdHeader callIdHeader = (itDialog != null ? itDialog.getCallId() : null);
        String callID = (callIdHeader != null ? callIdHeader.getCallId() : null);
        // Check if the application knows about this call id
        if (itDialog != null && callID != null && !activeCallIDs.contains(callID)) {
            // Application doesn't know anything about this dialog...
            if (itDialog.auditTag == 0) {
                // Mark this dialog as suspect
                itDialog.auditTag = currentTime;
            } else {
                // time's up.
                if (currentTime - itDialog.auditTag >= leakedDialogTimer) {
                    // Leaked dialog found
                    leakedDialogs++;
                    // Generate report
                    DialogState dialogState = itDialog.getState();
                    String dialogReport = "dialog id: " + itDialog.getDialogId() + ", dialog state: " + (dialogState != null ? dialogState.toString() : "null");
                    auditReport += "    " + dialogReport + "\n";
                    // Kill it
                    itDialog.setState(SIPDialog.TERMINATED_STATE);
                    if (stackLogger.isLoggingEnabled())
                        stackLogger.logDebug("auditDialogs: leaked " + dialogReport);
                }
            }
        }
    }
    // Return final report
    if (leakedDialogs > 0) {
        auditReport += "    Total: " + Integer.toString(leakedDialogs) + " leaked dialogs detected and removed.\n";
    } else {
        auditReport = null;
    }
    return auditReport;
}
Also used : DialogState(javax.sip.DialogState) Iterator(java.util.Iterator) CallIdHeader(javax.sip.header.CallIdHeader) LinkedList(java.util.LinkedList)

Example 3 with CallIdHeader

use of javax.sip.header.CallIdHeader in project XobotOS by xamarin.

the class SipHelper method createRequest.

private Request createRequest(String requestType, SipProfile caller, SipProfile callee, String tag) throws ParseException, SipException {
    FromHeader fromHeader = createFromHeader(caller, tag);
    ToHeader toHeader = createToHeader(callee);
    SipURI requestURI = callee.getUri();
    List<ViaHeader> viaHeaders = createViaHeaders();
    CallIdHeader callIdHeader = createCallIdHeader();
    CSeqHeader cSeqHeader = createCSeqHeader(requestType);
    MaxForwardsHeader maxForwards = createMaxForwardsHeader();
    Request request = mMessageFactory.createRequest(requestURI, requestType, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
    request.addHeader(createContactHeader(caller));
    return request;
}
Also used : CSeqHeader(javax.sip.header.CSeqHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ViaHeader(javax.sip.header.ViaHeader) FromHeader(javax.sip.header.FromHeader) ToHeader(javax.sip.header.ToHeader) Request(javax.sip.message.Request) CallIdHeader(javax.sip.header.CallIdHeader) SipURI(javax.sip.address.SipURI)

Aggregations

CallIdHeader (javax.sip.header.CallIdHeader)3 SipURI (javax.sip.address.SipURI)2 CSeqHeader (javax.sip.header.CSeqHeader)2 FromHeader (javax.sip.header.FromHeader)2 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)2 ToHeader (javax.sip.header.ToHeader)2 ViaHeader (javax.sip.header.ViaHeader)2 Request (javax.sip.message.Request)2 InetAddress (java.net.InetAddress)1 ParseException (java.text.ParseException)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 TooManyListenersException (java.util.TooManyListenersException)1 DialogState (javax.sip.DialogState)1 InvalidArgumentException (javax.sip.InvalidArgumentException)1 SipException (javax.sip.SipException)1 Address (javax.sip.address.Address)1 ContactHeader (javax.sip.header.ContactHeader)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 NotFoundException (org.jivesoftware.util.NotFoundException)1