Example #1
0
  /**
   * Find the transaction corresponding to a given request.
   *
   * @param sipMessage request for which to retrieve the transaction.
   * @param isServer search the server transaction table if true.
   * @return the transaction object corresponding to the request or null if no such mapping exists.
   */
  public SIPTransaction findTransaction(SIPMessage sipMessage, boolean isServer) {
    SIPTransaction retval = null;

    if (isServer) {
      Via via = sipMessage.getTopmostVia();
      if (via.getBranch() != null) {
        String key = sipMessage.getTransactionId();

        synchronized (this.serverTransactionTable) {
          retval = (SIPTransaction) serverTransactionTable.get(key);
          if (LogWriter.needsLogging) logMessage("looking for key " + key);
          if (retval != null && retval.isMessagePartOfTransaction(sipMessage)) return retval;
        }
      }
      // Need to scan the table for old style transactions (RFC 2543
      // style)
      synchronized (this.serverTransactions) {
        Iterator<SIPServerTransaction> it = serverTransactions.iterator();
        while (it.hasNext()) {
          SIPServerTransaction sipServerTransaction = (SIPServerTransaction) it.next();
          if (sipServerTransaction.isMessagePartOfTransaction(sipMessage))
            return sipServerTransaction;
        }
      }
    } else {
      Via via = sipMessage.getTopmostVia();
      if (via.getBranch() != null) {
        String key = sipMessage.getTransactionId();
        synchronized (this.clientTransactionTable) {
          retval = (SIPTransaction) clientTransactionTable.get(key);
          if (retval != null && retval.isMessagePartOfTransaction(sipMessage)) return retval;
        }
      }
      // Need to scan the table for old style transactions (RFC 2543
      // style)
      synchronized (this.clientTransactions) {
        Iterator<SIPClientTransaction> it = clientTransactions.iterator();
        while (it.hasNext()) {
          SIPClientTransaction clientTransaction = (SIPClientTransaction) it.next();
          if (clientTransaction.isMessagePartOfTransaction(sipMessage)) return clientTransaction;
        }
      }
    }
    return null;
  }
Example #2
0
 /**
  * Log a message into the log directory.
  *
  * @param message a SIPMessage to log
  * @param from from header of the message to log into the log directory
  * @param to to header of the message to log into the log directory
  * @param status the status to log.
  * @param sender is the server the sender or receiver (true if sender).
  * @param time is the reception time.
  */
 public void logMessage(
     SIPMessage message, String from, String to, String status, boolean sender, long time) {
   checkLogFile();
   CallID cid = (CallID) message.getCallId();
   String callId = null;
   if (cid != null) callId = cid.getCallId();
   String firstLine = message.getFirstLine().trim();
   String encoded = (logContent ? message.encode() : message.encodeMessage());
   String tid = message.getTransactionId();
   TimeStampHeader tshdr = (TimeStampHeader) message.getHeader(TimeStampHeader.NAME);
   long tsval = tshdr == null ? 0 : tshdr.getTime();
   logMessage(encoded, from, to, sender, callId, firstLine, status, tid, time, tsval);
 }