#include <jni.h> #include "jni_nativeBase.h" #include <stdio.h> #include <common/tools/tls_files.h> #include "d:\\tis\\source\\admin\\sxa\\sxa.h" #include "d:\\tis\\source\\admin\\sxa\\sxa_routines.h" extern void *thePointerToIt ; extern void **theNextElement ; extern VArray theNodes; extern VArray theDispatchers; extern MsgBase* theMsgBase; extern bool theResult ; extern BArray gpRegisteredTypes; /* * Class: jni_nativeBase * Method: getIntNative * Signature: ([I)I */ JNIEXPORT jint JNICALL Java_jni_nativeBase_getIntNative (JNIEnv *env, jclass, jintArray intArray) { RFC1157VarBind* varBindPtr = (RFC1157VarBind*) calloc(1,sizeof(RFC1157VarBind)); varBindPtr->name.idLength = env->GetArrayLength(intArray); varBindPtr->name.ids = (unsigned int*) env->GetIntArrayElements(intArray,0); ResolveVarBind(varBindPtr,ASN_RFC1157_GETREQUEST); return varBindPtr->value.asnValue.number; } /* * Class: jni_nativeBase * Method: getStringNative * Signature: ([I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_jni_nativeBase_getStringNative (JNIEnv *env, jclass, jintArray intArray) { RFC1157VarBind* varBindPtr = (RFC1157VarBind*) calloc(1,sizeof(RFC1157VarBind)); char returnString[128]; varBindPtr->name.idLength = env->GetArrayLength(intArray); varBindPtr->name.ids = (unsigned int*) env->GetIntArrayElements(intArray,0); ResolveVarBind(varBindPtr,ASN_RFC1157_GETREQUEST); sprintf(returnString, "%s", varBindPtr->value.asnValue.string.stream); return env->NewStringUTF(returnString); } /* * Class: jni_nativeBase * Method: getNextIntNative * Signature: ([[I)I */ JNIEXPORT jint JNICALL Java_jni_nativeBase_getNextIntNative (JNIEnv *env, jclass, jobjectArray objArray, jint oidIndex) { RFC1157VarBind* varBindPtr = (RFC1157VarBind*) calloc(1,sizeof(RFC1157VarBind)); // Read the incoming OID jintArray xxx = (jintArray) env->GetObjectArrayElement(objArray, oidIndex); varBindPtr->name.idLength = env->GetArrayLength(xxx); varBindPtr->name.ids = (unsigned int*) env->GetIntArrayElements(xxx,0); // Send the GETNEXT Request ResolveVarBind(varBindPtr,ASN_RFC1157_GETNEXTREQUEST); // Update OID for next GETNEXT-Request jobjectArray yyy = (jobjectArray)env->NewIntArray(varBindPtr->name.idLength); env->SetIntArrayRegion((jintArray)yyy,0,varBindPtr->name.idLength,(long*)varBindPtr->name.ids); env->SetObjectArrayElement(objArray,oidIndex,yyy); // attention: watch out for memory leaks! //Return Integer Value of assigned MIB-Variable return (int) varBindPtr->value.asnValue.number; } /* * Class: jni_nativeBase * Method: getNextStringNative * Signature: ([[I)Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_jni_nativeBase_getNextStringNative (JNIEnv *env, jclass, jobjectArray objArray, jint oidIndex) { RFC1157VarBind* varBindPtr = (RFC1157VarBind*) calloc(1,sizeof(RFC1157VarBind)); char returnString[128]; // Read the incoming OID jintArray xxx = (jintArray) env->GetObjectArrayElement(objArray, oidIndex); varBindPtr->name.idLength = env->GetArrayLength(xxx); varBindPtr->name.ids = (unsigned int*) env->GetIntArrayElements(xxx,0); // Send the GETNEXT Request ResolveVarBind(varBindPtr,ASN_RFC1157_GETNEXTREQUEST); // Update OID for next GETNEXT-Request jobjectArray yyy = (jobjectArray)env->NewIntArray(varBindPtr->name.idLength); env->SetIntArrayRegion((jintArray)yyy,0,varBindPtr->name.idLength,(long*)varBindPtr->name.ids); env->SetObjectArrayElement(objArray,oidIndex,yyy); // attention: watch out for memory leaks! //Return Integer Value of assigned MIB-Variable sprintf(returnString, "%s", varBindPtr->value.asnValue.string.stream); return env->NewStringUTF(returnString); } /* * Class: jni_nativeBase * Method: setNative * Signature: ([II)V */ JNIEXPORT void JNICALL Java_jni_nativeBase_setNative___3II (JNIEnv *env, jclass, jintArray intArray, jint newInt) { RFC1157VarBind* varBindPtr = (RFC1157VarBind*) calloc(1,sizeof(RFC1157VarBind)); varBindPtr->name.idLength = env->GetArrayLength(intArray); varBindPtr->name.ids = (unsigned int*) env->GetIntArrayElements(intArray,0); varBindPtr->value.asnType = ASN_INTEGER; varBindPtr->value.asnValue.number = newInt; ResolveVarBind(varBindPtr,ASN_RFC1157_SETREQUEST); } /* * Class: jni_nativeBase * Method: setNative * Signature: ([ILjava/lang/String;)V */ JNIEXPORT void JNICALL Java_jni_nativeBase_setNative___3ILjava_lang_String_2 (JNIEnv *env, jclass, jintArray intArray, jstring newString) { RFC1157VarBind* varBindPtr = (RFC1157VarBind*) calloc(1,sizeof(RFC1157VarBind)); const char* pStr = env->GetStringUTFChars(newString,0); varBindPtr->name.idLength = env->GetArrayLength(intArray); varBindPtr->name.ids = (unsigned int*) env->GetIntArrayElements(intArray,0); varBindPtr->value.asnType = ASN_OCTETSTRING; varBindPtr->value.asnValue.string.stream = (unsigned char*) pStr; varBindPtr->value.asnValue.string.length = env->GetStringLength(newString); ResolveVarBind(varBindPtr,ASN_RFC1157_SETREQUEST); env->ReleaseStringUTFChars(newString, pStr); } /* * Class: jni_nativeBase * Method: removeNative * Signature: ([I)V */ JNIEXPORT void JNICALL Java_jni_nativeBase_removeNative (JNIEnv *env, jclass, jintArray intArray) { RFC1157VarBind* varBindPtr = (RFC1157VarBind*) calloc(1,sizeof(RFC1157VarBind)); varBindPtr->name.idLength = env->GetArrayLength(intArray); varBindPtr->name.ids = (unsigned int*) env->GetIntArrayElements(intArray,0); varBindPtr->value.asnType = ASN_INTEGER; varBindPtr->value.asnValue.number = SNMP_NULL; ResolveVarBind(varBindPtr,ASN_RFC1157_SETREQUEST); } /* * Class: jni_nativeBase * Method: buildCAsnNodeStructure * Signature: ()V */ JNIEXPORT void JNICALL Java_jni_nativeBase_buildCAsnNodeStructure (JNIEnv *, jclass) { char path[MAX_FILENAME_LENGTH]; FILE* mibFile ; char nextLine[256] ; VString* words ; UINT min_oid[] = { 1, 1}; AsnObjectIdentifier a_small_oid = { OID_SIZEOF(min_oid), min_oid }; UINT max_oid[] = { 1, 9}; // AsnObjectIdentifier a_big_oid = { OID_SIZEOF(max_oid), max_oid }; InitializeCriticalSection(&gAlarmMailerCritSect); // alarm mailer SetTypeRegistry(&gpRegisteredTypes); if (!CfgGetFileRoot("\\config\\tis_mib.mdf", path, sizeof(path))) exit(1) mibFile = fopen(path, "rt") ; if (mibFile != NULL) { // Start node list with lowest possible OID thePointerToIt = new CAsnNode(a_small_oid) ; if (0 == thePointerToIt) { theResult = false ; } else { theNextElement = (void**)theNodes.Append() ; *theNextElement = thePointerToIt ; } while (0 != fgets(nextLine,256,mibFile)) { words = LineToWords(nextLine) ; if (*(words[0]) != 0) {} if (words[0] == "NODE") { thePointerToIt = new CAsnNode(words) ; if (0 == thePointerToIt) { theResult = false ; } else { static_cast<CAsnNode*>(thePointerToIt)->Log() ; theNextElement = (void**)theNodes.Append() ; *theNextElement = thePointerToIt ; } } else if (words[0] == "DISPATCHER") { thePointerToIt = new CDispatcherProperties(words) ; if (0 == thePointerToIt) { theResult = false ; } else { static_cast<CDispatcherProperties*>(thePointerToIt)->Log() ; theNextElement = (void**)theDispatchers.Append() ; *theNextElement = thePointerToIt ; } } fclose(mibFile) ; } else { theResult = false ; } InitDispatch(); InitDispIPC(); }