diff options
| author | Sam Ruby <rubys@php.net> | 1999-11-29 15:36:25 +0000 |
|---|---|---|
| committer | Sam Ruby <rubys@php.net> | 1999-11-29 15:36:25 +0000 |
| commit | fd9265362c9d4f32256ec8f23c36ebbfa650dfb9 (patch) | |
| tree | c13ffa00cc1f3bbd2cf283244a7c0a3f9e1870b4 /sapi | |
| parent | a76c133df16455dd7a29f8921f0a3609f6133734 (diff) | |
| download | php-git-fd9265362c9d4f32256ec8f23c36ebbfa650dfb9.tar.gz | |
Initial alpha-level of sapi/servlet. See README for details.
Diffstat (limited to 'sapi')
| -rw-r--r-- | sapi/servlet/Makefile.am | 28 | ||||
| -rw-r--r-- | sapi/servlet/README | 52 | ||||
| -rw-r--r-- | sapi/servlet/config.h.stub | 3 | ||||
| -rw-r--r-- | sapi/servlet/config.m4 | 41 | ||||
| -rw-r--r-- | sapi/servlet/servlet.c | 384 | ||||
| -rw-r--r-- | sapi/servlet/servlet.dsp | 271 | ||||
| -rw-r--r-- | sapi/servlet/servlet.java | 138 | ||||
| -rw-r--r-- | sapi/servlet/web.xml | 24 |
8 files changed, 941 insertions, 0 deletions
diff --git a/sapi/servlet/Makefile.am b/sapi/servlet/Makefile.am new file mode 100644 index 0000000000..d729f60a4c --- /dev/null +++ b/sapi/servlet/Makefile.am @@ -0,0 +1,28 @@ +# $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 diff --git a/sapi/servlet/README b/sapi/servlet/README new file mode 100644 index 0000000000..de6782ecf9 --- /dev/null +++ b/sapi/servlet/README @@ -0,0 +1,52 @@ +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 diff --git a/sapi/servlet/config.h.stub b/sapi/servlet/config.h.stub new file mode 100644 index 0000000000..bd5601c02e --- /dev/null +++ b/sapi/servlet/config.h.stub @@ -0,0 +1,3 @@ +#ifndef SAPI_SERVLET +#define SAPI_SERVLET 0 +#endif diff --git a/sapi/servlet/config.m4 b/sapi/servlet/config.m4 new file mode 100644 index 0000000000..c3bb31dc13 --- /dev/null +++ b/sapi/servlet/config.m4 @@ -0,0 +1,41 @@ +# $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) diff --git a/sapi/servlet/servlet.c b/sapi/servlet/servlet.c new file mode 100644 index 0000000000..d55d62cd1f --- /dev/null +++ b/sapi/servlet/servlet.c @@ -0,0 +1,384 @@ +/* + +----------------------------------------------------------------------+ + | 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); +} + diff --git a/sapi/servlet/servlet.dsp b/sapi/servlet/servlet.dsp new file mode 100644 index 0000000000..4dca8ce049 --- /dev/null +++ b/sapi/servlet/servlet.dsp @@ -0,0 +1,271 @@ +# Microsoft Developer Studio Project File - Name="servlet" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=servlet - Win32 Debug_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "servlet.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "servlet.mak" CFG="servlet - Win32 Debug_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "servlet - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "servlet - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "servlet - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "servlet - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "servlet - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "..\..\Release"
+# PROP BASE Intermediate_Dir "..\..\Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Release"
+# PROP Intermediate_Dir "..\..\Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
+# 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
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x40d /d "NDEBUG"
+# ADD RSC /l 0x40d /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# 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
+# 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"
+
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "..\..\Debug"
+# PROP BASE Intermediate_Dir "..\..\Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "..\..\Debug"
+# PROP Intermediate_Dir "..\..\Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
+# 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
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x40d /d "_DEBUG"
+# ADD RSC /l 0x40d /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# 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
+# 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"
+
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "..\..\Debug_TS"
+# PROP BASE Intermediate_Dir "..\..\Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "..\..\Debug_TS"
+# PROP Intermediate_Dir "..\..\Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# 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
+# 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
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x40d /d "_DEBUG"
+# ADD RSC /l 0x40d /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# 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
+# 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"
+
+!ELSEIF "$(CFG)" == "servlet - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "..\..\Release_TS"
+# PROP BASE Intermediate_Dir "..\..\Release_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Release_TS"
+# PROP Intermediate_Dir "..\..\Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# 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
+# 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
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x40d /d "NDEBUG"
+# ADD RSC /l 0x40d /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# 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
+# 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"
+
+!ENDIF
+
+# Begin Target
+
+# Name "servlet - Win32 Release"
+# Name "servlet - Win32 Debug"
+# Name "servlet - Win32 Debug_TS"
+# Name "servlet - Win32 Release_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\servlet.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\ext\java\java.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Java Files"
+
+# PROP Default_Filter "java"
+# Begin Source File
+
+SOURCE=.\servlet.java
+
+!IF "$(CFG)" == "servlet - Win32 Release"
+
+# Begin Custom Build
+OutDir=.\..\..\Release
+InputPath=.\servlet.java
+
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ if not exist net mkdir net
+ if not exist net\php mkdir net\php
+ copy $(InputPath) net\php > nul
+ copy ..\..\ext\java\reflect.java net\php > nul
+ echo library=phpsrvlt>net/php/reflect.properties
+ echo library=phpsrvlt>net/php/servlet.properties
+ $(JAVA_HOME)\bin\javac net\php\servlet.java
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
+ erase net\php\servlet.*
+ erase net\php\reflect.*
+ rmdir net\php
+ rmdir net
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug"
+
+# Begin Custom Build
+OutDir=.\..\..\Debug
+InputPath=.\servlet.java
+
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ if not exist net mkdir net
+ if not exist net\php mkdir net\php
+ copy $(InputPath) net\php > nul
+ copy ..\..\ext\java\reflect.java net\php > nul
+ echo library=phpsrvlt>net/php/reflect.properties
+ echo library=phpsrvlt>net/php/servlet.properties
+ $(JAVA_HOME)\bin\javac -g net\php\servlet.java
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
+ erase net\php\servlet.*
+ erase net\php\reflect.*
+ rmdir net\php
+ rmdir net
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "servlet - Win32 Debug_TS"
+
+USERDEP__SERVL=".\servlet.java"
+# Begin Custom Build
+OutDir=.\..\..\Debug_TS
+InputPath=.\servlet.java
+
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ if not exist net mkdir net
+ if not exist net\php mkdir net\php
+ copy *.java net\php > nul
+ copy ..\..\ext\java\reflect.java net\php > nul
+ echo library=phpsrvlt>net/php/reflect.properties
+ echo library=phpsrvlt>net/php/servlet.properties
+ $(JAVA_HOME)\bin\javac -g net\php\servlet.java
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
+ erase net\php\servlet.*
+ erase net\php\reflect.*
+ rmdir net\php
+ rmdir net
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "servlet - Win32 Release_TS"
+
+# Begin Custom Build
+OutDir=.\..\..\Release_TS
+InputPath=.\servlet.java
+
+"$(OutDir)\phpsrvlt.jar" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ if not exist net mkdir net
+ if not exist net\php mkdir net\php
+ copy $(InputPath) net\php > nul
+ copy ..\..\ext\java\reflect.java net\php > nul
+ echo library=phpsrvlt>net/php/reflect.properties
+ echo library=phpsrvlt>net/php/servlet.properties
+ $(JAVA_HOME)\bin\javac net\php\servlet.java
+ $(JAVA_HOME)\bin\jar c0f $(OutDir)\phpsrvlt.jar net\php\*.class net\php\*.properties
+ erase net\php\servlet.*
+ erase net\php\reflect.*
+ rmdir net\php
+ rmdir net
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\servlet.java
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\jtest.php
+# End Source File
+# End Target
+# End Project
diff --git a/sapi/servlet/servlet.java b/sapi/servlet/servlet.java new file mode 100644 index 0000000000..62be4f1d2c --- /dev/null +++ b/sapi/servlet/servlet.java @@ -0,0 +1,138 @@ +/* + +----------------------------------------------------------------------+ + | 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; + } +} diff --git a/sapi/servlet/web.xml b/sapi/servlet/web.xml new file mode 100644 index 0000000000..b6113aa332 --- /dev/null +++ b/sapi/servlet/web.xml @@ -0,0 +1,24 @@ +<?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> |
