diff options
author | Stig Bakken <ssb@php.net> | 1999-09-27 16:34:28 +0000 |
---|---|---|
committer | Stig Bakken <ssb@php.net> | 1999-09-27 16:34:28 +0000 |
commit | 2a854ca8b9e94ea75e949edb1283157b0daad617 (patch) | |
tree | 6eafc28bd9403f91354068a364254bde5d9afc7a | |
parent | 154663e9a2ee5310172886384a7c2a8598f66bc8 (diff) | |
download | php-git-2a854ca8b9e94ea75e949edb1283157b0daad617.tar.gz |
Generalized server-API build process on UNIX. Each SAPI
implementation now has its own directory under sapi/, just like
extensions have theirs under ext/. To make the final targets appear
in the main dir, the top-level Makefile includes sapi/NN/Makefile.inc
from the selected sapi backend. This is a plan Makefile stub without
any autoconf substitutions. Each SAPI backend also has its own
config.m4 like extensions (read at the end of diversion 2) and
config.h.stub files.
Each SAPI backend has to contain:
config.m4: just like for extensions, this file contains
autoconf/automake directives that end up in the configure script. The
only difference is that the sapi config.m4 files are read in diversion
(output block) 2 instead of 3. The sapi config.m4 files should set
two variables: PHP_SAPI (which sapi backend to choose) and SAPI_TARGET
(the name of the resulting library or program, previously BINNAME).
If they are not specified, they will default to "cgi" and "php",
respectively.
Makefile.inc: has to exist, has to define "INSTALL_IT" to the command
used to install the final target (or ":" for no operation). It also
has to define a plain Makefile rule (without autoconf substitutions)
to build $(SAPI_TARGET)
Makefile.am: just what you think. Make sure your target is called
"libphpsapi_NNN.a", where NNN is the value of PHP_SAPI.
Some testing and fixing probably remains. To make everything hang
together, I've done some ugly tricks that I can imagine causing some
problems. I've built and run the CGI version and built the Apache
DSO.
35 files changed, 1472 insertions, 435 deletions
@@ -2,6 +2,7 @@ PHP 4.0 CHANGE LOG ChangeLog ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ?? 1999, Version 4.0 Beta 3 +- Generalized server-API build procedure on UNIX (Stig) - Added '--disable-rpath' option (Sascha) - Added AOLserver SAPI module (Sascha) - Fixed XML Callbacks. (Thies) diff --git a/Makefile.in b/Makefile.in index 4996baa3ec..992bf7ad3f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -37,14 +37,15 @@ top_builddir = . ZEND_DIR = $(srcdir)/libzend TSRM_DIR = @TSRM_DIR@ -SUBDIRS=libzend ext $(TSRM_DIR) +SUBDIRS=libzend ext $(TSRM_DIR) sapi PACKAGE = @PACKAGE@ VERSION = @VERSION@ LN_S = @LN_S@ CC = @CC@ AR = ar rc -BINNAME = @BINNAME@ +PHP_SAPI = @PHP_SAPI@ +SAPI_TARGET = @SAPI_TARGET@ INSTALL_IT = @INSTALL_IT@ EXTRA_LIBS = @EXTRA_LIBS@ EXT_LIBS = @EXT_LIBS@ @@ -56,9 +57,11 @@ LDFLAGS_SHLIB = @LDFLAGS_SHLIB@ LDFLAGS_SHLIB_EXPORT = @LDFLAGS_SHLIB_EXPORT@ CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ +VERSION_SCRIPT = @VERSION_SCRIPT@ +RPATHS = @RPATHS@ CFLAGS = @CFLAGS@ @DEBUG_CFLAGS@ $(PROF_CFLAGS) COMPILE = $(CC) $(CFLAGS) $(CFLAGS_SHLIB) $(CPPFLAGS) $(INCLUDE) $(DEFS) @STRONGHOLD@ -LDFLAGS = @VERSION_SCRIPT@ @RPATHS@ @LDFLAGS@ $(LDFLAGS_SHLIB) $(LDFLAGS_SHLIB_EXPORT) -L$(ZEND_DIR) +LDFLAGS = $(VERSION_SCRIPT) $(RPATHS) @LDFLAGS@ $(LDFLAGS_SHLIB) $(LDFLAGS_SHLIB_EXPORT) -L$(ZEND_DIR) REGCFLAGS = $(CFLAGS) RANLIB = @RANLIB@ YACC = @YACC@ @@ -70,18 +73,20 @@ WARNING_LEVEL = @WARNING_LEVEL@ LEX_CFLAGS = -w$(WARNING_LEVEL) @LEX_CFLAGS@ EXT_SHARED = @EXT_SHARED@ LIBOBJS=@LIBOBJS@ +REGEX_LIB=@REGEX_LIB@ +FHTTPD_LIB=@FHTTPD_LIB@ +TSRM_LIB=@TSRM_LIB@ SOURCE = main.c internal_functions.c snprintf.c php3_sprintf.c \ configuration-parser.c configuration-scanner.c request_info.c \ safe_mode.c fopen-wrappers.c php3_realpath.c alloca.c output.c \ - php_ini.c SAPI.c cgi_main.c rfc1867.c dlist.c php_content_types.c \ - aolserver.c + php_ini.c SAPI.c rfc1867.c dlist.c php_content_types.c OBJS = $(SOURCE:.c=.o) $(LIBOBJS) PHPLIBS = -Llibzend -lzend -Lext -lphpext LIBS = $(PHPLIBS) $(EXTRA_LIBS) @LIBS@ -all: $(BINNAME) +all: $(SAPI_TARGET) all-recursive clean-recursive distclean-recursive \ maintainer-clean-depend-recursive: @@ -92,33 +97,8 @@ maintainer-clean-depend-recursive: (cd $$subdir && $(MAKE) $$target) || fail=yes; \ done && test -z "$$fail" -# CGI binary or fhttpd module -php: all-recursive $(OBJS) @REGEX_LIB@ @FHTTPD_LIB@ - $(CC) $(CFLAGS) -o $(BINNAME) $(LDFLAGS) $(OBJS) $(LIBS) - -# Apache modules -libphp4.a libmodphp4.a: all-recursive $(OBJS) @REGEX_LIB@ - $(AR) $@.tmp $(OBJS) - $(srcdir)/scripts/armerge $@ $@.tmp ext/libphpext.a libzend/libzend.a @TSRM_LIB@ - @rm -f $@.tmp - $(RANLIB) $(BINNAME) - -# Apache modules -libmodphp4-so.a: all-recursive $(OBJS) @REGEX_LIB@ - $(AR) $@.tmp $(OBJS) - $(srcdir)/scripts/armerge $@ $@.tmp ext/libphpext.a libzend/libzend.a @TSRM_LIB@ - @rm -f $@.tmp - $(RANLIB) libmodphp4-so.a - -# Apache 1.3 shared module -libphp4.so: $(srcdir)/mod_php4.c libmodphp4-so.a @REGEX_LIB@ - -@test -f ./mod_php4.c || test -L ./mod_php4.c || $(LN_S) $(srcdir)/mod_php4.c ./mod_php4.c - -@test -f ./mod_php4.c || test -h ./mod_php4.c || $(LN_S) $(srcdir)/mod_php4.c ./mod_php4.c - $(APXS) $(INCLUDE) -c -o libphp4.so @VERSION_SCRIPT@ @RPATHS@ ./mod_php4.c libmodphp4-so.a $(APXS_LDFLAGS) $(APXS_EXP) - -php4_aol.so: libmodphp4-so.a - g++ $(LDFLAGS) -shared aolserver.o -o $@ libmodphp4-so.a $(LIBS) - +include sapi/$(PHP_SAPI)/Makefile.inc + regex/libregex.a: (cd regex; $(MAKE) lib) @@ -179,12 +159,12 @@ distdir: maintainer-clean-depend: maintainer-clean-depend-recursive -bench: $(BINNAME) - ./$(BINNAME) -c. tests/bench.phtml +bench: php + ./php -c. tests/bench.phtml # can't use a single rule for this because 'test' is a directory test: regression -regression check: $(BINNAME) +regression check: php cd test && ./testall config.status: configure @@ -208,7 +188,7 @@ php_config.h.in: @MAINT@ stamp-h.in stamp-h.in: configure.in aclocal.m4 acconfig.h cd ${srcdir} && autoheader && touch ${srcdir}/stamp-h.in -install: install-recursive $(BINNAME) +install: install-recursive $(SAPI_TARGET) $(INSTALL_IT) install-recursive: diff --git a/configure.in.in b/configure.in.in index 82e30ae889..3dd1708059 100644 --- a/configure.in.in +++ b/configure.in.in @@ -1,18 +1,9 @@ -dnl $Id$ -*- sh -*- -dnl Process this file with autoconf to produce a configure script. +dnl ## $Id$ -*- sh -*- +dnl ## Process this file with autoconf to produce a configure script. divert(0) + AC_INIT(main.c) -recurse=yes -for arg in $@; do - case $arg in - ## This is to prevent "./config.status --recheck" from - ## running configure in libzend again. - --no-recursion) recurse=no;; - --enable-thread-safety) threadsafe=yes;; - *) ;; - esac -done if test "$with_shared_apache" != "no" && test -n "$with_shared_apache" ; then echo "" @@ -21,13 +12,12 @@ if test "$with_shared_apache" != "no" && test -n "$with_shared_apache" ; then exit 1 fi -cwd=`pwd` -cachefile=$cwd/config.cache - -if test "$recurse" = "yes"; then - (set -x; test -d libzend || mkdir libzend ; cd libzend; $cwd/$srcdir/libzend/configure --cache-file=$cachefile $@) || exit 1 - if test "$threadsafe" = "yes"; then - (set -x; test -d TSRM || mkdir TSRM; cd TSRM; $cwd/$srcdir/TSRM/configure --cache-file=$cachefile $@) || exit 1 +if test "$no_recursion" != "yes"; then + cwd=`pwd` + cachefile=$cwd/config.cache + (set -x; cd libzend; $cwd/$srcdir/libzend/configure --cache-file=$cachefile $@) || exit 1 + if test "$enable_thread_safety" = "yes"; then + (set -x; cd TSRM && $cwd/$srcdir/TSRM/configure --cache-file=$cachefile $@) || exit 1 fi (set -x; cd $srcdir; sh ltconfig --disable-static --enable-dlopen --cache-file=$cachefile ltmain.sh) fi @@ -124,11 +114,6 @@ if test "$ac_cv_prog_gcc" = "yes" -a "`uname -s`" = "Rhapsody"; then CPPFLAGS="$CPPFLAGS -traditional-cpp" fi -if test "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then - APXS_EXP="-bE:mod_php4.exp" -fi -AC_SUBST(APXS_EXP) - dnl Ugly hack to get around a problem with gcc on AIX. if test "$CC" = "gcc" -a "$ac_cv_prog_cc_g" = "yes" -a \ "`uname -sv`" = "AIX 4"; then @@ -426,44 +411,6 @@ abs_builddir=`pwd` AC_SUBST(abs_srcdir) AC_SUBST(abs_builddir) -AC_MSG_CHECKING(for Apache module support via DSO through APXS) -AC_ARG_WITH(apxs, -[ --with-apxs[=FILE] Build shared Apache module. FILE is the optional - pathname to the Apache apxs tool; defaults to "apxs". - (This option needs Perl installed)], -[ - if test "$withval" = "yes"; then - withval=apxs - fi - AC_EXPAND_PATH($withval, APXS) - APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@" - APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` - if test -d "$APXS_INCLUDEDIR/xml" ; then - XML_INCLUDE="$APXS_INCLUDEDIR/xml" - fi - APACHE_INCLUDE="-I$APXS_INCLUDEDIR" - BINNAME=libphp4.so - INSTALL_IT="\$(APXS) -i -a -n php4 $BINNAME" - CFLAGS_SHLIB=`perl -V:cccdlflags | cut -d\' -f2` - LDFLAGS_SHLIB=`perl -V:lddlflags | cut -d\' -f2` - LDFLAGS_SHLIB_EXPORT=`perl -V:ccdlflags | cut -d\' -f2` - PHP_LIBS= - STRONGHOLD= - INCLUDES="$INCLUDES $APACHE_INCLUDE" - AC_DEFINE(APACHE) - AC_SUBST(APXS) - AC_SUBST(APXS_LDFLAGS) - AC_SUBST(BINNAME) - AC_SUBST(INSTALL_IT) - AC_SUBST(PHP_LIBS) - AC_SUBST(APACHE_INCLUDE) - AC_DEFINE(HAVE_AP_CONFIG_H) - AC_DEFINE(HAVE_AP_COMPAT_H) - AC_MSG_RESULT(yes) -],[ - AC_MSG_RESULT(no) -]) - versioning="no" AC_MSG_CHECKING(whether to enable versioning) AC_ARG_ENABLE(versioning, @@ -489,160 +436,6 @@ AC_ARG_ENABLE(versioning, AC_MSG_RESULT($versioning) AC_SUBST(VERSION_SCRIPT) - -APACHE_INSTALL_FILES="$srcdir/mod_php4.* libphp4.module" - -if test "$BINNAME" != "libmodphp4-so.a"; then -if test "$BINNAME" != "libphp4.so"; then -AC_MSG_CHECKING(for Apache module support) -AC_ARG_WITH(apache, -[ --with-apache[=DIR] Build Apache module. DIR is the top-level Apache - build directory, defaults to /usr/local/etc/httpd.], -[ - if test "$withval" = "yes"; then - # Apache's default directory - withval=/usr/local/etc/httpd - fi - if test "$withval" != "no"; then -# For Apache 1.2.x - AC_EXPAND_PATH($withval, withval) - if test -f $withval/src/httpd.h; then - APACHE_INCLUDE=-I$withval/src - APACHE_TARGET=$withval/src - BINNAME=libphp4.a - INSTALL_IT="mkdir -p $APACHE_TARGET; cp $BINNAME $APACHE_INSTALL_FILES $APACHE_TARGET" - PHP_LIBS="-L. -lphp3" - AC_DEFINE(APACHE) - AC_MSG_RESULT(yes - Apache 1.2.x) - STRONGHOLD= - if test -f $withval/src/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H) - fi -# For Apache 1.3.x - elif test -f $withval/src/main/httpd.h; then - APACHE_INCLUDE="-I$withval/src/main -I$withval/src/os/unix -I$withval/src/ap" - APACHE_TARGET=$withval/src/modules/php4 - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - BINNAME=libmodphp4.a - INSTALL_IT="mkdir -p $APACHE_TARGET; cp $BINNAME $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4" - AC_DEFINE(APACHE) - AC_MSG_RESULT(yes - Apache 1.3.x) - STRONGHOLD= - if test -f $withval/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H) - fi - if test -f $withval/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H) - if test ! -f $withval/src/include/ap_config_auto.h; then - AC_MSG_ERROR(Please run Apache's configure or src/Configure program once and try again) - fi - else - if test -f $withval/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H) - fi - fi -# Also for Apache 1.3.x - elif test -f $withval/src/include/httpd.h; then - APACHE_INCLUDE="-I$withval/src/include -I$withval/src/os/unix" - APACHE_TARGET=$withval/src/modules/php4 - if test -d $withval/src/lib/expat-lite ; then - XML_INCLUDE=$withval/src/lib/expat-lite - fi - if test ! -d $APACHE_TARGET; then - mkdir $APACHE_TARGET - fi - BINNAME=libmodphp4.a - PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4" - INSTALL_IT="mkdir -p $APACHE_TARGET; cp $BINNAME $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" - AC_DEFINE(APACHE) - AC_MSG_RESULT(yes - Apache 1.3.x) - STRONGHOLD= - if test -f $withval/src/include/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H) - fi - if test -f $withval/src/include/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H) - if test ! -f $withval/src/include/ap_config_auto.h; then - AC_MSG_ERROR(Please run Apache's configure or src/Configure program once and try again) - fi - else - if test -f $withval/src/include/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H) - fi - fi -# For StrongHold 2.2 - elif test -f $withval/apache/httpd.h; then - APACHE_INCLUDE=-"I$withval/apache -I$withval/ssl/include" - APACHE_TARGET=$withval/apache - BINNAME=libmodphp4.a - PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4" - INSTALL_IT="mkdir -p $APACHE_TARGET; cp $BINNAME $APACHE_INSTALL_FILES $APACHE_TARGET" - STRONGHOLD=-DSTRONGHOLD=1 - AC_DEFINE(APACHE) - AC_MSG_RESULT(yes - StrongHold) - if test -f $withval/apache/ap_config.h; then - AC_DEFINE(HAVE_AP_CONFIG_H) - fi - if test -f $withval/src/ap_compat.h; then - AC_DEFINE(HAVE_AP_COMPAT_H) - if test ! -f $withval/src/include/ap_config_auto.h; then - AC_MSG_ERROR(Please run Apache's configure or src/Configure program once and try again) - fi - else - if test -f $withval/src/compat.h; then - AC_DEFINE(HAVE_OLD_COMPAT_H) - fi - fi - else - AC_MSG_RESULT(no) - AC_MSG_ERROR(Invalid Apache directory - unable to find httpd.h under $withval) - fi - else - AC_MSG_RESULT(no) - BINNAME=php - fi -],[ - AC_MSG_RESULT(no) - BINNAME=php -]) - -if test "$BINNAME" = "php" ; then - INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $BINNAME \$(bindir)/$BINNAME" -fi - -INCLUDES="$INCLUDES $APACHE_INCLUDE" -dnl## AC_SUBST(APACHE_INCLUDE) -AC_SUBST(APACHE_TARGET) -AC_SUBST(INSTALL_IT) -AC_SUBST(BINNAME) -AC_SUBST(STRONGHOLD) -AC_SUBST(PHP_LIBS) -fi -fi - -RESULT=no -AC_MSG_CHECKING(for AOLserver support) -AC_ARG_WITH(aolserver, -[ --with-aolserver=DIR], -[ - if test ! -d $withval ; then - AC_MSG_ERROR(You did not specify a directory) - fi - if test "$enable_thread_safety" != "yes"; then - AC_MSG_ERROR(AOLserver must be compiled using --enable-thread-safety) - fi - NS_DIR=$withval - AC_ADD_INCLUDE($NS_DIR/include) - AC_DEFINE(HAVE_AOLSERVER) - BINNAME=php4_aol.so - INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $BINNAME $NS_DIR/root/bin/$BINNAME" - RESULT=yes -]) -AC_MSG_RESULT($RESULT) - AC_MSG_CHECKING(whether to use bundled regex library) AC_ARG_WITH(system-regex, [ --with-system-regex Do not use the bundled regex library], @@ -686,49 +479,6 @@ fi AC_SUBST(REGEX_LIB) AC_SUBST(HSREGEX) -AC_MSG_CHECKING(for mod_charset compatibility option) -AC_ARG_WITH(mod_charset, -[ --with-mod_charset Enable transfer tables for mod_charset (Rus Apache).], -[ - AC_MSG_RESULT(yes) - AC_DEFINE(USE_TRANSFER_TABLES) -],[ - AC_MSG_RESULT(no) -]) - -AC_MSG_CHECKING(for fhttpd module support) -AC_ARG_WITH(fhttpd, -[ --with-fhttpd[=DIR] Build fhttpd module. DIR is the fhttpd sources - directory, defaults to /usr/local/src/fhttpd.], -[ - if test "$withval" = "yes"; then - # fhttpd source directory - withval=/usr/local/src/fhttpd - fi - if test "$withval" != "no"; then -# For fhttpd 0.3.x - if test -f $withval/servproc.h; then - FHTTPD_INCLUDE=-I$withval/ - FHTTPD_LIB=$withval/servproc.o - FHTTPD_TARGET=$withval/ - BINNAME=php - AC_DEFINE(FHTTPD) - AC_MSG_RESULT(yes - fhttpd 0.3.x) - else - AC_MSG_RESULT(no) - AC_MSG_ERROR(Invalid fhttpd directory - unable to find servproc.h under $withval) - fi - else - AC_MSG_RESULT(no) - fi -],[ - AC_MSG_RESULT(no) -]) -INCLUDES="$INCLUDES $FHTTPD_INCLUDE" -dnl## AC_SUBST(FHTTPD_INCLUDE) -AC_SUBST(FHTTPD_LIB) -AC_SUBST(FHTTPD_TARGET) - AC_MSG_CHECKING(whether to use a configuration file) AC_ARG_WITH(config-file-path, @@ -889,68 +639,6 @@ AC_ARG_ENABLE(rpath, ]) AC_MSG_RESULT($enable_rpath) -dnl AC_MSG_CHECKING(whether to enable PHP RPC support) -dnl AC_ARG_ENABLE(php-rpc, -dnl [ --enable-php-rpc Compile with PHP RPC support.], -dnl [ -dnl if test "$enableval" = "yes"; then -dnl AC_DEFINE(PHP_RPC, 1) -dnl AC_MSG_RESULT(yes) -dnl else -dnl AC_DEFINE(PHP_RPC, 0) -dnl AC_MSG_RESULT(no) -dnl fi -dnl ],[ -dnl AC_DEFINE(PHP_RPC, 0) -dnl AC_MSG_RESULT(no) -dnl ]) - -if test "$BINNAME" = "php"; then -AC_MSG_CHECKING(whether to force Apache CGI redirect) -AC_ARG_ENABLE(force-cgi-redirect, -[ --enable-force-cgi-redirect - Enable the security check for internal server - redirects. You should use this if you are - running the CGI version with Apache. ], -[ - if test "$enableval" = "yes"; then - AC_DEFINE(FORCE_CGI_REDIRECT, 1) - AC_MSG_RESULT(yes) - REDIRECT=1 - else - AC_DEFINE(FORCE_CGI_REDIRECT, 0) - AC_MSG_RESULT(no) - REDIRECT=0 - fi -],[ - AC_DEFINE(FORCE_CGI_REDIRECT, 0) - AC_MSG_RESULT(no) - REDIRECT=0 -]) - -AC_MSG_CHECKING(whether to discard path_info + path_translated) -AC_ARG_ENABLE(discard_path, -[ --enable-discard-path If this is enabled, the PHP CGI binary - can safely be placed outside of the - web tree and people will not be able - to circumvent .htaccess security. ], -[ - if test "$enableval" = "yes"; then - AC_DEFINE(DISCARD_PATH, 1) - AC_MSG_RESULT(yes) - DISCARD_PATH=1 - else - AC_DEFINE(DISCARD_PATH, 0) - AC_MSG_RESULT(no) - DISCARD_PATH=0 - fi -],[ - AC_DEFINE(DISCARD_PATH, 0) - AC_MSG_RESULT(no) - DISCARD_PATH=0 -]) -fi - AC_MSG_CHECKING(whether to enable short tags by default) AC_ARG_ENABLE(short-tags, [ --disable-short-tags Disable the short-form <? start tag by default.], @@ -999,16 +687,22 @@ AC_ARG_ENABLE(dmalloc, ]) AC_MSG_RESULT($DMALLOC_RESULT) +dnl ## This is the default server API. +PHP_SAPI=cgi +SAPI_TARGET=php + +esyscmd(./scripts/config-stubs sapi) + divert(3) AC_SUBST(EXTRA_LIBS) # reading config stubs -esyscmd(./scripts/config-stubs) +esyscmd(./scripts/config-stubs ext) divert(4) -dnl If we're using gcc and the user hasn't specified CFLAGS, add -O2. +dnl If we are using gcc and the user has not specified CFLAGS, add -O2. test -n "$auto_cflags" && test -n "$GCC" && CFLAGS="$CFLAGS -O2" dnl *** Commented out - generates slow code and consumes a lot of @@ -1037,6 +731,10 @@ AC_DEFINE_UNQUOTED(PHP_UNAME,"$PHP_UNAME") PHP_OS=`uname` AC_DEFINE_UNQUOTED(PHP_OS,"$PHP_OS") +AC_SUBST(PHP_LIBS) +AC_SUBST(PHP_SAPI) +AC_SUBST(SAPI_TARGET) + AC_OUTPUT(Makefile libphp4.module php4.spec scripts/mkextlib regex/Makefile @@EXT_MAKEFILES@@ build-defs.h, [ @@ -1066,7 +764,7 @@ if test "" = ""; then fi # Warn about CGI version with no extra security options. - if test "$BINNAME" = "php"; then + if test "$SAPI_TARGET" = "php"; then if test "$REDIRECT" = "0"; then if test "$DISCARD_PATH" = "0"; then echo "+--------------------------------------------------------------------+" diff --git a/ext/apache/apache.c b/ext/apache/apache.c index da439f58ed..8c8d50a82c 100644 --- a/ext/apache/apache.c +++ b/ext/apache/apache.c @@ -24,7 +24,7 @@ #include "php_globals.h" #include "php_ini.h" #include "SAPI.h" -#include "mod_php4.h" +#include "sapi/apache/mod_php4.h" #include "ext/standard/info.h" #include <stdlib.h> @@ -1,27 +1,16 @@ /* +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | + | PHP version 4.0 | +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + | Copyright (c) 1997, 1998, 1999 The PHP Group | +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program is distributed in the hope that it will be useful, | - | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | GNU General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | + | 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. | +----------------------------------------------------------------------+ | Authors: | | | diff --git a/main/main.c b/main/main.c index ca5ea920a5..b92b4acb0a 100644 --- a/main/main.c +++ b/main/main.c @@ -1172,53 +1172,6 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_ } } - - -/* some systems are missing these from their header files */ - -#if APACHE -PHPAPI int apache_php_module_main(request_rec *r, int fd, int display_source_mode SLS_DC) -{ - zend_file_handle file_handle; -#ifdef ZTS - zend_compiler_globals cg; - zend_executor_globals eg; - php_core_globals pcg; - zend_compiler_globals *compiler_globals=&cg; - zend_executor_globals *executor_globals=⪚ - php_core_globals *core_globals=&pcg; -#endif - SLS_FETCH(); - - if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC) == FAILURE) { - return FAILURE; - } - file_handle.type = ZEND_HANDLE_FD; - file_handle.handle.fd = fd; - file_handle.filename = SG(request_info).path_translated; - - if (display_source_mode) { - zend_syntax_highlighter_ini syntax_highlighter_ini; - - if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) { - php_get_highlight_struct(&syntax_highlighter_ini); - zend_highlight(&syntax_highlighter_ini); - fclose(file_handle.handle.fp); - return OK; - } else { - return NOT_FOUND; - } - } else { - (void) php_execute_script(&file_handle CLS_CC ELS_CC); - } - - php3_header(); /* Make sure headers have been sent */ - php_end_ob_buffering(1); - return (OK); -} -#endif /* APACHE */ - - #if WIN32||WINNT /* just so that this symbol gets exported... */ PHPAPI void dummy_indent() diff --git a/sapi/Makefile.am b/sapi/Makefile.am new file mode 100644 index 0000000000..bc9794a370 --- /dev/null +++ b/sapi/Makefile.am @@ -0,0 +1,14 @@ +## Process this file with automake to produce Makefile.in + +PHP_SAPI=@PHP_SAPI@ +PHP_SAPI_LIB=$(PHP_SAPI)/libphpsapi_$(PHP_SAPI).a +SUBDIRS = $(PHP_SAPI) + +noinst_LIBRARIES=libphpsapi.a + +libphpsapi.a: $(PHP_SAPI_LIB) + cp $(PHP_SAPI_LIB) $@ + @test "`uname -s`" = "Rhapsody" && $(RANLIB) $@ || exit 0 + +$(PHP_SAPI_LIB): + (cd $(PHP_SAPI); $(MAKE) libphpsapi_$(PHP_SAPI).a) diff --git a/sapi/aolserver/Makefile.am b/sapi/aolserver/Makefile.am new file mode 100644 index 0000000000..4a8edf6074 --- /dev/null +++ b/sapi/aolserver/Makefile.am @@ -0,0 +1,5 @@ +## Process this file with automake to produce Makefile.in + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpsapi_nsapi.a +libphpsapi_nsapi_a_SOURCES=aolserver.c diff --git a/sapi/aolserver/Makefile.inc b/sapi/aolserver/Makefile.inc new file mode 100644 index 0000000000..6c56958bc8 --- /dev/null +++ b/sapi/aolserver/Makefile.inc @@ -0,0 +1,6 @@ +# NSAPI/AOLserver module + +INSTALL_IT=: + +php4_nsapi.so: libmodphp4-so.a + g++ $(LDFLAGS) -shared sapi/nsapi/aolserver.o -o $@ libmodphp4-so.a $(LIBS) diff --git a/aolserver.c b/sapi/aolserver/aolserver.c index cbc4ec0257..cbc4ec0257 100644 --- a/aolserver.c +++ b/sapi/aolserver/aolserver.c diff --git a/sapi/aolserver/config.m4 b/sapi/aolserver/config.m4 new file mode 100644 index 0000000000..854785df04 --- /dev/null +++ b/sapi/aolserver/config.m4 @@ -0,0 +1,26 @@ +dnl ## $Id$ -*- sh -*- + +RESULT=no +AC_MSG_CHECKING(for AOLserver support) +AC_ARG_WITH(aolserver, +[ --with-aolserver=DIR], +[ + if test ! -d $withval ; then + AC_MSG_ERROR(You did not specify a directory) + fi + if test "$enable_thread_safety" != "yes"; then + AC_MSG_ERROR(AOLserver must be compiled using --enable-thread-safety) + fi + NS_DIR=$withval + AC_ADD_INCLUDE($NS_DIR/include) + AC_DEFINE(HAVE_AOLSERVER) + PHP_SAPI=nsapi + SAPI_TARGET=php4_nsapi.so + INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_TARGET $NS_DIR/root/bin/$SAPI_TARGET" + RESULT=yes +]) +AC_MSG_RESULT($RESULT) + +dnl ## Local Variables: +dnl ## tab-width: 4 +dnl ## End: diff --git a/sapi/apache/Makefile.am b/sapi/apache/Makefile.am new file mode 100644 index 0000000000..8661c36f80 --- /dev/null +++ b/sapi/apache/Makefile.am @@ -0,0 +1,6 @@ +## Process this file with automake to produce Makefile.in + +APACHE_INCLUDE=@APACHE_INCLUDE@ +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend $(APACHE_INCLUDE) +noinst_LIBRARIES=libphpsapi_apache.a +libphpsapi_apache_a_SOURCES=mod_php4.c diff --git a/sapi/apache/Makefile.inc b/sapi/apache/Makefile.inc new file mode 100644 index 0000000000..8b62c74c35 --- /dev/null +++ b/sapi/apache/Makefile.inc @@ -0,0 +1,23 @@ +# -*- makefile -*- + +INSTALL_IT=$(APACHE_INSTALL) + +# Apache modules +libphp4.a libmodphp4.a: all-recursive $(OBJS) sapi/libphpsapi.a $(REGEX_LIB) + $(AR) $@.tmp $(OBJS) + $(srcdir)/scripts/armerge $@ $@.tmp \ + ext/libphpext.a libzend/libzend.a sapi/libphpsapi.a $(TSRM_LIB) + @rm -f $@.tmp + $(RANLIB) $(SAPI_TARGET) + +# Apache modules +libmodphp4-so.a: all-recursive $(OBJS) sapi/libphpsapi.a $(REGEX_LIB) + $(AR) $@.tmp $(OBJS) + $(srcdir)/scripts/armerge $@ $@.tmp \ + ext/libphpext.a libzend/libzend.a sapi/libphpsapi.a $(TSRM_LIB) + @rm -f $@.tmp + $(RANLIB) libmodphp4-so.a + +# Apache 1.3 shared module +libphp4.so: libmodphp4-so.a $(REGEX_LIB) + $(APXS) $(INCLUDE) -c -o libphp4.so $(VERSION_SCRIPT) $(RPATHS) sapi/apache/mod_php4.c libmodphp4-so.a $(APXS_LDFLAGS) $(APXS_EXP) diff --git a/sapi/apache/config.h.stub b/sapi/apache/config.h.stub new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/sapi/apache/config.h.stub diff --git a/sapi/apache/config.m4 b/sapi/apache/config.m4 new file mode 100644 index 0000000000..b1bd590ed2 --- /dev/null +++ b/sapi/apache/config.m4 @@ -0,0 +1,190 @@ +dnl ## -*- sh -*- + +divert(1) + +if test "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then + APXS_EXP="-bE:sapi/apache/mod_php4.exp" +fi +AC_SUBST(APXS_EXP) + +divert(2) + +AC_MSG_CHECKING(for Apache module support via DSO through APXS) +AC_ARG_WITH(apxs, +[ --with-apxs[=FILE] Build shared Apache module. FILE is the optional + pathname to the Apache apxs tool; defaults to "apxs". + (This option needs Perl installed)], +[ + if test "$withval" = "yes"; then + withval=apxs + fi + AC_EXPAND_PATH($withval, APXS) + APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@" + APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` + if test -d "$APXS_INCLUDEDIR/xml" ; then + XML_INCLUDE="$APXS_INCLUDEDIR/xml" + fi + APACHE_INCLUDE="-I$APXS_INCLUDEDIR" + PHP_SAPI=apache + SAPI_TARGET=libphp4.so + APACHE_INSTALL="\$(APXS) -i -a -n php4 $SAPI_TARGET" + CFLAGS_SHLIB=`perl -V:cccdlflags | cut -d\' -f2` + LDFLAGS_SHLIB=`perl -V:lddlflags | cut -d\' -f2` + LDFLAGS_SHLIB_EXPORT=`perl -V:ccdlflags | cut -d\' -f2` + PHP_LIBS= + STRONGHOLD= + INCLUDES="$INCLUDES $APACHE_INCLUDE" + AC_DEFINE(APACHE) + AC_DEFINE(HAVE_AP_CONFIG_H) + AC_DEFINE(HAVE_AP_COMPAT_H) + AC_MSG_RESULT(yes) +],[ + AC_MSG_RESULT(no) +]) + +APACHE_INSTALL_FILES="$srcdir/mod_php4.* libphp4.module" + +if test "$SAPI_TARGET" != "libmodphp4-so.a"; then +if test "$SAPI_TARGET" != "libphp4.so"; then +AC_MSG_CHECKING(for Apache module support) +AC_ARG_WITH(apache, +[ --with-apache[=DIR] Build Apache module. DIR is the top-level Apache + build directory, defaults to /usr/local/etc/httpd.], +[ + if test "$withval" = "yes"; then + # Apache's default directory + withval=/usr/local/apache + fi + if test "$withval" != "no"; then + AC_EXPAND_PATH($withval, withval) + # For Apache 1.2.x + if test -f $withval/src/httpd.h; then + APACHE_INCLUDE=-I$withval/src + APACHE_TARGET=$withval/src + PHP_SAPI=apache + SAPI_TARGET=libphp4.a + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_TARGET $APACHE_INSTALL_FILES $APACHE_TARGET" + PHP_LIBS="-L. -lphp3" + AC_DEFINE(APACHE) + AC_MSG_RESULT(yes - Apache 1.2.x) + STRONGHOLD= + if test -f $withval/src/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H) + fi + # For Apache 1.3.x + elif test -f $withval/src/main/httpd.h; then + APACHE_INCLUDE="-I$withval/src/main -I$withval/src/os/unix -I$withval/src/ap" + APACHE_TARGET=$withval/src/modules/php4 + if test ! -d $APACHE_TARGET; then + mkdir $APACHE_TARGET + fi + PHP_SAPI=apache + SAPI_TARGET=libmodphp4.a + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_TARGET $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" + PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4" + AC_DEFINE(APACHE) + AC_MSG_RESULT(yes - Apache 1.3.x) + STRONGHOLD= + if test -f $withval/src/include/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H) + fi + if test -f $withval/src/include/ap_compat.h; then + AC_DEFINE(HAVE_AP_COMPAT_H) + if test ! -f $withval/src/include/ap_config_auto.h; then + AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again) + fi + else + if test -f $withval/src/include/compat.h; then + AC_DEFINE(HAVE_OLD_COMPAT_H) + fi + fi + # Also for Apache 1.3.x + elif test -f $withval/src/include/httpd.h; then + APACHE_INCLUDE="-I$withval/src/include -I$withval/src/os/unix" + APACHE_TARGET=$withval/src/modules/php4 + if test -d $withval/src/lib/expat-lite ; then + XML_INCLUDE=$withval/src/lib/expat-lite + fi + if test ! -d $APACHE_TARGET; then + mkdir $APACHE_TARGET + fi + PHP_SAPI=apache + SAPI_TARGET=libmodphp4.a + PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4" + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_TARGET $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" + AC_DEFINE(APACHE) + AC_MSG_RESULT(yes - Apache 1.3.x) + STRONGHOLD= + if test -f $withval/src/include/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H) + fi + if test -f $withval/src/include/ap_compat.h; then + AC_DEFINE(HAVE_AP_COMPAT_H) + if test ! -f $withval/src/include/ap_config_auto.h; then + AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again) + fi + else + if test -f $withval/src/include/compat.h; then + AC_DEFINE(HAVE_OLD_COMPAT_H) + fi + fi + # For StrongHold 2.2 + elif test -f $withval/apache/httpd.h; then + APACHE_INCLUDE=-"I$withval/apache -I$withval/ssl/include" + APACHE_TARGET=$withval/apache + PHP_SAPI=apache + SAPI_TARGET=libmodphp4.a + PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4" + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_TARGET $APACHE_INSTALL_FILES $APACHE_TARGET" + STRONGHOLD=-DSTRONGHOLD=1 + AC_DEFINE(APACHE) + AC_MSG_RESULT(yes - StrongHold) + if test -f $withval/apache/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H) + fi + if test -f $withval/src/ap_compat.h; then + AC_DEFINE(HAVE_AP_COMPAT_H) + if test ! -f $withval/src/include/ap_config_auto.h; then + AC_MSG_ERROR(Please run Apache\'s configure or src/Configure program once and try again) + fi + else + if test -f $withval/src/compat.h; then + AC_DEFINE(HAVE_OLD_COMPAT_H) + fi + fi + else + AC_MSG_RESULT(no) + AC_MSG_ERROR(Invalid Apache directory - unable to find httpd.h under $withval) + fi + else + AC_MSG_RESULT(no) + fi +],[ + AC_MSG_RESULT(no) +]) + +INCLUDES="$INCLUDES $APACHE_INCLUDE" +dnl## AC_SUBST(APACHE_INCLUDE) +fi +fi + +AC_SUBST(APACHE_INCLUDE) +AC_SUBST(APACHE_TARGET) +AC_SUBST(APXS) +AC_SUBST(APXS_LDFLAGS) +AC_SUBST(APACHE_INSTALL) +AC_SUBST(STRONGHOLD) + +AC_MSG_CHECKING(for mod_charset compatibility option) +AC_ARG_WITH(mod_charset, +[ --with-mod_charset Enable transfer tables for mod_charset (Rus Apache).], +[ + AC_MSG_RESULT(yes) + AC_DEFINE(USE_TRANSFER_TABLES) +],[ + AC_MSG_RESULT(no) +]) + +dnl ## Local Variables: +dnl ## tab-width: 4 +dnl ## End: diff --git a/mod_php4.c b/sapi/apache/mod_php4.c index 579287dbf3..2f844738f6 100644 --- a/mod_php4.c +++ b/sapi/apache/mod_php4.c @@ -22,11 +22,11 @@ #include "httpd.h" #include "http_config.h" #if MODULE_MAGIC_NUMBER > 19980712 -#include "ap_compat.h" +# include "ap_compat.h" #else -#if MODULE_MAGIC_NUMBER > 19980324 -#include "compat.h" -#endif +# if MODULE_MAGIC_NUMBER > 19980324 +# include "compat.h" +# endif #endif #include "http_core.h" #include "http_main.h" @@ -34,12 +34,20 @@ #include "http_request.h" #include "http_log.h" +#include "zend.h" #include "php.h" #include "php_ini.h" #include "php_globals.h" #include "SAPI.h" #include "main.h" +#include "zend_compile.h" +#include "zend_execute.h" +#include "zend_highlight.h" +#include "zend_indent.h" + +#include "ext/standard/php3_standard.h" + #include "util_script.h" #include "php_version.h" @@ -83,7 +91,47 @@ typedef struct _php_per_dir_entry { php_apache_info_struct php_apache_info; /* active config */ +/* some systems are missing these from their header files */ + +PHPAPI int apache_php_module_main(request_rec *r, int fd, int display_source_mode SLS_DC) +{ + zend_file_handle file_handle; +#ifdef ZTS + zend_compiler_globals cg; + zend_executor_globals eg; + php_core_globals pcg; + zend_compiler_globals *compiler_globals=&cg; + zend_executor_globals *executor_globals=⪚ + php_core_globals *core_globals=&pcg; +#endif + SLS_FETCH(); + if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC) == FAILURE) { + return FAILURE; + } + file_handle.type = ZEND_HANDLE_FD; + file_handle.handle.fd = fd; + file_handle.filename = SG(request_info).path_translated; + + if (display_source_mode) { + zend_syntax_highlighter_ini syntax_highlighter_ini; + + if (open_file_for_scanning(&file_handle CLS_CC)==SUCCESS) { + php_get_highlight_struct(&syntax_highlighter_ini); + zend_highlight(&syntax_highlighter_ini); + fclose(file_handle.handle.fp); + return OK; + } else { + return NOT_FOUND; + } + } else { + (void) php_execute_script(&file_handle CLS_CC ELS_CC); + } + + php3_header(); /* Make sure headers have been sent */ + php_end_ob_buffering(1); + return (OK); +} void php_save_umask() { diff --git a/mod_php4.exp b/sapi/apache/mod_php4.exp index 2dca1256c2..2dca1256c2 100644 --- a/mod_php4.exp +++ b/sapi/apache/mod_php4.exp diff --git a/mod_php4.h b/sapi/apache/mod_php4.h index 4fe749d2d6..4fe749d2d6 100644 --- a/mod_php4.h +++ b/sapi/apache/mod_php4.h diff --git a/sapi/cgi/Makefile.am b/sapi/cgi/Makefile.am new file mode 100644 index 0000000000..9525e44240 --- /dev/null +++ b/sapi/cgi/Makefile.am @@ -0,0 +1,5 @@ +## Process this file with automake to produce Makefile.in + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpsapi_cgi.a +libphpsapi_cgi_a_SOURCES=cgi_main.c diff --git a/sapi/cgi/Makefile.inc b/sapi/cgi/Makefile.inc new file mode 100644 index 0000000000..b48bd31b1c --- /dev/null +++ b/sapi/cgi/Makefile.inc @@ -0,0 +1,6 @@ +# CGI binary or fhttpd module + +INSTALL_IT=: + +php: all-recursive $(OBJS) $(REGEX_LIB) $(FHTTPD_LIB) + $(CC) $(CFLAGS) -o $(SAPI_TARGET) $(LDFLAGS) $(OBJS) -Lsapi -lphpsapi $(LIBS) diff --git a/cgi_main.c b/sapi/cgi/cgi_main.c index 4a165b80c5..4a165b80c5 100644 --- a/cgi_main.c +++ b/sapi/cgi/cgi_main.c diff --git a/sapi/cgi/config.h.in b/sapi/cgi/config.h.in new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/sapi/cgi/config.h.in diff --git a/sapi/cgi/config.m4 b/sapi/cgi/config.m4 new file mode 100644 index 0000000000..4722f33b16 --- /dev/null +++ b/sapi/cgi/config.m4 @@ -0,0 +1,83 @@ + +if test "$SAPI_TARGET" = "php"; then +AC_MSG_CHECKING(whether to force Apache CGI redirect) +AC_ARG_ENABLE(force-cgi-redirect, +[ --enable-force-cgi-redirect + Enable the security check for internal server + redirects. You should use this if you are + running the CGI version with Apache. ], +[ + if test "$enableval" = "yes"; then + AC_DEFINE(FORCE_CGI_REDIRECT, 1) + AC_MSG_RESULT(yes) + REDIRECT=1 + else + AC_DEFINE(FORCE_CGI_REDIRECT, 0) + AC_MSG_RESULT(no) + REDIRECT=0 + fi +],[ + AC_DEFINE(FORCE_CGI_REDIRECT, 0) + AC_MSG_RESULT(no) + REDIRECT=0 +]) + +AC_MSG_CHECKING(whether to discard path_info + path_translated) +AC_ARG_ENABLE(discard_path, +[ --enable-discard-path If this is enabled, the PHP CGI binary + can safely be placed outside of the + web tree and people will not be able + to circumvent .htaccess security. ], +[ + if test "$enableval" = "yes"; then + AC_DEFINE(DISCARD_PATH, 1) + AC_MSG_RESULT(yes) + DISCARD_PATH=1 + else + AC_DEFINE(DISCARD_PATH, 0) + AC_MSG_RESULT(no) + DISCARD_PATH=0 + fi +],[ + AC_DEFINE(DISCARD_PATH, 0) + AC_MSG_RESULT(no) + DISCARD_PATH=0 +]) +fi + +if test "$SAPI_TARGET" = "php" ; then + INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_TARGET \$(bindir)/$SAPI_TARGET" +fi + +AC_MSG_CHECKING(for fhttpd module support) +AC_ARG_WITH(fhttpd, +[ --with-fhttpd[=DIR] Build fhttpd module. DIR is the fhttpd sources + directory, defaults to /usr/local/src/fhttpd.], +[ + if test "$withval" = "yes"; then + # fhttpd source directory + withval=/usr/local/src/fhttpd + fi + if test "$withval" != "no"; then +# For fhttpd 0.3.x + if test -f $withval/servproc.h; then + FHTTPD_INCLUDE=-I$withval/ + FHTTPD_LIB=$withval/servproc.o + FHTTPD_TARGET=$withval/ + SAPI_TARGET=php + AC_DEFINE(FHTTPD) + AC_MSG_RESULT(yes - fhttpd 0.3.x) + else + AC_MSG_RESULT(no) + AC_MSG_ERROR(Invalid fhttpd directory - unable to find servproc.h under $withval) + fi + else + AC_MSG_RESULT(no) + fi +],[ + AC_MSG_RESULT(no) +]) +INCLUDES="$INCLUDES $FHTTPD_INCLUDE" +dnl## AC_SUBST(FHTTPD_INCLUDE) +AC_SUBST(FHTTPD_LIB) +AC_SUBST(FHTTPD_TARGET) diff --git a/sapi/isapi/Makefile.am b/sapi/isapi/Makefile.am new file mode 100644 index 0000000000..682eebc468 --- /dev/null +++ b/sapi/isapi/Makefile.am @@ -0,0 +1,5 @@ +## Process this file with automake to produce Makefile.in + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpsapi_isapi.a +libphpsapi_isapi_a_SOURCES=php4isapi.c diff --git a/sapi/isapi/Makefile.inc b/sapi/isapi/Makefile.inc new file mode 100644 index 0000000000..d64acf40eb --- /dev/null +++ b/sapi/isapi/Makefile.inc @@ -0,0 +1,6 @@ +# ISAPI/Zeus module + +INSTALL_IT=: + +php4isapi.so: libmodphp4-so.a + g++ $(LDFLAGS) -shared sapi/isapi/php4isapi.o -o $@ libmodphp4-so.a $(LIBS) diff --git a/sapi/isapi/config.m4 b/sapi/isapi/config.m4 new file mode 100644 index 0000000000..777ec8de65 --- /dev/null +++ b/sapi/isapi/config.m4 @@ -0,0 +1,31 @@ +dnl ## $Id$ -*- sh -*- + +AC_MSG_CHECKING(for Zeus ISAPI support) +AC_ARG_WITH(zeus, +[ --with-zeus=DIR Build PHP as an ISAPI module for use with Zeus.], +[ + if test "$withval" != "no"; then + SAPI_TARGET=libphp4_isapi.so + AC_MSG_RESULT(yes) + if test "${enable_thread_safety}" != "yes"; then + AC_MSG_ERROR(You must specify --enable-thread-safety to build as an ISAPI module) + fi + if test "$withval" = "yes"; then + zeuspath=/usr/local/zeus # the default + fi + if ! test -f "$zeuspath/web/include/httpext.h"; then + AC_MSG_ERROR(Unable to find httpext.h in $zeuspath/web/include) + fi + AC_ADD_INCLUDE($zeuspath/web/include) + PHP_SAPI=isapi + SAPI_TARGET=php4isapi.so + else + AC_MSG_RESULT(no) + fi +],[ + AC_MSG_RESULT(no) +]) + +dnl ## Local Variables: +dnl ## tab-width: 4 +dnl ## End: diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c new file mode 100644 index 0000000000..ee3f1f2179 --- /dev/null +++ b/sapi/isapi/php4isapi.c @@ -0,0 +1,464 @@ +#include <windows.h> +#include <httpext.h> +#include <httpfilt.h> +#include <httpext.h> +#include "php.h" +#include "main.h" +#include "SAPI.h" +#include "php_globals.h" +#include "ext/standard/info.h" + +#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") +#define ISAPI_SERVER_VAR_BUF_SIZE 1024 +#define ISAPI_POST_DATA_BUF 1024 + +int IWasLoaded=0; + +static char *isapi_server_variables[] = { + "ALL_HTTP", + "APPL_MD_PATH", + "APPL_PHYSICAL_PATH", + "AUTH_PASSWORD", + "AUTH_TYPE", + "AUTH_USER", + "CERT_COOKIE", + "CERT_FLAGS", + "CERT_ISSUER", + "CERT_KEYSIZE", + "CERT_SECRETKEYSIZE", + "CERT_SERIALNUMBER", + "CERT_SERVER_ISSUER", + "CERT_SERVER_SUBJECT", + "CERT_SUBJECT", + "CONTENT_LENGTH", + "CONTENT_TYPE", + "LOGON_USER", + "HTTP_COOKIE", + "HTTPS", + "HTTPS_KEYSIZE", + "HTTPS_SECRETKEYSIZE", + "HTTPS_SERVER_ISSUER", + "HTTPS_SERVER_SUBJECT", + "INSTANCE_ID", + "INSTANCE_META_PATH", + "PATH_INFO", + "PATH_TRANSLATED", + "QUERY_STRING", + "REMOTE_ADDR", + "REMOTE_HOST", + "REMOTE_USER", + "REQUEST_METHOD", + "SCRIPT_NAME", + "SERVER_NAME", + "SERVER_PORT", + "SERVER_PORT_SECURE", + "SERVER_PROTOCOL", + "SERVER_SOFTWARE", + "URL", + NULL +}; + + +static void php_info_isapi(ZEND_MODULE_INFO_FUNC_ARGS) +{ + char **p = isapi_server_variables; + char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; + DWORD variable_len; + LPEXTENSION_CONTROL_BLOCK lpECB; + SLS_FETCH(); + + lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); + + PUTS("<table border=5 width=\"600\">\n"); + php_info_print_table_header(2, "Server Variable", "Value"); + while (*p) { + variable_len = ISAPI_SERVER_VAR_BUF_SIZE; + if (lpECB->GetServerVariable(lpECB->ConnID, *p, variable_buf, &variable_len) + && variable_buf[0]) { + php_info_print_table_row(2, *p, variable_buf); + } else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + char *tmp_variable_buf; + + tmp_variable_buf = (char *) emalloc(variable_len); + if (lpECB->GetServerVariable(lpECB->ConnID, *p, tmp_variable_buf, &variable_len) + && variable_buf[0]) { + php_info_print_table_row(2, *p, tmp_variable_buf); + } + efree(tmp_variable_buf); + } + p++; + } + + PUTS("</table>"); +} + + +static zend_module_entry php_isapi_module = { + "ISAPI", + NULL, + NULL, + NULL, + NULL, + NULL, + php_info_isapi, + STANDARD_MODULE_PROPERTIES +}; + + +static int zend_isapi_ub_write(const char *str, uint str_length) +{ + DWORD num_bytes = str_length; + LPEXTENSION_CONTROL_BLOCK ecb; + SLS_FETCH(); + + ecb = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); + ecb->WriteClient(ecb->ConnID, (char *) str, &num_bytes, HSE_IO_SYNC ); + return num_bytes; +} + + +static int sapi_isapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC) +{ + return SAPI_HEADER_ADD; +} + + + +static void accumulate_header_length(sapi_header_struct *sapi_header, uint *total_length) +{ + *total_length += sapi_header->header_len+2; +} + + +static void concat_header(sapi_header_struct *sapi_header, char **combined_headers_ptr) +{ + memcpy(*combined_headers_ptr, sapi_header->header, sapi_header->header_len); + *combined_headers_ptr += sapi_header->header_len; + **combined_headers_ptr = '\r'; + (*combined_headers_ptr)++; + **combined_headers_ptr = '\n'; + (*combined_headers_ptr)++; +} + + +static int sapi_isapi_send_headers(sapi_headers_struct *sapi_headers SLS_DC) +{ + uint total_length = 2; /* account for the trailing \r\n */ + char *combined_headers, *combined_headers_ptr; + LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); + HSE_SEND_HEADER_EX_INFO header_info; + char status_buf[MAX_STATUS_LENGTH]; + sapi_header_struct default_content_type = { SAPI_DEFAULT_CONTENT_TYPE, sizeof(SAPI_DEFAULT_CONTENT_TYPE)-1 }; + sapi_header_struct php_version_header = { SAPI_PHP_VERSION_HEADER, sizeof(SAPI_PHP_VERSION_HEADER)-1 }; + PLS_FETCH(); + + /* Obtain headers length */ + if (SG(sapi_headers).send_default_content_type) { + accumulate_header_length(&default_content_type, (void *) &total_length); + } + if (PG(expose_php)) { + accumulate_header_length(&php_version_header, (void *) &total_length); + } + zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) accumulate_header_length, (void *) &total_length); + + /* Generate headers */ + combined_headers = (char *) emalloc(total_length+1); + combined_headers_ptr = combined_headers; + if (SG(sapi_headers).send_default_content_type) { + concat_header(&default_content_type, (void *) &combined_headers_ptr); + } + if (PG(expose_php)) { + concat_header(&php_version_header, (void *) &combined_headers_ptr); + } + zend_llist_apply_with_argument(&SG(sapi_headers).headers, (void (*)(void *, void *)) concat_header, (void *) &combined_headers_ptr); + *combined_headers_ptr++ = '\r'; + *combined_headers_ptr++ = '\n'; + *combined_headers_ptr = 0; + + switch (SG(sapi_headers).http_response_code) { + case 200: + header_info.pszStatus = "200 OK"; + break; + case 302: + header_info.pszStatus = "302 Moved Temporarily"; + break; + case 401: + header_info.pszStatus = "401 Authorization Required"; + break; + default: + snprintf(status_buf, MAX_STATUS_LENGTH, "%d Undescribed", SG(sapi_headers).http_response_code); + header_info.pszStatus = status_buf; + break; + } + header_info.cchStatus = strlen(header_info.pszStatus); + header_info.pszHeader = combined_headers; + header_info.cchHeader = total_length; + lpECB->dwHttpStatusCode = SG(sapi_headers).http_response_code; + + lpECB->ServerSupportFunction(lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); + + efree(combined_headers); + if (SG(sapi_headers).http_status_line) { + efree(SG(sapi_headers).http_status_line); + } + return SAPI_HEADER_SENT_SUCCESSFULLY; +} + + +static int php_isapi_startup(sapi_module_struct *sapi_module) +{ + if (php_module_startup(sapi_module)==FAILURE + || zend_register_module(&php_isapi_module)==FAILURE) { + return FAILURE; + } else { + return SUCCESS; + } +} + + + +static int sapi_isapi_read_post(char *buffer, uint count_bytes SLS_DC) +{ + LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); + DWORD read_from_buf=0; + DWORD read_from_input=0; + DWORD total_read=0; + + if (SG(read_post_bytes) < lpECB->cbAvailable) { + read_from_buf = MIN(lpECB->cbAvailable-SG(read_post_bytes), count_bytes); + memcpy(buffer, lpECB->lpbData+SG(read_post_bytes), read_from_buf); + total_read += read_from_buf; + } + if (read_from_buf<count_bytes + && (SG(read_post_bytes)+read_from_buf) < lpECB->cbTotalBytes) { + DWORD cbRead=0, cbSize; + + read_from_input = MIN(count_bytes-read_from_buf, lpECB->cbTotalBytes-SG(read_post_bytes)-read_from_buf); + while (cbRead < read_from_input) { + cbSize = read_from_input - cbRead; + if (!lpECB->ReadClient(lpECB->ConnID, buffer+read_from_buf+cbRead, &cbSize) || cbSize==0) { + break; + } + cbRead += cbSize; + } + total_read += cbRead; + } + SG(read_post_bytes) += total_read; + return total_read; +} + + +static char *sapi_isapi_read_cookies(SLS_D) +{ + LPEXTENSION_CONTROL_BLOCK lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); + char variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; + DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; + + if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", variable_buf, &variable_len)) { + return estrndup(variable_buf, variable_len); + } else if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) { + char *tmp_variable_buf = (char *) emalloc(variable_len+1); + + if (lpECB->GetServerVariable(lpECB->ConnID, "HTTP_COOKIE", tmp_variable_buf, &variable_len)) { + tmp_variable_buf[variable_len] = 0; + return tmp_variable_buf; + } else { + efree(tmp_variable_buf); + } + } + return NULL; +} + + +static sapi_module_struct sapi_module = { + "PHP Language", /* name */ + + php_isapi_startup, /* startup */ + php_module_shutdown_wrapper, /* shutdown */ + + zend_isapi_ub_write, /* unbuffered write */ + + php_error, /* error handler */ + + sapi_isapi_header_handler, /* header handler */ + sapi_isapi_send_headers, /* send headers handler */ + NULL, /* send header handler */ + + sapi_isapi_read_post, /* read POST data */ + sapi_isapi_read_cookies, /* read Cookies */ + + STANDARD_SAPI_MODULE_PROPERTIES +}; + + +BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pFilterVersion) +{ + pFilterVersion->dwFilterVersion = HTTP_FILTER_REVISION; + strcpy(pFilterVersion->lpszFilterDesc, sapi_module.name); + pFilterVersion->dwFlags= (SF_NOTIFY_AUTHENTICATION | SF_NOTIFY_PREPROC_HEADERS); + return TRUE; +} + + +DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificationType, LPVOID pvNotification) +{ + SLS_FETCH(); + + switch (notificationType) { + case SF_NOTIFY_PREPROC_HEADERS: + SG(request_info).auth_user = NULL; + SG(request_info).auth_password = NULL; + break; + case SF_NOTIFY_AUTHENTICATION: { + char *auth_user = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszUser; + char *auth_password = ((HTTP_FILTER_AUTHENT *) pvNotification)->pszPassword; + + if (auth_user && auth_user[0]) { + SG(request_info).auth_user = estrdup(auth_user); + } + if (auth_password && auth_password[0]) { + SG(request_info).auth_password = estrdup(auth_password); + } + auth_user[0] = 0; + auth_password[0] = 0; + return SF_STATUS_REQ_HANDLED_NOTIFICATION; + } + break; + } + return SF_STATUS_REQ_NEXT_NOTIFICATION; +} + + +static void init_request_info(sapi_globals_struct *sapi_globals, LPEXTENSION_CONTROL_BLOCK lpECB) +{ + SG(request_info).request_method = lpECB->lpszMethod; + SG(request_info).query_string = lpECB->lpszQueryString; + SG(request_info).path_translated = lpECB->lpszPathTranslated; + SG(request_info).request_uri = lpECB->lpszPathInfo; + SG(request_info).content_type = lpECB->lpszContentType; + SG(request_info).content_length = lpECB->cbTotalBytes; + { + char *path_end = strrchr(SG(request_info).path_translated, '\\'); + + if (path_end) { + *path_end = 0; + chdir(SG(request_info).path_translated); + *path_end = '\\'; + } + } +} + + +BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) +{ + pVer->dwExtensionVersion = HSE_VERSION; + lstrcpyn(pVer->lpszExtensionDesc, sapi_module.name, HSE_MAX_EXT_DLL_NAME_LEN); + return TRUE; +} + + +static void hash_isapi_variables(ELS_D SLS_DC) +{ + char static_variable_buf[ISAPI_SERVER_VAR_BUF_SIZE]; + char *variable_buf; + DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; + char *variable; + LPEXTENSION_CONTROL_BLOCK lpECB; + + lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); + + if (lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", static_variable_buf, &variable_len)) { + variable_buf = static_variable_buf; + } else { + if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) { + variable_buf = (char *) emalloc(variable_len); + if (!lpECB->GetServerVariable(lpECB->ConnID, "ALL_HTTP", variable_buf, &variable_len)) { + efree(variable_buf); + return; + } + } else { + return; + } + } + variable = strtok(variable_buf, "\r\n"); + while (variable) { + char *colon = strchr(variable, ':'); + + if (colon) { + char *value = colon+1; + zval *entry = (zval *) emalloc(sizeof(zval)); + + while (*value==' ') { + value++; + } + *colon = 0; + INIT_PZVAL(entry); + entry->value.str.len = strlen(value); + entry->value.str.val = estrndup(value, entry->value.str.len); + entry->type = IS_STRING; + zend_hash_add(&EG(symbol_table), variable, strlen(variable)+1, &entry, sizeof(zval *), NULL); + *colon = ':'; + } + variable = strtok(NULL, "\r\n"); + } + if (variable_buf!=static_variable_buf) { + efree(variable_buf); + } +} + + +DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) +{ + zend_file_handle file_handle; + SLS_FETCH(); + CLS_FETCH(); + ELS_FETCH(); + PLS_FETCH(); + + if (setjmp(EG(bailout))!=0) { + return HSE_STATUS_ERROR; + } + + init_request_info(sapi_globals, lpECB); + SG(server_context) = lpECB; + + file_handle.filename = sapi_globals->request_info.path_translated; + file_handle.type = ZEND_HANDLE_FILENAME; + + php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); + hash_isapi_variables(ELS_C SLS_CC); + php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); + if (SG(request_info).cookie_data) { + efree(SG(request_info).cookie_data); + } + php_request_shutdown(NULL); + return HSE_STATUS_SUCCESS; +} + + + +__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + switch (fdwReason) { + case DLL_PROCESS_ATTACH: + tsrm_startup(1, 1, 0); + sapi_startup(&sapi_module); + if (sapi_module.startup) { + sapi_module.startup(&sapi_module); + } + IWasLoaded = 1; + break; + case DLL_THREAD_ATTACH: + break; + case DLL_THREAD_DETACH: + ts_free_thread(); + break; + case DLL_PROCESS_DETACH: + if (sapi_module.shutdown) { + sapi_module.shutdown(&sapi_module); + } + tsrm_shutdown(); + break; + } + return TRUE; +}
\ No newline at end of file diff --git a/sapi/isapi/php4isapi.def b/sapi/isapi/php4isapi.def new file mode 100644 index 0000000000..596023ef55 --- /dev/null +++ b/sapi/isapi/php4isapi.def @@ -0,0 +1,5 @@ +EXPORTS +HttpFilterProc +GetFilterVersion +HttpExtensionProc +GetExtensionVersion diff --git a/sapi/isapi/php4isapi.dsp b/sapi/isapi/php4isapi.dsp new file mode 100644 index 0000000000..3facc5baca --- /dev/null +++ b/sapi/isapi/php4isapi.dsp @@ -0,0 +1,106 @@ +# Microsoft Developer Studio Project File - Name="php4isapi" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=php4isapi - 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 "php4isapi.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 "php4isapi.mak" CFG="php4isapi - Win32 Debug_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "php4isapi - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "php4isapi - 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)" == "php4isapi - 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 Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\win32" /I "..\libzend" /I ".." /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "COMPILE_LIBZEND" /D "WIN32" /D "_MBCS" /D "ZTS" /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 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /debug /machine:I386 /nodefaultlib:"libcmt" /pdbtype:sept /libpath:"..\Debug_TS"
+
+!ELSEIF "$(CFG)" == "php4isapi - 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 /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\include" /I "..\win32" /I "..\libzend" /I ".." /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PHP4ISAPI_EXPORTS" /D "MSVC5" /D "ZTS" /D "WIN32" /D "_MBCS" /D ZEND_DEBUG=0 /FR /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 kernel32.lib user32.lib gdi32.lib wsock32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386 /libpath:"..\Release_TS"
+
+!ENDIF
+
+# Begin Target
+
+# Name "php4isapi - Win32 Debug_TS"
+# Name "php4isapi - Win32 Release_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\php4isapi.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\php4isapi.def
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# End Target
+# End Project
diff --git a/sapi/nsapi/Makefile.am b/sapi/nsapi/Makefile.am new file mode 100644 index 0000000000..4a8edf6074 --- /dev/null +++ b/sapi/nsapi/Makefile.am @@ -0,0 +1,5 @@ +## Process this file with automake to produce Makefile.in + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpsapi_nsapi.a +libphpsapi_nsapi_a_SOURCES=aolserver.c diff --git a/sapi/nsapi/Makefile.inc b/sapi/nsapi/Makefile.inc new file mode 100644 index 0000000000..6c56958bc8 --- /dev/null +++ b/sapi/nsapi/Makefile.inc @@ -0,0 +1,6 @@ +# NSAPI/AOLserver module + +INSTALL_IT=: + +php4_nsapi.so: libmodphp4-so.a + g++ $(LDFLAGS) -shared sapi/nsapi/aolserver.o -o $@ libmodphp4-so.a $(LIBS) diff --git a/sapi/nsapi/aolserver.c b/sapi/nsapi/aolserver.c new file mode 100644 index 0000000000..cbc4ec0257 --- /dev/null +++ b/sapi/nsapi/aolserver.c @@ -0,0 +1,343 @@ +/* + +----------------------------------------------------------------------+ + | 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: Sascha Schumann <sascha@schumann.cx> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +/* conflict between PHP and aolserver */ +#define Debug php_Debug +#include "php.h" +#undef Debug + +#ifdef HAVE_AOLSERVER + +#include "php_ini.h" +#include "php_globals.h" +#include "SAPI.h" +#include "main.h" + +#include "ns.h" + +#include "php_version.h" + +int Ns_ModuleVersion = 1; + +#define NSLS_D ns_globals_struct *ns_context +#define NSLS_DC , NSLS_D +#define NSLS_C ns_context +#define NSLS_CC , NSLS_C +#define NSG(v) (ns_context->v) +#define NSLS_FETCH() ns_globals_struct *ns_context = ts_resource(ns_globals_id) + +static int ns_globals_id; + +typedef struct { + sapi_module_struct *sapi_module; + char *ns_server; + char *ns_module; +} php_ns_context; + +typedef struct { + Ns_Conn *conn; + Ns_DString content_type; +} ns_globals_struct; + +static void php_ns_config(php_ns_context *ctx); + +static int +php_ns_sapi_ub_write(const char *str, uint str_length) +{ + int sent_bytes; + NSLS_FETCH(); + + sent_bytes = Ns_ConnWrite(NSG(conn), (void *) str, str_length); + + return sent_bytes; +} + +static int +php_ns_sapi_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC) +{ + char *header_name, *header_content; + char *p; + NSLS_FETCH(); + + header_name = sapi_header->header; + header_content = p = strchr(header_name, ':'); + + if(!p) return 0; + + *p = '\0'; + do { + header_content++; + } while(*header_content == ' '); + + if(!strcasecmp(header_name, "Content-type")) { + Ns_ConnSetTypeHeader(NSG(conn), header_content); + } else { + Ns_ConnSetHeaders(NSG(conn), header_name, header_content); + } + + *p = ':'; + + efree(sapi_header->header); + + return 0; +} + +static int +php_ns_sapi_send_headers(sapi_headers_struct *sapi_headers SLS_DC) +{ + NSLS_FETCH(); + + if(SG(sapi_headers).send_default_content_type) { + Ns_ConnSetRequiredHeaders(NSG(conn), "text/html", 0); + } + Ns_ConnFlushHeaders(NSG(conn), SG(sapi_headers).http_response_code); + return SAPI_HEADER_SENT_SUCCESSFULLY; +} + +static int +php_ns_sapi_read_post(char *buf, uint count_bytes SLS_DC) +{ + uint total_read = 0; + NSLS_FETCH(); + + total_read = Ns_ConnRead(NSG(conn), buf, count_bytes); + + if(total_read == NS_ERROR) { + total_read = -1; + } + + return total_read; +} + +static char * +php_ns_sapi_read_cookies(SLS_D) +{ + int i; + char *http_cookie = NULL; + NSLS_FETCH(); + + i = Ns_SetFind(NSG(conn->headers), "cookie"); + if(i != -1) { + http_cookie = Ns_SetValue(NSG(conn->headers), i); + } + + return http_cookie; +} + +static sapi_module_struct sapi_module = { + "PHP Language", + + php_module_startup, /* startup */ + php_module_shutdown_wrapper, /* shutdown */ + + php_ns_sapi_ub_write, /* unbuffered write */ + + php_error, /* error handler */ + + php_ns_sapi_header_handler, /* header handler */ + php_ns_sapi_send_headers, /* send headers handler */ + NULL, /* send header handler */ + + php_ns_sapi_read_post, /* read POST data */ + php_ns_sapi_read_cookies, /* read Cookies */ + + STANDARD_SAPI_MODULE_PROPERTIES +}; + +static void +php_ns_hash_environment(NSLS_D CLS_DC ELS_DC PLS_DC SLS_DC) +{ + int i; + + for(i = 0; i < Ns_SetSize(NSG(conn->headers)); i++) { + char *key = Ns_SetKey(NSG(conn->headers), i); + char *value = Ns_SetValue(NSG(conn->headers), i); + char *p; + zval *pval; + char buf[512]; + int buf_len; + + buf_len = snprintf(buf, 511, "HTTP_%s", key); + for(p = buf; *p; p++) { + *p = toupper(*p); + if(*p < 'A' || *p > 'Z') { + *p = '_'; + } + } + + MAKE_STD_ZVAL(pval); + pval->type = IS_STRING; + pval->value.str.len = strlen(value); + pval->value.str.val = estrndup(value, pval->value.str.len); + + zend_hash_update(&EG(symbol_table), buf, buf_len + 1, &pval, sizeof(zval *), NULL); + } +} + +static int +php_ns_module_main(NSLS_D SLS_DC) +{ + zend_file_handle file_handle; + CLS_FETCH(); + ELS_FETCH(); + PLS_FETCH(); + + file_handle.type = ZEND_HANDLE_FILENAME; + file_handle.filename = SG(request_info).path_translated; + + php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC); + php_ns_hash_environment(NSLS_C CLS_CC ELS_CC PLS_CC SLS_CC); + php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC); + php_request_shutdown(NULL); + + return NS_OK; +} + +static void +php_ns_request_ctor(NSLS_D SLS_DC) +{ + char *server; + Ns_DString ds; + char *root; + + server = Ns_ConnServer(NSG(conn)); + + SG(request_info).query_string = NSG(conn->request->query); + + Ns_DStringInit(&ds); + Ns_UrlToFile(&ds, server, NSG(conn->request->url)); + SG(request_info).path_translated = strdup(Ns_DStringValue(&ds)); + Ns_DStringFree(&ds); + root = Ns_PageRoot(server); + SG(request_info).request_uri = SG(request_info).path_translated + strlen(root); + SG(request_info).request_method = NSG(conn)->request->method; + SG(request_info).content_length = Ns_ConnContentLength(NSG(conn)); + Ns_DStringInit(&NSG(content_type)); + Ns_ConnCopyToDString(NSG(conn), SG(request_info).content_length, &NSG(content_type)); + SG(request_info).content_type = Ns_DStringValue(&NSG(content_type)); + SG(request_info).auth_user = NULL; + SG(request_info).auth_password = NULL; +} + +static void +php_ns_request_dtor(NSLS_D SLS_DC) +{ + free(SG(request_info).path_translated); + Ns_DStringFree(&NSG(content_type)); +} + +static int +php_ns_request_handler(void *context, Ns_Conn *conn) +{ + int status = NS_OK; + SLS_FETCH(); + NSLS_FETCH(); + + NSG(conn) = conn; + + php_ns_request_ctor(NSLS_C SLS_CC); + + status = php_ns_module_main(NSLS_C SLS_CC); + + php_ns_request_dtor(NSLS_C SLS_CC); + + return status; +} + +static void +php_ns_config(php_ns_context *ctx) +{ + int i; + char *path; + Ns_Set *set; + + path = Ns_ConfigPath(ctx->ns_server, ctx->ns_module, NULL); + set = Ns_ConfigGetSection(path); + + for(i = 0; set && i < Ns_SetSize(set); i++) { + char *key = Ns_SetKey(set, i); + char *value = Ns_SetValue(set, i); + + if(!strcasecmp(key, "map")) { + Ns_Log(Notice, "Registering PHP for \"%s\"", value); + Ns_RegisterRequest(ctx->ns_server, "GET", value, php_ns_request_handler, NULL, ctx, 0); + Ns_RegisterRequest(ctx->ns_server, "POST", value, php_ns_request_handler, NULL, ctx, 0); + Ns_RegisterRequest(ctx->ns_server, "HEAD", value, php_ns_request_handler, NULL, ctx, 0); + } else if(!strcasecmp(key, "php_value")) { + char *val; + + val = strchr(value, ' '); + if(val) { + char *new_key; + + new_key = estrndup(value, val - value); + + do { + val++; + } while(*val == ' '); + + Ns_Log(Debug, "PHP configuration option '%s=%s'", new_key, val); + php_alter_ini_entry(new_key, strlen(new_key) + 1, val, + strlen(val) + 1, PHP_INI_SYSTEM); + + efree(new_key); + } + } + + } +} + +static void +php_ns_server_shutdown(void *context) +{ + php_ns_context *ctx = (php_ns_context *) context; + + ctx->sapi_module->shutdown(ctx->sapi_module); + sapi_shutdown(); + tsrm_shutdown(); + + free(ctx->ns_module); + free(ctx->ns_server); + free(ctx); +} + +int Ns_ModuleInit(char *server, char *module) +{ + php_ns_context *ctx; + + tsrm_startup(1, 1, 0); + sapi_startup(&sapi_module); + sapi_module.startup(&sapi_module); + + ns_globals_id = ts_allocate_id(sizeof(ns_globals_struct), NULL, NULL); + + ctx = malloc(sizeof *ctx); + ctx->sapi_module = &sapi_module; + ctx->ns_server = strdup(server); + ctx->ns_module = strdup(module); + + php_ns_config(ctx); + + Ns_RegisterServerShutdown(server, php_ns_server_shutdown, ctx); + + return NS_OK; +} + +#endif diff --git a/sapi/nsapi/config.m4 b/sapi/nsapi/config.m4 new file mode 100644 index 0000000000..854785df04 --- /dev/null +++ b/sapi/nsapi/config.m4 @@ -0,0 +1,26 @@ +dnl ## $Id$ -*- sh -*- + +RESULT=no +AC_MSG_CHECKING(for AOLserver support) +AC_ARG_WITH(aolserver, +[ --with-aolserver=DIR], +[ + if test ! -d $withval ; then + AC_MSG_ERROR(You did not specify a directory) + fi + if test "$enable_thread_safety" != "yes"; then + AC_MSG_ERROR(AOLserver must be compiled using --enable-thread-safety) + fi + NS_DIR=$withval + AC_ADD_INCLUDE($NS_DIR/include) + AC_DEFINE(HAVE_AOLSERVER) + PHP_SAPI=nsapi + SAPI_TARGET=php4_nsapi.so + INSTALL_IT="\$(SHELL) \$(srcdir)/install-sh -m 0755 $SAPI_TARGET $NS_DIR/root/bin/$SAPI_TARGET" + RESULT=yes +]) +AC_MSG_RESULT($RESULT) + +dnl ## Local Variables: +dnl ## tab-width: 4 +dnl ## End: diff --git a/scripts/config-stubs b/scripts/config-stubs index 9985066648..7c774f8407 100755 --- a/scripts/config-stubs +++ b/scripts/config-stubs @@ -2,6 +2,7 @@ # # $Id$ -for stubfile in ext/*/config.m4; do +dir=$1; shift +for stubfile in $dir/*/config.m4; do echo "sinclude($stubfile)" done diff --git a/scripts/preconfig b/scripts/preconfig index 59b48fe545..4813fb2687 100755 --- a/scripts/preconfig +++ b/scripts/preconfig @@ -10,7 +10,7 @@ if test -w configure.in.new || test -w acconfig.h.new ; then exit 1 fi -makefileams=`find ext -name Makefile.am -print | sort` +makefileams=`find ext sapi -name Makefile.am -print | sort` makefiles=`echo $makefileams | sed -e 's/\.am//g'` echo "dnl $disclaimer" > configure.in.new sed -e "s#@@EXT_MAKEFILES@@#$makefiles#" configure.in.in >> configure.in.new @@ -29,6 +29,12 @@ if test "$confighfiles" != "ext/*/config.h.stub"; then cat $file >> acconfig.h.new done fi +confighfiles=`echo sapi/*/config.h.stub` +if test "$confighfiles" != "sapi/*/config.h.stub"; then + for file in $confighfiles; do + cat $file >> acconfig.h.new + done +fi cmp acconfig.h acconfig.h.new > /dev/null 2>&1 if test $? -ne 0 ; then mv acconfig.h.new acconfig.h |