* #35924 (zrtp): switch to libzrtpcpp
diff --git a/jni/libzrtp/sources/clients/tivi/swigJava/SessionTest.java b/jni/libzrtp/sources/clients/tivi/swigJava/SessionTest.java
new file mode 100644
index 0000000..a90ce72
--- /dev/null
+++ b/jni/libzrtp/sources/clients/tivi/swigJava/SessionTest.java
@@ -0,0 +1,231 @@
+/*
+ * Copyright (c) 2013 Slient Circle LLC. All rights reserved.
+ *
+ *
+ * @author Werner Dittmann <Werner.Dittmann@t-online.de>
+ */
+
+import java.net.*;
+
+import wd.tivi.*;
+
+public class SessionTest {
+ static {
+ System.loadLibrary("zrtptivi");
+ }
+
+ CtZrtpSession session;
+ TestCallbackAudio callback;
+ TestSendCallbackAudio sendCallback;
+ DatagramSocket dgSock;
+
+ InetAddress localAddr;
+ InetAddress remoteAddr;
+
+ long uiSSRC = 0xfeedbacc;
+
+
+ // This is the callback that we use for audio stream
+ private class TestCallbackAudio extends CtZrtpCb {
+
+ @Override
+ public void onNewZrtpStatus(CtZrtpSession session, String p, CtZrtpSession.streamName streamNm) {
+ System.out.println("new status: " + p);
+ }
+
+ @Override
+ public void onNeedEnroll(CtZrtpSession session, CtZrtpSession.streamName streamNm, int info) {
+ System.out.println("Need enroll\n");
+ }
+
+ @Override
+ public void onPeer(CtZrtpSession session, String name, int iIsVerified, CtZrtpSession.streamName streamNm) {
+ System.out.println("onPeer: " + name);
+
+ byte[] buffer = new byte[30];
+
+ session.getInfo("rs1", buffer, buffer.length);
+ System.out.print("RS1: " + new String(buffer) + " ");
+
+ session.getInfo("rs2", buffer, buffer.length);
+ System.out.print("RS2: " + new String(buffer) + " ");
+
+ session.getInfo("pbx", buffer, buffer.length);
+ System.out.print("PBX: " + new String(buffer) + " ");
+
+ session.getInfo("aux", buffer, buffer.length);
+ System.out.println("AUX: " + new String(buffer) + " ");
+
+ session.getInfo("lbClient", buffer, buffer.length);
+ System.out.print("Client: " + new String(buffer) + " ");
+
+ session.getInfo("lbVersion", buffer, buffer.length);
+ System.out.print("Version: " + new String(buffer) + " ");
+
+ session.getInfo("lbChiper", buffer, buffer.length);
+ System.out.print("cipher: " + new String(buffer) + " ");
+
+ session.getInfo("lbHash", buffer, buffer.length);
+ System.out.print("hash: " + new String(buffer) + " ");
+
+ session.getInfo("lbAuthTag", buffer, buffer.length);
+ System.out.print("auth: " + new String(buffer) + " ");
+
+ session.getInfo("lbKeyExchange", buffer, buffer.length);
+ System.out.print("KeyEx: " + new String(buffer) + " ");
+
+ session.getInfo("sc_secure", buffer, buffer.length);
+ System.out.print("SC secure: " + new String(buffer) + " ");
+
+ session.getInfo("sdp_hash", buffer, buffer.length);
+ System.out.println("zrtp-hash: " + new String(buffer) + " ");
+
+ session.setLastPeerNameVerify("TestName", 0);
+ }
+
+ @Override
+ public void onZrtpWarning(CtZrtpSession session, String p, CtZrtpSession.streamName streamNm) {
+ System.out.println("Warning: " + p);
+ }
+ }
+
+ private class TestSendCallbackAudio extends CtZrtpSendCb {
+ @Override
+ public void sendRtp(CtZrtpSession session, byte[] packet, CtZrtpSession.streamName streamNm) {
+// hexdump("ZRTP packet", packet, length);
+ System.out.println("ZRTP send packet, length: " + packet.length);
+ sendData(packet);
+ }
+ }
+
+
+ void sendData(byte[ ]buffer) {
+ DatagramPacket dgram = new DatagramPacket(buffer, buffer.length, remoteAddr, 5004);
+ try {
+ dgSock.send(dgram);
+ }
+ catch (java.io.IOException ex) {
+ System.out.println("cannot send: " + ex);
+ }
+ }
+
+ public void simpleTest(String argv[]) {
+ byte[] helloHash = new byte[100];
+ byte[] dgramBuffer = new byte[2000];
+ long[] newLength = new long[1];
+
+ String local = "127.0.0.1";
+ String remote = "127.0.0.1";
+
+ if (argv.length >= 2) {
+ local = argv[0];
+ remote = argv[1];
+ }
+ // Setup the IP addresses to receive and send packets
+ try {
+ localAddr = InetAddress.getByName(local);
+ remoteAddr = InetAddress.getByName(remote);
+ }
+ catch (java.net.UnknownHostException ex) {
+ System.out.println("Host not known: " + ex);
+ }
+ System.out.println("Address: " + localAddr.getHostAddress() + ", " + remoteAddr.getHostAddress());
+
+ session = new CtZrtpSession();
+ callback = new TestCallbackAudio();
+ sendCallback = new TestSendCallbackAudio();
+
+ session.init(true, true); // audio and video
+
+ session.setUserCallback(callback, CtZrtpSession.streamName.AudioStream);
+ session.setSendCallback(sendCallback, CtZrtpSession.streamName.AudioStream);
+ session.getSignalingHelloHash(helloHash, CtZrtpSession.streamName.AudioStream);
+
+ System.out.println("Our Hello hash: " + new String(helloHash));
+
+ // Our receive datagram socket
+ try {
+ dgSock = new DatagramSocket(5002, localAddr);
+ }
+ catch (java.net.SocketException ex) {
+ System.out.println("cannot create datagram socket: " + ex);
+ }
+
+ if (!session.isStarted(CtZrtpSession.streamName.AudioStream)) {
+ System.out.println("Starting ...");
+ session.start(uiSSRC, CtZrtpSession.streamName.AudioStream);
+ }
+ DatagramPacket dgram = new DatagramPacket(dgramBuffer, dgramBuffer.length);
+ for (;;) {
+ try {
+ dgSock.receive(dgram);
+ }
+ catch (java.io.IOException ex) {
+ System.out.println("cannot receive: " + ex);
+ }
+// hexdump("recv buffer before", dgramBuffer, dgram.getLength());
+ int rc = session.processIncomingRtp(dgramBuffer, (long)dgram.getLength(), newLength, CtZrtpSession.streamName.AudioStream);
+
+ if (rc == 0)
+ continue;
+
+ System.out.println("processing returns: " + rc + ", new length: " + newLength[0]);
+ System.out.println("Received data: "+ new String(dgramBuffer, 12, (int)(newLength[0]-12)));
+// hexdump("recv buffer after", dgramBuffer, dgram.getLength());
+ }
+ }
+
+ public static void main(String argv[]) {
+ CtZrtpSession.initCache("testzid.dat");
+
+ SessionTest stest = new SessionTest();
+ stest.simpleTest(argv);
+ System.out.println("Something works.");
+ try {
+ Thread.sleep(5000);
+ }
+ catch (java.lang.InterruptedException ex) {
+ }
+ }
+
+ private static final char[] hex = "0123456789abcdef".toCharArray();
+
+ /**
+ * Dump a buffer in hex and readable format.
+ *
+ * @param title Printed at the beginning of the dump
+ * @param buf Byte buffer to dump
+ * @param len Number of bytes to dump, should be less or equal
+ * the buffer length
+ */
+ public void hexdump(String title, byte[] buf, int len) {
+ byte b;
+ System.err.println(title);
+ for(int i = 0 ; ; i += 16) {
+ for(int j=0; j < 16; ++j) {
+ if (i+j >= len) {
+ System.err.print(" ");
+ }
+ else {
+ b = buf[i+j];
+ System.err.print(" "+ hex[(b>>>4) &0xf] + hex[b&0xf] );
+ }
+ }
+ System.err.print(" ");
+ for(int j = 0; j < 16; ++j) {
+ if (i+j >= len) break;
+ b = buf[i+j];
+ if ( (byte)(b+1) < 32+1) {
+ System.err.print( '.' );
+ }
+ else {
+ System.err.print( (char)b );
+ }
+ }
+ System.err.println();
+ if (i+16 >= len) {
+ break;
+ }
+ }
+ }
+}
diff --git a/jni/libzrtp/sources/clients/tivi/swigJava/sessionTest.i b/jni/libzrtp/sources/clients/tivi/swigJava/sessionTest.i
new file mode 100644
index 0000000..9219435
--- /dev/null
+++ b/jni/libzrtp/sources/clients/tivi/swigJava/sessionTest.i
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2013 Slient Circle LLC. All rights reserved.
+ *
+ *
+ * @author Werner Dittmann <Werner.Dittmann@t-online.de>
+ */
+
+/*
+ * Call swig: "swig -java -c++ -package wd.tivi -outdir wd/tivi session.i"
+ * Compile wrapper: "g++ -c -I$JAVA_HOME/include -I.. session_wrap.cxx"
+ * Compile Java code: "javac -d class wd/tivi/*.java"
+ */
+
+
+%module (directors="1") tiviSession
+%{
+#include "CtZrtpCallback.h"
+#include "CtZrtpSession.h"
+%}
+%include "typemaps.i"
+%include "std_string.i"
+
+/*
+ * Actually there is no difference in handling of unsigned int and unsigned long
+ * with repect to C++/Java mapping. SWIG maps both to Java Long and retains the
+ * "size_t" in the JNI C code. Refer to SWIG's java/typemap.i file (usually located
+ * in /usr/share/swig/... )
+ *
+ * However, I leave this in to point out that there may be a different handling
+ * required for other architectures.
+ */
+#ifdef ARCH_32
+typedef unsigned int size_t;
+%apply unsigned int *INOUT { size_t *newLength };
+%apply unsigned int *INOUT { size_t *maxLen };
+%apply unsigned int *INOUT { size_t *sendLength };
+
+#else
+
+typedef unsigned long int size_t;
+%apply unsigned long *INOUT { size_t *newLength };
+%apply unsigned long *INOUT { size_t *maxLen };
+%apply unsigned long *INOUT { size_t *sendLength };
+#endif
+
+typedef int int32_t;
+
+%include "various.i"
+
+
+%typemap(in) (uint8_t *BYTE, size_t LENGTH) {
+ $1 = (uint8_t *) JCALL2(GetByteArrayElements, jenv, $input, 0);
+ $2 = (size_t) JCALL1(GetArrayLength, jenv, $input);
+}
+%typemap(jni) (uint8_t *BYTE, size_t LENGTH) "jbyteArray"
+%typemap(jtype) (uint8_t *BYTE, size_t LENGTH) "byte[]"
+%typemap(jstype) (uint8_t *BYTE, size_t LENGTH) "byte[]"
+%typemap(javain) (uint8_t *BYTE, size_t LENGTH) "$javainput"
+
+
+/*
+ * Define a INOUT typemap for uint8_t, largely copied from SWIG's java/typemap.i
+ */
+%typemap(in) (uint8_t *BYTE) {
+ if (!$input) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
+ return $null;
+ }
+ if (JCALL1(GetArrayLength, jenv, $input) == 0) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
+ return $null;
+ }
+ $1 = ($1_ltype) JCALL2(GetByteArrayElements, jenv, $input, 0);
+
+}
+
+%typemap(argout) (uint8_t* BYTE)
+{ JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); }
+
+%typemap(jni) (uint8_t *BYTE) "jbyteArray"
+%typemap(jtype) (uint8_t *BYTE) "byte[]"
+%typemap(jstype) (uint8_t *BYTE) "byte[]"
+%typemap(javain) (uint8_t *BYTE) "$javainput"
+
+/*
+ * Define when to apply the new typemap: if SWIG sees a method signature (also
+ * partial signature) it applies the patterns. "BYTE" is the placeholder for
+ * the real parameter name.
+ */
+%apply (uint8_t *BYTE) { (uint8_t *buffer) };
+
+/*
+ * Converts char* to Java byte[] array and not to Java String as usual.
+ * A Java byte[] is more versatile because we can modify data inside the array
+ * and reuse it as input to some other method.
+ *
+ * The typemap 'char* BYTE' is availabe in SWIG's java/various.i library file thus
+ * we can apply it immediately.
+ */
+%apply char *BYTE { char *helloHash };
+%apply char *BYTE { char *cryptoString };
+%apply char *BYTE { char *sendCryptoStr };
+%apply char *BYTE { char *recvCryptoStr };
+
+/*
+ * Typemaps for the two callback classes. SWIG implements Callback to Java using
+ * its director mechanism. This mechanism allows that you can extend a C++ class
+ * with a Java class and call Java methods that overwrite C++ methods either from
+ * Java code or from C++ code.
+ */
+
+/*
+ * First define the typemap pattern and the lines to insert if this pattern triggers
+ *
+ * The first typemap defines the actions that move the data from the C++ buffer to
+ * a Java byte[]. This is called "input to director java proxy". SWIG inserts
+ * these lines before it calls the Java proxy.
+ *
+ * These typemaps also use the maps defined above for uint8_t* / size_t combination.
+ * The standard SWIG library defines only char* / int combination.
+ */
+%typemap(directorin, descriptor="[B") (uint8_t *BYTE, size_t LENGTH) {
+ jbyteArray jb = (jenv)->NewByteArray($2);
+ (jenv)->SetByteArrayRegion(jb, 0, $2, (jbyte *)$1);
+ $input = jb;
+}
+
+/*
+ * Perform these actions if the Java method returns. In this case we copy the Java
+ * array back to the C++ buffer.
+ */
+%typemap(directorargout) (uint8_t *BYTE, size_t LENGTH)
+%{(jenv)->GetByteArrayRegion($input, 0, $2, (jbyte *)$1); %}
+
+%typemap(javadirectorin) (uint8_t *BYTE, size_t LENGTH) "$jniinput"
+/* %typemap(javadirectorout) (uint8_t *BYTE, size_t LENGTH) "$javacall" */
+
+%apply (uint8_t *BYTE, size_t LENGTH) { (uint8_t* packet, size_t length) };
+
+/*
+ * Use the director feature for the callback classes only.
+ * CAVEAT: these a pure virtual C++ classes. The Java implementation MUST overwrite
+ * all methods, otherwise you get a nice error message and process termination.
+ */
+%feature("director") CtZrtpCb;
+%feature("director") CtZrtpSendCb;
+
+/* Don't confuse SWIG with the __EXPORT macro */
+#define __EXPORT
+%include ../CtZrtpSession.h
+%include ../CtZrtpCallback.h