Beispiel #1
0
    public void run() {
      Request request = requestEvent.getRequest();
      try {
        // System.out.println("shootme: got an Invite sending OK");
        Response response = messageFactory.createResponse(180, request);
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        Address address =
            addressFactory.createAddress("Shootme <sip:" + myAddress + ":" + myPort + ">");
        ContactHeader contactHeader = headerFactory.createContactHeader(address);
        response.addHeader(contactHeader);

        // System.out.println("got a server tranasaction " + st);
        Dialog dialog = st.getDialog();
        /*
         * if (dialog != null) { System.out.println("Dialog " + dialog);
         * System.out.println("Dialog state " + dialog.getState()); }
         */
        st.sendResponse(response); // send 180(RING)
        response = messageFactory.createResponse(200, request);
        toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        String toTag = new Integer((int) (Math.random() * 1000)).toString();
        toHeader.setTag(toTag); // Application is supposed to set.
        response.addHeader(contactHeader);

        st.sendResponse(response); // send 200(OK)

      } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(0);
      }
    }
Beispiel #2
0
    public void run() {
      try {
        for (int i = 0; i < 1; i++) {

          Thread.sleep(1000);
          Request request = this.notifier.dialog.createRequest(Request.NOTIFY);
          SubscriptionStateHeader subscriptionState =
              headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
          request.addHeader(subscriptionState);
          request.addHeader(eventHeader);
          ClientTransaction ct = udpProvider.getNewClientTransaction(request);
          this.notifier.dialog.sendRequest(ct);
        }
        Request request = this.notifier.dialog.createRequest(Request.NOTIFY);
        SubscriptionStateHeader subscriptionState =
            headerFactory.createSubscriptionStateHeader(SubscriptionStateHeader.TERMINATED);
        request.addHeader(eventHeader);
        request.addHeader(subscriptionState);
        ClientTransaction ct = udpProvider.getNewClientTransaction(request);
        this.notifier.dialog.sendRequest(ct);
      } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(0);
      }
    }
