Example #1
0
  /**
   * Encodes a sample string, decodes it and makes sure that the decoded string has the same value
   * as the original
   */
  public void testEncodeDecode() {
    String data = "string to encode";
    byte[] expectedReturn = data.getBytes();

    byte[] encodedData = base64.encode(data.getBytes());
    byte[] actualReturn = base64.decode(encodedData);
    assertTrue("encode decode failed.", Arrays.equals(expectedReturn, actualReturn));
  }
Example #2
0
  /**
   * Encodes a sample string, decodes it and makes sure that the decoded string has the same value
   * as the original
   */
  public void testEncodeDecode1() {
    String data = "string to encode";
    byte[] expectedReturn = data.getBytes();

    byte[] encodedData = base64.encode(data.getBytes());

    String encodedString = new String(encodedData);

    byte[] actualReturn = base64.decode(encodedString);
    assertTrue("encode decode failed.", Arrays.equals(expectedReturn, actualReturn));

    assertEquals("Original and destination string do not match", data, new String(actualReturn));
  }
  /** Creates an Message through the advance createMessage() method and inspects its parameters. */
  public void testCreateMessage2() {
    String body =
        "This is an IM coming from the tested implementation" + " on " + new Date().toString();
    String contentType = "text/html";
    String encoding = "UTF-16";
    String subject = "test message";
    net.java.sip.communicator.service.protocol.Message msg =
        opSetBasicIM.createMessage(body.getBytes(), contentType, encoding, subject);

    assertEquals("message body", body, msg.getContent());
    assertTrue("message body bytes", Arrays.equals(body.getBytes(), msg.getRawData()));
    assertEquals("message length", body.length(), msg.getSize());
    assertEquals("message content type", contentType, msg.getContentType());
    assertEquals("message encoding", encoding, msg.getEncoding());
    assertNotNull("message uid", msg.getMessageUID());

    // a further test on message uid.
    net.java.sip.communicator.service.protocol.Message msg2 = opSetBasicIM.createMessage(body);
    assertFalse("message uid", msg.getMessageUID().equals(msg2.getMessageUID()));
  }
  static {
    bannedYuvCodecs = new ArrayList<String>();

    // Banned H264 encoders/decoders
    // Crashes
    bannedYuvCodecs.add("OMX.SEC.avc.enc");
    bannedYuvCodecs.add("OMX.SEC.h263.enc");
    // Don't support 3.1 profile used by Jitsi
    bannedYuvCodecs.add("OMX.Nvidia.h264.decode");
    // bannedYuvCodecs.add("OMX.SEC.avc.dec");

    // Banned VP8 encoders/decoders
    bannedYuvCodecs.add("OMX.SEC.vp8.dec");
    // This one works only for res 176x144
    bannedYuvCodecs.add("OMX.google.vpx.encoder");

    for (int codecIndex = 0, codecCount = MediaCodecList.getCodecCount();
        codecIndex < codecCount;
        codecIndex++) {
      MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(codecIndex);
      logger.info(
          "Discovered codec: "
              + codecInfo.getName()
              + "/"
              + Arrays.toString(codecInfo.getSupportedTypes()));
      CodecInfo ci = CodecInfo.getCodecInfo(codecInfo);
      if (ci != null) {
        codecs.add(ci);
        ci.setBanned(bannedYuvCodecs.contains(ci.getName()));
      }
    }
    logger.info("Selected H264 encoder: " + getCodecForType(MEDIA_CODEC_TYPE_H264, true));
    logger.info("Selected H264 decoder: " + getCodecForType(MEDIA_CODEC_TYPE_H264, false));
    logger.info("Selected H263 encoder: " + getCodecForType(MEDIA_CODEC_TYPE_H263, true));
    logger.info("Selected H263 decoder: " + getCodecForType(MEDIA_CODEC_TYPE_H263, false));
    logger.info("Selected VP8 encoder: " + getCodecForType(MEDIA_CODEC_TYPE_VP8, true));
    logger.info("Selected VP8 decoder: " + getCodecForType(MEDIA_CODEC_TYPE_VP8, false));
  }
  /** Creates an Message through the simple createMessage() method and inspects its parameters. */
  public void testCreateMessage1() {
    String body =
        "This is an IM coming from the tested implementation" + " on " + new Date().toString();
    net.java.sip.communicator.service.protocol.Message msg = opSetBasicIM1.createMessage(body);

    assertEquals("message body", body, msg.getContent());
    assertTrue("message body bytes", Arrays.equals(body.getBytes(), msg.getRawData()));
    assertEquals("message length", body.length(), msg.getSize());
    assertEquals(
        "message content type",
        OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE,
        msg.getContentType());

    assertEquals(
        "message encoding",
        OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING,
        msg.getEncoding());

    assertNotNull("message uid", msg.getMessageUID());

    // a further test on message uid.
    net.java.sip.communicator.service.protocol.Message msg2 = opSetBasicIM1.createMessage(body);
    assertFalse("message uid", msg.getMessageUID().equals(msg2.getMessageUID()));
  }
