Global charonservice_t object added to libandroidbridge
This is later used to call Java methods on CharonVpnService via JNI.
This commit is contained in:
@@ -4,7 +4,7 @@ include $(CLEAR_VARS)
|
|||||||
# copy-n-paste from Makefile.am
|
# copy-n-paste from Makefile.am
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
android_jni.c android_jni.h \
|
android_jni.c android_jni.h \
|
||||||
charonservice.c
|
charonservice.c charonservice.h
|
||||||
|
|
||||||
# build libandroidbridge -------------------------------------------------------
|
# build libandroidbridge -------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
|
#include "charonservice.h"
|
||||||
#include "android_jni.h"
|
#include "android_jni.h"
|
||||||
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
@@ -25,6 +26,23 @@
|
|||||||
#include <ipsec.h>
|
#include <ipsec.h>
|
||||||
#include <library.h>
|
#include <library.h>
|
||||||
|
|
||||||
|
typedef struct private_charonservice_t private_charonservice_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* private data of charonservice
|
||||||
|
*/
|
||||||
|
struct private_charonservice_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public interface
|
||||||
|
*/
|
||||||
|
charonservice_t public;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single instance of charonservice_t.
|
||||||
|
*/
|
||||||
|
charonservice_t *charonservice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hook in library for debugging messages
|
* hook in library for debugging messages
|
||||||
@@ -60,6 +78,31 @@ static void dbg_android(debug_t group, level_t level, char *fmt, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the charonservice object
|
||||||
|
*/
|
||||||
|
static void charonservice_init()
|
||||||
|
{
|
||||||
|
private_charonservice_t *this;
|
||||||
|
|
||||||
|
INIT(this,
|
||||||
|
.public = {
|
||||||
|
},
|
||||||
|
);
|
||||||
|
charonservice = &this->public;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deinitialize the charonservice object
|
||||||
|
*/
|
||||||
|
static void charonservice_deinit()
|
||||||
|
{
|
||||||
|
private_charonservice_t *this = (private_charonservice_t*)charonservice;
|
||||||
|
|
||||||
|
free(this);
|
||||||
|
charonservice = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize charon and the libraries via JNI
|
* Initialize charon and the libraries via JNI
|
||||||
*/
|
*/
|
||||||
@@ -90,10 +133,13 @@ JNI_METHOD(CharonVpnService, initializeCharon, void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
charonservice_init();
|
||||||
|
|
||||||
if (!libcharon_init("charon") ||
|
if (!libcharon_init("charon") ||
|
||||||
!charon->initialize(charon, PLUGINS))
|
!charon->initialize(charon, PLUGINS))
|
||||||
{
|
{
|
||||||
libcharon_deinit();
|
libcharon_deinit();
|
||||||
|
charonservice_deinit();
|
||||||
libipsec_deinit();
|
libipsec_deinit();
|
||||||
libhydra_deinit();
|
libhydra_deinit();
|
||||||
library_deinit();
|
library_deinit();
|
||||||
@@ -105,11 +151,12 @@ JNI_METHOD(CharonVpnService, initializeCharon, void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize charon and the libraries via JNI
|
* Deinitialize charon and all libraries
|
||||||
*/
|
*/
|
||||||
JNI_METHOD(CharonVpnService, deinitializeCharon, void)
|
JNI_METHOD(CharonVpnService, deinitializeCharon, void)
|
||||||
{
|
{
|
||||||
libcharon_deinit();
|
libcharon_deinit();
|
||||||
|
charonservice_deinit();
|
||||||
libipsec_deinit();
|
libipsec_deinit();
|
||||||
libhydra_deinit();
|
libhydra_deinit();
|
||||||
library_deinit();
|
library_deinit();
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Tobias Brunner
|
||||||
|
* Copyright (C) 2012 Giuliano Grassi
|
||||||
|
* Copyright (C) 2012 Ralf Sager
|
||||||
|
* Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup libandroidbridge libandroidbridge
|
||||||
|
*
|
||||||
|
* @defgroup charonservice charonservice
|
||||||
|
* @{ @ingroup libandroidbridge
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CHARONSERVICE_H_
|
||||||
|
#define CHARONSERVICE_H_
|
||||||
|
|
||||||
|
typedef struct charonservice_t charonservice_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public interface of charonservice.
|
||||||
|
*
|
||||||
|
* Used to communicate with CharonVpnService via JNI
|
||||||
|
*/
|
||||||
|
struct charonservice_t {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The single instance of charonservice_t.
|
||||||
|
*
|
||||||
|
* Set between JNI calls to initializeCharon() and deinitializeCharon().
|
||||||
|
*/
|
||||||
|
extern charonservice_t *charonservice;
|
||||||
|
|
||||||
|
#endif /** CHARONSERVICE_H_ @}*/
|
||||||
Reference in New Issue
Block a user