コード例 #1
0
ファイル: SipStack.java プロジェクト: schmalle/swsng
  /*
   * handles the deregistration of a client
   */
  private void handleDeRegister(Sockets mySocket) {
    if (this.m_regPacketOk == null) return;

    if (m_verbose) {
      System.out.println("SipStack.handleDeRegister: Reregistering packet");
    }

    int cseq = getCSeq(this.m_regPacketOk) + 100;
    String finalPacket = this.setCSeq(m_regPacketOk, cseq);
    finalPacket = setExpires(finalPacket, 0);

    try {
      mySocket.send(m_proxy, m_destinationPort, finalPacket.getBytes());
      String answer = mySocket.recieve();

      if (m_verbose) {
        System.out.println("SipStack.handleDeRegister: Answer from server + " + answer);
      }

    } catch (Exception e) {
      System.out.println("Exception: handleDeRegister()");
      return;
    }

    // reset "Expires: " field

  } // handleDeRegister
コード例 #2
0
ファイル: SipStack.java プロジェクト: schmalle/swsng
  /*
   * creates a BYE packet, if the "SEND A BYE packet after x" mode is activetd
   * @in: sipCode - sipcode
   * @in: sendData - data to be send/received
   * @out: final string
   *
   */
  private String handleByeAfter(int sipCode, String sendData, Sockets mySocket) {
    // dummy check, if the option is set at all
    if (this.m_byeAfter == null) return sendData;

    String strSipCode = new Integer(sipCode).toString();
    if (!this.m_byeAfter.equals(strSipCode)) return sendData;

    // increase CSEQ and replace current SIP mode with an ACK
    int cseq = getCSeq(sendData) + 1;
    sendData = replaceSipMode(sendData, "BYE ");
    sendData = setCSeq(sendData, cseq);

    try {
      mySocket.send(m_proxy, m_destinationPort, sendData.getBytes());
    } catch (Exception e) {

    }

    return null;
  } // handleByeAfter
コード例 #3
0
ファイル: SipStack.java プロジェクト: schmalle/swsng
  /*
   * generates a fully authenticated new register reuqest
   * @param sendData data to be send
   * @param answer (answer from server)
   * @param sipCode current sipcode
   * @param oldsipcode
   * @param mySocket initialized socket handler
   *
   * @returns <code>string</code> new packet
   */
  private String checkUnAuthorizedCase(
      String sendData, String answer, int sipCode, int prevSipCode, Sockets mySocket) {
    // look at register case

    if (sendData == null) return null;

    if (
    /*prevSipCode == 0 && */ sipCode == 401 && sendData.toUpperCase().startsWith(SIP_MODE_REG)) {

      if (m_verbose) System.out.println("Info: Working with response: " + answer);

      sendData = handleAuthentication(answer, sendData);
    } else if (
    /*prevSipCode == 0 && */ sipCode == 401 && sendData.toUpperCase().startsWith(SIP_MODE_INV)) {

      if (m_verbose) System.out.println("Info: Working with response: " + answer);

      sendData = handleAuthentication(answer, sendData);

      // generate ACK packet
      String ackData = getAckData(sendData);

      try {
        mySocket.send(m_proxy, m_destinationPort, ackData.getBytes());
      } catch (Exception e) {

      }

    } else {
      if (m_verbose)
        System.out.println(
            "Info(401): SIPCode"
                + new Integer(sipCode).toString()
                + " PreSipCode: "
                + new Integer(prevSipCode).toString()
                + "SendData "
                + sendData);
    }

    return sendData;
  } // checkUnAuthorizedRegisterCase
コード例 #4
0
ファイル: SipStack.java プロジェクト: schmalle/swsng
  /*
   * core routine to handle SIP related actions
   *
   * @param servermode 		flag to signal, if the routine was called in servermode
   * @param defaultSocket     initialized Sockets variable to be used for Sip handling
   * @return <code>0</code>   return code, 0 on ok
   * @return <code>-1</code>  return code, -1 on error
   */
  private int startOneStep(boolean serverMode, Sockets defaultSocket) {
    int sipCode = 0, prevSipCode = 0, loopRunner = 0;
    String answer = null;
    int returnCode = 0;

    // assign socket and break of, if needed
    Sockets mySocket = defaultSocket;
    if (defaultSocket == null) {
      mySocket = new Sockets(m_localPort, "udp", m_verbose, "localhost", 1000);
    }

    // check, if we have to register the user before we start the invitation
    // TODO: global status must be visible
    handleRegisterBeforeInvite(m_fileNameContent, serverMode, mySocket);

    String sendData = m_fileNameContent;

    // loop through the SIP processes as long as necessaey
    while (sipCode != 200 && loopRunner++ != 10 && sendData != null && returnCode == 0) {
      // show verbose information
      if (m_verbose) System.out.println("Info:\r\nSending data: " + sendData + "\r\n");

      try {
        // special check for call issues
        if (sipCode != 100 && sipCode != 183) {
          m_cseq = getCSeq(sendData);
          mySocket.send(m_proxy, m_destinationPort, sendData.getBytes());
        }

        answer = mySocket.recieve();
      } catch (SocketTimeoutException e) {
        answer = "<NONE>";
        returnCode = -1;
      } catch (Exception e) {
        if (m_verbose) System.out.println("Exception: startOneStep().. Beaking off");
        returnCode = -1;
        answer = "<NONE>";
      }

      // check if the server answered, if not break down
      if (answer == null) returnCode = -1;

      prevSipCode = sipCode;
      sipCode = getSipCode(answer);

      if (m_verbose) {
        System.out.println("Received answer: " + answer);
        System.out.println("Old Sip Code: " + prevSipCode + " New Sip Code: " + sipCode);
      }

      switch (sipCode) {
        case 200:
          {
            handleSipCode200(sendData);
            break;
          }

        case 486: // busy
          {
            loopRunner = EXIT;
            break;
          }

        case 401: // unauthorized
          {
            sendData = checkUnAuthorizedCase(sendData, answer, sipCode, prevSipCode, mySocket);
            break;
          }
      }

      // handle the byeafter case
      sendData = handleByeAfter(sipCode, sendData, mySocket);
    } // while sipCode != 200 && loopRunner != 10

    // check for possible deregister actions after going down
    if (this.m_deregister) {
      handleDeRegister(mySocket);
    }

    // clean up of generated sockets
    if (defaultSocket == null) {
      try {
        mySocket.close();
      } catch (Exception e) {
        returnCode = -1;
      }
    }

    return returnCode;
  } // startOneStep