Example #6
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);
    }
  }
  /**
   * Construct (with WhiteboardSession) and send a WhiteboardObject to a contact.
   *
   * @param wbSession the white-board session, to which the object would be send
   * @param ws WhiteboardShape to convert and send
   * @param c contact
   * @return WhiteboardObject sent
   */
  public WhiteboardObject sendWhiteboardObject(WhiteboardSession wbSession, WhiteboardShape ws)
      throws OperationFailedException {
    Vector supportedWBO = new Vector(Arrays.asList(wbSession.getSupportedWhiteboardObjects()));

    if (ws instanceof WhiteboardObjectPath) {
      if (!supportedWBO.contains(WhiteboardObjectPath.NAME)) return null;
      WhiteboardObjectPath obj =
          (WhiteboardObjectPath) wbSession.createWhiteboardObject(WhiteboardObjectPath.NAME);
      ws.setID(obj.getID());
      obj.setPoints(((WhiteboardObjectPath) ws).getPoints());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);
      return obj;
    } else if (ws instanceof WhiteboardObjectPolyLine) {
      if (!supportedWBO.contains(WhiteboardObjectPolyLine.NAME)) return null;
      WhiteboardObjectPolyLine obj =
          (WhiteboardObjectPolyLine)
              wbSession.createWhiteboardObject(WhiteboardObjectPolyLine.NAME);
      ws.setID(obj.getID());
      obj.setPoints(((WhiteboardObjectPolyLine) ws).getPoints());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);
      return obj;
    } else if (ws instanceof WhiteboardObjectPolygon) {
      if (!supportedWBO.contains(WhiteboardObjectPolygon.NAME)) return null;
      WhiteboardObjectPolygon obj =
          (WhiteboardObjectPolygon) wbSession.createWhiteboardObject(WhiteboardObjectPolygon.NAME);
      ws.setID(obj.getID());
      obj.setPoints(((WhiteboardObjectPolygon) ws).getPoints());
      obj.setBackgroundColor(((WhiteboardObjectPolygon) ws).getBackgroundColor());
      obj.setFill(((WhiteboardObjectPolygon) ws).isFill());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);
      return obj;
    } else if (ws instanceof WhiteboardObjectLine) {
      if (!supportedWBO.contains(WhiteboardObjectLine.NAME)) return null;
      WhiteboardObjectLine obj =
          (WhiteboardObjectLine) wbSession.createWhiteboardObject(WhiteboardObjectLine.NAME);
      ws.setID(obj.getID());
      obj.setWhiteboardPointStart(((WhiteboardObjectLine) ws).getWhiteboardPointStart());
      obj.setWhiteboardPointEnd(((WhiteboardObjectLine) ws).getWhiteboardPointEnd());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);
      return obj;
    } else if (ws instanceof WhiteboardObjectRect) {
      if (!supportedWBO.contains(WhiteboardObjectRect.NAME)) return null;
      WhiteboardObjectRect obj =
          (WhiteboardObjectRect) wbSession.createWhiteboardObject(WhiteboardObjectRect.NAME);
      ws.setID(obj.getID());
      obj.setFill(((WhiteboardObjectRect) ws).isFill());
      obj.setHeight(((WhiteboardObjectRect) ws).getHeight());
      obj.setWhiteboardPoint(((WhiteboardObjectRect) ws).getWhiteboardPoint());
      obj.setWidth((((WhiteboardObjectRect) ws)).getWidth());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);
      return obj;
    } else if (ws instanceof WhiteboardObjectCircle) {
      if (!supportedWBO.contains(WhiteboardObjectCircle.NAME)) return null;
      WhiteboardObjectCircle obj =
          (WhiteboardObjectCircle) wbSession.createWhiteboardObject(WhiteboardObjectCircle.NAME);
      ws.setID(obj.getID());
      obj.setFill(((WhiteboardObjectCircle) ws).isFill());
      obj.setRadius(((WhiteboardObjectCircle) ws).getRadius());
      obj.setWhiteboardPoint(((WhiteboardObjectCircle) ws).getWhiteboardPoint());
      obj.setBackgroundColor((((WhiteboardObjectCircle) ws)).getBackgroundColor());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);
      return obj;
    } else if (ws instanceof WhiteboardObjectText) {
      if (!supportedWBO.contains(WhiteboardObjectText.NAME)) return null;
      WhiteboardObjectText obj =
          (WhiteboardObjectText) wbSession.createWhiteboardObject(WhiteboardObjectText.NAME);
      ws.setID(obj.getID());
      obj.setFontName(((WhiteboardObjectText) ws).getFontName());
      obj.setFontSize(((WhiteboardObjectText) ws).getFontSize());
      obj.setText(((WhiteboardObjectText) ws).getText());
      obj.setWhiteboardPoint(((WhiteboardObjectText) ws).getWhiteboardPoint());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);
      return obj;
    } else if (ws instanceof WhiteboardObjectImage) {
      if (!supportedWBO.contains(WhiteboardObjectImage.NAME)) return null;
      WhiteboardObjectImage obj =
          (WhiteboardObjectImage) wbSession.createWhiteboardObject(WhiteboardObjectImage.NAME);
      ws.setID(obj.getID());
      obj.setBackgroundImage(((WhiteboardObjectImage) ws).getBackgroundImage());
      obj.setHeight(((WhiteboardObjectImage) ws).getHeight());
      obj.setWhiteboardPoint(((WhiteboardObjectImage) ws).getWhiteboardPoint());
      obj.setWidth(((WhiteboardObjectImage) ws).getWidth());
      obj.setColor(ws.getColor());
      obj.setThickness(ws.getThickness());
      wbSession.sendWhiteboardObject(obj);

      return obj;
    }

    return null;
  }