diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /sapi/apache | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'sapi/apache')
-rw-r--r-- | sapi/apache/CREDITS | 3 | ||||
-rw-r--r-- | sapi/apache/apMakefile.libdir | 4 | ||||
-rw-r--r-- | sapi/apache/apMakefile.tmpl | 77 | ||||
-rw-r--r-- | sapi/apache/config.m4 | 273 | ||||
-rw-r--r-- | sapi/apache/config.w32 | 24 | ||||
-rw-r--r-- | sapi/apache/libphp5.module.in | 11 | ||||
-rw-r--r-- | sapi/apache/libpre.c | 55 | ||||
-rw-r--r-- | sapi/apache/mod_php5.c | 1040 | ||||
-rw-r--r-- | sapi/apache/mod_php5.exp | 1 | ||||
-rw-r--r-- | sapi/apache/mod_php5.h | 60 | ||||
-rw-r--r-- | sapi/apache/php.sym | 1 | ||||
-rw-r--r-- | sapi/apache/php5apache.dsp | 151 | ||||
-rw-r--r-- | sapi/apache/php_apache.c | 607 | ||||
-rw-r--r-- | sapi/apache/php_apache_http.h | 70 | ||||
-rw-r--r-- | sapi/apache/sapi_apache.c | 73 |
15 files changed, 2450 insertions, 0 deletions
diff --git a/sapi/apache/CREDITS b/sapi/apache/CREDITS new file mode 100644 index 0000000..991deb5 --- /dev/null +++ b/sapi/apache/CREDITS @@ -0,0 +1,3 @@ +Apache 1.3 +Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar + diff --git a/sapi/apache/apMakefile.libdir b/sapi/apache/apMakefile.libdir new file mode 100644 index 0000000..7b52540 --- /dev/null +++ b/sapi/apache/apMakefile.libdir @@ -0,0 +1,4 @@ +This is a place-holder which indicates to Configure that it shouldn't +provide the default targets when building the Makefile in this directory. +Instead it'll just prepend all the important variable definitions, and +copy the Makefile.tmpl onto the end. diff --git a/sapi/apache/apMakefile.tmpl b/sapi/apache/apMakefile.tmpl new file mode 100644 index 0000000..5f77d9c --- /dev/null +++ b/sapi/apache/apMakefile.tmpl @@ -0,0 +1,77 @@ +## +## Apache 1.3 Makefile template for PHP 5.0 Module +## [src/modules/php5/Makefile.tmpl] +## + +# the parametrized target +LIB=libphp5.$(LIBEXT) + +# objects for building the static library +OBJS=mod_php5.o +OBJS_LIB=libmodphp5.a + +# objects for building the shared object library +SHLIB_OBJS=mod_php5.so-o +SHLIB_OBJS_LIB=libmodphp5.a + +# the general targets +all: lib +lib: $(LIB) + +# build the static library by merging the object files +libphp5.a: $(OBJS) $(OBJS_LIB) + cp $(OBJS_LIB) $@ + ar r $@ $(OBJS) + $(RANLIB) $@ + +# ugly hack to support older Apache-1.3 betas that don't set $LIBEXT +libphp5.: $(OBJS) $(OBJS_LIB) + cp $(OBJS_LIB) $@ + ar r $@ $(OBJS) + $(RANLIB) $@ + cp libphp5. libphp5.a + +# build the shared object library by linking the object files +libphp5.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) + rm -f $@ + $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(PHP_LIBS) + +# 1. extension .o for shared objects cannot be used here because +# first these files aren't still shared objects and second we +# have to use a different name to trigger the different +# implicit Make rule +# 2. extension -so.o (as used elsewhere) cannot be used because +# the suffix feature of Make really wants just .x, so we use +# extension .so-o +.SUFFIXES: .o .so-o +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< +.c.so-o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< && mv $*.o $*.so-o + +# cleanup +clean: + -rm -f $(OBJS) $(SHLIB_OBJS) $(LIB) + +# We really don't expect end users to use this rule. It works only with +# gcc, and rebuilds Makefile.tmpl. You have to re-run Configure after +# using it. +depend: + cp Makefile.tmpl Makefile.tmpl.bak \ + && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \ + && gcc -MM $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) *.c >> Makefile.new \ + && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' Makefile.new \ + > Makefile.tmpl \ + && rm Makefile.new + +#Dependencies + +$(OBJS): Makefile + +# DO NOT REMOVE +mod_php5.o: mod_php5.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \ + $(INCDIR)/buff.h \ + $(INCDIR)/http_config.h \ + $(INCDIR)/http_core.h $(INCDIR)/http_main.h \ + $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \ + $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php5.h diff --git a/sapi/apache/config.m4 b/sapi/apache/config.m4 new file mode 100644 index 0000000..af83e9b --- /dev/null +++ b/sapi/apache/config.m4 @@ -0,0 +1,273 @@ +dnl +dnl $Id$ +dnl +AC_DEFUN([PHP_APACHE_FD_CHECK], [ +AC_CACHE_CHECK([for member fd in BUFF *],ac_cv_php_fd_in_buff,[ + save=$CPPFLAGS + if test -n "$APXS_INCLUDEDIR"; then + CPPFLAGS="$CPPFLAGS -I$APXS_INCLUDEDIR" + else + CPPFLAGS="$CPPFLAGS $APACHE_INCLUDE" + fi + AC_TRY_COMPILE([#include <httpd.h>],[conn_rec *c; int fd = c->client->fd;],[ + ac_cv_php_fd_in_buff=yes],[ac_cv_php_fd_in_buff=no],[ac_cv_php_fd_in_buff=no]) + CPPFLAGS=$save +]) +if test "$ac_cv_php_fd_in_buff" = "yes"; then + AC_DEFINE(PHP_APACHE_HAVE_CLIENT_FD,1,[ ]) +fi +]) + +dnl Apache 1.x shared module +PHP_ARG_WITH(apxs,, +[ --with-apxs[=FILE] Build shared Apache 1.x module. FILE is the optional + pathname to the Apache apxs tool [apxs]], no, no) + +AC_MSG_CHECKING([for Apache 1.x module support via DSO through APXS]) + +if test "$PHP_APXS" != "no"; then + if test "$PHP_APXS" = "yes"; then + APXS=apxs + $APXS -q CFLAGS >/dev/null 2>&1 + if test "$?" != "0" && test -x /usr/sbin/apxs; then #SUSE 6.x + APXS=/usr/sbin/apxs + fi + else + PHP_EXPAND_PATH($PHP_APXS, APXS) + fi + + $APXS -q CFLAGS >/dev/null 2>&1 + if test "$?" != "0"; then + AC_MSG_RESULT() + AC_MSG_RESULT() + AC_MSG_RESULT([Sorry, I was not able to successfully run APXS. Possible reasons:]) + AC_MSG_RESULT() + AC_MSG_RESULT([1. Perl is not installed;]) + AC_MSG_RESULT([2. Apache was not compiled with DSO support (--enable-module=so);]) + AC_MSG_RESULT([3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs]) + AC_MSG_RESULT([The output of $APXS follows]) + $APXS -q CFLAGS + AC_MSG_ERROR([Aborting]) + fi + + APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@" + APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR` + APXS_CFLAGS=`$APXS -q CFLAGS` + APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET` + APACHE_INCLUDE=-I$APXS_INCLUDEDIR + + # Test that we're trying to configure with apache 1.x + PHP_AP_EXTRACT_VERSION($APXS_HTTPD) + if test "$APACHE_VERSION" -ge 2000000; then + AC_MSG_ERROR([You have enabled Apache 1.3 support while your server is Apache 2. Please use the appropiate switch --with-apxs2]) + fi + + for flag in $APXS_CFLAGS; do + case $flag in + -D*) APACHE_CPPFLAGS="$APACHE_CPPFLAGS $flag";; + esac + done + + case $host_alias in + *aix*) + APXS_LIBEXECDIR=`$APXS -q LIBEXECDIR` + EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp" + PHP_AIX_LDFLAGS="-Wl,-brtl" + build_type=shared + ;; + *darwin*) + MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD" + PHP_SUBST(MH_BUNDLE_FLAGS) + SAPI_SHARED=libs/libphp5.so + build_type=bundle + ;; + *) + build_type=shared + ;; + esac + + PHP_SELECT_SAPI(apache, $build_type, sapi_apache.c mod_php5.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR) + + # Test whether apxs support -S option + $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1 + + if test "$?" != "0"; then + APACHE_INSTALL="$APXS -i -a -n php5 $SAPI_SHARED" # Old apxs does not have -S option + else + APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR` + if test -z `$APXS -q SYSCONFDIR`; then + APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ + $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ + -i -n php5 $SAPI_SHARED" + else + APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR` + APACHE_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \ + \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \ + $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \ + -S SYSCONFDIR='$APXS_SYSCONFDIR' \ + -i -a -n php5 $SAPI_SHARED" + fi + fi + + if test -z "`$APXS -q LD_SHLIB`" || test "`$APXS -q LIBEXECDIR`" = "modules"; then + PHP_APXS_BROKEN=yes + fi + STRONGHOLD= + AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) + AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ]) + AC_DEFINE(HAVE_APACHE,1,[ ]) + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + +dnl Apache 1.x static module +PHP_ARG_WITH(apache,, +[ --with-apache[=DIR] Build Apache 1.x module. DIR is the top-level Apache + build directory [/usr/local/apache]], no, no) + +AC_MSG_CHECKING([for Apache 1.x module support]) + +if test "$PHP_SAPI" != "apache" && test "$PHP_APACHE" != "no"; then + + if test "$PHP_APACHE" = "yes"; then + # Apache's default directory + PHP_APACHE=/usr/local/apache + fi + + APACHE_INSTALL_FILES="\$(srcdir)/sapi/apache/mod_php5.* sapi/apache/libphp5.module" + + AC_DEFINE(HAVE_APACHE,1,[ ]) + APACHE_MODULE=yes + PHP_EXPAND_PATH($PHP_APACHE, PHP_APACHE) + # For Apache 1.2.x + if test -f $PHP_APACHE/src/httpd.h; then + APACHE_INCLUDE=-I$PHP_APACHE/src + APACHE_TARGET=$PHP_APACHE/src + PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_INSTALL_FILES $APACHE_TARGET" + PHP_LIBS="-L. -lphp3" + AC_MSG_RESULT([yes - Apache 1.2.x]) + STRONGHOLD= + if test -f $PHP_APACHE/src/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ]) + fi + # For Apache 2.0.x + elif test -f $PHP_APACHE/include/httpd.h && test -f $PHP_APACHE/srclib/apr/include/apr_general.h ; then + AC_MSG_ERROR([Use --with-apxs2 with Apache 2.x!]) + # For Apache 1.3.x + elif test -f $PHP_APACHE/src/main/httpd.h; then + APACHE_HAS_REGEX=1 + APACHE_INCLUDE="-I$PHP_APACHE/src/main -I$PHP_APACHE/src/os/unix -I$PHP_APACHE/src/ap" + APACHE_TARGET=$PHP_APACHE/src/modules/php5 + if test ! -d $APACHE_TARGET; then + mkdir $APACHE_TARGET + fi + PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" + PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" + AC_MSG_RESULT([yes - Apache 1.3.x]) + STRONGHOLD= + if test -f $PHP_APACHE/src/include/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) + fi + if test -f $PHP_APACHE/src/include/ap_compat.h; then + AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) + if test ! -f $PHP_APACHE/src/include/ap_config_auto.h; then + AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) + fi + elif test -f $PHP_APACHE/src/include/compat.h; then + AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) + fi + # Also for Apache 1.3.x + elif test -f $PHP_APACHE/src/include/httpd.h; then + APACHE_HAS_REGEX=1 + APACHE_INCLUDE="-I$PHP_APACHE/src/include -I$PHP_APACHE/src/os/unix" + APACHE_TARGET=$PHP_APACHE/src/modules/php5 + if test ! -d $APACHE_TARGET; then + mkdir $APACHE_TARGET + fi + PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) + PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache/apMakefile.libdir $APACHE_TARGET/Makefile.libdir" + AC_MSG_RESULT([yes - Apache 1.3.x]) + STRONGHOLD= + if test -f $PHP_APACHE/src/include/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) + fi + if test -f $PHP_APACHE/src/include/ap_compat.h; then + AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) + if test ! -f $PHP_APACHE/src/include/ap_config_auto.h; then + AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) + fi + elif test -f $PHP_APACHE/src/include/compat.h; then + AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) + fi + # For StrongHold 2.2 + elif test -f $PHP_APACHE/apache/httpd.h; then + APACHE_INCLUDE="-I$PHP_APACHE/apache -I$PHP_APACHE/ssl/include" + APACHE_TARGET=$PHP_APACHE/apache + PHP_SELECT_SAPI(apache, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE) + PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5" + APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET" + STRONGHOLD=-DSTRONGHOLD=1 + AC_MSG_RESULT([yes - StrongHold]) + if test -f $PHP_APACHE/apache/ap_config.h; then + AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ]) + fi + if test -f $PHP_APACHE/src/ap_compat.h; then + AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ]) + if test ! -f $PHP_APACHE/src/include/ap_config_auto.h; then + AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again]) + fi + elif test -f $PHP_APACHE/src/compat.h; then + AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ]) + fi + else + AC_MSG_RESULT(no) + AC_MSG_ERROR([Invalid Apache directory - unable to find httpd.h under $PHP_APACHE]) + fi +else + AC_MSG_RESULT(no) +fi + +# compatibility +if test -z "$enable_mod_charset" && test "$with_mod_charset"; then + enable_mod_charset=$with_mod_charset +fi + +PHP_ARG_ENABLE(mod-charset, whether to enable Apache charset compatibility option, +[ --enable-mod-charset APACHE: Enable transfer tables for mod_charset (Rus Apache)], no, no) + +if test "$PHP_MOD_CHARSET" = "yes"; then + AC_DEFINE(USE_TRANSFER_TABLES, 1, [ ]) +fi + +dnl Build as static module +if test "$APACHE_MODULE" = "yes"; then + PHP_TARGET_RDYNAMIC + $php_shtool mkdir -p sapi/apache + PHP_OUTPUT(sapi/apache/libphp5.module) +fi + +dnl General +if test -n "$APACHE_INSTALL"; then + if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then + APXS_EXP=-bE:sapi/apache/mod_php5.exp + fi + + PHP_APACHE_FD_CHECK + INSTALL_IT=$APACHE_INSTALL + + PHP_SUBST(APXS_EXP) + PHP_SUBST(APACHE_INCLUDE) + PHP_SUBST(APACHE_TARGET) + PHP_SUBST(APXS) + PHP_SUBST(APXS_LDFLAGS) + PHP_SUBST(APACHE_INSTALL) + PHP_SUBST(STRONGHOLD) +fi + +dnl ## Local Variables: +dnl ## tab-width: 4 +dnl ## End: diff --git a/sapi/apache/config.w32 b/sapi/apache/config.w32 new file mode 100644 index 0000000..e876d75 --- /dev/null +++ b/sapi/apache/config.w32 @@ -0,0 +1,24 @@ +// vim:ft=javascript +// $Id$ + +ARG_ENABLE('apache', 'Build Apache 1.3.x version of PHP', 'no'); + +ARG_WITH('apache-includes', 'Where to find Apache 1.3 headers', null); +ARG_WITH('apache-libs', 'Where to find Apache 1.3 libraries', null); + +if (PHP_APACHE != "no") { + if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE", php_usual_include_suspects + + ";" + PROGRAM_FILES + "\\Apache Group\\Apache\\include" + + ";" + PHP_PHP_BUILD + "\\apache\\src\\include") && + CHECK_LIB("ApacheCore.lib", "apache", php_usual_lib_suspects + + ';' + PROGRAM_FILES + '\\Apache Group\\Apache\\libexec' + + ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) { + // We need to play tricks to get our readdir.h used by apache + // headers + SAPI('apache', 'mod_php5.c sapi_apache.c php_apache.c', + 'php' + PHP_VERSION + 'apache.dll', + '/D APACHEPHP5_EXPORTS /D APACHE_READDIR_H /I win32'); + } else { + WARNING("Could not find apache libraries/headers"); + } +} diff --git a/sapi/apache/libphp5.module.in b/sapi/apache/libphp5.module.in new file mode 100644 index 0000000..00d9c49 --- /dev/null +++ b/sapi/apache/libphp5.module.in @@ -0,0 +1,11 @@ +Name: php5_module +ConfigStart + RULE_WANTHSREGEX=no + RULE_HIDE=yes + PHP_LIBS="@NATIVE_RPATHS@ @PHP_LDFLAGS@ @PHP_LIBS@ @EXTRA_LDFLAGS@ @EXTRA_LIBS@ $LIBS" + PHP_CFLAGS="$CFLAGS @OPENSSL_INCDIR_OPT@ -I@php_abs_top_builddir@/main -I@php_abs_top_builddir@/Zend -I@php_abs_top_builddir@/TSRM -I@php_abs_top_srcdir@ -I@php_abs_top_srcdir@/sapi/apache -I@php_abs_top_srcdir@/main -I@php_abs_top_srcdir@/Zend -I@php_abs_top_srcdir@/TSRM" + my_outfile="Makefile.config" + echo "PHP_CFLAGS=$PHP_CFLAGS" >>$my_outfile + echo "PHP_LIBS=$PHP_LIBS" >>$my_outfile + LIBS=$PHP_LIBS +ConfigEnd diff --git a/sapi/apache/libpre.c b/sapi/apache/libpre.c new file mode 100644 index 0000000..35b47cf --- /dev/null +++ b/sapi/apache/libpre.c @@ -0,0 +1,55 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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: | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifdef NETWARE + +/* ------------------------------------------------------------------ + * These functions are to be called when the shared NLM starts and + * stops. By using these functions instead of defining a main() + * and calling ExitThread(TSR_THREAD, 0), the load time of the + * shared NLM is faster and memory size reduced. + * + * You may also want to override these in your own Apache module + * to do any cleanup other than the mechanism Apache modules provide. + * ------------------------------------------------------------------ + */ + + +#ifdef __GNUC__ +#include <string.h> /* memset */ +extern char _edata, _end ; /* end of DATA (start of BSS), end of BSS */ +#endif + +int _lib_start() +{ +/* printf("Inside _lib_start\n");*/ +#ifdef __GNUC__ + memset (&_edata, 0, &_end - &_edata); +#endif + return 0; +} + +int _lib_stop() +{ +/* printf("Inside _lib_stop\n");*/ + return 0; +} + +#endif /* NETWARE */ diff --git a/sapi/apache/mod_php5.c b/sapi/apache/mod_php5.c new file mode 100644 index 0000000..11be0ed --- /dev/null +++ b/sapi/apache/mod_php5.c @@ -0,0 +1,1040 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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: Rasmus Lerdorf <rasmus@php.net> | + | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> | + | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ + +#include "php_apache_http.h" +#include "http_conf_globals.h" + +#ifdef NETWARE +#define SIGPIPE SIGINT +#endif + +#undef shutdown + +/* {{{ Prototypes + */ +int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC); +static void php_save_umask(void); +static void php_restore_umask(void); +static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC); +static char *sapi_apache_read_cookies(TSRMLS_D); +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC); +static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC); +static int send_php(request_rec *r, int display_source_mode, char *filename); +static int send_parsed_php(request_rec * r); +static int send_parsed_php_source(request_rec * r); +static int php_xbithack_handler(request_rec * r); +static void php_init_handler(server_rec *s, pool *p); +/* }}} */ + +#if MODULE_MAGIC_NUMBER >= 19970728 +static void php_child_exit_handler(server_rec *s, pool *p); +#endif + +#if MODULE_MAGIC_NUMBER > 19961007 +#define CONST_PREFIX const +#else +#define CONST_PREFIX +#endif +static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); +static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); +static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); +static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); +static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode); +static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2); + +/* ### these should be defined in mod_php5.h or somewhere else */ +#define USE_PATH 1 +#define IGNORE_URL 2 +#define MAX_STATUS_LENGTH sizeof("xxxx LONGEST POSSIBLE STATUS DESCRIPTION") + +module MODULE_VAR_EXPORT php5_module; + +int saved_umask; +static unsigned char apache_php_initialized; + +typedef struct _php_per_dir_entry { + char *key; + char *value; + uint key_length; + uint value_length; + int type; + char htaccess; +} php_per_dir_entry; + +/* some systems are missing these from their header files */ + +/* {{{ php_save_umask + */ +static void php_save_umask(void) +{ + saved_umask = umask(077); + umask(saved_umask); +} +/* }}} */ + +/* {{{ sapi_apache_ub_write + */ +static int sapi_apache_ub_write(const char *str, uint str_length TSRMLS_DC) +{ + int ret=0; + + if (SG(server_context)) { + ret = rwrite(str, str_length, (request_rec *) SG(server_context)); + } + if (ret != str_length) { + php_handle_aborted_connection(); + } + return ret; +} +/* }}} */ + +/* {{{ sapi_apache_flush + */ +static void sapi_apache_flush(void *server_context) +{ + if (server_context) { +#if MODULE_MAGIC_NUMBER > 19970110 + rflush((request_rec *) server_context); +#else + bflush((request_rec *) server_context->connection->client); +#endif + } +} +/* }}} */ + +/* {{{ sapi_apache_read_post + */ +static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC) +{ + int total_read_bytes=0, read_bytes; + request_rec *r = (request_rec *) SG(server_context); + void (*handler)(int); + + /* + * This handles the situation where the browser sends a Expect: 100-continue header + * and needs to recieve confirmation from the server on whether or not it can send + * the rest of the request. RFC 2616 + * + */ + if (!SG(read_post_bytes) && !ap_should_client_block(r)) { + return total_read_bytes; + } + + handler = signal(SIGPIPE, SIG_IGN); + while (total_read_bytes<count_bytes) { + hard_timeout("Read POST information", r); /* start timeout timer */ + read_bytes = get_client_block(r, buffer+total_read_bytes, count_bytes-total_read_bytes); + reset_timeout(r); + if (read_bytes<=0) { + break; + } + total_read_bytes += read_bytes; + } + signal(SIGPIPE, handler); + return total_read_bytes; +} +/* }}} */ + +/* {{{ sapi_apache_read_cookies + */ +static char *sapi_apache_read_cookies(TSRMLS_D) +{ + return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE"); +} +/* }}} */ + +/* {{{ sapi_apache_header_handler + */ +static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) +{ + char *header_name, *header_content, *p; + request_rec *r = (request_rec *) SG(server_context); + if(!r) { + return 0; + } + + switch(op) { + case SAPI_HEADER_DELETE_ALL: + clear_table(r->headers_out); + return 0; + + case SAPI_HEADER_DELETE: + table_unset(r->headers_out, sapi_header->header); + return 0; + + case SAPI_HEADER_ADD: + case SAPI_HEADER_REPLACE: + 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")) { + r->content_type = pstrdup(r->pool, header_content); + } else if (!strcasecmp(header_name, "Content-Length")) { + ap_set_content_length(r, strtol(header_content, (char **)NULL, 10)); + } else if (!strcasecmp(header_name, "Set-Cookie")) { + table_add(r->headers_out, header_name, header_content); + } else if (op == SAPI_HEADER_REPLACE) { + table_set(r->headers_out, header_name, header_content); + } else { + table_add(r->headers_out, header_name, header_content); + } + + *p = ':'; /* a well behaved header handler shouldn't change its original arguments */ + + return SAPI_HEADER_ADD; + + default: + return 0; + } +} +/* }}} */ + +/* {{{ sapi_apache_send_headers + */ +static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) +{ + request_rec *r = SG(server_context); + const char *sline = SG(sapi_headers).http_status_line; + int sline_len; + + if(r == NULL) { /* server_context is not here anymore */ + return SAPI_HEADER_SEND_FAILED; + } + + r->status = SG(sapi_headers).http_response_code; + + /* httpd requires that r->status_line is set to the first digit of + * the status-code: */ + if (sline && ((sline_len = strlen(sline)) > 12) && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ' && sline[12] == ' ') { + if ((sline_len - 9) > MAX_STATUS_LENGTH) { + r->status_line = ap_pstrndup(r->pool, sline + 9, MAX_STATUS_LENGTH); + } else { + r->status_line = ap_pstrndup(r->pool, sline + 9, sline_len - 9); + } + } + + if(r->status==304) { + send_error_response(r,0); + } else { + send_http_header(r); + } + return SAPI_HEADER_SENT_SUCCESSFULLY; +} +/* }}} */ + +/* {{{ sapi_apache_register_server_variables + */ +static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_DC) +{ + register int i; + array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env); + table_entry *elts = (table_entry *) arr->elts; + zval **path_translated; + HashTable *symbol_table; + unsigned int new_val_len; + + for (i = 0; i < arr->nelts; i++) { + char *val; + int val_len; + + if (elts[i].val) { + val = elts[i].val; + } else { + val = ""; + } + val_len = strlen(val); + if (sapi_module.input_filter(PARSE_SERVER, elts[i].key, &val, val_len, &new_val_len TSRMLS_CC)) { + php_register_variable_safe(elts[i].key, val, new_val_len, track_vars_array TSRMLS_CC); + } + } + + /* If PATH_TRANSLATED doesn't exist, copy it from SCRIPT_FILENAME */ + if (track_vars_array) { + symbol_table = track_vars_array->value.ht; + } else { + symbol_table = NULL; + } + if (symbol_table + && !zend_hash_exists(symbol_table, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED")) + && zend_hash_find(symbol_table, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &path_translated)==SUCCESS) { + php_register_variable("PATH_TRANSLATED", Z_STRVAL_PP(path_translated), track_vars_array TSRMLS_CC); + } + + if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &((request_rec *) SG(server_context))->uri, strlen(((request_rec *) SG(server_context))->uri), &new_val_len TSRMLS_CC)) { + php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array TSRMLS_CC); + } +} +/* }}} */ + +/* {{{ php_apache_startup + */ +static int php_apache_startup(sapi_module_struct *sapi_module) +{ + if (php_module_startup(sapi_module, &apache_module_entry, 1) == FAILURE) { + return FAILURE; + } else { + return SUCCESS; + } +} +/* }}} */ + +/* {{{ php_apache_log_message + */ +static void php_apache_log_message(char *message TSRMLS_DC) +{ + if (SG(server_context)) { +#if MODULE_MAGIC_NUMBER >= 19970831 + aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message); +#else + log_error(message, ((request_rec *) SG(server_context))->server); +#endif + } else { + fprintf(stderr, "%s\n", message); + } +} +/* }}} */ + +/* {{{ php_apache_request_shutdown + */ +static void php_apache_request_shutdown(void *dummy) +{ + TSRMLS_FETCH(); + + php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC); + if (AP(in_request)) { + AP(in_request) = 0; + php_request_shutdown(dummy); + } + SG(server_context) = NULL; + /* + * The server context (request) is NOT invalid by the time + * run_cleanups() is called + */ +} +/* }}} */ + +/* {{{ php_apache_sapi_activate + */ +static int php_apache_sapi_activate(TSRMLS_D) +{ + request_rec *r = (request_rec *) SG(server_context); + + /* + * For the Apache module version, this bit of code registers a cleanup + * function that gets triggered when our request pool is destroyed. + * We need this because at any point in our code we can be interrupted + * and that may happen before we have had time to free our memory. + * The php_request_shutdown function needs to free all outstanding allocated + * memory. + */ + block_alarms(); + register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec); + AP(in_request)=1; + unblock_alarms(); + + /* Override the default headers_only value - sometimes "GET" requests should actually only + * send headers. + */ + SG(request_info).headers_only = r->header_only; + return SUCCESS; +} +/* }}} */ + +/* {{{ php_apache_get_stat + */ +static struct stat *php_apache_get_stat(TSRMLS_D) +{ + return &((request_rec *) SG(server_context))->finfo; +} +/* }}} */ + +/* {{{ php_apache_getenv + */ +static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC) +{ + if (SG(server_context) == NULL) { + return NULL; + } + + return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name); +} +/* }}} */ + +/* {{{ sapi_apache_get_fd + */ +static int sapi_apache_get_fd(int *nfd TSRMLS_DC) +{ +#if PHP_APACHE_HAVE_CLIENT_FD + request_rec *r = SG(server_context); + int fd; + + fd = r->connection->client->fd; + + if (fd >= 0) { + if (nfd) *nfd = fd; + return SUCCESS; + } +#endif + return FAILURE; +} +/* }}} */ + +/* {{{ sapi_apache_force_http_10 + */ +static int sapi_apache_force_http_10(TSRMLS_D) +{ + request_rec *r = SG(server_context); + + r->proto_num = HTTP_VERSION(1,0); + + return SUCCESS; +} +/* }}} */ + +/* {{{ sapi_apache_get_target_uid + */ +static int sapi_apache_get_target_uid(uid_t *obj TSRMLS_DC) +{ + *obj = ap_user_id; + return SUCCESS; +} +/* }}} */ + +/* {{{ sapi_apache_get_target_gid + */ +static int sapi_apache_get_target_gid(gid_t *obj TSRMLS_DC) +{ + *obj = ap_group_id; + return SUCCESS; +} +/* }}} */ + +/* {{{ php_apache_get_request_time + */ +static double php_apache_get_request_time(TSRMLS_D) +{ + return (double) ((request_rec *)SG(server_context))->request_time; +} +/* }}} */ + +/* {{{ sapi_apache_child_terminate + */ +static void sapi_apache_child_terminate(TSRMLS_D) +{ +#ifndef MULTITHREAD + ap_child_terminate((request_rec *)SG(server_context)); +#endif +} +/* }}} */ + +/* {{{ sapi_module_struct apache_sapi_module + */ +static sapi_module_struct apache_sapi_module = { + "apache", /* name */ + "Apache", /* pretty name */ + + php_apache_startup, /* startup */ + php_module_shutdown_wrapper, /* shutdown */ + + php_apache_sapi_activate, /* activate */ + NULL, /* deactivate */ + + sapi_apache_ub_write, /* unbuffered write */ + sapi_apache_flush, /* flush */ + php_apache_get_stat, /* get uid */ + php_apache_getenv, /* getenv */ + + php_error, /* error handler */ + + sapi_apache_header_handler, /* header handler */ + sapi_apache_send_headers, /* send headers handler */ + NULL, /* send header handler */ + + sapi_apache_read_post, /* read POST data */ + sapi_apache_read_cookies, /* read Cookies */ + + sapi_apache_register_server_variables, /* register server variables */ + php_apache_log_message, /* Log message */ + php_apache_get_request_time, /* Get request time */ + sapi_apache_child_terminate, + + NULL, /* php.ini path override */ + +#ifdef PHP_WIN32 + NULL, + NULL, +#else + block_alarms, /* Block interruptions */ + unblock_alarms, /* Unblock interruptions */ +#endif + + NULL, /* default post reader */ + NULL, /* treat data */ + NULL, /* exe location */ + 0, /* ini ignore */ + 0, /* ini ignore cwd */ + sapi_apache_get_fd, + sapi_apache_force_http_10, + sapi_apache_get_target_uid, + sapi_apache_get_target_gid +}; +/* }}} */ + +/* {{{ php_restore_umask + */ +static void php_restore_umask(void) +{ + umask(saved_umask); +} +/* }}} */ + +/* {{{ init_request_info + */ +static void init_request_info(TSRMLS_D) +{ + request_rec *r = ((request_rec *) SG(server_context)); + char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH"); + const char *authorization=NULL; + char *tmp, *tmp_user; + + SG(request_info).query_string = r->args; + SG(request_info).path_translated = r->filename; + SG(request_info).request_uri = r->uri; + SG(request_info).request_method = (char *)r->method; + SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE"); + SG(request_info).content_length = (content_length ? atol(content_length) : 0); + SG(sapi_headers).http_response_code = r->status; + SG(request_info).proto_num = r->proto_num; + + if (r->headers_in) { + authorization = table_get(r->headers_in, "Authorization"); + } + + SG(request_info).auth_user = NULL; + SG(request_info).auth_password = NULL; + SG(request_info).auth_digest = NULL; + + if (authorization) { + char *p = getword(r->pool, &authorization, ' '); + if (!strcasecmp(p, "Basic")) { + tmp = uudecode(r->pool, authorization); + tmp_user = getword_nulls_nc(r->pool, &tmp, ':'); + if (tmp_user) { + r->connection->user = pstrdup(r->connection->pool, tmp_user); + r->connection->ap_auth_type = "Basic"; + SG(request_info).auth_user = estrdup(tmp_user); + } + if (tmp) { + SG(request_info).auth_password = estrdup(tmp); + } + } else if (!strcasecmp(p, "Digest")) { + r->connection->ap_auth_type = "Digest"; + SG(request_info).auth_digest = estrdup(authorization); + } + } +} +/* }}} */ + +/* {{{ php_apache_alter_ini_entries + */ +static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry TSRMLS_DC) +{ + zend_alter_ini_entry(per_dir_entry->key, per_dir_entry->key_length+1, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, per_dir_entry->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE); + return 0; +} +/* }}} */ + +/* {{{ php_apache_get_default_mimetype + */ +static char *php_apache_get_default_mimetype(request_rec *r TSRMLS_DC) +{ + + char *mimetype; + if (SG(default_mimetype) || SG(default_charset)) { + /* Assume output will be of the default MIME type. Individual + scripts may change this later. */ + char *tmpmimetype; + tmpmimetype = sapi_get_default_content_type(TSRMLS_C); + mimetype = pstrdup(r->pool, tmpmimetype); + efree(tmpmimetype); + } else { + mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET; + } + return mimetype; +} +/* }}} */ + +/* {{{ send_php + */ +static int send_php(request_rec *r, int display_source_mode, char *filename) +{ + int retval; + HashTable *per_dir_conf; + TSRMLS_FETCH(); + + if (AP(in_request)) { + zend_file_handle fh; + + fh.filename = r->filename; + fh.opened_path = NULL; + fh.free_filename = 0; + fh.type = ZEND_HANDLE_FILENAME; + + zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh); + return OK; + } + + SG(server_context) = r; + + zend_first_try { + + /* Make sure file exists */ + if (filename == NULL && r->finfo.st_mode == 0) { + return DECLINED; + } + + per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php5_module); + if (per_dir_conf) { + zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC); + } + + /* If PHP parser engine has been turned off with an "engine off" + * directive, then decline to handle this request + */ + if (!AP(engine)) { + r->content_type = php_apache_get_default_mimetype(r TSRMLS_CC); + zend_try { + zend_ini_deactivate(TSRMLS_C); + } zend_end_try(); + return DECLINED; + } + if (filename == NULL) { + filename = r->filename; + } + + /* Apache 1.2 has a more complex mechanism for reading POST data */ +#if MODULE_MAGIC_NUMBER > 19961007 + if ((retval = setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) { + zend_try { + zend_ini_deactivate(TSRMLS_C); + } zend_end_try(); + return retval; + } +#endif + + if (AP(last_modified)) { +#if MODULE_MAGIC_NUMBER < 19970912 + if ((retval = set_last_modified(r, r->finfo.st_mtime))) { + zend_try { + zend_ini_deactivate(TSRMLS_C); + } zend_end_try(); + return retval; + } +#else + update_mtime (r, r->finfo.st_mtime); + set_last_modified(r); + set_etag(r); +#endif + } + /* Assume output will be of the default MIME type. Individual + scripts may change this later in the request. */ + r->content_type = php_apache_get_default_mimetype(r TSRMLS_CC); + + /* Init timeout */ + hard_timeout("send", r); + + php_save_umask(); + add_common_vars(r); + add_cgi_vars(r); + + init_request_info(TSRMLS_C); + apache_php_module_main(r, display_source_mode TSRMLS_CC); + + /* Done, restore umask, turn off timeout, close file and return */ + php_restore_umask(); + kill_timeout(r); + } zend_end_try(); + + return OK; +} +/* }}} */ + +/* {{{ send_parsed_php + */ +static int send_parsed_php(request_rec * r) +{ + int result = send_php(r, 0, NULL); + TSRMLS_FETCH(); + + ap_table_setn(r->notes, "mod_php_memory_usage", + ap_psprintf(r->pool, "%lu", zend_memory_peak_usage(1 TSRMLS_CC))); + + return result; +} +/* }}} */ + +/* {{{ send_parsed_php_source + */ +static int send_parsed_php_source(request_rec * r) +{ + return send_php(r, 1, NULL); +} +/* }}} */ + +/* {{{ destroy_per_dir_entry + */ +static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry) +{ + free(per_dir_entry->key); + free(per_dir_entry->value); +} +/* }}} */ + +/* {{{ copy_per_dir_entry + */ +static void copy_per_dir_entry(php_per_dir_entry *per_dir_entry) +{ + php_per_dir_entry tmp = *per_dir_entry; + + per_dir_entry->key = (char *) malloc(tmp.key_length+1); + memcpy(per_dir_entry->key, tmp.key, tmp.key_length); + per_dir_entry->key[per_dir_entry->key_length] = 0; + + per_dir_entry->value = (char *) malloc(tmp.value_length+1); + memcpy(per_dir_entry->value, tmp.value, tmp.value_length); + per_dir_entry->value[per_dir_entry->value_length] = 0; +} +/* }}} */ + +/* {{{ should_overwrite_per_dir_entry + */ +static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_per_dir_entry *new_per_dir_entry, zend_hash_key *hash_key, void *pData) +{ + php_per_dir_entry *orig_per_dir_entry; + + if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &orig_per_dir_entry)==FAILURE) { + return 1; /* does not exist in dest, copy from source */ + } + + if (orig_per_dir_entry->type==PHP_INI_SYSTEM + && new_per_dir_entry->type!=PHP_INI_SYSTEM) { + return 0; + } else { + return 1; + } +} +/* }}} */ + +/* {{{ php_destroy_per_dir_info + */ +static void php_destroy_per_dir_info(HashTable *per_dir_info) +{ + zend_hash_destroy(per_dir_info); + free(per_dir_info); +} +/* }}} */ + +/* {{{ php_create_dir + */ +static void *php_create_dir(pool *p, char *dummy) +{ + HashTable *per_dir_info; + + per_dir_info = (HashTable *) malloc(sizeof(HashTable)); + zend_hash_init_ex(per_dir_info, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1, 0); + register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy); + + return per_dir_info; +} +/* }}} */ + +/* {{{ php_merge_dir + */ +static void *php_merge_dir(pool *p, void *basev, void *addv) +{ + /* This function *must* not modify addv or basev */ + HashTable *new; + + /* need a copy of addv to merge */ + new = php_create_dir(p, "php_merge_dir"); + zend_hash_copy(new, (HashTable *) basev, (copy_ctor_func_t) copy_per_dir_entry, NULL, sizeof(php_per_dir_entry)); + + zend_hash_merge_ex(new, (HashTable *) addv, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL); + return new; +} +/* }}} */ + +/* {{{ php_apache_value_handler_ex + */ +static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) +{ + php_per_dir_entry per_dir_entry; + + if (!apache_php_initialized) { + apache_php_initialized = 1; +#ifdef ZTS + tsrm_startup(1, 1, 0, NULL); +#endif + sapi_startup(&apache_sapi_module); + php_apache_startup(&apache_sapi_module); + } + per_dir_entry.type = mode; + per_dir_entry.htaccess = ((cmd->override & (RSRC_CONF|ACCESS_CONF)) == 0); + + if (strcasecmp(arg2, "none") == 0) { + arg2 = ""; + } + + per_dir_entry.key_length = strlen(arg1); + per_dir_entry.value_length = strlen(arg2); + + per_dir_entry.key = (char *) malloc(per_dir_entry.key_length+1); + memcpy(per_dir_entry.key, arg1, per_dir_entry.key_length); + per_dir_entry.key[per_dir_entry.key_length] = 0; + + per_dir_entry.value = (char *) malloc(per_dir_entry.value_length+1); + memcpy(per_dir_entry.value, arg2, per_dir_entry.value_length); + per_dir_entry.value[per_dir_entry.value_length] = 0; + + zend_hash_update(conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry), NULL); + return NULL; +} +/* }}} */ + +/* {{{ php_apache_value_handler + */ +static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) +{ + return php_apache_value_handler_ex(cmd, conf, arg1, arg2, PHP_INI_PERDIR); +} +/* }}} */ + +/* {{{ php_apache_admin_value_handler + */ +static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) +{ + return php_apache_value_handler_ex(cmd, conf, arg1, arg2, PHP_INI_SYSTEM); +} +/* }}} */ + +/* {{{ php_apache_flag_handler_ex + */ +static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode) +{ + char bool_val[2]; + + if (!strcasecmp(arg2, "On") || (arg2[0] == '1' && arg2[1] == '\0')) { + bool_val[0] = '1'; + } else { + bool_val[0] = '0'; + } + bool_val[1] = 0; + + return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode); +} +/* }}} */ + +/* {{{ php_apache_flag_handler + */ +static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) +{ + return php_apache_flag_handler_ex(cmd, conf, arg1, arg2, PHP_INI_PERDIR); +} +/* }}} */ + +/* {{{ php_apache_admin_flag_handler + */ +static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2) +{ + return php_apache_flag_handler_ex(cmd, conf, arg1, arg2, PHP_INI_SYSTEM); +} +/* }}} */ + +/* {{{ php_apache_phpini_set + */ +static CONST_PREFIX char *php_apache_phpini_set(cmd_parms *cmd, HashTable *conf, char *arg) +{ + if (apache_sapi_module.php_ini_path_override) { + return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored"; + } + apache_sapi_module.php_ini_path_override = ap_server_root_relative(cmd->pool, arg); + return NULL; +} +/* }}} */ + +/* {{{ int php_xbithack_handler(request_rec * r) + */ +static int php_xbithack_handler(request_rec * r) +{ + HashTable *per_dir_conf; + TSRMLS_FETCH(); + + if (!(r->finfo.st_mode & S_IXUSR)) { + return DECLINED; + } + per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php5_module); + if (per_dir_conf) { + zend_hash_apply((HashTable *) per_dir_conf, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC); + } + if(!AP(xbithack)) { + zend_try { + zend_ini_deactivate(TSRMLS_C); + } zend_end_try(); + return DECLINED; + } + return send_parsed_php(r); +} +/* }}} */ + +/* {{{ apache_php_module_shutdown_wrapper + */ +static void apache_php_module_shutdown_wrapper(void) +{ + apache_php_initialized = 0; + apache_sapi_module.shutdown(&apache_sapi_module); + +#if MODULE_MAGIC_NUMBER >= 19970728 + /* This function is only called on server exit if the apache API + * child_exit handler exists, so shutdown globally + */ + sapi_shutdown(); +#endif + +#ifdef ZTS + tsrm_shutdown(); +#endif +} +/* }}} */ + +#if MODULE_MAGIC_NUMBER >= 19970728 +/* {{{ php_child_exit_handler + */ +static void php_child_exit_handler(server_rec *s, pool *p) +{ +/* apache_php_initialized = 0; */ + apache_sapi_module.shutdown(&apache_sapi_module); + +#ifdef ZTS + tsrm_shutdown(); +#endif +} +/* }}} */ +#endif + +/* {{{ void php_init_handler(server_rec *s, pool *p) + */ +static void php_init_handler(server_rec *s, pool *p) +{ + register_cleanup(p, NULL, (void (*)(void *))apache_php_module_shutdown_wrapper, (void (*)(void *))php_module_shutdown_for_exec); + if (!apache_php_initialized) { + apache_php_initialized = 1; +#ifdef ZTS + tsrm_startup(1, 1, 0, NULL); +#endif + sapi_startup(&apache_sapi_module); + php_apache_startup(&apache_sapi_module); + } +#if MODULE_MAGIC_NUMBER >= 19980527 + { + TSRMLS_FETCH(); + if (PG(expose_php)) { + ap_add_version_component("PHP/" PHP_VERSION); + } + } +#endif +} +/* }}} */ + +/* {{{ handler_rec php_handlers[] + */ +handler_rec php_handlers[] = +{ + {"application/x-httpd-php", send_parsed_php}, + {"application/x-httpd-php-source", send_parsed_php_source}, + {"text/html", php_xbithack_handler}, + {NULL} +}; +/* }}} */ + +/* {{{ command_rec php_commands[] + */ +command_rec php_commands[] = +{ + {"php_value", php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"}, + {"php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"}, + {"php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"}, + {"php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"}, + {"PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, TAKE1, "Directory containing the php.ini file"}, + {NULL} +}; +/* }}} */ + +/* {{{ odule MODULE_VAR_EXPORT php5_module + */ +module MODULE_VAR_EXPORT php5_module = +{ + STANDARD_MODULE_STUFF, + php_init_handler, /* initializer */ + php_create_dir, /* per-directory config creator */ + php_merge_dir, /* dir merger */ + NULL, /* per-server config creator */ + NULL, /* merge server config */ + php_commands, /* command table */ + php_handlers, /* handlers */ + NULL, /* filename translation */ + NULL, /* check_user_id */ + NULL, /* check auth */ + NULL, /* check access */ + NULL, /* type_checker */ + NULL, /* fixups */ + NULL /* logger */ +#if MODULE_MAGIC_NUMBER >= 19970103 + , NULL /* header parser */ +#endif +#if MODULE_MAGIC_NUMBER >= 19970719 + , NULL /* child_init */ +#endif +#if MODULE_MAGIC_NUMBER >= 19970728 + , php_child_exit_handler /* child_exit */ +#endif +#if MODULE_MAGIC_NUMBER >= 19970902 + , NULL /* post read-request */ +#endif +}; +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/sapi/apache/mod_php5.exp b/sapi/apache/mod_php5.exp new file mode 100644 index 0000000..9ad0f0a --- /dev/null +++ b/sapi/apache/mod_php5.exp @@ -0,0 +1 @@ +php5_module diff --git a/sapi/apache/mod_php5.h b/sapi/apache/mod_php5.h new file mode 100644 index 0000000..bdbdd47 --- /dev/null +++ b/sapi/apache/mod_php5.h @@ -0,0 +1,60 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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: Rasmus Lerdorf <rasmus@php.net> | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ + +#ifndef MOD_PHP5_H +#define MOD_PHP5_H + +#if !defined(WIN32) && !defined(WINNT) +#ifndef MODULE_VAR_EXPORT +#define MODULE_VAR_EXPORT +#endif +#endif + +typedef struct { + long engine; + long last_modified; + long xbithack; + long terminate_child; + zend_bool in_request; +} php_apache_info_struct; + +extern zend_module_entry apache_module_entry; + +#ifdef ZTS +extern int php_apache_info_id; +#define AP(v) TSRMG(php_apache_info_id, php_apache_info_struct *, v) +#else +extern php_apache_info_struct php_apache_info; +#define AP(v) (php_apache_info.v) +#endif + +/* fix for gcc4 visibility patch */ +#ifndef PHP_WIN32 +# undef MODULE_VAR_EXPORT +# define MODULE_VAR_EXPORT PHPAPI +#endif + +#endif /* MOD_PHP5_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/sapi/apache/php.sym b/sapi/apache/php.sym new file mode 100644 index 0000000..9ad0f0a --- /dev/null +++ b/sapi/apache/php.sym @@ -0,0 +1 @@ +php5_module diff --git a/sapi/apache/php5apache.dsp b/sapi/apache/php5apache.dsp new file mode 100644 index 0000000..fbdb761 --- /dev/null +++ b/sapi/apache/php5apache.dsp @@ -0,0 +1,151 @@ +# Microsoft Developer Studio Project File - Name="php5apache" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=php5apache - Win32 Release_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 "php5apache.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 "php5apache.mak" CFG="php5apache - Win32 Release_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "php5apache - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "php5apache - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "php5apache - Win32 Release_TS_inline" (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)" == "php5apache - 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 "APACHEPHP5_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /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 php5ts.lib ApacheCore.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 /base:"0x60000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\release" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
+
+!ELSEIF "$(CFG)" == "php5apache - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Debug_TS"
+# PROP Intermediate_Dir "Debug_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 "APACHEPHP5_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /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 php5ts_debug.lib ApacheCore.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 /base:"0x60000000" /version:4.0 /dll /incremental:yes /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\php_build\release" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
+
+!ELSEIF "$(CFG)" == "php5apache - Win32 Release_TS_inline"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS_inline"
+# PROP BASE Intermediate_Dir "Release_TS_inline"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Release_TS_inline"
+# PROP Intermediate_Dir "Release_TS_inline"
+# 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 "APACHEPHP5_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\includes" /I "..\..\main" /I "..\..\TSRM" /I "..\..\regex" /I "C:\Program Files\Apache Group\Apache\include" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /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 php5ts.lib ApacheCore.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 /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\release" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline" /libpath:"C:\Program Files\Apache Group\Apache\libexec"
+
+!ENDIF
+
+# Begin Target
+
+# Name "php5apache - Win32 Release_TS"
+# Name "php5apache - Win32 Debug_TS"
+# Name "php5apache - Win32 Release_TS_inline"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\mod_php5.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\php_apache.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sapi_apache.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\mod_php5.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\php_apache_http.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/sapi/apache/php_apache.c b/sapi/apache/php_apache.c new file mode 100644 index 0000000..3745197 --- /dev/null +++ b/sapi/apache/php_apache.c @@ -0,0 +1,607 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | + | Stig Sæther Bakken <ssb@php.net> | + | David Sklar <sklar@student.net> | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ + +#include "php_apache_http.h" + +#if defined(PHP_WIN32) || defined(NETWARE) +#include "zend.h" +#include "ap_compat.h" +#endif + +#ifdef ZTS +int php_apache_info_id; +#else +php_apache_info_struct php_apache_info; +#endif + +#define SECTION(name) PUTS("<h2>" name "</h2>\n") + +#ifndef PHP_WIN32 +extern module *top_module; +extern module **ap_loaded_modules; +#else +extern __declspec(dllimport) module *top_module; +extern __declspec(dllimport) module **ap_loaded_modules; +#endif + +PHP_FUNCTION(virtual); +PHP_FUNCTION(apache_request_headers); +PHP_FUNCTION(apache_response_headers); +PHP_FUNCTION(apachelog); +PHP_FUNCTION(apache_note); +PHP_FUNCTION(apache_lookup_uri); +PHP_FUNCTION(apache_child_terminate); +PHP_FUNCTION(apache_setenv); +PHP_FUNCTION(apache_get_version); +PHP_FUNCTION(apache_get_modules); +PHP_FUNCTION(apache_reset_timeout); + +PHP_MINFO_FUNCTION(apache); + +ZEND_BEGIN_ARG_INFO(arginfo_apache_child_terminate, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_note, 0, 0, 1) + ZEND_ARG_INFO(0, note_name) + ZEND_ARG_INFO(0, note_value) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_virtual, 0, 0, 1) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_apache_request_headers, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_apache_response_headers, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_setenv, 0, 0, 2) + ZEND_ARG_INFO(0, variable) + ZEND_ARG_INFO(0, value) + ZEND_ARG_INFO(0, walk_to_top) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_apache_lookup_uri, 0, 0, 1) + ZEND_ARG_INFO(0, uri) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_apache_get_version, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_apache_get_modules, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_apache_reset_timeout, 0) +ZEND_END_ARG_INFO() + + + +const zend_function_entry apache_functions[] = { + PHP_FE(virtual, arginfo_apache_virtual) + PHP_FE(apache_request_headers, arginfo_apache_request_headers) + PHP_FE(apache_note, arginfo_apache_note) + PHP_FE(apache_lookup_uri, arginfo_apache_lookup_uri) + PHP_FE(apache_child_terminate, arginfo_apache_child_terminate) + PHP_FE(apache_setenv, arginfo_apache_setenv) + PHP_FE(apache_response_headers, arginfo_apache_response_headers) + PHP_FE(apache_get_version, arginfo_apache_get_version) + PHP_FE(apache_get_modules, arginfo_apache_get_modules) + PHP_FE(apache_reset_timeout, arginfo_apache_reset_timeout) + PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apache_request_headers) + {NULL, NULL, NULL} +}; + + +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache_info_struct, php_apache_info) + STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache_info_struct, php_apache_info) + STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache_info_struct, php_apache_info) + STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateLong, terminate_child, php_apache_info_struct, php_apache_info) +PHP_INI_END() + + + +static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC) +{ + apache_globals->in_request = 0; +} + + +static PHP_MINIT_FUNCTION(apache) +{ +#ifdef ZTS + ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL); +#else + php_apache_globals_ctor(&php_apache_info TSRMLS_CC); +#endif + REGISTER_INI_ENTRIES(); + return SUCCESS; +} + + +static PHP_MSHUTDOWN_FUNCTION(apache) +{ + UNREGISTER_INI_ENTRIES(); + return SUCCESS; +} + +zend_module_entry apache_module_entry = { + STANDARD_MODULE_HEADER, + "apache", + apache_functions, + PHP_MINIT(apache), + PHP_MSHUTDOWN(apache), + NULL, + NULL, + PHP_MINFO(apache), + NO_VERSION_YET, + STANDARD_MODULE_PROPERTIES +}; + +/* {{{ PHP_MINFO_FUNCTION + */ +PHP_MINFO_FUNCTION(apache) +{ + char *apv = (char *) ap_get_server_version(); + module *modp = NULL; + char output_buf[128]; +#if !defined(WIN32) && !defined(WINNT) + char name[64]; + char modulenames[1024]; + char *p; +#endif + server_rec *serv; + extern char server_root[MAX_STRING_LEN]; + extern uid_t user_id; + extern char *user_name; + extern gid_t group_id; + extern int max_requests_per_child; + + serv = ((request_rec *) SG(server_context))->server; + + + php_info_print_table_start(); + +#ifdef PHP_WIN32 + php_info_print_table_row(1, "Apache for Windows 95/NT"); + php_info_print_table_end(); + php_info_print_table_start(); +#elif defined(NETWARE) + php_info_print_table_row(1, "Apache for NetWare"); + php_info_print_table_end(); + php_info_print_table_start(); +#else + php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE); + php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET); +#endif + + if (apv && *apv) { + php_info_print_table_row(2, "Apache Version", apv); + } + +#ifdef APACHE_RELEASE + snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE); + php_info_print_table_row(2, "Apache Release", output_buf); +#endif + snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER); + php_info_print_table_row(2, "Apache API Version", output_buf); + snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port); + php_info_print_table_row(2, "Hostname:Port", output_buf); +#if !defined(WIN32) && !defined(WINNT) + snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id); + php_info_print_table_row(2, "User/Group", output_buf); + snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max); + php_info_print_table_row(2, "Max Requests", output_buf); +#endif + snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout); + php_info_print_table_row(2, "Timeouts", output_buf); +#if !defined(WIN32) && !defined(WINNT) +/* + This block seems to be working on NetWare; But it seems to be showing + all modules instead of just the loaded ones +*/ + php_info_print_table_row(2, "Server Root", server_root); + + strcpy(modulenames, ""); + for(modp = top_module; modp; modp = modp->next) { + strlcpy(name, modp->name, sizeof(name)); + if ((p = strrchr(name, '.'))) { + *p='\0'; /* Cut off ugly .c extensions on module names */ + } + strlcat(modulenames, name, sizeof(modulenames)); + if (modp->next) { + strlcat(modulenames, ", ", sizeof(modulenames)); + } + } + php_info_print_table_row(2, "Loaded Modules", modulenames); +#endif + + php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); + + { + register int i; + array_header *arr; + table_entry *elts; + request_rec *r; + + r = ((request_rec *) SG(server_context)); + arr = table_elts(r->subprocess_env); + elts = (table_entry *)arr->elts; + + SECTION("Apache Environment"); + php_info_print_table_start(); + php_info_print_table_header(2, "Variable", "Value"); + for (i=0; i < arr->nelts; i++) { + php_info_print_table_row(2, elts[i].key, elts[i].val); + } + php_info_print_table_end(); + } + + { + array_header *env_arr; + table_entry *env; + int i; + request_rec *r; + + r = ((request_rec *) SG(server_context)); + SECTION("HTTP Headers Information"); + php_info_print_table_start(); + php_info_print_table_colspan_header(2, "HTTP Request Headers"); + php_info_print_table_row(2, "HTTP Request", r->the_request); + env_arr = table_elts(r->headers_in); + env = (table_entry *)env_arr->elts; + for (i = 0; i < env_arr->nelts; ++i) { + if (env[i].key) { + php_info_print_table_row(2, env[i].key, env[i].val); + } + } + php_info_print_table_colspan_header(2, "HTTP Response Headers"); + env_arr = table_elts(r->headers_out); + env = (table_entry *)env_arr->elts; + for(i = 0; i < env_arr->nelts; ++i) { + if (env[i].key) { + php_info_print_table_row(2, env[i].key, env[i].val); + } + } + php_info_print_table_end(); + } +} +/* }}} */ + +/* {{{ proto bool apache_child_terminate(void) + Terminate apache process after this request */ +PHP_FUNCTION(apache_child_terminate) +{ +#ifndef MULTITHREAD + if (AP(terminate_child)) { + ap_child_terminate( ((request_rec *)SG(server_context)) ); + RETURN_TRUE; + } else { /* tell them to get lost! */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is disabled"); + RETURN_FALSE; + } +#else + php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is not supported in this build"); + RETURN_FALSE; +#endif +} +/* }}} */ + +/* {{{ proto string apache_note(string note_name [, string note_value]) + Get and set Apache request notes */ +PHP_FUNCTION(apache_note) +{ + char *note_name, *note_val = NULL; + int note_name_len, note_val_len; + char *old_val; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", ¬e_name, ¬e_name_len, ¬e_val, ¬e_val_len) == FAILURE) { + return; + } + + old_val = (char *) table_get(((request_rec *)SG(server_context))->notes, note_name); + + if (note_val) { + table_set(((request_rec *)SG(server_context))->notes, note_name, note_val); + } + + if (old_val) { + RETURN_STRING(old_val, 1); + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto bool virtual(string filename) + Perform an Apache sub-request */ +/* This function is equivalent to <!--#include virtual...--> + * in mod_include. It does an Apache sub-request. It is useful + * for including CGI scripts or .shtml files, or anything else + * that you'd parse through Apache (for .phtml files, you'd probably + * want to use <?Include>. This only works when PHP is compiled + * as an Apache module, since it uses the Apache API for doing + * sub requests. + */ +PHP_FUNCTION(virtual) +{ + char *filename; + int filename_len; + request_rec *rr = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { + return; + } + + if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - URI lookup failed", filename); + if (rr) + destroy_sub_req (rr); + RETURN_FALSE; + } + + if (rr->status != 200) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - error finding URI", filename); + if (rr) + destroy_sub_req (rr); + RETURN_FALSE; + } + + php_output_end_all(TSRMLS_C); + php_header(TSRMLS_C); + + if (run_sub_req(rr)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to include '%s' - request execution failed", filename); + if (rr) + destroy_sub_req (rr); + RETURN_FALSE; + } + + if (rr) + destroy_sub_req (rr); + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto array getallheaders(void) + Alias for apache_request_headers() */ +/* }}} */ + +/* {{{ proto array apache_request_headers(void) + Fetch all HTTP request headers */ +PHP_FUNCTION(apache_request_headers) +{ + array_header *env_arr; + table_entry *tenv; + int i; + + array_init(return_value); + env_arr = table_elts(((request_rec *) SG(server_context))->headers_in); + tenv = (table_entry *)env_arr->elts; + for (i = 0; i < env_arr->nelts; ++i) { + if (!tenv[i].key) { + continue; + } + if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) { + RETURN_FALSE; + } + } +} +/* }}} */ + +/* {{{ proto array apache_response_headers(void) + Fetch all HTTP response headers */ +PHP_FUNCTION(apache_response_headers) +{ + array_header *env_arr; + table_entry *tenv; + int i; + + array_init(return_value); + env_arr = table_elts(((request_rec *) SG(server_context))->headers_out); + tenv = (table_entry *)env_arr->elts; + for (i = 0; i < env_arr->nelts; ++i) { + if (!tenv[i].key) continue; + if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) { + RETURN_FALSE; + } + } +} +/* }}} */ + +/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top]) + Set an Apache subprocess_env variable */ +PHP_FUNCTION(apache_setenv) +{ + int var_len, val_len; + zend_bool top=0; + char *var = NULL, *val = NULL; + request_rec *r = (request_rec *) SG(server_context); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) { + return; + } + + while(top) { + if(r->prev) r = r->prev; + else break; + } + + ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len)); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto object apache_lookup_uri(string URI) + Perform a partial request of the given URI to obtain information about it */ +PHP_FUNCTION(apache_lookup_uri) +{ + char *filename; + int filename_len; + request_rec *rr=NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + return; + } + + if (!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed '%s'", filename); + RETURN_FALSE; + } + + object_init(return_value); + add_property_long(return_value,"status", rr->status); + + if (rr->the_request) { + add_property_string(return_value,"the_request", rr->the_request, 1); + } + if (rr->status_line) { + add_property_string(return_value,"status_line", (char *)rr->status_line, 1); + } + if (rr->method) { + add_property_string(return_value,"method", (char *)rr->method, 1); + } + if (rr->content_type) { + add_property_string(return_value,"content_type", (char *)rr->content_type, 1); + } + if (rr->handler) { + add_property_string(return_value,"handler", (char *)rr->handler, 1); + } + if (rr->uri) { + add_property_string(return_value,"uri", rr->uri, 1); + } + if (rr->filename) { + add_property_string(return_value,"filename", rr->filename, 1); + } + if (rr->path_info) { + add_property_string(return_value,"path_info", rr->path_info, 1); + } + if (rr->args) { + add_property_string(return_value,"args", rr->args, 1); + } + if (rr->boundary) { + add_property_string(return_value,"boundary", rr->boundary, 1); + } + + add_property_long(return_value,"no_cache", rr->no_cache); + add_property_long(return_value,"no_local_copy", rr->no_local_copy); + add_property_long(return_value,"allowed", rr->allowed); + add_property_long(return_value,"sent_bodyct", rr->sent_bodyct); + add_property_long(return_value,"bytes_sent", rr->bytes_sent); + add_property_long(return_value,"byterange", rr->byterange); + add_property_long(return_value,"clength", rr->clength); + +#if MODULE_MAGIC_NUMBER >= 19980324 + if (rr->unparsed_uri) { + add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1); + } + if(rr->mtime) { + add_property_long(return_value,"mtime", rr->mtime); + } +#endif + if(rr->request_time) { + add_property_long(return_value,"request_time", rr->request_time); + } + + destroy_sub_req(rr); +} +/* }}} */ + + +#if 0 +/* +This function is most likely a bad idea. Just playing with it for now. +*/ +PHP_FUNCTION(apache_exec_uri) +{ + char *filename; + int filename_len; + request_rec *rr=NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { + return; + } + + if(!(rr = ap_sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "URI lookup failed", filename); + RETURN_FALSE; + } + + RETVAL_LONG(ap_run_sub_req(rr)); + ap_destroy_sub_req(rr); +} +#endif + +/* {{{ proto string apache_get_version(void) + Fetch Apache version */ +PHP_FUNCTION(apache_get_version) +{ + char *apv = (char *) ap_get_server_version(); + + if (apv && *apv) { + RETURN_STRING(apv, 1); + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto array apache_get_modules(void) + Get a list of loaded Apache modules */ +PHP_FUNCTION(apache_get_modules) +{ + int n; + char *p; + + array_init(return_value); + + for (n = 0; ap_loaded_modules[n]; ++n) { + char *s = (char *) ap_loaded_modules[n]->name; + if ((p = strchr(s, '.'))) { + add_next_index_stringl(return_value, s, (p - s), 1); + } else { + add_next_index_string(return_value, s, 1); + } + } +} +/* }}} */ + +/* {{{ proto bool apache_reset_timeout(void) + Reset the Apache write timer */ +PHP_FUNCTION(apache_reset_timeout) +{ + ap_reset_timeout((request_rec *)SG(server_context)); + RETURN_TRUE; +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/sapi/apache/php_apache_http.h b/sapi/apache/php_apache_http.h new file mode 100644 index 0000000..12788d3 --- /dev/null +++ b/sapi/apache/php_apache_http.h @@ -0,0 +1,70 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | + | Stig Sæther Bakken <ssb@php.net> | + | David Sklar <sklar@student.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#define NO_REGEX_EXTRA_H + +#ifdef WIN32 +#include <stddef.h> +#endif + +#ifdef NETWARE +#include <netinet/in.h> +#endif + +#include "zend.h" +#include "ext/ereg/php_regex.h" +#include "php_compat.h" + +#ifdef HAVE_OPENSSL_EXT +/* zlib typedefs free_func which causes problems if the SSL includes happen + * after zlib.h is included */ +# include <openssl/ssl.h> +#endif + +#ifdef regex_t +#undef regex_t +#endif + +#include "httpd.h" +#include "http_config.h" + +#if MODULE_MAGIC_NUMBER > 19980712 +# include "ap_compat.h" +#else +# if MODULE_MAGIC_NUMBER > 19980324 +# include "compat.h" +# endif +#endif + +#include "http_core.h" +#include "http_main.h" +#include "http_protocol.h" +#include "http_request.h" +#include "http_log.h" +#include "util_script.h" + +#include "php_variables.h" +#include "php_main.h" +#include "php_ini.h" +#include "ext/standard/php_standard.h" + +#include "mod_php5.h" diff --git a/sapi/apache/sapi_apache.c b/sapi/apache/sapi_apache.c new file mode 100644 index 0000000..88c9985 --- /dev/null +++ b/sapi/apache/sapi_apache.c @@ -0,0 +1,73 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.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: Rasmus Lerdorf <rasmus@php.net> | + | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> | + | PHP 4.0 patches by: | + | Zeev Suraski <zeev@zend.com> | + | Stig Bakken <ssb@php.net> | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ + +#include "php_apache_http.h" + +/* {{{ apache_php_module_main + */ +int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC) +{ + int retval = OK; + zend_file_handle file_handle; + + if (php_request_startup(TSRMLS_C) == FAILURE) { + return FAILURE; + } + /* sending a file handle to another dll is not working + so let zend open it. */ + + if (display_source_mode) { + zend_syntax_highlighter_ini syntax_highlighter_ini; + + php_get_highlight_struct(&syntax_highlighter_ini); + if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC) != SUCCESS) { + retval = NOT_FOUND; + } + } else { + file_handle.type = ZEND_HANDLE_FILENAME; + file_handle.handle.fd = 0; + file_handle.filename = SG(request_info).path_translated; + file_handle.opened_path = NULL; + file_handle.free_filename = 0; + + (void) php_execute_script(&file_handle TSRMLS_CC); + } + + AP(in_request) = 0; + + zend_try { + php_request_shutdown(NULL); + } zend_end_try(); + + return retval; +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ |