Browse code

modules/app_java: README to README-draft, added actual README

Konstantin Mosesov authored on 17/03/2013 23:45:49
Showing 2 changed files
... ...
@@ -6,8 +6,6 @@ Edited by
6 6
 
7 7
 Konstantin Mosesov
8 8
 
9
-   <konstantinm@voipgroup.org.ua>
10
-
11 9
    Copyright © 2013 Konstantin Mosesov
12 10
      __________________________________________________________________
13 11
 
... ...
@@ -21,95 +19,35 @@ Konstantin Mosesov
21 19
               2.1. Kamailio Modules
22 20
               2.2. External Libraries or Applications
23 21
 
24
-        3. Parameters
25
-
26
-	      3.1. class_name (string)
27
-              3.2. child_init_method (string)
28
-	      3.3. java_options (string)
29
-	      3.4. force_kam_cmd_exec (int)
30
-
31
-        4. Functions
32
-
33
-	      4.0. Common requirements.
34
-              4.1. java_method_exec(method, method_signature, [param1[, param2]])
35
-	      4.2. java_s_method_exec(method, method_signature, [param1[, param2]])
36
-	      4.3. java_staticmethod_exec(method, method_signature, [param1[, param2]])
37
-	      4.4. java_s_staticmethod_exec(method, method_signature, [param1[, param2]])
38
-
39
-	5. Java module API
40
-
41
-	      5.0. Minimal program skeleton and structure of package org.siprouter
42
-		   5.0.1.  Minimal program skeleton
43
-		   5.0.2.  Structure of package org.siprouter
44
-	      5.1. abstract class NativeMethods
45
-	           5.1.1.  General logging
46
-			   5.1.1.0.   Logging levels and facilities
47
-			   5.1.1.1.   native void LM_GEN1(int logLevel, String s);
48
-			   5.1.1.2.   native void LM_GEN2(int logFacility, int logLevel, String s);
49
-			   5.1.1.3.   native void LM_ALERT(String s);
50
-			   5.1.1.4.   native void LM_CRIT(String s);
51
-			   5.1.1.5.   native void LM_WARN(String s);
52
-			   5.1.1.6.   native void LM_NOTICE(String s);
53
-			   5.1.1.7.   native void LM_ERR(String s);
54
-			   5.1.1.8.   native void LM_INFO(String s);
55
-			   5.1.1.9.   native void LM_DBG(String s);
56
-		   5.1.2.  Execution of kamailio commands
57
-			   5.1.2.1.   static native int KamExec(String fname, String... params);
58
-    			   5.1.2.2.   static native int SetURI(String ruri);
59
-    			   5.1.2.3.   static native int RewriteURI(String ruri);
60
-
61
-	      5.2. class IPPair.
62
-		   5.2.1.   final String ip;
63
-		   5.2.2.   final int port;
64
-	      5.3. abstract class SipMsg
65
-		   5.3.0.   Internal structure understanding.
66
-		   5.3.1.   int id;
67
-		   5.3.2.   int pid;
68
-		   5.3.3.   String eoh;
69
-		   5.3.4.   String unparsed;
70
-		   5.3.5.   String buf;
71
-		   5.3.6.   int len;
72
-		   5.3.7.   String new_uri;
73
-		   5.3.8.   String dst_uri;
74
-		   5.3.9.   int parsed_uri_ok;
75
-		   5.3.10.  int parsed_orig_ruri_ok;
76
-		   5.3.11.  String add_to_branch_s;
77
-		   5.3.12.  int add_to_branch_len;
78
-		   5.3.13.  int hash_index;
79
-		   5.3.14.  int msg_flags;
80
-		   5.3.15.  static native SipMsg ParseSipMsg();
81
-		   5.3.16.  static native String getMsgType();
82
-		   5.3.17.  static native String getRURI();
83
-		   5.3.18.  static native IPPair getSrcAddress();
84
-		   5.3.19.  static native IPPair getDstAddress();
85
-		   5.3.20.  static native String getBuffer();
86
-	      5.4. interface NativeInterface
87
-		   5.4.1.   abstract class Ranks
88
-			    5.4.1.1.  static final int PROC_MAIN
89
-			    5.4.1.2.  static final int PROC_TIMER
90
-			    5.4.1.3.  static final int PROC_RPC
91
-			    5.4.1.4.  static final int PROC_FIFO
92
-			    5.4.1.5.  static final int PROC_TCP_MAIN
93
-			    5.4.1.6.  static final int PROC_UNIXSOCK
94
-			    5.4.1.7.  static final int PROC_ATTENDANT
95
-			    5.4.1.8.  static final int PROC_INIT
96
-			    5.4.1.9.  static final int PROC_NOCHLDINIT
97
-			    5.4.1.10. static final int PROC_SIPINIT
98
-			    5.4.1.11. static final int PROC_SIPRPC
99
-			    5.4.1.12. static final int PROC_MIN
100
-		   5.4.2.   abstract class LogParams
101
-			    5.4.2.0.  Loggigng params
102
-			    5.4.2.1.  static final int L_ALERT
103
-			    5.4.2.2.  static final int L_BUG
104
-			    5.4.2.3.  static final int L_CRIT2
105
-			    5.4.2.4.  static final int L_CRIT
106
-			    5.4.2.5.  static final int L_ERR
107
-			    5.4.2.6.  static final int L_WARN
108
-			    5.4.2.7.  static final int L_NOTICE
109
-			    5.4.2.8.  static final int L_INFO
110
-			    5.4.2.9.  static final int L_DBG
111
-			    5.4.2.10. static final int DEFAULT_FACILITY
112
-	      5.5. Examples of usage Java API
22
+        3. Java runtime
23
+
24
+              3.1.
25
+
26
+        4. Parameters
27
+
28
+              4.1. class_name (string)
29
+              4.2. child_init_method (string)
30
+              4.3. java_options (string)
31
+              4.4. force_kam_cmd_exec (int)
32
+
33
+        5. Functions
34
+
35
+              5.1. Common requirements
36
+              5.2. java_method_exec(method, method_signature, [param1[,
37
+                      param2[, ...]]])
38
+
39
+              5.3. java_staticmethod_exec(method, method_signature,
40
+                      [param1[, param2[, ...]]])
41
+
42
+              5.4. java_s_method_exec(method, method_signature, [param1[,
43
+                      param2[, ...]]])
44
+
45
+              5.5. java_s_staticmethod_exec(method, method_signature,
46
+                      [param1[, param2[, ...]]])
47
+
48
+        6. Java Module API
49
+
50
+              6.1. Minimal program skeleton
113 51
 
114 52
    List of Examples
115 53
 
... ...
@@ -119,12 +57,20 @@ Konstantin Mosesov
119 57
    1.4. Set java_options parameter (live configuration)
120 58
    1.5. Set java_options parameter (verbose configuration)
121 59
    1.6. Set java_options parameter (debug configuration)
122
-
123
-   2.0. Example of usage signatures.
124
-   2.1. Example of usage java_method_exec()
125
-   2.2. Example of usage java_s_method_exec()
126
-   2.3. Example of usage java_staticmethod_exec()
127
-   3.4. Example of usage java_s_staticmethod_exec()
60
+   1.7. Set force_kam_cmd_exec parameter
61
+   1.8. Signature: "V"
62
+   1.9. Signature: "Ljava/lang/String;I"
63
+   1.10. Signature: "ZB"
64
+   1.11. Signature: "V"
65
+   1.12. Signature: "Ljava/lang/String;I"
66
+   1.13. Signature: "ZB"
67
+   1.14. Signature: "V"
68
+   1.15. Signature: "Ljava/lang/String;I"
69
+   1.16. Signature: "ZB"
70
+   1.17. Signature: "V"
71
+   1.18. Signature: "Ljava/lang/String;I"
72
+   1.19. Signature: "ZB"
73
+   1.20. Minimal program skeleton
128 74
 
129 75
 Chapter 1. Admin Guide
130 76
 
... ...
@@ -136,31 +82,46 @@ Chapter 1. Admin Guide
136 82
         2.1. Kamailio Modules
137 83
         2.2. External Libraries or Applications
138 84
 
139
-   3. Parameters
85
+   3. Java runtime
86
+
87
+        3.1.
88
+
89
+   4. Parameters
140 90
 
141
-        3.1. class_name (string)
142
-        3.2. child_init_method (string)
143
-        3.3. java_options (string)
144
-	3.4. force_kam_cmd_exec (int)
91
+        4.1. class_name (string)
92
+        4.2. child_init_method (string)
93
+        4.3. java_options (string)
94
+        4.4. force_kam_cmd_exec (int)
145 95
 
146
-   4. Functions
96
+   5. Functions
147 97
 
148
-	4.0. Common requirements.
149
-        4.1. java_method_exec(method, method_signature, [param1[, param2]])         - class method
150
-        4.2. java_s_method_exec(method, method_signature, [param1[, param2]])       - class synchronized method
151
-        4.3. java_staticmethod_exec(method, method_signature, [param1[, param2]])   - static method
152
-        4.4. java_s_staticmethod_exec(method, method_signature, [param1[, param2]]) - static synchronized method
98
+        5.1. Common requirements
99
+        5.2. java_method_exec(method, method_signature, [param1[, param2[,
100
+                ...]]])
101
+
102
+        5.3. java_staticmethod_exec(method, method_signature, [param1[,
103
+                param2[, ...]]])
104
+
105
+        5.4. java_s_method_exec(method, method_signature, [param1[,
106
+                param2[, ...]]])
107
+
108
+        5.5. java_s_staticmethod_exec(method, method_signature, [param1[,
109
+                param2[, ...]]])
110
+
111
+   6. Java Module API
112
+
113
+        6.1. Minimal program skeleton
153 114
 
154 115
 1. Overview
155 116
 
156
-   This module allows executing Java compiled classes from config file, exporting
157
-   functions to access the SIP message from Java using Java Native Interface (JNI).
117
+   This module allows executing Java compiled classes from config file,
118
+   exporting functions to access the SIP message from Java using Java
119
+   Native Interface (JNI).
158 120
 
159 121
 2. Dependencies
160 122
 
161 123
    2.1. Kamailio Modules
162 124
    2.2. External Libraries or Applications
163
-   2.3. Java runtime
164 125
 
165 126
 2.1. Kamailio Modules
166 127
 
... ...
@@ -169,49 +130,48 @@ Chapter 1. Admin Guide
169 130
 
170 131
 2.2. External Libraries or Applications
171 132
 
172
-   Legend:
173
-      * - Runtime library, required to launch
174
-      R - Required
175
-      O - Optional
176
-      D - Development (for building-rebuilding java)
177
-      P - Dependance of package
178
-
179
-   The following libraries or applications must be installed before
180
-   running Kamailio with this module loaded:
181
-     [*]    java-common            - Base of all Java packages
182
-     [*]    default-jre            - Standard Java or Java compatible Runtime
183
-     [*]    gcj-jre                - Java runtime environment using GIJ/classpath
184
-     [*]    libgcj12 (>=12)        - Java runtime library for use with gcj
185
-     [DR]   ant                    - Java based build tool like make
186
-     [DO]   ant-contrib            - collection of tasks, types and other tools for Apache Ant
187
-     [DPO]  ant-gcj                - Java based build tool like make (GCJ)
188
-     [DPO]  ant-optional           - Java based build tool like make - optional libraries
189
-     [DPO]  ant-optional-gcj       - Java based build tool like make - optional libraries (GCJ)
190
-     [DR]   default-jdk            - Standard Java or Java compatible Development Kit
191
-     [DR]   gcj-jdk                - gcj and classpath development tools for Java(TM)
192
-     [DR]   libgcj13-dev (>=12)    - Java development headers for use with gcj
193
-     [DO]   jdk                    - JDK Development Kit (either oracle jdk or openjdk)
194
-
195
-   The following libraries or applications must be compiled before
196
-   running Kamailio with this module loaded:
197
-     [*]   <class_name>.class
198
-     [*]   kamailio.jar
199
-
200
-2.3. Java runtime
133
+   The following packages are runtime libraries, required to launch
134
+     * java-common Base of all Java packages.
135
+     * default-jre Standard Java or Java compatible Runtime.
136
+     * gcj-jre Java runtime environment using GIJ/classpath.
137
+     * libgcj12 (>=12) Java runtime library for use with gcj.
138
+
139
+   The following packages are optional, required for development
140
+     * ant Java based build tool like make.
141
+     * ant-contrib Collection of tasks, types and other tools for Apache
142
+       Ant.
143
+     * ant-gcj Java based build tool like make (GCJ).
144
+     * default-jdk Standard Java or Java compatible Development Kit
145
+     * gcj-jdk gcj and classpath development tools for Java(TM)
146
+     * libgcj13-dev (>=12) Java development headers for use with gcj
147
+     * jdk JDK Development Kit (either oracle jdk or openjdk)
148
+
149
+   The following libraries or applications must be compiled before running
150
+   Kamailio with this module loaded:
151
+
152
+   The following packages are runtime libraries, required to launch
153
+     * <class_name>.class
154
+     * kamailio.jar
155
+
156
+3. Java runtime
157
+
158
+   3.1.
159
+
160
+3.1.
201 161
 
202 162
    Java runtime library (JRE or JDK) is required to use this module.
203 163
 
204
-3. Parameters
164
+4. Parameters
205 165
 
206
-   3.1. class_name (string)
207
-   3.2. child_init_method (string)
208
-   3.3. java_options (string)
209
-   3.4. force_kam_cmd_exec (int)
166
+   4.1. class_name (string)
167
+   4.2. child_init_method (string)
168
+   4.3. java_options (string)
169
+   4.4. force_kam_cmd_exec (int)
210 170
 
211
-3.1. class_name (string)
171
+4.1. class_name (string)
212 172
 
213
-   The class name should have the same compiled file name.
214
-   If the value is "Kamailio", then the compiled file should be named as "Kamailio.class".
173
+   The class name should have the same compiled file name. If the value is
174
+   "Kamailio", then the compiled file should be named as "Kamailio.class".
215 175
 
216 176
    Default value is “Kamailio”.
217 177
 
... ...
@@ -220,7 +180,7 @@ Chapter 1. Admin Guide
220 180
 modparam("app_java", "class_name", "Kamailio")
221 181
 ...
222 182
 
223
-3.2. child_init_method (string)
183
+4.2. child_init_method (string)
224 184
 
225 185
    TBD.
226 186
 
... ...
@@ -231,10 +191,9 @@ modparam("app_java", "class_name", "Kamailio")
231 191
 modparam("app_java", "child_init_method", "my_mod_init")
232 192
 ...
233 193
 
234
-3.3. java_options (string)
194
+4.3. java_options (string)
235 195
 
236
-   Java options for Java Virtual Machine.
237
-   For more info see: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/java.html
196
+   Java options for Java Virtual Machine. For more info read java docs
238 197
 
239 198
    Default value is “-Djava.compiler=NONE”.
240 199
 
... ...
@@ -245,593 +204,370 @@ modparam("app_java", "java_options", "-Djava.compiler=NONE")
245 204
 
246 205
    Example 1.4. Set java_options parameter (live configuration)
247 206
 ...
248
-modparam("app_java", "java_options", "-Djava.compiler=NONE -Djava.class.path=/path/to/kamailio/modules:/path/to/<class_name>_file_directory:/path/to/kamailio.jar")
207
+# Assumes "application java folder" is located at /opt/kamailio/java
208
+modparam("app_java", "java_options", "-Djava.compiler=NONE -Djava.class.path=/pa
209
+th/to/kamailio/modules:/opt/kamailio/java:/opt/kamailio/java/kamailio.jar")
249 210
 ...
250 211
 
251 212
    Example 1.5. Set java_options parameter (verbose configuration)
252 213
 ...
253
-modparam("app_java", "java_options", "-verbose:gc,class,jni -Djava.compiler=NONE -Djava.class.path=/path/to/kamailio/modules:/path/to/class_name_file_directory:/path/to/kamailio.jar")
214
+# Assumes "application java folder" is located at /opt/kamailio/java
215
+modparam("app_java", "java_options", "-verbose:gc,class,jni -Djava.compiler=NONE
216
+ -Djava.class.path=/path/to/kamailio/modules:/opt/kamailio/java:/opt/kamailio/ja
217
+va/kamailio.jar")
254 218
 ...
255 219
 
256 220
    Example 1.6. Set java_options parameter (debug configuration)
257 221
 ...
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")
222
+# Assumes "application java folder" is located at /opt/kamailio/java
223
+modparam("app_java", "java_options", "-Xdebug -verbose:gc,class,jni -Djava.compi
224
+ler=NONE -Djava.class.path=/path/to/kamailio/modules:/opt/kamailio/java:/opt/kam
225
+ailio/java/kamailio.jar")
259 226
 ...
260 227
 
261
-3.4. force_kam_cmd_exec (int)
262
-
263
-   This parameter forces execution a kamailio comnmand with java native method KamExec_raw.
264
-   Note: may cause a memory leaks if used from embedded languages.
265
-
266
-   Default value is 0 (off).
267
-
268
-4. Functions
269
-
270
-   4.0. Common requirements.
271
-   4.1. java_method_exec(method, method_signature, [param1[, param2]])
272
-   4.2. java_s_method_exec(method, method_signature, [param1[, param2]])
273
-   4.3. java_staticmethod_exec(method, method_signature, [param1[, param2]])
274
-   4.4. java_s_staticmethod_exec(method, method_signature, [param1[, param2]])
275
-
276
-4.0. Common requirements.
277
-
278
-   Each function has a required parameter “method_signature”.
279
-   For more info see: http://www.rgagnon.com/javadetails/java-0286.html
280
-   There are two parts to the signature. The first part is enclosed within the parentheses and represents the method's arguments. 
281
-   The second portion follows the closing parenthesis and represents the return type. The mapping between the Java type and C type is
282
-	Type     Chararacter 
283
-	boolean      Z 
284
-	byte         B 
285
-	char         C 
286
-	double       D 
287
-	float        F 
288
-	int          I 
289
-	long         J 
290
-	object       L 
291
-	short        S 
292
-	void         V 
293
-	array        [ 
294
-   Note that to specify an object, the "L" is followed by the object's class name and ends with a semi-colon, ';' .
295
-
296
-   app_java supports the following signatures
297
-      primitives: Z,B,C,D,F,I,J,L,S,V
298
-      objects: 
299
-		Ljava/lang/Boolean;
300
-		Ljava/lang/Byte;
301
-		Ljava/lang/Character;
302
-		Ljava/lang/Double;
303
-		Ljava/lang/Float;
304
-		Ljava/lang/Integer;
305
-		Ljava/lang/Long;
306
-		Ljava/lang/Short;
307
-		Ljava/lang/String;
308
-      NULL parameter: V
309
-
310
-   Each parameter passed to function will be cast according to given signature.
311
-
312
-   Example 2.0. Example of usage signatures.
313
-        0. Equivalent of java prototype:  public int ExampleMethod();
314
-...
315
-java_method_exec("ExampleMethod", "V");
316
-...
228
+4.4. force_kam_cmd_exec (int)
317 229
 
318
-        1. Equivalent of java prototype:  public int ExampleMethod(String param1, int param2);
319
-...
320
-java_method_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world", "5");
321
-...
322
-           In the above scenario parameter 2 ("5") will be cast to integer representation.
230
+   This parameter forces execution a kamailio comnmand with java native
231
+   method “KamExec”. # Note: this is an untested yet feature, may cause
232
+   (but may not) a memory leaks if used from embedded languages.
323 233
 
324
-        2. Equivalent of java prototype:  public int ExampleMethod(boolean param1, byte param2);
234
+   Default value is “0 (off)”.
235
+
236
+   Example 1.7. Set force_kam_cmd_exec parameter
325 237
 ...
326
-java_method_exec("ExampleMethod", "ZB", "true", "0x05");
238
+modparam("app_java", "force_kam_cmd_exec", 1)
327 239
 ...
328
-           In the above scenario parameter 1 ("true") will be cast to boolean representation.
329
-
330
-   Parameters are optional, ommitting a parameter meant the passed value is NULL.
331
-   Parameters count should be exactly the same as signature count.
332
-   Note, you shall use a correct signature, e.g. the following examples of combinations are invalid:
333
-        *) java_method_exec("ExampleMethod", "ZI", "False");
334
-        *) java_method_exec("ExampleMethod", "VI", "", "5");
335
-        *) java_method_exec("ExampleMethod", "LI", "something", "5");
336 240
 
337
-
338
-4.1.  java_method_exec(method, method_signature, [param1[, param2]])
339
-
340
-   Executes a java method “method”. Parameter “method_signature” is required (see 4.0).
341
-
342
-   Example 2.1. java_method_exec usage
343
-...
344
-# Equivalent of java prototype:  public int ExampleMethod();
241
+5. Functions
242
+
243
+   5.1. Common requirements
244
+   5.2. java_method_exec(method, method_signature, [param1[, param2[,
245
+          ...]]])
246
+
247
+   5.3. java_staticmethod_exec(method, method_signature, [param1[,
248
+          param2[, ...]]])
249
+
250
+   5.4. java_s_method_exec(method, method_signature, [param1[, param2[,
251
+          ...]]])
252
+
253
+   5.5. java_s_staticmethod_exec(method, method_signature, [param1[,
254
+          param2[, ...]]])
255
+
256
+5.1.  Common requirements
257
+
258
+   Each function has a required parameter “method_signature”. For more
259
+   info see Determine the signature of a method. Signature represents the
260
+   variable type. The mapping between the Java type and C type is
261
+                Type     Chararacter
262
+                boolean      Z
263
+                byte         B
264
+                char         C
265
+                double       D
266
+                float        F
267
+                int          I
268
+                long         J
269
+                object       L
270
+                short        S
271
+                void         V
272
+                Note that to specify an object, the "L" is followed by the objec
273
+t's class name and ends with a semi-colon, ';' .
274
+
275
+   app_java supports the following signatures:
276
+                Primitives: Z,B,C,D,F,I,J,L,S,V
277
+                Objects:
278
+                        Ljava/lang/Boolean;
279
+                        Ljava/lang/Byte;
280
+                        Ljava/lang/Character;
281
+                        Ljava/lang/Double;
282
+                        Ljava/lang/Float;
283
+                        Ljava/lang/Integer;
284
+                        Ljava/lang/Long;
285
+                        Ljava/lang/Short;
286
+                        Ljava/lang/String;
287
+                        NULL parameter: V
288
+
289
+        Each parameter passed to function will be cast according to given signat
290
+ure.
291
+
292
+        Parameters are optional, ommitting a parameter meant the passed value is
293
+ NULL.
294
+        Parameters count should be exactly the same as signature count.
295
+        Note 1: Arrays representation (symbol '[') is not supported yet.
296
+        Note 2: You shall use a correct signature, e.g. the following examples o
297
+f combinations are invalid:
298
+        java_method_exec("ExampleMethod", "ZI", "False");
299
+        java_method_exec("ExampleMethod", "LI", "something", "5");
300
+
301
+5.2. java_method_exec(method, method_signature, [param1[, param2[, ...]]])
302
+
303
+   Executes a java class method method. Parameter method_signature is
304
+   required.
305
+     * Example 1.8. Signature: "V"
306
+       Kamailio prototype
307
+java_method_exec("ExampleMethod", "V");
308
+       Java prototype
309
+public int ExampleMethod();
310
+       Example of usage:
311
+# Kamailio
345 312
 java_method_exec("ExampleMethod", "V");
346 313
 
347
-# Equivalent of java prototype:  public int ExampleMethod(String SipMessageBuffer, int SipMessageLenght);
314
+# Java
315
+public int ExampleMethod()
316
+{
317
+                ... do something;
318
+                return 1;
319
+}
320
+     * Example 1.9. Signature: "Ljava/lang/String;I"
321
+       Kamailio prototype
322
+java_method_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world", "5");
323
+       Java prototype
324
+public int ExampleMethod(String param1, int param2);
325
+       In the above scenario parameter 2 ("5") will be cast to integer
326
+       representation.
327
+       Example of usage:
328
+# Kamailio
348 329
 java_method_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");
349
-...
350
-
351
-
352
-4.2.  java_s_method_exec(method, method_signature, [param1[, param2]])
353
-
354
-   Executes a java synchronized method “method”. Parameter “method_signature” is required (see 4.0).
355
-   See a more info about to synchronization: http://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
356
-
357
-   Example 2.2. java_s_method_exec usage
358
-...
359
-# Equivalent of java prototype:  public synchronized int ExampleMethod();
360
-java_s_method_exec("ExampleMethod", "V");
361
-
362
-# Equivalent of java prototype:  public synchronized int ExampleMethod(String SipMessageBuffer, int SipMessageLenght);
363
-java_s_method_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");
364
-...
365 330
 
331
+# Java
332
+public int ExampleMethod(String SipMessageBuffer, int SipMessageLenght)
333
+{
334
+                ... do something with buffer;
335
+                return 1;
336
+}
337
+     * Example 1.10. Signature: "ZB"
338
+       Kamailio prototype
339
+java_method_exec("ExampleMethod", "ZB", "true", "0x05");
340
+       Java prototype
341
+public int ExampleMethod(boolean param1, byte param2);
342
+       In the above scenario parameter 1 ("true") will be cast to boolean
343
+       representation.
344
+       Example of usage:
345
+# Kamailio
346
+java_method_exec("ExampleMethod", "ZB", "true", "0x05");
366 347
 
367
-4.3.  java_staticmethod_exec(method, method_signature, [param1[, param2]])
348
+# Java
349
+public int ExampleMethod(boolean flagSet, byte bFlag);
350
+{
351
+                if (flagSet)
352
+                {
353
+                        ... do something with flags;
354
+                }
355
+                return 1;
356
+}
368 357
 
369
-   Executes a java static method “method”. Parameter “method_signature” is required (see 4.0).
358
+5.3. java_staticmethod_exec(method, method_signature, [param1[, param2[,
359
+...]]])
370 360
 
371
-   Example 2.3. java_staticmethod_exec usage
372
-...
373
-# Equivalent of java prototype:  public static int ExampleMethod();
361
+   Executes a java static method method. Parameter method_signature is
362
+   required.
363
+     * Example 1.11. Signature: "V"
364
+       Kamailio prototype
365
+java_staticmethod_exec("ExampleMethod", "V");
366
+       Java prototype
367
+public static int ExampleMethod();
368
+       Example of usage:
369
+# Kamailio
374 370
 java_staticmethod_exec("ExampleMethod", "V");
375 371
 
376
-# Equivalent of java prototype:  public static int ExampleMethod(String SipMessageBuffer, int SipMessageLenght);
372
+# Java
373
+public static int ExampleMethod()
374
+{
375
+                ... do something;
376
+                return 1;
377
+}
378
+     * Example 1.12. Signature: "Ljava/lang/String;I"
379
+       Kamailio prototype
380
+java_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world", "5
381
+");
382
+       Java prototype
383
+public static int ExampleMethod(String param1, int param2);
384
+       In the above scenario parameter 2 ("5") will be cast to integer
385
+       representation.
386
+       Example of usage:
387
+# Kamailio
377 388
 java_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");
378
-...
379
-
380
-
381
-4.4.  java_s_staticmethod_exec(method, method_signature, [param1[, param2]])
382
-
383
-   Executes a java synchronized static method “method”. Parameter “method_signature” is required (see 4.0).
384
-   See a more info about to synchronization: http://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
385
-
386
-   Example 2.4. java_s_staticmethod_exec usage
387
-...
388
-# Equivalent of java prototype:  public static synchronized int ExampleMethod();
389
-java_s_staticmethod_exec("ExampleMethod", "V");
390
-
391
-# Equivalent of java prototype:  public static synchronized int ExampleMethod(String SipMessageBuffer, int SipMessageLenght);
392
-java_s_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");
393
-...
394
-
395
-
396
-5. Java module API
397
-
398
-
399
-5.0. Minimal program skeleton and structure of package org.siprouter
400
-
401
-   5.0.1.  Minimal program skeleton
402
-
403
-...
404
-import org.siprouter.*;
405
-import org.siprouter.NativeInterface.*;
406 389
 
407
-public class Kamailio extends NativeMethods
390
+# Java
391
+public static int ExampleMethod(String SipMessageBuffer, int SipMessageLenght)
408 392
 {
409
-	/* Here you should specify a full path to app_java.so */
410
-        static
411
-        {
412
-            System.load("/opt/kamailio/lib/kamailio/modules/app_java.so");
413
-        }
414
-
415
-        /* Constructor. Do not remove !!! */
416
-        public Kamailio()
417
-        {
418
-        }
419
-
420
-	/*
421
-	    This method should be executed for each children process, immediately after forking.
422
-	    Required. Do not remove !!!
423
-	*/
424
-        public int child_init(int rank)
425
-        {
426
-	    return 1;
427
-	}
393
+                ... do something with buffer;
394
+                return 1;
395
+}
396
+     * Example 1.13. Signature: "ZB"
397
+       Kamailio prototype
398
+java_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");
399
+       Java prototype
400
+public static int ExampleMethod(boolean param1, byte param2);
401
+       In the above scenario parameter 1 ("true") will be cast to boolean
402
+       representation.
403
+       Example of usage:
404
+# Kamailio
405
+java_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");
406
+
407
+# Java
408
+public static int ExampleMethod(boolean flagSet, byte bFlag);
409
+{
410
+                if (flagSet)
411
+                {
412
+                        ... do something with flags;
413
+                }
414
+                return 1;
428 415
 }
429
-...
430
-
431
-   5.0.2.  Structure of package org.siprouter
432
-
433
-            org.siprouter ---*---*--*-------> class NativeMethods
434
-                             |   |  +--> class IPPair
435
-                             |   +--> class SipMsg
436
-                             +--> interface NativeInterface
437
-                                        |
438
-                                        +--> class Ranks
439
-                                        +--> class LogParams
440
-
441
-
442
-5.1. abstract class NativeMethods
443
-
444
-   5.1.1.   General logging
445
-
446
-	5.1.1.0.   Log levels and facilities
447
-
448
-		   Log levels:
449
-			L_ALERT		= -5
450
-			L_BUG		= -4
451
-			L_CRIT2		= -3
452
-			L_CRIT		= -2
453
-			L_ERR		= -1
454
-			L_WARN		= 0
455
-			L_NOTICE	= 1
456
-			L_INFO		= 2
457
-			L_DBG		= 3
458
-
459
-		   Log facilities (see man syslog(3)):
460
-			DEFAULT_FACILITY	= 0  (LOG_KERN (Linux))
461
-
462
-		   1. Example of usage log levels and facilities:
463
-		     LM_GEN1(LogParams.L_BUG, "Hello World!\n");
464
-		     produces (example of output):
465
-		      0(3003) BUG: app_java [java_native_methods.c:255]: Hello World!
466
-
467
-		   2. Example of usage log levels and facilities:
468
-		     LM_GEN2(LogParams.DEFAULT_FACILITY, LogParams.L_WARN, "Hello World!\n");
469
-		     produces (example of output):
470
-		      2(3147) WARNING: app_java [java_native_methods.c:279]: Hello World!
471
-
472
-
473
-	5.1.1.1.   native void LM_GEN1(int logLevel, String s);
474
-	5.1.1.2.   native void LM_GEN2(int logFacility, int logLevel, String s);
475
-	5.1.1.3.   native void LM_ALERT(String s);
476
-        5.1.1.4.   native void LM_CRIT(String s);
477
-        5.1.1.5.   native void LM_WARN(String s);
478
-        5.1.1.6.   native void LM_NOTICE(String s);
479
-        5.1.1.7.   native void LM_ERR(String s);
480
-        5.1.1.8.   native void LM_INFO(String s);
481
-        5.1.1.9.   native void LM_DBG(String s);
482
-
483
-   5.1.2.   Execution of kamailio commands
484
-
485
-	5.1.2.1.   static native int KamExec(String fname, String... params);
486
-
487
-		   Executes a kamailio command.
488
-
489
-		   Parameter 'fname'  - Required. Kamailio function name.
490
-		   Parameter 'params' - An array of string parameters. Note, this method allows up to 6 params,
491
-					it will ignore all parameters if more than 6.
492
-
493
-		   Returns:
494
-			     1 - command was successfully executed.
495
-			    -1 - execution of command was failed.
496
-
497
-        5.1.2.2.   static native int SetURI(String ruri);
498
-
499
-		   Rewrites the request URI.
500
-
501
-		   Returns:
502
-			    1 - Ok
503
-			   -1 - Failed
504
-
505
-		   Online reference: http://www.kamailio.org/wiki/cookbooks/3.3.x/core#rewriteuri
506
-
507
-        5.1.2.3.   static native int RewriteURI(String ruri);
508
-
509
-		   Rewrites the request URI.
510
-		   Alias method: SetURI
511
-
512
-		   Returns:
513
-			    1 - Ok
514
-			   -1 - Failed
515
-
516
-		   Online reference: http://www.kamailio.org/wiki/cookbooks/3.3.x/core#rewriteuri
517
-
518
-
519
-
520
-5.2.   class IPPair.
521
-
522
-   Represents an IP-address pair (IP, Port)
523
-
524
-   5.2.1.   final String ip;
525
-
526
-	    IP Address
527
-
528
-   5.2.2.   final int port;
529
-
530
-	    Port
531
-
532
-
533
-5.3. abstract class SipMsg
534
-
535
-   5.3.0.   Internal structure understanding.
536
-
537
-	    The class SipMsg is partially incapsulating kamailio's struct sip_msg.
538
-	    References: parser/msg_parser.h, parser/parse_fline.h
539
-
540
-   5.3.1.   int id;
541
-
542
-	    Message id, unique/process
543
-
544
-   5.3.2.   int pid;
545
-
546
-	    Process ID
547
-
548
-   5.3.3.   String eoh;
549
-
550
-	    Pointer to the end of header (if found) or null
551
-
552
-   5.3.4.   String unparsed;
553
-
554
-	    Here we stopped parsing
555
-
556
-   5.3.5.   String buf;
557
-
558
-	    Scratch pad, holds a modified message, via, etc. point into it.
559
-
560
-   5.3.6.   int len;
561
-
562
-	    Message len (orig)
563
-
564
-   5.3.7.   String new_uri;
565
-
566
-	    Changed first line uri, when you change this
567
-
568
-   5.3.8.   String dst_uri;
569
-
570
-	    Destination URI, must be forwarded to this URI if dst_url lenght != 0
571
-
572
-   5.3.9.   int parsed_uri_ok;
573
-
574
-	    1 if parsed_orig_uri is valid, 0 if not, set if to 0 if you modify the uri (e.g change new_uri)
575
-
576
-   5.3.10.  int parsed_orig_ruri_ok;
577
-
578
-	    1 if parsed_orig_uri is valid, 0 if not, set if to 0 if you modify the uri (e.g change new_uri)
579
-
580
-   5.3.11.  String add_to_branch_s;
581
-
582
-	    Whatever whoever want to append to branch comes here
583
-
584
-   5.3.12.  int add_to_branch_len;
585
-
586
-	    Lenght of add_to_branch_s
587
-
588
-   5.3.13.  int hash_index;
589
-
590
-	    Index to TM hash table; stored in core to avoid unnecessary calculations
591
-
592
-   5.3.14.  int msg_flags;
593
-
594
-	    Flags used by core. Allows to set various flags on the message; may be used 
595
-	    for simple inter-module communication or remembering processing state reache.
596
-
597
-   5.3.15.  static native SipMsg ParseSipMsg();
598
-
599
-	    This method is using to get an instance of class SipMsg and populate a properties
600
-	    of this class with a fields specified at 5.3.1 - 5.3.14.
601
-
602
-   5.3.16.  static native String getMsgType();
603
-
604
-	    Gets a message type. Return value:
605
-		'SIP_REQUEST' - if message is request
606
-		'SIP_REPLY'   - if message is reply
607
-		'SIP_INVALID' - if invalid message
608
-
609
-   5.3.17.  static native String getRURI();
610
-
611
-	    Gets a request URI (RURI).
612
-
613
-   5.3.18.  static native IPPair getSrcAddress();
614
-
615
-	    Gets a source IP address and port.
616
-
617
-   5.3.19.  static native IPPair getDstAddress();
618
-
619
-	    Gets a destination IP address and port.
620
-
621
-   5.3.20.  static native String getBuffer();
622
-
623
-	    Gets a message buffer.
624
-
625
-
626
-5.4. interface NativeInterface
627
-
628
-   5.4.1.   abstract class Ranks
629
-
630
-	5.4.1.1.  static final int PROC_MAIN
631
-
632
-		  Main ser process
633
-
634
-        5.4.1.2.  static final int PROC_TIMER
635
-
636
-		  Timer attendant process
637
-
638
-        5.4.1.3.  static final int PROC_RPC
639
-
640
-		  RPC type process
641
-
642
-        5.4.1.4.  static final int PROC_FIFO
643
-
644
-		  FIFO attendant process.
645
-		  Alias to PROC_RPC.
646
-
647
-        5.4.1.5.  static final int PROC_TCP_MAIN
648
-
649
-		  TCP main process
650
-
651
-        5.4.1.6.  static final int PROC_UNIXSOCK
652
-
653
-		  Unix socket server
654
-
655
-        5.4.1.7.  static final int PROC_ATTENDANT
656
-
657
-		  Main "attendant process
658
-
659
-        5.4.1.8.  static final int PROC_INIT
660 416
 
661
-		  Special rank, the context is the main ser process, but this is
662
-		  guaranteed to be executed before any rocess is forked, so it
663
-		  can be used to setup shared variables that depend on some
664
-		  after mod_init available information (e.g. total number of processes).
665
-		  @warning child_init(PROC_MAIN) is again called in the same process (main)
666
-		  (before tcp), so make sure you don't init things twice, 
667
-		  both in PROC_MAIN and PROC_INT
417
+5.4. java_s_method_exec(method, method_signature, [param1[, param2[, ...]]])
668 418
 
669
-        5.4.1.9.  static final int PROC_NOCHLDINIT
419
+   Executes a java class synchronized method method. Parameter
420
+   method_signature is required.
670 421
 
671
-		  no child init functions will be called if this rank is used in fork_process()
422
+   For more info see Synchronized Methods
423
+     * Example 1.14. Signature: "V"
424
+       Kamailio prototype
425
+java_s_method_exec("ExampleMethod", "V");
426
+       Java prototype
427
+public synchronized int ExampleMethod();
428
+       Example of usage:
429
+# Kamailio
430
+java_s_method_exec("ExampleMethod", "V");
672 431
 
673
-        5.4.1.10. static final int PROC_SIPINIT
432
+# Java
433
+public synchronized int ExampleMethod()
434
+{
435
+                ... do something;
436
+                return 1;
437
+}
438
+     * Example 1.15. Signature: "Ljava/lang/String;I"
439
+       Kamailio prototype
440
+java_s_method_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world", "5");
441
+       Java prototype
442
+public synchronized int ExampleMethod(String param1, int param2);
443
+       In the above scenario parameter 2 ("5") will be cast to integer
444
+       representation.
445
+       Example of usage:
446
+# Kamailio
447
+java_s_method_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");
674 448
 
675
-		  First SIP worker - some modules do special processing in this child, 
676
-		  like loading db data
449
+# Java
450
+public synchronized int ExampleMethod(String SipMessageBuffer, int SipMessageLen
451
+ght)
452
+{
453
+                ... do something with buffer;
454
+                return 1;
455
+}
456
+     * Example 1.16. Signature: "ZB"
457
+       Kamailio prototype
458
+java_s_method_exec("ExampleMethod", "ZB", "true", "0x05");
459
+       Java prototype
460
+public synchronized int ExampleMethod(boolean param1, byte param2);
461
+       In the above scenario parameter 1 ("true") will be cast to boolean
462
+       representation.
463
+       Example of usage:
464
+# Kamailio
465
+java_s_method_exec("ExampleMethod", "ZB", "true", "0x05");
466
+
467
+# Java
468
+public synchronized int ExampleMethod(boolean flagSet, byte bFlag);
469
+{
470
+                if (flagSet)
471
+                {
472
+                        ... do something with flags;
473
+                }
474
+                return 1;
475
+}
677 476
 
678
-        5.4.1.11. static final int PROC_SIPRPC
477
+5.5. java_s_staticmethod_exec(method, method_signature, [param1[, param2[,
478
+...]]])
679 479
 
680
-		  Used to init RPC worker as SIP commands handler.
681
-		  Don't do any special processing in the child init with this rank - 
682
-		  just bare child initialization
480
+   Executes a java synchronized static method method. Parameter
481
+   method_signature is required.
683 482
 
684
-        5.4.1.12. static final int PROC_MIN
483
+   For more info see Synchronized Methods
484
+     * Example 1.17. Signature: "V"
485
+       Kamailio prototype
486
+java_s_staticmethod_exec("ExampleMethod", "V");
487
+       Java prototype
488
+public static synchronized int ExampleMethod();
489
+       Example of usage:
490
+# Kamailio
491
+java_s_staticmethod_exec("ExampleMethod", "V");
685 492
 
686
-		  Minimum process rank.
687
-		  Alias to PROC_NOCHLDINIT.
493
+# Java
494
+public static synchronized int ExampleMethod()
495
+{
496
+                ... do something;
497
+                return 1;
498
+}
499
+     * Example 1.18. Signature: "Ljava/lang/String;I"
500
+       Kamailio prototype
501
+java_s_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world",
502
+"5");
503
+       Java prototype
504
+public static synchronized int ExampleMethod(String param1, int param2);
505
+       In the above scenario parameter 2 ("5") will be cast to integer
506
+       representation.
507
+       Example of usage:
508
+# Kamailio
509
+java_s_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");
688 510
 
689
-   5.4.2.   abstract class LogParams
690
-	5.4.2.0.  Loggigng params
691
-        5.4.2.1.  static final int L_ALERT
692
-        5.4.2.2.  static final int L_BUG
693
-        5.4.2.3.  static final int L_CRIT2
694
-        5.4.2.4.  static final int L_CRIT
695
-        5.4.2.5.  static final int L_ERR
696
-        5.4.2.6.  static final int L_WARN
697
-        5.4.2.7.  static final int L_NOTICE
698
-        5.4.2.8.  static final int L_INFO
699
-        5.4.2.9.  static final int L_DBG
700
-        5.4.2.10. static final int DEFAULT_FACILITY
511
+# Java
512
+public static synchronized int ExampleMethod(String SipMessageBuffer, int SipMes
513
+sageLenght)
514
+{
515
+                ... do something with buffer;
516
+                return 1;
517
+}
518
+     * Example 1.19. Signature: "ZB"
519
+       Kamailio prototype
520
+java_s_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");
521
+       Java prototype
522
+public static synchronized int ExampleMethod(boolean param1, byte param2);
523
+       In the above scenario parameter 1 ("true") will be cast to boolean
524
+       representation.
525
+       Example of usage:
526
+# Kamailio
527
+java_s_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");
528
+
529
+# Java
530
+public static synchronized int ExampleMethod(boolean flagSet, byte bFlag);
531
+{
532
+                if (flagSet)
533
+                {
534
+                        ... do something with flags;
535
+                }
536
+                return 1;
537
+}
701 538
 