Beispiel #3
0
  /** Process the ACK request. Send the bye and complete the call flow. */
  public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    try {
      // System.out.println("*** shootme: got an ACK "
      // + requestEvent.getRequest());
      if (serverTransaction == null) {
        System.out.println("null server transaction -- ignoring the ACK!");
        return;
      }
      Dialog dialog = serverTransaction.getDialog();
      this.createdCount++;
      System.out.println(
          "Dialog Created = "
              + dialog.getDialogId()
              + " createdCount "
              + this.createdCount
              + " Dialog State = "
              + dialog.getState());

      if (this.dialogIds.contains(dialog.getDialogId())) {
        System.out.println("OOPS ! I already saw " + dialog.getDialogId());
      } else {
        this.dialogIds.add(dialog.getDialogId());
      }

      Request byeRequest = dialog.createRequest(Request.BYE);
      ClientTransaction tr = sipProvider.getNewClientTransaction(byeRequest);
      // System.out.println("shootme: got an ACK -- sending bye! ");
      dialog.sendRequest(tr);

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #4
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("shootme: got an Invite sending Trying");
      // System.out.println("shootme: " + request);
      Response response = messageFactory.createResponse(Response.TRYING, request);
      ServerTransaction st = requestEvent.getServerTransaction();

      if (st == null) {
        st = sipProvider.getNewServerTransaction(request);
      }
      dialog = st.getDialog();

      st.sendResponse(response);

      this.okResponse = messageFactory.createResponse(Response.BUSY_HERE, request);

      ToHeader toHeader = (ToHeader) okResponse.getHeader(ToHeader.NAME);
      toHeader.setTag("4321"); // Application is supposed to set.

      this.inviteTid = st;
      // Defer sending the OK to simulate the phone ringing.
      this.inviteRequest = request;

      new Timer().schedule(new MyTimerTask(this), 100);
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #5
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("b2bua: got an Invite sending Trying");
      ServerTransaction st = requestEvent.getServerTransaction();
      if (st == null) {
        st = sipProvider.getNewServerTransaction(request);
      }
      Dialog dialog = st.getDialog();

      ToHeader to = (ToHeader) request.getHeader(ToHeader.NAME);
      SipURI toUri = (SipURI) to.getAddress().getURI();

      SipURI target = registrar.get(toUri.getUser());

      if (target == null) {
        System.out.println("User " + toUri + " is not registered.");
        throw new RuntimeException("User not registered " + toUri);
      } else {
        ClientTransaction otherLeg = call(target);
        otherLeg.setApplicationData(st);
        st.setApplicationData(otherLeg);
        dialog.setApplicationData(otherLeg.getDialog());
        otherLeg.getDialog().setApplicationData(dialog);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
  public void sendBye(String localSipURL, String remoteSipURL, ChatSession chatSession) {
    // Send a Bye only if there were exchanged messages!!!
    if (chatSession.isEstablishedSession()) {
      try {
        logger.debug("Sending a BYE in progress to " + remoteSipURL);

        SipProvider sipProvider = imUA.getSipProvider();

        javax.sip.Dialog dialog = chatSession.getDialog();

        Request request = dialog.createRequest(Request.BYE);

        // ProxyAuthorization header if not null:
        ProxyAuthorizationHeader proxyAuthHeader = imUA.getProxyAuthorizationHeader();
        if (proxyAuthHeader != null) request.setHeader(proxyAuthHeader);

        ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(request);

        dialog.sendRequest(clientTransaction);
        logger.debug("BYE sent:\n" + request);

      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } else {
      logger.debug("BYE not sent because of no exchanged messages!!!");
    }
  }
Beispiel #7
0
  private void sendInviteOK(RequestEvent requestEvent, ServerTransaction inviteTid) {
    try {
      logger.info("sendInviteOK: " + inviteTid);
      if (inviteTid.getState() != TransactionState.COMPLETED) {
        logger.info("shootme: Dialog state before OK: " + inviteTid.getDialog().getState());

        SipProvider sipProvider = (SipProvider) requestEvent.getSource();
        Request request = requestEvent.getRequest();
        Response okResponse = protocolObjects.messageFactory.createResponse(Response.OK, request);
        ListeningPoint lp = sipProvider.getListeningPoint(protocolObjects.transport);
        int myPort = lp.getPort();

        Address address =
            protocolObjects.addressFactory.createAddress(
                "Shootme <sip:" + myAddress + ":" + myPort + ">");
        ContactHeader contactHeader = protocolObjects.headerFactory.createContactHeader(address);
        okResponse.addHeader(contactHeader);
        inviteTid.sendResponse(okResponse);
        logger.info("shootme: Dialog state after OK: " + inviteTid.getDialog().getState());
        TestHarness.assertEquals(DialogState.CONFIRMED, inviteTid.getDialog().getState());
      } else {
        logger.info("semdInviteOK: inviteTid = " + inviteTid + " state = " + inviteTid.getState());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 /**
  * Sets the Call-Id of the InReplyToHeader. The CallId parameter uniquely identifies a serious of
  * messages within a dialogue.
  *
  * @param callId - the string value of the Call-Id of this InReplyToHeader.
  * @throws ParseException which signals that an error has been reached unexpectedly while parsing
  *     the callId value.
  */
 public void setCallId(String callId) throws ParseException {
   try {
     this.callId = new CallIdentifier(callId);
   } catch (Exception e) {
     throw new ParseException(e.getMessage(), 0);
   }
 }
  public void processBye(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    try {
      logger.debug("DEBUG: IMByeProcessing, Processing BYE in progress...");

      Request request = requestEvent.getRequest();

      MessageFactory messageFactory = imUA.getMessageFactory();
      InstantMessagingGUI instantMessagingGUI = imUA.getInstantMessagingGUI();
      ListenerInstantMessaging listenerInstantMessaging =
          instantMessagingGUI.getListenerInstantMessaging();
      ChatSessionManager chatSessionManager = listenerInstantMessaging.getChatSessionManager();
      String buddy = IMUtilities.getKey(request, "From");
      if (chatSessionManager.hasAlreadyChatSession(buddy)) {
        chatSessionManager.removeChatSession(buddy);
        // chatSession.setExitedSession(true,"Your contact has exited
        // the session");
      } else {
        logger.debug("DEBUG: IMByeProcessing, processBye(), no active chatSession");
      }

      // Send an OK
      Response response = messageFactory.createResponse(Response.OK, request);
      serverTransaction.sendResponse(response);
      logger.debug("DEBUG: IMByeProcessing, processBye(), OK replied to the BYE");

      logger.debug("DEBUG: IMByeProcessing, Processing BYE completed...");
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Beispiel #10
0
  /** Done with treatments for call end, now terminate the call */
  public void terminateCall() {
    if (receivedBye == false) {
      if (gotOk == false || (getState() == CallState.INVITED && callAnswered == false)) {

        try {
          Logger.writeFile("Call " + cp + ":  sendCancel");
          sipUtil.sendCancel(clientTransaction);
        } catch (Exception e) {
          Logger.println("sendCancel " + e.getMessage());
        }
      } else {
        /*
         * Try sending a BYE as well.
         * Seems that when we treat SESSION_PROGRESS
         * as OK, sometimes we need to send a CANCEL
         * and other times a BYE.  We'll send both.
         */
        try {
          Logger.writeFile("Call " + cp + ":  sendBye");
          sipUtil.sendBye(clientTransaction);
        } catch (Exception e) {
          Logger.println("Call " + cp + ":  sendBye" + e.getMessage());
        }
      }
    }
  }
Beispiel #11
0
  public void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    Request request = requestEvent.getRequest();
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    try {
      logger.info("shootme:  got a cancel. ");
      // Because this is not an In-dialog request, you will get a null server Tx id here.
      if (serverTransactionId == null) {
        serverTransactionId = sipProvider.getNewServerTransaction(request);
      }
      Response response = protocolObjects.messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);

      String serverTxId = ((ViaHeader) response.getHeader(ViaHeader.NAME)).getBranch();
      ServerTransaction serverTx = (ServerTransaction) this.serverTxTable.get(serverTxId);
      if (serverTx != null
          && (serverTx.getState().equals(TransactionState.TRYING)
              || serverTx.getState().equals(TransactionState.PROCEEDING))) {
        Request originalRequest = serverTx.getRequest();
        Response resp =
            protocolObjects.messageFactory.createResponse(
                Response.REQUEST_TERMINATED, originalRequest);
        serverTx.sendResponse(resp);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #12
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    try {
      // System.out.println("ProcessInvite");
      Request request = requestEvent.getRequest();
      SipProvider sipProvider = (SipProvider) requestEvent.getSource();
      // Note you need to create the Server Transaction
      // before the listener returns but you can delay sending the response

      ServerTransaction st = sipProvider.getNewServerTransaction(request);
      if (transactionIDs.containsKey(st.getBranchId())) {
        System.out.println(
            "OOOPS -- seen this guy before!! This must be a late guy "
                + st.getBranchId()
                + " st = "
                + transactionIDs.get(st.getBranchId()));
        return;
      } else {
        transactionIDs.put(st.getBranchId(), st);
      }

      TTask ttask = new TTask(requestEvent, st);
      int ttime;
      if ((numInvite % 4) == 0) ttime = 5000;
      else if ((numInvite % 4) == 1) ttime = 1000;
      else ttime = 300;
      numInvite++;
      new Timer().schedule(ttask, ttime);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  public void processResponse(ResponseEvent responseReceivedEvent) {

    // Log.info("Registering response...." + sipCallId);

    Response response = (Response) responseReceivedEvent.getResponse();
    int statusCode = response.getStatusCode();
    String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();

    Log.debug("Got response " + response);

    if (statusCode == Response.OK) {
      isRegistered = true;

      Log.info(
          "Voice bridge successfully registered with "
              + registrar
              + " for "
              + proxyCredentials.getXmppUserName());
      PluginImpl.sipRegisterStatus = "Registered ok with " + proxyCredentials.getHost();

      sipServerCallback.removeSipListener(sipCallId);

    } else if (statusCode == Response.UNAUTHORIZED
        || statusCode == Response.PROXY_AUTHENTICATION_REQUIRED) {

      if (method.equals(Request.REGISTER)) {
        CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);

        if (cseq.getSequenceNumber() < 2) {

          ClientTransaction regTrans =
              SipService.handleChallenge(
                  response, responseReceivedEvent.getClientTransaction(), proxyCredentials);

          if (regTrans != null) {
            try {
              regTrans.sendRequest();

            } catch (Exception e) {

              Log.info("Registration failed, cannot send transaction " + e);
              PluginImpl.sipRegisterStatus = "Registration error " + e.toString();
            }

          } else {
            Log.info("Registration failed, cannot create transaction");
            PluginImpl.sipRegisterStatus = "Registration cannot create transaction";
          }

        } else {
          Log.info("Registration failed " + responseReceivedEvent);
          PluginImpl.sipRegisterStatus = "Registration failed";
        }
      }

    } else {
      Log.info("Unrecognized response:  " + response);
    }
  }
Beispiel #14
0
  public void init() {
    this.dialogIds = new HashSet();
    this.transactionIDs = new HashMap();
    SipFactory sipFactory = null;
    sipStack = null;
    sipFactory = SipFactory.getInstance();
    sipFactory.setPathName("gov.nist");
    Properties properties = new Properties();

    properties.setProperty("javax.sip.STACK_NAME", "shootme");
    // You need 16 for logging traces. 32 for debug + traces.
    // Your code will limp at 32 but it is best for debugging.
    properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
    properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "shootmedebuglog.txt");
    properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "shootmelog.txt");
    // Guard against starvation.
    properties.setProperty("gov.nist.javax.sip.READ_TIMEOUT", "1000");
    // properties.setProperty("gov.nist.javax.sip.MAX_MESSAGE_SIZE",
    // "4096");
    properties.setProperty("gov.nist.javax.sip.CACHE_SERVER_CONNECTIONS", "false");

    try {
      // Create SipStack object
      sipStack = sipFactory.createSipStack(properties);
      System.out.println("sipStack = " + sipStack);
    } catch (PeerUnavailableException e) {
      // could not find
      // gov.nist.jain.protocol.ip.sip.SipStackImpl
      // in the classpath
      e.printStackTrace();
      System.err.println(e.getMessage());
      if (e.getCause() != null) e.getCause().printStackTrace();
      System.exit(0);
    }

    try {
      headerFactory = sipFactory.createHeaderFactory();
      addressFactory = sipFactory.createAddressFactory();
      messageFactory = sipFactory.createMessageFactory();
      ListeningPoint lp = sipStack.createListeningPoint(myAddress, 5070, "udp");
      ListeningPoint lp1 = sipStack.createListeningPoint(myAddress, 5070, "tcp");

      Shootme listener = this;

      SipProvider sipProvider = sipStack.createSipProvider(lp);
      System.out.println("udp provider " + sipProvider);
      sipProvider.addSipListener(listener);
      sipProvider = sipStack.createSipProvider(lp1);
      System.out.println("tcp provider " + sipProvider);
      sipProvider.addSipListener(listener);

    } catch (Exception ex) {
      System.out.println(ex.getMessage());
      ex.printStackTrace();
      usage();
    }
  }
Beispiel #15
0
  /** Process the invite request. */
  public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      logger.info("shootme: got an Invite sending Trying");
      // logger.info("shootme: " + request);

      ServerTransaction st = requestEvent.getServerTransaction();

      if (st == null) {
        logger.info("null server tx -- getting a new one");
        st = sipProvider.getNewServerTransaction(request);
      }

      logger.info("getNewServerTransaction : " + st);

      String txId = ((ViaHeader) request.getHeader(ViaHeader.NAME)).getBranch();
      this.serverTxTable.put(txId, st);

      // Create the 100 Trying response.
      Response response = protocolObjects.messageFactory.createResponse(Response.TRYING, request);
      ListeningPoint lp = sipProvider.getListeningPoint(protocolObjects.transport);
      int myPort = lp.getPort();

      Address address =
          protocolObjects.addressFactory.createAddress(
              "Shootme <sip:" + myAddress + ":" + myPort + ">");

      // Add a random sleep to stagger the two OK's for the benifit of implementations
      // that may not be too good about handling re-entrancy.
      int timeToSleep = (int) (Math.random() * 1000);

      Thread.sleep(timeToSleep);

      st.sendResponse(response);

      Response ringingResponse =
          protocolObjects.messageFactory.createResponse(Response.RINGING, request);
      ContactHeader contactHeader = protocolObjects.headerFactory.createContactHeader(address);
      response.addHeader(contactHeader);
      ToHeader toHeader = (ToHeader) ringingResponse.getHeader(ToHeader.NAME);
      String toTag =
          actAsNonRFC3261UAS ? null : new Integer((int) (Math.random() * 10000)).toString();
      if (!actAsNonRFC3261UAS) toHeader.setTag(toTag); // Application is supposed to set.
      ringingResponse.addHeader(contactHeader);
      st.sendResponse(ringingResponse);
      Dialog dialog = st.getDialog();
      dialog.setApplicationData(st);

      this.inviteSeen = true;

      new Timer().schedule(new MyTimerTask(requestEvent, st /*,toTag*/), 1000);
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #16
0
  public void init() {

    ConsoleAppender console = new ConsoleAppender(); // create appender
    // configure the appender
    String PATTERN = "%d [%p|%c|%C{1}] %m%n";
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.DEBUG);
    console.activateOptions();
    // add appender to any Logger (here is root)
    Logger.getRootLogger().addAppender(console);
    SipFactory sipFactory = null;
    sipStack = null;
    sipFactory = SipFactory.getInstance();
    sipFactory.setPathName("gov.nist");
    Properties properties = new Properties();
    properties.setProperty("javax.sip.STACK_NAME", "shootme");
    // You need 16 for logging traces. 32 for debug + traces.
    // Your code will limp at 32 but it is best for debugging.
    properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "LOG4J");
    properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "shootmedebug.txt");
    properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "shootmelog.txt");
    properties.setProperty(
        "gov.nist.javax.sip.MESSAGE_PROCESSOR_FACTORY", NioMessageProcessorFactory.class.getName());

    try {
      // Create SipStack object
      sipStack = sipFactory.createSipStack(properties);
      System.out.println("sipStack = " + sipStack);
    } catch (PeerUnavailableException e) {
      // could not find
      // gov.nist.jain.protocol.ip.sip.SipStackImpl
      // in the classpath
      e.printStackTrace();
      System.err.println(e.getMessage());
      if (e.getCause() != null) e.getCause().printStackTrace();
      System.exit(0);
    }

    try {
      headerFactory = sipFactory.createHeaderFactory();
      addressFactory = sipFactory.createAddressFactory();
      messageFactory = sipFactory.createMessageFactory();
      this.listeningPoint = sipStack.createListeningPoint("127.0.0.1", myPort, transport);

      B2BUA listener = this;

      sipProvider = sipStack.createSipProvider(listeningPoint);
      System.out.println("ws provider " + sipProvider);
      sipProvider.addSipListener(listener);

    } catch (Exception ex) {
      System.out.println(ex.getMessage());
      ex.printStackTrace();
    }
  }
Beispiel #17
0
 /** Process the ACK request, forward it to the other leg. */
 public void processAck(RequestEvent requestEvent, ServerTransaction serverTransaction) {
   try {
     Dialog dialog = serverTransaction.getDialog();
     System.out.println("b2bua: got an ACK! ");
     System.out.println("Dialog State = " + dialog.getState());
     Dialog otherDialog = (Dialog) dialog.getApplicationData();
     Request request = otherDialog.createAck(otherDialog.getLocalSeqNumber());
     otherDialog.sendAck(request);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Beispiel #18
0
  public void processResponse(ResponseEvent responseReceivedEvent) {
    System.out.println("Got a response");
    Response response = (Response) responseReceivedEvent.getResponse();
    Transaction tid = responseReceivedEvent.getClientTransaction();

    System.out.println(
        "Response received with client transaction id " + tid + ":\n" + response.getStatusCode());
    if (tid == null) {
      System.out.println("Stray response -- dropping ");
      return;
    }
    System.out.println("transaction state is " + tid.getState());
    System.out.println("Dialog = " + tid.getDialog());
    System.out.println("Dialog State is " + tid.getDialog().getState());

    try {
      if (response.getStatusCode() == Response.OK
          && ((CSeqHeader) response.getHeader(CSeqHeader.NAME))
              .getMethod()
              .equals(Request.INVITE)) {
        // Request cancel = inviteTid.createCancel();
        // ClientTransaction ct =
        //  sipProvider.getNewClientTransaction(cancel);
        // ct.sendRequest();
        Dialog dialog = tid.getDialog();
        CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
        Request ackRequest = dialog.createAck(cseq.getSeqNumber());
        System.out.println("Sending ACK");
        dialog.sendAck(ackRequest);

        // Send a Re INVITE but this time force it
        // to use UDP as the transport. Else, it will
        // Use whatever transport was used to create
        // the dialog.
        if (reInviteCount == 0) {
          Request inviteRequest = dialog.createRequest(Request.INVITE);
          ((SipURI) inviteRequest.getRequestURI()).removeParameter("transport");
          ((ViaHeader) inviteRequest.getHeader(ViaHeader.NAME)).setTransport("udp");
          inviteRequest.addHeader(contactHeader);
          try {
            Thread.sleep(100);
          } catch (Exception ex) {
          }
          ClientTransaction ct = udpProvider.getNewClientTransaction(inviteRequest);
          dialog.sendRequest(ct);
          reInviteCount++;
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #19
0
  /** Process the bye request. */
  public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("shootme:  got a bye sending OK.");
      Response response = messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);
      System.out.println("Dialog State is " + serverTransactionId.getDialog().getState());

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #20
0
 public void processRegister(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
   Request request = requestEvent.getRequest();
   ContactHeader contact = (ContactHeader) request.getHeader(ContactHeader.NAME);
   SipURI contactUri = (SipURI) contact.getAddress().getURI();
   FromHeader from = (FromHeader) request.getHeader(FromHeader.NAME);
   SipURI fromUri = (SipURI) from.getAddress().getURI();
   registrar.put(fromUri.getUser(), contactUri);
   try {
     Response response = this.messageFactory.createResponse(200, request);
     ServerTransaction serverTransaction = sipProvider.getNewServerTransaction(request);
     serverTransaction.sendResponse(response);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Beispiel #21
0
  public void init() {
    SipFactory sipFactory = null;
    sipStack = null;
    sipFactory = SipFactory.getInstance();
    sipFactory.setPathName("gov.nist");
    Properties properties = new Properties();
    properties.setProperty("javax.sip.STACK_NAME", "shootme");
    // You need 16 for logging traces. 32 for debug + traces.
    // Your code will limp at 32 but it is best for debugging.
    properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
    properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "shootmedebug.txt");
    properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "shootmelog.txt");

    try {
      // Create SipStack object
      sipStack = sipFactory.createSipStack(properties);
      System.out.println("sipStack = " + sipStack);
    } catch (PeerUnavailableException e) {
      // could not find
      // gov.nist.jain.protocol.ip.sip.SipStackImpl
      // in the classpath
      e.printStackTrace();
      System.err.println(e.getMessage());
      if (e.getCause() != null) e.getCause().printStackTrace();
      System.exit(0);
    }

    try {
      headerFactory = sipFactory.createHeaderFactory();
      addressFactory = sipFactory.createAddressFactory();
      messageFactory = sipFactory.createMessageFactory();
      ListeningPoint lp = sipStack.createListeningPoint("127.0.0.1", 5070, "udp");

      Shootme listener = this;

      SipProvider sipProvider = sipStack.createSipProvider(lp);
      System.out.println("udp provider " + sipProvider);
      sipProvider.addSipListener(listener);

    } catch (Exception ex) {
      System.out.println(ex.getMessage());
      ex.printStackTrace();
      usage();
    }
  }
  /**
   * Initialize -- load password files etc. Password file format is name:authentication
   * domain:password
   *
   * @param pwFileName is the password file name.
   * @param Exception is thrown when the password file is bad.
   */
  public void initialize(String pwFileName) {
    try {
      XMLAuthenticationParser parser = new XMLAuthenticationParser(pwFileName);

      String def = parser.getRealm();
      if (def != null) DEFAULT_REALM = def;
      ProxyDebug.println(
          "DEBUG, DigestAuthenticationMethod, initialize()," + " the realm is:" + DEFAULT_REALM);
      Vector usersTagList = parser.getUsersTagList();
      if (usersTagList != null)
        for (int i = 0; i < usersTagList.size(); i++) {
          UserTag userTag = (UserTag) usersTagList.elementAt(i);
          String userName = userTag.getUserName();
          // String userRealm=userTag.getUserRealm();
          String userPassword = userTag.getUserPassword();
          if (userName != null) {

            if (userPassword == null) {
              ProxyDebug.println(
                  "DEBUG, DigestAuthenticationMethod, initialize(),"
                      + " the userPassword parameter does not exist for user: "******", we use the default: \""
                      + NULL_PASSWORD
                      + "\"");
              userPassword = NULL_PASSWORD;
            }
            passwordTable.put(userName + "@" + DEFAULT_REALM, userPassword);
          } else {
            ProxyDebug.println(
                "DEBUG, DigestAuthenticationMethod, initialize(),"
                    + " the userName parameter does not exist, we skip this entry!!");
          }
        }
      else
        ProxyDebug.println(
            "DEBUG, DigestAuthenticationMethod, initialize(),"
                + "Error during parsing the passwords file!");

    } catch (Exception e) {
      ProxyDebug.println("ERROR, DigestAuthenticationMethod, initialize()," + "exception raised:");
      e.printStackTrace();
    }
  }
Beispiel #23
0
 private void shutDown() {
   try {
     try {
       Thread.sleep(2000);
     } catch (InterruptedException e) {
     }
     System.out.println("nulling reference");
     sipStack.deleteListeningPoint(tcpListeningPoint);
     sipStack.deleteListeningPoint(udpListeningPoint);
     // This will close down the stack and exit all threads
     tcpProvider.removeSipListener(this);
     udpProvider.removeSipListener(this);
     while (true) {
       try {
         sipStack.deleteSipProvider(udpProvider);
         sipStack.deleteSipProvider(tcpProvider);
         break;
       } catch (ObjectInUseException ex) {
         try {
           Thread.sleep(2000);
         } catch (InterruptedException e) {
           continue;
         }
       }
     }
     sipStack = null;
     tcpProvider = null;
     udpProvider = null;
     this.contactHeader = null;
     addressFactory = null;
     headerFactory = null;
     messageFactory = null;
     this.udpListeningPoint = null;
     this.tcpListeningPoint = null;
     this.reInviteCount = 0;
     System.gc();
     // Redo this from the start.
     if (counter < 10) this.init();
     else counter++;
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
  public void sendSubscribeToAllPresentities(Vector buddies, boolean EXPIRED) {
    try {
      logger.debug(
          "logger, IMSubscribeProcessing, sendSubscribeToAllPresentities(),"
              + " we have to subscribe to our buddies: let's send a SUBSCRIBE for each ones.");
      for (int i = 0; i < buddies.size(); i++) {
        BuddyTag buddyTag = (BuddyTag) buddies.elementAt(i);

        String buddyURI = buddyTag.getURI();

        InstantMessagingGUI imGUI = imUA.getInstantMessagingGUI();
        ListenerInstantMessaging listenerIM = imGUI.getListenerInstantMessaging();
        String localURL = listenerIM.getLocalSipURL();
        sendSubscribe(localURL, buddyURI, EXPIRED);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Beispiel #25
0
  /** Process the bye request. */
  public void processBye(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    Request request = requestEvent.getRequest();
    try {
      logger.info("shootme:  got a bye sending OK.");
      logger.info("shootme:  dialog = " + requestEvent.getDialog());
      logger.info("shootme:  dialogState = " + requestEvent.getDialog().getState());
      Response response = protocolObjects.messageFactory.createResponse(200, request);
      if (serverTransactionId != null) {
        serverTransactionId.sendResponse(response);
      }
      logger.info("shootme:  dialogState = " + requestEvent.getDialog().getState());

      this.byeSeen = true;

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #26
0
  private void handleReInvite(Request request, ServerTransaction st) {
    Logger.println("Call " + cp + " Re-INVITE\n" + request);

    if (request.getRawContent() == null) {
      Logger.error("Call " + cp + " no SDP in INVITE Request!");
      return;
    }

    String sdpBody = new String(request.getRawContent());

    SdpInfo sdpInfo;

    try {
      sdpInfo = sipUtil.getSdpInfo(sdpBody);
    } catch (ParseException e) {
      Logger.error("Call " + cp + " invalid SDP in re-INVITE Request! " + e.getMessage());
      return;
    }

    MediaInfo mediaInfo = sdpInfo.getMediaInfo();

    InetSocketAddress isa = new InetSocketAddress(sdpInfo.getRemoteHost(), sdpInfo.getRemotePort());

    InetSocketAddress rtcpAddress = sdpInfo.getRtcpAddress();

    setEndpointAddress(
        isa,
        mediaInfo.getPayload(),
        sdpInfo.getTransmitMediaInfo().getPayload(),
        sdpInfo.getTelephoneEventPayload(),
        rtcpAddress);

    isa = callHandler.getReceiveAddress();

    try {
      sipUtil.sendOkWithSdp(request, st, isa, sdpInfo);
    } catch (Exception e) {
      Logger.println("Call " + cp + " Failed to send ok with sdp for re-invite " + e.getMessage());
      return;
    }
  }
Beispiel #27
0
  public void processBye(Request request, ServerTransaction serverTransactionId) {
    try {
      System.out.println("shootist:  got a bye .");
      if (serverTransactionId == null) {
        System.out.println("shootist:  null TID.");
        return;
      }
      Dialog dialog = serverTransactionId.getDialog();
      System.out.println("Dialog State = " + dialog.getState());
      Response response = messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);
      System.out.println("shootist:  Sending OK.");
      System.out.println("Dialog State = " + dialog.getState());

      this.shutDown();

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #28
0
  public void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
      System.out.println("shootme:  got a cancel.");
      if (serverTransactionId == null) {
        System.out.println("shootme:  null tid.");
        return;
      }
      Response response = messageFactory.createResponse(200, request);
      serverTransactionId.sendResponse(response);
      if (dialog.getState() != DialogState.CONFIRMED) {
        response = messageFactory.createResponse(Response.REQUEST_TERMINATED, inviteRequest);
        inviteTid.sendResponse(response);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      System.exit(0);
    }
  }
Beispiel #29
0
  /**
   * handles a BYE request
   *
   * @param request the request
   * @param transId the transaction Id
   * @throws TransactionDoesNotExistException when the transaction record does not exist.
   */
  private void handleBye(Request request, ServerTransaction st) {
    try {
      CallIdHeader callIdHeader = (CallIdHeader) request.getHeader("Call-Id");

      String sipCallId = callIdHeader.getCallId();

      if (sipCallId.equals(this.sipCallId)) {
        receivedBye = true;

        try {
          Logger.writeFile("Call " + cp + " has hung up.");

          // sipUtil.sendOK(clientTransaction, st, cp);
          sipUtil.sendOK(request, st);
        } catch (Exception e) {
          /*
           * We sometimes get a null ServerTransaction
           */
        }
        cancelRequest("hung up");
        sipServerCallback.removeSipListener(sipCallId);
      } else {
        /*
         * this should not happen since the message has been
         * delegated to this sip agent.
         */
        throw new TransactionDoesNotExistException(
            cp + "BYE request received did not " + "match either party:  " + request);
      }
    } catch (TransactionDoesNotExistException e) {
      Logger.error("Call " + cp + " Transaction not found " + e.getMessage());
    } catch (SipException e) {
      Logger.exception("Call " + cp + " SIP Stack error", e);
      cancelRequest("handleBye:  SIP Stack error " + e.getMessage());
    } catch (Exception e) {
      Logger.exception("Call " + cp + " Unknown error ", e);
      cancelRequest("handleBye:  SIP Stack error " + e.getMessage());
    }
  }
Beispiel #30
0
 public void processResponse(ResponseEvent responseEvent) {
   ClientTransaction ct = responseEvent.getClientTransaction();
   Response response = responseEvent.getResponse();
   ServerTransaction st = (ServerTransaction) ct.getApplicationData();
   try {
     Response otherResponse =
         messageFactory.createResponse(response.getStatusCode(), st.getRequest());
     if (response.getStatusCode() == 200 && ct.getRequest().getMethod().equals("INVITE")) {
       Address address =
           addressFactory.createAddress("B2BUA <sip:" + myAddress + ":" + myPort + ">");
       ContactHeader contactHeader = headerFactory.createContactHeader(address);
       response.addHeader(contactHeader);
       ToHeader toHeader = (ToHeader) otherResponse.getHeader(ToHeader.NAME);
       if (toHeader.getTag() == null)
         toHeader.setTag(new Long(counter.getAndIncrement()).toString());
       otherResponse.addHeader(contactHeader);
     }
     st.sendResponse(otherResponse);
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }