@test -e net || mkdir net
@test -e net/php || mkdir net/php
@cp reflect.java net/php
+ @echo library=php4>net/php/reflect.properties
javac net/php/reflect.java
@test ! -f reflect.class || mv reflect.class net/php # bug in KJC javac
- zip -q0 php_java.jar net/php/*.class
+ zip -q0 php_java.jar net/php/*.class net/php/*.properties
@rm net/php/reflect.*
@rmdir net/php
@rmdir net
if test -d /usr/local/lib/kaffe; then
JAVA_CFLAGS="-DKAFFE"
JAVA_INCLUDE=-I/usr/local/include/kaffe
+ JAVA_CLASSPATH=/usr/local/share/kaffe/Klasses.jar
elif test -d /usr/lib/kaffe; then
JAVA_CFLAGS="-DKAFFE"
JAVA_INCLUDE=-I/usr/include/kaffe
+ JAVA_CLASSPATH=/usr/share/kaffe/Klasses.jar
else
AC_MSG_RESULT(no)
AC_MSG_ERROR(unable to find Java VM libraries)
JAVA_INCLUDE="-I$withval/include"
test -f $withval/lib/classes.zip && JAVA_CFLAGS="-DJNI_11"
test -f $withval/lib/jvm.jar && JAVA_CFLAGS="-DJNI_12"
+ test -f $withval/lib/classes.zip && JAVA_CLASSPATH="$withval/lib/classes.zip"
+ test -f $withval/lib/jvm.jar && JAVA_CLASSPATH="$withval/lib/jvm.jar"
for i in $JAVA_INCLUDE/*; do
test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE $i"
done
test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE -I$i"
test -f $i/classes.zip && JAVA_CFLAGS="-DJNI_11"
test -f $i/jvm.jar && JAVA_CFLAGS="-DJNI_12"
+ test -f $i/classes.zip && JAVA_CLASSPATH="$i/classes.zip"
+ test -f $i/jvm.jar && JAVA_CLASSPATH="$i/jvm.jar"
done
if test -z "$JAVA_INCLUDE"; then
AC_MSG_RESULT(no)
])
AC_SUBST(JAVA_CFLAGS)
+AC_SUBST(JAVA_CLASSPATH)
AC_SUBST(JAVA_INCLUDE)
AC_SUBST(JAVA_SHARED)
AC_SUBST(JAVA_LFLAGS)
arg=0;
}
(*jenv)->SetObjectArrayElement(jenv, result, i, arg);
- if (argv[i]->type != IS_OBJECT)
- (*jenv)->DeleteLocalRef(jenv, arg);
+ if (argv[i]->type != IS_OBJECT)
+ (*jenv)->DeleteLocalRef(jenv, arg);
}
return result;
}
return 0;
}
+
/***************************************************************************/
/*
pval **arguments = (pval **) emalloc(sizeof(pval *)*arg_count);
getParametersArray(ht, arg_count, arguments);
- if (iniUpdated && jvm) jvm_destroy();
- if (!jvm) jvm_create();
- if (!jvm) return;
+ if (iniUpdated && jenv) jvm_destroy();
+ if (!jenv) jvm_create();
+ if (!jenv) return;
if (!strcmp("java",function_name->element.value.str.val)) {
/***************************************************************************/
static void _php3_java_destructor(void *jobject) {
- (*jenv)->DeleteGlobalRef(jenv, jobject);
+ if (jenv) (*jenv)->DeleteGlobalRef(jenv, jobject);
}
PHP_MINIT_FUNCTION(java) {
/***************************************************************************/
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromString
- (JNIEnv *jenv, jobject self, jlong result, jstring value)
+ (JNIEnv *jenv, jclass self, jlong result, jstring value)
{
const char *valueAsUTF = (*jenv)->GetStringUTFChars(jenv, value, 0);
pval *presult = (pval*)(long)result;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromLong
- (JNIEnv *jenv, jobject self, jlong result, jlong value)
+ (JNIEnv *jenv, jclass self, jlong result, jlong value)
{
pval *presult = (pval*)(long)result;
presult->type=IS_LONG;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromDouble
- (JNIEnv *jenv, jobject self, jlong result, jdouble value)
+ (JNIEnv *jenv, jclass self, jlong result, jdouble value)
{
pval *presult = (pval*)(long)result;
presult->type=IS_DOUBLE;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromBoolean
- (JNIEnv *jenv, jobject self, jlong result, jboolean value)
+ (JNIEnv *jenv, jclass self, jlong result, jboolean value)
{
pval *presult = (pval*)(long)result;
presult->type=IS_BOOL;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromObject
- (JNIEnv *jenv, jobject self, jlong result, jobject value)
+ (JNIEnv *jenv, jclass self, jlong result, jobject value)
{
/* wrapper the java object in a pval object */
pval *presult = (pval*)(long)result;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setException
- (JNIEnv *jenv, jobject self, jlong result, jstring value)
+ (JNIEnv *jenv, jclass self, jlong result, jstring value)
{
pval *presult = (pval*)(long)result;
Java_net_php_reflect_setResultFromString(jenv, self, result, value);
presult->type=IS_EXCEPTION;
}
+
+JNIEXPORT void JNICALL Java_net_php_reflect_setEnv
+ (JNIEnv *newJenv, jclass self)
+{
+ iniUpdated=0;
+ jenv=newJenv;
+ if (!self) self = (*jenv)->FindClass(jenv, "net/php/reflect");
+ php_reflect = (*jenv)->NewGlobalRef(jenv, self);
+}
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac -g net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac -g net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
package net.php;
import java.lang.reflect.*;
+import java.util.ResourceBundle;
import java.beans.*;
class reflect {
- static { System.loadLibrary("php_java"); }
+ static { loadLibrary("reflect"); }
+
+ protected static void loadLibrary(String property) {
+ try {
+ ResourceBundle bundle = ResourceBundle.getBundle("net.php."+property);
+ System.loadLibrary(bundle.getString("library"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
//
// Native methods
private static native void setResultFromBoolean(long result, boolean value);
private static native void setResultFromObject(long result, Object value);
private static native void setException(long result, String value);
+ public static native void setEnv();
//
// Helper routines which encapsulate the native methods
@test -e net || mkdir net
@test -e net/php || mkdir net/php
@cp reflect.java net/php
+ @echo library=php4>net/php/reflect.properties
javac net/php/reflect.java
@test ! -f reflect.class || mv reflect.class net/php # bug in KJC javac
- zip -q0 php_java.jar net/php/*.class
+ zip -q0 php_java.jar net/php/*.class net/php/*.properties
@rm net/php/reflect.*
@rmdir net/php
@rmdir net
@test -e net || mkdir net
@test -e net/php || mkdir net/php
@cp reflect.java net/php
+ @echo library=php4>net/php/reflect.properties
javac net/php/reflect.java
@test ! -f reflect.class || mv reflect.class net/php # bug in KJC javac
- zip -q0 php_java.jar net/php/*.class
+ zip -q0 php_java.jar net/php/*.class net/php/*.properties
@rm net/php/reflect.*
@rmdir net/php
@rmdir net
if test -d /usr/local/lib/kaffe; then
JAVA_CFLAGS="-DKAFFE"
JAVA_INCLUDE=-I/usr/local/include/kaffe
+ JAVA_CLASSPATH=/usr/local/share/kaffe/Klasses.jar
elif test -d /usr/lib/kaffe; then
JAVA_CFLAGS="-DKAFFE"
JAVA_INCLUDE=-I/usr/include/kaffe
+ JAVA_CLASSPATH=/usr/share/kaffe/Klasses.jar
else
AC_MSG_RESULT(no)
AC_MSG_ERROR(unable to find Java VM libraries)
JAVA_INCLUDE="-I$withval/include"
test -f $withval/lib/classes.zip && JAVA_CFLAGS="-DJNI_11"
test -f $withval/lib/jvm.jar && JAVA_CFLAGS="-DJNI_12"
+ test -f $withval/lib/classes.zip && JAVA_CLASSPATH="$withval/lib/classes.zip"
+ test -f $withval/lib/jvm.jar && JAVA_CLASSPATH="$withval/lib/jvm.jar"
for i in $JAVA_INCLUDE/*; do
test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE $i"
done
test -f $i/jni_md.h && JAVA_INCLUDE="$JAVA_INCLUDE -I$i"
test -f $i/classes.zip && JAVA_CFLAGS="-DJNI_11"
test -f $i/jvm.jar && JAVA_CFLAGS="-DJNI_12"
+ test -f $i/classes.zip && JAVA_CLASSPATH="$i/classes.zip"
+ test -f $i/jvm.jar && JAVA_CLASSPATH="$i/jvm.jar"
done
if test -z "$JAVA_INCLUDE"; then
AC_MSG_RESULT(no)
])
AC_SUBST(JAVA_CFLAGS)
+AC_SUBST(JAVA_CLASSPATH)
AC_SUBST(JAVA_INCLUDE)
AC_SUBST(JAVA_SHARED)
AC_SUBST(JAVA_LFLAGS)
arg=0;
}
(*jenv)->SetObjectArrayElement(jenv, result, i, arg);
- if (argv[i]->type != IS_OBJECT)
- (*jenv)->DeleteLocalRef(jenv, arg);
+ if (argv[i]->type != IS_OBJECT)
+ (*jenv)->DeleteLocalRef(jenv, arg);
}
return result;
}
return 0;
}
+
/***************************************************************************/
/*
pval **arguments = (pval **) emalloc(sizeof(pval *)*arg_count);
getParametersArray(ht, arg_count, arguments);
- if (iniUpdated && jvm) jvm_destroy();
- if (!jvm) jvm_create();
- if (!jvm) return;
+ if (iniUpdated && jenv) jvm_destroy();
+ if (!jenv) jvm_create();
+ if (!jenv) return;
if (!strcmp("java",function_name->element.value.str.val)) {
/***************************************************************************/
static void _php3_java_destructor(void *jobject) {
- (*jenv)->DeleteGlobalRef(jenv, jobject);
+ if (jenv) (*jenv)->DeleteGlobalRef(jenv, jobject);
}
PHP_MINIT_FUNCTION(java) {
/***************************************************************************/
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromString
- (JNIEnv *jenv, jobject self, jlong result, jstring value)
+ (JNIEnv *jenv, jclass self, jlong result, jstring value)
{
const char *valueAsUTF = (*jenv)->GetStringUTFChars(jenv, value, 0);
pval *presult = (pval*)(long)result;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromLong
- (JNIEnv *jenv, jobject self, jlong result, jlong value)
+ (JNIEnv *jenv, jclass self, jlong result, jlong value)
{
pval *presult = (pval*)(long)result;
presult->type=IS_LONG;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromDouble
- (JNIEnv *jenv, jobject self, jlong result, jdouble value)
+ (JNIEnv *jenv, jclass self, jlong result, jdouble value)
{
pval *presult = (pval*)(long)result;
presult->type=IS_DOUBLE;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromBoolean
- (JNIEnv *jenv, jobject self, jlong result, jboolean value)
+ (JNIEnv *jenv, jclass self, jlong result, jboolean value)
{
pval *presult = (pval*)(long)result;
presult->type=IS_BOOL;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromObject
- (JNIEnv *jenv, jobject self, jlong result, jobject value)
+ (JNIEnv *jenv, jclass self, jlong result, jobject value)
{
/* wrapper the java object in a pval object */
pval *presult = (pval*)(long)result;
}
JNIEXPORT void JNICALL Java_net_php_reflect_setException
- (JNIEnv *jenv, jobject self, jlong result, jstring value)
+ (JNIEnv *jenv, jclass self, jlong result, jstring value)
{
pval *presult = (pval*)(long)result;
Java_net_php_reflect_setResultFromString(jenv, self, result, value);
presult->type=IS_EXCEPTION;
}
+
+JNIEXPORT void JNICALL Java_net_php_reflect_setEnv
+ (JNIEnv *newJenv, jclass self)
+{
+ iniUpdated=0;
+ jenv=newJenv;
+ if (!self) self = (*jenv)->FindClass(jenv, "net/php/reflect");
+ php_reflect = (*jenv)->NewGlobalRef(jenv, self);
+}
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac -g net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac -g net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
if not exist net mkdir net\r
if not exist net\php mkdir net\php\r
copy $(InputPath) net\php > nul\r
+ echo library=php_java>net\php\reflect.properties\r
$(JAVA_HOME)\bin\javac net\php\reflect.java\r
- $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class\r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\php_java.jar net\php\*.class net\php\*.properties\r
erase net\php\reflect.*\r
rmdir net\php\r
rmdir net\r
package net.php;
import java.lang.reflect.*;
+import java.util.ResourceBundle;
import java.beans.*;
class reflect {
- static { System.loadLibrary("php_java"); }
+ static { loadLibrary("reflect"); }
+
+ protected static void loadLibrary(String property) {
+ try {
+ ResourceBundle bundle = ResourceBundle.getBundle("net.php."+property);
+ System.loadLibrary(bundle.getString("library"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
//
// Native methods
private static native void setResultFromBoolean(long result, boolean value);
private static native void setResultFromObject(long result, Object value);
private static native void setException(long result, String value);
+ public static native void setEnv();
//
// Helper routines which encapsulate the native methods
CREDIT_LINE("ISAPI SAPI Module", "Andi Gutmans, Zeev Suraski");
CREDIT_LINE("CGI SAPI Module", "Rasmus Lerdorf, Stig Bakken");
CREDIT_LINE("AOLserver SAPI Module", "Sascha Schumann");
+ CREDIT_LINE("Servlet SAPI Module", "Sam Ruby");
CREDIT_LINE("Overall Work", "Thies C. Arntzen, Stig Bakken, Shane Caraveo, \
Rasmus Lerdorf, Sascha Schumann, Zeev Suraski, Andrei Zmievski, \
and others");
--- /dev/null
+# $Id$
+
+SRC=servlet.c java.c
+
+CFLAGS=@CFLAGS@ @JAVA_CFLAGS@
+INCLUDES=@INCLUDES@ @JAVA_INCLUDE@ -I@top_srcdir@ -I@top_srcdir@/libzend
+noinst_LTLIBRARIES=libphpsapi_servlet.la
+libphpsapi_servlet_la_SOURCES=$(SRC)
+
+java.c : ../../ext/java/java.c
+ @cp ../../ext/java/java.c .
+
+phplib_DATA=phpsrvlt.jar
+phpsrvlt.jar : servlet.java ../../ext/java/reflect.java
+ @test -e net || mkdir net
+ @test -e net/php || mkdir net/php
+ @cp servlet.java net/php
+ @cp ../../ext/java/reflect.java net/php
+ javac net/php/reflect.java
+ @echo library=php4>net/php/reflect.properties
+ @echo library=php4>net/php/servlet.properties
+ @test ! -f reflect.class || mv reflect.class net/php # bug in KJC javac
+ javac -classpath .:@SERVLET_CLASSPATH@:@JAVA_CLASSPATH@ net/php/servlet.java
+ @test ! -f servlet.class || mv servlet.class net/php # bug in KJC javac
+ zip -q0 phpsrvlt.jar net/php/*.class net/php/*.properties
+ @rm net/php/servlet.* net/php/reflect.*
+ @rmdir net/php
+ @rmdir net
--- /dev/null
+What is PHP4 sapi/servlet?
+
+ PHP4 sapi/servlet builds upon the mechanism defined by ext/java to enable
+ the entire PHP processor to be run as a servlet. The primary advanatage
+ of this from a PHP perspective is that web servers which support servlets
+ typically take great care in pooling and reusing JVMs.
+
+ Notes:
+
+ 1) While this code is intended to be able to run on any servlet engine,
+ it has only been tested on Apache's Jakarta/tomcat to date. Bug
+ reports, success stories and/or patches required to get this code
+ to run on other engines would be appreciated.
+
+ 2) This code clean compiles on Win32 and Linux, and is able to process
+ phpinfo() commands. Most of the code is in place, but very little
+ testing has been done on even such basic things as cookies and
+ sessions. Treat this code as early alpha at this point.
+
+ 3) Until overload resolution is addressed in php/java, much of the
+ javax.servlet interfaces can not be directly called. For example,
+ don't try to get the output stream from $response, and expect to
+ be able to use println. For now, use PHP's "echo" instead.
+
+ 4) PHP has a habit of changing the working directory. Sapi/servlet will
+ eventually change it back, but while PHP is running the servlet engine
+ may not be able to load any classes from the CLASSPATH which are
+ specified using a relative directory syntax, or find the work directory used
+ for administration and JSP compilation tasks.
+
+Build and execution instructions:
+
+ Most of the configuration hassles associated with ext/java are associated
+ with starting the JVM, and as such do not apply to sapi/servlet. In
+ particular, no updates to php.ini are required on any operating system.
+
+ Unix:
+ Build:
+ ./configure --with-servlet --with-java
+ Execute:
+ add phpsrvlet.jar to CLASSPATH
+ add directory containing libphp4.so to LD_LIBRARY_PATH
+ merge/overwrite build/tomcat/examples/WEB-INF/web.xml from sapi/servlet
+
+ Win32:
+ Build:
+ add jdsk (or d:\build\tomcat\classes) to CLASSPATH
+ build sapi\servlet\servlet.dsp
+ Execute:
+ add phpsrvlet.jar to CLASSPATH
+ add directory containing php4ts.dll and phpsrvlt.dll to PATH
+ merge/overwrite build\tomcat\examples\WEB-INF\web.xml from sapi\servlet
--- /dev/null
+#ifndef SAPI_SERVLET
+#define SAPI_SERVLET 0
+#endif
--- /dev/null
+# $Id$
+# config.m4 for servlet sapi
+
+AC_MSG_CHECKING(for Servlet support)
+AC_ARG_WITH(servlet,
+[ --with-servlet[=DIR] Include servlet support. DIR is the base install
+ directory for the JSDK. This SAPI prereqs the
+ java extension must be built as a shared dl.],
+[
+ if test "$withval" != "no"; then
+
+ if test "$withval" = "yes"; then
+ SERVLET_CLASSPATH=.
+ else
+ if test -f $withval/lib/jsdk.jar; then
+ SERVLET_CLASSPATH=$withval/lib/jsdk.jar
+ else
+ if test -d $withval/javax; then
+ SERVLET_CLASSPATH=$withval
+ else
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR(unable to find JSDK libraries)
+ fi
+ fi
+ fi
+
+ AC_DEFINE(SAPI_SERVLET)
+ enable_thread_safety=yes
+ passthru="$passthru --enable-thread-safety"
+ PHP_EXTENSION(servlet, "shared")
+ PHP_SAPI=servlet
+ PHP_BUILD_SHARED
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_RESULT(no)
+ fi
+],[
+ AC_MSG_RESULT(no)
+])
+
+AC_SUBST(SERVLET_CLASSPATH)
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Sam Ruby (rubys@us.ibm.com) |
+ +----------------------------------------------------------------------+
+*/
+
+#include <jni.h>
+
+#include "dl/phpdl.h"
+#include "php.h"
+#include "php_globals.h"
+
+#include "SAPI.h"
+
+#include <stdio.h>
+#include "php.h"
+#if WIN32|WINNT
+#include "win32/time.h"
+#include "win32/signal.h"
+#include <process.h>
+#else
+#include "build-defs.h"
+#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#if HAVE_SETLOCALE
+#include <locale.h>
+#endif
+#include "zend.h"
+#include "php_ini.h"
+#include "php_globals.h"
+#include "main.h"
+#include "fopen-wrappers.h"
+#include "ext/standard/php3_standard.h"
+#include "ext/standard/php3_dir.h"
+#include "snprintf.h"
+#if WIN32|WINNT
+#include <io.h>
+#include <fcntl.h>
+#include "win32/syslog.h"
+#include "win32/php_registry.h"
+#else
+#include <syslog.h>
+#endif
+
+#include "zend_compile.h"
+#include "zend_execute.h"
+#include "zend_highlight.h"
+#include "zend_indent.h"
+
+#if USE_SAPI
+#include "serverapi/sapi.h"
+void *gLock;
+#ifndef THREAD_SAFE
+struct sapi_request_info *sapi_rqst;
+#endif
+#endif
+
+#if WIN32|WINNT || !defined(HAVE_GETOPT)
+#include "php_getopt.h"
+#endif
+
+PHPAPI extern char *php3_ini_path;
+
+JNIEXPORT void JNICALL Java_net_php_reflect_setEnv
+ (JNIEnv *newJenv, jclass self);
+
+PHPAPI extern char *optarg;
+PHPAPI extern int optind;
+
+typedef struct {
+ JNIEnv *jenv;
+ jobject servlet;
+ char *cookies;
+} servlet_request;
+
+/***************************************************************************/
+
+/*
+ * JNI convenience utilities
+ */
+
+#define SETSTRING(target, source) \
+ { const char *UTFString; \
+ if (source) { \
+ UTFString = (*jenv)->GetStringUTFChars(jenv, source, 0); \
+ target = estrdup(UTFString); \
+ (*jenv)->ReleaseStringUTFChars(jenv, source, UTFString); \
+ } else { \
+ target = 0; \
+ } }
+
+#define FREESTRING(target) \
+ { if (target) { efree(target); target=0; } }
+
+void ThrowIOException (JNIEnv *jenv, char *msg) {
+ jclass iox = (*jenv)->FindClass (jenv, "java/io/IOException");
+ (*jenv)->ThrowNew (jenv, iox, (msg?msg:"null") );
+ printf("IOException: %s\n", msg);
+}
+
+void ThrowServletException (JNIEnv *jenv, char *msg) {
+ jclass sx = (*jenv)->FindClass (jenv, "javax/servlet/ServletException");
+ (*jenv)->ThrowNew (jenv, sx, msg);
+ printf("ServletException: %s\n", msg);
+}
+
+/***************************************************************************/
+
+/*
+ * sapi callbacks
+ */
+
+static int zend_servlet_ub_write(const char *str, uint str_length)
+{
+ SLS_FETCH();
+ if (!SG(server_context)) {
+ fprintf(stderr, str);
+ return 0;
+ }
+
+ {
+ JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
+ jobject servlet = ((servlet_request*)SG(server_context))->servlet;
+
+ jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
+ jmethodID write = (*jenv)->GetMethodID(jenv, servletClass, "write",
+ "(Ljava/lang/String;)V");
+ jstring arg=(*jenv)->NewStringUTF(jenv, str);
+ (*jenv)->CallVoidMethod(jenv, servlet, write, arg);
+ (*jenv)->DeleteLocalRef(jenv, arg);
+ return str_length;
+ }
+}
+
+
+static void sapi_servlet_send_header(sapi_header_struct *sapi_header, void *server_context)
+{
+ SLS_FETCH();
+ if (!sapi_header) return;
+ if (!SG(server_context)) return;
+
+ {
+ JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
+ jobject servlet = ((servlet_request*)SG(server_context))->servlet;
+
+ jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
+ jmethodID header = (*jenv)->GetMethodID(jenv, servletClass, "header",
+ "(Ljava/lang/String;)V");
+ jstring arg=(*jenv)->NewStringUTF(jenv, sapi_header->header);
+ (*jenv)->CallVoidMethod(jenv, servlet, header, arg);
+ (*jenv)->DeleteLocalRef(jenv, arg);
+ }
+}
+
+
+static int sapi_servlet_read_post(char *buffer, uint count_bytes SLS_DC)
+{
+ JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
+ jobject servlet = ((servlet_request*)SG(server_context))->servlet;
+
+ jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
+ jmethodID readPost = (*jenv)->GetMethodID(jenv, servletClass, "readPost",
+ "(I)Ljava/lang/String;");
+ jstring post = (*jenv)->CallObjectMethod(jenv, servlet, readPost,
+ count_bytes);
+
+ const char *postAsUTF = (*jenv)->GetStringUTFChars(jenv, post, 0);
+ uint read_bytes=(*jenv)->GetStringLength(jenv, post);
+ if (read_bytes>count_bytes) read_bytes=count_bytes;
+
+ memcpy(buffer, postAsUTF, count_bytes);
+
+ (*jenv)->ReleaseStringUTFChars(jenv, post, postAsUTF);
+
+ return read_bytes;
+}
+
+
+static char *sapi_servlet_read_cookies(SLS_D)
+{
+ JNIEnv *jenv = ((servlet_request*)SG(server_context))->jenv;
+ jobject servlet = ((servlet_request*)SG(server_context))->servlet;
+
+ jclass servletClass = (*jenv)->GetObjectClass(jenv, servlet);
+ jmethodID readCookies = (*jenv)->GetMethodID(jenv, servletClass,
+ "readCookies", "()Ljava/lang/String;");
+ jstring cookies = (*jenv)->CallObjectMethod(jenv, servlet, readCookies);
+
+ SETSTRING( ((servlet_request*)SG(server_context))->cookies, cookies);
+
+ return ((servlet_request*)SG(server_context))->cookies;
+}
+
+/***************************************************************************/
+
+/*
+ * sapi maintenance
+ */
+
+static sapi_module_struct sapi_module = {
+ "PHP Language", /* name */
+
+ php_module_startup, /* startup */
+ php_module_shutdown_wrapper, /* shutdown */
+
+ zend_servlet_ub_write, /* unbuffered write */
+
+ php_error, /* error handler */
+
+ NULL, /* header handler */
+ NULL, /* send headers handler */
+ sapi_servlet_send_header, /* send header handler */
+
+ sapi_servlet_read_post, /* read POST data */
+ sapi_servlet_read_cookies, /* read Cookies */
+
+ STANDARD_SAPI_MODULE_PROPERTIES
+};
+
+
+JNIEXPORT void JNICALL Java_net_php_servlet_startup
+ (JNIEnv *jenv, jobject self)
+{
+
+#ifdef ZTS
+ tsrm_startup(1,1,0);
+#else
+ if (setjmp(EG(bailout))!=0) {
+ ThrowServletException(jenv,"bailout");
+ return;
+ }
+#endif
+
+ sapi_startup(&sapi_module);
+
+ if (php_module_startup(&sapi_module)==FAILURE) {
+ ThrowServletException(jenv,"module startup failure");
+ return;
+ }
+}
+
+
+JNIEXPORT void JNICALL Java_net_php_servlet_shutdown
+ (JNIEnv *jenv, jobject self)
+{
+ SLS_FETCH();
+
+ php_module_shutdown();
+#ifdef ZTS
+ tsrm_shutdown();
+#endif
+ return;
+}
+
+/***************************************************************************/
+
+/*
+ * define a Java object to PHP
+ */
+
+JNIEXPORT jlong JNICALL Java_net_php_servlet_define
+ (JNIEnv *jenv, jobject self, jstring name)
+{
+ pval *pzval;
+ jlong addr = 0;
+ ELS_FETCH();
+ const char *nameAsUTF = (*jenv)->GetStringUTFChars(jenv, name, 0);
+
+ MAKE_STD_ZVAL(pzval);
+ (pval*)(long)addr = pzval;
+
+ zend_hash_add(&EG(symbol_table), (char*)nameAsUTF,
+ strlen(nameAsUTF)+1, &pzval, sizeof(pval *), NULL);
+ (*jenv)->ReleaseStringUTFChars(jenv, name, nameAsUTF);
+
+ return addr;
+}
+
+/*
+ * execute a script
+ */
+
+JNIEXPORT void JNICALL Java_net_php_servlet_send
+ (JNIEnv *jenv, jobject self,
+ jstring requestMethod, jstring queryString,
+ jstring pathInfo, jstring pathTranslated,
+ jstring contentType, jint contentLength, jstring authUser)
+{
+
+ zend_file_handle file_handle;
+ jlong addr = 0;
+ SLS_FETCH();
+ PLS_FETCH();
+ CLS_FETCH();
+ ELS_FETCH();
+
+#ifdef ZTS
+ if (setjmp(EG(bailout))!=0) {
+ ThrowServletException(jenv,"bailout");
+ return;
+ }
+#endif
+
+ SG(server_context) = emalloc(sizeof(servlet_request));
+ ((servlet_request*)SG(server_context))->jenv=jenv;
+ ((servlet_request*)SG(server_context))->servlet=self;
+ ((servlet_request*)SG(server_context))->cookies=0;
+
+ CG(extended_info) = 0;
+
+ /*
+ * Initialize the request
+ */
+ SETSTRING( SG(request_info).auth_user, authUser );
+ SETSTRING( SG(request_info).request_method, requestMethod );
+ SETSTRING( SG(request_info).query_string, queryString );
+ SETSTRING( SG(request_info).request_uri, pathInfo );
+ SETSTRING( SG(request_info).content_type, contentType );
+ SG(request_info).content_length = contentLength;
+ SG(request_info).auth_password = NULL;
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC)==FAILURE) {
+ ThrowServletException(jenv,"request startup failure");
+ return;
+ }
+
+ /*
+ * Parse the file
+ */
+ SETSTRING( SG(request_info).path_translated, pathTranslated );
+ file_handle.handle.fp = php3_fopen_for_parser();
+ file_handle.filename = SG(request_info).path_translated;
+ file_handle.type = ZEND_HANDLE_FP;
+
+ if (!file_handle.handle.fp) {
+ php_request_shutdown((void *) 0);
+ php_module_shutdown();
+ ThrowIOException(jenv,file_handle.filename);
+ return;
+ }
+
+ /*
+ * Execute the request
+ */
+ Java_net_php_reflect_setEnv(jenv, 0);
+ php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
+
+ /*
+ * Clean up
+ */
+ php3_header(); /* Make sure headers have been sent */
+
+ FREESTRING(SG(request_info).request_method);
+ FREESTRING(SG(request_info).query_string);
+ FREESTRING(SG(request_info).request_uri);
+ FREESTRING(SG(request_info).path_translated);
+ FREESTRING(SG(request_info).content_type);
+ FREESTRING(SG(request_info).auth_user);
+ FREESTRING(((servlet_request*)SG(server_context))->cookies);
+ efree(SG(server_context));
+ SG(server_context)=0;
+
+ php_request_shutdown((void *) 0);
+}
+
--- /dev/null
+# Microsoft Developer Studio Project File - Name="servlet" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102\r
+\r
+CFG=servlet - Win32 Debug_TS\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "servlet.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "servlet.mak" CFG="servlet - Win32 Debug_TS"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "servlet - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE "servlet - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE "servlet - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE "servlet - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+MTL=midl.exe\r
+RSC=rc.exe\r
+\r
+!IF "$(CFG)" == "servlet - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "..\..\Release"\r
+# PROP BASE Intermediate_Dir "..\..\Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\..\Release"\r
+# PROP Intermediate_Dir "..\..\Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\libzend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /YX /FD /c\r
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x40d /d "NDEBUG"\r
+# ADD RSC /l 0x40d /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r
+# ADD LINK32 php_java.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release/phpsrvlt.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release"\r
+\r
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "..\..\Debug"\r
+# PROP BASE Intermediate_Dir "..\..\Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "..\..\Debug"\r
+# PROP Intermediate_Dir "..\..\Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\libzend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /D ZEND_DEBUG=1 /FR /YX /FD /GZ /c\r
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x40d /d "_DEBUG"\r
+# ADD RSC /l 0x40d /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 php_java.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug/phpsrvlt.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug"\r
+\r
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug_TS"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "..\..\Debug_TS"\r
+# PROP BASE Intermediate_Dir "..\..\Debug_TS"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "..\..\Debug_TS"\r
+# PROP Intermediate_Dir "..\..\Debug_TS"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\..\libzend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /FR /YX /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\libzend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "_DEBUG" /D ZEND_DEBUG=1 /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /D "ZTS" /FR /YX /FD /GZ /c\r
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x40d /d "_DEBUG"\r
+# ADD RSC /l 0x40d /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 php4ts.lib php_java.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/phpsrvlt.dll" /pdbtype:sept /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Debug_TS"\r
+\r
+!ELSEIF "$(CFG)" == "servlet - Win32 Release_TS"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "..\..\Release_TS"\r
+# PROP BASE Intermediate_Dir "..\..\Release_TS"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\..\Release_TS"\r
+# PROP Intermediate_Dir "..\..\Release_TS"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\..\libzend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /YX /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\libzend" /I "$(JAVA_HOME)\include\win32" /I "$(JAVA_HOME)\include" /I "..\..\..\bindlib_w32" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL" /D "ZTS" /YX /FD /c\r
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x40d /d "NDEBUG"\r
+# ADD RSC /l 0x40d /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r
+# ADD LINK32 php4ts.lib php_java.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/phpsrvlt.dll" /libpath:"$(JAVA_HOME)\lib" /libpath:"..\..\Release_TS"\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "servlet - Win32 Release"\r
+# Name "servlet - Win32 Debug"\r
+# Name "servlet - Win32 Debug_TS"\r
+# Name "servlet - Win32 Release_TS"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\servlet.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=..\..\ext\java\java.c\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# End Group\r
+# Begin Group "Java Files"\r
+\r
+# PROP Default_Filter "java"\r
+# Begin Source File\r
+\r
+SOURCE=.\servlet.java\r
+\r
+!IF "$(CFG)" == "servlet - Win32 Release"\r
+\r
+# Begin Custom Build\r
+OutDir=.\..\..\Release\r
+InputPath=.\servlet.java\r
+\r
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\r
+ if not exist net mkdir net \r
+ if not exist net\php mkdir net\php \r
+ copy $(InputPath) net\php > nul \r
+ copy ..\..\ext\java\reflect.java net\php > nul\r
+ echo library=phpsrvlt>net/php/reflect.properties\r
+ echo library=phpsrvlt>net/php/servlet.properties\r
+ $(JAVA_HOME)\bin\javac net\php\servlet.java \r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties\r
+ erase net\php\servlet.* \r
+ erase net\php\reflect.* \r
+ rmdir net\php \r
+ rmdir net \r
+ \r
+# End Custom Build\r
+\r
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug"\r
+\r
+# Begin Custom Build\r
+OutDir=.\..\..\Debug\r
+InputPath=.\servlet.java\r
+\r
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\r
+ if not exist net mkdir net \r
+ if not exist net\php mkdir net\php \r
+ copy $(InputPath) net\php > nul \r
+ copy ..\..\ext\java\reflect.java net\php > nul\r
+ echo library=phpsrvlt>net/php/reflect.properties\r
+ echo library=phpsrvlt>net/php/servlet.properties\r
+ $(JAVA_HOME)\bin\javac -g net\php\servlet.java \r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties\r
+ erase net\php\servlet.* \r
+ erase net\php\reflect.* \r
+ rmdir net\php \r
+ rmdir net \r
+ \r
+# End Custom Build\r
+\r
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug_TS"\r
+\r
+USERDEP__SERVL=".\servlet.java" \r
+# Begin Custom Build\r
+OutDir=.\..\..\Debug_TS\r
+InputPath=.\servlet.java\r
+\r
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\r
+ if not exist net mkdir net \r
+ if not exist net\php mkdir net\php \r
+ copy *.java net\php > nul \r
+ copy ..\..\ext\java\reflect.java net\php > nul\r
+ echo library=phpsrvlt>net/php/reflect.properties\r
+ echo library=phpsrvlt>net/php/servlet.properties\r
+ $(JAVA_HOME)\bin\javac -g net\php\servlet.java \r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties\r
+ erase net\php\servlet.* \r
+ erase net\php\reflect.* \r
+ rmdir net\php \r
+ rmdir net \r
+ \r
+# End Custom Build\r
+\r
+!ELSEIF "$(CFG)" == "servlet - Win32 Release_TS"\r
+\r
+# Begin Custom Build\r
+OutDir=.\..\..\Release_TS\r
+InputPath=.\servlet.java\r
+\r
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"\r
+ if not exist net mkdir net \r
+ if not exist net\php mkdir net\php \r
+ copy $(InputPath) net\php > nul \r
+ copy ..\..\ext\java\reflect.java net\php > nul\r
+ echo library=phpsrvlt>net/php/reflect.properties\r
+ echo library=phpsrvlt>net/php/servlet.properties\r
+ $(JAVA_HOME)\bin\javac net\php\servlet.java \r
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties\r
+ erase net\php\servlet.* \r
+ erase net\php\reflect.* \r
+ rmdir net\php \r
+ rmdir net \r
+ \r
+# End Custom Build\r
+\r
+!ENDIF \r
+\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\servlet.java\r
+# End Source File\r
+# End Group\r
+# Begin Source File\r
+\r
+SOURCE=.\jtest.php\r
+# End Source File\r
+# End Target\r
+# End Project\r
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Sam Ruby (rubys@us.ibm.com) |
+ +----------------------------------------------------------------------+
+*/
+
+package net.php;
+
+import java.io.IOException;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+public class servlet extends HttpServlet {
+
+ char slash=System.getProperty("file.separator").charAt(0);
+ HttpServletRequest request;
+ HttpServletResponse response;
+ ServletInputStream stream;
+
+ /******************************************************************/
+ /* native methods */
+ /******************************************************************/
+
+ static { reflect.loadLibrary("servlet"); }
+ native void startup();
+ native long define(String name);
+ native void send(String requestMethod, String queryString,
+ String pathInfo, String pathTranslated,
+ String contentType, int contentLength, String authUser);
+ native void shutdown();
+
+ /******************************************************************/
+ /* sapi callbacks */
+ /******************************************************************/
+
+ String readPost(int bytes) {
+ try {
+ if (stream == null) stream=request.getInputStream();
+ byte[] data = new byte[bytes];
+ int len = stream.read(data, 0, bytes);
+ if (len <= 0) return "";
+ return new String(data, 0, len);
+ } catch (IOException e) {
+ return "";
+ }
+ }
+
+ String readCookies() {
+ reflect.setResult(define("request"), request);
+ reflect.setResult(define("response"), response);
+ return request.getHeader("cookie");
+ }
+
+ void header(String data) {
+ try {
+ if (data.startsWith("Content-Type: ")) {
+ response.setContentType(data.substring(data.indexOf(" ")+1));
+ } else if (data.startsWith("Location: ")) {
+ response.sendRedirect(data.substring(data.indexOf(" ")+1));
+ } else {
+ int colon = data.indexOf(": ");
+ if (colon > 0) {
+ response.addHeader(data.substring(0,colon),
+ data.substring(colon+2));
+ } else {
+ response.getWriter().println(data);
+ }
+ }
+ } catch (IOException e) {
+ System.err.print(data);
+ }
+ }
+
+ void write(String data) {
+ try {
+ response.getWriter().print(data);
+ } catch (IOException e) {
+ System.err.print(data);
+ }
+ }
+
+ /******************************************************************/
+ /* servlet interface */
+ /******************************************************************/
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ startup();
+ }
+
+ public void service(HttpServletRequest request,
+ HttpServletResponse response)
+ throws ServletException
+ {
+ this.request=request;
+ this.response=response;
+ send(request.getMethod(), request.getQueryString(),
+ request.getPathInfo(), getPathTranslated(),
+ request.getContentType(), request.getContentLength(),
+ request.getRemoteUser());
+
+ try {
+ if (stream != null) stream.close();
+ } catch (IOException e) {
+ throw new ServletException(e);
+ }
+ }
+
+ public void destroy() {
+ shutdown();
+ super.destroy();
+ }
+
+ /******************************************************************/
+ /* utility function */
+ /******************************************************************/
+
+ String getPathTranslated() {
+ /* I have no idea why this has to be this hard... */
+ String servletPath=request.getServletPath();
+ String contextPath=getServletContext().getRealPath(servletPath);
+ servletPath=servletPath.replace('/',slash);
+ contextPath=contextPath.substring(0,contextPath.lastIndexOf(slash));
+ return contextPath+servletPath;
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
+ "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
+
+<web-app>
+ <servlet>
+ <servlet-name>
+ php
+ </servlet-name>
+ <servlet-class>
+ net.php.servlet
+ </servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>
+ php
+ </servlet-name>
+ <url-pattern>
+ *.php
+ </url-pattern>
+ </servlet-mapping>
+</web-app>