README-draft 25 KB

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