mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-16 17:41:52 +03:00
JNI calls for log
This commit is contained in:
committed by
Felipe Zimmerle
parent
c18fe9ea8a
commit
455cbbac9e
@@ -1,6 +1,5 @@
|
||||
|
||||
#undef inline
|
||||
#define inline __inline //__ for C
|
||||
#define inline __inline
|
||||
|
||||
//#include <stdio.h>
|
||||
#include "org_modsecurity_ModSecurity.h"
|
||||
@@ -8,30 +7,30 @@
|
||||
#include "api.h"
|
||||
|
||||
|
||||
//#define MODSECURITY_JAVACLASS "org/modsecurity/ModSecurity"
|
||||
//
|
||||
//#define MODSECURITY_LOGMETHOD "log"
|
||||
//#define MODSECURITY_LOGSIG "(ILjava/lang/String;)V"
|
||||
#define MODSECURITY_JAVACLASS "org/modsecurity/ModSecurity"
|
||||
|
||||
//JavaVM *jvm;
|
||||
//jobject modSecurityInstance;
|
||||
//jclass modSecurityClass;
|
||||
#define MODSECURITY_LOGMETHOD "log"
|
||||
#define MODSECURITY_LOGSIG "(ILjava/lang/String;)V"
|
||||
|
||||
JavaVM *jvm;
|
||||
jobject modSecurityInstance;
|
||||
jclass modSecurityClass;
|
||||
//
|
||||
void logSec(void *obj, int level, char *str)
|
||||
{
|
||||
// //JNIEnv *env;
|
||||
// //jstring jStr;
|
||||
// //jmethodID logMethod;
|
||||
// // (*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
|
||||
//
|
||||
// //jStr = (*env)->NewStringUTF(env, str);
|
||||
// //
|
||||
// //logMethod = (*env)->GetMethodID(env, modSecurityClass, MODSECURITY_LOGMETHOD, MODSECURITY_LOGSIG);
|
||||
// //(*env)->CallVoidMethod(env, modSecurityInstance, logMethod, level, jStr);
|
||||
// //
|
||||
// //(*env)->ReleaseStringUTFChars(env, jStr, str);
|
||||
//
|
||||
// //(*jvm)->DetachCurrentThread(jvm);
|
||||
JNIEnv *env;
|
||||
jstring jStr;
|
||||
jmethodID logMethod;
|
||||
(*jvm)->AttachCurrentThread(jvm, (void **)&env, NULL);
|
||||
|
||||
jStr = (*env)->NewStringUTF(env, str);
|
||||
|
||||
logMethod = (*env)->GetMethodID(env, modSecurityClass, MODSECURITY_LOGMETHOD, MODSECURITY_LOGSIG);
|
||||
(*env)->CallVoidMethod(env, modSecurityInstance, logMethod, level, jStr);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jStr, str);
|
||||
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +56,12 @@ apr_status_t WriteResponseCallback(request_rec *r, char *buf, unsigned int lengt
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_modsecurity_ModSecurity_initialize(JNIEnv *env, jobject obj)
|
||||
{
|
||||
//jclass localCls;
|
||||
//(*env)->GetJavaVM(env, &jvm);
|
||||
//modSecurityInstance = (*env)->NewGlobalRef(env, obj);
|
||||
//localCls = (*env)->FindClass(env, MODSECURITY_JAVACLASS);
|
||||
//modSecurityClass = (jclass) (*env)->NewGlobalRef(env, localCls);
|
||||
//(*env)->DeleteLocalRef(env, localCls);
|
||||
jclass localCls;
|
||||
(*env)->GetJavaVM(env, &jvm);
|
||||
modSecurityInstance = (*env)->NewGlobalRef(env, obj);
|
||||
localCls = (*env)->FindClass(env, MODSECURITY_JAVACLASS);
|
||||
modSecurityClass = (jclass) (*env)->NewGlobalRef(env, localCls);
|
||||
(*env)->DeleteLocalRef(env, localCls);
|
||||
|
||||
modsecSetLogHook(NULL, logSec);
|
||||
|
||||
@@ -76,7 +75,7 @@ JNIEXPORT jint JNICALL Java_org_modsecurity_ModSecurity_initialize(JNIEnv *env,
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_modsecurity_ModSecurity_destroy(JNIEnv *env, jobject obj)
|
||||
{
|
||||
// //(*env)->DeleteGlobalRef(env, modSecurityInstance);
|
||||
// //(*env)->DeleteGlobalRef(env, modSecurityClass);
|
||||
(*env)->DeleteGlobalRef(env, modSecurityInstance);
|
||||
(*env)->DeleteGlobalRef(env, modSecurityClass);
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user