Module: sip-router
Branch: master
Commit: ebaab480a74fdde6036b471ec1175c4ad294c758
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ebaab48…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Jan 16 22:27:34 2013 +0100
Revert "app_java:"
This reverts commit db74e5230a26fdfebbf88f9575ea8a7636719743.
- code is master is fronzen for v4.0.0
---
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, 97 insertions(+), 26 deletions(-)
diff --git a/modules/app_java/config_examples/app_java.mod
b/modules/app_java/config_examples/app_java.mod
deleted file mode 100644
index b7606ff..0000000
--- a/modules/app_java/config_examples/app_java.mod
+++ /dev/null
@@ -1,10 +0,0 @@
-
-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
deleted file mode 100644
index 94156ac..0000000
--- a/modules/app_java/config_examples/modules.cfg
+++ /dev/null
@@ -1 +0,0 @@
-include_file "app_java.mod"
diff --git a/modules/app_java/global.h b/modules/app_java/global.h
index c4cf292..4a08fb1 100644
--- a/modules/app_java/global.h
+++ b/modules/app_java/global.h
@@ -33,8 +33,18 @@
#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 f1a5eaa..12a99c7 100644
--- a/modules/app_java/java_examples/Makefile
+++ b/modules/app_java/java_examples/Makefile
@@ -1,7 +1,16 @@
+#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 Kamailio.class
+ rm -f *.class
+
+
diff --git a/modules/app_java/java_examples/build.sh
b/modules/app_java/java_examples/build.sh
index d1d7815..869038d 100755
--- a/modules/app_java/java_examples/build.sh
+++ b/modules/app_java/java_examples/build.sh
@@ -1,3 +1,4 @@
#!/bin/bash
-make clean all
+make clean
+make
diff --git a/modules/app_java/java_mod.c b/modules/app_java/java_mod.c
index 443b063..d354f52 100644
--- a/modules/app_java/java_mod.c
+++ b/modules/app_java/java_mod.c
@@ -163,6 +163,7 @@ 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))
@@ -243,6 +244,7 @@ static int child_init(int rank)
(*env)->DeleteLocalRef(env, child_init_id);
+
if (jvm != NULL)
(*jvm)->DetachCurrentThread(jvm);
@@ -259,6 +261,7 @@ 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 dd12d1f..688710e 100644
--- a/modules/app_java/utils.c
+++ b/modules/app_java/utils.c
@@ -27,8 +27,6 @@
#include <time.h>
#include "utils.h"
-#include "../../sr_module.h"
-
char **split(char *str, char *sep)
{
@@ -37,13 +35,11 @@ char **split(char *str, char *sep)
char *saveptr = NULL;
int i;
- buf = (char **)pkg_realloc(NULL, sizeof(char *));
+ buf = (char **)calloc(1, sizeof(char *));
if (!buf)
{
- LM_ERR("pkg_realloc() has failed. Not enough memory!\n");
- return NULL;
+ return '\0';
}
- memset(&buf, 0, sizeof(char *));
if (str == NULL)
return buf;
@@ -63,18 +59,79 @@ char **split(char *str, char *sep)
if (token == NULL || !strcmp(token, ""))
break;
- buf = (char **)pkg_realloc(buf, (i+1) * sizeof(char *));
- if (!buf)
- {
- LM_ERR("pkg_realloc() has failed. Not enough memory!\n");
- return NULL;
- }
+ buf = (char **)realloc(buf, (i+1) * sizeof(char *));
buf[i] = strdup(token);
}
- buf[i] = NULL;
+ buf[i] = '\0';
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 f477716..1478137 100644
--- a/modules/app_java/utils.h
+++ b/modules/app_java/utils.h
@@ -28,5 +28,7 @@
#include <string.h>
char **split(char *, char *);
+char *rand_string(const int);
+char *str_replace(char *, char *, char *);
#endif