Browse code

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 authored on 18/03/2013 00:04:17
Showing 11 changed files
... ...
@@ -14,7 +14,7 @@ modparam("app_java", "java_options", "-Djava.compiler=NONE -Djava.class.path=<KA
14 14
 
15 15
 # This parameter forces execution a kamailio comnmand with java native method KamExec.
16 16
 # Note: this is an untested feature, may cause (but may not) a memory leaks if used from embedded languages.
17
-modparam("app_java", "force_kam_cmd_exec", 1);
17
+modparam("app_java", "force_cmd_exec", 1);
18 18
 
19 19
 
20 20
 
... ...
@@ -28,7 +28,7 @@ Konstantin Mosesov
28 28
               4.1. class_name (string)
29 29
               4.2. child_init_method (string)
30 30
               4.3. java_options (string)
31
-              4.4. force_kam_cmd_exec (int)
31
+              4.4. force_cmd_exec (int)
32 32
 
33 33
         5. Functions
34 34
 
... ...
@@ -57,7 +57,7 @@ Konstantin Mosesov
57 57
    1.4. Set java_options parameter (live configuration)
58 58
    1.5. Set java_options parameter (verbose configuration)
59 59
    1.6. Set java_options parameter (debug configuration)
60
-   1.7. Set force_kam_cmd_exec parameter
60
+   1.7. Set force_cmd_exec parameter
61 61
    1.8. Signature: "V"
62 62
    1.9. Signature: "Ljava/lang/String;I"
63 63
    1.10. Signature: "ZB"
... ...
@@ -91,7 +91,7 @@ Chapter 1. Admin Guide
91 91
         4.1. class_name (string)
92 92
         4.2. child_init_method (string)
93 93
         4.3. java_options (string)
94
-        4.4. force_kam_cmd_exec (int)
94
+        4.4. force_cmd_exec (int)
95 95
 
96 96
    5. Functions
97 97
 
... ...
@@ -166,7 +166,7 @@ Chapter 1. Admin Guide
166 166
    4.1. class_name (string)
167 167
    4.2. child_init_method (string)
168 168
    4.3. java_options (string)
169
-   4.4. force_kam_cmd_exec (int)
169
+   4.4. force_cmd_exec (int)
170 170
 
171 171
 4.1. class_name (string)
172 172
 
... ...
@@ -225,7 +225,7 @@ ler=NONE -Djava.class.path=/path/to/kamailio/modules:/opt/kamailio/java:/opt/kam
225 225
 ailio/java/kamailio.jar")
226 226
 ...
227 227
 
228
-4.4. force_kam_cmd_exec (int)
228
+4.4. force_cmd_exec (int)
229 229
 
230 230
    This parameter forces execution a kamailio comnmand with java native
231 231
    method “KamExec”. # Note: this is an untested yet feature, may cause
... ...
@@ -233,9 +233,9 @@ ailio/java/kamailio.jar")
233 233
 
234 234
    Default value is “0 (off)”.
235 235
 
236
-   Example 1.7. Set force_kam_cmd_exec parameter
236
+   Example 1.7. Set force_cmd_exec parameter
237 237
 ...
238
-modparam("app_java", "force_kam_cmd_exec", 1)
238
+modparam("app_java", "force_cmd_exec", 1)
239 239
 ...
240 240
 
241 241
 5. Functions
... ...
@@ -26,7 +26,7 @@ Konstantin Mosesov
26 26
 	      3.1. class_name (string)
27 27
               3.2. child_init_method (string)
28 28
 	      3.3. java_options (string)
29
-	      3.4. force_kam_cmd_exec (int)
29
+	      3.4. force_cmd_exec (int)
30 30
 
31 31
         4. Functions
32 32
 
... ...
@@ -141,7 +141,7 @@ Chapter 1. Admin Guide
141 141
         3.1. class_name (string)
142 142
         3.2. child_init_method (string)
143 143
         3.3. java_options (string)
144
-	3.4. force_kam_cmd_exec (int)
144
+	3.4. force_cmd_exec (int)
145 145
 
146 146
    4. Functions
147 147
 
... ...
@@ -206,7 +206,7 @@ Chapter 1. Admin Guide
206 206
    3.1. class_name (string)
207 207
    3.2. child_init_method (string)
208 208
    3.3. java_options (string)
209
-   3.4. force_kam_cmd_exec (int)
209
+   3.4. force_cmd_exec (int)
210 210
 
211 211
 3.1. class_name (string)
212 212
 
... ...
@@ -258,7 +258,7 @@ modparam("app_java", "java_options", "-verbose:gc,class,jni -Djava.compiler=NONE
258 258
 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")
259 259
 ...
260 260
 
261
-3.4. force_kam_cmd_exec (int)
261
+3.4. force_cmd_exec (int)
262 262
 
263 263
    This parameter forces execution a kamailio comnmand with java native method KamExec_raw.
264 264
    Note: may cause a memory leaks if used from embedded languages.
... ...
@@ -190,9 +190,9 @@ modparam("app_java", "java_options", "-Xdebug -verbose:gc,class,jni -Djava.compi
190 190
 			</example>
191 191
 		</section>
192 192
 
193
-		<!-- force_kam_cmd_exec -->
193
+		<!-- force_cmd_exec -->
194 194
 		<section>
195
-			<title><varname>force_kam_cmd_exec</varname> (int)</title>
195
+			<title><varname>force_cmd_exec</varname> (int)</title>
196 196
 			<para>
197 197
 				This parameter forces execution a &kamailiobinary; comnmand with java native method <quote>KamExec</quote>.
198 198
 				# 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
203 203
 				</emphasis>
204 204
 			</para>
205 205
 			<example>
206
-				<title>Set <varname>force_kam_cmd_exec</varname> parameter</title>
206
+				<title>Set <varname>force_cmd_exec</varname> parameter</title>
207 207
 				<programlisting format="linespecific">
208 208
 ...
209
-modparam("app_java", "force_kam_cmd_exec", 1)
209
+modparam("app_java", "force_cmd_exec", 1)
210 210
 ...
211 211
 </programlisting>
212 212
 			</example>
... ...
@@ -54,7 +54,7 @@ static param_export_t params[] = {
54 54
     {"class_name",         STR_PARAM, &class_name },
55 55
     {"child_init_method",  STR_PARAM, &child_init_mname },
56 56
     {"java_options",	   STR_PARAM, &java_options_str },
57
-    {"force_kam_cmd_exec", INT_PARAM, &force_kam_cmd_exec },
57
+    {"force_cmd_exec", INT_PARAM, &force_cmd_exec },
58 58
     {0,0,0}
59 59
 };
60 60
 
... ...
@@ -101,15 +101,15 @@ static int mod_init(void)
101 101
     char **opts;
102 102
     int nOptions;
103 103
 
104
-    if (force_kam_cmd_exec < 0 || force_kam_cmd_exec > 1)
104
+    if (force_cmd_exec < 0 || force_cmd_exec > 1)
105 105
     {
106
-	LM_ERR("Parameter force_kam_cmd_exec should be either 0 or 1\n");
106
+	LM_ERR("Parameter force_cmd_exec should be either 0 or 1\n");
107 107
 	return -1;
108 108
     }
109 109
 
110
-    if (force_kam_cmd_exec)
110
+    if (force_cmd_exec)
111 111
     {
112
-	LM_NOTICE("app_java: Parameter force_kam_cmd_exec may cause a memory leaks if used from embedded languages\n");
112
+	LM_NOTICE("app_java: Parameter force_cmd_exec may cause a memory leaks if used from embedded languages\n");
113 113
     }
114 114
 
115 115
     options = (JavaVMOption *)pkg_malloc(sizeof(JavaVMOption));
... ...
@@ -25,6 +25,6 @@
25 25
 #ifndef __JAVA_MOD_H__
26 26
 #define	__JAVA_MOD_H__
27 27
 
28
-int force_kam_cmd_exec;
28
+int force_cmd_exec;
29 29
 
30 30
 #endif
... ...
@@ -374,7 +374,7 @@ int KamExec(JNIEnv *jenv, char *fname, int argc, char **argv)
374 374
     }
375 375
 
376 376
     /* check fixups */
377
-    if (force_kam_cmd_exec == 0 && fexport->fixup != NULL && fexport->free_fixup == NULL)
377
+    if (force_cmd_exec == 0 && fexport->fixup != NULL && fexport->free_fixup == NULL)
378 378
     {
379 379
         LM_ERR("app_java: KamExec(): function '%s' has fixup - cannot be used\n", fname);
380 380
 	return -1;
... ...
@@ -175,6 +175,19 @@ void handle_exception(void)
175 175
 
176 176
 }
177 177
 
178
+void ThrowNewException(JNIEnv *env, char *fmt, ...)
179
+{
180
+    va_list ap;
181
+    char buf[1024];
182
+
183
+    memset(buf, 0, sizeof(char));
184
+
185
+    va_start(ap, fmt);
186
+    vsnprintf(buf, 1024, fmt, ap);
187
+    va_end(ap);
188
+
189
+    (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/Exception"), buf);
190
+}
178 191
 
179 192
 void handle_VM_init_failure(int res)
180 193
 {
... ...
@@ -31,6 +31,7 @@
31 31
 #include <jni.h>
32 32
 
33 33
 void handle_exception(void);
34
+void ThrowNewException(JNIEnv *, char *, ...);
34 35
 void handle_VM_init_failure(int res);
35 36
 
36 37
 
... ...
@@ -87,51 +87,3 @@ char **split(char *str, char *sep)
87 87
     return buf;
88 88
 }
89 89
 
90
-void ThrowNewException(JNIEnv *env, char *fmt, ...)
91
-{
92
-    va_list ap;
93
-    char buf[1024];
94
-
95
-    memset(buf, 0, sizeof(char));
96
-
97
-    va_start(ap, fmt);
98
-    vsnprintf(buf, 1024, fmt, ap);
99
-    va_end(ap);
100
-
101
-    (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/Exception"), buf);
102
-}
103
-
104
-
105
-struct sip_msg *get_struct_sip_msg(JNIEnv *jenv)
106
-{
107
-    jfieldID fid;
108
-    int msgptr;
109
-    jclass cls;
110
-
111
-    cls = (*jenv)->GetObjectClass(jenv, KamailioClassInstance);
112
-    fid = (*jenv)->GetFieldID(jenv, cls, "mop", "I");
113
-    if (!fid)
114
-    {
115
-        (*jenv)->ExceptionClear(jenv);
116
-        LM_ERR("Failed to find protected field org.siprouter.NativeMethods.mop\n");
117
-        return NULL;
118
-    }
119
-    (*jenv)->DeleteLocalRef(jenv, cls);
120
-
121
-    msgptr = (int)(*jenv)->GetIntField(jenv, KamailioClassInstance, fid);
122
-    if ((*jenv)->ExceptionCheck(jenv))
123
-    {
124
-        handle_exception();
125
-        return NULL;
126
-    }
127
-
128
-    if (msgptr == 0x0)
129
-    {
130
-        LM_ERR("app_java: KamExec(): Unable to execute. Internal Error: msgptr is NULL\n");
131
-        return NULL;
132
-    }
133
-
134
-    return FORCE_CAST_O2P(msgptr, struct sip_msg *);
135
-}
136
-
137
-
... ...
@@ -29,11 +29,6 @@
29 29
 
30 30
 #include <jni.h>
31 31
 
32
-// cast object to pointer
33
-#define FORCE_CAST_O2P(var, type) *(type*)&var
34
-
35 32
 char **split(char *, char *);
36
-void ThrowNewException(JNIEnv *, char *, ...);
37
-struct sip_msg *get_struct_sip_msg(JNIEnv *);
38 33
 
39 34
 #endif