539
+6. Java Module API
702 540
 
703
-5.5. Examples of usage Java API
541
+   6.1. Minimal program skeleton
704 542
 
705
-...
543
+6.1. Minimal program skeleton
706 544
 
707
-import java.lang.*;
708
-import java.io.*; 
545
+   Example 1.20. Minimal program skeleton
709 546
 
710 547
 import org.siprouter.*;
711 548
 import org.siprouter.NativeInterface.*;
712 549
 
713 550
 public class Kamailio extends NativeMethods
714 551
 {
715
-	static
716
-	{
717
-	    System.load("/opt/kamailio/lib/kamailio/modules/app_java.so");
718
-	}
719
-
720
-	/* Constructor. Do not remove !!! */
721
-	public Kamailio()
722
-	{
723
-	}
724
-
725
-
726
-	public int child_init(int rank)
727
-	{
728
-	    switch (rank)
729
-	    {
730
-		case Ranks.PROC_MAIN:
731
-		    LM_INFO("We're at PROC_MAIN\n");
732
-		    break;
733
-		case Ranks.PROC_TIMER:
734
-		    LM_INFO("We're at PROC_TIMER\n");
735
-		    break;
736
-		case Ranks.PROC_RPC:
737
-		    LM_INFO("We're at PROC_RPC/PROC_FIFO\n");
738
-		    break;
739
-		case Ranks.PROC_TCP_MAIN:
740
-		    LM_INFO("We're at PROC_TCP_MAIN\n");
741
-		    break;
742
-		case Ranks.PROC_UNIXSOCK:
743
-		    LM_INFO("We're at PROC_UNIXSOCK\n");
744
-		    break;
745
-		case Ranks.PROC_ATTENDANT:
746
-		    LM_INFO("We're at PROC_ATTENDANT\n");
747
-		    break;
748
-		case Ranks.PROC_INIT:
749
-		    LM_INFO("We're at PROC_INIT\n");
750
-		    break;
751
-		case Ranks.PROC_NOCHLDINIT:
752
-		    LM_INFO("We're at PROC_NOCHLDINIT/PROC_MIN\n");
753
-		    break;
754
-		case Ranks.PROC_SIPINIT:
755
-		    LM_INFO("We're at PROC_SIPINIT\n");
756
-		    break;
757
-		case Ranks.PROC_SIPRPC:
758
-		    LM_INFO("We're at PROC_SIPRPC\n");
759
-		    break;
760
-	    }
761
-
762
-	    return 1;
763
-	}
764
-
765
-	public int TestMethod()
766
-	{
767
-
768
-	    LM_INFO(String.format("Msg Type: %s\n", SipMsg.getMsgType()));
769
-
770
-	    IPPair src = SipMsg.getSrcAddress();
771
-	    if (src != null)
772
-	    {
773
-		LM_INFO(String.format("src address=%s, src port=%d\n", src.ip, src.port));
774
-	    }
775
-	    else
776
-	    {
777
-		LM_ERR("IPPair src is null!");
778
-	    }
779
-
780
-	    IPPair dst = SipMsg.getDstAddress();
781
-	    if (dst != null)
782
-	    {
783
-		LM_INFO(String.format("dst address=%s, dst port=%d\n", dst.ip, dst.port));
784
-	    }
785
-	    else
786
-	    {
787
-		LM_ERR("IPPair dst is null!");
788
-	    }
789
-
790
-	    LM_INFO(String.format("buffer:\n%s\n", SipMsg.getBuffer().trim()));
791
-
792
-	    SipMsg msg = SipMsg.ParseSipMsg();
793
-	    if (msg != null)
794
-	    {
795
-		LM_INFO("msg:\n");
796
-		LM_INFO(String.format("\tid=%d\n", msg.id));
797
-		LM_INFO(String.format("\tpid=%d\n", msg.pid));
798
-		LM_INFO(String.format("\teoh='%s'\n", msg.eoh));
799
-		LM_INFO(String.format("\tunparsed='%s'\n", msg.unparsed));
800
-		LM_INFO(String.format("\tbuf='%s'\n", msg.buf));
801
-		LM_INFO(String.format("\tlen=%d\n", msg.len));
802
-		LM_INFO(String.format("\tnew_uri='%s'\n", msg.new_uri));
803
-		LM_INFO(String.format("\tdst_uri='%s'\n", msg.dst_uri));
804
-		LM_INFO(String.format("\tparsed_uri_ok=%d\n", msg.parsed_uri_ok));
805
-		LM_INFO(String.format("\tparsed_orig_ruri_ok=%d\n", msg.parsed_orig_ruri_ok));
806
-		LM_INFO(String.format("\tadd_to_branch_s='%s'\n", msg.add_to_branch_s));
807
-		LM_INFO(String.format("\tadd_to_branch_len=%d\n", msg.add_to_branch_len));
808
-		LM_INFO(String.format("\thash_index=%d\n", msg.hash_index));
809
-		LM_INFO(String.format("\tmsg_flags=%d\n", msg.msg_flags));
810
-		LM_INFO(String.format("\tset_global_address='%s'\n", msg.set_global_address));
811
-		LM_INFO(String.format("\tset_global_port='%s'\n", msg.set_global_port));
812
-	    }
813
-	    else
814
-	    {
815
-		LM_ERR("SipMsg msg is null!\n");
816
-	    }
817
-
818
-	    return 1;
819
-	}
552
+                /* Here you should specify a full path to app_java.so */
553
+                static
554
+                {
555
+                                System.load("/opt/kamailio/lib/kamailio/modules/
556
+app_java.so");
557
+                }
558
+
559
+                /* Constructor. Do not remove !!! */
560
+                public Kamailio()
561
+                {
562
+                }
563
+
564
+                /*
565
+                This method should be executed for each children process, immedi
566
+ately after forking.
567
+                Required. Do not remove !!!
568
+                */
569
+                public int child_init(int rank)
570
+                {
571
+                                return 1;
572
+                }
820 573
 }
821
-
822
-...
823
-
824
-
825
-
826
-
827
-
828
-
829
-
830
-
831
-
832
-
833
-
834
-
835
-
836
-
837
-
838 574
new file mode 100644
... ...
@@ -0,0 +1,837 @@
1
+app_java Module
2
+
3
+Konstantin Mosesov
4
+
5
+Edited by
6
+
7
+Konstantin Mosesov
8
+
9
+   <konstantinm@voipgroup.org.ua>
10
+
11
+   Copyright © 2013 Konstantin Mosesov
12
+     __________________________________________________________________
13
+
14
+   Table of Contents
15
+
16
+   1. Admin Guide
17
+
18
+        1. Overview
19
+        2. Dependencies
20
+
21
+              2.1. Kamailio Modules
22
+              2.2. External Libraries or Applications
23
+
24
+        3. Parameters
25
+
26
+	      3.1. class_name (string)
27
+              3.2. child_init_method (string)
28
+	      3.3. java_options (string)
29
+	      3.4. force_kam_cmd_exec (int)
30
+
31
+        4. Functions
32
+
33
+	      4.0. Common requirements.
34
+              4.1. java_method_exec(method, method_signature, [param1[, param2]])
35
+	      4.2. java_s_method_exec(method, method_signature, [param1[, param2]])
36
+	      4.3. java_staticmethod_exec(method, method_signature, [param1[, param2]])
37
+	      4.4. java_s_staticmethod_exec(method, method_signature, [param1[, param2]])
38
+
39
+	5. Java module API
40
+
41
+	      5.0. Minimal program skeleton and structure of package org.siprouter
42
+		   5.0.1.  Minimal program skeleton
43
+		   5.0.2.  Structure of package org.siprouter
44
+	      5.1. abstract class NativeMethods
45
+	           5.1.1.  General logging
46
+			   5.1.1.0.   Logging levels and facilities
47
+			   5.1.1.1.   native void LM_GEN1(int logLevel, String s);
48
+			   5.1.1.2.   native void LM_GEN2(int logFacility, int logLevel, String s);
49
+			   5.1.1.3.   native void LM_ALERT(String s);
50
+			   5.1.1.4.   native void LM_CRIT(String s);
51
+			   5.1.1.5.   native void LM_WARN(String s);
52
+			   5.1.1.6.   native void LM_NOTICE(String s);
53
+			   5.1.1.7.   native void LM_ERR(String s);
54
+			   5.1.1.8.   native void LM_INFO(String s);
55
+			   5.1.1.9.   native void LM_DBG(String s);
56
+		   5.1.2.  Execution of kamailio commands
57
+			   5.1.2.1.   static native int KamExec(String fname, String... params);
58
+    			   5.1.2.2.   static native int SetURI(String ruri);
59
+    			   5.1.2.3.   static native int RewriteURI(String ruri);
60
+
61
+	      5.2. class IPPair.
62
+		   5.2.1.   final String ip;
63
+		   5.2.2.   final int port;
64
+	      5.3. abstract class SipMsg
65
+		   5.3.0.   Internal structure understanding.
66
+		   5.3.1.   int id;
67
+		   5.3.2.   int pid;
68
+		   5.3.3.   String eoh;
69
+		   5.3.4.   String unparsed;
70
+		   5.3.5.   String buf;
71
+		   5.3.6.   int len;
72
+		   5.3.7.   String new_uri;
73
+		   5.3.8.   String dst_uri;
74
+		   5.3.9.   int parsed_uri_ok;
75
+		   5.3.10.  int parsed_orig_ruri_ok;
76
+		   5.3.11.  String add_to_branch_s;
77
+		   5.3.12.  int add_to_branch_len;
78
+		   5.3.13.  int hash_index;
79
+		   5.3.14.  int msg_flags;
80
+		   5.3.15.  static native SipMsg ParseSipMsg();
81
+		   5.3.16.  static native String getMsgType();
82
+		   5.3.17.  static native String getRURI();
83
+		   5.3.18.  static native IPPair getSrcAddress();
84
+		   5.3.19.  static native IPPair getDstAddress();
85
+		   5.3.20.  static native String getBuffer();
86
+	      5.4. interface NativeInterface
87
+		   5.4.1.   abstract class Ranks
88
+			    5.4.1.1.  static final int PROC_MAIN
89
+			    5.4.1.2.  static final int PROC_TIMER
90
+			    5.4.1.3.  static final int PROC_RPC
91
+			    5.4.1.4.  static final int PROC_FIFO
92
+			    5.4.1.5.  static final int PROC_TCP_MAIN
93
+			    5.4.1.6.  static final int PROC_UNIXSOCK
94
+			    5.4.1.7.  static final int PROC_ATTENDANT
95
+			    5.4.1.8.  static final int PROC_INIT
96
+			    5.4.1.9.  static final int PROC_NOCHLDINIT
97
+			    5.4.1.10. static final int PROC_SIPINIT
98
+			    5.4.1.11. static final int PROC_SIPRPC
99
+			    5.4.1.12. static final int PROC_MIN
100
+		   5.4.2.   abstract class LogParams
101
+			    5.4.2.0.  Loggigng params
102
+			    5.4.2.1.  static final int L_ALERT
103
+			    5.4.2.2.  static final int L_BUG
104
+			    5.4.2.3.  static final int L_CRIT2
105
+			    5.4.2.4.  static final int L_CRIT
106
+			    5.4.2.5.  static final int L_ERR
107
+			    5.4.2.6.  static final int L_WARN
108
+			    5.4.2.7.  static final int L_NOTICE
109
+			    5.4.2.8.  static final int L_INFO
110
+			    5.4.2.9.  static final int L_DBG
111
+			    5.4.2.10. static final int DEFAULT_FACILITY
112
+	      5.5. Examples of usage Java API
113
+
114
+   List of Examples
115
+
116
+   1.1. Set class_name parameter
117
+   1.2. Set child_init_method parameter
118
+   1.3. Set java_options parameter
119
+   1.4. Set java_options parameter (live configuration)
120
+   1.5. Set java_options parameter (verbose configuration)
121
+   1.6. Set java_options parameter (debug configuration)
122
+
123
+   2.0. Example of usage signatures.
124
+   2.1. Example of usage java_method_exec()
125
+   2.2. Example of usage java_s_method_exec()
126
+   2.3. Example of usage java_staticmethod_exec()
127
+   3.4. Example of usage java_s_staticmethod_exec()
128
+
129
+Chapter 1. Admin Guide
130
+
131
+   Table of Contents
132
+
133
+   1. Overview
134
+   2. Dependencies
135
+
136
+        2.1. Kamailio Modules
137
+        2.2. External Libraries or Applications
138
+
139
+   3. Parameters
140
+
141
+        3.1. class_name (string)
142
+        3.2. child_init_method (string)
143
+        3.3. java_options (string)
144
+	3.4. force_kam_cmd_exec (int)
145
+
146
+   4. Functions
147
+
148
+	4.0. Common requirements.
149
+        4.1. java_method_exec(method, method_signature, [param1[, param2]])         - class method
150
+        4.2. java_s_method_exec(method, method_signature, [param1[, param2]])       - class synchronized method
151
+        4.3. java_staticmethod_exec(method, method_signature, [param1[, param2]])   - static method
152
+        4.4. java_s_staticmethod_exec(method, method_signature, [param1[, param2]]) - static synchronized method
153
+
154
+1. Overview
155
+
156
+   This module allows executing Java compiled classes from config file, exporting
157
+   functions to access the SIP message from Java using Java Native Interface (JNI).
158
+
159
+2. Dependencies
160
+
161
+   2.1. Kamailio Modules
162
+   2.2. External Libraries or Applications
163
+   2.3. Java runtime
164
+
165
+2.1. Kamailio Modules