--- /dev/null
+
+LTLIBRARY_NAME = libsapi.la
+LTLIBRARY_SOURCES = sapi_apache.c mod_php4.c php_apache.c
+
+EXTRA_INCLUDES = $(APACHE_INCLUDE)
+
+include $(top_srcdir)/build/ltlib.mk
--- /dev/null
+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.
--- /dev/null
+##
+## Apache 1.3 Makefile template for PHP 4.0 Module
+## [src/modules/php4/Makefile.tmpl]
+##
+
+# the parametrized target
+LIB=libphp4.$(LIBEXT)
+
+# objects for building the static library
+OBJS=mod_php4.o
+OBJS_LIB=libmodphp4.a
+
+# objects for building the shared object library
+SHLIB_OBJS=mod_php4.so-o
+SHLIB_OBJS_LIB=libmodphp4.a
+
+# the general targets
+all: lib
+lib: $(LIB)
+
+# build the static library by merging the object files
+libphp4.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
+libphp4.: $(OBJS) $(OBJS_LIB)
+ cp $(OBJS_LIB) $@
+ ar r $@ $(OBJS)
+ $(RANLIB) $@
+ cp libphp4. libphp4.a
+
+# build the shared object library by linking the object files
+libphp4.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB)
+ rm -f $@
+ $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(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) $(SPACER) $<
+.c.so-o:
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $(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) *.c >> Makefile.new \
+ && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' Makefile.new \
+ > Makefile.tmpl \
+ && rm Makefile.new
+
+#Dependencies
+
+$(OBJS): Makefile
+
+# DO NOT REMOVE
+mod_php4.o: mod_php4.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_php4.h
--- /dev/null
+dnl ## -*- sh -*-
+
+AC_DEFUN(PHP_APACHE_CHECK_RDYNAMIC,[
+ if test -n "$GCC"; then
+ dnl we should use a PHP-specific macro here
+ TSRM_CHECK_GCC_ARG(-rdynamic, gcc_rdynamic=yes)
+ if test "$gcc_rdynamic" = "yes"; then
+ PHP_LDFLAGS="$PHP_LDFLAGS -rdynamic"
+ fi
+ fi
+])
+
+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".],[
+ if test "$withval" = "yes"; then
+ APXS=apxs
+ if $APXS -q CFLAGS >/dev/null 2>&1; then
+ :
+ else
+ if test -x /usr/sbin/apxs ; then #SUSE 6.x
+ APXS=/usr/sbin/apxs
+ fi
+ fi
+ else
+ AC_EXPAND_PATH($withval, APXS)
+ fi
+
+ if $APXS -q CFLAGS >/dev/null 2>&1; then
+ :
+ else
+ AC_MSG_RESULT()
+ $APXS
+ AC_MSG_ERROR([Sorry, I cannot run apxs. Either you need to install Perl or you need to pass the absolute path of apxs by using --with-apxs=/absolute/path/to/apxs])
+ fi
+
+ APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@"
+ APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR`
+ APXS_CFLAGS=`$APXS -q CFLAGS`
+ AC_ADD_INCLUDE($APXS_INCLUDEDIR)
+ if `echo $APXS_CFLAGS|grep USE_HSREGEX>/dev/null`; then
+ APACHE_HAS_REGEX=yes
+ fi
+ if `echo $APXS_CFLAGS|grep EAPI>/dev/null`; then
+ CPPFLAGS="$CPPFLAGS -DEAPI"
+ fi
+ PHP_SAPI=apache
+ APACHE_INSTALL="$APXS -i -a -n php4 $SAPI_SHARED"
+ PHP_BUILD_SHARED
+ 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_MSG_RESULT(yes)
+],[
+ AC_MSG_RESULT(no)
+])
+
+APACHE_INSTALL_FILES="\$(srcdir)/sapi/apache/mod_php4.* sapi/apache/libphp4.module"
+
+if test "$PHP_SAPI" != "apache"; 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
+ APACHE_MODULE=yes
+ 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
+ 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 $withval/src/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
+ fi
+ # For Apache 2.0.x
+ elif test -f $withval/src/include/httpd.h &&
+ test -f $withval/src/lib/apr/include/apr_general.h ; then
+ APACHE_HAS_REGEX=1
+ APACHE_INCLUDE="-I$withval/src/include -I$withval/src/os/unix -I$withval/src/lib/apr/include"
+ APACHE_TARGET=$withval/src/modules/php4
+ if test ! -d $APACHE_TARGET; then
+ mkdir $APACHE_TARGET
+ fi
+ PHP_SAPI=apache
+ APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.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/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
+ AC_MSG_RESULT(yes - Apache 2.0.X)
+ STRONGHOLD=
+ if test -f $withval/src/include/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
+ fi
+ if test -f $withval/src/include/ap_compat.h; then
+ AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
+ 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,1,[ ])
+ fi
+ fi
+ # For Apache 1.3.x
+ elif test -f $withval/src/main/httpd.h; then
+ APACHE_HAS_REGEX=1
+ 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
+ APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.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/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
+ 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,1,[ ])
+ fi
+ if test -f $withval/src/include/ap_compat.h; then
+ AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
+ 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,1,[ ])
+ fi
+ fi
+ # Also for Apache 1.3.x
+ elif test -f $withval/src/include/httpd.h; then
+ APACHE_HAS_REGEX=1
+ APACHE_INCLUDE="-I$withval/src/include -I$withval/src/os/unix"
+ APACHE_TARGET=$withval/src/modules/php4
+ if test ! -d $APACHE_TARGET; then
+ mkdir $APACHE_TARGET
+ fi
+ PHP_SAPI=apache
+ PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
+ APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.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 $withval/src/include/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
+ fi
+ if test -f $withval/src/include/ap_compat.h; then
+ AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
+ 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,1,[ ])
+ 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
+ PHP_LIBS="-Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4"
+ APACHE_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp4.a; cp $APACHE_INSTALL_FILES $APACHE_TARGET"
+ STRONGHOLD=-DSTRONGHOLD=1
+ AC_MSG_RESULT(yes - StrongHold)
+ if test -f $withval/apache/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
+ fi
+ if test -f $withval/src/ap_compat.h; then
+ AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
+ 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,1,[ ])
+ 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"
+fi
+
+if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then
+ APXS_EXP="-bE:sapi/apache/mod_php4.exp"
+fi
+
+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)
+
+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,1,[ ])
+],[
+ AC_MSG_RESULT(no)
+])
+
+if test -n "$APACHE_MODULE"; then
+ PHP_APACHE_CHECK_RDYNAMIC
+ $php_shtool mkdir -p sapi/apache
+ PHP_OUTPUT(sapi/apache/libphp4.module)
+ PHP_BUILD_STATIC
+fi
+
+if test -n "$APACHE_INSTALL"; then
+ INSTALL_IT=$APACHE_INSTALL
+fi
+
+dnl ## Local Variables:
+dnl ## tab-width: 4
+dnl ## End:
--- /dev/null
+Name: php4_module
+ConfigStart
+ RULE_WANTHSREGEX=no
+ LIBS=" -Wl,-rpath,/home/rasmus/gd-1.8 -Wl,-rpath,/usr/local/lib/mysql -Wl,-rpath,/usr/local/lib -rdynamic -L/home/rasmus/gd-1.8 -L/usr/local/lib/mysql -L/usr/local/lib -Lmodules/php4 -L../modules/php4 -L../../modules/php4 -lmodphp4 -lgdbm -lpam -ldl -lpdf -ltiff -ltiff -lpng -lpng -ljpeg -ljpeg -lmysqlclient -lldap -llber -lttf -lpng -lz -lgd -lresolv -lm -ldl -lcrypt -lnsl -lresolv -lz -ljpeg -lpng -ltiff $LIBS"
+ RULE_HIDE=yes
+ CFLAGS="$CFLAGS -I/home/rasmus/php4 -I/home/rasmus/php4/main -I/home/rasmus/php4/main -I/home/rasmus/php4/Zend -I/home/rasmus/php4/Zend -I/home/rasmus/php4"
+ConfigEnd
--- /dev/null
+Name: php4_module
+ConfigStart
+ RULE_WANTHSREGEX=no
+ LIBS="@NATIVE_RPATHS@ @PHP_LDFLAGS@ @PHP_LIBS@ @EXTRA_LIBS@ $LIBS"
+ RULE_HIDE=yes
+ CFLAGS="$CFLAGS -I@abs_srcdir@ -I@abs_srcdir@/main -I@abs_builddir@/main -I@abs_srcdir@/Zend -I@abs_builddir@/Zend -I@abs_builddir@/TSRM -I@abs_srcdir@/TSRM -I@abs_builddir@"
+ConfigEnd
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 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_02.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: |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#define NO_REGEX_EXTRA_H
+#ifdef WIN32
+#include <winsock2.h>
+#include <stddef.h>
+#endif
+
+#include "zend.h"
+#include "php.h"
+#include "php_variables.h"
+
+#include "apr_strings.h"
+#include "ap_buckets.h"
+#include "util_filter.h"
+#include "ap_config.h"
+#include "httpd.h"
+#include "http_config.h"
+#include "http_request.h"
+#include "http_core.h"
+#include "http_protocol.h"
+#include "http_main.h"
+#include "http_log.h"
+#include "util_script.h"
+#include "http_conf_globals.h"
+
+#include "php_ini.h"
+#include "php_globals.h"
+#include "SAPI.h"
+#include "php_main.h"
+
+#include "zend_compile.h"
+#include "zend_execute.h"
+#include "zend_highlight.h"
+#include "zend_indent.h"
+
+#include "ext/standard/php_standard.h"
+
+#include "util_script.h"
+
+#include "mod_php4.h"
+
+#undef shutdown
+
+int apache_php_module_main(request_rec *r, int display_source_mode CLS_DC ELS_DC PLS_DC SLS_DC);
+void php_save_umask(void);
+void php_restore_umask(void);
+int sapi_apache_read_post(char *buffer, uint count_bytes SLS_DC);
+char *sapi_apache_read_cookies(SLS_D);
+int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC);
+int sapi_apache_send_headers(sapi_headers_struct *sapi_headers SLS_DC);
+int send_php(request_rec *r, int display_source_mode, char *filename);
+int send_parsed_php(request_rec * r);
+int send_parsed_php_source(request_rec * r);
+int php_xbithack_handler(request_rec * r);
+void php_init_handler(server_rec *s, pool *p);
+
+static void php_child_exit_handler(server_rec *s, pool *p);
+
+#define CONST_PREFIX const
+CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+
+/* ### these should be defined in mod_php4.h or somewhere else */
+#define USE_PATH 1
+#define IGNORE_URL 2
+
+module MODULE_VAR_EXPORT php4_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;
+} php_per_dir_entry;
+
+php_apache_info_struct php_apache_info; /* active config */
+
+/* some systems are missing these from their header files */
+
+void php_save_umask(void)
+{
+ saved_umask = umask(077);
+ umask(saved_umask);
+}
+
+
+static int sapi_apache_ub_write(const char *str, uint str_length)
+{
+ int ret;
+ SLS_FETCH();
+ PLS_FETCH();
+
+ if (SG(server_context)) {
+ ret = ap_rwrite(str, str_length, (request_rec *) SG(server_context));
+ } else {
+ ret = fwrite(str, 1, str_length, stderr);
+ }
+ if(ret != str_length) {
+ PG(connection_status) = PHP_CONNECTION_ABORTED;
+ if (!PG(ignore_user_abort)) {
+ zend_bailout();
+ }
+ }
+ return ret;
+}
+
+
+
+static void sapi_apache_flush(void *server_context)
+{
+ if (server_context) {
+ ap_rflush((request_rec *) server_context);
+ }
+}
+
+
+int sapi_apache_read_post(char *buffer, uint count_bytes SLS_DC)
+{
+ uint total_read_bytes=0, read_bytes;
+ request_rec *r = (request_rec *) SG(server_context);
+ void (*handler)(int);
+
+ 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;
+}
+
+
+char *sapi_apache_read_cookies(SLS_D)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE");
+}
+
+
+int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC)
+{
+ char *header_name, *header_content, *p;
+ request_rec *r = (request_rec *) SG(server_context);
+
+ 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, "Set-Cookie")) {
+ table_add(r->headers_out, header_name, header_content);
+ } else {
+ table_set(r->headers_out, header_name, header_content);
+ }
+
+ *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
+
+ efree(sapi_header->header);
+
+ return 0; /* don't use the default SAPI mechanism, Apache duplicates this functionality */
+}
+
+
+int sapi_apache_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
+{
+ if(SG(server_context) == NULL) { /* server_context is not here anymore */
+ return SAPI_HEADER_SEND_FAILED;
+ }
+
+ ((request_rec *) SG(server_context))->status = SG(sapi_headers).http_response_code;
+ send_http_header((request_rec *) SG(server_context));
+ return SAPI_HEADER_SENT_SUCCESSFULLY;
+}
+
+
+static void sapi_apache_register_server_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
+{
+ register int i;
+ array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
+ table_entry *elts = (table_entry *) arr->elts;
+ char *script_filename=NULL;
+
+ for (i = 0; i < arr->nelts; i++) {
+ char *val;
+
+ if (elts[i].val) {
+ val = elts[i].val;
+ if (!strcmp(elts[i].key, "SCRIPT_FILENAME")) {
+ script_filename = val;
+ }
+ } else {
+ val = empty_string;
+ }
+ php_register_variable(elts[i].key, val, track_vars_array ELS_CC PLS_CC);
+ }
+
+ /* insert special variables */
+ if (script_filename) {
+ php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array ELS_CC PLS_CC);
+ }
+ php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array ELS_CC PLS_CC);
+}
+
+static int php_apache_startup(sapi_module_struct *sapi_module)
+{
+ if(php_module_startup(sapi_module) == FAILURE
+ || zend_startup_module(&apache_module_entry) == FAILURE) {
+ return FAILURE;
+ } else {
+ return SUCCESS;
+ }
+}
+
+
+static void php_apache_log_message(char *message)
+{
+ SLS_FETCH();
+
+ if (SG(server_context)) {
+ aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message);
+ } else {
+ fprintf(stderr, "%s", message);
+ fprintf(stderr, "\n");
+ }
+}
+
+
+static void php_apache_request_shutdown(void *dummy)
+{
+ SLS_FETCH();
+
+ SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */
+ php_request_shutdown(dummy);
+}
+
+
+static int php_apache_sapi_activate(SLS_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(((request_rec *) SG(server_context))->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec);
+ 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;
+}
+
+
+static struct stat *php_apache_get_stat(SLS_D)
+{
+ return &((request_rec *) SG(server_context))->finfo;
+}
+
+
+static char *php_apache_getenv(char *name, size_t name_len SLS_DC)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name);
+}
+
+
+static sapi_module_struct sapi_module_conf = {
+ "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 */
+
+#ifdef PHP_WIN32
+ NULL,
+ NULL,
+#else
+ block_alarms, /* Block interruptions */
+ unblock_alarms, /* Unblock interruptions */
+#endif
+
+ STANDARD_SAPI_MODULE_PROPERTIES
+};
+
+
+void php_restore_umask(void)
+{
+ umask(saved_umask);
+}
+
+
+static void init_request_info(SLS_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;
+
+ 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 ? atoi(content_length) : 0);
+ SG(sapi_headers).http_response_code = r->status;
+
+ if (r->headers_in) {
+ authorization = table_get(r->headers_in, "Authorization");
+ }
+ if (authorization
+/* && !auth_type(r) */
+ && !strcasecmp(getword(r->pool, &authorization, ' '), "Basic")) {
+ tmp = uudecode(r->pool, authorization);
+ SG(request_info).auth_user = getword_nulls_nc(r->pool, &tmp, ':');
+ if (SG(request_info).auth_user) {
+ r->connection->user = pstrdup(r->connection->pool,SG(request_info).auth_user);
+ r->connection->ap_auth_type = "Basic";
+ SG(request_info).auth_user = estrdup(SG(request_info).auth_user);
+ }
+ SG(request_info).auth_password = tmp;
+ if (SG(request_info).auth_password) {
+ SG(request_info).auth_password = estrdup(SG(request_info).auth_password);
+ }
+ } else {
+ SG(request_info).auth_user = NULL;
+ SG(request_info).auth_password = NULL;
+ }
+}
+
+
+static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry)
+{
+ php_alter_ini_entry(per_dir_entry->key, per_dir_entry->key_length+1, per_dir_entry->value, per_dir_entry->value_length+1, per_dir_entry->type, PHP_INI_STAGE_ACTIVATE);
+ return 0;
+}
+
+static char *php_apache_get_default_mimetype(request_rec *r SLS_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(SLS_C);
+ mimetype = pstrdup(r->pool, tmpmimetype);
+ efree(tmpmimetype);
+ } else {
+ mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET;
+ }
+ return mimetype;
+}
+
+int send_php(request_rec *r, int display_source_mode, char *filename)
+{
+ int retval;
+ HashTable *per_dir_conf;
+ SLS_FETCH();
+ ELS_FETCH();
+ CLS_FETCH();
+ PLS_FETCH();
+
+ if (setjmp(EG(bailout))!=0) {
+ return OK;
+ }
+ per_dir_conf = (HashTable *) ap_get_module_config(r->per_dir_config, &php4_module);
+ if (per_dir_conf) {
+ zend_hash_apply((HashTable *) per_dir_conf, (int (*)(void *)) php_apache_alter_ini_entries);
+ }
+
+ /* We don't accept OPTIONS requests, but take everything else */
+ if (r->method_number == M_OPTIONS) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+
+ /* Make sure file exists */
+ if (filename == NULL && r->finfo.st_mode == 0) {
+ return DECLINED;
+ }
+
+ /* If PHP parser engine has been turned off with an "engine off"
+ * directive, then decline to handle this request
+ */
+ if (!php_apache_info.engine) {
+ r->content_type = php_apache_get_default_mimetype(r SLS_CC);
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ if (filename == NULL) {
+ filename = r->filename;
+ }
+
+ if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))
+ return retval;
+ if (php_apache_info.last_modified) {
+ ap_update_mtime (r, r->finfo.st_mtime);
+ ap_set_last_modified(r);
+ ap_set_etag(r);
+ }
+ /* 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 SLS_CC);
+
+ SG(server_context) = r;
+
+ php_save_umask();
+ ap_add_common_vars(r);
+ ap_add_cgi_vars(r);
+
+ init_request_info(SLS_C);
+ apache_php_module_main(r, display_source_mode CLS_CC ELS_CC PLS_CC SLS_CC);
+
+ /* Done, restore umask, turn off timeout, close file and return */
+ php_restore_umask();
+ return OK;
+}
+
+
+int send_parsed_php(request_rec * r)
+{
+ return send_php(r, 0, NULL);
+}
+
+
+int send_parsed_php_source(request_rec * r)
+{
+ return send_php(r, 1, NULL);
+}
+
+
+static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry)
+{
+ free(per_dir_entry->key);
+ free(per_dir_entry->value);
+}
+
+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;
+}
+
+
+static zend_bool should_overwrite_per_dir_entry(php_per_dir_entry *orig_per_dir_entry, php_per_dir_entry *new_per_dir_entry)
+{
+ if (new_per_dir_entry->type==PHP_INI_SYSTEM
+ && orig_per_dir_entry->type!=PHP_INI_SYSTEM) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+
+static void php_destroy_per_dir_info(HashTable *per_dir_info)
+{
+ zend_hash_destroy(per_dir_info);
+ free(per_dir_info);
+}
+
+
+static void *php_create_dir(pool *p, char *dummy)
+{
+ HashTable *per_dir_info;
+
+ per_dir_info = (HashTable *) malloc(sizeof(HashTable));
+ zend_hash_init(per_dir_info, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1);
+ register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy);
+
+ return per_dir_info;
+}
+
+
+static void *php_merge_dir(pool *p, void *basev, void *addv)
+{
+ php_per_dir_entry tmp;
+
+ /* This function *must* return addv, and not modify basev */
+ zend_hash_merge_ex((HashTable *) addv, (HashTable *) basev, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (zend_bool (*)(void *, void *)) should_overwrite_per_dir_entry);
+ /*zend_hash_merge((HashTable *) addv, (HashTable *) basev, (void (*)(void *)) copy_per_dir_entry, &tmp, sizeof(php_per_dir_entry), 0);*/
+ return addv;
+}
+
+
+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);
+#endif
+ sapi_startup(&sapi_module_conf);
+ php_apache_startup(&sapi_module_conf);
+ }
+ per_dir_entry.type = mode;
+
+ 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((HashTable *) conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry), NULL);
+ return NULL;
+}
+
+
+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);
+}
+
+
+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);
+}
+
+
+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")) {
+ 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);
+}
+
+
+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);
+}
+
+
+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);
+}
+
+
+
+
+int php_xbithack_handler(request_rec * r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *) get_module_config(r->per_dir_config, &php4_module);
+ if (!(r->finfo.st_mode & S_IXUSR)) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ if (conf->xbithack == 0) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ return send_parsed_php(r);
+}
+
+static void apache_php_module_shutdown_wrapper(void)
+{
+ apache_php_initialized = 0;
+ sapi_module_conf.shutdown(&sapi_module_conf);
+
+ /* This function is only called on server exit if the apache API
+ * child_exit handler exists, so shutdown globally
+ */
+ sapi_shutdown();
+
+#ifdef ZTS
+ tsrm_shutdown();
+#endif
+}
+
+static void php_child_exit_handler(server_rec *s, pool *p)
+{
+/* apache_php_initialized = 0; */
+ sapi_module_conf.shutdown(&sapi_module_conf);
+
+#ifdef ZTS
+ tsrm_shutdown();
+#endif
+}
+
+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);
+#endif
+ sapi_startup(&sapi_module_conf);
+ php_apache_startup(&sapi_module_conf);
+ }
+ {
+ PLS_FETCH();
+ if (PG(expose_php)) {
+ ap_add_version_component("PHP/" PHP_VERSION);
+ }
+ }
+}
+
+
+#if HAVE_MOD_DAV
+
+extern int phpdav_mkcol_test_handler(request_rec *r);
+extern int phpdav_mkcol_create_handler(request_rec *r);
+
+/* conf is being read twice (both here and in send_php()) */
+int send_parsed_php_dav_script(request_rec *r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *) get_module_config(r->per_dir_config,
+ &php4_module);
+ return send_php(r, 0, 0, conf->dav_script);
+}
+
+static int php_type_checker(request_rec *r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *)get_module_config(r->per_dir_config,
+ &php4_module);
+
+ /* If DAV support is enabled, use mod_dav's type checker. */
+ if (conf->dav_script) {
+ dav_api_set_request_handler(r, send_parsed_php_dav_script);
+ dav_api_set_mkcol_handlers(r, phpdav_mkcol_test_handler,
+ phpdav_mkcol_create_handler);
+ /* leave the rest of the request to mod_dav */
+ return dav_api_type_checker(r);
+ }
+
+ return DECLINED;
+}
+
+static const 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[] =
+{
+ {"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)"},
+ {NULL}
+};
+
+module AP_MODULE_DECLARE_DATA php_module =
+{
+ STANDARD20_MODULE_STUFF,
+ php_create_dir, /* dir config creater */
+ php_merge_dir, /* dir merger --- default is to override */
+ NULL, /* server config */
+ NULL, /* merge server config */
+ php_commands, /* command apr_table_t */
+ php_handlers, /* handlers */
+ NULL /* register hooks */
+};
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
--- /dev/null
+***************
+*** 321,327 ****
+ }
+
+
+- static sapi_module_struct sapi_module = {
+ "apache", /* name */
+ "Apache", /* pretty name */
+
+--- 321,327 ----
+ }
+
+
++ static sapi_module_struct sapi_module_conf = {
+ "apache", /* name */
+ "Apache", /* pretty name */
+
+***************
+*** 576,583 ****
+ #ifdef ZTS
+ tsrm_startup(1, 1, 0);
+ #endif
+- sapi_startup(&sapi_module);
+- php_apache_startup(&sapi_module);
+ }
+ per_dir_entry.type = mode;
+
+--- 576,583 ----
+ #ifdef ZTS
+ tsrm_startup(1, 1, 0);
+ #endif
++ sapi_startup(&sapi_module_conf);
++ php_apache_startup(&sapi_module_conf);
+ }
+ per_dir_entry.type = mode;
+
+***************
+*** 661,667 ****
+ static void apache_php_module_shutdown_wrapper(void)
+ {
+ apache_php_initialized = 0;
+- sapi_module.shutdown(&sapi_module);
+
+ #if MODULE_MAGIC_NUMBER >= 19970728
+ /* This function is only called on server exit if the apache API
+--- 661,667 ----
+ static void apache_php_module_shutdown_wrapper(void)
+ {
+ apache_php_initialized = 0;
++ sapi_module.shutdown(&sapi_module_conf);
+
+ #if MODULE_MAGIC_NUMBER >= 19970728
+ /* This function is only called on server exit if the apache API
+***************
+*** 679,685 ****
+ static void php_child_exit_handler(server_rec *s, pool *p)
+ {
+ /* apache_php_initialized = 0; */
+- sapi_module.shutdown(&sapi_module);
+
+ #ifdef ZTS
+ tsrm_shutdown();
+--- 679,685 ----
+ static void php_child_exit_handler(server_rec *s, pool *p)
+ {
+ /* apache_php_initialized = 0; */
++ sapi_module.shutdown(&sapi_module_conf);
+
+ #ifdef ZTS
+ tsrm_shutdown();
+***************
+*** 695,702 ****
+ #ifdef ZTS
+ tsrm_startup(1, 1, 0);
+ #endif
+- sapi_startup(&sapi_module);
+- php_apache_startup(&sapi_module);
+ }
+ #if MODULE_MAGIC_NUMBER >= 19980527
+ {
+--- 695,702 ----
+ #ifdef ZTS
+ tsrm_startup(1, 1, 0);
+ #endif
++ sapi_startup(&sapi_module_conf);
++ php_apache_startup(&sapi_module_conf);
+ }
+ #if MODULE_MAGIC_NUMBER >= 19980527
+ {
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 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_02.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$ */
+
+#define NO_REGEX_EXTRA_H
+#ifdef WIN32
+#include <winsock2.h>
+#include <stddef.h>
+#endif
+
+#include "zend.h"
+#include "php.h"
+#include "php_variables.h"
+#include "SAPI.h"
+
+#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 "php_ini.h"
+#include "php_globals.h"
+#include "SAPI.h"
+#include "php_main.h"
+
+#include "zend_compile.h"
+#include "zend_execute.h"
+#include "zend_highlight.h"
+#include "zend_indent.h"
+
+#include "ext/standard/php_standard.h"
+
+#include "util_script.h"
+
+#include "mod_php4.h"
+#if HAVE_MOD_DAV
+# include "mod_dav.h"
+#endif
+
+int apache_php_module_main(request_rec *r, int display_source_mode CLS_DC ELS_DC PLS_DC SLS_DC);
+void php_save_umask(void);
+void php_restore_umask(void);
+int sapi_apache_read_post(char *buffer, uint count_bytes SLS_DC);
+char *sapi_apache_read_cookies(SLS_D);
+int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC);
+int sapi_apache_send_headers(sapi_headers_struct *sapi_headers SLS_DC);
+int send_php(request_rec *r, int display_source_mode, char *filename);
+int send_parsed_php(request_rec * r);
+int send_parsed_php_source(request_rec * r);
+int php_xbithack_handler(request_rec * r);
+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
+CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+
+/* ### these should be defined in mod_php4.h or somewhere else */
+#define USE_PATH 1
+#define IGNORE_URL 2
+
+module MODULE_VAR_EXPORT php4_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;
+} php_per_dir_entry;
+
+php_apache_info_struct php_apache_info; /* active config */
+
+/* some systems are missing these from their header files */
+
+void php_save_umask(void)
+{
+ saved_umask = umask(077);
+ umask(saved_umask);
+}
+
+
+static int sapi_apache_ub_write(const char *str, uint str_length)
+{
+ int ret;
+ SLS_FETCH();
+ PLS_FETCH();
+
+ if (SG(server_context)) {
+ ret = rwrite(str, str_length, (request_rec *) SG(server_context));
+ } else {
+ ret = fwrite(str, 1, str_length, stderr);
+ }
+ if(ret != str_length) {
+ PG(connection_status) = PHP_CONNECTION_ABORTED;
+ if (!PG(ignore_user_abort)) {
+ zend_bailout();
+ }
+ }
+ return ret;
+}
+
+
+
+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
+ }
+}
+
+
+int sapi_apache_read_post(char *buffer, uint count_bytes SLS_DC)
+{
+ uint total_read_bytes=0, read_bytes;
+ request_rec *r = (request_rec *) SG(server_context);
+ void (*handler)(int);
+
+ 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;
+}
+
+
+char *sapi_apache_read_cookies(SLS_D)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE");
+}
+
+
+int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC)
+{
+ char *header_name, *header_content, *p;
+ request_rec *r = (request_rec *) SG(server_context);
+
+ 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, "Set-Cookie")) {
+ table_add(r->headers_out, header_name, header_content);
+ } else {
+ table_set(r->headers_out, header_name, header_content);
+ }
+
+ *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
+
+ efree(sapi_header->header);
+
+ return 0; /* don't use the default SAPI mechanism, Apache duplicates this functionality */
+}
+
+
+int sapi_apache_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
+{
+ if(SG(server_context) == NULL) { /* server_context is not here anymore */
+ return SAPI_HEADER_SEND_FAILED;
+ }
+
+ ((request_rec *) SG(server_context))->status = SG(sapi_headers).http_response_code;
+ send_http_header((request_rec *) SG(server_context));
+ return SAPI_HEADER_SENT_SUCCESSFULLY;
+}
+
+
+static void sapi_apache_register_server_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
+{
+ register int i;
+ array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
+ table_entry *elts = (table_entry *) arr->elts;
+ char *script_filename=NULL;
+
+ for (i = 0; i < arr->nelts; i++) {
+ char *val;
+
+ if (elts[i].val) {
+ val = elts[i].val;
+ if (!strcmp(elts[i].key, "SCRIPT_FILENAME")) {
+ script_filename = val;
+ }
+ } else {
+ val = empty_string;
+ }
+ php_register_variable(elts[i].key, val, track_vars_array ELS_CC PLS_CC);
+ }
+
+ /* insert special variables */
+ if (script_filename) {
+ php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array ELS_CC PLS_CC);
+ }
+ php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array ELS_CC PLS_CC);
+}
+
+static int php_apache_startup(sapi_module_struct *sapi_module)
+{
+ if(php_module_startup(sapi_module) == FAILURE
+ || zend_startup_module(&apache_module_entry) == FAILURE) {
+ return FAILURE;
+ } else {
+ return SUCCESS;
+ }
+}
+
+
+static void php_apache_log_message(char *message)
+{
+ SLS_FETCH();
+
+ 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, ((requset_rec *) SG(server_context))->server);
+#endif
+ } else {
+ fprintf(stderr, message);
+ fprintf(stderr, "\n");
+ }
+}
+
+
+static void php_apache_request_shutdown(void *dummy)
+{
+ SLS_FETCH();
+
+ SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */
+ php_request_shutdown(dummy);
+}
+
+
+static int php_apache_sapi_activate(SLS_D)
+{
+ /*
+ * 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(((request_rec *) SG(server_context))->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec);
+ unblock_alarms();
+ return SUCCESS;
+}
+
+
+static struct stat *php_apache_get_stat(SLS_D)
+{
+ return &((request_rec *) SG(server_context))->finfo;
+}
+
+
+static char *php_apache_getenv(char *name, int name_len SLS_DC)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name);
+}
+
+
+static sapi_module_struct 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 */
+
+#ifdef PHP_WIN32
+ NULL,
+ NULL,
+#else
+ block_alarms, /* Block interruptions */
+ unblock_alarms, /* Unblock interruptions */
+#endif
+
+ STANDARD_SAPI_MODULE_PROPERTIES
+};
+
+
+void php_restore_umask(void)
+{
+ umask(saved_umask);
+}
+
+
+static void init_request_info(SLS_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;
+
+ 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 ? atoi(content_length) : 0);
+
+ if (r->headers_in) {
+ authorization = table_get(r->headers_in, "Authorization");
+ }
+ if (authorization
+/* && !auth_type(r) */
+ && !strcasecmp(getword(r->pool, &authorization, ' '), "Basic")) {
+ tmp = uudecode(r->pool, authorization);
+ SG(request_info).auth_user = getword_nulls_nc(r->pool, &tmp, ':');
+ if (SG(request_info).auth_user) {
+ r->connection->user = pstrdup(r->connection->pool,SG(request_info).auth_user);
+ r->connection->ap_auth_type = "Basic";
+ SG(request_info).auth_user = estrdup(SG(request_info).auth_user);
+ }
+ SG(request_info).auth_password = tmp;
+ if (SG(request_info).auth_password) {
+ SG(request_info).auth_password = estrdup(SG(request_info).auth_password);
+ }
+ } else {
+ SG(request_info).auth_user = NULL;
+ SG(request_info).auth_password = NULL;
+ }
+}
+
+
+static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry)
+{
+ php_alter_ini_entry(per_dir_entry->key, per_dir_entry->key_length+1, per_dir_entry->value, per_dir_entry->value_length+1, per_dir_entry->type, PHP_INI_STAGE_ACTIVATE);
+ return 0;
+}
+
+static char *php_apache_get_default_mimetype(request_rec *r SLS_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(SLS_C);
+ mimetype = pstrdup(r->pool, tmpmimetype);
+ efree(tmpmimetype);
+ } else {
+ mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET;
+ }
+ return mimetype;
+}
+
+int send_php(request_rec *r, int display_source_mode, char *filename)
+{
+ int retval;
+ HashTable *per_dir_conf;
+ SLS_FETCH();
+ ELS_FETCH();
+ CLS_FETCH();
+ PLS_FETCH();
+
+ if (setjmp(EG(bailout))!=0) {
+ return OK;
+ }
+ per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
+ if (per_dir_conf) {
+ zend_hash_apply((HashTable *) per_dir_conf, (int (*)(void *)) php_apache_alter_ini_entries);
+ }
+
+ /* We don't accept OPTIONS requests, but take everything else */
+ if (r->method_number == M_OPTIONS) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+
+ /* Make sure file exists */
+ if (filename == NULL && r->finfo.st_mode == 0) {
+ return DECLINED;
+ }
+
+ /* If PHP parser engine has been turned off with an "engine off"
+ * directive, then decline to handle this request
+ */
+ if (!php_apache_info.engine) {
+ r->content_type = php_apache_get_default_mimetype(r SLS_CC);
+ r->allowed |= (1 << METHODS) - 1;
+ 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_ERROR)))
+ return retval;
+#endif
+
+ if (php_apache_info.last_modified) {
+#if MODULE_MAGIC_NUMBER < 19970912
+ if ((retval = set_last_modified(r, r->finfo.st_mtime))) {
+ 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 SLS_CC);
+
+ /* Init timeout */
+ hard_timeout("send", r);
+
+ SG(server_context) = r;
+
+ php_save_umask();
+ V_CHDIR_FILE(filename);
+ add_common_vars(r);
+ add_cgi_vars(r);
+
+ init_request_info(SLS_C);
+ apache_php_module_main(r, display_source_mode CLS_CC ELS_CC PLS_CC SLS_CC);
+
+ /* Done, restore umask, turn off timeout, close file and return */
+ php_restore_umask();
+ kill_timeout(r);
+ return OK;
+}
+
+
+int send_parsed_php(request_rec * r)
+{
+ return send_php(r, 0, NULL);
+}
+
+
+int send_parsed_php_source(request_rec * r)
+{
+ return send_php(r, 1, NULL);
+}
+
+
+static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry)
+{
+ free(per_dir_entry->key);
+ free(per_dir_entry->value);
+}
+
+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;
+}
+
+
+static void php_destroy_per_dir_info(HashTable *per_dir_info)
+{
+ zend_hash_destroy(per_dir_info);
+ free(per_dir_info);
+}
+
+static void *php_create_dir(pool *p, char *dummy)
+{
+ HashTable *per_dir_info;
+
+ per_dir_info = (HashTable *) malloc(sizeof(HashTable));
+ zend_hash_init(per_dir_info, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1);
+ register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy);
+
+ return per_dir_info;
+}
+
+
+static void *php_merge_dir(pool *p, void *basev, void *addv)
+{
+ php_per_dir_entry tmp;
+
+ zend_hash_merge((HashTable *) addv, (HashTable *) basev, (void (*)(void *)) copy_per_dir_entry, &tmp, sizeof(php_per_dir_entry), 0);
+ return addv;
+}
+
+
+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);
+#endif
+ sapi_startup(&sapi_module);
+ php_apache_startup(&sapi_module);
+ }
+ per_dir_entry.type = mode;
+
+ 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((HashTable *) conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry), NULL);
+ return NULL;
+}
+
+
+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);
+}
+
+
+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);
+}
+
+
+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")) {
+ 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);
+}
+
+
+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);
+}
+
+
+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);
+}
+
+
+
+
+int php_xbithack_handler(request_rec * r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *) get_module_config(r->per_dir_config, &php4_module);
+ if (!(r->finfo.st_mode & S_IXUSR)) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ if (conf->xbithack == 0) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ return send_parsed_php(r);
+}
+
+static void apache_php_module_shutdown_wrapper(void)
+{
+ apache_php_initialized = 0;
+ sapi_module.shutdown(&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
+static void php_child_exit_handler(server_rec *s, pool *p)
+{
+/* apache_php_initialized = 0; */
+ sapi_module.shutdown(&sapi_module);
+
+#ifdef ZTS
+ tsrm_shutdown();
+#endif
+}
+#endif
+
+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);
+#endif
+ sapi_startup(&sapi_module);
+ php_apache_startup(&sapi_module);
+ }
+#if MODULE_MAGIC_NUMBER >= 19980527
+ {
+ PLS_FETCH();
+ if (PG(expose_php)) {
+ ap_add_version_component("PHP/" PHP_VERSION);
+ }
+ }
+#endif
+}
+
+
+#if HAVE_MOD_DAV
+
+extern int phpdav_mkcol_test_handler(request_rec *r);
+extern int phpdav_mkcol_create_handler(request_rec *r);
+
+/* conf is being read twice (both here and in send_php()) */
+int send_parsed_php_dav_script(request_rec *r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *) get_module_config(r->per_dir_config,
+ &php4_module);
+ return send_php(r, 0, 0, conf->dav_script);
+}
+
+static int php_type_checker(request_rec *r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *)get_module_config(r->per_dir_config,
+ &php4_module);
+
+ /* If DAV support is enabled, use mod_dav's type checker. */
+ if (conf->dav_script) {
+ dav_api_set_request_handler(r, send_parsed_php_dav_script);
+ dav_api_set_mkcol_handlers(r, phpdav_mkcol_test_handler,
+ phpdav_mkcol_create_handler);
+ /* leave the rest of the request to mod_dav */
+ return dav_api_type_checker(r);
+ }
+
+ return DECLINED;
+}
+
+#else /* HAVE_MOD_DAV */
+
+# define php_type_checker NULL
+
+#endif /* HAVE_MOD_DAV */
+
+
+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[] =
+{
+ {"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)"},
+ {NULL}
+};
+
+
+
+module MODULE_VAR_EXPORT php4_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 */
+ php_type_checker, /* 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:
+ */
--- /dev/null
+php4_module
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 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_02.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> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#ifndef MOD_PHP4_H
+#define MOD_PHP4_H
+
+#if !defined(WIN32) && !defined(WINNT)
+#ifndef MODULE_VAR_EXPORT
+#define MODULE_VAR_EXPORT
+#endif
+#endif
+
+typedef struct {
+ long engine;
+ long last_modified;
+ char *dav_script;
+ long xbithack;
+} php_apache_info_struct;
+
+extern zend_module_entry apache_module_entry;
+extern php_apache_info_struct php_apache_info;
+
+#ifdef WIN32
+#define S_IXUSR _S_IEXEC
+#endif
+
+#endif /* MOD_PHP4_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 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_02.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$ */
+
+#define NO_REGEX_EXTRA_H
+#ifdef WIN32
+#include <winsock2.h>
+#include <stddef.h>
+#endif
+
+#include "zend.h"
+#include "php.h"
+#include "php_variables.h"
+#include "SAPI.h"
+
+#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 "php_ini.h"
+#include "php_globals.h"
+#include "SAPI.h"
+#include "php_main.h"
+
+#include "zend_compile.h"
+#include "zend_execute.h"
+#include "zend_highlight.h"
+#include "zend_indent.h"
+
+#include "ext/standard/php_standard.h"
+
+#include "util_script.h"
+
+#include "mod_php4.h"
+#if HAVE_MOD_DAV
+# include "mod_dav.h"
+#endif
+
+int apache_php_module_main(request_rec *r, int fd, int display_source_mode CLS_DC ELS_DC PLS_DC SLS_DC);
+void php_save_umask(void);
+void php_restore_umask(void);
+int sapi_apache_read_post(char *buffer, uint count_bytes SLS_DC);
+char *sapi_apache_read_cookies(SLS_D);
+int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC);
+int sapi_apache_send_headers(sapi_headers_struct *sapi_headers SLS_DC);
+int send_php(request_rec *r, int display_source_mode, char *filename);
+int send_parsed_php(request_rec * r);
+int send_parsed_php_source(request_rec * r);
+int php_xbithack_handler(request_rec * r);
+void php_init_handler(server_rec *s, pool *p);
+
+#if MODULE_MAGIC_NUMBER > 19961007
+#define CONST_PREFIX const
+#else
+#define CONST_PREFIX
+#endif
+CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2);
+
+/* ### these should be defined in mod_php4.h or somewhere else */
+#define USE_PATH 1
+#define IGNORE_URL 2
+
+module MODULE_VAR_EXPORT php4_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;
+} php_per_dir_entry;
+
+/* handled apropriately in apache_php_module_main */
+/* popenf isn't working on Windows, use open instead
+#if WIN32|WINNT
+# ifdef popenf
+# undef popenf
+# endif
+# define popenf(p,n,f,m) open((n),(f),(m))
+# ifdef pclosef
+# undef pclosef
+# endif
+# define pclosef(p,f) close(f)
+#endif
+*/
+
+php_apache_info_struct php_apache_info; /* active config */
+
+/* some systems are missing these from their header files */
+
+void php_save_umask(void)
+{
+ saved_umask = umask(077);
+ umask(saved_umask);
+}
+
+
+static int sapi_apache_ub_write(const char *str, uint str_length)
+{
+ int ret;
+ SLS_FETCH();
+ PLS_FETCH();
+
+ if (SG(server_context)) {
+ ret = rwrite(str, str_length, (request_rec *) SG(server_context));
+ } else {
+ ret = fwrite(str, 1, str_length, stderr);
+ }
+ if(ret != str_length) {
+ PG(connection_status) = PHP_CONNECTION_ABORTED;
+ if (!PG(ignore_user_abort)) {
+ zend_bailout();
+ }
+ }
+ return ret;
+}
+
+
+
+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
+ }
+}
+
+
+int sapi_apache_read_post(char *buffer, uint count_bytes SLS_DC)
+{
+ uint total_read_bytes=0, read_bytes;
+ request_rec *r = (request_rec *) SG(server_context);
+ void (*handler)(int);
+
+ 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;
+}
+
+
+char *sapi_apache_read_cookies(SLS_D)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE");
+}
+
+
+int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers SLS_DC)
+{
+ char *header_name, *header_content, *p;
+ request_rec *r = (request_rec *) SG(server_context);
+
+ 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, "Set-Cookie")) {
+ table_add(r->headers_out, header_name, header_content);
+ } else {
+ table_set(r->headers_out, header_name, header_content);
+ }
+
+ *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
+
+ efree(sapi_header->header);
+
+ return 0; /* don't use the default SAPI mechanism, Apache duplicates this functionality */
+}
+
+
+int sapi_apache_send_headers(sapi_headers_struct *sapi_headers SLS_DC)
+{
+ if(SG(server_context) == NULL) { /* server_context is not here anymore */
+ return SAPI_HEADER_SEND_FAILED;
+ }
+
+ ((request_rec *) SG(server_context))->status = SG(sapi_headers).http_response_code;
+ send_http_header((request_rec *) SG(server_context));
+ return SAPI_HEADER_SENT_SUCCESSFULLY;
+}
+
+
+static void sapi_apache_register_server_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
+{
+ register int i;
+ array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
+ table_entry *elts = (table_entry *) arr->elts;
+ char *script_filename=NULL;
+
+ for (i = 0; i < arr->nelts; i++) {
+ char *val;
+
+ if (elts[i].val) {
+ val = elts[i].val;
+ if (!strcmp(elts[i].key, "SCRIPT_FILENAME")) {
+ script_filename = val;
+ }
+ } else {
+ val = empty_string;
+ }
+ php_register_variable(elts[i].key, val, NULL ELS_CC PLS_CC);
+ }
+
+ /* insert special variables */
+ if (script_filename) {
+ php_register_variable("PATH_TRANSLATED", script_filename, track_vars_array ELS_CC PLS_CC);
+ }
+ php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array ELS_CC PLS_CC);
+}
+
+static int php_apache_startup(sapi_module_struct *sapi_module)
+{
+ if(php_module_startup(sapi_module) == FAILURE
+ || zend_startup_module(&apache_module_entry) == FAILURE) {
+ return FAILURE;
+ } else {
+ return SUCCESS;
+ }
+}
+
+
+static void php_apache_log_message(char *message)
+{
+ SLS_FETCH();
+
+ 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, ((requset_rec *) SG(server_context))->server);
+#endif
+ } else {
+ fprintf(stderr, message);
+ fprintf(stderr, "\n");
+ }
+}
+
+
+static void php_apache_request_shutdown(void *dummy)
+{
+ SLS_FETCH();
+
+ SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */
+ php_request_shutdown(dummy);
+}
+
+
+static int php_apache_sapi_activate(SLS_D)
+{
+ /*
+ * 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(((request_rec *) SG(server_context))->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec);
+ unblock_alarms();
+ return SUCCESS;
+}
+
+
+static struct stat *php_apache_get_stat(SLS_D)
+{
+ return &((request_rec *) SG(server_context))->finfo;
+}
+
+
+static char *php_apache_getenv(char *name, int name_len SLS_DC)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name);
+}
+
+
+static sapi_module_struct sapi_module = {
+ "Apache", /* 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 */
+
+#ifdef PHP_WIN32
+ NULL,
+ NULL,
+#else
+ block_alarms, /* Block interruptions */
+ unblock_alarms, /* Unblock interruptions */
+#endif
+
+ STANDARD_SAPI_MODULE_PROPERTIES
+};
+
+
+void php_restore_umask(void)
+{
+ umask(saved_umask);
+}
+
+
+static void init_request_info(SLS_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;
+
+ 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 ? atoi(content_length) : 0);
+
+ if (r->headers_in) {
+ authorization = table_get(r->headers_in, "Authorization");
+ }
+ if (authorization
+/* && !auth_type(r) */
+ && !strcmp(getword(r->pool, &authorization, ' '), "Basic")) {
+ tmp = uudecode(r->pool, authorization);
+ SG(request_info).auth_user = getword_nulls_nc(r->pool, &tmp, ':');
+ if (SG(request_info).auth_user) {
+ SG(request_info).auth_user = estrdup(SG(request_info).auth_user);
+/* r->connection->user = pstrdup(r->pool,SG(request_info).auth_user); */
+ }
+ SG(request_info).auth_password = tmp;
+ if (SG(request_info).auth_password) {
+ SG(request_info).auth_password = estrdup(SG(request_info).auth_password);
+ }
+ } else {
+ SG(request_info).auth_user = NULL;
+ SG(request_info).auth_password = NULL;
+ }
+}
+
+
+static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry)
+{
+ php_alter_ini_entry(per_dir_entry->key, per_dir_entry->key_length+1, per_dir_entry->value, per_dir_entry->value_length+1, per_dir_entry->type, PHP_INI_STAGE_ACTIVATE);
+ return 0;
+}
+
+static char *php_apache_get_default_mimetype(request_rec *r SLS_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(SLS_C);
+ mimetype = pstrdup(r->pool, tmpmimetype);
+ efree(tmpmimetype);
+ } else {
+ mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET;
+ }
+ return mimetype;
+}
+
+int send_php(request_rec *r, int display_source_mode, char *filename)
+{
+ int fd, retval;
+ HashTable *per_dir_conf;
+ SLS_FETCH();
+ ELS_FETCH();
+ CLS_FETCH();
+ PLS_FETCH();
+
+ if (setjmp(EG(bailout))!=0) {
+ return OK;
+ }
+ per_dir_conf = (HashTable *) get_module_config(r->per_dir_config, &php4_module);
+ zend_hash_apply((HashTable *) per_dir_conf, (int (*)(void *)) php_apache_alter_ini_entries);
+
+ /* We don't accept OPTIONS requests, but take everything else */
+ if (r->method_number == M_OPTIONS) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+
+ /* Make sure file exists */
+ if (filename == NULL && r->finfo.st_mode == 0) {
+ return DECLINED;
+ }
+
+ /* If PHP parser engine has been turned off with an "engine off"
+ * directive, then decline to handle this request
+ */
+ if (!php_apache_info.engine) {
+ r->content_type = php_apache_get_default_mimetype(r SLS_CC);
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ if (filename == NULL) {
+ filename = r->filename;
+ }
+ /* Open the file */
+ if ((fd = popenf(r->pool, filename, O_RDONLY, 0)) == -1) {
+ log_reason("file permissions deny server access", filename, r);
+ return FORBIDDEN;
+ }
+
+ /* 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_ERROR)))
+ return retval;
+#endif
+
+ if (php_apache_info.last_modified) {
+#if MODULE_MAGIC_NUMBER < 19970912
+ if ((retval = set_last_modified(r, r->finfo.st_mtime))) {
+ 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 SLS_CC);
+
+ /* Init timeout */
+ hard_timeout("send", r);
+
+ SG(server_context) = r;
+
+ php_save_umask();
+ V_CHDIR_FILE(filename);
+ add_common_vars(r);
+ add_cgi_vars(r);
+
+ init_request_info(SLS_C);
+ apache_php_module_main(r, fd, display_source_mode CLS_CC ELS_CC PLS_CC SLS_CC);
+
+ /* Done, restore umask, turn off timeout, close file and return */
+ php_restore_umask();
+ kill_timeout(r);
+ pclosef(r->pool, fd);
+ return OK;
+}
+
+
+int send_parsed_php(request_rec * r)
+{
+ return send_php(r, 0, NULL);
+}
+
+
+int send_parsed_php_source(request_rec * r)
+{
+ return send_php(r, 1, NULL);
+}
+
+
+static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry)
+{
+ free(per_dir_entry->key);
+ free(per_dir_entry->value);
+}
+
+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;
+}
+
+
+static void php_destroy_per_dir_info(HashTable *per_dir_info)
+{
+ zend_hash_destroy(per_dir_info);
+ free(per_dir_info);
+}
+
+static void *php_create_dir(pool *p, char *dummy)
+{
+ HashTable *per_dir_info;
+
+ per_dir_info = (HashTable *) malloc(sizeof(HashTable));
+ zend_hash_init(per_dir_info, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1);
+ register_cleanup(p, (void *) per_dir_info, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) zend_hash_destroy);
+
+ return per_dir_info;
+}
+
+
+static void *php_merge_dir(pool *p, void *basev, void *addv)
+{
+ php_per_dir_entry tmp;
+
+ zend_hash_merge((HashTable *) addv, (HashTable *) basev, (void (*)(void *)) copy_per_dir_entry, &tmp, sizeof(php_per_dir_entry), 0);
+ return addv;
+}
+
+
+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);
+#endif
+ sapi_startup(&sapi_module);
+ php_apache_startup(&sapi_module);
+ }
+ per_dir_entry.type = mode;
+
+ 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((HashTable *) conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry), NULL);
+ return NULL;
+}
+
+
+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);
+}
+
+
+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);
+}
+
+
+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")) {
+ 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);
+}
+
+
+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);
+}
+
+
+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);
+}
+
+
+
+
+int php_xbithack_handler(request_rec * r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *) get_module_config(r->per_dir_config, &php4_module);
+ if (!(r->finfo.st_mode & S_IXUSR)) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ if (conf->xbithack == 0) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ return send_parsed_php(r);
+}
+
+static void apache_php_module_shutdown_wrapper(void)
+{
+ apache_php_initialized = 0;
+ sapi_module.shutdown(&sapi_module);
+#ifdef ZTS
+ tsrm_shutdown();
+#endif
+}
+
+
+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);
+#endif
+ sapi_startup(&sapi_module);
+ php_apache_startup(&sapi_module);
+ }
+#if MODULE_MAGIC_NUMBER >= 19980527
+ {
+ PLS_FETCH();
+ if (PG(expose_php)) {
+ ap_add_version_component("PHP/" PHP_VERSION);
+ }
+ }
+#endif
+}
+
+
+#if HAVE_MOD_DAV
+
+extern int phpdav_mkcol_test_handler(request_rec *r);
+extern int phpdav_mkcol_create_handler(request_rec *r);
+
+/* conf is being read twice (both here and in send_php()) */
+int send_parsed_php_dav_script(request_rec *r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *) get_module_config(r->per_dir_config,
+ &php4_module);
+ return send_php(r, 0, 0, conf->dav_script);
+}
+
+static int php_type_checker(request_rec *r)
+{
+ php_apache_info_struct *conf;
+
+ conf = (php_apache_info_struct *)get_module_config(r->per_dir_config,
+ &php4_module);
+
+ /* If DAV support is enabled, use mod_dav's type checker. */
+ if (conf->dav_script) {
+ dav_api_set_request_handler(r, send_parsed_php_dav_script);
+ dav_api_set_mkcol_handlers(r, phpdav_mkcol_test_handler,
+ phpdav_mkcol_create_handler);
+ /* leave the rest of the request to mod_dav */
+ return dav_api_type_checker(r);
+ }
+
+ return DECLINED;
+}
+
+#else /* HAVE_MOD_DAV */
+
+# define php_type_checker NULL
+
+#endif /* HAVE_MOD_DAV */
+
+
+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[] =
+{
+ {"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)"},
+ {NULL}
+};
+
+
+
+module MODULE_VAR_EXPORT php4_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 */
+ php_type_checker, /* 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
+ ,NULL /* child_exit */
+#endif
+#if MODULE_MAGIC_NUMBER >= 19970902
+ ,NULL /* post read-request */
+#endif
+};
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
--- /dev/null
+php4_module
--- /dev/null
+# Microsoft Developer Studio Project File - Name="php4apache" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102\r
+\r
+CFG=php4apache - Win32 Release_TS\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "php4apache.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "php4apache.mak" CFG="php4apache - Win32 Release_TS"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "php4apache - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE "php4apache - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE "php4apache - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+MTL=midl.exe\r
+RSC=rc.exe\r
+\r
+!IF "$(CFG)" == "php4apache - Win32 Release_TS"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release_TS"\r
+# PROP BASE Intermediate_Dir "Release_TS"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\..\Release_TS"\r
+# PROP Intermediate_Dir "Release_TS"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP4_EXPORTS" /YX /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "\apache\src\include" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP4_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c\r
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r
+# ADD LINK32 php4ts.lib 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:"\apache\src\corer" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"\r
+\r
+!ELSEIF "$(CFG)" == "php4apache - Win32 Debug_TS"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Debug_TS"\r
+# PROP BASE Intermediate_Dir "Debug_TS"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\Debug_TS"\r
+# PROP Intermediate_Dir "Debug_TS"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP4_EXPORTS" /YX /FD /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "\apache\src\include" /I "..\..\main" /I "..\..\TSRM" /D "_DEBUG" /D ZEND_DEBUG=1 /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP4_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /FR /YX /FD /c\r
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r
+# ADD LINK32 php4ts_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 /out:"..\..\Debug_TS/php4apache.dll" /pdbtype:sept /libpath:"\apache\src\cored" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"\r
+\r
+!ELSEIF "$(CFG)" == "php4apache - Win32 Release_TS_inline"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release_TS_inline"\r
+# PROP BASE Intermediate_Dir "Release_TS_inline"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\..\Release_TS_inline"\r
+# PROP Intermediate_Dir "Release_TS_inline"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP4_EXPORTS" /YX /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\.." /I "..\..\..\bindlib_w32" /I "\apache\src\include" /I "..\..\main" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "NDEBUG" /D "ZTS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "_WINDOWS" /D "_USRDLL" /D "APACHEPHP4_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c\r
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386\r
+# ADD LINK32 php4ts.lib 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:"\apache\src\corer" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "php4apache - Win32 Release_TS"\r
+# Name "php4apache - Win32 Debug_TS"\r
+# Name "php4apache - Win32 Release_TS_inline"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\mod_php4.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\php_apache.c\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\sapi_apache.c\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\mod_php4.h\r
+# End Source File\r
+# Begin Source File\r
+\r
+SOURCE=.\php_apache_http.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 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_02.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@guardian.no> |
+ | David Sklar <sklar@student.net> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#define NO_REGEX_EXTRA_H
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <stddef.h>
+#endif
+
+#include "php.h"
+#include "ext/standard/head.h"
+#include "php_globals.h"
+#include "php_ini.h"
+#include "SAPI.h"
+#include "mod_php4.h"
+#include "ext/standard/info.h"
+
+#include <stdlib.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include "php_apache_http.h"
+#include "http_request.h"
+
+#ifdef PHP_WIN32
+#include "zend.h"
+#include "ap_compat.h"
+#else
+#include "build-defs.h"
+#endif
+
+#define SECTION(name) PUTS("<H2 align=\"center\">" name "</H2>\n")
+
+extern module *top_module;
+
+PHP_FUNCTION(virtual);
+PHP_FUNCTION(getallheaders);
+PHP_FUNCTION(apachelog);
+PHP_FUNCTION(apache_note);
+PHP_FUNCTION(apache_lookup_uri);
+
+PHP_MINFO_FUNCTION(apache);
+
+function_entry apache_functions[] = {
+ PHP_FE(virtual, NULL)
+ PHP_FE(getallheaders, NULL)
+ PHP_FE(apache_note, NULL)
+ PHP_FE(apache_lookup_uri, NULL)
+ {NULL, NULL, NULL}
+};
+
+
+static PHP_INI_MH(OnChangeApacheInt)
+{
+ long *p;
+ char *base = (char *) &php_apache_info;
+
+ p = (long *) (base+(size_t) mh_arg1);
+
+ if (new_value) {
+ *p = atoi(new_value);
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
+}
+
+
+static PHP_INI_MH(OnChangeApacheString)
+{
+ char **p;
+ char *base = (char *) &php_apache_info;
+
+ p = (char **) (base+(size_t) mh_arg1);
+
+ if (new_value) {
+ *p = new_value;
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
+}
+
+PHP_INI_BEGIN()
+ PHP_INI_ENTRY1("xbithack", "0", PHP_INI_ALL, OnChangeApacheInt, (void *) XtOffsetOf(php_apache_info_struct, xbithack))
+ PHP_INI_ENTRY1("engine", "1", PHP_INI_ALL, OnChangeApacheInt, (void *) XtOffsetOf(php_apache_info_struct, engine))
+ PHP_INI_ENTRY1("last_modified", "0", PHP_INI_ALL, OnChangeApacheInt, (void *) XtOffsetOf(php_apache_info_struct, last_modified))
+ PHP_INI_ENTRY1("dav_script", NULL, PHP_INI_ALL, OnChangeApacheString, (void *) XtOffsetOf(php_apache_info_struct, dav_script))
+PHP_INI_END()
+
+
+static PHP_MINIT_FUNCTION(apache)
+{
+ REGISTER_INI_ENTRIES();
+ return SUCCESS;
+}
+
+
+static PHP_MSHUTDOWN_FUNCTION(apache)
+{
+ UNREGISTER_INI_ENTRIES();
+ return SUCCESS;
+}
+
+
+zend_module_entry apache_module_entry = {
+ "apache", apache_functions, PHP_MINIT(apache), PHP_MSHUTDOWN(apache), NULL, NULL, PHP_MINFO(apache), STANDARD_MODULE_PROPERTIES
+};
+
+/* {{{ proto string apache_note(string note_name [, string note_value])
+ Get and set Apache request notes */
+PHP_FUNCTION(apache_note)
+{
+ pval **arg_name,**arg_val;
+ char *note_val;
+ int arg_count = ARG_COUNT(ht);
+ SLS_FETCH();
+
+ if (arg_count<1 || arg_count>2 ||
+ zend_get_parameters_ex(arg_count,&arg_name,&arg_val) ==FAILURE ) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_string_ex(arg_name);
+ note_val = (char *) table_get(((request_rec *)SG(server_context))->notes,(*arg_name)->value.str.val);
+
+ if (arg_count == 2) {
+ convert_to_string_ex(arg_val);
+ table_set(((request_rec *)SG(server_context))->notes,(*arg_name)->value.str.val,(*arg_val)->value.str.val);
+ }
+
+ if (note_val) {
+ RETURN_STRING(note_val,1);
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+PHP_MINFO_FUNCTION(apache)
+{
+ 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;
+ SLS_FETCH();
+
+ 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();
+#else
+ php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE);
+ php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET);
+#endif
+
+ php_info_print_table_row(2, "Apache Version", SERVER_VERSION);
+
+#ifdef APACHE_RELEASE
+ sprintf(output_buf, "%d", APACHE_RELEASE);
+ php_info_print_table_row(2, "Apache Release", output_buf);
+#endif
+ sprintf(output_buf, "%d", MODULE_MAGIC_NUMBER);
+ php_info_print_table_row(2, "Apache API Version", output_buf);
+ sprintf(output_buf, "%s:%u", serv->server_hostname,serv->port);
+ php_info_print_table_row(2, "Hostname:Port", output_buf);
+#if !defined(WIN32) && !defined(WINNT)
+ sprintf(output_buf, "%s(%d)/%d", user_name,(int)user_id,(int)group_id);
+ php_info_print_table_row(2, "User/Group", output_buf);
+ sprintf(output_buf, "Per Child: %d<br>Keep Alive: %s<br>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
+ sprintf(output_buf, "Connection: %d<br>Keep-Alive: %d",serv->timeout,serv->keep_alive_timeout);
+ php_info_print_table_row(2, "Timeouts", output_buf);
+#if !defined(WIN32) && !defined(WINNT)
+ 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 */
+ }
+ strcat(modulenames, name);
+ if (modp->next) {
+ strcat(modulenames, ", ");
+ }
+ }
+ php_info_print_table_row(2, "Loaded Modules", modulenames);
+#endif
+
+ php_info_print_table_end();
+
+
+ {
+ register int i;
+ array_header *arr;
+ table_entry *elts;
+ request_rec *r;
+ SLS_FETCH();
+
+ 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;
+ SLS_FETCH();
+
+ 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();
+ }
+
+}
+
+/* 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.
+ */
+/* {{{ proto int virtual(string filename)
+ Perform an Apache sub-request */
+PHP_FUNCTION(virtual)
+{
+ pval **filename;
+ request_rec *rr = NULL;
+ SLS_FETCH();
+
+ if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1,&filename) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string_ex(filename);
+
+ if (!(rr = sub_req_lookup_uri ((*filename)->value.str.val,((request_rec *) SG(server_context))))) {
+ php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", (*filename)->value.str.val);
+ if (rr) destroy_sub_req (rr);
+ RETURN_FALSE;
+ }
+
+ if (rr->status != 200) {
+ php_error(E_WARNING, "Unable to include '%s' - error finding URI", (*filename)->value.str.val);
+ if (rr) destroy_sub_req (rr);
+ RETURN_FALSE;
+ }
+
+ /* Cannot include another PHP file because of global conflicts */
+ if (rr->content_type &&
+ !strcmp(rr->content_type, PHP_MIME_TYPE)) {
+ php_error(E_WARNING, "Cannot include a PHP file "
+ "(use <code><?include \"%s\"></code> instead)", (*filename)->value.str.val);
+ if (rr) destroy_sub_req (rr);
+ RETURN_FALSE;
+ }
+
+ php_end_ob_buffers(1);
+ php_header();
+
+ if (run_sub_req(rr)) {
+ php_error(E_WARNING, "Unable to include '%s' - request execution failed", (*filename)->value.str.val);
+ if (rr) destroy_sub_req (rr);
+ RETURN_FALSE;
+ } else {
+ if (rr) destroy_sub_req (rr);
+ RETURN_TRUE;
+ }
+}
+/* }}} */
+
+/* {{{ proto array getallheaders(void)
+ Fetch all HTTP request headers */
+PHP_FUNCTION(getallheaders)
+{
+ array_header *env_arr;
+ table_entry *tenv;
+ int i;
+ SLS_FETCH();
+ PLS_FETCH();
+
+ if (array_init(return_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+ 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 ||
+ (PG(safe_mode) &&
+ !strncasecmp(tenv[i].key, "authorization", 13))) {
+ continue;
+ }
+ if (add_assoc_string(return_value, tenv[i].key,(tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
+ RETURN_FALSE;
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto class apache_lookup_uri(string URI)
+ Perform a partial request of the given URI to obtain information about it */
+PHP_FUNCTION(apache_lookup_uri)
+{
+ pval **filename;
+ request_rec *rr=NULL;
+ SLS_FETCH();
+
+ if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1,&filename) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string_ex(filename);
+
+ if(!(rr = sub_req_lookup_uri((*filename)->value.str.val,((request_rec *) SG(server_context))))) {
+ php_error(E_WARNING, "URI lookup failed",(*filename)->value.str.val);
+ 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)
+{
+ pval **filename;
+ request_rec *rr=NULL;
+ SLS_FETCH();
+
+ if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1,&filename) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string_ex(filename);
+
+ if(!(rr = ap_sub_req_lookup_uri((*filename)->value.str.val,((request_rec *) SG(server_context))))) {
+ php_error(E_WARNING, "URI lookup failed",(*filename)->value.str.val);
+ RETURN_FALSE;
+ }
+ RETVAL_LONG(ap_run_sub_req(rr));
+ ap_destroy_sub_req(rr);
+}
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
--- /dev/null
+# if HAVE_AP_CONFIG_H
+#include "ap_config_auto.h"
+#ifdef RHAPSODY
+#undef HAVE_SNPRINTF
+#endif
+#include "ap_config.h"
+#ifdef RHAPSODY
+#undef HAVE_SNPRINTF
+#define HAVE_SNPRINTF 1
+#endif
+# endif
+# if HAVE_OLD_COMPAT_H
+#include "compat.h"
+# endif
+# if HAVE_AP_COMPAT_H
+#include "ap_compat.h"
+# endif
+#include "httpd.h"
+#include "http_main.h"
+#include "http_core.h"
+#include "http_request.h"
+#include "http_protocol.h"
+#include "http_config.h"
+#include "http_log.h"
--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP version 4.0 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 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_02.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@fast.no> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#define NO_REGEX_EXTRA_H
+#ifdef WIN32
+#include <winsock2.h>
+#include <stddef.h>
+#endif
+
+#include "php.h"
+
+#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 "zend.h"
+#include "php_ini.h"
+#include "php_globals.h"
+#include "SAPI.h"
+#include "php_main.h"
+#include "zend_compile.h"
+#include "zend_execute.h"
+#include "zend_highlight.h"
+#include "zend_indent.h"
+#include "ext/standard/php_standard.h"
+#include "util_script.h"
+#include "php_version.h"
+
+int apache_php_module_main(request_rec *r, int display_source_mode CLS_DC ELS_DC PLS_DC SLS_DC)
+{
+ zend_file_handle file_handle;
+
+ if (php_request_startup(CLS_C ELS_CC PLS_CC SLS_CC) == 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)) {
+ return OK;
+ } else {
+ return 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 CLS_CC ELS_CC PLS_CC);
+ }
+
+ php_header(); /* Make sure headers have been sent */
+ php_end_ob_buffers(1);
+ return (OK);
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
--- /dev/null
+*** sapi_apache.c.orig Fri Oct 13 23:12:44 2000
+--- sapi_apache.c Fri Oct 13 23:25:39 2000
+***************
+*** 69,91 ****
+ /* sending a file handle to another dll is not working
+ // so let zend open it.
+ */
+! 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;
+!
+ 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);
+ return OK;
+ } else {
+ return NOT_FOUND;
+ }
+ } else {
+ (void) php_execute_script(&file_handle CLS_CC ELS_CC PLS_CC);
+ }
+
+--- 69,91 ----
+ /* 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)){
+ return OK;
+ } else {
+ return 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 CLS_CC ELS_CC PLS_CC);
+ }
+