Skip to content

Instantly share code, notes, and snippets.

View sonOfRa's full-sized avatar

Simon Levermann sonOfRa

View GitHub Profile
/*
* Class: im_tox_jtoxcore_JTox
* Method: tox_sendmessage
* Signature: (JILjava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_im_tox_jtoxcore_JTox_tox_1sendmessage__JILjava_lang_String_2
(JNIEnv *, jobject, jlong, jint, jstring);
/*
* Class: im_tox_jtoxcore_JTox
/* Get name of friendnumber and put it in name.
* name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes.
*
* return 0 if success.
* return -1 if failure.
*/
int tox_getname(Tox *tox, int friendnumber, uint8_t *name);
VS
/**
* Null-terminate the given string. Length is the length of the original string,
* out must be allocated with a size of at least length+1
*/
void nullterminate(uint8_t *in, uint16_t length, char *out) {
memcpy(out, in, length);
out[length] = '\0';
}
# Define a variable for classpath
CLASS_PATH = ../bin
GCC_INCLUDE = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
# Package name
PACKAGE_NAME = im.tox.jtoxcore
all : libjtox.so
libjtox.so : JTox.o
public String arrListtoStr(ArrayList<String> list) {
StringBuffer buff = new StringBuffer();
for(String str : list) {
buff.append(str);
}
return str;
}
@sonOfRa
sonOfRa / JTox.c
Last active December 23, 2015 00:09
Mysterious segfaults
JNIEXPORT jint JNICALL Java_im_tox_jtoxcore_JTox_tox_1addfriend(JNIEnv * env,
jobject obj, jlong messenger, jstring address, jstring data) {
const uint8_t *_address = (*env)->GetStringUTFChars(env, address, 0);
const uint8_t *_data = (*env)->GetStringUTFChars(env, data, 0);
uint8_t __address[TOX_FRIEND_ADDRESS_SIZE];
hex_to_addr(_address, __address);
printf("beep\n");
fflush(stdout);
@sonOfRa
sonOfRa / JTox.c
Created September 19, 2013 15:08
Mysterious failure to call methods
JNIEXPORT void JNICALL Java_im_tox_jtoxcore_JTox_tox_1onfriendrequest(
JNIEnv * env, jobject obj, jlong messenger, jobject callback) {
tox_jni_globals_t *_messenger = (tox_jni_globals_t *) messenger;
if (_messenger->frqc) {
if (_messenger->frqc->jobj) {
(*env)->DeleteGlobalRef(env, _messenger->frqc->jobj);
}
free(_messenger->frqc);
}
public static String getByteString(byte[] in) throws ToxException {
try {
if (in == null) {
return "";
}
System.out.println(in.length); // This is line 1399
return new String(in, "UTF-8");
} catch (UnsupportedEncodingException e) {
ToxException e1 = new ToxException(ToxError.TOX_UNKNOWN);
e1.initCause(e);
./configure --host="i686-pc-mingw32" CFLAGS="-march=i686 -mtune=generic" --prefix=/usr/i686-pc-mingw32 --with-sysroot=/usr/i686-pc-mingw32
make
cd . && /bin/sh ./config.status libtoxcore.pc
config.status: creating libtoxcore.pc
make all-recursive
make[1]: Entering directory `/home/simon/repos/tox'
Making all in build
make[2]: Entering directory `/home/simon/repos/tox/build'
CC ../toxcore/libtoxcore_la-DHT.lo
../toxcore/DHT.c: In function 'addto_lists':
../toxcore/DHT.c:459:5: warning: passing argument 1 of 'IN6_IS_ADDR_V4MAPPED' from incompatible pointer type [enabled by default]
In file included from ../toxcore/network.h:40:0,
from ../toxcore/Lossless_UDP.h:27,
from ../toxcore/net_crypto.h:27,
from ../toxcore/DHT.h:27,
from ../toxcore/DHT.c:30:
/usr/x86_64-w64-mingw32/mingw/include/ws2tcpip.h:99:5: note: expected 'const struct in6_addr *' but argument is of type 'union IP6 *'
libtool: link: warning: library `/usr/x86_64-w64-mingw32/lib/libsodium.la' was moved.
In file included from ../other/DHT_bootstrap.c:36:0: