浏览代码

modules/app_java: refactoring, changed parameter 'force_kam_cmd_exec' to 'force_cmd_exec', updated docs
- moved ThrowNewException from utils to java_support
- removed macro FORCE_CAST_O2P
- removed get_struct_sip_msg
- renamed parameter 'force_kam_cmd_exec' to 'force_cmd_exec'
- updated docs caused parameter change

Konstantin Mosesov 12 年之前
父节点
当前提交
07ddc78df8

+ 1 - 1
modules/app_java/QUICKSTART.TXT

@@ -14,7 +14,7 @@ modparam("app_java", "java_options", "-Djava.compiler=NONE -Djava.class.path=<KA
 
 # This parameter forces execution a kamailio comnmand with java native method KamExec.
 # Note: this is an untested feature, may cause (but may not) a memory leaks if used from embedded languages.
-modparam("app_java", "force_kam_cmd_exec", 1);
+modparam("app_java", "force_cmd_exec", 1);
 
 
 

+ 7 - 7
modules/app_java/README

@@ -28,7 +28,7 @@ Konstantin Mosesov
               4.1. class_name (string)
               4.2. child_init_method (string)
               4.3. java_options (string)
-              4.4. force_kam_cmd_exec (int)
+              4.4. force_cmd_exec (int)
 
         5. Functions
 
@@ -57,7 +57,7 @@ Konstantin Mosesov
    1.4. Set java_options parameter (live configuration)
    1.5. Set java_options parameter (verbose configuration)
    1.6. Set java_options parameter (debug configuration)
-   1.7. Set force_kam_cmd_exec parameter
+   1.7. Set force_cmd_exec parameter
    1.8. Signature: "V"
    1.9. Signature: "Ljava/lang/String;I"
    1.10. Signature: "ZB"
@@ -91,7 +91,7 @@ Chapter 1. Admin Guide
         4.1. class_name (string)
         4.2. child_init_method (string)
         4.3. java_options (string)
-        4.4. force_kam_cmd_exec (int)
+        4.4. force_cmd_exec (int)
 
    5. Functions
 
@@ -166,7 +166,7 @@ Chapter 1. Admin Guide
    4.1. class_name (string)
    4.2. child_init_method (string)
    4.3. java_options (string)
-   4.4. force_kam_cmd_exec (int)
+   4.4. force_cmd_exec (int)
 
 4.1. class_name (string)
 
@@ -225,7 +225,7 @@ ler=NONE -Djava.class.path=/path/to/kamailio/modules:/opt/kamailio/java:/opt/kam
 ailio/java/kamailio.jar")
 ...
 
-4.4. force_kam_cmd_exec (int)
+4.4. force_cmd_exec (int)
 
    This parameter forces execution a kamailio comnmand with java native
    method “KamExec”. # Note: this is an untested yet feature, may cause
@@ -233,9 +233,9 @@ ailio/java/kamailio.jar")
 
    Default value is “0 (off)”.
 
-   Example 1.7. Set force_kam_cmd_exec parameter
+   Example 1.7. Set force_cmd_exec parameter
 ...
-modparam("app_java", "force_kam_cmd_exec", 1)
+modparam("app_java", "force_cmd_exec", 1)
 ...
 
 5. Functions

+ 4 - 4
modules/app_java/README-draft

@@ -26,7 +26,7 @@ Konstantin Mosesov
 	      3.1. class_name (string)
               3.2. child_init_method (string)
 	      3.3. java_options (string)
-	      3.4. force_kam_cmd_exec (int)
+	      3.4. force_cmd_exec (int)
 
         4. Functions
 
@@ -141,7 +141,7 @@ Chapter 1. Admin Guide
         3.1. class_name (string)
         3.2. child_init_method (string)
         3.3. java_options (string)
-	3.4. force_kam_cmd_exec (int)
+	3.4. force_cmd_exec (int)
 
    4. Functions
 
@@ -206,7 +206,7 @@ Chapter 1. Admin Guide
    3.1. class_name (string)
    3.2. child_init_method (string)
    3.3. java_options (string)
-   3.4. force_kam_cmd_exec (int)
+   3.4. force_cmd_exec (int)
 
 3.1. class_name (string)
 
@@ -258,7 +258,7 @@ modparam("app_java", "java_options", "-verbose:gc,class,jni -Djava.compiler=NONE
 modparam("app_java", "java_options", "-Xdebug -verbose:gc,class,jni -Djava.compiler=NONE -Djava.class.path=/path/to/kamailio/modules:/path/to/class_name_file_directory:/path/to/kamailio.jar")
 ...
 
-3.4. force_kam_cmd_exec (int)
+3.4. force_cmd_exec (int)
 
    This parameter forces execution a kamailio comnmand with java native method KamExec_raw.
    Note: may cause a memory leaks if used from embedded languages.

+ 4 - 4
modules/app_java/doc/app_java_admin.xml

@@ -190,9 +190,9 @@ modparam("app_java", "java_options", "-Xdebug -verbose:gc,class,jni -Djava.compi
 			</example>
 		</section>
 
-		<!-- force_kam_cmd_exec -->
+		<!-- force_cmd_exec -->
 		<section>
-			<title><varname>force_kam_cmd_exec</varname> (int)</title>
+			<title><varname>force_cmd_exec</varname> (int)</title>
 			<para>
 				This parameter forces execution a &kamailiobinary; comnmand with java native method <quote>KamExec</quote>.
 				# Note: this is an untested yet feature, may cause (but may not) a memory leaks if used from embedded languages.
@@ -203,10 +203,10 @@ modparam("app_java", "java_options", "-Xdebug -verbose:gc,class,jni -Djava.compi
 				</emphasis>
 			</para>
 			<example>
-				<title>Set <varname>force_kam_cmd_exec</varname> parameter</title>
+				<title>Set <varname>force_cmd_exec</varname> parameter</title>
 				<programlisting format="linespecific">
 ...
-modparam("app_java", "force_kam_cmd_exec", 1)
+modparam("app_java", "force_cmd_exec", 1)
 ...
 </programlisting>
 			</example>

+ 5 - 5
modules/app_java/java_mod.c

@@ -54,7 +54,7 @@ static param_export_t params[] = {
     {"class_name",         STR_PARAM, &class_name },
     {"child_init_method",  STR_PARAM, &child_init_mname },
     {"java_options",	   STR_PARAM, &java_options_str },
-    {"force_kam_cmd_exec", INT_PARAM, &force_kam_cmd_exec },
+    {"force_cmd_exec", INT_PARAM, &force_cmd_exec },
     {0,0,0}
 };
 
@@ -101,15 +101,15 @@ static int mod_init(void)
     char **opts;
     int nOptions;
 
-    if (force_kam_cmd_exec < 0 || force_kam_cmd_exec > 1)
+    if (force_cmd_exec < 0 || force_cmd_exec > 1)
     {
-	LM_ERR("Parameter force_kam_cmd_exec should be either 0 or 1\n");
+	LM_ERR("Parameter force_cmd_exec should be either 0 or 1\n");
 	return -1;
     }
 
-    if (force_kam_cmd_exec)
+    if (force_cmd_exec)
     {
-	LM_NOTICE("app_java: Parameter force_kam_cmd_exec may cause a memory leaks if used from embedded languages\n");
+	LM_NOTICE("app_java: Parameter force_cmd_exec may cause a memory leaks if used from embedded languages\n");
     }
 
     options = (JavaVMOption *)pkg_malloc(sizeof(JavaVMOption));

+ 1 - 1
modules/app_java/java_mod.h

@@ -25,6 +25,6 @@
 #ifndef __JAVA_MOD_H__
 #define	__JAVA_MOD_H__
 
-int force_kam_cmd_exec;
+int force_cmd_exec;
 
 #endif

+ 1 - 1
modules/app_java/java_native_methods.c

@@ -374,7 +374,7 @@ int KamExec(JNIEnv *jenv, char *fname, int argc, char **argv)
     }
 
     /* check fixups */
-    if (force_kam_cmd_exec == 0 && fexport->fixup != NULL && fexport->free_fixup == NULL)
+    if (force_cmd_exec == 0 && fexport->fixup != NULL && fexport->free_fixup == NULL)
     {
         LM_ERR("app_java: KamExec(): function '%s' has fixup - cannot be used\n", fname);
 	return -1;

+ 13 - 0
modules/app_java/java_support.c

@@ -175,6 +175,19 @@ void handle_exception(void)
 
 }
 
+void ThrowNewException(JNIEnv *env, char *fmt, ...)
+{
+    va_list ap;
+    char buf[1024];
+
+    memset(buf, 0, sizeof(char));
+
+    va_start(ap, fmt);
+    vsnprintf(buf, 1024, fmt, ap);
+    va_end(ap);
+
+    (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/Exception"), buf);
+}
 
 void handle_VM_init_failure(int res)
 {

+ 1 - 0
modules/app_java/java_support.h

@@ -31,6 +31,7 @@
 #include <jni.h>
 
 void handle_exception(void);
+void ThrowNewException(JNIEnv *, char *, ...);
 void handle_VM_init_failure(int res);
 
 

+ 0 - 48
modules/app_java/utils.c

@@ -87,51 +87,3 @@ char **split(char *str, char *sep)
     return buf;
 }
 
-void ThrowNewException(JNIEnv *env, char *fmt, ...)
-{
-    va_list ap;
-    char buf[1024];
-
-    memset(buf, 0, sizeof(char));
-
-    va_start(ap, fmt);
-    vsnprintf(buf, 1024, fmt, ap);
-    va_end(ap);
-
-    (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/Exception"), buf);
-}
-
-
-struct sip_msg *get_struct_sip_msg(JNIEnv *jenv)
-{
-    jfieldID fid;
-    int msgptr;
-    jclass cls;
-
-    cls = (*jenv)->GetObjectClass(jenv, KamailioClassInstance);
-    fid = (*jenv)->GetFieldID(jenv, cls, "mop", "I");
-    if (!fid)
-    {
-        (*jenv)->ExceptionClear(jenv);
-        LM_ERR("Failed to find protected field org.siprouter.NativeMethods.mop\n");
-        return NULL;
-    }
-    (*jenv)->DeleteLocalRef(jenv, cls);
-
-    msgptr = (int)(*jenv)->GetIntField(jenv, KamailioClassInstance, fid);
-    if ((*jenv)->ExceptionCheck(jenv))
-    {
-        handle_exception();
-        return NULL;
-    }
-
-    if (msgptr == 0x0)
-    {
-        LM_ERR("app_java: KamExec(): Unable to execute. Internal Error: msgptr is NULL\n");
-        return NULL;
-    }
-
-    return FORCE_CAST_O2P(msgptr, struct sip_msg *);
-}
-
-

+ 0 - 5
modules/app_java/utils.h

@@ -29,11 +29,6 @@
 
 #include <jni.h>
 
-// cast object to pointer
-#define FORCE_CAST_O2P(var, type) *(type*)&var
-
 char **split(char *, char *);
-void ThrowNewException(JNIEnv *, char *, ...);
-struct sip_msg *get_struct_sip_msg(JNIEnv *);
 
 #endif