Esempio n. 1
0
  /** When a new Message is received by the SipProvider. */
  public void onReceivedMessage(SipProvider provider, Message msg) {
    // printLog("onReceivedMessage()", LogLevel.MEDIUM);
    if (statusIs(D_TERMINATED)) {
      printLog("subscription already terminated: message discarded", LogLevel.MEDIUM);
      return;
    }
    // else
    if (msg.isRequest() && msg.isSubscribe()) {
      if (statusIs(NotifierDialog.D_WAITING)) { // the first SUBSCRIBE
        // request
        changeStatus(D_SUBSCRIBED);
        sip_provider.removeSipProviderListener(new MethodIdentifier(SipMethods.SUBSCRIBE));
      }
      subscribe_req = msg;
      NameAddress target = msg.getToHeader().getNameAddress();
      NameAddress subscriber = msg.getFromHeader().getNameAddress();
      EventHeader eh = msg.getEventHeader();
      if (eh != null) {
        event = eh.getEvent();
        id = eh.getId();
      }
      // ==> jinsub for presence server
      if (event.endsWith("presence")) {
        notifyEvent = target.toString();
      }
      //
      update(UAS, msg);
      // System.out.println("����� ��¿��?");
      // subscribe_transaction = new TransactionServer(sip_provider, msg, null);
      if (listener != null)
        // Here is going to add vector_key
        listener.onDlgSubscribe(this, target, subscriber, event, id, msg);

    } else if (msg.isRequest() && msg.isPublish()) {
      // ==> jinsub for presence server
      NameAddress target = msg.getToHeader().getNameAddress();
      NameAddress publisher = msg.getFromHeader().getNameAddress();
      EventHeader eh = msg.getEventHeader();
      if (eh.getEvent().endsWith(event) && target.toString().endsWith(notifyEvent)) {
        // System.out.println("����� ��¿��2?");
        // publish_transaction = new TransactionServer(sip_provider, msg, null);
        if (listener != null) listener.onDlgPublish(this, target, publisher, event, id, msg);
      }
      //
    } else {
      printLog("message is not a SUBSCRIBE: message discarded", LogLevel.HIGH);
    }
  }
 /**
  * Creates a SIP response message.
  *
  * @param req the request message
  * @param code the response code
  * @param reason the response reason
  * @param contact the contact address
  * @param local_tag the local tag in the 'To' header
  * @param body the message body
  */
 public static Message createResponse(
     Message req,
     int code,
     String reason,
     String local_tag,
     NameAddress contact,
     String content_type,
     String body) {
   Message resp = new Message();
   resp.setStatusLine(new StatusLine(code, reason));
   resp.setVias(req.getVias());
   if (code >= 180 && code < 300 && req.hasRecordRouteHeader())
     resp.setRecordRoutes(req.getRecordRoutes());
   ToHeader toh = req.getToHeader();
   if (local_tag != null) toh.setParameter("tag", local_tag);
   resp.setToHeader(toh);
   resp.setFromHeader(req.getFromHeader());
   resp.setCallIdHeader(req.getCallIdHeader());
   resp.setCSeqHeader(req.getCSeqHeader());
   if (contact != null) resp.setContactHeader(new ContactHeader(contact));
   // add Server header field
   if (SipStack.server_info != null) resp.setServerHeader(new ServerHeader(SipStack.server_info));
   // if (body!=null) resp.setBody(body); else resp.setBody("");
   if (content_type == null) resp.setBody(body);
   else resp.setBody(content_type, body);
   // System.out.println("DEBUG: MessageFactory:
   // response:\n"+resp.toString());
   return resp;
 }
 /** Creates a CANCEL request. */
 public static Message createCancelRequest(Message method, Dialog dialog) {
   ToHeader to = method.getToHeader();
   FromHeader from = method.getFromHeader();
   SipURL request_uri = method.getRequestLine().getAddress();
   NameAddress contact = method.getContactHeader().getNameAddress();
   ViaHeader via = method.getViaHeader();
   String host_addr = via.getHost();
   int host_port = via.getPort();
   boolean rport = via.hasRport();
   String proto = via.getProtocol();
   String branch = method.getViaHeader().getBranch();
   return createRequest(
       SipMethods.CANCEL,
       request_uri,
       to.getNameAddress(),
       from.getNameAddress(),
       contact,
       proto,
       host_addr,
       host_port,
       rport,
       method.getCallIdHeader().getCallId(),
       method.getCSeqHeader().getSequenceNumber(),
       from.getParameter("tag"),
       to.getParameter("tag"),
       branch,
       "",
       null,
       null); // modified by mandrajg
 }
