Module: sip-router
Branch: master
Commit: db74e5230a26fdfebbf88f9575ea8a7636719743
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=db74e52…
Author: Konstantin Mosesov <ez(a)voipgroup.org.ua>
Committer: Konstantin Mosesov <ez(a)voipgroup.org.ua>
Date: Wed Jan 16 21:08:42 2013 +0200
app_java:
- code cleanup
- changed all *alloc to pkg_*alloc
- added examples module configuration file
---
modules/app_java/config_examples/app_java.mod | 10 +++
modules/app_java/config_examples/modules.cfg | 1 +
modules/app_java/global.h | 10 ---
modules/app_java/java_examples/Makefile | 11 +---
modules/app_java/java_examples/build.sh | 3 +-
modules/app_java/java_mod.c | 3 -
modules/app_java/utils.c | 83 ++++---------------------
modules/app_java/utils.h | 2 -
8 files changed, 26 insertions(+), 97 deletions(-)
diff --git a/modules/app_java/config_examples/app_java.mod
b/modules/app_java/config_examples/app_java.mod
new file mode 100644
index 0000000..b7606ff
--- /dev/null
+++ b/modules/app_java/config_examples/app_java.mod
@@ -0,0 +1,10 @@
+
+loadmodule "app_java.so"
+modparam("app_java", "script_name",
"/opt/kamailio/java/Kamailio.class")
+modparam("app_java", "pkg_tree_path", "")
+modparam("app_java", "class_name", "Kamailio")
+#modparam("app_java", "java_options", "-Xdebug
-Djava.compiler=NONE
-Djava.class.path=/opt/kamailio/lib/kamailio/modules:/opt/kamailio/java
-Djava.library.path=/usr/lib/jvm/java-gcj-4.7:/opt/kamailio/lib/kamailio/modules:/opt/kamailio/java
-verbose:gc,class,jni")
+#modparam("app_java", "java_options", "-Xdebug
-Djava.compiler=NONE
-Djava.class.path=/opt/kamailio/lib/kamailio/modules:/opt/kamailio/java
-verbose:gc,class,jni")
+modparam("app_java", "java_options", "-Djava.compiler=NONE
-Djava.class.path=/opt/kamailio/lib/kamailio/modules:/opt/kamailio/java
-verbose:gc,jni")
+modparam("app_java", "child_init_method", "child_init")
+
diff --git a/modules/app_java/config_examples/modules.cfg
b/modules/app_java/config_examples/modules.cfg
new file mode 100644
index 0000000..94156ac
--- /dev/null
+++ b/modules/app_java/config_examples/modules.cfg
@@ -0,0 +1 @@
+include_file "app_java.mod"
diff --git a/modules/app_java/global.h b/modules/app_java/global.h
index 4a08fb1..c4cf292 100644
--- a/modules/app_java/global.h
+++ b/modules/app_java/global.h
@@ -33,18 +33,8 @@
#define JAVA_MODULE_PKG_PATH "org/sip-router"
-typedef struct threadData
-{
- JNIEnv *env;
- JavaVM *jvm;
- char *sClassName;
- int iThreadIndex;
-} tstThreadData;
-
-
JavaVM *jvm;
JNIEnv *env;
-tstThreadData *pThreadData;
jclass KamailioClass;
jclass KamailioClassInstanceRef;
jobject KamailioClassInstance;
diff --git a/modules/app_java/java_examples/Makefile
b/modules/app_java/java_examples/Makefile
index 12a99c7..f1a5eaa 100644
--- a/modules/app_java/java_examples/Makefile
+++ b/modules/app_java/java_examples/Makefile
@@ -1,16 +1,7 @@
-#JAVA_HOME=$(readlink -f $(which javac) | sed "s:bin/javac::")
-#CLASSPATH := /usr/local/lib/kamailio/modules
-
-JAVA_HOME ?= /usr/lib/jvm/java-gcj-4.7/
-
all:
-# export
JAVA_HOME=/usr/lib/jvm/java-gcj-4.7:/opt/kamailio/lib/kamailio/modules:/opt/kamailio/java
-# export CLASSPATH=/opt/kamailio/lib/kamailio/modules:/opt/kamailio/java
javac Kamailio.java
clean:
- rm -f *.class
-
-
+ rm -f Kamailio.class
diff --git a/modules/app_java/java_examples/build.sh
b/modules/app_java/java_examples/build.sh
index 869038d..d1d7815 100755
--- a/modules/app_java/java_examples/build.sh
+++ b/modules/app_java/java_examples/build.sh
@@ -1,4 +1,3 @@
#!/bin/bash
-make clean
-make
+make clean all
diff --git a/modules/app_java/java_mod.c b/modules/app_java/java_mod.c
index d354f52..443b063 100644
--- a/modules/app_java/java_mod.c
+++ b/modules/app_java/java_mod.c
@@ -163,7 +163,6 @@ static int mod_init(void)
}
-// KamailioClass = (*env)->FindClass(env, class_name.s);
KamailioClass = (*env)->FindClass(env, class_object_name);
pkg_free(class_object_name);
if (!KamailioClass || (*env)->ExceptionCheck(env))
@@ -244,7 +243,6 @@ static int child_init(int rank)
(*env)->DeleteLocalRef(env, child_init_id);
-
if (jvm != NULL)
(*jvm)->DetachCurrentThread(jvm);
@@ -261,7 +259,6 @@ static void mod_destroy(void)
if (jvm != NULL)
{
-
(*jvm)->DetachCurrentThread(jvm);
(*jvm)->DestroyJavaVM(jvm);
}
diff --git a/modules/app_java/utils.c b/modules/app_java/utils.c
index 688710e..dd12d1f 100644
--- a/modules/app_java/utils.c
+++ b/modules/app_java/utils.c
@@ -27,6 +27,8 @@
#include <time.h>
#include "utils.h"
+#include "../../sr_module.h"
+
char **split(char *str, char *sep)
{
@@ -35,11 +37,13 @@ char **split(char *str, char *sep)
char *saveptr = NULL;
int i;
- buf = (char **)calloc(1, sizeof(char *));
+ buf = (char **)pkg_realloc(NULL, sizeof(char *));
if (!buf)
{
- return '\0';
+ LM_ERR("pkg_realloc() has failed. Not enough memory!\n");
+ return NULL;
}
+ memset(&buf, 0, sizeof(char *));
if (str == NULL)
return buf;
@@ -59,79 +63,18 @@ char **split(char *str, char *sep)
if (token == NULL || !strcmp(token, ""))
break;
- buf = (char **)realloc(buf, (i+1) * sizeof(char *));
+ buf = (char **)pkg_realloc(buf, (i+1) * sizeof(char *));
+ if (!buf)
+ {
+ LM_ERR("pkg_realloc() has failed. Not enough memory!\n");
+ return NULL;
+ }
buf[i] = strdup(token);
}
- buf[i] = '\0';
+ buf[i] = NULL;
free(token);
return buf;
}
-
-char *rand_string(const int len)
-{
- char *buf;
- const char alphanum[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- int i;
-
- buf = (char *)calloc(len+1, sizeof(char));
- if (!buf)
- return NULL;
-
- srand(time(NULL));
- for (i=0; i<len; i++)
- {
- buf[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
- }
-
- buf[len] = '\0';
-
- return buf;
-}
-
-char *str_replace(char *original, char *pattern, char *replacement)
-{
- char *oriptr, *patloc, *retptr, *returned;
- size_t replen, patlen, orilen, patcnt, retlen, skplen;
-
- replen = strlen(replacement);
- patlen = strlen(pattern);
- orilen = strlen(original);
- patcnt = 0;
-
- // find how many times the pattern occurs in the original string
- for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc +
patlen)
- {
- patcnt++;
- }
-
- // allocate memory for the new string
- retlen = orilen + patcnt * (replen - patlen);
- returned = (char *)malloc((retlen+1) * sizeof(char));
-
- if (returned != NULL)
- {
- // copy the original string,
- // replacing all the instances of the pattern
- retptr = returned;
- for (oriptr = original; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen)
- {
- skplen = patloc - oriptr;
-
- // copy the section until the occurence of the pattern
- strncpy(retptr, oriptr, skplen);
- retptr += skplen;
-
- // copy the replacement
- strncpy(retptr, replacement, replen);
- retptr += replen;
- }
-
- // copy the rest of the string.
- strcpy(retptr, oriptr);
- }
-
- return returned;
-}
diff --git a/modules/app_java/utils.h b/modules/app_java/utils.h
index 1478137..f477716 100644
--- a/modules/app_java/utils.h
+++ b/modules/app_java/utils.h
@@ -28,7 +28,5 @@
#include <string.h>
char **split(char *, char *);
-char *rand_string(const int);
-char *str_replace(char *, char *, char *);
#endif