Exemplo n.º 1
0
  /**
   * Receives options requests and replies with an OK response containing methods that we support.
   *
   * @param requestEvent the incoming options request.
   * @return <tt>true</tt> if request has been successfully processed, <tt>false</tt> otherwise
   */
  @Override
  public boolean processRequest(RequestEvent requestEvent) {
    Response optionsOK = null;
    try {
      optionsOK =
          provider.getMessageFactory().createResponse(Response.OK, requestEvent.getRequest());

      // add to the allows header all methods that we support
      for (String method : provider.getSupportedMethods()) {
        // don't support REGISTERs
        if (!method.equals(Request.REGISTER))
          optionsOK.addHeader(provider.getHeaderFactory().createAllowHeader(method));
      }

      Iterable<String> knownEventsList = provider.getKnownEventsList();

      synchronized (knownEventsList) {
        for (String event : knownEventsList)
          optionsOK.addHeader(provider.getHeaderFactory().createAllowEventsHeader(event));
      }
    } catch (ParseException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to create an incoming OPTIONS request", ex);
      return false;
    }

    try {
      SipStackSharing.getOrCreateServerTransaction(requestEvent).sendResponse(optionsOK);
    } catch (TransactionUnavailableException ex) {
      // this means that we received an OPTIONS request outside the scope
      // of a transaction which could mean that someone is simply sending
      // us b****hit to keep a NAT connection alive, so let's not get too
      // excited.
      if (logger.isInfoEnabled())
        logger.info("Failed to respond to an incoming " + "transactionless OPTIONS request");
      if (logger.isTraceEnabled()) logger.trace("Exception was:", ex);
      return false;
    } catch (InvalidArgumentException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to send an incoming OPTIONS request", ex);
      return false;
    } catch (SipException ex) {
      // What else could we do apart from logging?
      logger.warn("Failed to send an incoming OPTIONS request", ex);
      return false;
    }

    return true;
  }
 /**
  * The method queries a Stun server for a binding for the port and address that <tt>sock</tt> is
  * bound on.
  *
  * @param sock the socket whose port and address we'dlike to resolve (the stun message gets sent
  *     trhough that socket)
  * @return StunAddress the address returned by the stun server or null if an error occurred or no
  *     address was returned
  * @throws IOException if an error occurs while stun4j is using sockets.
  * @throws BindException if the port is already in use.
  */
 private StunAddress queryStunServer(DatagramSocket sock) throws IOException, BindException {
   StunAddress mappedAddress = null;
   if (detector != null && useStun) {
     mappedAddress = detector.getMappingFor(sock);
     if (logger.isTraceEnabled()) {
       logger.trace(
           "For socket with address "
               + sock.getLocalAddress().getHostAddress()
               + " and port "
               + sock.getLocalPort()
               + " the stun server returned the "
               + "following mapping ["
               + mappedAddress
               + "]");
     }
   }
   return mappedAddress;
 }
Exemplo n.º 3
0
  public SocketManager(Socket socket) {
    this.socket = socket;

    users = new ArrayList<User>();
    tUser = new User();

    // Spring Framework IoC
    ClassPathXmlApplicationContext beanfactory = null;
    try {
      beanfactory = new ClassPathXmlApplicationContext(SPRING_CONFIG_DEFAULT);
      userSvc = (IUserSvc) beanfactory.getBean("userSvc");

    } catch (Exception e) {
      dLog.error("Unable to configure Spring beans", e);
    } finally {
      if (beanfactory != null) {
        beanfactory.close();
      }
    }

    dLog.trace("In constructor");
  }
Exemplo n.º 4
0
  @Override
  public void run() {
    SOCKET_PORT = String.valueOf(socket.getRemoteSocketAddress());
    dLog.trace("Starting to run server");
    // get all users
    try {
      users = userSvc.getAllUsers();
    } catch (Exception e2) {
      dLog.error("Unable to get all users", e2);
    }
    dLog.trace("Got " + users.size() + " users");

    try {
      while (!exit) {
        out = new ObjectOutputStream(socket.getOutputStream());
        in = new ObjectInputStream(socket.getInputStream());
        dLog.trace("Successfully got input/output streams");

        String inputStr = "";
        out.writeObject("Burrito POS Server Connected. Enter Username: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"INPUT | " + inputStr);
        parent.updateStatus(appendInfo("INPUT | " + inputStr));

        while (!inputStr.equals("exit") && !this.exit) {
          dLog.trace("Exit? " + exit);
          if (tUser.getUserName() == null) {
            tUser.setUserName(inputStr);
            out.writeObject("OK User " + inputStr + ", enter password: "******"OUTPUT | OK User " + inputStr + ", enter password: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"Username: "******" | Password: "******"Stored user: "******" | stored pass: "******"OK User verified. Enter command: ");
              dLog.trace("OUTPUT | OK User verified. Enter command: ");
              parent.updateStatus(appendInfo("OUTPUT | OK User verified. Enter command: "));
              auth = true;
            } else {
              tUser.setUserName(null);
              tUser.setPassword(null);
              out.writeObject("ERROR Invalid Credentials. Enter Username: "******"OUTPUT | ERROR Invalid Credentials. Enter Username: "******"OUTPUT | ERROR Invalid Credentials. Enter Username: "******"exit")) {
              out.writeObject("OK Command " + inputStr + " entered. Enter command: ");
              dLog.trace("OUTPUT | OK Command " + inputStr + " entered. Enter command: ");
              parent.updateStatus(
                  appendInfo("OUTPUT | OK Command " + inputStr + " entered. Enter command: "));
            }
          }

          inputStr = (String) in.readObject();
          dLog.trace("INPUT | " + inputStr);
          parent.updateStatus(appendInfo("INPUT | " + inputStr));
        }

        exit = true;
        try {
          dLog.trace("Closing the socket");
          auth = false;
          out.writeObject("Exiting");
          dLog.trace("Exiting");
          parent.updateStatus(appendInfo("Exiting"));
          this.close();
        } catch (Exception e1) {
          dLog.error("Exception in closing socket", e1);
        }
      }
    } catch (Exception e) {
      dLog.error("Exception in SocketManager run", e);
    }
  }
Exemplo n.º 5
0
 public void setExit(boolean exit) {
   dLog.trace("setExit: " + exit);
   this.exit = exit;
 }
 /** Constructor for <tt>ReplacementServiceDirectImageImpl</tt>. */
 public ReplacementServiceDirectImageImpl() {
   setMaxImgSizeFromConf();
   logger.trace("Creating a Direct Image Link Source.");
 }
Exemplo n.º 7
0
 /**
  * Log an error message.
  *
  * @param message -- error message to log.
  */
 public void logFatalError(String message) {
   if (logger.isTraceEnabled()) logger.trace("Fatal error from the JAIN-SIP stack: " + message);
 }
Exemplo n.º 8
0
 /**
  * logs a stack trace. This helps to look at the stack frame.
  *
  * @param traceLevel currently unused.
  */
 public void logStackTrace(int traceLevel) {
   if (logger.isTraceEnabled()) logger.trace("JAIN-SIP stack trace", new Throwable());
 }
Exemplo n.º 9
0
 /**
  * Logs the build time stamp of the jain-sip reference implementation.
  *
  * @param buildTimeStamp the build time stamp of the jain-sip reference implementation.
  */
 public void setBuildTimeStamp(String buildTimeStamp) {
   if (logger.isTraceEnabled()) logger.trace("JAIN-SIP RI build " + buildTimeStamp);
 }