Search in sources :

Example 1 with AddressImpl

use of gov.nist.javax.sip.address.AddressImpl in project XobotOS by xamarin.

the class SIPDialog method addRoute.

/**
     * Add a route list extracted from a record route list. If this is a server dialog then we
     * assume that the record are added to the route list IN order. If this is a client dialog
     * then we assume that the record route headers give us the route list to add in reverse
     * order.
     * 
     * @param recordRouteList -- the record route list from the incoming message.
     */
private void addRoute(RecordRouteList recordRouteList) {
    try {
        if (this.isClientDialog()) {
            // This is a client dialog so we extract the record
            // route from the response and reverse its order to
            // careate a route list.
            this.routeList = new RouteList();
            // start at the end of the list and walk backwards
            ListIterator li = recordRouteList.listIterator(recordRouteList.size());
            boolean addRoute = true;
            while (li.hasPrevious()) {
                RecordRoute rr = (RecordRoute) li.previous();
                if (addRoute) {
                    Route route = new Route();
                    AddressImpl address = ((AddressImpl) ((AddressImpl) rr.getAddress()).clone());
                    route.setAddress(address);
                    route.setParameters((NameValueList) rr.getParameters().clone());
                    this.routeList.add(route);
                }
            }
        } else {
            // This is a server dialog. The top most record route
            // header is the one that is closest to us. We extract the
            // route list in the same order as the addresses in the
            // incoming request.
            this.routeList = new RouteList();
            ListIterator li = recordRouteList.listIterator();
            boolean addRoute = true;
            while (li.hasNext()) {
                RecordRoute rr = (RecordRoute) li.next();
                if (addRoute) {
                    Route route = new Route();
                    AddressImpl address = ((AddressImpl) ((AddressImpl) rr.getAddress()).clone());
                    route.setAddress(address);
                    route.setParameters((NameValueList) rr.getParameters().clone());
                    routeList.add(route);
                }
            }
        }
    } finally {
        if (sipStack.getStackLogger().isLoggingEnabled()) {
            Iterator it = routeList.iterator();
            while (it.hasNext()) {
                SipURI sipUri = (SipURI) (((Route) it.next()).getAddress().getURI());
                if (!sipUri.hasLrParam()) {
                    if (sipStack.isLoggingEnabled()) {
                        sipStack.getStackLogger().logWarning("NON LR route in Route set detected for dialog : " + this);
                        sipStack.getStackLogger().logStackTrace();
                    }
                }
            }
        }
    }
}
Also used : ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AddressImpl(gov.nist.javax.sip.address.AddressImpl) RouteList(gov.nist.javax.sip.header.RouteList) RecordRouteList(gov.nist.javax.sip.header.RecordRouteList) ListIterator(java.util.ListIterator) SipURI(javax.sip.address.SipURI) RecordRoute(gov.nist.javax.sip.header.RecordRoute) Route(gov.nist.javax.sip.header.Route) RecordRoute(gov.nist.javax.sip.header.RecordRoute)

Example 2 with AddressImpl

use of gov.nist.javax.sip.address.AddressImpl in project XobotOS by xamarin.

the class ListeningPointImpl method createContactHeader.

public ContactHeader createContactHeader() {
    try {
        String ipAddress = this.getIPAddress();
        int port = this.getPort();
        SipURI sipURI = new SipUri();
        sipURI.setHost(ipAddress);
        sipURI.setPort(port);
        sipURI.setTransportParam(this.transport);
        Contact contact = new Contact();
        AddressImpl address = new AddressImpl();
        address.setURI(sipURI);
        contact.setAddress(address);
        return contact;
    } catch (Exception ex) {
        InternalErrorHandler.handleException("Unexpected exception", sipStack.getStackLogger());
        return null;
    }
}
Also used : AddressImpl(gov.nist.javax.sip.address.AddressImpl) SipURI(javax.sip.address.SipURI) SipUri(gov.nist.javax.sip.address.SipUri) IOException(java.io.IOException) ParseException(java.text.ParseException) Contact(gov.nist.javax.sip.header.Contact)

Example 3 with AddressImpl

use of gov.nist.javax.sip.address.AddressImpl in project XobotOS by xamarin.

the class Contact method setWildCardFlag.

/**
     * Set the wildCardFlag member
     * @param w boolean to set
     */
public void setWildCardFlag(boolean w) {
    this.wildCardFlag = true;
    this.address = new AddressImpl();
    this.address.setWildCardFlag();
}
Also used : AddressImpl(gov.nist.javax.sip.address.AddressImpl)

Example 4 with AddressImpl

use of gov.nist.javax.sip.address.AddressImpl in project XobotOS by xamarin.

the class SIPClientTransaction method createAck.

/*
     * (non-Javadoc)
     * 
     * @see javax.sip.ClientTransaction#createAck()
     */
