Esempio n. 1
0
  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);
    }
  }
Esempio n. 2
0
  public void unregister() throws IOException {
    if (!isRegistered) {
      return;
    }

    cancelPendingRegistrations();
    isRegistered = false;

    if (this.registerRequest == null) {
      Log.info("Couldn't find the initial register request");
      throw new IOException("Couldn't find the initial register request");
    }

    Request unregisterRequest = (Request) registerRequest.clone();

    try {
      unregisterRequest.getExpires().setExpires(0);
      CSeqHeader cSeqHeader = (CSeqHeader) unregisterRequest.getHeader(CSeqHeader.NAME);
      // [issue 1] - increment registration cseq number
      // reported by - Roberto Tealdi <*****@*****.**>
      cSeqHeader.setSequenceNumber(cSeqHeader.getSequenceNumber() + 1);
    } catch (InvalidArgumentException e) {
      Log.info("Unable to set Expires Header " + e.getMessage());
      return;
    }

    ClientTransaction unregisterTransaction = null;

    try {
      unregisterTransaction = sipProvider.getNewClientTransaction(unregisterRequest);
    } catch (TransactionUnavailableException e) {
      throw new IOException("Unable to create a unregister transaction " + e.getMessage());
    }
    try {
      unregisterTransaction.sendRequest();
    } catch (SipException e) {
      Log.info("Faied to send unregister request " + e.getMessage());
      return;
    }
  }
  public void processResponse(ResponseEvent responseEvent) {
    Response response = responseEvent.getResponse();
    ClientTransaction clientTransaction = responseEvent.getClientTransaction();
    CSeqHeader cseqHeader = (CSeqHeader) response.getHeader(CSeqHeader.NAME);

    logger.debug("***** Response: " + response.getStatusCode() + " received by UA *****");
    logger.debug(response);
    logger.debug("***** Response dispatched *****");

    if (response.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED
        || response.getStatusCode() == Response.UNAUTHORIZED) {
      if (clientTransaction == null) {
        logger.info("Bad username ?");
      } else {
        try {
          logger.debug("IMUserAgent, processResponse(), Credentials to provide!");
          // WE start the authentication process!!!
          // Let's get the Request related to this response:
          Request clonedRequest = (Request) clientTransaction.getRequest().clone();
          if (clonedRequest == null) {
            logger.debug(
                "IMUserAgent, processResponse(), the request "
                    + " that caused the 407 has not been retrieved!!! Return cancelled!");
          } else {
            // Let's increase the Cseq:
            cseqHeader = (CSeqHeader) clonedRequest.getHeader(CSeqHeader.NAME);
            cseqHeader.setSequenceNumber(cseqHeader.getSequenceNumber() + 1);
            // Let's add a Proxy-Authorization header:
            // We send the informations stored:
            FromHeader fromHeader = (FromHeader) clonedRequest.getHeader(FromHeader.NAME);
            String fromURI = fromHeader.getAddress().getURI().toString();
            Header header;
            if (fromURI.equals(getLocalURI())) {
              header = authenticationProcess.getHeader(response);
            } else {
              String fromAddress = IMUtilities.getUsernameFromURI(fromURI);
              logger.info("Fetching credentials dor user: "******"ERROR, user not found");
                header = null;
              }
            }

            if (header == null) {
              logger.debug(
                  "IMUserAgent, processResponse(), Proxy-Authorization "
                      + " header is null, the request is not resent");
            } else {
              clonedRequest.setHeader(header);

              ClientTransaction newClientTransaction =
                  getSipProvider().getNewClientTransaction(clonedRequest);

              newClientTransaction.sendRequest();
              logger.debug(
                  "IMUserAgent, processResponse(), REGISTER "
                      + "with credentials sent:\n"
                      + clonedRequest);
            }
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    } else {
      if (cseqHeader.getMethod().equals("REGISTER")) {
        //	logger.info("REGISTER Response received");
        sipRC.processResponse(responseEvent);
      } else if (cseqHeader.getMethod().equals("ACK")) {

      } else if (cseqHeader.getMethod().equals("MESSAGE")) {
        sipMC.processResponse(responseEvent);
      }
    }
  }