File: README

package info (click to toggle)
kamailio 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 56,100 kB
  • sloc: ansic: 552,832; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (579 lines) | stat: -rw-r--r-- 16,478 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
app_java Module

Konstantin Mosesov

Edited by

Konstantin Mosesov

   Copyright  2013, 2014 Konstantin Mosesov
     __________________________________________________________________

   Table of Contents

   1. Admin Guide

        1. Overview
        2. Dependencies

              2.1. Kamailio Modules
              2.2. External Libraries or Applications

        3. Java runtime

              3.1. JRE or JDK is required to use this module

        4. Parameters

              4.1. class_name (string)
              4.2. child_init_method (string)
              4.3. java_options (string)
              4.4. force_cmd_exec (int)

        5. Functions

              5.1. Common requirements
              5.2. java_method_exec(method, method_signature, [param1[,
                      param2[, ...]]])

              5.3. java_staticmethod_exec(method, method_signature,
                      [param1[, param2[, ...]]])

              5.4. java_s_method_exec(method, method_signature, [param1[,
                      param2[, ...]]])

              5.5. java_s_staticmethod_exec(method, method_signature,
                      [param1[, param2[, ...]]])

        6. Java Module API

              6.1. Minimal program skeleton

   List of Examples

   1.1. Set class_name parameter
   1.2. Set child_init_method parameter
   1.3. Set java_options parameter
   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_cmd_exec parameter
   1.8. Signature: "V"
   1.9. Signature: "Ljava/lang/String;I"
   1.10. Signature: "ZB"
   1.11. Signature: "V"
   1.12. Signature: "Ljava/lang/String;I"
   1.13. Signature: "ZB"
   1.14. Signature: "V"
   1.15. Signature: "Ljava/lang/String;I"
   1.16. Signature: "ZB"
   1.17. Signature: "V"
   1.18. Signature: "Ljava/lang/String;I"
   1.19. Signature: "ZB"
   1.20. Minimal program skeleton

Chapter 1. Admin Guide

   Table of Contents

   1. Overview
   2. Dependencies

        2.1. Kamailio Modules
        2.2. External Libraries or Applications

   3. Java runtime

        3.1. JRE or JDK is required to use this module

   4. Parameters

        4.1. class_name (string)
        4.2. child_init_method (string)
        4.3. java_options (string)
        4.4. force_cmd_exec (int)

   5. Functions

        5.1. Common requirements
        5.2. java_method_exec(method, method_signature, [param1[, param2[,
                ...]]])

        5.3. java_staticmethod_exec(method, method_signature, [param1[,
                param2[, ...]]])

        5.4. java_s_method_exec(method, method_signature, [param1[,
                param2[, ...]]])

        5.5. java_s_staticmethod_exec(method, method_signature, [param1[,
                param2[, ...]]])

   6. Java Module API

        6.1. Minimal program skeleton

1. Overview

   This module allows execution of Java compiled classes from the Kamailio
   config file, exporting functions to access the SIP message from Java
   using the Java Native Interface (JNI).

2. Dependencies

   2.1. Kamailio Modules
   2.2. External Libraries or Applications

2.1. Kamailio Modules

   The following modules must be loaded before this module:
     * none.

2.2. External Libraries or Applications

   The following packages are runtime libraries, required to launch
     * java-common Base of all Java packages.
     * default-jre Standard Java or Java compatible Runtime.
     * gcj-jre Java runtime environment using GIJ/classpath.
     * libgcj12 (>=12) Java runtime library for use with gcj.

   The following packages are optional, required for development
     * ant Java based build tool like make.
     * ant-contrib Collection of tasks, types and other tools for Apache
       Ant.
     * ant-gcj Java based build tool like make (GCJ).
     * default-jdk Standard Java or Java compatible Development Kit
     * gcj-jdk gcj and classpath development tools for Java(TM)
     * libgcj13-dev (>=12) Java development headers for use with gcj
     * jdk JDK Development Kit (either oracle jdk or openjdk)

   The following libraries or applications must be compiled before running
   Kamailio with this module loaded:

   The following packages are runtime libraries, required to launch
     * <class_name>.class
     * kamailio.jar

3. Java runtime

   3.1. JRE or JDK is required to use this module

3.1. JRE or JDK is required to use this module

   Java runtime library (JRE and JDK for building app_java) is required to
   use this module.

4. Parameters

   4.1. class_name (string)
   4.2. child_init_method (string)
   4.3. java_options (string)
   4.4. force_cmd_exec (int)

4.1. class_name (string)

   The class name should have the same compiled file name. If the value is
   "Kamailio", then the compiled file should be named as "Kamailio.class".

   Default value is "Kamailio".

   Example 1.1. Set class_name parameter
...
modparam("app_java", "class_name", "Kamailio")
...

4.2. child_init_method (string)

   TBD.

   Default value is "child_init".

   Example 1.2. Set child_init_method parameter
...
modparam("app_java", "child_init_method", "my_mod_init")
...

4.3. java_options (string)

   Java options for Java Virtual Machine. For more info read java docs

   Default value is "-Djava.compiler=NONE".

   Example 1.3. Set java_options parameter