public Request createAck() throws SipException {
    SIPRequest originalRequest = this.getOriginalRequest();
    if (originalRequest == null)
        throw new SipException("bad state " + getState());
    if (getMethod().equalsIgnoreCase(Request.ACK)) {
        throw new SipException("Cannot ACK an ACK!");
    } else if (lastResponse == null) {
        throw new SipException("bad Transaction state");
    } else if (lastResponse.getStatusCode() < 200) {
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logDebug("lastResponse = " + lastResponse);
        }
        throw new SipException("Cannot ACK a provisional response!");
    }
    SIPRequest ackRequest = originalRequest.createAckRequest((To) lastResponse.getTo());
    // Pull the record route headers from the last reesponse.
    RecordRouteList recordRouteList = lastResponse.getRecordRouteHeaders();
    if (recordRouteList == null) {
        // request URI.
        if (lastResponse.getContactHeaders() != null && lastResponse.getStatusCode() / 100 != 3) {
            Contact contact = (Contact) lastResponse.getContactHeaders().getFirst();
            javax.sip.address.URI uri = (javax.sip.address.URI) contact.getAddress().getURI().clone();
            ackRequest.setRequestURI(uri);
        }
        return ackRequest;
    }
    ackRequest.removeHeader(RouteHeader.NAME);
    RouteList routeList = new RouteList();
    // start at the end of the list and walk backwards
    ListIterator<RecordRoute> li = recordRouteList.listIterator(recordRouteList.size());
    while (li.hasPrevious()) {
        RecordRoute rr = (RecordRoute) li.previous();
        Route route = new Route();
        route.setAddress((AddressImpl) ((AddressImpl) rr.getAddress()).clone());
        route.setParameters((NameValueList) rr.getParameters().clone());
        routeList.add(route);
    }
    Contact contact = null;
    if (lastResponse.getContactHeaders() != null) {
        contact = (Contact) lastResponse.getContactHeaders().getFirst();
    }
    if (!((SipURI) ((Route) routeList.getFirst()).getAddress().getURI()).hasLrParam()) {
        // Contact may not yet be there (bug reported by Andreas B).
        Route route = null;
        if (contact != null) {
            route = new Route();
            route.setAddress((AddressImpl) ((AddressImpl) (contact.getAddress())).clone());
        }
        Route firstRoute = (Route) routeList.getFirst();
        routeList.removeFirst();
        javax.sip.address.URI uri = firstRoute.getAddress().getURI();
        ackRequest.setRequestURI(uri);
        if (route != null)
            routeList.add(route);
        ackRequest.addHeader(routeList);
    } else {
        if (contact != null) {
            javax.sip.address.URI uri = (javax.sip.address.URI) contact.getAddress().getURI().clone();
            ackRequest.setRequestURI(uri);
            ackRequest.addHeader(routeList);
        }
    }
    return ackRequest;
}
Also used : RecordRouteList(gov.nist.javax.sip.header.RecordRouteList) RouteList(gov.nist.javax.sip.header.RouteList) SIPRequest(gov.nist.javax.sip.message.SIPRequest) SipURI(javax.sip.address.SipURI) Contact(gov.nist.javax.sip.header.Contact) RecordRoute(gov.nist.javax.sip.header.RecordRoute) RecordRouteList(gov.nist.javax.sip.header.RecordRouteList) AddressImpl(gov.nist.javax.sip.address.AddressImpl) SipException(javax.sip.SipException) RecordRoute(gov.nist.javax.sip.header.RecordRoute) Route(gov.nist.javax.sip.header.Route)

Example 5 with AddressImpl

use of gov.nist.javax.sip.address.AddressImpl in project XobotOS by xamarin.

the class AddressHeaderParser method parse.

protected void parse(AddressHeaderIms addressHeader) throws ParseException {
    dbg_enter("AddressHeaderParser.parse");
    try {
        AddressParser addressParser = new AddressParser(this.getLexer());
        AddressImpl addr = addressParser.address(true);
        addressHeader.setAddress(addr);
    } catch (ParseException ex) {
        throw ex;
    } finally {
        dbg_leave("AddressParametersParser.parse");
    }
}
Also used : AddressParser(gov.nist.javax.sip.parser.AddressParser) AddressImpl(gov.nist.javax.sip.address.AddressImpl) ParseException(java.text.ParseException)

Aggregations

AddressImpl (gov.nist.javax.sip.address.AddressImpl)5 SipURI (javax.sip.address.SipURI)3 Contact (gov.nist.javax.sip.header.Contact)2 RecordRoute (gov.nist.javax.sip.header.RecordRoute)2 RecordRouteList (gov.nist.javax.sip.header.RecordRouteList)2 Route (gov.nist.javax.sip.header.Route)2 RouteList (gov.nist.javax.sip.header.RouteList)2 ParseException (java.text.ParseException)2 SipUri (gov.nist.javax.sip.address.SipUri)1 SIPRequest (gov.nist.javax.sip.message.SIPRequest)1 AddressParser (gov.nist.javax.sip.parser.AddressParser)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 SipException (javax.sip.SipException)1