Beispiel #1
0
  /*
   * 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
Beispiel #2
0
  /*
   * 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