summaryrefslogtreecommitdiff
path: root/sapi/apache_hooks
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/apache_hooks')
-rw-r--r--sapi/apache_hooks/CREDITS2
-rw-r--r--sapi/apache_hooks/README206
-rw-r--r--sapi/apache_hooks/apMakefile.libdir4
-rw-r--r--sapi/apache_hooks/apMakefile.tmpl77
-rw-r--r--sapi/apache_hooks/config.m4275
-rw-r--r--sapi/apache_hooks/config.w3221
-rw-r--r--sapi/apache_hooks/libphp5.module.in11
-rw-r--r--sapi/apache_hooks/mod_php5.c1493
-rw-r--r--sapi/apache_hooks/mod_php5.exp1
-rw-r--r--sapi/apache_hooks/mod_php5.h88
-rw-r--r--sapi/apache_hooks/php.sym1
-rwxr-xr-xsapi/apache_hooks/php5apache_hooks.dsp151
-rw-r--r--sapi/apache_hooks/php_apache.c1972
-rw-r--r--sapi/apache_hooks/php_apache_http.h44
-rw-r--r--sapi/apache_hooks/sapi_apache.c131
15 files changed, 4477 insertions, 0 deletions
diff --git a/sapi/apache_hooks/CREDITS b/sapi/apache_hooks/CREDITS
new file mode 100644
index 0000000..86ac27d
--- /dev/null
+++ b/sapi/apache_hooks/CREDITS
@@ -0,0 +1,2 @@
+Apache 1.3 (apache_hooks)
+Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar, George Schlossnagle, Lukas Schroeder
diff --git a/sapi/apache_hooks/README b/sapi/apache_hooks/README
new file mode 100644
index 0000000..9a5a3e2
--- /dev/null
+++ b/sapi/apache_hooks/README
@@ -0,0 +1,206 @@
+This is very beta documentation. Clearly better stuff can and will follow.
+
+INTRO:
+
+apache_hooks is a full super-set enhancement of the apache 1.3 sapi that allows for
+php code to be run on the apache request object at every stage of the apache
+request. It supports all of the apache 1.3 sapi commands and configurations, and
+additionally supports the following httpd.conf directives:
+
+
+HTTPD.CONF DIRECTIEVS:
+
+phpRequire /path/to/file = requires a file at the beginning of an
+initial apache request
+
+phpUriHandler /path/to/file = registers a hook that will run the
+specified file at the uri translation stage of the apache request
+phpUriHandler Class::Method = registers a hook to run Class::Method at
+the uri translation stage of the apache request
+
+phpPostReadHandler /path/to/file = hook for post-read phase
+phpPostReadHandlerMethod Class::Method
+
+phpHeaderHandler = hook for header parsing phase
+phpHeaderHandlerMethod
+
+phpAuthHandler = hook for authentication phase
+phpAuthHandlerMethod
+
+phpAccessHandler = hook for access control phase
+phpAccessHandlerMethod
+
+phpTypeHandler = hook for Type Checking phase
+phpTypeHandlerMethod
+
+phpFixupHandler = hook for 'fixup' phase
+phpFixupHandlerMethod
+
+phpLoggerHandler = hook for logging phase
+phpLoggerHandlerMethod
+
+AddHandler php-script = set's up a special type handler
+phpResponseHandler /path/to/file = sets file to be called to handle
+response phase
+phpResponseHandlerMethod Class::Method
+
+
+All handlers may be stacked, i.e. you can list multiple handler directives
+in a single scope and they will be run in order.
+
+
+EXAMPLES:
+
+So, to set up a 'hello world' location handler (so that any request to
+/hello/* returns hello world) you can:
+
+phpRequire /tmp/setup.php
+<Location /hello>
+AddHandler php-script
+phpResponseHandlerMethod Hello::World
+</Location>
+
+with
+#/tmp/setup.php
+<?
+class Hello {
+ function World() {
+ global $request;
+ $request->send_http_header();
+ echo "Hello World";
+ }
+}
+?>
+
+$request is the apache request. It is instantiated at all stages
+automatically. The methods of that class are:
+
+getallheaders
+args
+boundary
+content_encoding
+content_type
+filename
+handler
+hostname
+method
+path_info
+protocol
+status_line
+the_request
+unparsed_uri
+uri
+allowed
+bytes_sent
+chunked
+content_length
+header_only
+method_number
+mtime
+no_cache
+no_local_copy
+proto_num
+proxyreq
+read_body
+remaining
+request_time
+status
+headers_in
+headers_out
+err_headers_out
+auth_name
+auth_type
+basic_auth_pw
+discard_request_body
+is_initial_req
+meets_conditions
+remote_host
+satisfies
+server_port
+set_etag
+set_last_modified
+some_auth_required
+update_mtime
+send_http_header
+basic_http_header
+send_header_field
+send_http_trace
+send_http_options
+send_error_response
+set_content_length
+set_keepalive
+rputs
+log_error
+lookup_uri
+lookup_file
+method_uri
+run
+internal_redirect
+
+
+These all wrap the ap_* apache EXPORT_API functions using the same
+semantics (and are also the same as the Apache::Request methods in
+mod_perl if you are familiar with that)
+
+So, a uri handler to redirect all non-local traffic to /404.php (an
+error page) would be
+
+phpUriHandler /tmp/uri.php
+
+#/tmp/uri.php
+<?
+ if($REMOTE_ADDR != '127.0.0.1') {
+ $request->uri('/404.php');
+ }
+ return OK;
+?>
+
+It's important to note that since this is called from the uri
+translations phase, this validation is performed for every request to
+the server, not just for php pages.
+
+Also, scope is shared between all the hooks. So in the above, we could
+merge the two and do something like:
+
+#/tmp/uri.php
+<?
+ if($REMOTE_ADDR != '127.0.0.1') {
+ $whoami = 'Stranger';
+ }
+ else {
+ $whoami = 'Friend';
+ }
+ return DECLINED; # because we're not redirecting, just messing around
+?>
+
+and then:
+
+#/tmp/setup.php
+<?
+class Hello {
+ function World() {
+ global $request;
+ global $whoami;
+ $request->send_http_header();
+ echo "Hello $whoami";
+ }
+}
+?>
+
+These variables are also in the same scope as a script if your script is
+being handled by the standard application/x-httpd-php handler.
+
+This allows you to make decisions and pass data between your handlers
+and scripts at all stages.
+
+The above are clearly trite examples, but hopefully give you a starting
+point.
+
+One note: all handlers can be validly re-entered 'in sub-requests'.
+For this reason you should not define functions/classes here without
+anti-redefinition guards (I would just recommend putting them in an
+include and using include_one). This is not true for phpRequire, which
+is only entered once, at the main request, and so it is safe to make
+function/class declarations there (in fact that's what it's for).
+
+Hope that helps!
diff --git a/sapi/apache_hooks/apMakefile.libdir b/sapi/apache_hooks/apMakefile.libdir
new file mode 100644
index 0000000..7b52540
--- /dev/null
+++ b/sapi/apache_hooks/apMakefile.libdir
@@ -0,0 +1,4 @@
+This is a place-holder which indicates to Configure that it shouldn't
+provide the default targets when building the Makefile in this directory.
+Instead it'll just prepend all the important variable definitions, and
+copy the Makefile.tmpl onto the end.
diff --git a/sapi/apache_hooks/apMakefile.tmpl b/sapi/apache_hooks/apMakefile.tmpl
new file mode 100644
index 0000000..4054e8e
--- /dev/null
+++ b/sapi/apache_hooks/apMakefile.tmpl
@@ -0,0 +1,77 @@
+##
+## Apache 1.3 Makefile template for PHP 4.0 Module
+## [src/modules/php5/Makefile.tmpl]
+##
+
+# the parametrized target
+LIB=libphp5.$(LIBEXT)
+
+# objects for building the static library
+OBJS=mod_php5.o
+OBJS_LIB=libmodphp5.a
+
+# objects for building the shared object library
+SHLIB_OBJS=mod_php5.so-o
+SHLIB_OBJS_LIB=libmodphp5.a
+
+# the general targets
+all: lib
+lib: $(LIB)
+
+# build the static library by merging the object files
+libphp5.a: $(OBJS) $(OBJS_LIB)
+ cp $(OBJS_LIB) $@
+ ar r $@ $(OBJS)
+ $(RANLIB) $@
+
+# ugly hack to support older Apache-1.3 betas that don't set $LIBEXT
+libphp5.: $(OBJS) $(OBJS_LIB)
+ cp $(OBJS_LIB) $@
+ ar r $@ $(OBJS)
+ $(RANLIB) $@
+ cp libphp5. libphp5.a
+
+# build the shared object library by linking the object files
+libphp5.so: $(SHLIB_OBJS) $(SHLIB_OBJS_LIB)
+ rm -f $@
+ $(LD_SHLIB) $(LDFLAGS_SHLIB) -o $@ $(SHLIB_OBJS) $(SHLIB_OBJS_LIB) $(LIBS) $(PHP_LIBS)
+
+# 1. extension .o for shared objects cannot be used here because
+# first these files aren't still shared objects and second we
+# have to use a different name to trigger the different
+# implicit Make rule
+# 2. extension -so.o (as used elsewhere) cannot be used because
+# the suffix feature of Make really wants just .x, so we use
+# extension .so-o
+.SUFFIXES: .o .so-o
+.c.o:
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $<
+.c.so-o:
+ $(CC) -c $(INCLUDES) $(CFLAGS) $(CFLAGS_SHLIB) $(PHP_CFLAGS) $(CPPFLAGS) $(SPACER) $< && mv $*.o $*.so-o
+
+# cleanup
+clean:
+ -rm -f $(OBJS) $(SHLIB_OBJS) $(LIB)
+
+# We really don't expect end users to use this rule. It works only with
+# gcc, and rebuilds Makefile.tmpl. You have to re-run Configure after
+# using it.
+depend:
+ cp Makefile.tmpl Makefile.tmpl.bak \
+ && sed -ne '1,/^# DO NOT REMOVE/p' Makefile.tmpl > Makefile.new \
+ && gcc -MM $(INCLUDES) $(CFLAGS) $(PHP_CFLAGS) $(CPPFLAGS) *.c >> Makefile.new \
+ && sed -e '1,$$s: $(INCDIR)/: $$(INCDIR)/:g' Makefile.new \
+ > Makefile.tmpl \
+ && rm Makefile.new
+
+#Dependencies
+
+$(OBJS): Makefile
+
+# DO NOT REMOVE
+mod_php5.o: mod_php5.c $(INCDIR)/httpd.h $(INCDIR)/conf.h \
+ $(INCDIR)/buff.h \
+ $(INCDIR)/http_config.h \
+ $(INCDIR)/http_core.h $(INCDIR)/http_main.h \
+ $(INCDIR)/http_protocol.h $(INCDIR)/http_request.h \
+ $(INCDIR)/http_log.h $(INCDIR)/util_script.h mod_php5.h
diff --git a/sapi/apache_hooks/config.m4 b/sapi/apache_hooks/config.m4
new file mode 100644
index 0000000..4213b7c
--- /dev/null
+++ b/sapi/apache_hooks/config.m4
@@ -0,0 +1,275 @@
+dnl
+dnl $Id$
+dnl
+AC_DEFUN([PHP_APACHE_FD_CHECK], [
+AC_CACHE_CHECK([for member fd in BUFF *],ac_cv_php_fd_in_buff,[
+ save=$CPPFLAGS
+ if test -n "$APXS_INCLUDEDIR"; then
+ CPPFLAGS="$CPPFLAGS -I$APXS_INCLUDEDIR"
+ else
+ CPPFLAGS="$CPPFLAGS $APACHE_INCLUDE"
+ fi
+ AC_TRY_COMPILE([#include <httpd.h>],[conn_rec *c; int fd = c->client->fd;],[
+ ac_cv_php_fd_in_buff=yes],[ac_cv_php_fd_in_buff=no],[ac_cv_php_fd_in_buff=no])
+ CPPFLAGS=$save
+])
+if test "$ac_cv_php_fd_in_buff" = "yes"; then
+ AC_DEFINE(PHP_APACHE_HAVE_CLIENT_FD,1,[ ])
+fi
+])
+
+dnl Apache 1.x shared module
+PHP_ARG_WITH(apache-hooks,,
+[ --with-apache-hooks[=FILE]
+ EXPERIMENTAL: Build shared Apache 1.x module. FILE is the optional
+ pathname to the Apache apxs tool [apxs]], no, no)
+
+AC_MSG_CHECKING([for Apache 1.x (hooks) module support via DSO through APXS])
+
+if test "$PHP_APACHE_HOOKS" != "no"; then
+ if test "$PHP_APACHE_HOOKS" = "yes"; then
+ APXS=apxs
+ $APXS -q CFLAGS >/dev/null 2>&1
+ if test "$?" != "0" && test -x /usr/sbin/apxs; then #SUSE 6.x
+ APXS=/usr/sbin/apxs
+ fi
+ else
+ PHP_EXPAND_PATH($PHP_APACHE_HOOKS, APXS)
+ fi
+
+ $APXS -q CFLAGS >/dev/null 2>&1
+ if test "$?" != "0"; then
+ AC_MSG_RESULT()
+ AC_MSG_RESULT()
+ AC_MSG_RESULT([Sorry, I was not able to successfully run APXS. Possible reasons:])
+ AC_MSG_RESULT()
+ AC_MSG_RESULT([1. Perl is not installed;])
+ AC_MSG_RESULT([2. Apache was not compiled with DSO support (--enable-module=so);])
+ AC_MSG_RESULT([3. 'apxs' is not in your path. Try to use --with-apxs=/path/to/apxs])
+ AC_MSG_RESULT([The output of $APXS follows])
+ $APXS -q CFLAGS
+ AC_MSG_ERROR([Aborting])
+ fi
+
+ APXS_LDFLAGS="@SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@"
+ APXS_INCLUDEDIR=`$APXS -q INCLUDEDIR`
+ APXS_CFLAGS=`$APXS -q CFLAGS`
+ APXS_HTTPD=`$APXS -q SBINDIR`/`$APXS -q TARGET`
+ APACHE_INCLUDE=-I$APXS_INCLUDEDIR
+
+ # Test that we're trying to configure with apache 1.x
+ PHP_AP_EXTRACT_VERSION($APXS_HTTPD)
+ if test "$APACHE_VERSION" -ge 2000000; then
+ AC_MSG_ERROR([You have enabled Apache 1.3 support while your server is Apache 2. Please use the appropiate switch --with-apxs2])
+ fi
+
+ for flag in $APXS_CFLAGS; do
+ case $flag in
+ -D*) APACHE_CPPFLAGS="$APACHE_CPPFLAGS $flag";;
+ esac
+ done
+
+ case $host_alias in
+ *aix*)
+ APXS_LIBEXECDIR=`$APXS -q LIBEXECDIR`
+ EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,-brtl -Wl,-bI:$APXS_LIBEXECDIR/httpd.exp"
+ PHP_AIX_LDFLAGS="-Wl,-brtl"
+ build_type=shared
+ ;;
+ *darwin*)
+ MH_BUNDLE_FLAGS="-dynamic -twolevel_namespace -bundle -bundle_loader $APXS_HTTPD"
+ PHP_SUBST(MH_BUNDLE_FLAGS)
+ SAPI_SHARED=libs/libphp5.so
+ build_type=bundle
+ ;;
+ *)
+ build_type=shared
+ ;;
+ esac
+
+ PHP_SELECT_SAPI(apache_hooks, $build_type, sapi_apache.c mod_php5.c php_apache.c, $APACHE_CPPFLAGS -I$APXS_INCLUDEDIR)
+
+ # Test whether apxs support -S option
+ $APXS -q -S CFLAGS="$APXS_CFLAGS" CFLAGS >/dev/null 2>&1
+
+ if test "$?" != "0"; then
+ APACHE_HOOKS_INSTALL="$APXS -i -a -n php5 $SAPI_SHARED" # Old apxs does not have -S option
+ else
+ APXS_LIBEXECDIR='$(INSTALL_ROOT)'`$APXS -q LIBEXECDIR`
+ if test -z `$APXS -q SYSCONFDIR`; then
+ APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
+ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
+ -i -n php5 $SAPI_SHARED"
+ else
+ APXS_SYSCONFDIR='$(INSTALL_ROOT)'`$APXS -q SYSCONFDIR`
+ APACHE_HOOKS_INSTALL="\$(mkinstalldirs) '$APXS_LIBEXECDIR' && \
+ \$(mkinstalldirs) '$APXS_SYSCONFDIR' && \
+ $APXS -S LIBEXECDIR='$APXS_LIBEXECDIR' \
+ -S SYSCONFDIR='$APXS_SYSCONFDIR' \
+ -i -a -n php5 $SAPI_SHARED"
+ fi
+ fi
+
+ if test -z "`$APXS -q LD_SHLIB`" || test "`$APXS -q LIBEXECDIR`" = "modules"; then
+ PHP_APXS_BROKEN=yes
+ fi
+ STRONGHOLD=
+ AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
+ AC_DEFINE(HAVE_AP_COMPAT_H,1,[ ])
+ AC_DEFINE(HAVE_APACHE_HOOKS,1,[ ])
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+fi
+
+dnl Apache 1.x static module
+PHP_ARG_WITH(apache-hooks-static,,
+[ --with-apache-hooks-static[=DIR]
+ EXPERIMENTAL: Build Apache 1.x module. DIR is the top-level Apache
+ build directory [/usr/local/apache]], no, no)
+
+AC_MSG_CHECKING(for Apache 1.x (hooks) module support)
+
+if test "$PHP_SAPI" != "apache" && test "$PHP_SAPI" != "apache_hooks" && test "$PHP_APACHE_HOOKS_STATIC" != "no"; then
+
+ if test "$PHP_APACHE_HOOKS_STATIC" = "yes"; then
+ # Apache's default directory
+ PHP_APACHE_HOOKS_STATIC=/usr/local/apache
+ fi
+
+ APACHE_HOOKS_INSTALL_FILES="\$(srcdir)/sapi/apache_hooks/mod_php5.* sapi/apache_hooks/libphp5.module"
+
+ AC_DEFINE(HAVE_APACHE,1,[ ])
+ APACHE_HOOKS_MODULE=yes
+ PHP_EXPAND_PATH($PHP_APACHE_HOOKS_STATIC, PHP_APACHE_HOOKS_STATIC)
+ # For Apache 1.2.x
+ if test -f $PHP_APACHE_HOOKS_STATIC/src/httpd.h; then
+ APACHE_INCLUDE=-I$PHP_APACHE_HOOKS_STATIC/src
+ APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src
+ PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE)
+ APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET"
+ PHP_LIBS="-L. -lphp3"
+ AC_MSG_RESULT([yes - Apache 1.2.x])
+ STRONGHOLD=
+ if test -f $PHP_APACHE_HOOKS_STATIC/src/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H,1,[ ])
+ fi
+ # For Apache 2.0.x
+ elif test -f $PHP_APACHE_HOOKS_STATIC/include/httpd.h && test -f $PHP_APACHE_HOOKS_STATIC/srclib/apr/include/apr_general.h ; then
+ AC_MSG_ERROR([Use --with-apxs2 with Apache 2.x!])
+ # For Apache 1.3.x
+ elif test -f $PHP_APACHE_HOOKS_STATIC/src/main/httpd.h; then
+ APACHE_HAS_REGEX=1
+ APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/main -I$PHP_APACHE_HOOKS_STATIC/src/os/unix -I$PHP_APACHE_HOOKS_STATIC/src/ap"
+ APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php5
+ if test ! -d $APACHE_TARGET; then
+ mkdir $APACHE_TARGET
+ fi
+ PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE)
+ APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir"
+ PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5"
+ AC_MSG_RESULT([yes - Apache 1.3.x])
+ STRONGHOLD=
+ if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ])
+ fi
+ if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_compat.h; then
+ AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ])
+ if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then
+ AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again])
+ fi
+ elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/compat.h; then
+ AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ])
+ fi
+ # Also for Apache 1.3.x
+ elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/httpd.h; then
+ APACHE_HAS_REGEX=1
+ APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/src/include -I$PHP_APACHE_HOOKS_STATIC/src/os/unix"
+ APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/src/modules/php5
+ if test ! -d $APACHE_TARGET; then
+ mkdir $APACHE_TARGET
+ fi
+ PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE)
+ PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5"
+ APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET; cp $srcdir/sapi/apache_hooks/apMakefile.tmpl $APACHE_TARGET/Makefile.tmpl; cp $srcdir/sapi/apache_hooks/apMakefile.libdir $APACHE_TARGET/Makefile.libdir"
+ AC_MSG_RESULT([yes - Apache 1.3.x])
+ STRONGHOLD=
+ if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ])
+ fi
+ if test -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_compat.h; then
+ AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ])
+ if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then
+ AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again])
+ fi
+ elif test -f $PHP_APACHE_HOOKS_STATIC/src/include/compat.h; then
+ AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ])
+ fi
+ # For StrongHold 2.2
+ elif test -f $PHP_APACHE_HOOKS_STATIC/apache/httpd.h; then
+ APACHE_INCLUDE="-I$PHP_APACHE_HOOKS_STATIC/apache -I$PHP_APACHE_HOOKS_STATIC/ssl/include"
+ APACHE_TARGET=$PHP_APACHE_HOOKS_STATIC/apache
+ PHP_SELECT_SAPI(apache_hooks, static, sapi_apache.c mod_php5.c php_apache.c, $APACHE_INCLUDE)
+ PHP_LIBS="-Lmodules/php5 -L../modules/php5 -L../../modules/php5 -lmodphp5"
+ APACHE_HOOKS_INSTALL="mkdir -p $APACHE_TARGET; cp $SAPI_STATIC $APACHE_TARGET/libmodphp5.a; cp $APACHE_HOOKS_INSTALL_FILES $APACHE_TARGET"
+ STRONGHOLD=-DSTRONGHOLD=1
+ AC_MSG_RESULT([yes - StrongHold])
+ if test -f $PHP_APACHE_HOOKS_STATIC/apache/ap_config.h; then
+ AC_DEFINE(HAVE_AP_CONFIG_H, 1, [ ])
+ fi
+ if test -f $PHP_APACHE_HOOKS_STATIC/src/ap_compat.h; then
+ AC_DEFINE(HAVE_AP_COMPAT_H, 1, [ ])
+ if test ! -f $PHP_APACHE_HOOKS_STATIC/src/include/ap_config_auto.h; then
+ AC_MSG_ERROR([Please run Apache\'s configure or src/Configure program once and try again])
+ fi
+ elif test -f $PHP_APACHE_HOOKS_STATIC/src/compat.h; then
+ AC_DEFINE(HAVE_OLD_COMPAT_H, 1, [ ])
+ fi
+ else
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([Invalid Apache directory - unable to find httpd.h under $PHP_APACHE_HOOKS_STATIC])
+ fi
+else
+ AC_MSG_RESULT(no)
+fi
+
+# compatibility
+if test -z "$enable_mod_charset" && test "$with_mod_charset"; then
+ enable_mod_charset=$with_mod_charset
+fi
+
+PHP_ARG_ENABLE(mod-charset, whether to enable Apache charset compatibility option,
+[ --enable-mod-charset APACHE (hooks): Enable transfer tables for mod_charset (Rus Apache)], no, no)
+
+if test "$PHP_MOD_CHARSET" = "yes"; then
+ AC_DEFINE(USE_TRANSFER_TABLES, 1, [ ])
+fi
+
+dnl Build as static module
+if test "$APACHE_HOOKS_MODULE" = "yes"; then
+ PHP_TARGET_RDYNAMIC
+ $php_shtool mkdir -p sapi/apache_hooks
+ PHP_OUTPUT(sapi/apache_hooks/libphp5.module)
+fi
+
+dnl General
+if test -n "$APACHE_HOOKS_INSTALL"; then
+ if test "x$APXS" != "x" -a "`uname -sv`" = "AIX 4" -a "$GCC" != "yes"; then
+ APXS_EXP=-bE:sapi/apache_hooks/mod_php5.exp
+ fi
+
+ PHP_APACHE_FD_CHECK
+ INSTALL_IT=$APACHE_HOOKS_INSTALL
+
+ PHP_SUBST(APXS_EXP)
+ PHP_SUBST(APACHE_INCLUDE)
+ PHP_SUBST(APACHE_TARGET)
+ PHP_SUBST(APXS)
+ PHP_SUBST(APXS_LDFLAGS)
+ PHP_SUBST(APACHE_HOOKS_INSTALL)
+ PHP_SUBST(STRONGHOLD)
+fi
+
+dnl ## Local Variables:
+dnl ## tab-width: 4
+dnl ## End:
diff --git a/sapi/apache_hooks/config.w32 b/sapi/apache_hooks/config.w32
new file mode 100644
index 0000000..85dc624
--- /dev/null
+++ b/sapi/apache_hooks/config.w32
@@ -0,0 +1,21 @@
+// vim:ft=javascript
+// $Id$
+
+ARG_WITH('apache-hooks', 'Build Apache 1.3.x (hooks) version of PHP', 'no');
+
+if (PHP_APACHE_HOOKS != "no") {
+ if (CHECK_HEADER_ADD_INCLUDE("httpd.h", "CFLAGS_APACHE_HOOKS", php_usual_include_suspects +
+ ";" + PROGRAM_FILES + "\\Apache Group\\Apache\\include" +
+ ";" + PHP_PHP_BUILD + "\\apache\\src\\include") &&
+ CHECK_LIB("ApacheCore.lib", "apache_hooks", php_usual_lib_suspects +
+ ';' + PROGRAM_FILES + '\\Apache Group\\Apache\\libexec' +
+ ";" + PHP_PHP_BUILD + "\\apache\\src\\corer")) {
+ // We need to play tricks to get our readdir.h used by apache
+ // headers
+ SAPI('apache_hooks', 'mod_php5.c sapi_apache.c php_apache.c',
+ 'php' + PHP_VERSION + 'apache_hooks.dll',
+ '/D APACHEPHP5_EXPORTS /D APACHE_READDIR_H /I win32');
+ } else {
+ WARNING("Could not find apache libraries/headers");
+ }
+}
diff --git a/sapi/apache_hooks/libphp5.module.in b/sapi/apache_hooks/libphp5.module.in
new file mode 100644
index 0000000..8488181
--- /dev/null
+++ b/sapi/apache_hooks/libphp5.module.in
@@ -0,0 +1,11 @@
+Name: php5_module
+ConfigStart
+ RULE_WANTHSREGEX=no
+ RULE_HIDE=yes
+ PHP_LIBS="@NATIVE_RPATHS@ @PHP_LDFLAGS@ @PHP_LIBS@ @EXTRA_LIBS@ $LIBS"
+ PHP_CFLAGS="$CFLAGS @OPENSSL_INCDIR_OPT@ -I@php_abs_top_builddir@/main -I@php_abs_top_builddir@/Zend -I@php_abs_top_builddir@/TSRM -I@php_abs_top_srcdir@ -I@php_abs_top_srcdir@/sapi/apache -I@php_abs_top_srcdir@/main -I@php_abs_top_srcdir@/Zend -I@php_abs_top_srcdir@/TSRM"
+ my_outfile="Makefile.config"
+ echo "PHP_CFLAGS=$PHP_CFLAGS" >>$my_outfile
+ echo "PHP_LIBS=$PHP_LIBS" >>$my_outfile
+ LIBS=$PHP_LIBS
+ConfigEnd
diff --git a/sapi/apache_hooks/mod_php5.c b/sapi/apache_hooks/mod_php5.c
new file mode 100644
index 0000000..dda6e49
--- /dev/null
+++ b/sapi/apache_hooks/mod_php5.c
@@ -0,0 +1,1493 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Rasmus Lerdorf <rasmus@php.net> |
+ | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
+ | PHP 4.0 patches by Zeev Suraski <zeev@zend.com> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#include "php_apache_http.h"
+
+#ifdef NETWARE
+#define SIGPIPE SIGINT
+#endif
+
+#undef shutdown
+
+/* {{{ Prototypes
+ */
+int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC);
+static void php_save_umask(void);
+static void php_restore_umask(void);
+static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC);
+static char *sapi_apache_read_cookies(TSRMLS_D);
+static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC);
+static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC);
+static int send_php(request_rec *r, int display_source_mode, char *filename);
+static int send_parsed_php(request_rec * r);
+static int send_parsed_php_source(request_rec * r);
+static int php_xbithack_handler(request_rec * r);
+static void php_init_handler(server_rec *s, pool *p);
+/* }}} */
+
+#if MODULE_MAGIC_NUMBER >= 19970728
+static void php_child_exit_handler(server_rec *s, pool *p);
+#endif
+
+#if MODULE_MAGIC_NUMBER > 19961007
+#define CONST_PREFIX const
+#else
+#define CONST_PREFIX
+#endif
+
+
+typedef struct _sapi_stack {
+ int top, max, persistent;
+ void **elements;
+} sapi_stack;
+
+typedef struct _php_per_dir_config {
+ HashTable *ini_settings;
+ sapi_stack headers_handlers;
+ sapi_stack auth_handlers;
+ sapi_stack access_handlers;
+ sapi_stack type_handlers;
+ sapi_stack fixup_handlers;
+ sapi_stack logger_handlers;
+ sapi_stack post_read_handlers;
+ sapi_stack response_handlers;
+} php_per_dir_config;
+
+typedef struct _php_per_server_config {
+ sapi_stack uri_handlers;
+ sapi_stack requires;
+} php_per_server_config;
+
+
+static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2);
+static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2);
+static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2);
+static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode);
+static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2);
+
+/* ### these should be defined in mod_php5.h or somewhere else */
+#define USE_PATH 1
+#define IGNORE_URL 2
+
+module MODULE_VAR_EXPORT php5_module;
+
+int saved_umask;
+/* static int setup_env = 0; */
+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;
+
+/* some systems are missing these from their header files */
+
+/* {{{ zend stack utility functions
+ */
+
+/* This code is ripped part and parcel from zend_stack.[ch]. Assuming that the
+ patch supporting zend_stack_init_ex is applied, all but the bottom two
+ module-specific iterators will be removed
+ */
+
+int sapi_stack_init_ex(sapi_stack *stack, int persistent)
+{
+ stack->top = 0;
+ stack->persistent = persistent;
+ stack->elements = (void **) pemalloc(sizeof(void **) * STACK_BLOCK_SIZE, persistent);
+ if (!stack->elements) {
+ return FAILURE;
+ } else {
+ stack->max = STACK_BLOCK_SIZE;
+ return SUCCESS;
+ }
+}
+int sapi_stack_push(sapi_stack *stack, void *element)
+{
+ if (stack->top >= stack->max) { /* we need to allocate more memory */
+ stack->elements = (void **) perealloc(stack->elements,
+ (sizeof(void **) * (stack->max += STACK_BLOCK_SIZE)), stack->persistent);
+ if (!stack->elements) {
+ return FAILURE;
+ }
+ }
+ stack->elements[stack->top] = (void *) element;
+ return stack->top++;
+}
+void* sapi_stack_pop(sapi_stack *stack) {
+ if(stack->top == 0) {
+ return NULL;
+ }
+ else {
+ return stack->elements[--stack->top];
+ }
+}
+
+int sapi_stack_destroy(sapi_stack *stack)
+{
+ return SUCCESS;
+}
+
+int sapi_stack_apply_with_argument_all(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
+{
+ int i, retval;
+
+ switch (type) {
+ case ZEND_STACK_APPLY_TOPDOWN:
+ for (i=stack->top-1; i>=0; i--) {
+ retval = apply_function(stack->elements[i], arg);
+ }
+ break;
+ case ZEND_STACK_APPLY_BOTTOMUP:
+ for (i=0; i<stack->top; i++) {
+ retval = apply_function(stack->elements[i], arg);
+ }
+ break;
+ }
+ return retval;
+}
+
+
+int sapi_stack_apply_with_argument_stop_if_equals(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg, int stopval)
+{
+ int i;
+ int ret = DECLINED;
+ switch (type) {
+ case ZEND_STACK_APPLY_TOPDOWN:
+ for (i=stack->top-1; i>=0; i--) {
+ if ((ret = apply_function(stack->elements[i], arg)) == stopval) {
+ break;
+ }
+ }
+ break;
+ case ZEND_STACK_APPLY_BOTTOMUP:
+ for (i=0; i<stack->top; i++) {
+ if ((ret = apply_function(stack->elements[i], arg)) == stopval) {
+ break;
+ }
+ }
+ break;
+ }
+ return ret;
+}
+
+int sapi_stack_apply_with_argument_stop_if_http_error(sapi_stack *stack, int type, int (*apply_function)(void *element, void *arg), void *arg)
+{
+ int i;
+ int ret = DECLINED;
+ switch (type) {
+ case ZEND_STACK_APPLY_TOPDOWN:
+ for (i=stack->top-1; i>=0; i--) {
+ if ((ret = apply_function(stack->elements[i], arg)) > 0) {
+ break;
+ }
+ }
+ break;
+ case ZEND_STACK_APPLY_BOTTOMUP:
+ for (i=0; i<stack->top; i++) {
+ if ((ret = apply_function(stack->elements[i], arg)) > 0) {
+ break;
+ }
+ }
+ break;
+ }
+ return ret;
+}
+
+void php_handler_stack_destroy(sapi_stack *stack)
+{
+ php_handler *ph;
+ while((ph = (php_handler *)sapi_stack_pop(stack)) != NULL) {
+ free(ph->name);
+ free(ph);
+ }
+}
+/* }}} */
+
+/* {{{ php_save_umask
+ */
+static void php_save_umask(void)
+{
+ saved_umask = umask(077);
+ umask(saved_umask);
+}
+/* }}} */
+
+/* {{{ sapi_apache_ub_write
+ */
+static int sapi_apache_ub_write(const char *str, uint str_length TSRMLS_DC)
+{
+ int ret=0;
+
+ if (SG(server_context)) {
+ ret = rwrite(str, str_length, (request_rec *) SG(server_context));
+ }
+ if (ret != str_length) {
+ php_handle_aborted_connection();
+ }
+ return ret;
+}
+/* }}} */
+
+/* {{{ sapi_apache_flush
+ */
+static void sapi_apache_flush(void *server_context)
+{
+ if (server_context) {
+#if MODULE_MAGIC_NUMBER > 19970110
+ rflush((request_rec *) server_context);
+#else
+ bflush((request_rec *) server_context->connection->client);
+#endif
+ }
+}
+/* }}} */
+
+/* {{{ sapi_apache_read_post
+ */
+static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC)
+{
+ uint total_read_bytes=0, read_bytes;
+ request_rec *r = (request_rec *) SG(server_context);
+ void (*handler)(int);
+
+ /*
+ * This handles the situation where the browser sends a Expect: 100-continue header
+ * and needs to recieve confirmation from the server on whether or not it can send
+ * the rest of the request. RFC 2616
+ *
+ */
+ if (!SG(read_post_bytes) && !ap_should_client_block(r)) {
+ return total_read_bytes;
+ }
+
+ handler = signal(SIGPIPE, SIG_IGN);
+ while (total_read_bytes<count_bytes) {
+ hard_timeout("Read POST information", r); /* start timeout timer */
+ read_bytes = get_client_block(r, buffer+total_read_bytes, count_bytes-total_read_bytes);
+ reset_timeout(r);
+ if (read_bytes<=0) {
+ break;
+ }
+ total_read_bytes += read_bytes;
+ }
+ signal(SIGPIPE, handler);
+ return total_read_bytes;
+}
+/* }}} */
+
+/* {{{ sapi_apache_read_cookies
+ */
+static char *sapi_apache_read_cookies(TSRMLS_D)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, "HTTP_COOKIE");
+}
+/* }}} */
+
+/* {{{ sapi_apache_header_handler
+ */
+static int sapi_apache_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC)
+{
+ char *header_name, *header_content, *p;
+ request_rec *r = (request_rec *) SG(server_context);
+ if(!r) {
+ return 0;
+ }
+
+ switch(op) {
+ case SAPI_HEADER_DELETE_ALL:
+ clear_table(r->headers_out);
+ return 0;
+
+ case SAPI_HEADER_DELETE:
+ table_unset(r->headers_out, sapi_header->header);
+ return 0;
+
+ case SAPI_HEADER_ADD:
+ case SAPI_HEADER_REPLACE:
+ header_name = sapi_header->header;
+
+ header_content = p = strchr(header_name, ':');
+ if (!p) {
+ return 0;
+ }
+
+ *p = 0;
+ do {
+ header_content++;
+ } while (*header_content==' ');
+
+ if (!strcasecmp(header_name, "Content-Type")) {
+ r->content_type = pstrdup(r->pool, header_content);
+ } else if (!strcasecmp(header_name, "Set-Cookie")) {
+ table_add(r->headers_out, header_name, header_content);
+ } else if (op == SAPI_HEADER_REPLACE) {
+ table_set(r->headers_out, header_name, header_content);
+ } else {
+ table_add(r->headers_out, header_name, header_content);
+ }
+
+ *p = ':'; /* a well behaved header handler shouldn't change its original arguments */
+
+ return SAPI_HEADER_ADD;
+
+ default:
+ return 0;
+ }
+}
+/* }}} */
+
+/* {{{ sapi_apache_send_headers
+ */
+static int sapi_apache_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
+{
+ 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;
+ /* check that we haven't sent headers already, we use our own
+ * headers_sent since we may send headers at anytime
+ */
+ if(!AP(headers_sent)) {
+ send_http_header((request_rec *) SG(server_context));
+ AP(headers_sent) = 1;
+ }
+ return SAPI_HEADER_SENT_SUCCESSFULLY;
+}
+/* }}} */
+
+/* {{{ sapi_apache_register_server_variables
+ */
+static void sapi_apache_register_server_variables(zval *track_vars_array TSRMLS_DC)
+{
+ register int i;
+ array_header *arr = table_elts(((request_rec *) SG(server_context))->subprocess_env);
+ table_entry *elts = (table_entry *) arr->elts;
+ zval **path_translated;
+ HashTable *symbol_table;
+
+ for (i = 0; i < arr->nelts; i++) {
+ char *val;
+
+ if (elts[i].val) {
+ val = elts[i].val;
+ } else {
+ val = "";
+ }
+ php_register_variable(elts[i].key, val, track_vars_array TSRMLS_CC);
+ }
+
+ /* If PATH_TRANSLATED doesn't exist, copy it from SCRIPT_FILENAME */
+ if (track_vars_array) {
+ symbol_table = track_vars_array->value.ht;
+ } else {
+ symbol_table = NULL;
+ }
+ if (symbol_table
+ && !zend_hash_exists(symbol_table, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"))
+ && zend_hash_find(symbol_table, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &path_translated)==SUCCESS) {
+ php_register_variable("PATH_TRANSLATED", Z_STRVAL_PP(path_translated), track_vars_array TSRMLS_CC);
+ }
+
+ php_register_variable("PHP_SELF", ((request_rec *) SG(server_context))->uri, track_vars_array TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ php_apache_startup
+ */
+static int php_apache_startup(sapi_module_struct *sapi_module)
+{
+ if (php_module_startup(sapi_module, &apache_module_entry, 1) == FAILURE) {
+ return FAILURE;
+ } else {
+ return SUCCESS;
+ }
+}
+/* }}} */
+
+/* {{{ php_apache_log_message
+ */
+static void php_apache_log_message(char *message TSRMLS_DC)
+{
+ if (SG(server_context)) {
+#if MODULE_MAGIC_NUMBER >= 19970831
+ aplog_error(NULL, 0, APLOG_ERR | APLOG_NOERRNO, ((request_rec *) SG(server_context))->server, "%s", message);
+#else
+ log_error(message, ((request_rec *) SG(server_context))->server);
+#endif
+ } else {
+ fprintf(stderr, "%s", message);
+ fprintf(stderr, "\n");
+ }
+}
+/* }}} */
+
+/* {{{ php_apache_request_shutdown
+ */
+static void php_apache_request_shutdown(void *dummy)
+{
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_CLEANUP;
+ php_output_set_status(PHP_OUTPUT_DISABLED TSRMLS_CC);
+ SG(server_context) = NULL; /* The server context (request) is invalid by the time run_cleanups() is called */
+ if(SG(sapi_started)) {
+ php_request_shutdown(dummy);
+ SG(sapi_started) = 0;
+ }
+ AP(in_request) = 0;
+ if(AP(setup_env)) {
+ AP(setup_env) = 0;
+ }
+ AP(current_hook) = AP_WAITING_FOR_REQUEST;
+ AP(headers_sent) = 0;
+}
+/* }}} */
+
+/* {{{ php_apache_sapi_activate
+ */
+static int php_apache_sapi_activate(TSRMLS_D)
+{
+ request_rec *r = (request_rec *) SG(server_context);
+
+ /*
+ * For the Apache module version, this bit of code registers a cleanup
+ * function that gets triggered when our request pool is destroyed.
+ * We need this because at any point in our code we can be interrupted
+ * and that may happen before we have had time to free our memory.
+ * The php_request_shutdown function needs to free all outstanding allocated
+ * memory.
+ */
+ block_alarms();
+ register_cleanup(r->pool, NULL, php_apache_request_shutdown, php_request_shutdown_for_exec);
+ AP(in_request)=1;
+ unblock_alarms();
+
+ /* Override the default headers_only value - sometimes "GET" requests should actually only
+ * send headers.
+ */
+ SG(request_info).headers_only = r->header_only;
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ php_apache_get_stat
+ */
+static struct stat *php_apache_get_stat(TSRMLS_D)
+{
+ return &((request_rec *) SG(server_context))->finfo;
+}
+/* }}} */
+
+/* {{{ php_apache_getenv
+ */
+static char *php_apache_getenv(char *name, size_t name_len TSRMLS_DC)
+{
+ return (char *) table_get(((request_rec *) SG(server_context))->subprocess_env, name);
+}
+/* }}} */
+
+/* {{{ sapi_module_struct apache_sapi_module
+ */
+static sapi_module_struct apache_sapi_module = {
+ "apache", /* name */
+ "Apache", /* pretty name */
+
+ php_apache_startup, /* startup */
+ php_module_shutdown_wrapper, /* shutdown */
+
+ php_apache_sapi_activate, /* activate */
+ NULL, /* deactivate */
+
+ sapi_apache_ub_write, /* unbuffered write */
+ sapi_apache_flush, /* flush */
+ php_apache_get_stat, /* get uid */
+ php_apache_getenv, /* getenv */
+
+ php_error, /* error handler */
+
+ sapi_apache_header_handler, /* header handler */
+ sapi_apache_send_headers, /* send headers handler */
+ NULL, /* send header handler */
+
+ sapi_apache_read_post, /* read POST data */
+ sapi_apache_read_cookies, /* read Cookies */
+
+ sapi_apache_register_server_variables, /* register server variables */
+ php_apache_log_message, /* Log message */
+ NULL, /* Get request time */
+ NULL, /* child terminate */
+
+ NULL, /* php.ini path override */
+
+#ifdef PHP_WIN32
+ NULL,
+ NULL,
+#else
+ block_alarms, /* Block interruptions */
+ unblock_alarms, /* Unblock interruptions */
+#endif
+
+ NULL, /* default post reader */
+ NULL, /* treat data */
+ NULL, /* exe location */
+ 0, /* ini ignore */
+ NULL
+
+};
+/* }}} */
+
+/* {{{ php_restore_umask
+ */
+static void php_restore_umask(void)
+{
+ umask(saved_umask);
+}
+/* }}} */
+
+/* {{{ init_request_info
+ */
+static void init_request_info(TSRMLS_D)
+{
+ request_rec *r = ((request_rec *) SG(server_context));
+ char *content_length = (char *) table_get(r->subprocess_env, "CONTENT_LENGTH");
+ const char *authorization=NULL;
+ char *tmp, *tmp_user;
+
+ SG(request_info).query_string = r->args;
+ SG(request_info).path_translated = r->filename;
+ SG(request_info).request_uri = r->uri;
+ SG(request_info).request_method = (char *)r->method;
+ SG(request_info).proto_num = r->proto_num;
+ SG(request_info).content_type = (char *) table_get(r->subprocess_env, "CONTENT_TYPE");
+ SG(request_info).content_length = (content_length ? atol(content_length) : 0);
+ SG(sapi_headers).http_response_code = r->status;
+
+ if (r->headers_in) {
+ authorization = table_get(r->headers_in, "Authorization");
+ }
+
+ SG(request_info).auth_user = NULL;
+ SG(request_info).auth_password = NULL;
+
+ if (authorization && !auth_type(r)) {
+ if (!strcasecmp(getword(r->pool, &authorization, ' '), "Basic")) {
+ tmp = uudecode(r->pool, authorization);
+ tmp_user = getword_nulls_nc(r->pool, &tmp, ':');
+ if (tmp_user) {
+ r->connection->user = pstrdup(r->connection->pool, tmp_user);
+ r->connection->ap_auth_type = "Basic";
+ SG(request_info).auth_user = estrdup(tmp_user);
+ }
+ if (tmp) {
+ SG(request_info).auth_password = estrdup(tmp);
+ }
+ } else if (!strcasecmp(getword(r->pool, &authorization, ' '), "Digest")) {
+ r->connection->ap_auth_type = "Digest";
+ SG(request_info).auth_digest = estrdup(authorization);
+ }
+ }
+}
+/* }}} */
+
+/* {{{ php_apache_alter_ini_entries
+ */
+static int php_apache_alter_ini_entries(php_per_dir_entry *per_dir_entry TSRMLS_DC)
+{
+ zend_alter_ini_entry(per_dir_entry->key, per_dir_entry->key_length+1, per_dir_entry->value, per_dir_entry->value_length, per_dir_entry->type, PHP_INI_STAGE_ACTIVATE);
+ return 0;
+}
+/* }}} */
+
+/* {{{ php_apache_get_default_mimetype
+ */
+static char *php_apache_get_default_mimetype(request_rec *r TSRMLS_DC)
+{
+
+ char *mimetype;
+ if (SG(default_mimetype) || SG(default_charset)) {
+ /* Assume output will be of the default MIME type. Individual
+ scripts may change this later. */
+ char *tmpmimetype;
+ tmpmimetype = sapi_get_default_content_type(TSRMLS_C);
+ mimetype = pstrdup(r->pool, tmpmimetype);
+ efree(tmpmimetype);
+ } else {
+ mimetype = SAPI_DEFAULT_MIMETYPE "; charset=" SAPI_DEFAULT_CHARSET;
+ }
+ return mimetype;
+}
+/* }}} */
+
+/* {{{ send_php
+ */
+static int send_php(request_rec *r, int display_source_mode, char *filename)
+{
+ int retval;
+ php_per_dir_config *per_dir_conf;
+ TSRMLS_FETCH();
+ if (AP(in_request)) {
+ zend_file_handle fh;
+
+ fh.filename = r->filename;
+ fh.opened_path = NULL;
+ fh.free_filename = 0;
+ fh.type = ZEND_HANDLE_FILENAME;
+
+ zend_execute_scripts(ZEND_INCLUDE TSRMLS_CC, NULL, 1, &fh);
+ return OK;
+ }
+
+ zend_first_try {
+
+ /* Make sure file exists */
+ if (filename == NULL && r->finfo.st_mode == 0) {
+ return DECLINED;
+ }
+
+ per_dir_conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ if (per_dir_conf) {
+ zend_hash_apply((HashTable *) per_dir_conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ }
+
+ /* If PHP parser engine has been turned off with an "engine off"
+ * directive, then decline to handle this request
+ */
+ if (!AP(engine)) {
+ r->content_type = php_apache_get_default_mimetype(r TSRMLS_CC);
+ r->allowed |= (1 << METHODS) - 1;
+ zend_try {
+ zend_ini_deactivate(TSRMLS_C);
+ } zend_end_try();
+ return DECLINED;
+ }
+ if (filename == NULL) {
+ filename = r->filename;
+ }
+
+ /* Apache 1.2 has a more complex mechanism for reading POST data */
+#if MODULE_MAGIC_NUMBER > 19961007
+ if ((retval = setup_client_block(r, REQUEST_CHUNKED_ERROR))) {
+ zend_try {
+ zend_ini_deactivate(TSRMLS_C);
+ } zend_end_try();
+ return retval;
+ }
+#endif
+
+ if (AP(last_modified)) {
+#if MODULE_MAGIC_NUMBER < 19970912
+ if ((retval = set_last_modified(r, r->finfo.st_mtime))) {
+ zend_try {
+ zend_ini_deactivate(TSRMLS_C);
+ } zend_end_try();
+ return retval;
+ }
+#else
+ update_mtime (r, r->finfo.st_mtime);
+ set_last_modified(r);
+ set_etag(r);
+#endif
+ }
+ /* Assume output will be of the default MIME type. Individual
+ scripts may change this later in the request. */
+ r->content_type = php_apache_get_default_mimetype(r TSRMLS_CC);
+
+ /* Init timeout */
+ hard_timeout("send", r);
+
+ SG(server_context) = r;
+
+ php_save_umask();
+ if(!AP(setup_env)) {
+ AP(setup_env) = 1;
+ add_common_vars(r);
+ add_cgi_vars(r);
+ }
+ init_request_info(TSRMLS_C);
+ apache_php_module_main(r, display_source_mode TSRMLS_CC);
+
+ /* Done, restore umask, turn off timeout, close file and return */
+ php_restore_umask();
+ kill_timeout(r);
+ } zend_end_try();
+
+ return OK;
+}
+/* }}} */
+
+/* {{{ send_parsed_php
+ */
+static int send_parsed_php(request_rec * r)
+{
+ int result = send_php(r, 0, NULL);
+ TSRMLS_FETCH();
+
+ ap_table_setn(r->notes, "mod_php_memory_usage",
+ ap_psprintf(r->pool, "%u", zend_memory_peak_usage(1 TSRMLS_CC)));
+
+ return result;
+}
+/* }}} */
+
+/* {{{ send_parsed_php_source
+ */
+static int send_parsed_php_source(request_rec * r)
+{
+ return send_php(r, 1, NULL);
+}
+/* }}} */
+
+
+/* {{{ destroy_per_dir_entry
+ */
+static void destroy_per_dir_entry(php_per_dir_entry *per_dir_entry)
+{
+ free(per_dir_entry->key);
+ free(per_dir_entry->value);
+}
+/* }}} */
+
+/* {{{ copy_per_dir_entry
+ */
+static void copy_per_dir_entry(php_per_dir_entry *per_dir_entry)
+{
+ php_per_dir_entry tmp = *per_dir_entry;
+
+ per_dir_entry->key = (char *) malloc(tmp.key_length+1);
+ memcpy(per_dir_entry->key, tmp.key, tmp.key_length);
+ per_dir_entry->key[per_dir_entry->key_length] = 0;
+
+ per_dir_entry->value = (char *) malloc(tmp.value_length+1);
+ memcpy(per_dir_entry->value, tmp.value, tmp.value_length);
+ per_dir_entry->value[per_dir_entry->value_length] = 0;
+}
+/* }}} */
+
+/* {{{ should_overwrite_per_dir_entry;
+
+ */
+static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_per_dir_entry *orig_per_dir_entry, zend_hash_key *hash_key, void *pData)
+{
+ php_per_dir_entry *new_per_dir_entry;
+
+ if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &new_per_dir_entry)==FAILURE) {
+ return 1; /* does not exist in dest, copy from source */
+ }
+
+ if (new_per_dir_entry->type==PHP_INI_SYSTEM
+ && orig_per_dir_entry->type!=PHP_INI_SYSTEM) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+/* }}} */
+/* {{{ php_destroy_per_server_info
+ */
+static void php_destroy_per_server_info(php_per_server_config *conf)
+{
+ php_handler_stack_destroy(&conf->requires);
+ php_handler_stack_destroy(&conf->uri_handlers);
+}
+/* }}} */
+
+/* {{{ php_destroy_per_dir_info
+ */
+static void php_destroy_per_dir_info(php_per_dir_config *conf)
+{
+ zend_hash_destroy(conf->ini_settings);
+ php_handler_stack_destroy(&conf->response_handlers);
+ php_handler_stack_destroy(&conf->auth_handlers);
+ php_handler_stack_destroy(&conf->access_handlers);
+ php_handler_stack_destroy(&conf->type_handlers);
+ php_handler_stack_destroy(&conf->fixup_handlers);
+ php_handler_stack_destroy(&conf->logger_handlers);
+ php_handler_stack_destroy(&conf->post_read_handlers);
+ php_handler_stack_destroy(&conf->headers_handlers);
+ free(conf->ini_settings);
+}
+/* }}} */
+
+/* {{{ php_create_server
+ */
+static void *php_create_server(pool *p, char *dummy)
+{
+ php_per_server_config *conf;
+ conf = (php_per_server_config *) malloc(sizeof(php_per_server_config));
+ register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_server_info, (void (*)(void *)) php_destroy_per_server_info);
+
+ sapi_stack_init_ex(&conf->requires, 1);
+ sapi_stack_init_ex(&conf->uri_handlers, 1);
+ return conf;
+}
+
+/* }}} */
+
+
+/* {{{ php_create_dir
+ */
+static void *php_create_dir(pool *p, char *dummy)
+{
+ php_per_dir_config *conf;
+ conf = (php_per_dir_config *) malloc(sizeof(php_per_dir_config));
+ conf->ini_settings = (HashTable *) malloc(sizeof(HashTable));
+ zend_hash_init_ex(conf->ini_settings, 5, NULL, (void (*)(void *)) destroy_per_dir_entry, 1, 0);
+ sapi_stack_init_ex(&conf->response_handlers, 1);
+ sapi_stack_init_ex(&conf->headers_handlers, 1);
+ sapi_stack_init_ex(&conf->auth_handlers, 1);
+ sapi_stack_init_ex(&conf->access_handlers, 1);
+ sapi_stack_init_ex(&conf->type_handlers, 1);
+ sapi_stack_init_ex(&conf->fixup_handlers, 1);
+ sapi_stack_init_ex(&conf->logger_handlers, 1);
+ sapi_stack_init_ex(&conf->post_read_handlers, 1);
+ register_cleanup(p, (void *) conf, (void (*)(void *)) php_destroy_per_dir_info, (void (*)(void *)) php_destroy_per_dir_info);
+
+ return conf;
+}
+
+/* }}} */
+
+/* {{{ php_merge_dir
+ */
+static void *php_merge_dir(pool *p, void *basev, void *addv)
+{
+ php_per_dir_config *a = (php_per_dir_config *) addv;
+ php_per_dir_config *b = (php_per_dir_config *) basev;
+ /* This function *must* return addv, and not modify basev */
+ zend_hash_merge_ex((HashTable *) a->ini_settings, (HashTable *) b->ini_settings, (copy_ctor_func_t) copy_per_dir_entry, sizeof(php_per_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL);
+ a->headers_handlers = (a->headers_handlers.top)?a->headers_handlers:b->headers_handlers;
+ a->auth_handlers = (a->auth_handlers.top)?a->auth_handlers:b->auth_handlers;
+ a->access_handlers = (a->access_handlers.top)?a->access_handlers:b->access_handlers;
+ a->type_handlers = (a->type_handlers.top)?a->type_handlers:b->type_handlers;
+ a->fixup_handlers = (a->fixup_handlers.top)?a->fixup_handlers:b->fixup_handlers;
+ a->logger_handlers = (a->logger_handlers.top)?a->logger_handlers:b->logger_handlers;
+ a->post_read_handlers = (a->post_read_handlers.top)?a->post_read_handlers:b->post_read_handlers;
+ a->response_handlers = (a->response_handlers.top)?a->response_handlers:b->response_handlers;
+ return a;
+}
+/* }}} */
+
+/* {{{ php_apache_value_handler_ex
+ */
+static CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode)
+{
+ php_per_dir_entry per_dir_entry;
+
+ if (!apache_php_initialized) {
+ apache_php_initialized = 1;
+#ifdef ZTS
+ tsrm_startup(1, 1, 0, NULL);
+#endif
+ sapi_startup(&apache_sapi_module);
+ php_apache_startup(&apache_sapi_module);
+ }
+ per_dir_entry.type = mode;
+
+ if (strcasecmp(arg2, "none") == 0) {
+ arg2 = "";
+ }
+
+ per_dir_entry.key_length = strlen(arg1);
+ per_dir_entry.value_length = strlen(arg2);
+
+ per_dir_entry.key = (char *) malloc(per_dir_entry.key_length+1);
+ memcpy(per_dir_entry.key, arg1, per_dir_entry.key_length);
+ per_dir_entry.key[per_dir_entry.key_length] = 0;
+
+ per_dir_entry.value = (char *) malloc(per_dir_entry.value_length+1);
+ memcpy(per_dir_entry.value, arg2, per_dir_entry.value_length);
+ per_dir_entry.value[per_dir_entry.value_length] = 0;
+
+ zend_hash_update(conf, per_dir_entry.key, per_dir_entry.key_length, &per_dir_entry, sizeof(php_per_dir_entry), NULL);
+ return NULL;
+}
+/* }}} */
+
+static CONST_PREFIX char *php_set_server_handler(server_rec *s, char *arg1, long handler_stage, long handler_type)
+{
+ php_per_server_config *conf;
+ php_handler *handler;
+ handler = (php_handler *) malloc(sizeof(php_handler));
+ handler->type = handler_type;
+ handler->stage = handler_stage;
+ handler->name = strdup(arg1);
+ conf = get_module_config(s->module_config, &php5_module);
+ switch(handler_stage) {
+ case AP_URI_TRANS:
+ sapi_stack_push(&conf->uri_handlers, handler);
+ break;
+ default:
+ sapi_stack_push(&conf->requires, handler);
+ break;
+ }
+ return NULL;
+}
+
+static CONST_PREFIX char *php_set_dir_handler(php_per_dir_config *conf, char *arg1, long handler_stage, long handler_type)
+{
+ php_handler *handler;
+ handler = (php_handler *) malloc(sizeof(php_handler));
+ handler->type = handler_type;
+ handler->stage = handler_stage;
+ handler->name = strdup(arg1);
+ switch(handler_stage) {
+ case AP_POST_READ:
+ sapi_stack_push(&conf->post_read_handlers, handler);
+ break;
+ case AP_HEADER_PARSE:
+ sapi_stack_push(&conf->headers_handlers, handler);
+ break;
+ case AP_ACCESS_CONTROL:
+ sapi_stack_push(&conf->access_handlers, handler);
+ break;
+ case AP_AUTHENTICATION:
+ sapi_stack_push(&conf->auth_handlers, handler);
+ break;
+ case AP_AUTHORIZATION:
+ break;
+ case AP_TYPE_CHECKING:
+ sapi_stack_push(&conf->type_handlers, handler);
+ break;
+ case AP_FIXUP:
+ sapi_stack_push(&conf->fixup_handlers, handler);
+ break;
+ case AP_RESPONSE:
+ sapi_stack_push(&conf->response_handlers, handler);
+ break;
+ case AP_LOGGING:
+ sapi_stack_push(&conf->logger_handlers, handler);
+ break;
+ default:
+ break;
+ }
+ return NULL;
+}
+
+/* {{{ php_set_uri_handler
+ */
+static CONST_PREFIX char *php_set_uri_handler(cmd_parms *cmd, void *dummy, char *arg1)
+{
+ return php_set_server_handler(cmd->server, arg1, AP_URI_TRANS, AP_HANDLER_TYPE_FILE);
+}
+/* }}} */
+
+/* {{{ php_set_uri_handler_code */
+static CONST_PREFIX char *php_set_uri_handler_code(cmd_parms *cmd, void *dummy, char *arg1)
+{
+ return php_set_server_handler(cmd->server, arg1, AP_URI_TRANS, AP_HANDLER_TYPE_METHOD);
+}
+/* }}} */
+
+/* {{{ php_set_header_handler
+ */
+static CONST_PREFIX char *php_set_header_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_HEADER_PARSE, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_header_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_HEADER_PARSE, AP_HANDLER_TYPE_METHOD);
+}
+/* }}} */
+
+/* {{{ php_set_auth_handler
+ */
+static CONST_PREFIX char *php_set_auth_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_AUTHENTICATION, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_auth_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_AUTHENTICATION, AP_HANDLER_TYPE_METHOD);
+}
+
+/* }}} */
+
+/* {{{ php_set_access_handler
+ */
+static CONST_PREFIX char *php_set_access_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_ACCESS_CONTROL, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_access_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_ACCESS_CONTROL, AP_HANDLER_TYPE_METHOD);
+}
+
+/* }}} */
+
+/* {{{ php_set_type_handler
+ */
+static CONST_PREFIX char *php_set_type_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_TYPE_CHECKING, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_type_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_TYPE_CHECKING, AP_HANDLER_TYPE_METHOD);
+}
+
+/* }}} */
+
+/* {{{ php_set_fixup_handler
+ */
+static CONST_PREFIX char *php_set_fixup_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_FIXUP, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_fixup_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_FIXUP, AP_HANDLER_TYPE_METHOD);
+}
+/* }}} */
+
+/* {{{ php_set_logger_handler
+ */
+static CONST_PREFIX char *php_set_logger_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_LOGGING, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_logger_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_LOGGING, AP_HANDLER_TYPE_METHOD);
+}
+
+/* }}} */
+
+/* {{{ php_set_post_read_handler
+ */
+static CONST_PREFIX char *php_set_post_read_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_POST_READ, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_post_read_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_POST_READ, AP_HANDLER_TYPE_METHOD);
+}
+
+
+/* }}} */
+
+/* {{{ php_set_require
+ */
+
+static CONST_PREFIX char *php_set_require(cmd_parms *cmd, void *dummy, char *arg1)
+{
+ return php_set_server_handler(cmd->server, arg1, 0, AP_HANDLER_TYPE_FILE);
+}
+/* }}} */
+
+/* {{{ php_set_response_handler
+ */
+static CONST_PREFIX char *php_set_response_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_RESPONSE, AP_HANDLER_TYPE_FILE);
+}
+static CONST_PREFIX char *php_set_response_handler_code(cmd_parms *cmd, php_per_dir_config *conf, char *arg1)
+{
+ return php_set_dir_handler(conf, arg1, AP_RESPONSE, AP_HANDLER_TYPE_METHOD);
+}
+/* }}} */
+
+/* {{{ php_apache_value_handler
+ */
+static CONST_PREFIX char *php_apache_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2)
+{
+ return php_apache_value_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_PERDIR);
+}
+/* }}} */
+
+/* {{{ php_apache_admin_value_handler
+ */
+static CONST_PREFIX char *php_apache_admin_value_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2)
+{
+ return php_apache_value_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_SYSTEM);
+}
+/* }}} */
+
+/* {{{ php_apache_flag_handler_ex
+ */
+static CONST_PREFIX char *php_apache_flag_handler_ex(cmd_parms *cmd, HashTable *conf, char *arg1, char *arg2, int mode)
+{
+ char bool_val[2];
+
+ if (!strcasecmp(arg2, "On")) {
+ bool_val[0] = '1';
+ } else {
+ bool_val[0] = '0';
+ }
+ bool_val[1] = 0;
+
+ return php_apache_value_handler_ex(cmd, conf, arg1, bool_val, mode);
+}
+/* }}} */
+
+/* {{{ php_apache_flag_handler
+ */
+static CONST_PREFIX char *php_apache_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2)
+{
+ return php_apache_flag_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_PERDIR);
+}
+/* }}} */
+
+/* {{{ php_apache_admin_flag_handler
+ */
+static CONST_PREFIX char *php_apache_admin_flag_handler(cmd_parms *cmd, php_per_dir_config *conf, char *arg1, char *arg2)
+{
+ return php_apache_flag_handler_ex(cmd, conf->ini_settings, arg1, arg2, PHP_INI_SYSTEM);
+}
+/* }}} */
+
+/* {{{ php_apache_phpini_set
+ */
+static CONST_PREFIX char *php_apache_phpini_set(cmd_parms *cmd, HashTable *conf, char *arg)
+{
+ if (apache_sapi_module.php_ini_path_override) {
+ return "Only first PHPINIDir directive honored per configuration tree - subsequent ones ignored";
+ }
+ apache_sapi_module.php_ini_path_override = ap_server_root_relative(cmd->pool, arg);
+ return NULL;
+}
+/* }}} */
+
+/* {{{ int php_xbithack_handler(request_rec * r)
+ */
+static int php_xbithack_handler(request_rec * r)
+{
+ php_per_dir_config *conf;
+ TSRMLS_FETCH();
+
+ if (!(r->finfo.st_mode & S_IXUSR)) {
+ r->allowed |= (1 << METHODS) - 1;
+ return DECLINED;
+ }
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ if (conf) {
+ zend_hash_apply((HashTable *) conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ }
+ if(!AP(xbithack)) {
+ r->allowed |= (1 << METHODS) - 1;
+ zend_try {
+ zend_ini_deactivate(TSRMLS_C);
+ } zend_end_try();
+ return DECLINED;
+ }
+ return send_parsed_php(r);
+}
+/* }}} */
+
+/* {{{ apache_php_module_shutdown_wrapper
+ */
+static void apache_php_module_shutdown_wrapper(void)
+{
+ apache_php_initialized = 0;
+ apache_sapi_module.shutdown(&apache_sapi_module);
+
+#if MODULE_MAGIC_NUMBER >= 19970728
+ /* This function is only called on server exit if the apache API
+ * child_exit handler exists, so shutdown globally
+ */
+ sapi_shutdown();
+#endif
+
+#ifdef ZTS
+ tsrm_shutdown();
+#endif
+}
+/* }}} */
+
+#if MODULE_MAGIC_NUMBER >= 19970728
+/* {{{ php_child_exit_handler
+ */
+static void php_child_exit_handler(server_rec *s, pool *p)
+{
+/* apache_php_initialized = 0; */
+ apache_sapi_module.shutdown(&apache_sapi_module);
+
+#ifdef ZTS
+ tsrm_shutdown();
+#endif
+}
+/* }}} */
+#endif
+
+/* {{{ void php_init_handler(server_rec *s, pool *p)
+ */
+static void php_init_handler(server_rec *s, pool *p)
+{
+ register_cleanup(p, NULL, (void (*)(void *))apache_php_module_shutdown_wrapper, (void (*)(void *))php_module_shutdown_for_exec);
+ if (!apache_php_initialized) {
+ apache_php_initialized = 1;
+#ifdef ZTS
+ tsrm_startup(1, 1, 0, NULL);
+#endif
+ sapi_startup(&apache_sapi_module);
+ php_apache_startup(&apache_sapi_module);
+ }
+#if MODULE_MAGIC_NUMBER >= 19980527
+ {
+ TSRMLS_FETCH();
+ if (PG(expose_php)) {
+ ap_add_version_component("PHP/" PHP_VERSION);
+ }
+ }
+#endif
+}
+/* }}} */
+
+static int php_run_hook(php_handler *handler, request_rec *r)
+{
+ zval *ret = NULL;
+ php_per_dir_config *conf;
+
+ TSRMLS_FETCH();
+
+ if(!AP(apache_config_loaded)) {
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ if (conf)
+ zend_hash_apply((HashTable *)conf->ini_settings, (apply_func_t) php_apache_alter_ini_entries TSRMLS_CC);
+ AP(apache_config_loaded) = 1;
+ }
+ if (!handler->name) {
+ return DECLINED;
+ }
+ php_save_umask();
+ if (!AP(setup_env)) {
+ AP(setup_env) = 1;
+ add_common_vars(r);
+ add_cgi_vars(r);
+ }
+ SG(server_context) = r;
+ init_request_info(TSRMLS_C);
+ apache_php_module_hook(r, handler, &ret TSRMLS_CC);
+ php_restore_umask();
+ kill_timeout(r);
+ if (ret) {
+ convert_to_long(ret);
+ return Z_LVAL_P(ret);
+ }
+ return HTTP_INTERNAL_SERVER_ERROR;
+}
+
+
+static int php_uri_translation(request_rec *r)
+{
+ php_per_server_config *conf;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_URI_TRANS;
+ conf = (php_per_server_config *) get_module_config(r->server->module_config, &php5_module);
+ return sapi_stack_apply_with_argument_stop_if_equals(&conf->uri_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook, r, OK);
+}
+
+static int php_header_hook(request_rec *r)
+{
+ php_per_dir_config *conf;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_HEADER_PARSE;
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ return sapi_stack_apply_with_argument_stop_if_http_error(&conf->headers_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook, r);
+}
+
+static int php_auth_hook(request_rec *r)
+{
+ php_per_dir_config *conf;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_AUTHENTICATION;
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ return sapi_stack_apply_with_argument_stop_if_equals(&conf->auth_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook, r, OK);
+}
+
+static int php_access_hook(request_rec *r)
+{
+ php_per_dir_config *conf;
+ int status = DECLINED;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_ACCESS_CONTROL;
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ status = sapi_stack_apply_with_argument_stop_if_http_error(&conf->access_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook, r);
+ return status;
+
+}
+
+static int php_type_hook(request_rec *r)
+{
+ php_per_dir_config *conf;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_TYPE_CHECKING;
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ return sapi_stack_apply_with_argument_stop_if_equals(&conf->type_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook,
+ r, OK);
+}
+
+static int php_fixup_hook(request_rec *r)
+{
+ php_per_dir_config *conf;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_FIXUP;
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ return sapi_stack_apply_with_argument_stop_if_http_error(&conf->fixup_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook,
+ r);
+}
+
+static int php_logger_hook(request_rec *r)
+{
+ php_per_dir_config *conf;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_LOGGING;
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ return sapi_stack_apply_with_argument_stop_if_http_error(&conf->logger_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook,
+ r);
+}
+
+static int php_post_read_hook(request_rec *r)
+{
+ php_per_dir_config *conf;
+ php_per_server_config *svr;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_POST_READ;
+ svr = get_module_config(r->server->module_config, &php5_module);
+ if(ap_is_initial_req(r)) {
+ sapi_stack_apply_with_argument_all(&svr->requires, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r);
+ }
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ return sapi_stack_apply_with_argument_stop_if_http_error(&conf->post_read_handlers,
+ ZEND_STACK_APPLY_BOTTOMUP,
+ (int (*)(void *element, void *)) php_run_hook, r);
+}
+
+static int php_response_handler(request_rec *r)
+{
+ php_per_dir_config *conf;
+ TSRMLS_FETCH();
+ AP(current_hook) = AP_RESPONSE;
+ conf = (php_per_dir_config *) get_module_config(r->per_dir_config, &php5_module);
+ return sapi_stack_apply_with_argument_all(&conf->response_handlers, ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *)) php_run_hook, r);
+}
+
+/* {{{ handler_rec php_handlers[]
+ */
+handler_rec php_handlers[] =
+{
+ {"application/x-httpd-php", send_parsed_php},
+ {"application/x-httpd-php-source", send_parsed_php_source},
+ {"text/html", php_xbithack_handler},
+ {"php-script", php_response_handler},
+ {NULL}
+};
+/* }}} */
+
+/* {{{ command_rec php_commands[]
+ */
+command_rec php_commands[] =
+{
+ {"php_value", php_apache_value_handler, NULL, OR_OPTIONS, TAKE2, "PHP Value Modifier"},
+ {"phpUriHandler", php_set_uri_handler, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"},
+ {"phpUriHandlerMethod", php_set_uri_handler_code, NULL, RSRC_CONF, TAKE1, "PHP Value Modifier"},
+#if MODULE_MAGIC_NUMBER >= 19970103
+ {"phpHeaderHandler", php_set_header_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpHeaderHandlerMethod", php_set_header_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+#endif
+ {"phpAuthHandler", php_set_auth_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpAuthHandlerMethod", php_set_auth_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpAccessHandler", php_set_access_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpAccessHandlerMethod", php_set_access_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpTypeHandler", php_set_type_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpTypeHandlerMethod", php_set_type_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpFixupHandler", php_set_fixup_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpFixupHandlerMethod", php_set_fixup_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpLoggerHandler", php_set_logger_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpLoggerHandlerMethod", php_set_logger_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+#if MODULE_MAGIC_NUMBER >= 19970902
+ {"phpPostReadHandler", php_set_post_read_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpPostReadHandlerMethod", php_set_post_read_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpRequire", php_set_require, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpResponseHandler", php_set_response_handler, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+ {"phpResponseHandlerMethod", php_set_response_handler_code, NULL, OR_OPTIONS, TAKE1, "PHP Value Modifier"},
+#endif
+ {"php_flag", php_apache_flag_handler, NULL, OR_OPTIONS, TAKE2, "PHP Flag Modifier"},
+ {"php_admin_value", php_apache_admin_value_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Value Modifier (Admin)"},
+ {"php_admin_flag", php_apache_admin_flag_handler, NULL, ACCESS_CONF|RSRC_CONF, TAKE2, "PHP Flag Modifier (Admin)"},
+ {"PHPINIDir", php_apache_phpini_set, NULL, RSRC_CONF, TAKE1, "Directory containing the php.ini file"},
+ {NULL}
+};
+/* }}} */
+
+/* {{{ module MODULE_VAR_EXPORT php5_module
+ */
+module MODULE_VAR_EXPORT php5_module =
+{
+ STANDARD_MODULE_STUFF,
+ php_init_handler, /* initializer */
+ php_create_dir, /* per-directory config creator */
+ php_merge_dir, /* dir merger */
+ php_create_server, /* per-server config creator */
+ NULL, /* merge server config */
+ php_commands, /* command table */
+ php_handlers, /* handlers */
+ php_uri_translation, /* filename translation */
+ NULL, /* check_user_id */
+ php_auth_hook, /* check auth */
+ php_access_hook, /* check access */
+ php_type_hook, /* type_checker */
+ php_fixup_hook, /* fixups */
+ php_logger_hook /* logger */
+#if MODULE_MAGIC_NUMBER >= 19970103
+ , php_header_hook /* 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
+ , php_post_read_hook /* post read-request */
+#endif
+};
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/sapi/apache_hooks/mod_php5.exp b/sapi/apache_hooks/mod_php5.exp
new file mode 100644
index 0000000..9ad0f0a
--- /dev/null
+++ b/sapi/apache_hooks/mod_php5.exp
@@ -0,0 +1 @@
+php5_module
diff --git a/sapi/apache_hooks/mod_php5.h b/sapi/apache_hooks/mod_php5.h
new file mode 100644
index 0000000..86a5863
--- /dev/null
+++ b/sapi/apache_hooks/mod_php5.h
@@ -0,0 +1,88 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Rasmus Lerdorf <rasmus@php.net> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#ifndef MOD_PHP5_H
+#define MOD_PHP5_H
+
+#if !defined(WIN32) && !defined(WINNT)
+#ifndef MODULE_VAR_EXPORT
+#define MODULE_VAR_EXPORT
+#endif
+#endif
+
+typedef struct {
+ long engine;
+ long last_modified;
+ long xbithack;
+ long terminate_child;
+ long setup_env;
+ long current_hook;
+ zend_bool in_request;
+ zend_bool apache_config_loaded;
+ zend_bool headers_sent;
+} php_apache_info_struct;
+
+typedef struct _php_handler {
+ long type;
+ long stage;
+ char *name;
+} php_handler;
+
+#define AP_HANDLER_TYPE_FILE 0
+#define AP_HANDLER_TYPE_METHOD 1
+
+extern zend_module_entry apache_module_entry;
+
+#ifdef ZTS
+extern int php_apache_info_id;
+#define AP(v) TSRMG(php_apache_info_id, php_apache_info_struct *, v)
+#else
+extern php_apache_info_struct php_apache_info;
+#define AP(v) (php_apache_info.v)
+#endif
+
+/* defines for the various stages of the apache request */
+#define AP_WAITING_FOR_REQUEST 0
+#define AP_POST_READ 1
+#define AP_URI_TRANS 2
+#define AP_HEADER_PARSE 3
+#define AP_ACCESS_CONTROL 4
+#define AP_AUTHENTICATION 5
+#define AP_AUTHORIZATION 6
+#define AP_TYPE_CHECKING 7
+#define AP_FIXUP 8
+#define AP_RESPONSE 9
+#define AP_LOGGING 10
+#define AP_CLEANUP 11
+
+
+/* fix for gcc4 visibility patch */
+#ifndef PHP_WIN32
+# undef MODULE_VAR_EXPORT
+# define MODULE_VAR_EXPORT PHPAPI
+#endif
+
+#endif /* MOD_PHP5_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/sapi/apache_hooks/php.sym b/sapi/apache_hooks/php.sym
new file mode 100644
index 0000000..9ad0f0a
--- /dev/null
+++ b/sapi/apache_hooks/php.sym
@@ -0,0 +1 @@
+php5_module
diff --git a/sapi/apache_hooks/php5apache_hooks.dsp b/sapi/apache_hooks/php5apache_hooks.dsp
new file mode 100755
index 0000000..cc60f4b
--- /dev/null
+++ b/sapi/apache_hooks/php5apache_hooks.dsp
@@ -0,0 +1,151 @@
+# Microsoft Developer Studio Project File - Name="php5apache_hooks" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=php5apache_hooks - Win32 Release_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "php5apache_hooks.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "php5apache_hooks.mak" CFG="php5apache_hooks - Win32 Release_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "php5apache_hooks - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "php5apache_hooks - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "php5apache_hooks - Win32 Release_TS_inline" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "php5apache_hooks - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS"
+# PROP BASE Intermediate_Dir "Release_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\..\regex" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\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 "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 php5ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /machine:I386 /libpath:"..\..\..\php_build\apache\src\corer" /libpath:"..\..\Release_TS" /libpath:"..\..\TSRM\Release_TS" /libpath:"..\..\Zend\Release_TS"
+
+!ELSEIF "$(CFG)" == "php5apache_hooks - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\..\regex" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\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 "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 php5ts_debug.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /base:"0x60000000" /version:4.0 /dll /incremental:yes /debug /machine:I386 /out:"..\..\Debug_TS/php5apache_hooks.dll" /pdbtype:sept /libpath:"..\..\..\php_build\apache\src\cored" /libpath:"..\..\Debug_TS" /libpath:"..\..\TSRM\Debug_TS" /libpath:"..\..\Zend\Debug_TS"
+
+!ELSEIF "$(CFG)" == "php5apache_hooks - Win32 Release_TS_inline"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS_inline"
+# PROP BASE Intermediate_Dir "Release_TS_inline"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\..\Release_TS_inline"
+# PROP Intermediate_Dir "Release_TS_inline"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APACHEPHP5_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "...\..\include" /I "..\..\win32" /I "..\..\Zend" /I "..\..\regex" /I "..\.." /I "..\..\..\bindlib_w32" /I "..\..\..\php_build\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 "APACHEPHP5_EXPORTS" /D "WIN32" /D "_MBCS" /D "APACHE_READDIR_H" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 php5ts.lib ApacheCore.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /dll /machine:I386 /libpath:"\apache\src\corer" /libpath:"..\..\Release_TS_inline" /libpath:"..\..\TSRM\Release_TS_inline" /libpath:"..\..\Zend\Release_TS_inline"
+
+!ENDIF
+
+# Begin Target
+
+# Name "php5apache_hooks - Win32 Release_TS"
+# Name "php5apache_hooks - Win32 Debug_TS"
+# Name "php5apache_hooks - Win32 Release_TS_inline"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\mod_php5.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\php_apache.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\sapi_apache.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\mod_php5.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\php_apache_http.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/sapi/apache_hooks/php_apache.c b/sapi/apache_hooks/php_apache.c
new file mode 100644
index 0000000..dde6d88
--- /dev/null
+++ b/sapi/apache_hooks/php_apache.c
@@ -0,0 +1,1972 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+ | Stig Sæther Bakken <ssb@php.net> |
+ | David Sklar <sklar@student.net> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#include "php_apache_http.h"
+
+#if defined(PHP_WIN32) || defined(NETWARE)
+#include "zend.h"
+#include "ap_compat.h"
+#else
+#include <build-defs.h>
+#endif
+
+#ifdef ZTS
+int php_apache_info_id;
+#else
+php_apache_info_struct php_apache_info;
+#endif
+
+#define SECTION(name) PUTS("<H2 align=\"center\">" name "</H2>\n")
+
+#undef offsetof
+#define offsetof(s_type,field) ((size_t)&(((s_type*)0)->field))
+
+extern module *top_module;
+extern module **ap_loaded_modules;
+static int le_apachereq;
+static zend_class_entry *apacherequest_class_entry;
+
+static void apache_table_to_zval(table *, zval *return_value);
+
+PHP_FUNCTION(virtual);
+PHP_FUNCTION(apache_request_headers);
+PHP_FUNCTION(apache_response_headers);
+PHP_FUNCTION(apachelog);
+PHP_FUNCTION(apache_note);
+PHP_FUNCTION(apache_lookup_uri);
+PHP_FUNCTION(apache_child_terminate);
+PHP_FUNCTION(apache_setenv);
+PHP_FUNCTION(apache_get_version);
+PHP_FUNCTION(apache_get_modules);
+
+PHP_MINFO_FUNCTION(apache);
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_virtual, 0, 0, 1)
+ ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_setenv, 0, 0, 2)
+ ZEND_ARG_INFO(0, variable)
+ ZEND_ARG_INFO(0, value)
+ ZEND_ARG_INFO(0, walk_to_top)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_lookup_uri, 0, 0, 1)
+ ZEND_ARG_INFO(0, uri)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_apachehooks__void, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_apachehooks_note, 0, 0, 1)
+ ZEND_ARG_INFO(0, note_name)
+ ZEND_ARG_INFO(0, note_value)
+ZEND_END_ARG_INFO()
+
+const zend_function_entry apache_functions[] = {
+ PHP_FE(virtual, arginfo_apachehooks_virtual)
+ PHP_FE(apache_request_headers, arginfo_apachehooks__void)
+ PHP_FE(apache_note, arginfo_apachehooks_note)
+ PHP_FE(apache_lookup_uri, arginfo_apachehooks_lookup_uri)
+ PHP_FE(apache_child_terminate, arginfo_apachehooks__void)
+ PHP_FE(apache_setenv, arginfo_apachehooks_setenv)
+ PHP_FE(apache_response_headers, arginfo_apachehooks__void)
+ PHP_FE(apache_get_version, arginfo_apachehooks__void)
+ PHP_FE(apache_get_modules, arginfo_apachehooks__void)
+ PHP_FALIAS(getallheaders, apache_request_headers, arginfo_apachehooks__void)
+ {NULL, NULL, NULL}
+};
+
+/* {{{ php_apache ini entries
+ */
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY("xbithack", "0", PHP_INI_ALL, OnUpdateLong, xbithack, php_apache_info_struct, php_apache_info)
+ STD_PHP_INI_ENTRY("engine", "1", PHP_INI_ALL, OnUpdateLong, engine, php_apache_info_struct, php_apache_info)
+ STD_PHP_INI_ENTRY("last_modified", "0", PHP_INI_ALL, OnUpdateLong, last_modified, php_apache_info_struct, php_apache_info)
+ STD_PHP_INI_ENTRY("child_terminate", "0", PHP_INI_ALL, OnUpdateLong, terminate_child, php_apache_info_struct, php_apache_info)
+PHP_INI_END()
+/* }}} */
+
+static void php_apache_globals_ctor(php_apache_info_struct *apache_globals TSRMLS_DC)
+{
+ apache_globals->in_request = 0;
+}
+
+
+#define APREQ_GET_THIS(ZVAL) if (NULL == (ZVAL = getThis())) { \
+ php_error(E_WARNING, "%s(): underlying ApacheRequest object missing", \
+ get_active_function_name(TSRMLS_C)); \
+ RETURN_FALSE; \
+ }
+#define APREQ_GET_REQUEST(ZVAL, R) APREQ_GET_THIS(ZVAL); \
+ R = get_apache_request(ZVAL TSRMLS_CC)
+
+static void php_apache_request_free(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+{
+ zval *z = (zval *)rsrc->ptr;
+/* fprintf(stderr, "%s() %p\n", __FUNCTION__, z); */
+ zval_ptr_dtor(&z);
+}
+
+static request_rec *get_apache_request(zval *z TSRMLS_DC)
+{
+ request_rec *r;
+ zval **addr;
+
+ if (NULL == z) {
+ php_error(E_WARNING, "get_apache_request() invalid wrapper passed");
+ return NULL;
+ }
+
+ if (Z_TYPE_P(z) != IS_OBJECT) {
+ php_error(E_WARNING, "%s(): wrapper is not an object", get_active_function_name(TSRMLS_C));
+ return NULL;
+ }
+
+ if (zend_hash_index_find(Z_OBJPROP_P(z), 0, (void **)&addr) == FAILURE) {
+ php_error(E_WARNING, "%s(): underlying object missing", get_active_function_name(TSRMLS_C));
+ return NULL;
+ }
+
+ r = (request_rec *)Z_LVAL_PP(addr);
+ if (!r) {
+ php_error(E_WARNING, "%s(): request_rec invalid", get_active_function_name(TSRMLS_C));
+ return NULL;
+ }
+
+ return r;
+}
+
+/* {{{ php_apache_request_new(request_rec *r)
+ * create a new zval-instance for ApacheRequest that wraps request_rec
+ */
+zval *php_apache_request_new(request_rec *r)
+{
+ zval *req;
+ zval *addr;
+
+ TSRMLS_FETCH();
+
+ MAKE_STD_ZVAL(addr);
+ Z_TYPE_P(addr) = IS_LONG;
+ Z_LVAL_P(addr) = (int) r;
+
+ MAKE_STD_ZVAL(req);
+ object_init_ex(req, apacherequest_class_entry);
+ zend_hash_index_update(Z_OBJPROP_P(req), 0, &addr, sizeof(zval *), NULL);
+
+ return req;
+}
+/* }}} */
+
+/* {{{ apache_request_read_string_slot()
+ */
+static void apache_request_read_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
+{
+ zval *id;
+ request_rec *r;
+ char *s;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ s = *(char **)((char*)r + offset);
+
+ if (s) {
+ RETURN_STRING(s, 1);
+ }
+
+ RETURN_EMPTY_STRING();
+}
+/* }}} */
+
+
+/* {{{ apache_request_string_slot()
+ */
+static void apache_request_string_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
+{
+ zval *id;
+ request_rec *r;
+ char *old_value, *new_value = NULL;
+ int new_value_len;
+ char **target;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &new_value, &new_value_len) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ target = (char **)((char*)r + offset);
+ old_value = *target;
+
+ if (new_value) {
+ *target = ap_pstrdup(r->pool, new_value);
+ }
+
+ if (old_value) {
+ RETURN_STRING(old_value, 1);
+ }
+
+ RETURN_EMPTY_STRING();
+}
+/* }}} */
+
+/* {{{ apache_request_read_int_slot()
+ */
+static void apache_request_read_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
+{
+ zval *id;
+ request_rec *r;
+ long l;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ l = *(long *)((char*)r + offset);
+
+ RETURN_LONG(l);
+}
+/* }}} */
+
+/* {{{ apache_request_int_slot()
+ */
+static void apache_request_int_slot(int offset, INTERNAL_FUNCTION_PARAMETERS)
+{
+ zval *id;
+ request_rec *r;
+ long old_value, new_value;
+ long *target;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &new_value) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ target = (long *)((char*)r + offset);
+ old_value = *target;
+
+ switch (ZEND_NUM_ARGS()) {
+ case 0:
+ break;
+ case 1:
+ *target = new_value;
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
+ RETURN_LONG(old_value);
+}
+/* }}} */
+
+
+/* {{{ access string slots of request rec
+ */
+
+/* {{{ proto string ApacheRequest::filename([string new_filename])
+ */
+PHP_FUNCTION(apache_request_filename)
+{
+ apache_request_string_slot(offsetof(request_rec, filename), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::uri([string new_uri])
+ */
+PHP_FUNCTION(apache_request_uri)
+{
+ apache_request_string_slot(offsetof(request_rec, uri), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::unparsed_uri([string new_unparsed_uri])
+ */
+PHP_FUNCTION(apache_request_unparsed_uri)
+{
+ apache_request_string_slot(offsetof(request_rec, unparsed_uri), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::path_info([string new_path_info])
+ */
+PHP_FUNCTION(apache_request_path_info)
+{
+ apache_request_string_slot(offsetof(request_rec, path_info), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::args([string new_args])
+ */
+PHP_FUNCTION(apache_request_args)
+{
+ apache_request_string_slot(offsetof(request_rec, args), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::boundary()
+ */
+PHP_FUNCTION(apache_request_boundary)
+{
+ apache_request_read_string_slot(offsetof(request_rec, boundary), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+
+/* {{{ proto string ApacheRequest::content_type([string new_type])
+ */
+PHP_FUNCTION(apache_request_content_type)
+{
+ apache_request_string_slot(offsetof(request_rec, content_type), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::content_encoding([string new_encoding])
+ */
+PHP_FUNCTION(apache_request_content_encoding)
+{
+ apache_request_string_slot(offsetof(request_rec, content_encoding), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::handler([string new_handler])
+ */
+PHP_FUNCTION(apache_request_handler)
+{
+ apache_request_string_slot(offsetof(request_rec, handler), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::the_request()
+ */
+PHP_FUNCTION(apache_request_the_request)
+{
+ apache_request_read_string_slot(offsetof(request_rec, the_request), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::protocol()
+ */
+PHP_FUNCTION(apache_request_protocol)
+{
+ apache_request_read_string_slot(offsetof(request_rec, protocol), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::hostname()
+ */
+PHP_FUNCTION(apache_request_hostname)
+{
+ apache_request_read_string_slot(offsetof(request_rec, hostname), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::status_line([string new_status_line])
+ */
+PHP_FUNCTION(apache_request_status_line)
+{
+ apache_request_string_slot(offsetof(request_rec, status_line), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto string ApacheRequest::method()
+ */
+PHP_FUNCTION(apache_request_method)
+{
+ apache_request_read_string_slot(offsetof(request_rec, method), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* }}} access string slots of request rec */
+
+/* {{{ access int slots of request_rec
+ */
+
+/* {{{ proto int ApacheRequest::proto_num()
+ */
+PHP_FUNCTION(apache_request_proto_num)
+{
+ apache_request_read_int_slot(offsetof(request_rec, proto_num), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::assbackwards()
+ */
+PHP_FUNCTION(apache_request_assbackwards)
+{
+ apache_request_read_int_slot(offsetof(request_rec, assbackwards), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+
+/* {{{ proto int ApacheRequest::proxyreq([int new_proxyreq])
+ */
+PHP_FUNCTION(apache_request_proxyreq)
+{
+ apache_request_int_slot(offsetof(request_rec, proxyreq), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::chunked()
+ */
+PHP_FUNCTION(apache_request_chunked)
+{
+ apache_request_read_int_slot(offsetof(request_rec, chunked), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+
+/* {{{ proto int ApacheRequest::header_only()
+ */
+PHP_FUNCTION(apache_request_header_only)
+{
+ apache_request_read_int_slot(offsetof(request_rec, header_only), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::request_time()
+ */
+PHP_FUNCTION(apache_request_request_time)
+{
+ apache_request_read_int_slot(offsetof(request_rec, request_time), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::status([int new_status])
+ */
+PHP_FUNCTION(apache_request_status)
+{
+ apache_request_int_slot(offsetof(request_rec, status), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::method_number([int method_number])
+ */
+PHP_FUNCTION(apache_request_method_number)
+{
+ apache_request_read_int_slot(offsetof(request_rec, method_number), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::allowed([int allowed])
+ */
+PHP_FUNCTION(apache_request_allowed)
+{
+ apache_request_int_slot(offsetof(request_rec, allowed), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::bytes_sent()
+ */
+PHP_FUNCTION(apache_request_bytes_sent)
+{
+ apache_request_read_int_slot(offsetof(request_rec, bytes_sent), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::mtime()
+ */
+PHP_FUNCTION(apache_request_mtime)
+{
+ apache_request_read_int_slot(offsetof(request_rec, mtime), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::content_length([int new_content_length])
+ */
+PHP_FUNCTION(apache_request_content_length)
+{
+ zval *id;
+ long zlen;
+ request_rec *r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &zlen) == FAILURE) {
+ return;
+ }
+
+ if (ZEND_NUM_ARGS() == 0) {
+ apache_request_read_int_slot(offsetof(request_rec, clength), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ } else {
+ APREQ_GET_REQUEST(id, r);
+
+ (void)ap_set_content_length(r, zlen);
+ RETURN_TRUE;
+ }
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::remaining()
+ */
+PHP_FUNCTION(apache_request_remaining)
+{
+ apache_request_read_int_slot(offsetof(request_rec, remaining), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::no_cache()
+ */
+PHP_FUNCTION(apache_request_no_cache)
+{
+ apache_request_int_slot(offsetof(request_rec, no_cache), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::no_local_copy()
+ */
+PHP_FUNCTION(apache_request_no_local_copy)
+{
+ apache_request_int_slot(offsetof(request_rec, no_local_copy), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+/* {{{ proto int ApacheRequest::read_body()
+ */
+PHP_FUNCTION(apache_request_read_body)
+{
+ apache_request_int_slot(offsetof(request_rec, read_body), INTERNAL_FUNCTION_PARAM_PASSTHRU);
+}
+/* }}} */
+
+
+/* }}} access int slots of request_rec */
+
+
+/* {{{ proto array apache_request_headers_in()
+ * fetch all incoming request headers
+ */
+PHP_FUNCTION(apache_request_headers_in)
+{
+ zval *id;
+ request_rec *r;
+
+ APREQ_GET_REQUEST(id, r);
+
+ apache_table_to_zval(r->headers_in, return_value);
+}
+/* }}} */
+
+
+/* {{{ add_header_to_table
+*/
+static void add_header_to_table(table *t, INTERNAL_FUNCTION_PARAMETERS)
+{
+ zval *first = NULL;
+ zval *second = NULL;
+ zval **entry, **value;
+ char *string_key;
+ uint string_key_len;
+ ulong num_key;
+
+ zend_bool replace = 0;
+ HashPosition pos;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zb", &first, &second, &replace) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if (Z_TYPE_P(first) == IS_ARRAY) {
+ switch(ZEND_NUM_ARGS()) {
+ case 1:
+ case 3:
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(first), &pos);
+ while (zend_hash_get_current_data_ex(Z_ARRVAL_P(first), (void **)&entry, &pos) == SUCCESS) {
+ switch(zend_hash_get_current_key_ex(Z_ARRVAL_P(first), &string_key, &string_key_len, &num_key, 0, &pos)) {
+ case HASH_KEY_IS_STRING:
+ if (zend_hash_find(Z_ARRVAL_P(first), string_key, string_key_len, (void **)&value) == FAILURE) {
+ zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
+ continue;
+ }
+ if (!value) {
+ zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
+ continue;
+ }
+
+ convert_to_string_ex(value);
+ if (replace) {
+ ap_table_set(t, string_key, Z_STRVAL_PP(value));
+ } else {
+ ap_table_merge(t, string_key, Z_STRVAL_PP(value));
+ }
+ break;
+ case HASH_KEY_IS_LONG:
+ default:
+ php_error(E_WARNING, "%s(): Can only add STRING keys to headers!", get_active_function_name(TSRMLS_C));
+ break;
+ }
+
+ zend_hash_move_forward_ex(Z_ARRVAL_P(first), &pos);
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+ } else if (Z_TYPE_P(first) == IS_STRING) {
+ switch(ZEND_NUM_ARGS()) {
+ case 2:
+ case 3:
+ convert_to_string_ex(&second);
+ if (replace) {
+ ap_table_set(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
+ } else {
+ ap_table_merge(t, Z_STRVAL_P(first), Z_STRVAL_P(second));
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+ } else {
+ RETURN_FALSE;
+ }
+}
+
+/* }}} */
+
+
+/* {{{ proto array apache_request_headers_out([{string name|array list} [, string value [, bool replace = false]]])
+ * fetch all outgoing request headers
+ */
+PHP_FUNCTION(apache_request_headers_out)
+{
+ zval *id;
+ request_rec *r;
+
+ APREQ_GET_REQUEST(id, r);
+
+ if (ZEND_NUM_ARGS() > 0) {
+ add_header_to_table(r->headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ }
+
+ apache_table_to_zval(r->headers_out, return_value);
+}
+/* }}} */
+
+
+/* {{{ proto array apache_request_err_headers_out([{string name|array list} [, string value [, bool replace = false]]])
+ * fetch all headers that go out in case of an error or a subrequest
+ */
+PHP_FUNCTION(apache_request_err_headers_out)
+{
+ zval *id;
+ request_rec *r;
+
+ APREQ_GET_REQUEST(id, r);
+
+ if (ZEND_NUM_ARGS() > 0) {
+ add_header_to_table(r->err_headers_out, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+ }
+
+ apache_table_to_zval(r->err_headers_out, return_value);
+}
+/* }}} */
+
+
+/* {{{ proxy functions for the ap_* functions family
+ */
+
+/* {{{ proto int apache_request_server_port()
+ */
+PHP_FUNCTION(apache_request_server_port)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ RETURN_LONG(ap_get_server_port(r));
+}
+/* }}} */
+
+/* {{{ proto int apache_request_remote_host([int type])
+ */
+PHP_FUNCTION(apache_request_remote_host)
+{
+ zval *id;
+ long type = 0;
+ request_rec *r;
+ char *res;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &type) == FAILURE) {
+ return;
+ }
+
+ if (!type) {
+ type = REMOTE_NAME;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ res = (char *)ap_get_remote_host(r->connection, r->per_dir_config, (int)type);
+
+ if (res) {
+ RETURN_STRING(res, 1);
+ }
+
+ RETURN_EMPTY_STRING();
+}
+/* }}} */
+
+/* {{{ proto long apache_request_update_mtime([int dependency_mtime])
+ */
+PHP_FUNCTION(apache_request_update_mtime)
+{
+ zval *id;
+ request_rec *r;
+ long mtime = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &mtime) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ RETURN_LONG(ap_update_mtime(r, (int) mtime));
+}
+/* }}} */
+
+
+/* {{{ proto void apache_request_set_etag()
+ */
+PHP_FUNCTION(apache_request_set_etag)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_set_etag(r);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto void apache_request_set_last_modified()
+ */
+PHP_FUNCTION(apache_request_set_last_modified)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_set_last_modified(r);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto long apache_request_meets_conditions()
+ */
+PHP_FUNCTION(apache_request_meets_conditions)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ RETURN_LONG(ap_meets_conditions(r));
+}
+/* }}} */
+
+/* {{{ proto long apache_request_discard_request_body()
+ */
+PHP_FUNCTION(apache_request_discard_request_body)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ RETURN_LONG(ap_discard_request_body(r));
+}
+/* }}} */
+
+/* {{{ proto long apache_request_satisfies()
+ */
+PHP_FUNCTION(apache_request_satisfies)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ RETURN_LONG(ap_satisfies(r));
+}
+/* }}} */
+
+
+/* {{{ proto bool apache_request_is_initial_req()
+ */
+PHP_FUNCTION(apache_request_is_initial_req)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ RETURN_BOOL(ap_is_initial_req(r));
+}
+/* }}} */
+
+/* {{{ proto bool apache_request_some_auth_required()
+ */
+PHP_FUNCTION(apache_request_some_auth_required)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ RETURN_BOOL(ap_some_auth_required(r));
+}
+/* }}} */
+
+/* {{{ proto string apache_request_auth_type()
+ */
+PHP_FUNCTION(apache_request_auth_type)
+{
+ zval *id;
+ request_rec *r;
+ char *t;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ t = (char *)ap_auth_type(r);
+ if (!t) {
+ RETURN_NULL();
+ }
+
+ RETURN_STRING(t, 1);
+}
+/* }}} */
+
+/* {{{ proto string apache_request_auth_name()
+ */
+PHP_FUNCTION(apache_request_auth_name)
+{
+ zval *id;
+ request_rec *r;
+ char *t;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ t = (char *)ap_auth_name(r);
+ if (!t) {
+ RETURN_NULL();
+ }
+
+ RETURN_STRING(t, 1);
+}
+/* }}} */
+
+/* {{{ proto apache_request_basic_auth_pw()
+ */
+PHP_FUNCTION(apache_request_basic_auth_pw)
+{
+ zval *id, *zpw;
+ request_rec *r;
+ const char *pw;
+ long status;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zpw) == FAILURE) {
+ return;
+ }
+
+ if (!PZVAL_IS_REF(zpw)) {
+ zend_error(E_WARNING, "Parameter wasn't passed by reference");
+ RETURN_NULL();
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ pw = NULL;
+ status = ap_get_basic_auth_pw(r, &pw);
+ if (status == OK && pw) {
+ ZVAL_STRING(zpw, (char *)pw, 1);
+ } else {
+ ZVAL_NULL(zpw);
+ }
+ RETURN_LONG(status);
+}
+/* }}} */
+
+
+/* http_protocol.h */
+
+PHP_FUNCTION(apache_request_send_http_header)
+{
+ zval *id;
+ request_rec *r;
+ char *type = NULL;
+ int typelen;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &type, &typelen) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+ if(type) {
+ r->content_type = pstrdup(r->pool, type);
+ }
+ ap_send_http_header(r);
+ SG(headers_sent) = 1;
+ AP(headers_sent) = 1;
+ RETURN_TRUE;
+}
+
+PHP_FUNCTION(apache_request_basic_http_header)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_basic_http_header((request_rec *)SG(server_context));
+ SG(headers_sent) = 1;
+ AP(headers_sent) = 1;
+ RETURN_TRUE;
+}
+
+PHP_FUNCTION(apache_request_send_http_trace)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_send_http_trace((request_rec *)SG(server_context));
+ SG(headers_sent) = 1;
+ AP(headers_sent) = 1;
+ RETURN_TRUE;
+}
+
+PHP_FUNCTION(apache_request_send_http_options)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_send_http_options((request_rec *)SG(server_context));
+ SG(headers_sent) = 1;
+ AP(headers_sent) = 1;
+ RETURN_TRUE;
+}
+
+PHP_FUNCTION(apache_request_send_error_response)
+{
+ zval *id;
+ request_rec *r;
+ long rec = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &rec) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+ ap_send_error_response(r, (int) rec);
+ RETURN_TRUE;
+}
+
+PHP_FUNCTION(apache_request_set_content_length)
+{
+ long length;
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &length) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_set_content_length(r, length);
+ RETURN_TRUE;
+}
+
+PHP_FUNCTION(apache_request_set_keepalive)
+{
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+ ap_set_keepalive(r);
+ RETURN_TRUE;
+}
+
+/* This stuff should use streams or however this is implemented now
+
+PHP_FUNCTION(apache_request_send_fd)
+{
+}
+
+PHP_FUNCTION(apache_request_send_fd_length)
+{
+}
+*/
+
+/* These are for overriding default output behaviour */
+PHP_FUNCTION(apache_request_rputs)
+{
+ char *buffer;
+ int buffer_len;
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buffer, &buffer_len) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+ ap_rwrite(buffer, buffer_len, (request_rec*)SG(server_context));
+}
+
+/* This stuff would be useful for custom POST handlers,
+ which should be supported. Probably by not using
+ sapi_activate at all inside a phpResponseHandler
+ and instead using a builtin composed of the below
+ calls as a apache_read_request_body() and allow
+ people to custom craft their own.
+
+PHP_FUNCTION(apache_request_setup_client_block)
+{
+}
+
+PHP_FUNCTION(apache_request_should_client_block)
+{
+}
+
+PHP_FUNCTION(apache_request_get_client_block)
+{
+}
+
+PHP_FUNCTION(apache_request_discard_request_body)
+{
+}
+*/
+
+/* http_log.h */
+
+/* {{{ proto boolean apache_request_log_error(string message, [long facility])
+ */
+PHP_FUNCTION(apache_request_log_error)
+{
+ zval *id;
+ char *z_errstr;
+ int z_errstr_len;
+ long facility = APLOG_ERR;
+ request_rec *r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &z_errstr, &z_errstr_len, &facility) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+ ap_log_error(APLOG_MARK, (int) facility, r->server, "%s", z_errstr);
+ RETURN_TRUE;
+}
+/* }}} */
+/* http_main.h */
+
+/* {{{ proto object apache_request_sub_req_lookup_uri(string uri)
+ Returns sub-request for the specified uri. You would
+ need to run it yourself with run()
+*/
+PHP_FUNCTION(apache_request_sub_req_lookup_uri)
+{
+ zval *id;
+ char *file;
+ int file_len;
+ request_rec *r, *sub_r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+ sub_r = ap_sub_req_lookup_uri(file, r);
+
+ if (!sub_r) {
+ RETURN_FALSE;
+ }
+ return_value = php_apache_request_new(sub_r);
+}
+/* }}} */
+
+/* {{{ proto object apache_request_sub_req_lookup_file(string file)
+ Returns sub-request for the specified file. You would
+ need to run it yourself with run().
+*/
+PHP_FUNCTION(apache_request_sub_req_lookup_file)
+{
+ zval *id;
+ char *file;
+ int file_len;
+ request_rec *r, *sub_r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ sub_r = ap_sub_req_lookup_file(file, r);
+
+ if (!sub_r) {
+ RETURN_FALSE;
+ }
+ return_value = php_apache_request_new(sub_r);
+}
+/* }}} */
+
+/* {{{ proto object apache_request_sub_req_method_uri(string method, string uri)
+ Returns sub-request for the specified file. You would
+ need to run it yourself with run().
+*/
+PHP_FUNCTION(apache_request_sub_req_method_uri)
+{
+ zval *id;
+ char *file, *method;
+ int file_len, method_len;
+ request_rec *r, *sub_r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &method, &method_len, &file, &file_len) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ sub_r = ap_sub_req_method_uri(method, file, r);
+
+ if (!sub_r) {
+ RETURN_FALSE;
+ }
+ return_value = php_apache_request_new(sub_r);
+}
+/* }}} */
+
+/* {{{ proto long apache_request_run()
+ This is a wrapper for ap_sub_run_req and ap_destory_sub_req. It takes
+ sub_request, runs it, destroys it, and returns it's status.
+*/
+PHP_FUNCTION(apache_request_run)
+{
+ zval *id;
+ request_rec *r;
+ int status;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+ if (!r || ap_is_initial_req(r)) {
+ RETURN_FALSE;
+ }
+ status = ap_run_sub_req(r);
+ ap_destroy_sub_req(r);
+ RETURN_LONG(status);
+}
+/* }}} */
+
+PHP_FUNCTION(apache_request_internal_redirect)
+{
+ zval *id;
+ char *new_uri;
+ int new_uri_len;
+ request_rec *r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &new_uri, &new_uri_len) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_internal_redirect(new_uri, r);
+}
+
+PHP_FUNCTION(apache_request_send_header_field)
+{
+ char *fieldname, *fieldval;
+ int fieldname_len, fieldval_len;
+ zval *id;
+ request_rec *r;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &fieldname, &fieldname_len, &fieldval, &fieldval_len) == FAILURE) {
+ return;
+ }
+
+ APREQ_GET_REQUEST(id, r);
+
+ ap_send_header_field(r, fieldname, fieldval);
+ SG(headers_sent) = 1;
+ AP(headers_sent) = 1;
+}
+
+
+
+/* }}} */
+
+/* {{{ php_apache_request_class_functions
+ */
+const static zend_function_entry php_apache_request_class_functions[] = {
+ /* string slots */
+ PHP_FALIAS(args, apache_request_args, NULL)
+ PHP_FALIAS(boundary, apache_request_boundary, NULL)
+ PHP_FALIAS(content_encoding, apache_request_content_encoding, NULL)
+ PHP_FALIAS(content_type, apache_request_content_type, NULL)
+ PHP_FALIAS(filename, apache_request_filename, NULL)
+ PHP_FALIAS(handler, apache_request_handler, NULL)
+ PHP_FALIAS(hostname, apache_request_hostname, NULL)
+ PHP_FALIAS(method, apache_request_method, NULL)
+ PHP_FALIAS(path_info, apache_request_path_info, NULL)
+ PHP_FALIAS(protocol, apache_request_protocol, NULL)
+ PHP_FALIAS(status_line, apache_request_status_line, NULL)
+ PHP_FALIAS(the_request, apache_request_the_request, NULL)
+ PHP_FALIAS(unparsed_uri, apache_request_unparsed_uri, NULL)
+ PHP_FALIAS(uri, apache_request_uri, NULL)
+
+ /* int slots */
+ PHP_FALIAS(allowed, apache_request_allowed, NULL)
+ PHP_FALIAS(bytes_sent, apache_request_bytes_sent, NULL)
+ PHP_FALIAS(chunked, apache_request_chunked, NULL)
+ PHP_FALIAS(content_length, apache_request_content_length, NULL)
+ PHP_FALIAS(header_only, apache_request_header_only, NULL)
+ PHP_FALIAS(method_number, apache_request_method_number, NULL)
+ PHP_FALIAS(mtime, apache_request_mtime, NULL)
+ PHP_FALIAS(no_cache, apache_request_no_cache, NULL)
+ PHP_FALIAS(no_local_copy, apache_request_no_local_copy, NULL)
+ PHP_FALIAS(proto_num, apache_request_proto_num, NULL)
+ PHP_FALIAS(proxyreq, apache_request_proxyreq, NULL)
+ PHP_FALIAS(read_body, apache_request_read_body, NULL)
+ PHP_FALIAS(remaining, apache_request_remaining, NULL)
+ PHP_FALIAS(request_time, apache_request_request_time, NULL)
+ PHP_FALIAS(status, apache_request_status, NULL)
+
+ /* tables & arrays */
+ PHP_FALIAS(headers_in, apache_request_headers_in, NULL)
+ PHP_FALIAS(headers_out, apache_request_headers_out, NULL)
+ PHP_FALIAS(err_headers_out, apache_request_err_headers_out, NULL)
+
+
+ /* proxy functions for the ap_* functions family */
+#undef auth_name
+#undef auth_type
+#undef discard_request_body
+#undef is_initial_req
+#undef meets_conditions
+#undef satisfies
+#undef set_etag
+#undef set_last_modified
+#undef some_auth_required
+#undef update_mtime
+#undef send_http_header
+#undef send_header_field
+#undef basic_http_header
+#undef send_http_trace
+#undef send_http_options
+#undef send_error_response
+#undef set_content_length
+#undef set_keepalive
+#undef rputs
+#undef log_error
+#undef lookup_uri
+#undef lookup_file
+#undef method_uri
+#undef run
+#undef internal_redirect
+ PHP_FALIAS(auth_name, apache_request_auth_name, NULL)
+ PHP_FALIAS(auth_type, apache_request_auth_type, NULL)
+ PHP_FALIAS(basic_auth_pw, apache_request_basic_auth_pw, NULL)
+ PHP_FALIAS(discard_request_body, apache_request_discard_request_body, NULL)
+ PHP_FALIAS(is_initial_req, apache_request_is_initial_req, NULL)
+ PHP_FALIAS(meets_conditions, apache_request_meets_conditions, NULL)
+ PHP_FALIAS(remote_host, apache_request_remote_host, NULL)
+ PHP_FALIAS(satisfies, apache_request_satisfies, NULL)
+ PHP_FALIAS(server_port, apache_request_server_port, NULL)
+ PHP_FALIAS(set_etag, apache_request_set_etag, NULL)
+ PHP_FALIAS(set_last_modified, apache_request_set_last_modified, NULL)
+ PHP_FALIAS(some_auth_required, apache_request_some_auth_required, NULL)
+ PHP_FALIAS(update_mtime, apache_request_update_mtime, NULL)
+ PHP_FALIAS(send_http_header, apache_request_send_http_header, NULL)
+ PHP_FALIAS(basic_http_header, apache_request_basic_http_header, NULL)
+ PHP_FALIAS(send_header_field, apache_request_send_header_field, NULL)
+ PHP_FALIAS(send_http_trace, apache_request_send_http_trace, NULL)
+ PHP_FALIAS(send_http_options, apache_request_send_http_trace, NULL)
+ PHP_FALIAS(send_error_response, apache_request_send_error_response, NULL)
+ PHP_FALIAS(set_content_length, apache_request_set_content_length, NULL)
+ PHP_FALIAS(set_keepalive, apache_request_set_keepalive, NULL)
+ PHP_FALIAS(rputs, apache_request_rputs, NULL)
+ PHP_FALIAS(log_error, apache_request_log_error, NULL)
+ PHP_FALIAS(lookup_uri, apache_request_sub_req_lookup_uri, NULL)
+ PHP_FALIAS(lookup_file, apache_request_sub_req_lookup_file, NULL)
+ PHP_FALIAS(method_uri, apache_request_sub_req_method_uri, NULL)
+ PHP_FALIAS(run, apache_request_run, NULL)
+ PHP_FALIAS(internal_redirect, apache_request_internal_redirect, NULL)
+ PHP_FE_END
+};
+/* }}} */
+
+
+static PHP_MINIT_FUNCTION(apache)
+{
+ zend_class_entry ce;
+
+#ifdef ZTS
+ ts_allocate_id(&php_apache_info_id, sizeof(php_apache_info_struct), (ts_allocate_ctor) php_apache_globals_ctor, NULL);
+#else
+ php_apache_globals_ctor(&php_apache_info TSRMLS_CC);
+#endif
+ REGISTER_INI_ENTRIES();
+
+
+ le_apachereq = zend_register_list_destructors_ex(php_apache_request_free, NULL, "ApacheRequest", module_number);
+ INIT_OVERLOADED_CLASS_ENTRY(ce, "ApacheRequest", php_apache_request_class_functions, NULL, NULL, NULL);
+ apacherequest_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
+
+ REGISTER_LONG_CONSTANT("OK", OK, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DECLINED", DECLINED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("FORBIDDEN", FORBIDDEN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("AUTH_REQUIRED", AUTH_REQUIRED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("DONE", DONE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("SERVER_ERROR", SERVER_ERROR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("REDIRECT", REDIRECT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("BAD_REQUEST", BAD_REQUEST, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("NOT_FOUND", NOT_FOUND, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_CONTINUE", HTTP_CONTINUE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_SWITCHING_PROTOCOLS", HTTP_SWITCHING_PROTOCOLS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_PROCESSING", HTTP_PROCESSING, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_OK", HTTP_OK, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_CREATED", HTTP_CREATED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_ACCEPTED", HTTP_ACCEPTED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_NON_AUTHORITATIVE", HTTP_NON_AUTHORITATIVE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_NO_CONTENT", HTTP_NO_CONTENT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_RESET_CONTENT", HTTP_RESET_CONTENT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_PARTIAL_CONTENT", HTTP_PARTIAL_CONTENT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_MULTI_STATUS", HTTP_MULTI_STATUS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_MULTIPLE_CHOICES", HTTP_MULTIPLE_CHOICES, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_MOVED_PERMANENTLY", HTTP_MOVED_PERMANENTLY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_MOVED_TEMPORARILY", HTTP_MOVED_TEMPORARILY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_SEE_OTHER", HTTP_SEE_OTHER, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_NOT_MODIFIED", HTTP_NOT_MODIFIED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_USE_PROXY", HTTP_USE_PROXY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_TEMPORARY_REDIRECT", HTTP_TEMPORARY_REDIRECT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_BAD_REQUEST", HTTP_BAD_REQUEST, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_UNAUTHORIZED", HTTP_UNAUTHORIZED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_PAYMENT_REQUIRED", HTTP_PAYMENT_REQUIRED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_FORBIDDEN", HTTP_FORBIDDEN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_NOT_FOUND", HTTP_NOT_FOUND, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_METHOD_NOT_ALLOWED", HTTP_METHOD_NOT_ALLOWED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_NOT_ACCEPTABLE", HTTP_NOT_ACCEPTABLE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_PROXY_AUTHENTICATION_REQUIRED", HTTP_PROXY_AUTHENTICATION_REQUIRED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_REQUEST_TIME_OUT", HTTP_REQUEST_TIME_OUT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_CONFLICT", HTTP_CONFLICT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_GONE", HTTP_GONE, CONST_CS | CONST_PERSISTENT);REGISTER_LONG_CONSTANT("HTTP_LENGTH_REQUIRED", HTTP_LENGTH_REQUIRED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_PRECONDITION_FAILED", HTTP_PRECONDITION_FAILED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_REQUEST_ENTITY_TOO_LARGE", HTTP_REQUEST_ENTITY_TOO_LARGE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_REQUEST_URI_TOO_LARGE", HTTP_REQUEST_URI_TOO_LARGE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_UNSUPPORTED_MEDIA_TYPE", HTTP_UNSUPPORTED_MEDIA_TYPE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_RANGE_NOT_SATISFIABLE", HTTP_RANGE_NOT_SATISFIABLE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_EXPECTATION_FAILED", HTTP_EXPECTATION_FAILED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_UNPROCESSABLE_ENTITY", HTTP_UNPROCESSABLE_ENTITY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_LOCKED", HTTP_LOCKED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_FAILED_DEPENDENCY", HTTP_FAILED_DEPENDENCY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_INTERNAL_SERVER_ERROR", HTTP_INTERNAL_SERVER_ERROR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_NOT_IMPLEMENTED", HTTP_NOT_IMPLEMENTED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_BAD_GATEWAY", HTTP_BAD_GATEWAY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_SERVICE_UNAVAILABLE", HTTP_SERVICE_UNAVAILABLE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_GATEWAY_TIME_OUT", HTTP_GATEWAY_TIME_OUT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_VERSION_NOT_SUPPORTED", HTTP_VERSION_NOT_SUPPORTED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_VARIANT_ALSO_VARIES", HTTP_VARIANT_ALSO_VARIES, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_INSUFFICIENT_STORAGE", HTTP_INSUFFICIENT_STORAGE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("HTTP_NOT_EXTENDED", HTTP_NOT_EXTENDED, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_EMERG", APLOG_EMERG, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_ALERT", APLOG_ALERT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_CRIT", APLOG_CRIT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_ERR", APLOG_ERR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_WARNING", APLOG_WARNING, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_NOTICE", APLOG_NOTICE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_INFO", APLOG_INFO, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("APLOG_DEBUG", APLOG_DEBUG, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_GET", M_GET, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_PUT", M_PUT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_POST", M_POST, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_DELETE", M_DELETE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_CONNECT", M_CONNECT, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_OPTIONS", M_OPTIONS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_TRACE", M_TRACE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_PATCH", M_PATCH, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_PROPFIND", M_PROPFIND, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_PROPPATCH", M_PROPPATCH, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_MKCOL", M_MKCOL, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_COPY", M_COPY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_MOVE", M_MOVE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_LOCK", M_LOCK, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_UNLOCK", M_UNLOCK, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("M_INVALID", M_INVALID, CONST_CS | CONST_PERSISTENT);
+
+ /* Possible values for request_rec.read_body (set by handling module):
+ * REQUEST_NO_BODY Send 413 error if message has any body
+ * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length
+ * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me.
+ * REQUEST_CHUNKED_PASS Pass the chunks to me without removal.
+ */
+ REGISTER_LONG_CONSTANT("REQUEST_NO_BODY", REQUEST_NO_BODY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_ERROR", REQUEST_CHUNKED_ERROR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_DECHUNK", REQUEST_CHUNKED_DECHUNK, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("REQUEST_CHUNKED_PASS", REQUEST_CHUNKED_PASS, CONST_CS | CONST_PERSISTENT);
+
+ /* resolve types for remote_host() */
+ REGISTER_LONG_CONSTANT("REMOTE_HOST", REMOTE_HOST, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("REMOTE_NAME", REMOTE_NAME, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("REMOTE_NOLOOKUP", REMOTE_NOLOOKUP, CONST_CS | CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("REMOTE_DOUBLE_REV", REMOTE_DOUBLE_REV, CONST_CS | CONST_PERSISTENT);
+
+ return SUCCESS;
+}
+
+
+static PHP_MSHUTDOWN_FUNCTION(apache)
+{
+ UNREGISTER_INI_ENTRIES();
+ return SUCCESS;
+}
+
+zend_module_entry apache_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "apache",
+ apache_functions,
+ PHP_MINIT(apache),
+ PHP_MSHUTDOWN(apache),
+ NULL,
+ NULL,
+ PHP_MINFO(apache),
+ NO_VERSION_YET,
+ STANDARD_MODULE_PROPERTIES
+};
+
+/* {{{ proto bool apache_child_terminate(void)
+ Terminate apache process after this request */
+PHP_FUNCTION(apache_child_terminate)
+{
+#ifndef MULTITHREAD
+ if (AP(terminate_child)) {
+ ap_child_terminate( ((request_rec *)SG(server_context)) );
+ RETURN_TRUE;
+ } else { /* tell them to get lost! */
+ php_error(E_WARNING, "apache.child_terminate is disabled");
+ RETURN_FALSE;
+ }
+#else
+ php_error(E_WARNING, "apache_child_terminate() is not supported in this build");
+ RETURN_FALSE;
+#endif
+}
+/* }}} */
+
+/* {{{ proto string apache_note(string note_name [, string note_value])
+ Get and set Apache request notes */
+PHP_FUNCTION(apache_note)
+{
+ char *arg_name, *arg_val = NULL;
+ int arg_name_len, arg_val_len;
+ char *note_val;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &arg_name, &arg_name_len, &arg_val, &arg_val_len) == FAILURE) {
+ return;
+ }
+
+ note_val = (char *) table_get(((request_rec *)SG(server_context))->notes, arg_name);
+
+ if (arg_val) {
+ table_set(((request_rec *)SG(server_context))->notes, arg_name, arg_val);
+ }
+
+ if (!note_val) {
+ RETURN_FALSE;
+ }
+
+ RETURN_STRING(note_val, 1);
+}
+/* }}} */
+
+/* {{{ PHP_MINFO_FUNCTION
+ */
+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;
+
+ serv = ((request_rec *) SG(server_context))->server;
+
+
+ php_info_print_table_start();
+
+#ifdef PHP_WIN32
+ php_info_print_table_row(1, "Apache for Windows 95/NT");
+ php_info_print_table_end();
+ php_info_print_table_start();
+#elif defined(NETWARE)
+ php_info_print_table_row(1, "Apache for NetWare");
+ php_info_print_table_end();
+ php_info_print_table_start();
+#else
+ php_info_print_table_row(2, "APACHE_INCLUDE", PHP_APACHE_INCLUDE);
+ php_info_print_table_row(2, "APACHE_TARGET", PHP_APACHE_TARGET);
+#endif
+
+ php_info_print_table_row(2, "Apache Version", SERVER_VERSION);
+
+#ifdef APACHE_RELEASE
+ snprintf(output_buf, sizeof(output_buf), "%d", APACHE_RELEASE);
+ php_info_print_table_row(2, "Apache Release", output_buf);
+#endif
+ snprintf(output_buf, sizeof(output_buf), "%d", MODULE_MAGIC_NUMBER);
+ php_info_print_table_row(2, "Apache API Version", output_buf);
+ snprintf(output_buf, sizeof(output_buf), "%s:%u", serv->server_hostname, serv->port);
+ php_info_print_table_row(2, "Hostname:Port", output_buf);
+#if !defined(WIN32) && !defined(WINNT)
+ snprintf(output_buf, sizeof(output_buf), "%s(%d)/%d", user_name, (int)user_id, (int)group_id);
+ php_info_print_table_row(2, "User/Group", output_buf);
+ snprintf(output_buf, sizeof(output_buf), "Per Child: %d - Keep Alive: %s - Max Per Connection: %d", max_requests_per_child, serv->keep_alive ? "on":"off", serv->keep_alive_max);
+ php_info_print_table_row(2, "Max Requests", output_buf);
+#endif
+ snprintf(output_buf, sizeof(output_buf), "Connection: %d - Keep-Alive: %d", serv->timeout, serv->keep_alive_timeout);
+ php_info_print_table_row(2, "Timeouts", output_buf);
+#if !defined(WIN32) && !defined(WINNT)
+/*
+ This block seems to be working on NetWare; But it seems to be showing
+ all modules instead of just the loaded ones
+*/
+ php_info_print_table_row(2, "Server Root", server_root);
+
+ strcpy(modulenames, "");
+ for(modp = top_module; modp; modp = modp->next) {
+ strlcpy(name, modp->name, sizeof(name));
+ if ((p = strrchr(name, '.'))) {
+ *p='\0'; /* Cut off ugly .c extensions on module names */
+ }
+ strlcat(modulenames, name, sizeof(modulenames));
+ if (modp->next) {
+ strlcat(modulenames, ", ", sizeof(modulenames));
+ }
+ }
+ php_info_print_table_row(2, "Loaded Modules", modulenames);
+#endif
+
+ php_info_print_table_end();
+
+ DISPLAY_INI_ENTRIES();
+
+ {
+ register int i;
+ array_header *arr;
+ table_entry *elts;
+ request_rec *r;
+
+ r = ((request_rec *) SG(server_context));
+ arr = table_elts(r->subprocess_env);
+ elts = (table_entry *)arr->elts;
+
+ SECTION("Apache Environment");
+ php_info_print_table_start();
+ php_info_print_table_header(2, "Variable", "Value");
+ for (i=0; i < arr->nelts; i++) {
+ php_info_print_table_row(2, elts[i].key, elts[i].val);
+ }
+ php_info_print_table_end();
+ }
+
+ {
+ array_header *env_arr;
+ table_entry *env;
+ int i;
+ request_rec *r;
+
+ r = ((request_rec *) SG(server_context));
+ SECTION("HTTP Headers Information");
+ php_info_print_table_start();
+ php_info_print_table_colspan_header(2, "HTTP Request Headers");
+ php_info_print_table_row(2, "HTTP Request", r->the_request);
+ env_arr = table_elts(r->headers_in);
+ env = (table_entry *)env_arr->elts;
+ for (i = 0; i < env_arr->nelts; ++i) {
+ if (env[i].key) {
+ php_info_print_table_row(2, env[i].key, env[i].val);
+ }
+ }
+ php_info_print_table_colspan_header(2, "HTTP Response Headers");
+ env_arr = table_elts(r->headers_out);
+ env = (table_entry *)env_arr->elts;
+ for(i = 0; i < env_arr->nelts; ++i) {
+ if (env[i].key) {
+ php_info_print_table_row(2, env[i].key, env[i].val);
+ }
+ }
+ php_info_print_table_end();
+ }
+}
+/* }}} */
+
+/* {{{ proto bool virtual(string filename)
+ Perform an Apache sub-request */
+/* This function is equivalent to <!--#include virtual...-->
+ * in mod_include. It does an Apache sub-request. It is useful
+ * for including CGI scripts or .shtml files, or anything else
+ * that you'd parse through Apache (for .phtml files, you'd probably
+ * want to use <?Include>. This only works when PHP is compiled
+ * as an Apache module, since it uses the Apache API for doing
+ * sub requests.
+ */
+PHP_FUNCTION(virtual)
+{
+ char *filename;
+ int filename_len;
+ request_rec *rr = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
+ }
+
+ if (!(rr = sub_req_lookup_uri (filename, ((request_rec *) SG(server_context))))) {
+ php_error(E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
+ if (rr)
+ destroy_sub_req (rr);
+ RETURN_FALSE;
+ }
+
+ if (rr->status != 200) {
+ php_error(E_WARNING, "Unable to include '%s' - error finding URI", filename);
+ if (rr)
+ destroy_sub_req (rr);
+ RETURN_FALSE;
+ }
+
+ php_output_end_all(TSRMLS_C);
+ php_header(TSRMLS_C);
+
+ if (run_sub_req(rr)) {
+ php_error(E_WARNING, "Unable to include '%s' - request execution failed", filename);
+ if (rr)
+ destroy_sub_req (rr);
+ RETURN_FALSE;
+ }
+
+ if (rr)
+ destroy_sub_req (rr);
+ RETURN_TRUE;
+}
+/* }}} */
+
+
+/* {{{ apache_table_to_zval(table *, zval *return_value)
+ Fetch all HTTP request headers */
+static void apache_table_to_zval(table *t, zval *return_value)
+{
+ array_header *env_arr;
+ table_entry *tenv;
+ int i;
+
+ array_init(return_value);
+ env_arr = table_elts(t);
+ tenv = (table_entry *)env_arr->elts;
+ for (i = 0; i < env_arr->nelts; ++i) {
+ if (!tenv[i].key) {
+ continue;
+ }
+ if (add_assoc_string(return_value, tenv[i].key, (tenv[i].val==NULL) ? "" : tenv[i].val, 1)==FAILURE) {
+ RETURN_FALSE;
+ }
+ }
+
+}
+/* }}} */
+
+
+/* {{{ proto array getallheaders(void)
+*/
+/* Alias for apache_request_headers() */
+/* }}} */
+
+/* {{{ proto array apache_request_headers(void)
+ Fetch all HTTP request headers */
+PHP_FUNCTION(apache_request_headers)
+{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ apache_table_to_zval(((request_rec *)SG(server_context))->headers_in, return_value);
+}
+/* }}} */
+
+/* {{{ proto array apache_response_headers(void)
+ Fetch all HTTP response headers */
+PHP_FUNCTION(apache_response_headers)
+{
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ apache_table_to_zval(((request_rec *) SG(server_context))->headers_out, return_value);
+}
+/* }}} */
+
+/* {{{ proto bool apache_setenv(string variable, string value [, bool walk_to_top])
+ Set an Apache subprocess_env variable */
+PHP_FUNCTION(apache_setenv)
+{
+ int var_len, val_len;
+ zend_bool top=0;
+ char *var = NULL, *val = NULL;
+ request_rec *r = (request_rec *) SG(server_context);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &var, &var_len, &val, &val_len, &top) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ while(top) {
+ if (r->prev) {
+ r = r->prev;
+ }
+ else break;
+ }
+
+ ap_table_setn(r->subprocess_env, ap_pstrndup(r->pool, var, var_len), ap_pstrndup(r->pool, val, val_len));
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto object apache_lookup_uri(string URI)
+ Perform a partial request of the given URI to obtain information about it */
+PHP_FUNCTION(apache_lookup_uri)
+{
+ char *filename;
+ int filename_len;
+ request_rec *rr=NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+ return;
+ }
+
+ if(!(rr = sub_req_lookup_uri(filename, ((request_rec *) SG(server_context))))) {
+ php_error(E_WARNING, "URI lookup failed", filename);
+ RETURN_FALSE;
+ }
+
+ object_init(return_value);
+ add_property_long(return_value,"status", rr->status);
+
+ if (rr->the_request) {
+ add_property_string(return_value,"the_request", rr->the_request, 1);
+ }
+ if (rr->status_line) {
+ add_property_string(return_value,"status_line", (char *)rr->status_line, 1);
+ }
+ if (rr->method) {
+ add_property_string(return_value,"method", (char *)rr->method, 1);
+ }
+ if (rr->content_type) {
+ add_property_string(return_value,"content_type", (char *)rr->content_type, 1);
+ }
+ if (rr->handler) {
+ add_property_string(return_value,"handler", (char *)rr->handler, 1);
+ }
+ if (rr->uri) {
+ add_property_string(return_value,"uri", rr->uri, 1);
+ }
+ if (rr->filename) {
+ add_property_string(return_value,"filename", rr->filename, 1);
+ }
+ if (rr->path_info) {
+ add_property_string(return_value,"path_info", rr->path_info, 1);
+ }
+ if (rr->args) {
+ add_property_string(return_value,"args", rr->args, 1);
+ }
+ if (rr->boundary) {
+ add_property_string(return_value,"boundary", rr->boundary, 1);
+ }
+ add_property_long(return_value,"no_cache", rr->no_cache);
+ add_property_long(return_value,"no_local_copy", rr->no_local_copy);
+ add_property_long(return_value,"allowed", rr->allowed);
+ add_property_long(return_value,"sent_bodyct", rr->sent_bodyct);
+ add_property_long(return_value,"bytes_sent", rr->bytes_sent);
+ add_property_long(return_value,"byterange", rr->byterange);
+ add_property_long(return_value,"clength", rr->clength);
+
+#if MODULE_MAGIC_NUMBER >= 19980324
+ if (rr->unparsed_uri) {
+ add_property_string(return_value,"unparsed_uri", rr->unparsed_uri, 1);
+ }
+ if(rr->mtime) {
+ add_property_long(return_value,"mtime", rr->mtime);
+ }
+#endif
+ if(rr->request_time) {
+ add_property_long(return_value,"request_time", rr->request_time);
+ }
+
+ destroy_sub_req(rr);
+}
+/* }}} */
+
+
+#if 0
+/*
+This function is most likely a bad idea. Just playing with it for now.
+*/
+
+PHP_FUNCTION(apache_exec_uri)
+{
+ zval **filename;
+ request_rec *rr=NULL;
+
+ if (ZEND_NUM_ARGS() != 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
+
+/* {{{ proto string apache_get_version(void)
+ Fetch Apache version */
+PHP_FUNCTION(apache_get_version)
+{
+ char *apv = (char *) ap_get_server_version();
+
+ if (apv && *apv) {
+ RETURN_STRING(apv, 1);
+ } else {
+ RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto array apache_get_modules(void)
+ Get a list of loaded Apache modules */
+PHP_FUNCTION(apache_get_modules)
+{
+ int n;
+ char *p;
+
+ array_init(return_value);
+
+ for (n = 0; ap_loaded_modules[n]; ++n) {
+ char *s = (char *) ap_loaded_modules[n]->name;
+ if ((p = strchr(s, '.'))) {
+ add_next_index_stringl(return_value, s, (p - s), 1);
+ } else {
+ add_next_index_string(return_value, s, 1);
+ }
+ }
+}
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff --git a/sapi/apache_hooks/php_apache_http.h b/sapi/apache_hooks/php_apache_http.h
new file mode 100644
index 0000000..23cf7fe
--- /dev/null
+++ b/sapi/apache_hooks/php_apache_http.h
@@ -0,0 +1,44 @@
+#define NO_REGEX_EXTRA_H
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <stddef.h>
+#endif
+
+#ifdef NETWARE
+#include <netinet/in.h>
+#endif
+
+#include "zend.h"
+#include "zend_stack.h"
+#include "ext/ereg/php_regex.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 "util_script.h"
+
+#include "php_variables.h"
+#include "php_main.h"
+#include "php_ini.h"
+#include "ext/standard/php_standard.h"
+
+#include "mod_php5.h"
+
+
+zval *php_apache_request_new(request_rec *r);
+
+int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRMLS_DC);
diff --git a/sapi/apache_hooks/sapi_apache.c b/sapi/apache_hooks/sapi_apache.c
new file mode 100644
index 0000000..a9c9d67
--- /dev/null
+++ b/sapi/apache_hooks/sapi_apache.c
@@ -0,0 +1,131 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 5 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2013 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.01 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_01.txt |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Authors: Rasmus Lerdorf <rasmus@php.net> |
+ | (with helpful hints from Dean Gaudet <dgaudet@arctic.org> |
+ | PHP 4.0 patches by: |
+ | Zeev Suraski <zeev@zend.com> |
+ | Stig Bakken <ssb@php.net> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id$ */
+
+#include "php_apache_http.h"
+
+/* {{{ apache_php_module_main
+ */
+int apache_php_module_main(request_rec *r, int display_source_mode TSRMLS_DC)
+{
+ zend_file_handle file_handle;
+
+ if (php_request_startup(TSRMLS_C) == FAILURE) {
+ return FAILURE;
+ }
+ /* sending a file handle to another dll is not working
+ so let zend open it. */
+
+ if (display_source_mode) {
+ zend_syntax_highlighter_ini syntax_highlighter_ini;
+
+ php_get_highlight_struct(&syntax_highlighter_ini);
+ if (highlight_file(SG(request_info).path_translated, &syntax_highlighter_ini TSRMLS_CC)){
+ 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 TSRMLS_CC);
+ }
+ AP(in_request) = 0;
+
+ return (OK);
+}
+/* }}} */
+
+/* {{{ apache_php_module_hook
+ */
+int apache_php_module_hook(request_rec *r, php_handler *handler, zval **ret TSRMLS_DC)
+{
+ zend_file_handle file_handle;
+ zval *req;
+ char *tmp;
+
+#if PHP_SIGCHILD
+ signal(SIGCHLD, sigchld_handler);
+#endif
+ if(AP(current_hook) == AP_RESPONSE) {
+ if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
+ return FAILURE;
+ }
+ else {
+ if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
+ return FAILURE;
+ }
+
+ req = php_apache_request_new(r);
+ php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
+
+ switch(handler->type) {
+ case AP_HANDLER_TYPE_FILE:
+ php_register_variable("PHP_SELF_HOOK", handler->name, PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
+ memset(&file_handle, 0, sizeof(file_handle));
+ file_handle.type = ZEND_HANDLE_FILENAME;
+ file_handle.filename = handler->name;
+ (void) php_execute_simple_script(&file_handle, ret TSRMLS_CC);
+ break;
+ case AP_HANDLER_TYPE_METHOD:
+ if( (tmp = strstr(handler->name, "::")) != NULL && *(tmp+2) != '\0' ) {
+ zval *class;
+ zval *method;
+ *tmp = '\0';
+ ALLOC_ZVAL(class);
+ ZVAL_STRING(class, handler->name, 1);
+ ALLOC_ZVAL(method);
+ ZVAL_STRING(method, tmp +2, 1);
+ *tmp = ':';
+ call_user_function_ex(EG(function_table), &class, method, ret, 0, NULL, 0, NULL TSRMLS_CC);
+ zval_dtor(class);
+ zval_dtor(method);
+ }
+ else {
+ php_error(E_ERROR, "Unable to call %s - not a Class::Method\n", handler->name);
+ /* not a class::method */
+ }
+ break;
+ default:
+ /* not a valid type */
+ assert(0);
+ break;
+ }
+ zval_dtor(req);
+ AP(in_request) = 0;
+
+ return OK;
+}
+
+/* }}} */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */