Search in sources :

Example 6 with Address

use of javax.sip.address.Address in project Openfire by igniterealtime.

the class RegisterProcessing method processOK.

void processOK(ClientTransaction clientTransatcion, Response response) {
    isRegistered = true;
    FromHeader fromHeader = ((FromHeader) response.getHeader(FromHeader.NAME));
    Address address = fromHeader.getAddress();
    int expires = 0;
    if (!isUnregistering) {
        ContactHeader contactHeader = (ContactHeader) response.getHeader(ContactHeader.NAME);
        // TODO check if the registrar created the contact address
        if (contactHeader != null) {
            expires = contactHeader.getExpires();
        } else {
            ExpiresHeader expiresHeader = response.getExpires();
            if (expiresHeader != null) {
                expires = expiresHeader.getExpires();
            }
        }
    }
    // fix by Luca Bincoletto <Luca.Bincoletto@tilab.com>
    if (expires == 0) {
        isUnregistering = false;
        sipManCallback.fireUnregistered(address.toString());
    } else {
        if (reRegisterTimer != null)
            reRegisterTimer.cancel();
        if (keepAliveTimer != null)
            keepAliveTimer.cancel();
        reRegisterTimer = new Timer();
        keepAliveTimer = new Timer();
        // if (expires > 0 && expires < 60) {
        // [issue 2] Schedule re registrations
        // bug reported by LynlvL@netscape.com
        // use the value returned by the server to reschedule
        // registration
        SipURI uri = (SipURI) address.getURI();
        scheduleReRegistration(uri.getHost(), uri.getPort(), uri.getTransportParam(), expires);
        // }
        /*
            * else{ SipURI uri = (SipURI) address.getURI();
            * scheduleReRegistration(uri.getHost(), uri.getServerPort(),
            * uri.getTransportParam(), expires); }
            */
        sipManCallback.fireRegistered(address.toString());
    }
}
Also used : Address(javax.sip.address.Address) Timer(java.util.Timer) SipURI(javax.sip.address.SipURI)

Example 7 with Address

use of javax.sip.address.Address in project Openfire by igniterealtime.

the class RegisterProcessing method register.

synchronized void register(String registrarAddress, int registrarPort, String registrarTransport, int expires) throws CommunicationsException {
    try {
        isUnregistering = false;
        // From
        FromHeader fromHeader = sipManCallback.getFromHeader(true);
        Address fromAddress = fromHeader.getAddress();
        sipManCallback.fireRegistering(fromAddress.toString());
        // Request URI
        SipURI requestURI = null;
        try {
            requestURI = sipManCallback.addressFactory.createSipURI(null, registrarAddress);
        } catch (ParseException ex) {
            throw new CommunicationsException("Bad registrar address:" + registrarAddress, ex);
        } catch (NullPointerException ex) {
            // Do not throw an exc, we should rather silently notify the
            // user
            // throw new CommunicationsException("A registrar address was
            // not specified!", ex);
            sipManCallback.fireUnregistered(fromAddress.getURI().toString() + " (registrar not specified)");
            return;
        }
        requestURI.setPort(registrarPort);
        try {
            requestURI.setTransportParam(registrarTransport);
        } catch (ParseException ex) {
            throw new CommunicationsException(registrarTransport + " is not a valid transport!", ex);
        }
        // Call ID Header
        CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
        // CSeq Header
        CSeqHeader cSeqHeader = null;
        try {
            cSeqHeader = sipManCallback.headerFactory.createCSeqHeader(1, Request.REGISTER);
        } catch (ParseException ex) {
            // Should never happen
            Log.error("register", ex);
        } catch (InvalidArgumentException ex) {
            // Should never happen
            Log.error("register", ex);
        }
        // To Header
        ToHeader toHeader = null;
        try {
            toHeader = sipManCallback.headerFactory.createToHeader(fromAddress, null);
        } catch (ParseException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
        }
        // User Agent Header
        UserAgentHeader uaHeader = null;
        ArrayList<String> userAgentList = new ArrayList<String>();
        userAgentList.add(SIPConfig.getStackName());
        try {
            uaHeader = sipManCallback.headerFactory.createUserAgentHeader(userAgentList);
        } catch (ParseException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
        }
        // Via Headers
        ArrayList viaHeaders = sipManCallback.getLocalViaHeaders();
        // MaxForwardsHeader
        MaxForwardsHeader maxForwardsHeader = sipManCallback.getMaxForwardsHeader();
        // Request
        Request request = null;
        try {
            request = sipManCallback.messageFactory.createRequest(requestURI, Request.REGISTER, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader);
            request.setHeader(uaHeader);
        } catch (ParseException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create the register request!", ex);
        }
        // Expires Header
        ExpiresHeader expHeader = null;
        for (int retry = 0; retry < 2; retry++) {
            try {
                expHeader = sipManCallback.headerFactory.createExpiresHeader(expires);
            } catch (InvalidArgumentException ex) {
                if (retry == 0) {
                    expires = 3600;
                    continue;
                }
                throw new CommunicationsException("Invalid registrations expiration parameter - " + expires, ex);
            }
        }
        request.addHeader(expHeader);
        // Contact Header should contain IP - bug report - Eero Vaarnas
        ContactHeader contactHeader = sipManCallback.getRegistrationContactHeader();
        request.addHeader(contactHeader);
        // Transaction
        ClientTransaction regTrans = null;
        try {
            regTrans = sipManCallback.sipProvider.getNewClientTransaction(request);
        } catch (TransactionUnavailableException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create a register transaction!\n" + "Check that the Registrar address is correct!");
        }
        try {
            regTrans.sendRequest();
        }// we sometimes get a null pointer exception here so catch them all
         catch (Exception ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not send out the register request!", ex);
        }
        this.registerRequest = request;
    } catch (Exception e) {
        Log.error("register", e);
    }
}
Also used : Address(javax.sip.address.Address) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) SipSecurityException(org.jivesoftware.openfire.sip.tester.security.SipSecurityException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) ParseException(java.text.ParseException) ParseException(java.text.ParseException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 8 with Address

use of javax.sip.address.Address in project Openfire by igniterealtime.

the class RegisterProcessing method processTimeout.

void processTimeout(Transaction transatcion, Request request) {
    isRegistered = true;
    FromHeader fromHeader = ((FromHeader) request.getHeader(FromHeader.NAME));
    Address address = fromHeader.getAddress();
    sipManCallback.fireUnregistered("Request timeouted for: " + address.toString());
}
Also used : Address(javax.sip.address.Address)

Example 9 with Address

use of javax.sip.address.Address in project camel by apache.

the class SipConfiguration method createFromHeader.

private void createFromHeader() throws ParseException {
    SipURI fromAddress = getAddressFactory().createSipURI(getFromUser(), getFromHost());
    fromAddress.setPort(Integer.valueOf(getFromPort()).intValue());
    Address fromNameAddress = addressFactory.createAddress(fromAddress);
    fromNameAddress.setDisplayName(getFromUser());
    setFromHeader(headerFactory.createFromHeader(fromNameAddress, getFromUser() + "_Header"));
}
Also used : Address(javax.sip.address.Address) SipURI(javax.sip.address.SipURI)

Example 10 with Address

use of javax.sip.address.Address in project XobotOS by xamarin.

the class SipSessionGroup method createPeerProfile.

private static SipProfile createPeerProfile(HeaderAddress header) throws SipException {
    try {
        Address address = header.getAddress();
        SipURI uri = (SipURI) address.getURI();
        String username = uri.getUser();
        if (username == null)
            username = ANONYMOUS;
        int port = uri.getPort();
        SipProfile.Builder builder = new SipProfile.Builder(username, uri.getHost()).setDisplayName(address.getDisplayName());
        if (port > 0)
            builder.setPort(port);
        return builder.build();
    } catch (IllegalArgumentException e) {
        throw new SipException("createPeerProfile()", e);
    } catch (ParseException e) {
        throw new SipException("createPeerProfile()", e);
    }
}
Also used : HeaderAddress(javax.sip.header.HeaderAddress) Address(javax.sip.address.Address) SipProfile(android.net.sip.SipProfile) ParseException(java.text.ParseException) SipURI(javax.sip.address.SipURI) SipException(javax.sip.SipException) ListeningPoint(javax.sip.ListeningPoint)

Aggregations

Address (javax.sip.address.Address)16 SipURI (javax.sip.address.SipURI)14 ParseException (java.text.ParseException)7 InetAddress (java.net.InetAddress)5 Request (javax.sip.message.Request)5 SipException (javax.sip.SipException)4 InvalidArgumentException (javax.sip.InvalidArgumentException)3 FromHeader (javax.sip.header.FromHeader)3 CommunicationsException (org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 InetSocketAddress (java.net.InetSocketAddress)2 TooManyListenersException (java.util.TooManyListenersException)2 URI (javax.sip.address.URI)2 ContactHeader (javax.sip.header.ContactHeader)2 SubscriptionStateHeader (javax.sip.header.SubscriptionStateHeader)2 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2 SipProfile (android.net.sip.SipProfile)1 ArrayList (java.util.ArrayList)1 ListIterator (java.util.ListIterator)1 Timer (java.util.Timer)1