Esempio n. 4
0
 /** When a new Message is received by the SipProvider. */
 public void onReceivedMessage(SipProvider provider, Message msg) {
   printLog("onReceivedMessage()", LogLevel.MEDIUM);
   if (statusIs(D_TERMINATED)) {
     printLog("subscription already terminated: message discarded", LogLevel.MEDIUM);
     return;
   }
   // else
   if (msg.isRequest() && msg.isSubscribe()) {
     if (statusIs(NotifierDialog.D_WAITING)) { // the first SUBSCRIBE
       // request
       changeStatus(D_SUBSCRIBED);
       sip_provider.removeSipProviderListener(new MethodIdentifier(SipMethods.SUBSCRIBE));
     }
     subscribe_req = msg;
     NameAddress target = msg.getToHeader().getNameAddress();
     NameAddress subscriber = msg.getFromHeader().getNameAddress();
     EventHeader eh = msg.getEventHeader();
     if (eh != null) {
       event = eh.getEvent();
       id = eh.getId();
     }
     update(UAS, msg);
     subscribe_transaction = new TransactionServer(sip_provider, msg, null);
     if (listener != null) listener.onDlgSubscribe(this, target, subscriber, event, id, msg);
   } else {
     printLog("message is not a SUBSCRIBE: message discarded", LogLevel.HIGH);
   }
 }
 /** Method derived from interface SipListener. */
 public void onReceivedMessage(SipProvider provider, Message msg) {
   if (msg.isRequest() && msg.isInvite()) {
     if (listener != null)
       listener.onNewInviteDialog(
           this,
           new InviteDialog(sip_provider, msg, listener),
           msg.getToHeader().getNameAddress(),
           msg.getFromHeader().getNameAddress(),
           msg.getBody(),
           msg);
   }
 }
Esempio n. 6
0
 /**
  * Inherited from TransactionServerListener. When the TransactionServer goes into the "Trying"
  * state receiving a request
  *
  * <p>If called for a INVITE transaction, it initializes the dialog information, <br>
  * moves to D_INVITED state, and add a listener to the SipProvider, <br>
  * and fires <i>onInvite(caller,body,msg)</i>.
  */
 public void onTransRequest(TransactionServer ts, Message req) {
   printLog("inside onTransRequest(ts,msg)", LogLevel.LOW);
   if (ts.getTransactionMethod().equals(SipMethods.INVITE)) {
     if (!verifyStatus(statusIs(D_WAITING))) return;
     changeStatus(D_INVITED);
     invite_req = req;
     update(Dialog.UAS, invite_req);
     listener.onDlgInvite(
         this,
         invite_req.getToHeader().getNameAddress(),
         invite_req.getFromHeader().getNameAddress(),
         invite_req.getBody(),
         invite_req);
   }
 }
