Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add token lock/unlock callbacks to Java bindings
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Aug 12, 2014
1 parent 731bed6 commit f85299e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions java/src/org/infradead/libopenconnect/LibOpenConnect.java
Expand Up @@ -59,6 +59,8 @@ public abstract class LibOpenConnect {
public int onWriteNewConfig(byte[] buf) { return 0; }
public void onProtectSocket(int fd) { }
public void onStatsUpdate(VPNStats stats) { }
public int onTokenLock() { return 0; }
public int onTokenUnlock(String newToken) { return 0; }

/* create/destroy library instances */

Expand Down
45 changes: 45 additions & 0 deletions jni.c
Expand Up @@ -525,6 +525,49 @@ static void progress_cb(void *privdata, int level, const char *fmt, ...)
(*ctx->jenv)->PopLocalFrame(ctx->jenv, NULL);
}

static int lock_token_cb(void *privdata)
{
struct libctx *ctx = privdata;
jmethodID mid;
int ret = -1;

if ((*ctx->jenv)->PushLocalFrame(ctx->jenv, 256) < 0)
return -1;

mid = get_obj_mid(ctx, ctx->jobj, "onTokenLock", "(V)I");
if (!mid)
goto out;

(*ctx->jenv)->CallIntMethod(ctx->jenv, ctx->jobj, mid);

out:
(*ctx->jenv)->PopLocalFrame(ctx->jenv, NULL);
return ret;
}

static int unlock_token_cb(void *privdata, const char *new_token)
{
struct libctx *ctx = privdata;
jstring jtoken;
int ret = -1;
jmethodID mid;

if ((*ctx->jenv)->PushLocalFrame(ctx->jenv, 256) < 0)
return -1;

jtoken = dup_to_jstring(ctx->jenv, new_token);
if (!jtoken)
goto out;

mid = get_obj_mid(ctx, ctx->jobj, "onTokenUnlock", "(Ljava/lang/String;)I");
if (mid)
ret = (*ctx->jenv)->CallIntMethod(ctx->jenv, ctx->jobj, mid, jtoken);

out:
(*ctx->jenv)->PopLocalFrame(ctx->jenv, NULL);
return ret;
}

/* Library init/uninit */

static jobject init_async_lock(struct libctx *ctx)
Expand Down Expand Up @@ -566,6 +609,8 @@ JNIEXPORT jlong JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_init(
if (!ctx->vpninfo)
goto bad_delete_ref;

openconnect_set_token_callbacks(ctx->vpninfo, ctx, lock_token_cb,
unlock_token_cb);
openconnect_set_protect_socket_handler(ctx->vpninfo, protect_socket_cb);
openconnect_set_stats_handler(ctx->vpninfo, stats_cb);

Expand Down

0 comments on commit f85299e

Please sign in to comment.