예제 #1
0
  /** Loading the values stored into configuration form */
  private void loadValues() {
    PacketLoggingService packetLogging = LoggingUtilsActivator.getPacketLoggingService();
    PacketLoggingConfiguration cfg = packetLogging.getConfiguration();

    enableCheckBox.setSelected(cfg.isGlobalLoggingEnabled());

    sipProtocolCheckBox.setSelected(cfg.isSipLoggingEnabled());
    jabberProtocolCheckBox.setSelected(cfg.isJabberLoggingEnabled());
    rtpProtocolCheckBox.setSelected(cfg.isRTPLoggingEnabled());
    ice4jProtocolCheckBox.setSelected(cfg.isIce4JLoggingEnabled());
    fileCountField.setText(String.valueOf(cfg.getLogfileCount()));
    fileSizeField.setText(String.valueOf(cfg.getLimit() / 1000));

    updateButtonsState();
  }
  /**
   * Log the packet.
   *
   * @param packet packet to log
   */
  @Override
  protected void doLogPacket(RawPacket packet, InetSocketAddress target) {
    if (socket == null || packet == null || target == null) return;

    // Do not log the packet if it has been processed (and already
    // logged) by the ice4j stack.
    if (socket instanceof MultiplexingDatagramSocket) return;

    PacketLoggingService pktLogging = getPacketLoggingService();

    if (pktLogging != null) {
      pktLogging.logPacket(
          PacketLoggingService.ProtocolName.RTP,
          socket.getLocalAddress().getAddress(),
          socket.getLocalPort(),
          target.getAddress().getAddress(),
          target.getPort(),
          PacketLoggingService.TransportName.UDP,
          true,
          packet.getBuffer(),
          packet.getOffset(),
          packet.getLength());
    }
  }
  /**
   * Log the packet.
   *
   * @param p packet to log
   */
  @Override
  protected void doLogPacket(DatagramPacket p) {
    if (socket.getLocalAddress() == null) return;

    // Do not log the packet if this one has been processed (and already
    // logged) by the ice4j stack.
    if (socket instanceof MultiplexingDatagramSocket) return;

    PacketLoggingService pktLogging = getPacketLoggingService();

    if (pktLogging != null) {
      pktLogging.logPacket(
          PacketLoggingService.ProtocolName.RTP,
          p.getAddress().getAddress(),
          p.getPort(),
          socket.getLocalAddress().getAddress(),
          socket.getLocalPort(),
          PacketLoggingService.TransportName.UDP,
          false,
          p.getData(),
          p.getOffset(),
          p.getLength());
    }
  }
예제 #4
0
  /** Invoked when an action occurs. */
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    PacketLoggingService packetLogging = LoggingUtilsActivator.getPacketLoggingService();

    if (source.equals(enableCheckBox)) {
      // turn it on/off in activator
      packetLogging.getConfiguration().setGlobalLoggingEnabled(enableCheckBox.isSelected());
      updateButtonsState();
    } else if (source.equals(sipProtocolCheckBox)) {
      packetLogging.getConfiguration().setSipLoggingEnabled(sipProtocolCheckBox.isSelected());
    } else if (source.equals(jabberProtocolCheckBox)) {
      packetLogging.getConfiguration().setJabberLoggingEnabled(jabberProtocolCheckBox.isSelected());
    } else if (source.equals(rtpProtocolCheckBox)) {
      packetLogging.getConfiguration().setRTPLoggingEnabled(rtpProtocolCheckBox.isSelected());
    } else if (source.equals(ice4jProtocolCheckBox)) {
      packetLogging.getConfiguration().setIce4JLoggingEnabled(ice4jProtocolCheckBox.isSelected());
    } else if (source.equals(archiveButton)) {
      // don't block the UI thread
      new Thread(
              new Runnable() {
                public void run() {
                  collectLogs();
                }
              })
          .start();
    } else if (source.equals(uploadLogsButton)) {
      // don't block the UI thread
      new Thread(
              new Runnable() {
                public void run() {
                  uploadLogs();
                }
              })
          .start();
    }
  }
예제 #5
0
  /**
   * Logs the specified message and details to the packet logging service if enabled.
   *
   * @param message the message to log
   * @param sender determines whether we are the origin of this message.
   */
  private void logPacket(SIPMessage message, boolean sender) {
    try {
      PacketLoggingService packetLogging = SipActivator.getPacketLogging();
      if (packetLogging == null
          || !packetLogging.isLoggingEnabled(PacketLoggingService.ProtocolName.SIP)
          /* Via not present in CRLF packet on TCP - causes NPE */
          || message.getTopmostVia() == null) return;

      String transport = message.getTopmostVia().getTransport();
      boolean isTransportUDP = transport.equalsIgnoreCase("UDP");

      byte[] srcAddr;
      int srcPort;
      byte[] dstAddr;
      int dstPort;

      // if addresses are not set use empty byte array with length
      // equals to the other address or just empty
      // byte array with length 4 (ipv4 0.0.0.0)
      if (sender) {
        if (!isTransportUDP) {
          InetSocketAddress localAddress =
              getLocalAddressForDestination(
                  message.getRemoteAddress(),
                  message.getRemotePort(),
                  message.getLocalAddress(),
                  transport);
          srcPort = localAddress.getPort();
          srcAddr = localAddress.getAddress().getAddress();
        } else {
          srcPort = message.getLocalPort();
          if (message.getLocalAddress() != null) srcAddr = message.getLocalAddress().getAddress();
          else if (message.getRemoteAddress() != null)
            srcAddr = new byte[message.getRemoteAddress().getAddress().length];
          else srcAddr = new byte[4];
        }

        dstPort = message.getRemotePort();
        if (message.getRemoteAddress() != null) dstAddr = message.getRemoteAddress().getAddress();
        else dstAddr = new byte[srcAddr.length];
      } else {
        if (!isTransportUDP) {
          InetSocketAddress dstAddress =
              getLocalAddressForDestination(
                  message.getRemoteAddress(),
                  message.getRemotePort(),
                  message.getLocalAddress(),
                  transport);
          dstPort = dstAddress.getPort();
          dstAddr = dstAddress.getAddress().getAddress();
        } else {
          dstPort = message.getLocalPort();
          if (message.getLocalAddress() != null) dstAddr = message.getLocalAddress().getAddress();
          else if (message.getRemoteAddress() != null)
            dstAddr = new byte[message.getRemoteAddress().getAddress().length];
          else dstAddr = new byte[4];
        }

        srcPort = message.getRemotePort();
        if (message.getRemoteAddress() != null) srcAddr = message.getRemoteAddress().getAddress();
        else srcAddr = new byte[dstAddr.length];
      }

      byte[] msg = null;
      if (message instanceof SIPRequest) {
        SIPRequest req = (SIPRequest) message;
        if (req.getMethod().equals(SIPRequest.MESSAGE)
            && message.getContentTypeHeader() != null
            && message.getContentTypeHeader().getContentType().equalsIgnoreCase("text")) {
          int len = req.getContentLength().getContentLength();

          if (len > 0) {
            SIPRequest newReq = (SIPRequest) req.clone();

            byte[] newContent = new byte[len];
            Arrays.fill(newContent, (byte) '.');
            newReq.setMessageContent(newContent);
            msg = newReq.toString().getBytes("UTF-8");
          }
        }
      }

      if (msg == null) {
        msg = message.toString().getBytes("UTF-8");
      }

      packetLogging.logPacket(
          PacketLoggingService.ProtocolName.SIP,
          srcAddr,
          srcPort,
          dstAddr,
          dstPort,
          isTransportUDP
              ? PacketLoggingService.TransportName.UDP
              : PacketLoggingService.TransportName.TCP,
          sender,
          msg);
    } catch (Throwable e) {
      logger.error("Cannot obtain message body", e);
    }
  }