...
modparam("app_java", "java_options", "-Djava.compiler=NONE")
...

   Example 1.4. Set java_options parameter (live configuration)
...
# Assumes "application java folder" is located at /opt/kamailio/java
modparam("app_java", "java_options", "-Djava.compiler=NONE
    -Djava.class.path=/path/to/kamailio/modules:/opt/kamailio/java:
    /opt/kamailio/java/kamailio.jar")
...

   Example 1.5. Set java_options parameter (verbose configuration)
...
# Assumes "application java folder" is located at /opt/kamailio/java
modparam("app_java", "java_options", "-verbose:gc,class,jni
    -Djava.compiler=NONE -Djava.class.path=/path/to/kamailio/modules:
    /opt/kamailio/java:/opt/kamailio/java/kamailio.jar")
...

   Example 1.6. Set java_options parameter (debug configuration)
...
# Assumes "application java folder" is located at /opt/kamailio/java
modparam("app_java", "java_options", "-Xdebug -verbose:gc,class,jni
    -Djava.compiler=NONE -Djava.class.path=/path/to/kamailio/modules:
    /opt/kamailio/java:/opt/kamailio/java/kamailio.jar")
...

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
   (but may not) a memory leaks if used from embedded languages.

   Default value is "0 (off)".

   Example 1.7. Set force_cmd_exec parameter
...
modparam("app_java", "force_cmd_exec", 1)
...

5. Functions

   5.1. Common requirements
   5.2. java_method_exec(method, method_signature, [param1[, param2[,
          ...]]])

   5.3. java_staticmethod_exec(method, method_signature, [param1[,
          param2[, ...]]])

   5.4. java_s_method_exec(method, method_signature, [param1[, param2[,
          ...]]])

   5.5. java_s_staticmethod_exec(method, method_signature, [param1[,
          param2[, ...]]])

5.1. Common requirements

   Each function has a required parameter "method_signature". For more
   info see Determine the signature of a method. Signature represents the
   variable type. The mapping between the Java type and C type is
                Type     Chararacter
                boolean      Z
                byte         B
                char         C
                double       D
                float        F
                int          I
                long         J
                object       L
                short        S
                void         V
                Note that to specify an object, the "L" is followed by the
                object's class name and ends with a semi-colon, ';' .

   app_java supports the following signatures:
                Primitives: Z,B,C,D,F,I,J,L,S,V
                Objects:
                        Ljava/lang/Boolean;
                        Ljava/lang/Byte;
                        Ljava/lang/Character;
                        Ljava/lang/Double;
                        Ljava/lang/Float;
                        Ljava/lang/Integer;
                        Ljava/lang/Long;
                        Ljava/lang/Short;
                        Ljava/lang/String;
                        NULL parameter: V

        Each parameter passed to function will be cast according to given signat
ure.

        Parameters are optional, ommitting a parameter meant the passed value is
 NULL.
        Parameters count should be exactly the same as signature count.
        Note 1: Arrays representation (symbol '[') is not supported yet.
        Note 2: You shall use a correct signature, e.g. the following examples o
f
        combinations are invalid:
        java_method_exec("ExampleMethod", "ZI", "False");
        java_method_exec("ExampleMethod", "LI", "something", "5");

5.2. java_method_exec(method, method_signature, [param1[, param2[, ...]]])

   Executes a java class method method. Parameter method_signature is
   required.
     * Example 1.8. Signature: "V"
       Kamailio prototype
java_method_exec("ExampleMethod", "V");
       Java prototype
public int ExampleMethod();
       Example of usage:
# Kamailio
java_method_exec("ExampleMethod", "V");

# Java
public int ExampleMethod()
{
    ... do something;
    return 1;
}
     * Example 1.9. Signature: "Ljava/lang/String;I"
       Kamailio prototype
java_method_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world", "5");
       Java prototype
public int ExampleMethod(String param1, int param2);
       In the above scenario parameter 2 ("5") will be cast to integer
       representation.
       Example of usage:
# Kamailio
java_method_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");

# Java
public int ExampleMethod(String SipMessageBuffer, int SipMessageLenght)
{
    ... do something with buffer;
    return 1;
}
     * Example 1.10. Signature: "ZB"
       Kamailio prototype
java_method_exec("ExampleMethod", "ZB", "true", "0x05");
       Java prototype
public int ExampleMethod(boolean param1, byte param2);
       In the above scenario parameter 1 ("true") will be cast to boolean
       representation.
       Example of usage:
# Kamailio
java_method_exec("ExampleMethod", "ZB", "true", "0x05");

# Java
public int ExampleMethod(boolean flagSet, byte bFlag);
{
    if (flagSet)
    {
        ... do something with flags;
    }

    return 1;
}

5.3. java_staticmethod_exec(method, method_signature, [param1[, param2[,
...]]])

   Executes a Java static method method. Parameter method_signature is
   required.
     * Example 1.11. Signature: "V"
       Kamailio prototype
java_staticmethod_exec("ExampleMethod", "V");
       Java prototype
public static int ExampleMethod();
       Example of usage:
# Kamailio
java_staticmethod_exec("ExampleMethod", "V");

# Java
public static int ExampleMethod()
{
    ... do something;
    return 1;
}
     * Example 1.12. Signature: "Ljava/lang/String;I"
       Kamailio prototype
java_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world", "5
");
       Java prototype
public static int ExampleMethod(String param1, int param2);
       In the above scenario parameter 2 ("5") will be cast to integer
       representation.
       Example of usage:
# Kamailio
java_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");

# Java
public static int ExampleMethod(String SipMessageBuffer, int SipMessageLenght)
{
    ... do something with buffer;
    return 1;
}
     * Example 1.13. Signature: "ZB"
       Kamailio prototype
java_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");
       Java prototype
public static int ExampleMethod(boolean param1, byte param2);
       In the above scenario parameter 1 ("true") will be cast to boolean
       representation.
       Example of usage:
# Kamailio
java_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");

# Java
public static int ExampleMethod(boolean flagSet, byte bFlag);
{
    if (flagSet)
    {
        ... do something with flags;
    }

    return 1;
}

5.4. java_s_method_exec(method, method_signature, [param1[, param2[, ...]]])

   Executes a Java class synchronized method method. Parameter
   method_signature is required.

   For more info see Synchronized Methods
     * Example 1.14. Signature: "V"
       Kamailio prototype
java_s_method_exec("ExampleMethod", "V");
       Java prototype
public synchronized int ExampleMethod();
       Example of usage:
# Kamailio
java_s_method_exec("ExampleMethod", "V");

# Java
public synchronized int ExampleMethod()
{
    ... do something;
    return 1;
}
     * Example 1.15. Signature: "Ljava/lang/String;I"
       Kamailio prototype
java_s_method_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world", "5");
       Java prototype
public synchronized int ExampleMethod(String param1, int param2);
       In the above scenario parameter 2 ("5") will be cast to integer
       representation.
       Example of usage:
# Kamailio
java_s_method_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");

# Java
public synchronized int ExampleMethod(String SipMessageBuffer, int SipMessageLen
ght)
{
    ... do something with buffer;
    return 1;
}
     * Example 1.16. Signature: "ZB"
       Kamailio prototype
java_s_method_exec("ExampleMethod", "ZB", "true", "0x05");
       Java prototype
public synchronized int ExampleMethod(boolean param1, byte param2);
       In the above scenario parameter 1 ("true") will be cast to boolean
       representation.
       Example of usage:
# Kamailio
java_s_method_exec("ExampleMethod", "ZB", "true", "0x05");

# Java
public synchronized int ExampleMethod(boolean flagSet, byte bFlag);
{
    if (flagSet)
    {
        ... do something with flags;
    }

    return 1;
}

5.5. java_s_staticmethod_exec(method, method_signature, [param1[, param2[,
...]]])

   Executes a java synchronized static method method. Parameter
   method_signature is required.

   For more info see Synchronized Methods
     * Example 1.17. Signature: "V"
       Kamailio prototype
java_s_staticmethod_exec("ExampleMethod", "V");
       Java prototype
public static synchronized int ExampleMethod();
       Example of usage:
# Kamailio
java_s_staticmethod_exec("ExampleMethod", "V");

# Java
public static synchronized int ExampleMethod()
{
    ... do something;
    return 1;
}
     * Example 1.18. Signature: "Ljava/lang/String;I"
       Kamailio prototype
java_s_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "Hello world",
"5");
       Java prototype
public static synchronized int ExampleMethod(String param1, int param2);
       In the above scenario parameter 2 ("5") will be cast to integer
       representation.
       Example of usage:
# Kamailio
java_s_staticmethod_exec("ExampleMethod", "Ljava/lang/String;I", "$mb", "$ml");

# Java
public static synchronized int ExampleMethod(String SipMessageBuffer, int SipMes
sageLenght)
{
    ... do something with buffer;
    return 1;
}
     * Example 1.19. Signature: "ZB"
       Kamailio prototype
java_s_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");
       Java prototype
public static synchronized int ExampleMethod(boolean param1, byte param2);
       In the above scenario parameter 1 ("true") will be cast to boolean
       representation.
       Example of usage:
# Kamailio
java_s_staticmethod_exec("ExampleMethod", "ZB", "true", "0x05");

# Java
public static synchronized int ExampleMethod(boolean flagSet, byte bFlag);
{
    if (flagSet)
    {
        ... do something with flags;
    }

    return 1;
}

6. Java Module API

   6.1. Minimal program skeleton

6.1. Minimal program skeleton

   Example 1.20. Minimal program skeleton

import org.siprouter.*;
import org.siprouter.NativeInterface.*;

public class Kamailio extends NativeMethods
{
    /* Here you should specify a full path to app_java.so */
    static
    {
        System.load("/opt/kamailio/lib/kamailio/modules/app_java.so");
    }

    /* Constructor. Do not remove !!! */
    public Kamailio()
    {
    }

    /*
        This method should be executed for each children process, immediately af
ter forking.
        Required. Do not remove !!!
    */
    public int child_init(int rank)
    {
        return 1;
    }
}