Esempio n. 7
0
 /** When a new Message is received by the SipInterface. */
 public void onReceivedMessage(SipInterface sip, Message msg) { // printLog("Message received:
   // "+msg.getFirstLine().substring(0,msg.toString().indexOf('\r')));
   if (msg.isRequest()) {
     (new TransactionServer(sip_provider, msg, null))
         .respondWith(MessageFactory.createResponse(msg, 200, SipResponses.reasonOf(200), null));
     NameAddress sender = msg.getFromHeader().getNameAddress();
     NameAddress recipient = msg.getToHeader().getNameAddress();
     String subject = null;
     if (msg.hasSubjectHeader()) subject = msg.getSubjectHeader().getSubject();
     String content_type = msg.getContentTypeHeader().getContentType();
     String content = msg.getBody();
     if (listener != null)
       listener.onMaReceivedMessage(this, sender, recipient, subject, content_type, content);
   }
 }
 /** 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;
 }
Esempio n. 9
0
 /**
  * Inherited from class SipProviderListener. Called when a new message is received (out of any
  * ongoing transaction) for the current InviteDialog. Always checks for out-of-date methods (CSeq
  * header sequence number).
  *
  * <p>If the message is ACK(2xx/INVITE) request, it moves to D_CALL state, and fires
  * <i>onDlgAck(this,body,msg)</i>.
  *
  * <p>If the message is 2xx(INVITE) response, it create a new AckTransactionClient
  *
  * <p>If the message is BYE, it moves to D_BYED state, removes the listener from SipProvider,
  * fires onDlgBye(this,msg) then it responds with 200 OK, moves to D_CLOSE state and fires
  * onDlgClose(this)
  */
 public void onReceivedMessage(SipProvider sip_provider, Message msg) {
   printLog("inside onReceivedMessage(sip_provider,message)", LogLevel.MEDIUM);
   if (msg.isRequest()
       && !(msg.isAck() || msg.isCancel())
       && msg.getCSeqHeader().getSequenceNumber() <= getRemoteCSeq()) {
     printLog("Request message is too late (CSeq too small): Message discarded", LogLevel.HIGH);
     return;
   }
   // invite received
   if (msg.isRequest() && msg.isInvite()) {
     verifyStatus(statusIs(D_INIT) || statusIs(D_CALL));
     // NOTE: if the invite_ts.listen() is used, you should not arrive
     // here with the D_INIT state..
     // however state D_INIT has been included for robustness against
     // further changes.
     if (statusIs(D_INIT)) changeStatus(D_INVITED);
     else changeStatus(D_ReINVITED);
     invite_req = msg;
     invite_ts = new InviteTransactionServer(sip_provider, invite_req, this);
     // ((TransactionServer)transaction).listen();
     update(Dialog.UAS, invite_req);
     if (statusIs(D_INVITED))
       listener.onDlgInvite(
           this,
           invite_req.getToHeader().getNameAddress(),
           invite_req.getFromHeader().getNameAddress(),
           invite_req.getBody(),
           invite_req);
     else listener.onDlgReInvite(this, invite_req.getBody(), invite_req);
   } else
   // ack (of 2xx of INVITE)
   if (msg.isRequest() && msg.isAck()) {
     if (!verifyStatus(statusIs(D_ACCEPTED) || statusIs(D_ReACCEPTED))) return;
     changeStatus(D_CALL);
     // terminates the AckTransactionServer
     ack_ts.terminate();
     listener.onDlgAck(this, msg.getBody(), msg);
     listener.onDlgCall(this);
   } else
   // keep sending ACK (if already sent) for any "200 OK" received
   if (msg.isResponse()) {
     if (!verifyStatus(statusIs(D_CALL))) return;
     int code = msg.getStatusLine().getCode();
     verifyThat(code >= 200 && code < 300, "code 2xx was expected");
     if (ack_req != null) {
       AckTransactionClient ack_tc = new AckTransactionClient(sip_provider, ack_req, null);
       ack_tc.request();
     }
   } else
   // bye received
   if (msg.isRequest() && msg.isBye()) {
     if (!verifyStatus(statusIs(D_CALL) || statusIs(D_BYEING))) return;
     changeStatus(D_BYED);
     bye_ts = new TransactionServer(sip_provider, msg, this);
     // automatically sends a 200 OK
     Message resp = MessageFactory.createResponse(msg, 200, SipResponses.reasonOf(200), null);
     respond(resp);
     listener.onDlgBye(this, msg);
     changeStatus(D_CLOSE);
     listener.onDlgClose(this);
   } else
   // cancel received
   if (msg.isRequest() && msg.isCancel()) {
     if (!verifyStatus(statusIs(D_INVITED) || statusIs(D_ReINVITED))) return;
     // create a CANCEL TransactionServer and send a 200 OK (CANCEL)
     TransactionServer ts = new TransactionServer(sip_provider, msg, null);
     // ts.listen();
     ts.respondWith(MessageFactory.createResponse(msg, 200, SipResponses.reasonOf(200), null));
     // automatically sends a 487 Cancelled
     Message resp =
         MessageFactory.createResponse(invite_req, 487, SipResponses.reasonOf(487), null);
     respond(resp);
     listener.onDlgCancel(this, msg);
   } else
   // any other request received
   if (msg.isRequest()) {
     TransactionServer ts = new TransactionServer(sip_provider, msg, null);
     // ts.listen();
     ts.respondWith(MessageFactory.createResponse(msg, 405, SipResponses.reasonOf(405), null));
   }
 }