/**
  * Creates a SIP request message within a dialog, with a new branch via-parameter.
  *
  * @param dialog the Dialog used to compose the various Message headers
  * @param method the request method
  * @param body the message body
  */
 public static Message createRequest(Dialog dialog, String method, String body) {
   NameAddress to = dialog.getRemoteName();
   NameAddress from = dialog.getLocalName();
   NameAddress target = dialog.getRemoteContact();
   if (target == null) target = to;
   SipURL request_uri = target.getAddress();
   if (request_uri == null) request_uri = dialog.getRemoteName().getAddress();
   SipProvider sip_provider = dialog.getSipProvider();
   String via_addr = sip_provider.getViaAddress();
   int host_port = sip_provider.getPort();
   boolean rport = sip_provider.isRportSet();
   String proto;
   if (target.getAddress().hasTransport()) proto = target.getAddress().getTransport();
   else proto = sip_provider.getDefaultTransport();
   NameAddress contact = dialog.getLocalContact();
   if (contact == null) contact = from;
   // increment the CSeq, if method is not ACK nor CANCEL
   if (!SipMethods.isAck(method) && !SipMethods.isCancel(method)) dialog.incLocalCSeq();
   String call_id = dialog.getCallID();
   long cseq = dialog.getLocalCSeq();
   String local_tag = dialog.getLocalTag();
   String remote_tag = dialog.getRemoteTag();
   // String branch=SipStack.pickBranch();
   Message req =
       createRequest(
           method,
           request_uri,
           to,
           from,
           contact,
           proto,
           via_addr,
           host_port,
           rport,
           call_id,
           cseq,
           local_tag,
           remote_tag,
           null,
           body,
           null,
           null); // modified by mandrajg
   Vector<NameAddress> route = dialog.getRoute();
   if (route != null && route.size() > 0) {
     Vector<String> route_s = new Vector<String>(route.size());
     for (Enumeration<NameAddress> e = route.elements(); e.hasMoreElements(); ) {
       NameAddress elem = e.nextElement();
       route_s.add(elem.toString());
     }
     req.addRoutes(new MultipleHeader(SipHeaders.Route, route_s));
   }
   req.rfc2543RouteAdapt();
   return req;
 }
Ejemplo n.º 2
0
  private String getContactURL(String username, SipProvider sip_provider) {
    int i = username.indexOf("@");
    if (i != -1) {
      // if the username already contains a @
      // strip it and everthing following it
      username = username.substring(0, i);
    }

    return username
        + "@"
        + IpAddress.localIpAddress
        + (sip_provider.getPort() != 0 ? ":" + sip_provider.getPort() : "")
        + ";transport="
        + sip_provider.getDefaultTransport();
  }
 /**
  * Creates a new REGISTER request.
  *
  * <p>If contact is null, set contact as star * (register all)
  */
 public static Message createRegisterRequest(
     SipProvider sip_provider,
     NameAddress to,
     NameAddress from,
     NameAddress contact,
     String qvalue,
     String icsi) { // modified by mandrajg
   SipURL to_url = to.getAddress();
   SipURL registrar = new SipURL(to_url.getHost(), to_url.getPort());
   String via_addr = sip_provider.getViaAddress();
   int host_port = sip_provider.getPort();
   boolean rport = sip_provider.isRportSet();
   String proto;
   if (to_url.hasTransport()) proto = to_url.getTransport();
   else proto = sip_provider.getDefaultTransport();
   String call_id = sip_provider.pickCallId();
   int cseq = SipProvider.pickInitialCSeq();
   String local_tag = SipProvider.pickTag();
   // String branch=SipStack.pickBranch();
   Message req =
       createRequest(
           SipMethods.REGISTER,
           registrar,
           to,
           from,
           contact,
           proto,
           via_addr,
           host_port,
           rport,
           call_id,
           cseq,
           local_tag,
           null,
           null,
           null,
           qvalue,
           icsi); // modified by mandrajg
   // if no contact, deregister all
   if (contact == null) {
     ContactHeader star = new ContactHeader(); // contact is *
     req.setContactHeader(star);
     req.setExpiresHeader(new ExpiresHeader(String.valueOf(SipStack.default_expires)));
   }
   return req;
 }
  /**
   * Creates a SIP request message. Where
   *
   * <UL>
   *   <LI>via address and port are taken from SipProvider
   *   <LI>transport protocol is taken from request-uri (if transport parameter is present) or the
   *       default transport for the SipProvider is used.
   * </UL>
   *
   * @param sip_provider the SipProvider used to fill the Via field
   * @see
   *     #createRequest(String,SipURL,NameAddress,NameAddress,NameAddress,String,String,int,String,long,String,String,String,String)
   */
  public static Message createRequest(
      SipProvider sip_provider,
      String method,
      SipURL request_uri,
      NameAddress to,
      NameAddress from,
      NameAddress contact,
      String call_id,
      long cseq,
      String local_tag,
      String remote_tag,
      String branch,
      String body,
      String icsi) { // modified by mandrajg
    String via_addr = sip_provider.getViaAddress();
    int host_port = sip_provider.getPort();
    boolean rport = sip_provider.isRportSet();
    String proto;
    if (request_uri.hasTransport()) proto = request_uri.getTransport();
    else proto = sip_provider.getDefaultTransport();

    return createRequest(
        method,
        request_uri,
        to,
        from,
        contact,
        proto,
        via_addr,
        host_port,
        rport,
        call_id,
        cseq,
        local_tag,
        remote_tag,
        branch,
        body,
        null,
        icsi); // modified by mandrajg
  }
 /** Creates an ACK request for a non-2xx response */
 public static Message createNon2xxAckRequest(
     SipProvider sip_provider, Message method, Message resp) {
   SipURL request_uri = method.getRequestLine().getAddress();
   FromHeader from = method.getFromHeader();
   ToHeader to = resp.getToHeader();
   String via_addr = sip_provider.getViaAddress();
   int host_port = sip_provider.getPort();
   boolean rport = sip_provider.isRportSet();
   String proto;
   if (request_uri.hasTransport()) proto = request_uri.getTransport();
   else proto = sip_provider.getDefaultTransport();
   String branch = method.getViaHeader().getBranch();
   NameAddress contact = null;
   Message ack =
       createRequest(
           SipMethods.ACK,
           request_uri,
           to.getNameAddress(),
           from.getNameAddress(),
           contact,
           proto,
           via_addr,
           host_port,
           rport,
           method.getCallIdHeader().getCallId(),
           method.getCSeqHeader().getSequenceNumber(),
           from.getParameter("tag"),
           to.getParameter("tag"),
           branch,
           null,
           null,
           null); // modified by mandrajg
   ack.removeExpiresHeader();
   if (method.hasRouteHeader()) ack.setRoutes(method.getRoutes());
   return ack;
 }