java_native_methods.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /* $Id$
  2. *
  3. * Copyright (C) 2009 Sippy Software, Inc., http://www.sippysoft.com
  4. *
  5. * This file is part of SIP-Router, a free SIP server.
  6. *
  7. * SIP-Router is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * SIP-Router is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #include <libgen.h>
  23. #include "../../str.h"
  24. #include "../../sr_module.h"
  25. #include <jni.h>
  26. #include "global.h"
  27. #include "utils.h"
  28. #include "java_mod.h"
  29. #include "java_iface.h"
  30. #include "java_support.h"
  31. #include "java_native_methods.h"
  32. //// native methods ////
  33. /*
  34. java: native void LM_XXXXXX(Params XXXX);
  35. c: JNIEXPORT void JNICALL Java_Kamailio_LM_1XXXXXX(JNIEnv *jenv, jobject this, Params XXXX)
  36. Why (for example) Java_Kamailio_LM_1ERR but not Java_Kamailio_LM_ERR?
  37. See explaination here: http://qscribble.blogspot.ca/2012/04/underscores-in-jni-method-names.html
  38. */
  39. #ifdef LM_ERR
  40. // java: native void LM_ERR(String s);
  41. JNIEXPORT void JNICALL Java_Kamailio_LM_1ERR(JNIEnv *jenv, jobject this, jstring js)
  42. {
  43. const char *s;
  44. jboolean iscopy;
  45. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  46. if ((*jenv)->ExceptionCheck(jenv))
  47. {
  48. handle_exception();
  49. return;
  50. }
  51. LM_ERR("%s", s == NULL ? "null\n" : s);
  52. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  53. }
  54. #endif
  55. #ifdef LM_WARN
  56. // java: native void LM_WARN(String s);
  57. JNIEXPORT void JNICALL Java_Kamailio_LM_1WARN(JNIEnv *jenv, jobject this, jstring js)
  58. {
  59. const char *s;
  60. jboolean iscopy;
  61. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  62. if ((*jenv)->ExceptionCheck(jenv))
  63. {
  64. handle_exception();
  65. return;
  66. }
  67. LM_WARN("%s", s == NULL ? "null\n" : s);
  68. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  69. }
  70. #endif
  71. #ifdef LM_NOTICE
  72. // java: native void LM_NOTICE(String s);
  73. JNIEXPORT void JNICALL Java_Kamailio_LM_1NOTICE(JNIEnv *jenv, jobject this, jstring js)
  74. {
  75. const char *s;
  76. jboolean iscopy;
  77. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  78. if ((*jenv)->ExceptionCheck(jenv))
  79. {
  80. handle_exception();
  81. return;
  82. }
  83. LM_NOTICE("%s", s == NULL ? "null\n" : s);
  84. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  85. }
  86. #endif
  87. #ifdef LM_INFO
  88. // java: native void LM_INFO(String s);
  89. JNIEXPORT void JNICALL Java_Kamailio_LM_1INFO(JNIEnv *jenv, jobject this, jstring js)
  90. {
  91. const char *s;
  92. jboolean iscopy;
  93. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  94. if ((*jenv)->ExceptionCheck(jenv))
  95. {
  96. handle_exception();
  97. return;
  98. }
  99. LM_INFO("%s", s == NULL ? "null\n" : s);
  100. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  101. }
  102. #endif
  103. #ifdef LM_DBG
  104. // java: native void LM_DBG(String s);
  105. JNIEXPORT void JNICALL Java_Kamailio_LM_1DBG(JNIEnv *jenv, jobject this, jstring js)
  106. {
  107. const char *s;
  108. jboolean iscopy;
  109. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  110. if ((*jenv)->ExceptionCheck(jenv))
  111. {
  112. handle_exception();
  113. return;
  114. }
  115. LM_DBG("%s", s == NULL ? "null\n" : s);
  116. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  117. }
  118. #endif
  119. #ifdef LM_CRIT
  120. // java: native void LM_CRIT(String s);
  121. JNIEXPORT void JNICALL Java_Kamailio_LM_1CRIT(JNIEnv *jenv, jobject this, jstring js)
  122. {
  123. const char *s;
  124. jboolean iscopy;
  125. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  126. if ((*jenv)->ExceptionCheck(jenv))
  127. {
  128. handle_exception();
  129. return;
  130. }
  131. LM_CRIT("%s", s == NULL ? "null\n" : s);
  132. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  133. }
  134. #endif
  135. #ifdef LM_ALERT
  136. // java: native void LM_ALERT(String s);
  137. JNIEXPORT void JNICALL Java_Kamailio_LM_1ALERT(JNIEnv *jenv, jobject this, jstring js)
  138. {
  139. const char *s;
  140. jboolean iscopy;
  141. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  142. if ((*jenv)->ExceptionCheck(jenv))
  143. {
  144. handle_exception();
  145. return;
  146. }
  147. LM_ALERT("%s", s == NULL ? "null\n" : s);
  148. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  149. }
  150. #endif
  151. #ifdef LM_GEN1
  152. // java: native void LM_GEN1(int logLevel, String s);
  153. JNIEXPORT void JNICALL Java_Kamailio_LM_1GEN1(JNIEnv *jenv, jobject this, jint ll, jstring js)
  154. {
  155. const char *s;
  156. jboolean iscopy;
  157. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  158. if ((*jenv)->ExceptionCheck(jenv))
  159. {
  160. handle_exception();
  161. return;
  162. }
  163. LM_GEN1(ll, "%s", s == NULL ? "null\n" : s);
  164. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  165. }
  166. #endif
  167. #ifdef LM_GEN2
  168. // java: native void LM_GEN2(int logLevel, int logFacility, String s);
  169. JNIEXPORT void JNICALL Java_Kamailio_LM_1GEN2(JNIEnv *jenv, jobject this, jint ll, jint lf, jstring js)
  170. {
  171. const char *s;
  172. jboolean iscopy;
  173. s = (*jenv)->GetStringUTFChars(jenv, js, &iscopy);
  174. if ((*jenv)->ExceptionCheck(jenv))
  175. {
  176. handle_exception();
  177. return;
  178. }
  179. LM_GEN2(ll, lf, "%s", s == NULL ? "null\n" : s);
  180. (*jenv)->ReleaseStringUTFChars(jenv, js, s);
  181. }
  182. #endif
  183. //// native properties ////